From: Ken L. <kl...@st...> - 2008-07-17 19:35:55
|
During runtime I would like to mark some VM_Field objects, particular those which represent static fields of classes by using a bit in the objects' status header. In the Baseline compiler for IA32 I extended the GET_STATIC_FIELD (and PUT_STATIC_FIELD) method to first check if the corresponding VM_Field object of the static field accessed is marked with the bit in its status header and then execute a method bar() by passing the VM_Field object. The modification looks something like this: protected final void emit_resolved_getstatic(VM_FieldReference fieldRef) { VM_Field field = fieldRef.peekResolvedField(); Offset fieldOffset = field.getOffset(); int address = VM_Magic.objectAsAddress(field).toInt(); if (fieldRef.getSize() <= BYTES_IN_INT) { asm.emitMOV_Reg_Imm(T0, address); asm.emitMOV_Reg_RegDisp(T1, T0, STATUS_HEADER_OFFSET); asm.emitTEST_Reg_Imm_Word(T1, MARK_BIT); VM_ForwardReference fr1 = asm.forwardJcc(VM_Assembler.EQ); asm.emitPUSH_Reg(T0); genParameterRegisterLoad(1); asm.emitCALL_RegDisp(JTOC, VM_Entrypoints.foo.getOffset()); fr1.resolved(asm); asm.emitPUSH_RegDisp(JTOC, fieldOffset); } else { ... } } When compiling an image, I was not able to start the RVM due to a "sp (0x57a6e340) too far below stackLimit (0x00000000) to recover" error message. With the help of some debugging outputs I found out that the VM_Field objects in the BootImage have a "strange" address like 0x2157 which was the reason why the loading of the status header into a register failed. After discussing with Ian Rogers (thanks for the support btw!) we found out that "the address in the boot image writer is an int literal place holder for the real object". Ian suggested to wrap my code around a conditional if(VM.runningVM). Correct me if I'm wrong but when the bootimage writer compiles classes, the VM.runningVM variable is false at that time and when accessing a static field belonging to a bootimage class during runtime, my code will never be executed. A tested this shortly by instantiating an object of a class Foo { static int i; stati String s; } containing some static fields, marking their VM_Field objects with the corresponding bit and accessing those fields in the VM. The result although was that my code wasn't executed because of the above assumption, I think. Or does the BootImage only consists of bytecode which are compiled by the baseline (or optimising) compiler during runtime to machine code? Am I misunderstanding something? Cheers, Ken |