* @param level Optimization level
* @param isBootstrap
* @return The compiled method
*/
protected CompiledMethod doCompile(VmMethod method, NativeStream nos, int level, boolean isBootstrap) {
final CompiledMethod cm = new CompiledMethod(level);
if (method.isNative()) {
Object label = new Label(method.getMangledName());
cm.setCodeStart(nos.getObjectRef(label));
} else {
final X86Assembler os = (X86Assembler) nos;
final EntryPoints context = getEntryPoints();
// Create the helper
final X86CompilerHelper ih = new X86CompilerHelper(os, null, context, isBootstrap);
// Start an "object"
final NativeStream.ObjectInfo objectInfo = os.startObject(context.getVmMethodCodeClass());
// Start the code creation
cm.setCodeStart(os.setObjectRef(new Label(method.getMangledName() + "$$start")));
// Setup call to {@link VmMethod#recompileMethod(int, int)}
final VmType<?> declClass = method.getDeclaringClass();
os.writePUSH(declClass.getSharedStaticsIndex());
os.writePUSH(declClass.indexOf(method));
final int recompileStatOfs = ih.getSharedStaticsOffset(context.getRecompileMethod());
os.writeCALL(ih.STATICS, recompileStatOfs);
// Emit jump to the newly compiled code.
final int methodStatOfs = ih.getSharedStaticsOffset(method);
os.writeJMP(ih.STATICS, methodStatOfs);
// Close the "object"
objectInfo.markEnd();
// The end
cm.setCodeEnd(os.setObjectRef(new Label(method.getMangledName() + "$$end")));
// Test for unresolved objectrefs
if (!isBootstrap && os.hasUnresolvedObjectRefs()) {
throw new Error("There are unresolved objectrefs " + os.getUnresolvedObjectRefs());
}