32 import sun.jvm.hotspot.utilities.*; 33 34 public class OopMapValue { 35 private short value; 36 private short contentReg; 37 38 /** Read from target VM; located in compiler/oopMap.hpp */ 39 // How bits are organized 40 static int TYPE_BITS; 41 static int REGISTER_BITS; 42 static int TYPE_SHIFT; 43 static int REGISTER_SHIFT; 44 static int TYPE_MASK; 45 static int TYPE_MASK_IN_PLACE; 46 static int REGISTER_MASK; 47 static int REGISTER_MASK_IN_PLACE; 48 49 // Types of OopValues 50 static int UNUSED_VALUE; 51 static int OOP_VALUE; 52 static int VALUE_VALUE; 53 static int NARROWOOP_VALUE; 54 static int CALLEE_SAVED_VALUE; 55 static int DERIVED_OOP_VALUE; 56 57 static { 58 VM.registerVMInitializedObserver(new Observer() { 59 public void update(Observable o, Object data) { 60 initialize(VM.getVM().getTypeDataBase()); 61 } 62 }); 63 } 64 65 private static void initialize(TypeDataBase db) { 66 TYPE_BITS = db.lookupIntConstant("OopMapValue::type_bits").intValue(); 67 REGISTER_BITS = db.lookupIntConstant("OopMapValue::register_bits").intValue(); 68 TYPE_SHIFT = db.lookupIntConstant("OopMapValue::type_shift").intValue(); 69 REGISTER_SHIFT = db.lookupIntConstant("OopMapValue::register_shift").intValue(); 70 TYPE_MASK = db.lookupIntConstant("OopMapValue::type_mask").intValue(); 71 TYPE_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::type_mask_in_place").intValue(); 72 REGISTER_MASK = db.lookupIntConstant("OopMapValue::register_mask").intValue(); 73 REGISTER_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::register_mask_in_place").intValue(); 74 UNUSED_VALUE = db.lookupIntConstant("OopMapValue::unused_value").intValue(); 75 OOP_VALUE = db.lookupIntConstant("OopMapValue::oop_value").intValue(); 76 VALUE_VALUE = db.lookupIntConstant("OopMapValue::value_value").intValue(); 77 NARROWOOP_VALUE = db.lookupIntConstant("OopMapValue::narrowoop_value").intValue(); 78 CALLEE_SAVED_VALUE = db.lookupIntConstant("OopMapValue::callee_saved_value").intValue(); 79 DERIVED_OOP_VALUE = db.lookupIntConstant("OopMapValue::derived_oop_value").intValue(); 80 } 81 82 public static abstract class OopTypes { 83 public static final OopTypes UNUSED_VALUE = new OopTypes() { int getValue() { return OopMapValue.UNUSED_VALUE; }}; 84 public static final OopTypes OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.OOP_VALUE; }}; 85 public static final OopTypes VALUE_VALUE = new OopTypes() { int getValue() { return OopMapValue.VALUE_VALUE; }}; 86 public static final OopTypes NARROWOOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.NARROWOOP_VALUE; }}; 87 public static final OopTypes CALLEE_SAVED_VALUE = new OopTypes() { int getValue() { return OopMapValue.CALLEE_SAVED_VALUE; }}; 88 public static final OopTypes DERIVED_OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.DERIVED_OOP_VALUE; }}; 89 90 abstract int getValue(); 91 protected OopTypes() {} 92 } 93 94 public OopMapValue() { setValue((short) 0); setContentReg(new VMReg(0)); } 95 public OopMapValue(VMReg reg, OopTypes t) { setReg(reg); setType(t); } 96 public OopMapValue(VMReg reg, OopTypes t, VMReg reg2) { setReg(reg); setType(t); setContentReg(reg2); } 97 public OopMapValue(CompressedReadStream stream) { readFrom(stream); } 98 99 public void readFrom(CompressedReadStream stream) { 100 setValue((short) stream.readInt()); 101 if (isCalleeSaved() || isDerivedOop()) { 102 setContentReg(new VMReg(stream.readInt())); 103 } 104 } 105 106 // Querying 107 public boolean isOop() { return (getValue() & TYPE_MASK_IN_PLACE) == OOP_VALUE; } 108 public boolean isValue() { return (getValue() & TYPE_MASK_IN_PLACE) == VALUE_VALUE; } 109 public boolean isNarrowOop() { return (getValue() & TYPE_MASK_IN_PLACE) == NARROWOOP_VALUE; } 110 public boolean isCalleeSaved() { return (getValue() & TYPE_MASK_IN_PLACE) == CALLEE_SAVED_VALUE; } 111 public boolean isDerivedOop() { return (getValue() & TYPE_MASK_IN_PLACE) == DERIVED_OOP_VALUE; } 112 113 public VMReg getReg() { return new VMReg((getValue() & REGISTER_MASK_IN_PLACE) >> REGISTER_SHIFT); } 114 public void setReg(VMReg r) { setValue((short) (r.getValue() << REGISTER_SHIFT | (getValue() & TYPE_MASK_IN_PLACE))); } 115 116 public OopTypes getType() { 117 int which = (getValue() & TYPE_MASK_IN_PLACE); 118 if (which == UNUSED_VALUE) return OopTypes.UNUSED_VALUE; 119 else if (which == OOP_VALUE) return OopTypes.OOP_VALUE; 120 else if (which == VALUE_VALUE) return OopTypes.VALUE_VALUE; 121 else if (which == NARROWOOP_VALUE) return OopTypes.NARROWOOP_VALUE; 122 else if (which == CALLEE_SAVED_VALUE) return OopTypes.CALLEE_SAVED_VALUE; 123 else if (which == DERIVED_OOP_VALUE) return OopTypes.DERIVED_OOP_VALUE; 124 else throw new InternalError("unknown which " + which + " (TYPE_MASK_IN_PLACE = " + TYPE_MASK_IN_PLACE + ")"); 125 } 126 public void setType(OopTypes t) { setValue((short) ((getValue() & REGISTER_MASK_IN_PLACE) | t.getValue())); } 127 128 public VMReg getContentReg() { return new VMReg(contentReg); } 129 public void setContentReg(VMReg r) { contentReg = (short) r.getValue(); } 130 131 /** Physical location queries */ 132 public boolean isRegisterLoc() { return (getReg().lessThan(VM.getVM().getVMRegImplInfo().getStack0())); } 133 public boolean isStackLoc() { return (getReg().greaterThanOrEqual(VM.getVM().getVMRegImplInfo().getStack0())); } 134 135 /** Returns offset from sp. */ 136 public int getStackOffset() { 137 if (Assert.ASSERTS_ENABLED) { 138 Assert.that(isStackLoc(), "must be stack location"); 139 } 140 return getReg().minus(VM.getVM().getVMRegImplInfo().getStack0()); | 32 import sun.jvm.hotspot.utilities.*; 33 34 public class OopMapValue { 35 private short value; 36 private short contentReg; 37 38 /** Read from target VM; located in compiler/oopMap.hpp */ 39 // How bits are organized 40 static int TYPE_BITS; 41 static int REGISTER_BITS; 42 static int TYPE_SHIFT; 43 static int REGISTER_SHIFT; 44 static int TYPE_MASK; 45 static int TYPE_MASK_IN_PLACE; 46 static int REGISTER_MASK; 47 static int REGISTER_MASK_IN_PLACE; 48 49 // Types of OopValues 50 static int UNUSED_VALUE; 51 static int OOP_VALUE; 52 static int NARROWOOP_VALUE; 53 static int CALLEE_SAVED_VALUE; 54 static int DERIVED_OOP_VALUE; 55 56 static { 57 VM.registerVMInitializedObserver(new Observer() { 58 public void update(Observable o, Object data) { 59 initialize(VM.getVM().getTypeDataBase()); 60 } 61 }); 62 } 63 64 private static void initialize(TypeDataBase db) { 65 TYPE_BITS = db.lookupIntConstant("OopMapValue::type_bits").intValue(); 66 REGISTER_BITS = db.lookupIntConstant("OopMapValue::register_bits").intValue(); 67 TYPE_SHIFT = db.lookupIntConstant("OopMapValue::type_shift").intValue(); 68 REGISTER_SHIFT = db.lookupIntConstant("OopMapValue::register_shift").intValue(); 69 TYPE_MASK = db.lookupIntConstant("OopMapValue::type_mask").intValue(); 70 TYPE_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::type_mask_in_place").intValue(); 71 REGISTER_MASK = db.lookupIntConstant("OopMapValue::register_mask").intValue(); 72 REGISTER_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::register_mask_in_place").intValue(); 73 UNUSED_VALUE = db.lookupIntConstant("OopMapValue::unused_value").intValue(); 74 OOP_VALUE = db.lookupIntConstant("OopMapValue::oop_value").intValue(); 75 NARROWOOP_VALUE = db.lookupIntConstant("OopMapValue::narrowoop_value").intValue(); 76 CALLEE_SAVED_VALUE = db.lookupIntConstant("OopMapValue::callee_saved_value").intValue(); 77 DERIVED_OOP_VALUE = db.lookupIntConstant("OopMapValue::derived_oop_value").intValue(); 78 } 79 80 public static abstract class OopTypes { 81 public static final OopTypes UNUSED_VALUE = new OopTypes() { int getValue() { return OopMapValue.UNUSED_VALUE; }}; 82 public static final OopTypes OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.OOP_VALUE; }}; 83 public static final OopTypes NARROWOOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.NARROWOOP_VALUE; }}; 84 public static final OopTypes CALLEE_SAVED_VALUE = new OopTypes() { int getValue() { return OopMapValue.CALLEE_SAVED_VALUE; }}; 85 public static final OopTypes DERIVED_OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.DERIVED_OOP_VALUE; }}; 86 87 abstract int getValue(); 88 protected OopTypes() {} 89 } 90 91 public OopMapValue() { setValue((short) 0); setContentReg(new VMReg(0)); } 92 public OopMapValue(VMReg reg, OopTypes t) { setReg(reg); setType(t); } 93 public OopMapValue(VMReg reg, OopTypes t, VMReg reg2) { setReg(reg); setType(t); setContentReg(reg2); } 94 public OopMapValue(CompressedReadStream stream) { readFrom(stream); } 95 96 public void readFrom(CompressedReadStream stream) { 97 setValue((short) stream.readInt()); 98 if (isCalleeSaved() || isDerivedOop()) { 99 setContentReg(new VMReg(stream.readInt())); 100 } 101 } 102 103 // Querying 104 public boolean isOop() { return (getValue() & TYPE_MASK_IN_PLACE) == OOP_VALUE; } 105 public boolean isNarrowOop() { return (getValue() & TYPE_MASK_IN_PLACE) == NARROWOOP_VALUE; } 106 public boolean isCalleeSaved() { return (getValue() & TYPE_MASK_IN_PLACE) == CALLEE_SAVED_VALUE; } 107 public boolean isDerivedOop() { return (getValue() & TYPE_MASK_IN_PLACE) == DERIVED_OOP_VALUE; } 108 109 public VMReg getReg() { return new VMReg((getValue() & REGISTER_MASK_IN_PLACE) >> REGISTER_SHIFT); } 110 public void setReg(VMReg r) { setValue((short) (r.getValue() << REGISTER_SHIFT | (getValue() & TYPE_MASK_IN_PLACE))); } 111 112 public OopTypes getType() { 113 int which = (getValue() & TYPE_MASK_IN_PLACE); 114 if (which == UNUSED_VALUE) return OopTypes.UNUSED_VALUE; 115 else if (which == OOP_VALUE) return OopTypes.OOP_VALUE; 116 else if (which == NARROWOOP_VALUE) return OopTypes.NARROWOOP_VALUE; 117 else if (which == CALLEE_SAVED_VALUE) return OopTypes.CALLEE_SAVED_VALUE; 118 else if (which == DERIVED_OOP_VALUE) return OopTypes.DERIVED_OOP_VALUE; 119 else throw new InternalError("unknown which " + which + " (TYPE_MASK_IN_PLACE = " + TYPE_MASK_IN_PLACE + ")"); 120 } 121 public void setType(OopTypes t) { setValue((short) ((getValue() & REGISTER_MASK_IN_PLACE) | t.getValue())); } 122 123 public VMReg getContentReg() { return new VMReg(contentReg); } 124 public void setContentReg(VMReg r) { contentReg = (short) r.getValue(); } 125 126 /** Physical location queries */ 127 public boolean isRegisterLoc() { return (getReg().lessThan(VM.getVM().getVMRegImplInfo().getStack0())); } 128 public boolean isStackLoc() { return (getReg().greaterThanOrEqual(VM.getVM().getVMRegImplInfo().getStack0())); } 129 130 /** Returns offset from sp. */ 131 public int getStackOffset() { 132 if (Assert.ASSERTS_ENABLED) { 133 Assert.that(isStackLoc(), "must be stack location"); 134 } 135 return getReg().minus(VM.getVM().getVMRegImplInfo().getStack0()); |