comparison src/share/vm/jvmci/jvmciCodeInstaller.cpp @ 21730:b9f9b8af17ff

Simplify interface to reference map
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Wed, 03 Jun 2015 19:57:38 -0700
parents ce2113326bc8
children df9d2375512a
comparison
equal deleted inserted replaced
21729:e7f5ddef438d 21730:b9f9b8af17ff
67 Method* getMethodFromHotSpotMethod(oop hotspot_method) { 67 Method* getMethodFromHotSpotMethod(oop hotspot_method) {
68 assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethodImpl::klass()), "sanity"); 68 assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethodImpl::klass()), "sanity");
69 return asMethod(HotSpotResolvedJavaMethodImpl::metaspaceMethod(hotspot_method)); 69 return asMethod(HotSpotResolvedJavaMethodImpl::metaspaceMethod(hotspot_method));
70 } 70 }
71 71
72 const int MapWordBits = 64;
73
74 static int entry_value(typeArrayOop words, int i) {
75 jint words_idx = i / MapWordBits;
76 assert(words_idx >= 0 && words_idx < words->length(), "unexpected index");
77 jlong word = words->long_at(words_idx);
78 return (word >> (i % MapWordBits)) & 15LL;
79 }
80
81 static int fixedmap_size(oop bitset) {
82 typeArrayOop arr = HotSpotOopMap::words(bitset);
83 return arr->length() * MapWordBits;
84 }
85
86 static void set_vmreg_oops(OopMap* map, VMReg reg, typeArrayOop words, int idx) {
87 int value = entry_value(words, 4 * idx);
88 switch (value) {
89 case 10:
90 map->set_oop(reg);
91 break;
92 case 5:
93 map->set_narrowoop(reg);
94 map->set_narrowoop(reg->next());
95 break;
96 case 1:
97 map->set_narrowoop(reg);
98 break;
99 case 4:
100 map->set_narrowoop(reg->next());
101 break;
102 case 0:
103 break;
104 default:
105 assert(false, err_msg("unexpected bit pattern at %d = 0x%x", idx, value));
106 ShouldNotReachHere();
107 }
108 }
109
110 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo 72 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo
111 static OopMap* create_oop_map(jint total_frame_size, jint parameter_count, oop debug_info) { 73 OopMap* CodeInstaller::create_oop_map(oop debug_info) {
112 OopMap* map = new OopMap(total_frame_size, parameter_count);
113 oop reference_map = DebugInfo::referenceMap(debug_info); 74 oop reference_map = DebugInfo::referenceMap(debug_info);
114 oop register_map = HotSpotReferenceMap::registerRefMap(reference_map); 75 OopMap* map = new OopMap(_total_frame_size, _parameter_count);
115 oop frame_map = HotSpotReferenceMap::frameRefMap(reference_map); 76 objArrayOop objects = HotSpotReferenceMap::objects(reference_map);
77 typeArrayOop bytesPerArray = HotSpotReferenceMap::bytesPerElement(reference_map);
78 for (int i = 0; i < objects->length(); i++) {
79 oop value = objects->obj_at(i);
80 oop lirKind = AbstractValue::lirKind(value);
81 oop platformKind = LIRKind::platformKind(lirKind);
82 int bytesPerElement = bytesPerArray->int_at(i);
83 assert(bytesPerElement == 4 || bytesPerElement == 8, "wrong sizes");
84 jint referenceMask = LIRKind::referenceMask(lirKind);
85 assert(referenceMask != 0, "must be a reference type");
86 assert(referenceMask != -1, "must not be a derived reference type");
87
88 VMReg vmReg;
89 if (value->is_a(RegisterValue::klass())) {
90 oop reg = RegisterValue::reg(value);
91 jint number = code_Register::number(reg);
92 vmReg = CodeInstaller::get_hotspot_reg(number);
93 } else if (value->is_a(StackSlot::klass())) {
94 jint offset = StackSlot::offset(value);
95 #ifdef TARGET_ARCH_sparc
96 if(offset >= 0) {
97 offset += 128;
98 }
99 #endif
100 if (StackSlot::addFrameSize(value)) {
101 offset += _total_frame_size;
102 }
103 assert(offset % 4 == 0, "must be aligned");
104 vmReg = VMRegImpl::stack2reg(offset / 4);
105 }
106
107 int bit = 1;
108 while (referenceMask != 0) {
109 if (referenceMask & bit) {
110 if (bytesPerElement == 8) {
111 map->set_oop(vmReg);
112 } else {
113 map->set_narrowoop(vmReg);
114 }
115 referenceMask &= ~bit;
116 }
117 vmReg = vmReg->next();
118 if (bytesPerElement == 8) {
119 vmReg = vmReg->next();
120 }
121 bit <<= 1;
122 }
123 }
116 oop callee_save_info = (oop) DebugInfo::calleeSaveInfo(debug_info); 124 oop callee_save_info = (oop) DebugInfo::calleeSaveInfo(debug_info);
117
118 if (register_map != NULL) {
119 typeArrayOop words = HotSpotOopMap::words(register_map);
120 int mapIdx = 0;
121 for (jint i = 0; i < RegisterImpl::number_of_registers; i++) {
122 set_vmreg_oops(map, as_Register(i)->as_VMReg(), words, mapIdx);
123 mapIdx++;
124 }
125 #ifdef TARGET_ARCH_x86
126 for (jint i = 0; i < XMMRegisterImpl::number_of_registers; i++) {
127 VMReg reg = as_XMMRegister(i)->as_VMReg();
128 for (jint j = 0; j < 4; j++) {
129 set_vmreg_oops(map, reg->next(2 * j), words, mapIdx++);
130 }
131 }
132 #endif
133 #ifdef TARGET_ARCH_sparc
134 for (jint i = 0; i < FloatRegisterImpl::number_of_registers; i++) {
135 VMReg reg = as_FloatRegister(i)->as_VMReg();
136 set_vmreg_oops(map, reg, words, mapIdx++);
137 }
138 #endif
139 }
140
141 typeArrayOop words = HotSpotOopMap::words(frame_map);
142 int size = fixedmap_size(frame_map) / 4;
143 for (jint i = 0; i < size; i++) {
144 // HotSpot stack slots are 4 bytes
145 VMReg reg = VMRegImpl::stack2reg(i * VMRegImpl::slots_per_word);
146 set_vmreg_oops(map, reg, words, i);
147 }
148
149 if (callee_save_info != NULL) { 125 if (callee_save_info != NULL) {
150 objArrayOop registers = RegisterSaveLayout::registers(callee_save_info); 126 objArrayOop registers = RegisterSaveLayout::registers(callee_save_info);
151 typeArrayOop slots = RegisterSaveLayout::slots(callee_save_info); 127 typeArrayOop slots = RegisterSaveLayout::slots(callee_save_info);
152 for (jint i = 0; i < slots->length(); i++) { 128 for (jint i = 0; i < slots->length(); i++) {
153 oop jvmci_reg = registers->obj_at(i); 129 oop jvmci_reg = registers->obj_at(i);
259 second = value; 235 second = value;
260 } 236 }
261 return value; 237 return value;
262 } 238 }
263 } else if (value->is_a(StackSlot::klass())) { 239 } else if (value->is_a(StackSlot::klass())) {
264 Location::Type locationType; 240 jint offset = StackSlot::offset(value);
241 #ifdef TARGET_ARCH_sparc
242 if(offset >= 0) {
243 offset += 128;
244 }
245 #endif
246 if (StackSlot::addFrameSize(value)) {
247 offset += _total_frame_size;
248 }
249
250 Location::Type locationType;
265 if (type == T_LONG) { 251 if (type == T_LONG) {
266 locationType = reference ? Location::oop : Location::lng; 252 locationType = reference ? Location::oop : Location::lng;
267 } else if (type == T_INT) { 253 } else if (type == T_INT) {
268 locationType = reference ? Location::narrowoop : Location::normal; 254 locationType = reference ? Location::narrowoop : Location::normal;
269 } else if(type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN) { 255 } else if(type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN) {
275 assert(!reference, "unexpected type in stack slot"); 261 assert(!reference, "unexpected type in stack slot");
276 locationType = Location::dbl; 262 locationType = Location::dbl;
277 } else { 263 } else {
278 assert(type == T_OBJECT && reference, "unexpected type in stack slot"); 264 assert(type == T_OBJECT && reference, "unexpected type in stack slot");
279 locationType = Location::oop; 265 locationType = Location::oop;
280 }
281 jint offset = StackSlot::offset(value);
282 #ifdef TARGET_ARCH_sparc
283 if(offset >= 0) {
284 offset += 128;
285 }
286 #endif
287 if (StackSlot::addFrameSize(value)) {
288 offset += _total_frame_size;
289 } 266 }
290 ScopeValue* value = new LocationValue(Location::new_stk_loc(locationType, offset)); 267 ScopeValue* value = new LocationValue(Location::new_stk_loc(locationType, offset));
291 if (type == T_DOUBLE || (type == T_LONG && !reference)) { 268 if (type == T_DOUBLE || (type == T_LONG && !reference)) {
292 second = value; 269 second = value;
293 } 270 }
854 oop debug_info = CompilationResult_Infopoint::debugInfo(site); 831 oop debug_info = CompilationResult_Infopoint::debugInfo(site);
855 assert(debug_info != NULL, "debug info expected"); 832 assert(debug_info != NULL, "debug info expected");
856 833
857 // address instruction = _instructions->start() + pc_offset; 834 // address instruction = _instructions->start() + pc_offset;
858 // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start(); 835 // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start();
859 _debug_recorder->add_safepoint(pc_offset, create_oop_map(_total_frame_size, _parameter_count, debug_info)); 836 _debug_recorder->add_safepoint(pc_offset, create_oop_map(debug_info));
860 record_scope(pc_offset, debug_info); 837 record_scope(pc_offset, debug_info);
861 _debug_recorder->end_safepoint(pc_offset); 838 _debug_recorder->end_safepoint(pc_offset);
862 } 839 }
863 840
864 void CodeInstaller::site_Infopoint(CodeBuffer& buffer, jint pc_offset, oop site) { 841 void CodeInstaller::site_Infopoint(CodeBuffer& buffer, jint pc_offset, oop site) {
889 866
890 NativeInstruction* inst = nativeInstruction_at(_instructions->start() + pc_offset); 867 NativeInstruction* inst = nativeInstruction_at(_instructions->start() + pc_offset);
891 jint next_pc_offset = CodeInstaller::pd_next_offset(inst, pc_offset, hotspot_method); 868 jint next_pc_offset = CodeInstaller::pd_next_offset(inst, pc_offset, hotspot_method);
892 869
893 if (debug_info != NULL) { 870 if (debug_info != NULL) {
894 _debug_recorder->add_safepoint(next_pc_offset, create_oop_map(_total_frame_size, _parameter_count, debug_info)); 871 _debug_recorder->add_safepoint(next_pc_offset, create_oop_map(debug_info));
895 record_scope(next_pc_offset, debug_info); 872 record_scope(next_pc_offset, debug_info);
896 } 873 }
897 874
898 if (foreign_call != NULL) { 875 if (foreign_call != NULL) {
899 jlong foreign_call_destination = HotSpotForeignCallTarget::address(foreign_call); 876 jlong foreign_call_destination = HotSpotForeignCallTarget::address(foreign_call);