comparison src/share/vm/jvmci/jvmciCodeInstaller.cpp @ 22711:316e768645c0

8139589: [JVMCI] throw exceptions in faulty code installation operations
author Roland Schatz <roland.schatz@oracle.com>
date Thu, 29 Oct 2015 15:21:55 +0100
parents 15013021dbfa
children 3c0753fbb592
comparison
equal deleted inserted replaced
22710:7e7573382a23 22711:316e768645c0
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 CompilerToVM::asMethod(hotspot_method); 69 return CompilerToVM::asMethod(hotspot_method);
70 } 70 }
71 71
72 VMReg getVMRegFromLocation(oop location, int total_frame_size) { 72 VMReg getVMRegFromLocation(Handle location, int total_frame_size, TRAPS) {
73 oop reg = code_Location::reg(location); 73 Handle reg = code_Location::reg(location);
74 jint offset = code_Location::offset(location); 74 jint offset = code_Location::offset(location);
75 75
76 if (reg != NULL) { 76 if (reg.not_null()) {
77 // register 77 // register
78 jint number = code_Register::number(reg); 78 jint number = code_Register::number(reg);
79 VMReg vmReg = CodeInstaller::get_hotspot_reg(number); 79 VMReg vmReg = CodeInstaller::get_hotspot_reg(number, CHECK_NULL);
80 assert(offset % 4 == 0, "must be aligned"); 80 if (offset % 4 == 0) {
81 return vmReg->next(offset / 4); 81 return vmReg->next(offset / 4);
82 } else {
83 JVMCI_ERROR_NULL(err_msg("unaligned subregister offset %d in oop map", offset));
84 }
82 } else { 85 } else {
83 // stack slot 86 // stack slot
84 assert(offset % 4 == 0, "must be aligned"); 87 if (offset % 4 == 0) {
85 return VMRegImpl::stack2reg(offset / 4); 88 return VMRegImpl::stack2reg(offset / 4);
89 } else {
90 JVMCI_ERROR_NULL(err_msg("unaligned stack offset %d in oop map", offset));
91 }
86 } 92 }
87 } 93 }
88 94
89 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo 95 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo
90 OopMap* CodeInstaller::create_oop_map(oop debug_info) { 96 OopMap* CodeInstaller::create_oop_map(Handle debug_info, TRAPS) {
91 oop reference_map = DebugInfo::referenceMap(debug_info); 97 Handle reference_map = DebugInfo::referenceMap(debug_info);
92 if (HotSpotReferenceMap::maxRegisterSize(reference_map) > 16) { 98 if (HotSpotReferenceMap::maxRegisterSize(reference_map) > 16) {
93 _has_wide_vector = true; 99 _has_wide_vector = true;
94 } 100 }
95 OopMap* map = new OopMap(_total_frame_size, _parameter_count); 101 OopMap* map = new OopMap(_total_frame_size, _parameter_count);
96 objArrayOop objects = HotSpotReferenceMap::objects(reference_map); 102 objArrayHandle objects = HotSpotReferenceMap::objects(reference_map);
97 objArrayOop derivedBase = HotSpotReferenceMap::derivedBase(reference_map); 103 objArrayHandle derivedBase = HotSpotReferenceMap::derivedBase(reference_map);
98 typeArrayOop sizeInBytes = HotSpotReferenceMap::sizeInBytes(reference_map); 104 typeArrayHandle sizeInBytes = HotSpotReferenceMap::sizeInBytes(reference_map);
99 for (int i = 0; i < objects->length(); i++) { 105 for (int i = 0; i < objects->length(); i++) {
100 oop location = objects->obj_at(i); 106 Handle location = objects->obj_at(i);
101 oop baseLocation = derivedBase->obj_at(i); 107 Handle baseLocation = derivedBase->obj_at(i);
102 int bytes = sizeInBytes->int_at(i); 108 int bytes = sizeInBytes->int_at(i);
103 109
104 VMReg vmReg = getVMRegFromLocation(location, _total_frame_size); 110 VMReg vmReg = getVMRegFromLocation(location, _total_frame_size, CHECK_NULL);
105 if (baseLocation != NULL) { 111 if (baseLocation.not_null()) {
106 // derived oop 112 // derived oop
107 assert(bytes == 8, "derived oop can't be compressed"); 113 #ifdef _LP64
108 VMReg baseReg = getVMRegFromLocation(baseLocation, _total_frame_size); 114 if (bytes == 8) {
109 map->set_derived_oop(vmReg, baseReg); 115 #else
116 if (bytes == 4) {
117 #endif
118 VMReg baseReg = getVMRegFromLocation(baseLocation, _total_frame_size, CHECK_NULL);
119 map->set_derived_oop(vmReg, baseReg);
120 } else {
121 JVMCI_ERROR_NULL(err_msg("invalid derived oop size in ReferenceMap: %d", bytes));
122 }
123 #ifdef _LP64
110 } else if (bytes == 8) { 124 } else if (bytes == 8) {
111 // wide oop 125 // wide oop
112 map->set_oop(vmReg); 126 map->set_oop(vmReg);
127 } else if (bytes == 4) {
128 // narrow oop
129 map->set_narrowoop(vmReg);
130 #else
131 } else if (bytes == 4) {
132 map->set_oop(vmReg);
133 #endif
113 } else { 134 } else {
114 // narrow oop 135 JVMCI_ERROR_NULL(err_msg("invalid oop size in ReferenceMap: %d", bytes));
115 assert(bytes == 4, "wrong size"); 136 }
116 map->set_narrowoop(vmReg); 137 }
117 } 138
118 } 139 Handle callee_save_info = (oop) DebugInfo::calleeSaveInfo(debug_info);
119 140 if (callee_save_info.not_null()) {
120 oop callee_save_info = (oop) DebugInfo::calleeSaveInfo(debug_info); 141 objArrayHandle registers = RegisterSaveLayout::registers(callee_save_info);
121 if (callee_save_info != NULL) { 142 typeArrayHandle slots = RegisterSaveLayout::slots(callee_save_info);
122 objArrayOop registers = RegisterSaveLayout::registers(callee_save_info);
123 typeArrayOop slots = RegisterSaveLayout::slots(callee_save_info);
124 for (jint i = 0; i < slots->length(); i++) { 143 for (jint i = 0; i < slots->length(); i++) {
125 oop jvmci_reg = registers->obj_at(i); 144 Handle jvmci_reg = registers->obj_at(i);
126 jint jvmci_reg_number = code_Register::number(jvmci_reg); 145 jint jvmci_reg_number = code_Register::number(jvmci_reg);
127 VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number); 146 VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number, CHECK_NULL);
128 // HotSpot stack slots are 4 bytes 147 // HotSpot stack slots are 4 bytes
129 jint jvmci_slot = slots->int_at(i); 148 jint jvmci_slot = slots->int_at(i);
130 jint hotspot_slot = jvmci_slot * VMRegImpl::slots_per_word; 149 jint hotspot_slot = jvmci_slot * VMRegImpl::slots_per_word;
131 VMReg hotspot_slot_as_reg = VMRegImpl::stack2reg(hotspot_slot); 150 VMReg hotspot_slot_as_reg = VMRegImpl::stack2reg(hotspot_slot);
132 map->set_callee_saved(hotspot_slot_as_reg, hotspot_reg); 151 map->set_callee_saved(hotspot_slot_as_reg, hotspot_reg);
138 } 157 }
139 } 158 }
140 return map; 159 return map;
141 } 160 }
142 161
143 Metadata* CodeInstaller::record_metadata_reference(Handle& constant) { 162 Metadata* CodeInstaller::record_metadata_reference(Handle constant, TRAPS) {
144 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant); 163 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
145 if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) { 164 if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
146 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj)); 165 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
147 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), err_msg("unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass))); 166 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), err_msg("unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass)));
148 int index = _oop_recorder->find_index(klass); 167 int index = _oop_recorder->find_index(klass);
153 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), err_msg("unexpected compressed method pointer %s @ " INTPTR_FORMAT, method->name()->as_C_string(), p2i(method))); 172 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), err_msg("unexpected compressed method pointer %s @ " INTPTR_FORMAT, method->name()->as_C_string(), p2i(method)));
154 int index = _oop_recorder->find_index(method); 173 int index = _oop_recorder->find_index(method);
155 TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), method->name()->as_C_string()); 174 TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), method->name()->as_C_string());
156 return method; 175 return method;
157 } else { 176 } else {
158 fatal(err_msg("unexpected metadata reference for constant of type %s", obj->klass()->name()->as_C_string())); 177 JVMCI_ERROR_NULL(err_msg("unexpected metadata reference for constant of type %s", obj->klass()->signature_name()));
159 return NULL;
160 } 178 }
161 } 179 }
162 180
163 #ifdef _LP64 181 #ifdef _LP64
164 narrowKlass CodeInstaller::record_narrow_metadata_reference(Handle& constant) { 182 narrowKlass CodeInstaller::record_narrow_metadata_reference(Handle constant, TRAPS) {
165 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant); 183 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
166 assert(HotSpotMetaspaceConstantImpl::compressed(constant), err_msg("unexpected uncompressed pointer")); 184 assert(HotSpotMetaspaceConstantImpl::compressed(constant), err_msg("unexpected uncompressed pointer"));
167 assert(obj->is_a(HotSpotResolvedObjectTypeImpl::klass()), err_msg("unexpected compressed pointer of type %s", obj->klass()->name()->as_C_string())); 185
186 if (!obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
187 JVMCI_ERROR_0(err_msg("unexpected compressed pointer of type %s", obj->klass()->signature_name()));
188 }
168 189
169 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj)); 190 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
170 int index = _oop_recorder->find_index(klass); 191 int index = _oop_recorder->find_index(klass);
171 TRACE_jvmci_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string()); 192 TRACE_jvmci_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
172 return Klass::encode_klass(klass); 193 return Klass::encode_klass(klass);
173 } 194 }
174 #endif 195 #endif
175 196
176 Location::Type CodeInstaller::get_oop_type(oop value) { 197 Location::Type CodeInstaller::get_oop_type(Handle value) {
177 oop lirKind = Value::lirKind(value); 198 Handle lirKind = Value::lirKind(value);
178 oop platformKind = LIRKind::platformKind(lirKind); 199 Handle platformKind = LIRKind::platformKind(lirKind);
179 assert(LIRKind::referenceMask(lirKind) == 1, "unexpected referenceMask"); 200 assert(LIRKind::referenceMask(lirKind) == 1, "unexpected referenceMask");
180 201
181 if (platformKind == word_kind()) { 202 if (platformKind == word_kind()) {
182 return Location::oop; 203 return Location::oop;
183 } else { 204 } else {
184 return Location::narrowoop; 205 return Location::narrowoop;
185 } 206 }
186 } 207 }
187 208
188 ScopeValue* CodeInstaller::get_scope_value(oop value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second) { 209 ScopeValue* CodeInstaller::get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS) {
189 second = NULL; 210 second = NULL;
190 if (value == Value::ILLEGAL()) { 211 if (value == Value::ILLEGAL()) {
191 assert(type == T_ILLEGAL, "expected legal value"); 212 if (type != T_ILLEGAL) {
213 JVMCI_ERROR_NULL(err_msg("unexpected illegal value, expected %s", basictype_to_str(type)));
214 }
192 return _illegal_value; 215 return _illegal_value;
193 } else if (value->is_a(RegisterValue::klass())) { 216 } else if (value->is_a(RegisterValue::klass())) {
194 oop reg = RegisterValue::reg(value); 217 Handle reg = RegisterValue::reg(value);
195 jint number = code_Register::number(reg); 218 jint number = code_Register::number(reg);
196 VMReg hotspotRegister = get_hotspot_reg(number); 219 VMReg hotspotRegister = get_hotspot_reg(number, CHECK_NULL);
197 if (is_general_purpose_reg(hotspotRegister)) { 220 if (is_general_purpose_reg(hotspotRegister)) {
198 Location::Type locationType; 221 Location::Type locationType;
199 if (type == T_OBJECT) { 222 if (type == T_OBJECT) {
200 locationType = get_oop_type(value); 223 locationType = get_oop_type(value);
201 } else if (type == T_LONG) { 224 } else if (type == T_LONG) {
202 locationType = Location::lng; 225 locationType = Location::lng;
226 } else if (type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN) {
227 locationType = Location::int_in_long;
203 } else { 228 } else {
204 assert(type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN, "unexpected type in cpu register"); 229 JVMCI_ERROR_NULL(err_msg("unexpected type %s in cpu register", basictype_to_str(type)));
205 locationType = Location::int_in_long;
206 } 230 }
207 ScopeValue* value = new LocationValue(Location::new_reg_loc(locationType, hotspotRegister)); 231 ScopeValue* value = new LocationValue(Location::new_reg_loc(locationType, hotspotRegister));
208 if (type == T_LONG) { 232 if (type == T_LONG) {
209 second = value; 233 second = value;
210 } 234 }
211 return value; 235 return value;
212 } else { 236 } else {
213 assert(type == T_FLOAT || type == T_DOUBLE, "only float and double expected in xmm register");
214 Location::Type locationType; 237 Location::Type locationType;
215 if (type == T_FLOAT) { 238 if (type == T_FLOAT) {
216 // this seems weird, but the same value is used in c1_LinearScan 239 // this seems weird, but the same value is used in c1_LinearScan
217 locationType = Location::normal; 240 locationType = Location::normal;
241 } else if (type == T_DOUBLE) {
242 locationType = Location::dbl;
218 } else { 243 } else {
219 locationType = Location::dbl; 244 JVMCI_ERROR_NULL(err_msg("unexpected type %s in floating point register", basictype_to_str(type)));
220 } 245 }
221 ScopeValue* value = new LocationValue(Location::new_reg_loc(locationType, hotspotRegister)); 246 ScopeValue* value = new LocationValue(Location::new_reg_loc(locationType, hotspotRegister));
222 if (type == T_DOUBLE) { 247 if (type == T_DOUBLE) {
223 second = value; 248 second = value;
224 } 249 }
235 locationType = get_oop_type(value); 260 locationType = get_oop_type(value);
236 } else if (type == T_LONG) { 261 } else if (type == T_LONG) {
237 locationType = Location::lng; 262 locationType = Location::lng;
238 } else if (type == T_DOUBLE) { 263 } else if (type == T_DOUBLE) {
239 locationType = Location::dbl; 264 locationType = Location::dbl;
265 } else if (type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN) {
266 locationType = Location::normal;
240 } else { 267 } else {
241 assert(type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN, "unexpected type in stack slot"); 268 JVMCI_ERROR_NULL(err_msg("unexpected type %s in stack slot", basictype_to_str(type)));
242 locationType = Location::normal;
243 } 269 }
244 ScopeValue* value = new LocationValue(Location::new_stk_loc(locationType, offset)); 270 ScopeValue* value = new LocationValue(Location::new_stk_loc(locationType, offset));
245 if (type == T_DOUBLE || type == T_LONG) { 271 if (type == T_DOUBLE || type == T_LONG) {
246 second = value; 272 second = value;
247 } 273 }
250 if (value->is_a(PrimitiveConstant::klass())) { 276 if (value->is_a(PrimitiveConstant::klass())) {
251 if (value->is_a(RawConstant::klass())) { 277 if (value->is_a(RawConstant::klass())) {
252 jlong prim = PrimitiveConstant::primitive(value); 278 jlong prim = PrimitiveConstant::primitive(value);
253 return new ConstantLongValue(prim); 279 return new ConstantLongValue(prim);
254 } else { 280 } else {
255 assert(type == JVMCIRuntime::kindToBasicType(JavaKind::typeChar(PrimitiveConstant::kind(value))), "primitive constant type doesn't match"); 281 BasicType constantType = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(PrimitiveConstant::kind(value)));
282 if (type != constantType) {
283 JVMCI_ERROR_NULL(err_msg("primitive constant type doesn't match, expected %s but got %s", basictype_to_str(type), basictype_to_str(constantType)));
284 }
256 if (type == T_INT || type == T_FLOAT) { 285 if (type == T_INT || type == T_FLOAT) {
257 jint prim = (jint)PrimitiveConstant::primitive(value); 286 jint prim = (jint)PrimitiveConstant::primitive(value);
258 switch (prim) { 287 switch (prim) {
259 case -1: return _int_m1_scope_value; 288 case -1: return _int_m1_scope_value;
260 case 0: return _int_0_scope_value; 289 case 0: return _int_0_scope_value;
261 case 1: return _int_1_scope_value; 290 case 1: return _int_1_scope_value;
262 case 2: return _int_2_scope_value; 291 case 2: return _int_2_scope_value;
263 default: return new ConstantIntValue(prim); 292 default: return new ConstantIntValue(prim);
264 } 293 }
265 } else { 294 } else if (type == T_LONG || type == T_DOUBLE) {
266 assert(type == T_LONG || type == T_DOUBLE, "unexpected primitive constant type");
267 jlong prim = PrimitiveConstant::primitive(value); 295 jlong prim = PrimitiveConstant::primitive(value);
268 second = _int_1_scope_value; 296 second = _int_1_scope_value;
269 return new ConstantLongValue(prim); 297 return new ConstantLongValue(prim);
298 } else {
299 JVMCI_ERROR_NULL(err_msg("unexpected primitive constant type %s", basictype_to_str(type)));
270 } 300 }
271 } 301 }
272 } else { 302 } else if (value->is_a(NullConstant::klass()) || value->is_a(HotSpotCompressedNullConstant::klass())) {
273 assert(type == T_OBJECT, "unexpected object constant"); 303 if (type == T_OBJECT) {
274 if (value->is_a(NullConstant::klass()) || value->is_a(HotSpotCompressedNullConstant::klass())) {
275 return _oop_null_scope_value; 304 return _oop_null_scope_value;
276 } else { 305 } else {
277 assert(value->is_a(HotSpotObjectConstantImpl::klass()), "unexpected constant type"); 306 JVMCI_ERROR_NULL(err_msg("unexpected null constant, expected %s", basictype_to_str(type)));
307 }
308 } else if (value->is_a(HotSpotObjectConstantImpl::klass())) {
309 if (type == T_OBJECT) {
278 oop obj = HotSpotObjectConstantImpl::object(value); 310 oop obj = HotSpotObjectConstantImpl::object(value);
279 assert(obj != NULL, "null value must be in NullConstant"); 311 if (obj == NULL) {
312 JVMCI_ERROR_NULL("null value must be in NullConstant");
313 }
280 return new ConstantOopWriteValue(JNIHandles::make_local(obj)); 314 return new ConstantOopWriteValue(JNIHandles::make_local(obj));
315 } else {
316 JVMCI_ERROR_NULL(err_msg("unexpected object constant, expected %s", basictype_to_str(type)));
281 } 317 }
282 } 318 }
283 } else if (value->is_a(VirtualObject::klass())) { 319 } else if (value->is_a(VirtualObject::klass())) {
284 assert(type == T_OBJECT, "unexpected virtual object"); 320 if (type == T_OBJECT) {
285 int id = VirtualObject::id(value); 321 int id = VirtualObject::id(value);
286 ScopeValue* object = objects->at(id); 322 if (0 <= id && id < objects->length()) {
287 assert(object != NULL, "missing value"); 323 ScopeValue* object = objects->at(id);
288 return object; 324 if (object != NULL) {
289 } else { 325 return object;
290 value->klass()->print(); 326 }
291 value->print(); 327 }
292 } 328 JVMCI_ERROR_NULL(err_msg("unknown virtual object id %d", id));
293 ShouldNotReachHere(); 329 } else {
294 return NULL; 330 JVMCI_ERROR_NULL(err_msg("unexpected virtual object, expected %s", basictype_to_str(type)));
295 } 331 }
296 332 }
297 void CodeInstaller::record_object_value(ObjectValue* sv, oop value, GrowableArray<ScopeValue*>* objects) { 333
298 oop type = VirtualObject::type(value); 334 JVMCI_ERROR_NULL(err_msg("unexpected value in scope: %s", value->klass()->signature_name()))
335 }
336
337 void CodeInstaller::record_object_value(ObjectValue* sv, Handle value, GrowableArray<ScopeValue*>* objects, TRAPS) {
338 Handle type = VirtualObject::type(value);
299 int id = VirtualObject::id(value); 339 int id = VirtualObject::id(value);
300 oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type); 340 oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type);
301 Klass* klass = java_lang_Class::as_Klass(javaMirror); 341 Klass* klass = java_lang_Class::as_Klass(javaMirror);
302 bool isLongArray = klass == Universe::longArrayKlassObj(); 342 bool isLongArray = klass == Universe::longArrayKlassObj();
303 343
304 objArrayOop values = VirtualObject::values(value); 344 objArrayHandle values = VirtualObject::values(value);
305 objArrayOop slotKinds = VirtualObject::slotKinds(value); 345 objArrayHandle slotKinds = VirtualObject::slotKinds(value);
306 for (jint i = 0; i < values->length(); i++) { 346 for (jint i = 0; i < values->length(); i++) {
307 ScopeValue* cur_second = NULL; 347 ScopeValue* cur_second = NULL;
308 oop object = values->obj_at(i); 348 Handle object = values->obj_at(i);
309 oop kind = slotKinds->obj_at(i); 349 BasicType type = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(slotKinds->obj_at(i)));
310 BasicType type = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(kind)); 350 ScopeValue* value = get_scope_value(object, type, objects, cur_second, CHECK);
311 ScopeValue* value = get_scope_value(object, type, objects, cur_second);
312 351
313 if (isLongArray && cur_second == NULL) { 352 if (isLongArray && cur_second == NULL) {
314 // we're trying to put ints into a long array... this isn't really valid, but it's used for some optimizations. 353 // we're trying to put ints into a long array... this isn't really valid, but it's used for some optimizations.
315 // add an int 0 constant 354 // add an int 0 constant
316 cur_second = _int_0_scope_value; 355 cur_second = _int_0_scope_value;
322 assert(value != NULL, "missing value"); 361 assert(value != NULL, "missing value");
323 sv->field_values()->append(value); 362 sv->field_values()->append(value);
324 } 363 }
325 } 364 }
326 365
327 MonitorValue* CodeInstaller::get_monitor_value(oop value, GrowableArray<ScopeValue*>* objects) { 366 MonitorValue* CodeInstaller::get_monitor_value(Handle value, GrowableArray<ScopeValue*>* objects, TRAPS) {
328 guarantee(value->is_a(StackLockValue::klass()), "Monitors must be of type StackLockValue"); 367 if (!value->is_a(StackLockValue::klass())) {
368 JVMCI_ERROR_NULL(err_msg("Monitors must be of type StackLockValue, got %s", value->klass()->signature_name()));
369 }
329 370
330 ScopeValue* second = NULL; 371 ScopeValue* second = NULL;
331 ScopeValue* owner_value = get_scope_value(StackLockValue::owner(value), T_OBJECT, objects, second); 372 ScopeValue* owner_value = get_scope_value(StackLockValue::owner(value), T_OBJECT, objects, second, CHECK_NULL);
332 assert(second == NULL, "monitor cannot occupy two stack slots"); 373 assert(second == NULL, "monitor cannot occupy two stack slots");
333 374
334 ScopeValue* lock_data_value = get_scope_value(StackLockValue::slot(value), T_LONG, objects, second); 375 ScopeValue* lock_data_value = get_scope_value(StackLockValue::slot(value), T_LONG, objects, second, CHECK_NULL);
335 assert(second == lock_data_value, "monitor is LONG value that occupies two stack slots"); 376 assert(second == lock_data_value, "monitor is LONG value that occupies two stack slots");
336 assert(lock_data_value->is_location(), "invalid monitor location"); 377 assert(lock_data_value->is_location(), "invalid monitor location");
337 Location lock_data_loc = ((LocationValue*)lock_data_value)->location(); 378 Location lock_data_loc = ((LocationValue*)lock_data_value)->location();
338 379
339 bool eliminated = false; 380 bool eliminated = false;
342 } 383 }
343 384
344 return new MonitorValue(owner_value, lock_data_loc, eliminated); 385 return new MonitorValue(owner_value, lock_data_loc, eliminated);
345 } 386 }
346 387
347 void CodeInstaller::initialize_dependencies(oop compiled_code) { 388 void CodeInstaller::initialize_dependencies(oop compiled_code, TRAPS) {
348 JavaThread* thread = JavaThread::current(); 389 JavaThread* thread = JavaThread::current();
349 CompilerThread* compilerThread = thread->is_Compiler_thread() ? thread->as_CompilerThread() : NULL; 390 CompilerThread* compilerThread = thread->is_Compiler_thread() ? thread->as_CompilerThread() : NULL;
350 _oop_recorder = new OopRecorder(&_arena, true); 391 _oop_recorder = new OopRecorder(&_arena, true);
351 _dependencies = new Dependencies(&_arena, _oop_recorder, compilerThread != NULL ? compilerThread->log() : NULL); 392 _dependencies = new Dependencies(&_arena, _oop_recorder, compilerThread != NULL ? compilerThread->log() : NULL);
352 objArrayHandle assumptions = HotSpotCompiledCode::assumptions(compiled_code); 393 objArrayHandle assumptions = HotSpotCompiledCode::assumptions(compiled_code);
364 } else if (assumption->klass() == Assumptions_ConcreteMethod::klass()) { 405 } else if (assumption->klass() == Assumptions_ConcreteMethod::klass()) {
365 assumption_ConcreteMethod(assumption); 406 assumption_ConcreteMethod(assumption);
366 } else if (assumption->klass() == Assumptions_CallSiteTargetValue::klass()) { 407 } else if (assumption->klass() == Assumptions_CallSiteTargetValue::klass()) {
367 assumption_CallSiteTargetValue(assumption); 408 assumption_CallSiteTargetValue(assumption);
368 } else { 409 } else {
369 assumption->print(); 410 JVMCI_ERROR(err_msg("unexpected Assumption subclass %s", assumption->klass()->signature_name()));
370 fatal("unexpected Assumption subclass");
371 } 411 }
372 } 412 }
373 } 413 }
374 } 414 }
375 if (JvmtiExport::can_hotswap_or_post_breakpoint()) { 415 if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
384 } 424 }
385 } 425 }
386 } 426 }
387 427
388 // constructor used to create a method 428 // constructor used to create a method
389 JVMCIEnv::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler, Handle target, Handle& compiled_code, CodeBlob*& cb, Handle installed_code, Handle speculation_log) { 429 JVMCIEnv::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler, Handle target, Handle& compiled_code, CodeBlob*& cb, Handle installed_code, Handle speculation_log, TRAPS) {
390 CodeBuffer buffer("JVMCI Compiler CodeBuffer"); 430 CodeBuffer buffer("JVMCI Compiler CodeBuffer");
391 jobject compiled_code_obj = JNIHandles::make_local(compiled_code()); 431 jobject compiled_code_obj = JNIHandles::make_local(compiled_code());
392 initialize_dependencies(JNIHandles::resolve(compiled_code_obj)); 432 initialize_dependencies(JNIHandles::resolve(compiled_code_obj), CHECK_OK);
393 433
394 // Get instructions and constants CodeSections early because we need it. 434 // Get instructions and constants CodeSections early because we need it.
395 _instructions = buffer.insts(); 435 _instructions = buffer.insts();
396 _constants = buffer.consts(); 436 _constants = buffer.consts();
397 437
398 initialize_fields(target(), JNIHandles::resolve(compiled_code_obj)); 438 initialize_fields(target(), JNIHandles::resolve(compiled_code_obj), CHECK_OK);
399 JVMCIEnv::CodeInstallResult result = initialize_buffer(buffer); 439 JVMCIEnv::CodeInstallResult result = initialize_buffer(buffer, CHECK_OK);
400 if (result != JVMCIEnv::ok) { 440 if (result != JVMCIEnv::ok) {
401 return result; 441 return result;
402 } 442 }
403 process_exception_handlers(); 443 process_exception_handlers();
404 444
437 guarantee((cb->code_begin() - cb->content_begin()) >= _constants_size, err_msg("%d < %d", (int)(cb->code_begin() - cb->content_begin()), _constants_size)); 477 guarantee((cb->code_begin() - cb->content_begin()) >= _constants_size, err_msg("%d < %d", (int)(cb->code_begin() - cb->content_begin()), _constants_size));
438 } 478 }
439 return result; 479 return result;
440 } 480 }
441 481
442 void CodeInstaller::initialize_fields(oop target, oop compiled_code) { 482 void CodeInstaller::initialize_fields(oop target, oop compiled_code, TRAPS) {
443 if (compiled_code->is_a(HotSpotCompiledNmethod::klass())) { 483 if (compiled_code->is_a(HotSpotCompiledNmethod::klass())) {
444 Handle hotspotJavaMethod = HotSpotCompiledNmethod::method(compiled_code); 484 Handle hotspotJavaMethod = HotSpotCompiledNmethod::method(compiled_code);
445 methodHandle method = getMethodFromHotSpotMethod(hotspotJavaMethod()); 485 methodHandle method = getMethodFromHotSpotMethod(hotspotJavaMethod());
446 _parameter_count = method->size_of_parameters(); 486 _parameter_count = method->size_of_parameters();
447 TRACE_jvmci_2("installing code for %s", method->name_and_sig_as_C_string()); 487 TRACE_jvmci_2("installing code for %s", method->name_and_sig_as_C_string());
458 _total_frame_size = HotSpotCompiledCode::totalFrameSize(compiled_code); 498 _total_frame_size = HotSpotCompiledCode::totalFrameSize(compiled_code);
459 _custom_stack_area_offset = HotSpotCompiledCode::customStackAreaOffset(compiled_code); 499 _custom_stack_area_offset = HotSpotCompiledCode::customStackAreaOffset(compiled_code);
460 500
461 // Pre-calculate the constants section size. This is required for PC-relative addressing. 501 // Pre-calculate the constants section size. This is required for PC-relative addressing.
462 _data_section_handle = JNIHandles::make_local(HotSpotCompiledCode::dataSection(compiled_code)); 502 _data_section_handle = JNIHandles::make_local(HotSpotCompiledCode::dataSection(compiled_code));
463 guarantee(HotSpotCompiledCode::dataSectionAlignment(compiled_code) <= _constants->alignment(), "Alignment inside constants section is restricted by alignment of section begin"); 503 if ((_constants->alignment() % HotSpotCompiledCode::dataSectionAlignment(compiled_code)) != 0) {
504 JVMCI_ERROR(err_msg("invalid data section alignment: %d", HotSpotCompiledCode::dataSectionAlignment(compiled_code)));
505 }
464 _constants_size = data_section()->length(); 506 _constants_size = data_section()->length();
465 507
466 _data_section_patches_handle = JNIHandles::make_local(HotSpotCompiledCode::dataSectionPatches(compiled_code)); 508 _data_section_patches_handle = JNIHandles::make_local(HotSpotCompiledCode::dataSectionPatches(compiled_code));
467 509
468 #ifndef PRODUCT 510 #ifndef PRODUCT
475 517
476 oop arch = TargetDescription::arch(target); 518 oop arch = TargetDescription::arch(target);
477 _word_kind_handle = JNIHandles::make_local(Architecture::wordKind(arch)); 519 _word_kind_handle = JNIHandles::make_local(Architecture::wordKind(arch));
478 } 520 }
479 521
480 int CodeInstaller::estimate_stubs_size() { 522 int CodeInstaller::estimate_stubs_size(TRAPS) {
481 // Estimate the number of static call stubs that might be emitted. 523 // Estimate the number of static call stubs that might be emitted.
482 int static_call_stubs = 0; 524 int static_call_stubs = 0;
483 objArrayOop sites = this->sites(); 525 objArrayOop sites = this->sites();
484 for (int i = 0; i < sites->length(); i++) { 526 for (int i = 0; i < sites->length(); i++) {
485 oop site = sites->obj_at(i); 527 oop site = sites->obj_at(i);
486 if (site->is_a(CompilationResult_Mark::klass())) { 528 if (site->is_a(CompilationResult_Mark::klass())) {
487 oop id_obj = CompilationResult_Mark::id(site); 529 oop id_obj = CompilationResult_Mark::id(site);
488 if (id_obj != NULL) { 530 if (id_obj != NULL) {
489 assert(java_lang_boxing_object::is_instance(id_obj, T_INT), "Integer id expected"); 531 if (!java_lang_boxing_object::is_instance(id_obj, T_INT)) {
532 JVMCI_ERROR_0(err_msg("expected Integer id, got %s", id_obj->klass()->signature_name()));
533 }
490 jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT)); 534 jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT));
491 if (id == INVOKESTATIC || id == INVOKESPECIAL) { 535 if (id == INVOKESTATIC || id == INVOKESPECIAL) {
492 static_call_stubs++; 536 static_call_stubs++;
493 } 537 }
494 } 538 }
496 } 540 }
497 return static_call_stubs * CompiledStaticCall::to_interp_stub_size(); 541 return static_call_stubs * CompiledStaticCall::to_interp_stub_size();
498 } 542 }
499 543
500 // perform data and call relocation on the CodeBuffer 544 // perform data and call relocation on the CodeBuffer
501 JVMCIEnv::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer) { 545 JVMCIEnv::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer, TRAPS) {
502 HandleMark hm; 546 HandleMark hm;
503 objArrayHandle sites = this->sites(); 547 objArrayHandle sites = this->sites();
504 int locs_buffer_size = sites->length() * (relocInfo::length_limit + sizeof(relocInfo)); 548 int locs_buffer_size = sites->length() * (relocInfo::length_limit + sizeof(relocInfo));
505 549
506 // Allocate enough space in the stub section for the static call 550 // Allocate enough space in the stub section for the static call
507 // stubs. Stubs have extra relocs but they are managed by the stub 551 // stubs. Stubs have extra relocs but they are managed by the stub
508 // section itself so they don't need to be accounted for in the 552 // section itself so they don't need to be accounted for in the
509 // locs_buffer above. 553 // locs_buffer above.
510 int stubs_size = estimate_stubs_size(); 554 int stubs_size = estimate_stubs_size(CHECK_OK);
511 int total_size = round_to(_code_size, buffer.insts()->alignment()) + round_to(_constants_size, buffer.consts()->alignment()) + round_to(stubs_size, buffer.stubs()->alignment()); 555 int total_size = round_to(_code_size, buffer.insts()->alignment()) + round_to(_constants_size, buffer.consts()->alignment()) + round_to(stubs_size, buffer.stubs()->alignment());
512 556
513 if (total_size > JVMCINMethodSizeLimit) { 557 if (total_size > JVMCINMethodSizeLimit) {
514 return JVMCIEnv::code_too_large; 558 return JVMCIEnv::code_too_large;
515 } 559 }
538 _instructions->set_end(end_pc); 582 _instructions->set_end(end_pc);
539 583
540 for (int i = 0; i < data_section_patches()->length(); i++) { 584 for (int i = 0; i < data_section_patches()->length(); i++) {
541 Handle patch = data_section_patches()->obj_at(i); 585 Handle patch = data_section_patches()->obj_at(i);
542 Handle reference = CompilationResult_DataPatch::reference(patch); 586 Handle reference = CompilationResult_DataPatch::reference(patch);
543 assert(reference->is_a(CompilationResult_ConstantReference::klass()), err_msg("patch in data section must be a ConstantReference")); 587 if (!reference->is_a(CompilationResult_ConstantReference::klass())) {
588 JVMCI_ERROR_OK(err_msg("invalid patch in data section: %s", reference->klass()->signature_name()));
589 }
544 Handle constant = CompilationResult_ConstantReference::constant(reference); 590 Handle constant = CompilationResult_ConstantReference::constant(reference);
545 address dest = _constants->start() + CompilationResult_Site::pcOffset(patch); 591 address dest = _constants->start() + CompilationResult_Site::pcOffset(patch);
546 if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) { 592 if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
547 if (HotSpotMetaspaceConstantImpl::compressed(constant)) { 593 if (HotSpotMetaspaceConstantImpl::compressed(constant)) {
548 #ifdef _LP64 594 #ifdef _LP64
549 *((narrowKlass*) dest) = record_narrow_metadata_reference(constant); 595 *((narrowKlass*) dest) = record_narrow_metadata_reference(constant, CHECK_OK);
550 #else 596 #else
551 fatal("unexpected compressed Klass* in 32-bit mode"); 597 JVMCI_ERROR_OK("unexpected compressed Klass* in 32-bit mode");
552 #endif 598 #endif
553 } else { 599 } else {
554 *((Metadata**) dest) = record_metadata_reference(constant); 600 *((Metadata**) dest) = record_metadata_reference(constant, CHECK_OK);
555 } 601 }
556 } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) { 602 } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
557 Handle obj = HotSpotObjectConstantImpl::object(constant); 603 Handle obj = HotSpotObjectConstantImpl::object(constant);
558 jobject value = JNIHandles::make_local(obj()); 604 jobject value = JNIHandles::make_local(obj());
559 int oop_index = _oop_recorder->find_index(value); 605 int oop_index = _oop_recorder->find_index(value);
560 606
561 if (HotSpotObjectConstantImpl::compressed(constant)) { 607 if (HotSpotObjectConstantImpl::compressed(constant)) {
562 #ifdef _LP64 608 #ifdef _LP64
563 _constants->relocate(dest, oop_Relocation::spec(oop_index), relocInfo::narrow_oop_in_const); 609 _constants->relocate(dest, oop_Relocation::spec(oop_index), relocInfo::narrow_oop_in_const);
564 #else 610 #else
565 fatal("unexpected compressed oop in 32-bit mode"); 611 JVMCI_ERROR_OK("unexpected compressed oop in 32-bit mode");
566 #endif 612 #endif
567 } else { 613 } else {
568 _constants->relocate(dest, oop_Relocation::spec(oop_index)); 614 _constants->relocate(dest, oop_Relocation::spec(oop_index));
569 } 615 }
570 } else { 616 } else {
571 ShouldNotReachHere(); 617 JVMCI_ERROR_OK(err_msg("invalid constant in data section: %s", constant->klass()->signature_name()));
572 } 618 }
573 } 619 }
574 jint last_pc_offset = -1; 620 jint last_pc_offset = -1;
575 for (int i = 0; i < sites->length(); i++) { 621 for (int i = 0; i < sites->length(); i++) {
576 { 622 Handle site = sites->obj_at(i);
577 No_Safepoint_Verifier no_safepoint; 623 jint pc_offset = CompilationResult_Site::pcOffset(site);
578 oop site = sites->obj_at(i); 624
579 jint pc_offset = CompilationResult_Site::pcOffset(site); 625 if (site->is_a(CompilationResult_Call::klass())) {
580 626 TRACE_jvmci_4("call at %i", pc_offset);
581 if (site->is_a(CompilationResult_Call::klass())) { 627 site_Call(buffer, pc_offset, site, CHECK_OK);
582 TRACE_jvmci_4("call at %i", pc_offset); 628 } else if (site->is_a(CompilationResult_Infopoint::klass())) {
583 site_Call(buffer, pc_offset, site); 629 // three reasons for infopoints denote actual safepoints
584 } else if (site->is_a(CompilationResult_Infopoint::klass())) { 630 oop reason = CompilationResult_Infopoint::reason(site);
585 // three reasons for infopoints denote actual safepoints 631 if (InfopointReason::SAFEPOINT() == reason || InfopointReason::CALL() == reason || InfopointReason::IMPLICIT_EXCEPTION() == reason) {
586 oop reason = CompilationResult_Infopoint::reason(site); 632 TRACE_jvmci_4("safepoint at %i", pc_offset);
587 if (InfopointReason::SAFEPOINT() == reason || InfopointReason::CALL() == reason || InfopointReason::IMPLICIT_EXCEPTION() == reason) { 633 site_Safepoint(buffer, pc_offset, site, CHECK_OK);
588 TRACE_jvmci_4("safepoint at %i", pc_offset); 634 } else if (InfopointReason::METHOD_START() == reason || InfopointReason::METHOD_END() == reason || InfopointReason::LINE_NUMBER() == reason) {
589 site_Safepoint(buffer, pc_offset, site); 635 site_Infopoint(buffer, pc_offset, site, CHECK_OK);
590 } else { 636 } else {
591 // if the infopoint is not an actual safepoint, it must have one of the other reasons 637 JVMCI_ERROR_OK(err_msg("unknown infopoint reason at %i", pc_offset));
592 // (safeguard against new safepoint types that require handling above) 638 }
593 assert(InfopointReason::METHOD_START() == reason || InfopointReason::METHOD_END() == reason || InfopointReason::LINE_NUMBER() == reason, ""); 639 } else if (site->is_a(CompilationResult_DataPatch::klass())) {
594 site_Infopoint(buffer, pc_offset, site); 640 TRACE_jvmci_4("datapatch at %i", pc_offset);
595 } 641 site_DataPatch(buffer, pc_offset, site, CHECK_OK);
596 } else if (site->is_a(CompilationResult_DataPatch::klass())) { 642 } else if (site->is_a(CompilationResult_Mark::klass())) {
597 TRACE_jvmci_4("datapatch at %i", pc_offset); 643 TRACE_jvmci_4("mark at %i", pc_offset);
598 site_DataPatch(buffer, pc_offset, site); 644 site_Mark(buffer, pc_offset, site, CHECK_OK);
599 } else if (site->is_a(CompilationResult_Mark::klass())) { 645 } else {
600 TRACE_jvmci_4("mark at %i", pc_offset); 646 JVMCI_ERROR_OK(err_msg("unexpected site subclass: %s", site->klass()->signature_name()));
601 site_Mark(buffer, pc_offset, site); 647 }
602 } else { 648 last_pc_offset = pc_offset;
603 fatal("unexpected Site subclass"); 649
604 }
605 last_pc_offset = pc_offset;
606 }
607 if (CodeInstallSafepointChecks && SafepointSynchronize::do_call_back()) { 650 if (CodeInstallSafepointChecks && SafepointSynchronize::do_call_back()) {
608 // this is a hacky way to force a safepoint check but nothing else was jumping out at me. 651 // this is a hacky way to force a safepoint check but nothing else was jumping out at me.
609 ThreadToNativeFromVM ttnfv(JavaThread::current()); 652 ThreadToNativeFromVM ttnfv(JavaThread::current());
610 } 653 }
611 } 654 }
612 655
613 #ifndef PRODUCT 656 #ifndef PRODUCT
614 if (comments() != NULL) { 657 if (comments() != NULL) {
615 No_Safepoint_Verifier no_safepoint;
616 for (int i = 0; i < comments()->length(); i++) { 658 for (int i = 0; i < comments()->length(); i++) {
617 oop comment = comments()->obj_at(i); 659 oop comment = comments()->obj_at(i);
618 assert(comment->is_a(HotSpotCompiledCode_Comment::klass()), "cce"); 660 assert(comment->is_a(HotSpotCompiledCode_Comment::klass()), "cce");
619 jint offset = HotSpotCompiledCode_Comment::pcOffset(comment); 661 jint offset = HotSpotCompiledCode_Comment::pcOffset(comment);
620 char* text = java_lang_String::as_utf8_string(HotSpotCompiledCode_Comment::text(comment)); 662 char* text = java_lang_String::as_utf8_string(HotSpotCompiledCode_Comment::text(comment));
696 return true; 738 return true;
697 } 739 }
698 return true; 740 return true;
699 } 741 }
700 742
701 GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(oop debug_info) { 743 GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(Handle debug_info, TRAPS) {
702 objArrayOop virtualObjects = DebugInfo::virtualObjectMapping(debug_info); 744 objArrayHandle virtualObjects = DebugInfo::virtualObjectMapping(debug_info);
703 if (virtualObjects == NULL) { 745 if (virtualObjects.is_null()) {
704 return NULL; 746 return NULL;
705 } 747 }
706 GrowableArray<ScopeValue*>* objects = new GrowableArray<ScopeValue*>(virtualObjects->length(), virtualObjects->length(), NULL); 748 GrowableArray<ScopeValue*>* objects = new GrowableArray<ScopeValue*>(virtualObjects->length(), virtualObjects->length(), NULL);
707 // Create the unique ObjectValues 749 // Create the unique ObjectValues
708 for (int i = 0; i < virtualObjects->length(); i++) { 750 for (int i = 0; i < virtualObjects->length(); i++) {
709 oop value = virtualObjects->obj_at(i); 751 Handle value = virtualObjects->obj_at(i);
710 int id = VirtualObject::id(value); 752 int id = VirtualObject::id(value);
711 oop type = VirtualObject::type(value); 753 Handle type = VirtualObject::type(value);
712 oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type); 754 oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type);
713 ObjectValue* sv = new ObjectValue(id, new ConstantOopWriteValue(JNIHandles::make_local(Thread::current(), javaMirror))); 755 ObjectValue* sv = new ObjectValue(id, new ConstantOopWriteValue(JNIHandles::make_local(Thread::current(), javaMirror)));
714 assert(objects->at(id) == NULL, "once"); 756 if (id < 0 || id >= objects->length()) {
757 JVMCI_ERROR_NULL(err_msg("virtual object id %d out of bounds", id));
758 }
759 if (objects->at(id) != NULL) {
760 JVMCI_ERROR_NULL(err_msg("duplicate virtual object id %d", id));
761 }
715 objects->at_put(id, sv); 762 objects->at_put(id, sv);
716 } 763 }
717 // All the values which could be referenced by the VirtualObjects 764 // All the values which could be referenced by the VirtualObjects
718 // exist, so now describe all the VirtualObjects themselves. 765 // exist, so now describe all the VirtualObjects themselves.
719 for (int i = 0; i < virtualObjects->length(); i++) { 766 for (int i = 0; i < virtualObjects->length(); i++) {
720 oop value = virtualObjects->obj_at(i); 767 Handle value = virtualObjects->obj_at(i);
721 int id = VirtualObject::id(value); 768 int id = VirtualObject::id(value);
722 record_object_value(objects->at(id)->as_ObjectValue(), value, objects); 769 record_object_value(objects->at(id)->as_ObjectValue(), value, objects, CHECK_NULL);
723 } 770 }
724 _debug_recorder->dump_object_pool(objects); 771 _debug_recorder->dump_object_pool(objects);
725 return objects; 772 return objects;
726 } 773 }
727 774
728 void CodeInstaller::record_scope(jint pc_offset, oop debug_info) { 775 void CodeInstaller::record_scope(jint pc_offset, Handle debug_info, TRAPS) {
729 oop position = DebugInfo::bytecodePosition(debug_info); 776 Handle position = DebugInfo::bytecodePosition(debug_info);
730 if (position == NULL) { 777 if (position.is_null()) {
731 // Stubs do not record scope info, just oop maps 778 // Stubs do not record scope info, just oop maps
732 return; 779 return;
733 } 780 }
734 781
735 GrowableArray<ScopeValue*>* objectMapping = record_virtual_objects(debug_info); 782 GrowableArray<ScopeValue*>* objectMapping = record_virtual_objects(debug_info, CHECK);
736 record_scope(pc_offset, position, objectMapping); 783 record_scope(pc_offset, position, objectMapping, CHECK);
737 } 784 }
738 785
739 void CodeInstaller::record_scope(jint pc_offset, oop position, GrowableArray<ScopeValue*>* objects) { 786 void CodeInstaller::record_scope(jint pc_offset, Handle position, GrowableArray<ScopeValue*>* objects, TRAPS) {
740 oop frame = NULL; 787 Handle frame;
741 if (position->is_a(BytecodeFrame::klass())) { 788 if (position->is_a(BytecodeFrame::klass())) {
742 frame = position; 789 frame = position;
743 } 790 }
744 oop caller_frame = BytecodePosition::caller(position); 791 Handle caller_frame = BytecodePosition::caller(position);
745 if (caller_frame != NULL) { 792 if (caller_frame.not_null()) {
746 record_scope(pc_offset, caller_frame, objects); 793 record_scope(pc_offset, caller_frame, objects, CHECK);
747 } 794 }
748 795
749 oop hotspot_method = BytecodePosition::method(position); 796 Handle hotspot_method = BytecodePosition::method(position);
750 Method* method = getMethodFromHotSpotMethod(hotspot_method); 797 Method* method = getMethodFromHotSpotMethod(hotspot_method());
751 jint bci = BytecodePosition::bci(position); 798 jint bci = BytecodePosition::bci(position);
752 if (bci == BytecodeFrame::BEFORE_BCI()) { 799 if (bci == BytecodeFrame::BEFORE_BCI()) {
753 bci = SynchronizationEntryBCI; 800 bci = SynchronizationEntryBCI;
754 } 801 }
755 802
756 TRACE_jvmci_2("Recording scope pc_offset=%d bci=%d method=%s", pc_offset, bci, method->name_and_sig_as_C_string()); 803 TRACE_jvmci_2("Recording scope pc_offset=%d bci=%d method=%s", pc_offset, bci, method->name_and_sig_as_C_string());
757 804
758 bool reexecute = false; 805 bool reexecute = false;
759 if (frame != NULL) { 806 if (frame.not_null()) {
760 if (bci == SynchronizationEntryBCI){ 807 if (bci == SynchronizationEntryBCI){
761 reexecute = false; 808 reexecute = false;
762 } else { 809 } else {
763 Bytecodes::Code code = Bytecodes::java_code_at(method, method->bcp_from(bci)); 810 Bytecodes::Code code = Bytecodes::java_code_at(method, method->bcp_from(bci));
764 reexecute = bytecode_should_reexecute(code); 811 reexecute = bytecode_should_reexecute(code);
765 if (frame != NULL) { 812 if (frame.not_null()) {
766 reexecute = (BytecodeFrame::duringCall(frame) == JNI_FALSE); 813 reexecute = (BytecodeFrame::duringCall(frame) == JNI_FALSE);
767 } 814 }
768 } 815 }
769 } 816 }
770 817
771 DebugToken* locals_token = NULL; 818 DebugToken* locals_token = NULL;
772 DebugToken* expressions_token = NULL; 819 DebugToken* expressions_token = NULL;
773 DebugToken* monitors_token = NULL; 820 DebugToken* monitors_token = NULL;
774 bool throw_exception = false; 821 bool throw_exception = false;
775 822
776 if (frame != NULL) { 823 if (frame.not_null()) {
777 jint local_count = BytecodeFrame::numLocals(frame); 824 jint local_count = BytecodeFrame::numLocals(frame);
778 jint expression_count = BytecodeFrame::numStack(frame); 825 jint expression_count = BytecodeFrame::numStack(frame);
779 jint monitor_count = BytecodeFrame::numLocks(frame); 826 jint monitor_count = BytecodeFrame::numLocks(frame);
780 objArrayOop values = BytecodeFrame::values(frame); 827 objArrayHandle values = BytecodeFrame::values(frame);
781 objArrayOop slotKinds = BytecodeFrame::slotKinds(frame); 828 objArrayHandle slotKinds = BytecodeFrame::slotKinds(frame);
782 829
783 assert(local_count + expression_count + monitor_count == values->length(), "unexpected values length"); 830 if (local_count + expression_count + monitor_count != values->length()) {
784 assert(local_count + expression_count == slotKinds->length(), "unexpected slotKinds length"); 831 JVMCI_ERROR(err_msg("unexpected values length %d in scope (%d locals, %d expressions, %d monitors)", values->length(), local_count, expression_count, monitor_count));
832 }
833 if (local_count + expression_count != slotKinds->length()) {
834 JVMCI_ERROR(err_msg("unexpected slotKinds length %d in scope (%d locals, %d expressions)", slotKinds->length(), local_count, expression_count));
835 }
785 836
786 GrowableArray<ScopeValue*>* locals = local_count > 0 ? new GrowableArray<ScopeValue*> (local_count) : NULL; 837 GrowableArray<ScopeValue*>* locals = local_count > 0 ? new GrowableArray<ScopeValue*> (local_count) : NULL;
787 GrowableArray<ScopeValue*>* expressions = expression_count > 0 ? new GrowableArray<ScopeValue*> (expression_count) : NULL; 838 GrowableArray<ScopeValue*>* expressions = expression_count > 0 ? new GrowableArray<ScopeValue*> (expression_count) : NULL;
788 GrowableArray<MonitorValue*>* monitors = monitor_count > 0 ? new GrowableArray<MonitorValue*> (monitor_count) : NULL; 839 GrowableArray<MonitorValue*>* monitors = monitor_count > 0 ? new GrowableArray<MonitorValue*> (monitor_count) : NULL;
789 840
790 TRACE_jvmci_2("Scope at bci %d with %d values", bci, values->length()); 841 TRACE_jvmci_2("Scope at bci %d with %d values", bci, values->length());
791 TRACE_jvmci_2("%d locals %d expressions, %d monitors", local_count, expression_count, monitor_count); 842 TRACE_jvmci_2("%d locals %d expressions, %d monitors", local_count, expression_count, monitor_count);
792 843
793 for (jint i = 0; i < values->length(); i++) { 844 for (jint i = 0; i < values->length(); i++) {
794 ScopeValue* second = NULL; 845 ScopeValue* second = NULL;
795 oop value = values->obj_at(i); 846 Handle value = values->obj_at(i);
796 if (i < local_count) { 847 if (i < local_count) {
797 oop kind = slotKinds->obj_at(i); 848 BasicType type = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(slotKinds->obj_at(i)));
798 BasicType type = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(kind)); 849 ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
799 ScopeValue* first = get_scope_value(value, type, objects, second);
800 if (second != NULL) { 850 if (second != NULL) {
801 locals->append(second); 851 locals->append(second);
802 } 852 }
803 locals->append(first); 853 locals->append(first);
804 } else if (i < local_count + expression_count) { 854 } else if (i < local_count + expression_count) {
805 oop kind = slotKinds->obj_at(i); 855 BasicType type = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(slotKinds->obj_at(i)));
806 BasicType type = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(kind)); 856 ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
807 ScopeValue* first = get_scope_value(value, type, objects, second);
808 if (second != NULL) { 857 if (second != NULL) {
809 expressions->append(second); 858 expressions->append(second);
810 } 859 }
811 expressions->append(first); 860 expressions->append(first);
812 } else { 861 } else {
813 monitors->append(get_monitor_value(value, objects)); 862 MonitorValue *monitor = get_monitor_value(value, objects, CHECK);
863 monitors->append(monitor);
814 } 864 }
815 if (second != NULL) { 865 if (second != NULL) {
816 i++; 866 i++;
817 assert(i < values->length(), "double-slot value not followed by Value.ILLEGAL"); 867 if (i >= values->length() || values->obj_at(i) != Value::ILLEGAL()) {
818 assert(values->obj_at(i) == Value::ILLEGAL(), "double-slot value not followed by Value.ILLEGAL"); 868 JVMCI_ERROR("double-slot value not followed by Value.ILLEGAL");
869 }
819 } 870 }
820 } 871 }
821 872
822 locals_token = _debug_recorder->create_scope_values(locals); 873 locals_token = _debug_recorder->create_scope_values(locals);
823 expressions_token = _debug_recorder->create_scope_values(expressions); 874 expressions_token = _debug_recorder->create_scope_values(expressions);
828 879
829 _debug_recorder->describe_scope(pc_offset, method, NULL, bci, reexecute, throw_exception, false, false, 880 _debug_recorder->describe_scope(pc_offset, method, NULL, bci, reexecute, throw_exception, false, false,
830 locals_token, expressions_token, monitors_token); 881 locals_token, expressions_token, monitors_token);
831 } 882 }
832 883
833 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site) { 884 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
834 oop debug_info = CompilationResult_Infopoint::debugInfo(site); 885 Handle debug_info = CompilationResult_Infopoint::debugInfo(site);
835 assert(debug_info != NULL, "debug info expected"); 886 if (debug_info.is_null()) {
887 JVMCI_ERROR(err_msg("debug info expected at safepoint at %i", pc_offset));
888 }
836 889
837 // address instruction = _instructions->start() + pc_offset; 890 // address instruction = _instructions->start() + pc_offset;
838 // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start(); 891 // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start();
839 _debug_recorder->add_safepoint(pc_offset, create_oop_map(debug_info)); 892 OopMap *map = create_oop_map(debug_info, CHECK);
840 record_scope(pc_offset, debug_info); 893 _debug_recorder->add_safepoint(pc_offset, map);
894 record_scope(pc_offset, debug_info, CHECK);
841 _debug_recorder->end_safepoint(pc_offset); 895 _debug_recorder->end_safepoint(pc_offset);
842 } 896 }
843 897
844 void CodeInstaller::site_Infopoint(CodeBuffer& buffer, jint pc_offset, oop site) { 898 void CodeInstaller::site_Infopoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
845 oop debug_info = CompilationResult_Infopoint::debugInfo(site); 899 Handle debug_info = CompilationResult_Infopoint::debugInfo(site);
846 assert(debug_info != NULL, "debug info expected"); 900 if (debug_info.is_null()) {
901 JVMCI_ERROR(err_msg("debug info expected at infopoint at %i", pc_offset));
902 }
847 903
848 _debug_recorder->add_non_safepoint(pc_offset); 904 _debug_recorder->add_non_safepoint(pc_offset);
849 record_scope(pc_offset, debug_info); 905 record_scope(pc_offset, debug_info, CHECK);
850 _debug_recorder->end_non_safepoint(pc_offset); 906 _debug_recorder->end_non_safepoint(pc_offset);
851 } 907 }
852 908
853 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, oop site) { 909 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
854 oop target = CompilationResult_Call::target(site); 910 Handle target = CompilationResult_Call::target(site);
855 InstanceKlass* target_klass = InstanceKlass::cast(target->klass()); 911 InstanceKlass* target_klass = InstanceKlass::cast(target->klass());
856 912
857 oop hotspot_method = NULL; // JavaMethod 913 Handle hotspot_method; // JavaMethod
858 oop foreign_call = NULL; 914 Handle foreign_call;
859 915
860 if (target_klass->is_subclass_of(SystemDictionary::HotSpotForeignCallTarget_klass())) { 916 if (target_klass->is_subclass_of(SystemDictionary::HotSpotForeignCallTarget_klass())) {
861 foreign_call = target; 917 foreign_call = target;
862 } else { 918 } else {
863 hotspot_method = target; 919 hotspot_method = target;
864 } 920 }
865 921
866 oop debug_info = CompilationResult_Call::debugInfo(site); 922 Handle debug_info = CompilationResult_Call::debugInfo(site);
867 923
868 assert(!!hotspot_method ^ !!foreign_call, "Call site needs exactly one type"); 924 assert(hotspot_method.not_null() ^ foreign_call.not_null(), "Call site needs exactly one type");
869 925
870 NativeInstruction* inst = nativeInstruction_at(_instructions->start() + pc_offset); 926 NativeInstruction* inst = nativeInstruction_at(_instructions->start() + pc_offset);
871 jint next_pc_offset = CodeInstaller::pd_next_offset(inst, pc_offset, hotspot_method); 927 jint next_pc_offset = CodeInstaller::pd_next_offset(inst, pc_offset, hotspot_method, CHECK);
872 928
873 if (debug_info != NULL) { 929 if (debug_info.not_null()) {
874 _debug_recorder->add_safepoint(next_pc_offset, create_oop_map(debug_info)); 930 OopMap *map = create_oop_map(debug_info, CHECK);
875 record_scope(next_pc_offset, debug_info); 931 _debug_recorder->add_safepoint(next_pc_offset, map);
876 } 932 record_scope(next_pc_offset, debug_info, CHECK);
877 933 }
878 if (foreign_call != NULL) { 934
935 if (foreign_call.not_null()) {
879 jlong foreign_call_destination = HotSpotForeignCallTarget::address(foreign_call); 936 jlong foreign_call_destination = HotSpotForeignCallTarget::address(foreign_call);
880 CodeInstaller::pd_relocate_ForeignCall(inst, foreign_call_destination); 937 CodeInstaller::pd_relocate_ForeignCall(inst, foreign_call_destination, CHECK);
881 } else { // method != NULL 938 } else { // method != NULL
882 assert(hotspot_method != NULL, "unexpected JavaMethod"); 939 if (debug_info.is_null()) {
883 assert(debug_info != NULL, "debug info expected"); 940 JVMCI_ERROR(err_msg("debug info expected at call at %i", pc_offset));
941 }
884 942
885 TRACE_jvmci_3("method call"); 943 TRACE_jvmci_3("method call");
886 CodeInstaller::pd_relocate_JavaMethod(hotspot_method, pc_offset); 944 CodeInstaller::pd_relocate_JavaMethod(hotspot_method, pc_offset, CHECK);
887 if (_next_call_type == INVOKESTATIC || _next_call_type == INVOKESPECIAL) { 945 if (_next_call_type == INVOKESTATIC || _next_call_type == INVOKESPECIAL) {
888 // Need a static call stub for transitions from compiled to interpreted. 946 // Need a static call stub for transitions from compiled to interpreted.
889 CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset); 947 CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset);
890 } 948 }
891 } 949 }
892 950
893 _next_call_type = INVOKE_INVALID; 951 _next_call_type = INVOKE_INVALID;
894 952
895 if (debug_info != NULL) { 953 if (debug_info.not_null()) {
896 _debug_recorder->end_safepoint(next_pc_offset); 954 _debug_recorder->end_safepoint(next_pc_offset);
897 } 955 }
898 } 956 }
899 957
900 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { 958 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
901 oop reference = CompilationResult_DataPatch::reference(site); 959 Handle reference = CompilationResult_DataPatch::reference(site);
902 if (reference->is_a(CompilationResult_ConstantReference::klass())) { 960 if (reference->is_a(CompilationResult_ConstantReference::klass())) {
903 Handle constant = CompilationResult_ConstantReference::constant(reference); 961 Handle constant = CompilationResult_ConstantReference::constant(reference);
904 if (constant->is_a(HotSpotObjectConstantImpl::klass())) { 962 if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
905 pd_patch_OopConstant(pc_offset, constant); 963 pd_patch_OopConstant(pc_offset, constant, CHECK);
906 } else if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) { 964 } else if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
907 pd_patch_MetaspaceConstant(pc_offset, constant); 965 pd_patch_MetaspaceConstant(pc_offset, constant, CHECK);
908 } else { 966 } else {
909 fatal("unknown constant type in data patch"); 967 JVMCI_ERROR(err_msg("unknown constant type in data patch: %s", constant->klass()->signature_name()));
910 } 968 }
911 } else if (reference->is_a(CompilationResult_DataSectionReference::klass())) { 969 } else if (reference->is_a(CompilationResult_DataSectionReference::klass())) {
912 int data_offset = CompilationResult_DataSectionReference::offset(reference); 970 int data_offset = CompilationResult_DataSectionReference::offset(reference);
913 assert(0 <= data_offset && data_offset < _constants_size, err_msg("data offset 0x%X points outside data section (size 0x%X)", data_offset, _constants_size)); 971 if (0 <= data_offset && data_offset < _constants_size) {
972 pd_patch_DataSectionReference(pc_offset, data_offset);
973 } else {
974 JVMCI_ERROR(err_msg("data offset 0x%X points outside data section (size 0x%X)", data_offset, _constants_size));
975 }
914 pd_patch_DataSectionReference(pc_offset, data_offset); 976 pd_patch_DataSectionReference(pc_offset, data_offset);
915 } else { 977 } else {
916 fatal("unknown data patch type"); 978 JVMCI_ERROR(err_msg("unknown data patch type: %s", reference->klass()->signature_name()));
917 } 979 }
918 } 980 }
919 981
920 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { 982 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
921 oop id_obj = CompilationResult_Mark::id(site); 983 Handle id_obj = CompilationResult_Mark::id(site);
922 984
923 if (id_obj != NULL) { 985 if (id_obj.not_null()) {
924 assert(java_lang_boxing_object::is_instance(id_obj, T_INT), "Integer id expected"); 986 if (!java_lang_boxing_object::is_instance(id_obj(), T_INT)) {
987 JVMCI_ERROR(err_msg("expected Integer id, got %s", id_obj->klass()->signature_name()));
988 }
925 jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT)); 989 jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT));
926 990
927 address pc = _instructions->start() + pc_offset; 991 address pc = _instructions->start() + pc_offset;
928 992
929 switch (id) { 993 switch (id) {
952 break; 1016 break;
953 case POLL_NEAR: 1017 case POLL_NEAR:
954 case POLL_FAR: 1018 case POLL_FAR:
955 case POLL_RETURN_NEAR: 1019 case POLL_RETURN_NEAR:
956 case POLL_RETURN_FAR: 1020 case POLL_RETURN_FAR:
957 pd_relocate_poll(pc, id); 1021 pd_relocate_poll(pc, id, CHECK);
958 break; 1022 break;
959 case CARD_TABLE_SHIFT: 1023 case CARD_TABLE_SHIFT:
960 case CARD_TABLE_ADDRESS: 1024 case CARD_TABLE_ADDRESS:
961 break; 1025 break;
962 default: 1026 default:
963 ShouldNotReachHere(); 1027 JVMCI_ERROR(err_msg("invalid mark id: %d", id));
964 break; 1028 break;
965 } 1029 }
966 } 1030 }
967 } 1031 }
968 1032