1 /* |
1 /* |
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
266 if (_id == load_klass_id) { |
266 if (_id == load_klass_id) { |
267 // produce a copy of the load klass instruction for use by the being initialized case |
267 // produce a copy of the load klass instruction for use by the being initialized case |
268 #ifdef ASSERT |
268 #ifdef ASSERT |
269 address start = __ pc(); |
269 address start = __ pc(); |
270 #endif |
270 #endif |
271 AddressLiteral addrlit(NULL, oop_Relocation::spec(_oop_index)); |
271 AddressLiteral addrlit(NULL, metadata_Relocation::spec(_index)); |
|
272 __ patchable_set(addrlit, _obj); |
|
273 |
|
274 #ifdef ASSERT |
|
275 for (int i = 0; i < _bytes_to_copy; i++) { |
|
276 address ptr = (address)(_pc_start + i); |
|
277 int a_byte = (*ptr) & 0xFF; |
|
278 assert(a_byte == *start++, "should be the same code"); |
|
279 } |
|
280 #endif |
|
281 } else if (_id == load_mirror_id) { |
|
282 // produce a copy of the load mirror instruction for use by the being initialized case |
|
283 #ifdef ASSERT |
|
284 address start = __ pc(); |
|
285 #endif |
|
286 AddressLiteral addrlit(NULL, oop_Relocation::spec(_index)); |
272 __ patchable_set(addrlit, _obj); |
287 __ patchable_set(addrlit, _obj); |
273 |
288 |
274 #ifdef ASSERT |
289 #ifdef ASSERT |
275 for (int i = 0; i < _bytes_to_copy; i++) { |
290 for (int i = 0; i < _bytes_to_copy; i++) { |
276 address ptr = (address)(_pc_start + i); |
291 address ptr = (address)(_pc_start + i); |
287 } |
302 } |
288 } |
303 } |
289 |
304 |
290 address end_of_patch = __ pc(); |
305 address end_of_patch = __ pc(); |
291 int bytes_to_skip = 0; |
306 int bytes_to_skip = 0; |
292 if (_id == load_klass_id) { |
307 if (_id == load_mirror_id) { |
293 int offset = __ offset(); |
308 int offset = __ offset(); |
294 if (CommentedAssembly) { |
309 if (CommentedAssembly) { |
295 __ block_comment(" being_initialized check"); |
310 __ block_comment(" being_initialized check"); |
296 } |
311 } |
297 |
312 |
298 // static field accesses have special semantics while the class |
313 // static field accesses have special semantics while the class |
299 // initializer is being run so we emit a test which can be used to |
314 // initializer is being run so we emit a test which can be used to |
300 // check that this code is being executed by the initializing |
315 // check that this code is being executed by the initializing |
301 // thread. |
316 // thread. |
302 assert(_obj != noreg, "must be a valid register"); |
317 assert(_obj != noreg, "must be a valid register"); |
303 assert(_oop_index >= 0, "must have oop index"); |
318 assert(_index >= 0, "must have oop index"); |
304 __ load_heap_oop(_obj, java_lang_Class::klass_offset_in_bytes(), G3); |
319 __ ld_ptr(_obj, java_lang_Class::klass_offset_in_bytes(), G3); |
305 __ ld_ptr(G3, in_bytes(instanceKlass::init_thread_offset()), G3); |
320 __ ld_ptr(G3, in_bytes(InstanceKlass::init_thread_offset()), G3); |
306 __ cmp_and_brx_short(G2_thread, G3, Assembler::notEqual, Assembler::pn, call_patch); |
321 __ cmp_and_brx_short(G2_thread, G3, Assembler::notEqual, Assembler::pn, call_patch); |
307 |
322 |
308 // load_klass patches may execute the patched code before it's |
323 // load_klass patches may execute the patched code before it's |
309 // copied back into place so we need to jump back into the main |
324 // copied back into place so we need to jump back into the main |
310 // code of the nmethod to continue execution. |
325 // code of the nmethod to continue execution. |
333 assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info"); |
348 assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info"); |
334 |
349 |
335 address entry = __ pc(); |
350 address entry = __ pc(); |
336 NativeGeneralJump::insert_unconditional((address)_pc_start, entry); |
351 NativeGeneralJump::insert_unconditional((address)_pc_start, entry); |
337 address target = NULL; |
352 address target = NULL; |
|
353 relocInfo::relocType reloc_type = relocInfo::none; |
338 switch (_id) { |
354 switch (_id) { |
339 case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); break; |
355 case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); break; |
340 case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id); break; |
356 case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id); reloc_type = relocInfo::metadata_type; break; |
|
357 case load_mirror_id: target = Runtime1::entry_for(Runtime1::load_mirror_patching_id); reloc_type = relocInfo::oop_type; break; |
341 default: ShouldNotReachHere(); |
358 default: ShouldNotReachHere(); |
342 } |
359 } |
343 __ bind(call_patch); |
360 __ bind(call_patch); |
344 |
361 |
345 if (CommentedAssembly) { |
362 if (CommentedAssembly) { |
349 __ delayed()->nop(); |
366 __ delayed()->nop(); |
350 assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change"); |
367 assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change"); |
351 ce->add_call_info_here(_info); |
368 ce->add_call_info_here(_info); |
352 __ br(Assembler::always, false, Assembler::pt, _patch_site_entry); |
369 __ br(Assembler::always, false, Assembler::pt, _patch_site_entry); |
353 __ delayed()->nop(); |
370 __ delayed()->nop(); |
354 if (_id == load_klass_id) { |
371 if (_id == load_klass_id || _id == load_mirror_id) { |
355 CodeSection* cs = __ code_section(); |
372 CodeSection* cs = __ code_section(); |
356 address pc = (address)_pc_start; |
373 address pc = (address)_pc_start; |
357 RelocIterator iter(cs, pc, pc + 1); |
374 RelocIterator iter(cs, pc, pc + 1); |
358 relocInfo::change_reloc_info_for_address(&iter, (address) pc, relocInfo::oop_type, relocInfo::none); |
375 relocInfo::change_reloc_info_for_address(&iter, (address) pc, reloc_type, relocInfo::none); |
359 |
376 |
360 pc = (address)(_pc_start + NativeMovConstReg::add_offset); |
377 pc = (address)(_pc_start + NativeMovConstReg::add_offset); |
361 RelocIterator iter2(cs, pc, pc+1); |
378 RelocIterator iter2(cs, pc, pc+1); |
362 relocInfo::change_reloc_info_for_address(&iter2, (address) pc, relocInfo::oop_type, relocInfo::none); |
379 relocInfo::change_reloc_info_for_address(&iter2, (address) pc, reloc_type, relocInfo::none); |
363 } |
380 } |
364 |
381 |
365 } |
382 } |
366 |
383 |
367 |
384 |