Mercurial > hg > graal-compiler
annotate src/share/vm/c1/c1_Runtime1.cpp @ 356:1ee8caae33af
Merge
author | tonyp |
---|---|
date | Thu, 21 Aug 2008 23:36:31 -0400 |
parents | 37f87013dfd8 d1605aabd0a1 |
children | f8199438385b |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_c1_Runtime1.cpp.incl" | |
27 | |
28 | |
29 // Implementation of StubAssembler | |
30 | |
31 StubAssembler::StubAssembler(CodeBuffer* code, const char * name, int stub_id) : C1_MacroAssembler(code) { | |
32 _name = name; | |
33 _must_gc_arguments = false; | |
34 _frame_size = no_frame_size; | |
35 _num_rt_args = 0; | |
36 _stub_id = stub_id; | |
37 } | |
38 | |
39 | |
40 void StubAssembler::set_info(const char* name, bool must_gc_arguments) { | |
41 _name = name; | |
42 _must_gc_arguments = must_gc_arguments; | |
43 } | |
44 | |
45 | |
46 void StubAssembler::set_frame_size(int size) { | |
47 if (_frame_size == no_frame_size) { | |
48 _frame_size = size; | |
49 } | |
50 assert(_frame_size == size, "can't change the frame size"); | |
51 } | |
52 | |
53 | |
54 void StubAssembler::set_num_rt_args(int args) { | |
55 if (_num_rt_args == 0) { | |
56 _num_rt_args = args; | |
57 } | |
58 assert(_num_rt_args == args, "can't change the number of args"); | |
59 } | |
60 | |
61 // Implementation of Runtime1 | |
62 | |
63 bool Runtime1::_is_initialized = false; | |
64 CodeBlob* Runtime1::_blobs[Runtime1::number_of_ids]; | |
65 const char *Runtime1::_blob_names[] = { | |
66 RUNTIME1_STUBS(STUB_NAME, LAST_STUB_NAME) | |
67 }; | |
68 | |
69 #ifndef PRODUCT | |
70 // statistics | |
71 int Runtime1::_generic_arraycopy_cnt = 0; | |
72 int Runtime1::_primitive_arraycopy_cnt = 0; | |
73 int Runtime1::_oop_arraycopy_cnt = 0; | |
74 int Runtime1::_arraycopy_slowcase_cnt = 0; | |
75 int Runtime1::_new_type_array_slowcase_cnt = 0; | |
76 int Runtime1::_new_object_array_slowcase_cnt = 0; | |
77 int Runtime1::_new_instance_slowcase_cnt = 0; | |
78 int Runtime1::_new_multi_array_slowcase_cnt = 0; | |
79 int Runtime1::_monitorenter_slowcase_cnt = 0; | |
80 int Runtime1::_monitorexit_slowcase_cnt = 0; | |
81 int Runtime1::_patch_code_slowcase_cnt = 0; | |
82 int Runtime1::_throw_range_check_exception_count = 0; | |
83 int Runtime1::_throw_index_exception_count = 0; | |
84 int Runtime1::_throw_div0_exception_count = 0; | |
85 int Runtime1::_throw_null_pointer_exception_count = 0; | |
86 int Runtime1::_throw_class_cast_exception_count = 0; | |
87 int Runtime1::_throw_incompatible_class_change_error_count = 0; | |
88 int Runtime1::_throw_array_store_exception_count = 0; | |
89 int Runtime1::_throw_count = 0; | |
90 #endif | |
91 | |
92 BufferBlob* Runtime1::_buffer_blob = NULL; | |
93 | |
94 // Simple helper to see if the caller of a runtime stub which | |
95 // entered the VM has been deoptimized | |
96 | |
97 static bool caller_is_deopted() { | |
98 JavaThread* thread = JavaThread::current(); | |
99 RegisterMap reg_map(thread, false); | |
100 frame runtime_frame = thread->last_frame(); | |
101 frame caller_frame = runtime_frame.sender(®_map); | |
102 assert(caller_frame.is_compiled_frame(), "must be compiled"); | |
103 return caller_frame.is_deoptimized_frame(); | |
104 } | |
105 | |
106 // Stress deoptimization | |
107 static void deopt_caller() { | |
108 if ( !caller_is_deopted()) { | |
109 JavaThread* thread = JavaThread::current(); | |
110 RegisterMap reg_map(thread, false); | |
111 frame runtime_frame = thread->last_frame(); | |
112 frame caller_frame = runtime_frame.sender(®_map); | |
113 VM_DeoptimizeFrame deopt(thread, caller_frame.id()); | |
114 VMThread::execute(&deopt); | |
115 assert(caller_is_deopted(), "Must be deoptimized"); | |
116 } | |
117 } | |
118 | |
119 | |
120 BufferBlob* Runtime1::get_buffer_blob() { | |
121 // Allocate code buffer space only once | |
122 BufferBlob* blob = _buffer_blob; | |
123 if (blob == NULL) { | |
124 // setup CodeBuffer. Preallocate a BufferBlob of size | |
125 // NMethodSizeLimit plus some extra space for constants. | |
126 int code_buffer_size = desired_max_code_buffer_size() + desired_max_constant_size(); | |
127 blob = BufferBlob::create("Compiler1 temporary CodeBuffer", | |
128 code_buffer_size); | |
129 guarantee(blob != NULL, "must create initial code buffer"); | |
130 _buffer_blob = blob; | |
131 } | |
132 return _buffer_blob; | |
133 } | |
134 | |
135 void Runtime1::setup_code_buffer(CodeBuffer* code, int call_stub_estimate) { | |
136 // Preinitialize the consts section to some large size: | |
137 int locs_buffer_size = 20 * (relocInfo::length_limit + sizeof(relocInfo)); | |
138 char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size); | |
139 code->insts()->initialize_shared_locs((relocInfo*)locs_buffer, | |
140 locs_buffer_size / sizeof(relocInfo)); | |
141 code->initialize_consts_size(desired_max_constant_size()); | |
142 // Call stubs + deopt/exception handler | |
143 code->initialize_stubs_size((call_stub_estimate * LIR_Assembler::call_stub_size) + | |
144 LIR_Assembler::exception_handler_size + | |
145 LIR_Assembler::deopt_handler_size); | |
146 } | |
147 | |
148 | |
149 void Runtime1::generate_blob_for(StubID id) { | |
150 assert(0 <= id && id < number_of_ids, "illegal stub id"); | |
151 ResourceMark rm; | |
152 // create code buffer for code storage | |
153 CodeBuffer code(get_buffer_blob()->instructions_begin(), | |
154 get_buffer_blob()->instructions_size()); | |
155 | |
156 setup_code_buffer(&code, 0); | |
157 | |
158 // create assembler for code generation | |
159 StubAssembler* sasm = new StubAssembler(&code, name_for(id), id); | |
160 // generate code for runtime stub | |
161 OopMapSet* oop_maps; | |
162 oop_maps = generate_code_for(id, sasm); | |
163 assert(oop_maps == NULL || sasm->frame_size() != no_frame_size, | |
164 "if stub has an oop map it must have a valid frame size"); | |
165 | |
166 #ifdef ASSERT | |
167 // Make sure that stubs that need oopmaps have them | |
168 switch (id) { | |
169 // These stubs don't need to have an oopmap | |
170 case dtrace_object_alloc_id: | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
171 case g1_pre_barrier_slow_id: |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
172 case g1_post_barrier_slow_id: |
0 | 173 case slow_subtype_check_id: |
174 case fpu2long_stub_id: | |
175 case unwind_exception_id: | |
176 #ifndef TIERED | |
177 case counter_overflow_id: // Not generated outside the tiered world | |
178 #endif | |
179 #ifdef SPARC | |
180 case handle_exception_nofpu_id: // Unused on sparc | |
181 #endif | |
182 break; | |
183 | |
184 // All other stubs should have oopmaps | |
185 default: | |
186 assert(oop_maps != NULL, "must have an oopmap"); | |
187 } | |
188 #endif | |
189 | |
190 // align so printing shows nop's instead of random code at the end (SimpleStubs are aligned) | |
191 sasm->align(BytesPerWord); | |
192 // make sure all code is in code buffer | |
193 sasm->flush(); | |
194 // create blob - distinguish a few special cases | |
195 CodeBlob* blob = RuntimeStub::new_runtime_stub(name_for(id), | |
196 &code, | |
197 CodeOffsets::frame_never_safe, | |
198 sasm->frame_size(), | |
199 oop_maps, | |
200 sasm->must_gc_arguments()); | |
201 // install blob | |
202 assert(blob != NULL, "blob must exist"); | |
203 _blobs[id] = blob; | |
204 } | |
205 | |
206 | |
207 void Runtime1::initialize() { | |
208 // Warning: If we have more than one compilation running in parallel, we | |
209 // need a lock here with the current setup (lazy initialization). | |
210 if (!is_initialized()) { | |
211 _is_initialized = true; | |
212 | |
213 // platform-dependent initialization | |
214 initialize_pd(); | |
215 // generate stubs | |
216 for (int id = 0; id < number_of_ids; id++) generate_blob_for((StubID)id); | |
217 // printing | |
218 #ifndef PRODUCT | |
219 if (PrintSimpleStubs) { | |
220 ResourceMark rm; | |
221 for (int id = 0; id < number_of_ids; id++) { | |
222 _blobs[id]->print(); | |
223 if (_blobs[id]->oop_maps() != NULL) { | |
224 _blobs[id]->oop_maps()->print(); | |
225 } | |
226 } | |
227 } | |
228 #endif | |
229 } | |
230 } | |
231 | |
232 | |
233 CodeBlob* Runtime1::blob_for(StubID id) { | |
234 assert(0 <= id && id < number_of_ids, "illegal stub id"); | |
235 if (!is_initialized()) initialize(); | |
236 return _blobs[id]; | |
237 } | |
238 | |
239 | |
240 const char* Runtime1::name_for(StubID id) { | |
241 assert(0 <= id && id < number_of_ids, "illegal stub id"); | |
242 return _blob_names[id]; | |
243 } | |
244 | |
245 const char* Runtime1::name_for_address(address entry) { | |
246 for (int id = 0; id < number_of_ids; id++) { | |
247 if (entry == entry_for((StubID)id)) return name_for((StubID)id); | |
248 } | |
249 | |
250 #define FUNCTION_CASE(a, f) \ | |
251 if ((intptr_t)a == CAST_FROM_FN_PTR(intptr_t, f)) return #f | |
252 | |
253 FUNCTION_CASE(entry, os::javaTimeMillis); | |
254 FUNCTION_CASE(entry, os::javaTimeNanos); | |
255 FUNCTION_CASE(entry, SharedRuntime::OSR_migration_end); | |
256 FUNCTION_CASE(entry, SharedRuntime::d2f); | |
257 FUNCTION_CASE(entry, SharedRuntime::d2i); | |
258 FUNCTION_CASE(entry, SharedRuntime::d2l); | |
259 FUNCTION_CASE(entry, SharedRuntime::dcos); | |
260 FUNCTION_CASE(entry, SharedRuntime::dexp); | |
261 FUNCTION_CASE(entry, SharedRuntime::dlog); | |
262 FUNCTION_CASE(entry, SharedRuntime::dlog10); | |
263 FUNCTION_CASE(entry, SharedRuntime::dpow); | |
264 FUNCTION_CASE(entry, SharedRuntime::drem); | |
265 FUNCTION_CASE(entry, SharedRuntime::dsin); | |
266 FUNCTION_CASE(entry, SharedRuntime::dtan); | |
267 FUNCTION_CASE(entry, SharedRuntime::f2i); | |
268 FUNCTION_CASE(entry, SharedRuntime::f2l); | |
269 FUNCTION_CASE(entry, SharedRuntime::frem); | |
270 FUNCTION_CASE(entry, SharedRuntime::l2d); | |
271 FUNCTION_CASE(entry, SharedRuntime::l2f); | |
272 FUNCTION_CASE(entry, SharedRuntime::ldiv); | |
273 FUNCTION_CASE(entry, SharedRuntime::lmul); | |
274 FUNCTION_CASE(entry, SharedRuntime::lrem); | |
275 FUNCTION_CASE(entry, SharedRuntime::lrem); | |
276 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_entry); | |
277 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_exit); | |
278 FUNCTION_CASE(entry, trace_block_entry); | |
279 | |
280 #undef FUNCTION_CASE | |
281 | |
282 return "<unknown function>"; | |
283 } | |
284 | |
285 | |
286 JRT_ENTRY(void, Runtime1::new_instance(JavaThread* thread, klassOopDesc* klass)) | |
287 NOT_PRODUCT(_new_instance_slowcase_cnt++;) | |
288 | |
289 assert(oop(klass)->is_klass(), "not a class"); | |
290 instanceKlassHandle h(thread, klass); | |
291 h->check_valid_for_instantiation(true, CHECK); | |
292 // make sure klass is initialized | |
293 h->initialize(CHECK); | |
294 // allocate instance and return via TLS | |
295 oop obj = h->allocate_instance(CHECK); | |
296 thread->set_vm_result(obj); | |
297 JRT_END | |
298 | |
299 | |
300 JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* thread, klassOopDesc* klass, jint length)) | |
301 NOT_PRODUCT(_new_type_array_slowcase_cnt++;) | |
302 // Note: no handle for klass needed since they are not used | |
303 // anymore after new_typeArray() and no GC can happen before. | |
304 // (This may have to change if this code changes!) | |
305 assert(oop(klass)->is_klass(), "not a class"); | |
306 BasicType elt_type = typeArrayKlass::cast(klass)->element_type(); | |
307 oop obj = oopFactory::new_typeArray(elt_type, length, CHECK); | |
308 thread->set_vm_result(obj); | |
309 // This is pretty rare but this runtime patch is stressful to deoptimization | |
310 // if we deoptimize here so force a deopt to stress the path. | |
311 if (DeoptimizeALot) { | |
312 deopt_caller(); | |
313 } | |
314 | |
315 JRT_END | |
316 | |
317 | |
318 JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* thread, klassOopDesc* array_klass, jint length)) | |
319 NOT_PRODUCT(_new_object_array_slowcase_cnt++;) | |
320 | |
321 // Note: no handle for klass needed since they are not used | |
322 // anymore after new_objArray() and no GC can happen before. | |
323 // (This may have to change if this code changes!) | |
324 assert(oop(array_klass)->is_klass(), "not a class"); | |
325 klassOop elem_klass = objArrayKlass::cast(array_klass)->element_klass(); | |
326 objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK); | |
327 thread->set_vm_result(obj); | |
328 // This is pretty rare but this runtime patch is stressful to deoptimization | |
329 // if we deoptimize here so force a deopt to stress the path. | |
330 if (DeoptimizeALot) { | |
331 deopt_caller(); | |
332 } | |
333 JRT_END | |
334 | |
335 | |
336 JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* thread, klassOopDesc* klass, int rank, jint* dims)) | |
337 NOT_PRODUCT(_new_multi_array_slowcase_cnt++;) | |
338 | |
339 assert(oop(klass)->is_klass(), "not a class"); | |
340 assert(rank >= 1, "rank must be nonzero"); | |
341 #ifdef _LP64 | |
342 // In 64 bit mode, the sizes are stored in the top 32 bits | |
343 // of each 64 bit stack entry. | |
344 // dims is actually an intptr_t * because the arguments | |
345 // are pushed onto a 64 bit stack. | |
346 // We must create an array of jints to pass to multi_allocate. | |
347 // We reuse the current stack because it will be popped | |
348 // after this bytecode is completed. | |
349 if ( rank > 1 ) { | |
350 int index; | |
351 for ( index = 1; index < rank; index++ ) { // First size is ok | |
352 dims[index] = dims[index*2]; | |
353 } | |
354 } | |
355 #endif | |
356 oop obj = arrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK); | |
357 thread->set_vm_result(obj); | |
358 JRT_END | |
359 | |
360 | |
361 JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* thread, StubID id)) | |
362 tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", id); | |
363 JRT_END | |
364 | |
365 | |
366 JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* thread)) | |
367 THROW(vmSymbolHandles::java_lang_ArrayStoreException()); | |
368 JRT_END | |
369 | |
370 | |
371 JRT_ENTRY(void, Runtime1::post_jvmti_exception_throw(JavaThread* thread)) | |
372 if (JvmtiExport::can_post_exceptions()) { | |
373 vframeStream vfst(thread, true); | |
374 address bcp = vfst.method()->bcp_from(vfst.bci()); | |
375 JvmtiExport::post_exception_throw(thread, vfst.method(), bcp, thread->exception_oop()); | |
376 } | |
377 JRT_END | |
378 | |
379 #ifdef TIERED | |
380 JRT_ENTRY(void, Runtime1::counter_overflow(JavaThread* thread, int bci)) | |
381 RegisterMap map(thread, false); | |
382 frame fr = thread->last_frame().sender(&map); | |
383 nmethod* nm = (nmethod*) fr.cb(); | |
384 assert(nm!= NULL && nm->is_nmethod(), "what?"); | |
385 methodHandle method(thread, nm->method()); | |
386 if (bci == 0) { | |
387 // invocation counter overflow | |
388 if (!Tier1CountOnly) { | |
389 CompilationPolicy::policy()->method_invocation_event(method, CHECK); | |
390 } else { | |
391 method()->invocation_counter()->reset(); | |
392 } | |
393 } else { | |
394 if (!Tier1CountOnly) { | |
395 // Twe have a bci but not the destination bci and besides a backedge | |
396 // event is more for OSR which we don't want here. | |
397 CompilationPolicy::policy()->method_invocation_event(method, CHECK); | |
398 } else { | |
399 method()->backedge_counter()->reset(); | |
400 } | |
401 } | |
402 JRT_END | |
403 #endif // TIERED | |
404 | |
405 extern void vm_exit(int code); | |
406 | |
407 // Enter this method from compiled code handler below. This is where we transition | |
408 // to VM mode. This is done as a helper routine so that the method called directly | |
409 // from compiled code does not have to transition to VM. This allows the entry | |
410 // method to see if the nmethod that we have just looked up a handler for has | |
411 // been deoptimized while we were in the vm. This simplifies the assembly code | |
412 // cpu directories. | |
413 // | |
414 // We are entering here from exception stub (via the entry method below) | |
415 // If there is a compiled exception handler in this method, we will continue there; | |
416 // otherwise we will unwind the stack and continue at the caller of top frame method | |
417 // Note: we enter in Java using a special JRT wrapper. This wrapper allows us to | |
418 // control the area where we can allow a safepoint. After we exit the safepoint area we can | |
419 // check to see if the handler we are going to return is now in a nmethod that has | |
420 // been deoptimized. If that is the case we return the deopt blob | |
421 // unpack_with_exception entry instead. This makes life for the exception blob easier | |
422 // because making that same check and diverting is painful from assembly language. | |
423 // | |
424 | |
425 | |
426 JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, nmethod*& nm)) | |
427 | |
428 Handle exception(thread, ex); | |
429 nm = CodeCache::find_nmethod(pc); | |
430 assert(nm != NULL, "this is not an nmethod"); | |
431 // Adjust the pc as needed/ | |
432 if (nm->is_deopt_pc(pc)) { | |
433 RegisterMap map(thread, false); | |
434 frame exception_frame = thread->last_frame().sender(&map); | |
435 // if the frame isn't deopted then pc must not correspond to the caller of last_frame | |
436 assert(exception_frame.is_deoptimized_frame(), "must be deopted"); | |
437 pc = exception_frame.pc(); | |
438 } | |
439 #ifdef ASSERT | |
440 assert(exception.not_null(), "NULL exceptions should be handled by throw_exception"); | |
441 assert(exception->is_oop(), "just checking"); | |
442 // Check that exception is a subclass of Throwable, otherwise we have a VerifyError | |
443 if (!(exception->is_a(SystemDictionary::throwable_klass()))) { | |
444 if (ExitVMOnVerifyError) vm_exit(-1); | |
445 ShouldNotReachHere(); | |
446 } | |
447 #endif | |
448 | |
449 // Check the stack guard pages and reenable them if necessary and there is | |
450 // enough space on the stack to do so. Use fast exceptions only if the guard | |
451 // pages are enabled. | |
452 bool guard_pages_enabled = thread->stack_yellow_zone_enabled(); | |
453 if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack(); | |
454 | |
455 if (JvmtiExport::can_post_exceptions()) { | |
456 // To ensure correct notification of exception catches and throws | |
457 // we have to deoptimize here. If we attempted to notify the | |
458 // catches and throws during this exception lookup it's possible | |
459 // we could deoptimize on the way out of the VM and end back in | |
460 // the interpreter at the throw site. This would result in double | |
461 // notifications since the interpreter would also notify about | |
462 // these same catches and throws as it unwound the frame. | |
463 | |
464 RegisterMap reg_map(thread); | |
465 frame stub_frame = thread->last_frame(); | |
466 frame caller_frame = stub_frame.sender(®_map); | |
467 | |
468 // We don't really want to deoptimize the nmethod itself since we | |
469 // can actually continue in the exception handler ourselves but I | |
470 // don't see an easy way to have the desired effect. | |
471 VM_DeoptimizeFrame deopt(thread, caller_frame.id()); | |
472 VMThread::execute(&deopt); | |
473 | |
474 return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); | |
475 } | |
476 | |
477 // ExceptionCache is used only for exceptions at call and not for implicit exceptions | |
478 if (guard_pages_enabled) { | |
479 address fast_continuation = nm->handler_for_exception_and_pc(exception, pc); | |
480 if (fast_continuation != NULL) { | |
481 if (fast_continuation == ExceptionCache::unwind_handler()) fast_continuation = NULL; | |
482 return fast_continuation; | |
483 } | |
484 } | |
485 | |
486 // If the stack guard pages are enabled, check whether there is a handler in | |
487 // the current method. Otherwise (guard pages disabled), force an unwind and | |
488 // skip the exception cache update (i.e., just leave continuation==NULL). | |
489 address continuation = NULL; | |
490 if (guard_pages_enabled) { | |
491 | |
492 // New exception handling mechanism can support inlined methods | |
493 // with exception handlers since the mappings are from PC to PC | |
494 | |
495 // debugging support | |
496 // tracing | |
497 if (TraceExceptions) { | |
498 ttyLocker ttyl; | |
499 ResourceMark rm; | |
500 tty->print_cr("Exception <%s> (0x%x) thrown in compiled method <%s> at PC " PTR_FORMAT " for thread 0x%x", | |
501 exception->print_value_string(), (address)exception(), nm->method()->print_value_string(), pc, thread); | |
502 } | |
503 // for AbortVMOnException flag | |
504 NOT_PRODUCT(Exceptions::debug_check_abort(exception)); | |
505 | |
506 // Clear out the exception oop and pc since looking up an | |
507 // exception handler can cause class loading, which might throw an | |
508 // exception and those fields are expected to be clear during | |
509 // normal bytecode execution. | |
510 thread->set_exception_oop(NULL); | |
511 thread->set_exception_pc(NULL); | |
512 | |
513 continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false); | |
514 // If an exception was thrown during exception dispatch, the exception oop may have changed | |
515 thread->set_exception_oop(exception()); | |
516 thread->set_exception_pc(pc); | |
517 | |
518 // the exception cache is used only by non-implicit exceptions | |
519 if (continuation == NULL) { | |
520 nm->add_handler_for_exception_and_pc(exception, pc, ExceptionCache::unwind_handler()); | |
521 } else { | |
522 nm->add_handler_for_exception_and_pc(exception, pc, continuation); | |
523 } | |
524 } | |
525 | |
526 thread->set_vm_result(exception()); | |
527 | |
528 if (TraceExceptions) { | |
529 ttyLocker ttyl; | |
530 ResourceMark rm; | |
531 tty->print_cr("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT " for exception thrown at PC " PTR_FORMAT, | |
532 thread, continuation, pc); | |
533 } | |
534 | |
535 return continuation; | |
536 JRT_END | |
537 | |
538 // Enter this method from compiled code only if there is a Java exception handler | |
539 // in the method handling the exception | |
540 // We are entering here from exception stub. We don't do a normal VM transition here. | |
541 // We do it in a helper. This is so we can check to see if the nmethod we have just | |
542 // searched for an exception handler has been deoptimized in the meantime. | |
543 address Runtime1::exception_handler_for_pc(JavaThread* thread) { | |
544 oop exception = thread->exception_oop(); | |
545 address pc = thread->exception_pc(); | |
546 // Still in Java mode | |
547 debug_only(ResetNoHandleMark rnhm); | |
548 nmethod* nm = NULL; | |
549 address continuation = NULL; | |
550 { | |
551 // Enter VM mode by calling the helper | |
552 | |
553 ResetNoHandleMark rnhm; | |
554 continuation = exception_handler_for_pc_helper(thread, exception, pc, nm); | |
555 } | |
556 // Back in JAVA, use no oops DON'T safepoint | |
557 | |
558 // Now check to see if the nmethod we were called from is now deoptimized. | |
559 // If so we must return to the deopt blob and deoptimize the nmethod | |
560 | |
561 if (nm != NULL && caller_is_deopted()) { | |
562 continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); | |
563 } | |
564 | |
565 return continuation; | |
566 } | |
567 | |
568 | |
569 JRT_ENTRY(void, Runtime1::throw_range_check_exception(JavaThread* thread, int index)) | |
570 NOT_PRODUCT(_throw_range_check_exception_count++;) | |
571 Events::log("throw_range_check"); | |
572 char message[jintAsStringSize]; | |
573 sprintf(message, "%d", index); | |
574 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), message); | |
575 JRT_END | |
576 | |
577 | |
578 JRT_ENTRY(void, Runtime1::throw_index_exception(JavaThread* thread, int index)) | |
579 NOT_PRODUCT(_throw_index_exception_count++;) | |
580 Events::log("throw_index"); | |
581 char message[16]; | |
582 sprintf(message, "%d", index); | |
583 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IndexOutOfBoundsException(), message); | |
584 JRT_END | |
585 | |
586 | |
587 JRT_ENTRY(void, Runtime1::throw_div0_exception(JavaThread* thread)) | |
588 NOT_PRODUCT(_throw_div0_exception_count++;) | |
589 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArithmeticException(), "/ by zero"); | |
590 JRT_END | |
591 | |
592 | |
593 JRT_ENTRY(void, Runtime1::throw_null_pointer_exception(JavaThread* thread)) | |
594 NOT_PRODUCT(_throw_null_pointer_exception_count++;) | |
595 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException()); | |
596 JRT_END | |
597 | |
598 | |
599 JRT_ENTRY(void, Runtime1::throw_class_cast_exception(JavaThread* thread, oopDesc* object)) | |
600 NOT_PRODUCT(_throw_class_cast_exception_count++;) | |
601 ResourceMark rm(thread); | |
602 char* message = SharedRuntime::generate_class_cast_message( | |
603 thread, Klass::cast(object->klass())->external_name()); | |
604 SharedRuntime::throw_and_post_jvmti_exception( | |
605 thread, vmSymbols::java_lang_ClassCastException(), message); | |
606 JRT_END | |
607 | |
608 | |
609 JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* thread)) | |
610 NOT_PRODUCT(_throw_incompatible_class_change_error_count++;) | |
611 ResourceMark rm(thread); | |
612 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IncompatibleClassChangeError()); | |
613 JRT_END | |
614 | |
615 | |
616 JRT_ENTRY_NO_ASYNC(void, Runtime1::monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock)) | |
617 NOT_PRODUCT(_monitorenter_slowcase_cnt++;) | |
618 if (PrintBiasedLockingStatistics) { | |
619 Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); | |
620 } | |
621 Handle h_obj(thread, obj); | |
622 assert(h_obj()->is_oop(), "must be NULL or an object"); | |
623 if (UseBiasedLocking) { | |
624 // Retry fast entry if bias is revoked to avoid unnecessary inflation | |
625 ObjectSynchronizer::fast_enter(h_obj, lock->lock(), true, CHECK); | |
626 } else { | |
627 if (UseFastLocking) { | |
628 // When using fast locking, the compiled code has already tried the fast case | |
629 assert(obj == lock->obj(), "must match"); | |
630 ObjectSynchronizer::slow_enter(h_obj, lock->lock(), THREAD); | |
631 } else { | |
632 lock->set_obj(obj); | |
633 ObjectSynchronizer::fast_enter(h_obj, lock->lock(), false, THREAD); | |
634 } | |
635 } | |
636 JRT_END | |
637 | |
638 | |
639 JRT_LEAF(void, Runtime1::monitorexit(JavaThread* thread, BasicObjectLock* lock)) | |
640 NOT_PRODUCT(_monitorexit_slowcase_cnt++;) | |
641 assert(thread == JavaThread::current(), "threads must correspond"); | |
642 assert(thread->last_Java_sp(), "last_Java_sp must be set"); | |
643 // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown | |
644 EXCEPTION_MARK; | |
645 | |
646 oop obj = lock->obj(); | |
647 assert(obj->is_oop(), "must be NULL or an object"); | |
648 if (UseFastLocking) { | |
649 // When using fast locking, the compiled code has already tried the fast case | |
650 ObjectSynchronizer::slow_exit(obj, lock->lock(), THREAD); | |
651 } else { | |
652 ObjectSynchronizer::fast_exit(obj, lock->lock(), THREAD); | |
653 } | |
654 JRT_END | |
655 | |
656 | |
657 static klassOop resolve_field_return_klass(methodHandle caller, int bci, TRAPS) { | |
658 Bytecode_field* field_access = Bytecode_field_at(caller(), caller->bcp_from(bci)); | |
659 // This can be static or non-static field access | |
660 Bytecodes::Code code = field_access->code(); | |
661 | |
662 // We must load class, initialize class and resolvethe field | |
663 FieldAccessInfo result; // initialize class if needed | |
664 constantPoolHandle constants(THREAD, caller->constants()); | |
665 LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK_NULL); | |
666 return result.klass()(); | |
667 } | |
668 | |
669 | |
670 // | |
671 // This routine patches sites where a class wasn't loaded or | |
672 // initialized at the time the code was generated. It handles | |
673 // references to classes, fields and forcing of initialization. Most | |
674 // of the cases are straightforward and involving simply forcing | |
675 // resolution of a class, rewriting the instruction stream with the | |
676 // needed constant and replacing the call in this function with the | |
677 // patched code. The case for static field is more complicated since | |
678 // the thread which is in the process of initializing a class can | |
679 // access it's static fields but other threads can't so the code | |
680 // either has to deoptimize when this case is detected or execute a | |
681 // check that the current thread is the initializing thread. The | |
682 // current | |
683 // | |
684 // Patches basically look like this: | |
685 // | |
686 // | |
687 // patch_site: jmp patch stub ;; will be patched | |
688 // continue: ... | |
689 // ... | |
690 // ... | |
691 // ... | |
692 // | |
693 // They have a stub which looks like this: | |
694 // | |
695 // ;; patch body | |
696 // movl <const>, reg (for class constants) | |
697 // <or> movl [reg1 + <const>], reg (for field offsets) | |
698 // <or> movl reg, [reg1 + <const>] (for field offsets) | |
699 // <being_init offset> <bytes to copy> <bytes to skip> | |
700 // patch_stub: call Runtime1::patch_code (through a runtime stub) | |
701 // jmp patch_site | |
702 // | |
703 // | |
704 // A normal patch is done by rewriting the patch body, usually a move, | |
705 // and then copying it into place over top of the jmp instruction | |
706 // being careful to flush caches and doing it in an MP-safe way. The | |
707 // constants following the patch body are used to find various pieces | |
708 // of the patch relative to the call site for Runtime1::patch_code. | |
709 // The case for getstatic and putstatic is more complicated because | |
710 // getstatic and putstatic have special semantics when executing while | |
711 // the class is being initialized. getstatic/putstatic on a class | |
712 // which is being_initialized may be executed by the initializing | |
713 // thread but other threads have to block when they execute it. This | |
714 // is accomplished in compiled code by executing a test of the current | |
715 // thread against the initializing thread of the class. It's emitted | |
716 // as boilerplate in their stub which allows the patched code to be | |
717 // executed before it's copied back into the main body of the nmethod. | |
718 // | |
719 // being_init: get_thread(<tmp reg> | |
720 // cmpl [reg1 + <init_thread_offset>], <tmp reg> | |
721 // jne patch_stub | |
722 // movl [reg1 + <const>], reg (for field offsets) <or> | |
723 // movl reg, [reg1 + <const>] (for field offsets) | |
724 // jmp continue | |
725 // <being_init offset> <bytes to copy> <bytes to skip> | |
726 // patch_stub: jmp Runtim1::patch_code (through a runtime stub) | |
727 // jmp patch_site | |
728 // | |
729 // If the class is being initialized the patch body is rewritten and | |
730 // the patch site is rewritten to jump to being_init, instead of | |
731 // patch_stub. Whenever this code is executed it checks the current | |
732 // thread against the intializing thread so other threads will enter | |
733 // the runtime and end up blocked waiting the class to finish | |
734 // initializing inside the calls to resolve_field below. The | |
735 // initializing class will continue on it's way. Once the class is | |
736 // fully_initialized, the intializing_thread of the class becomes | |
737 // NULL, so the next thread to execute this code will fail the test, | |
738 // call into patch_code and complete the patching process by copying | |
739 // the patch body back into the main part of the nmethod and resume | |
740 // executing. | |
741 // | |
742 // | |
743 | |
744 JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id )) | |
745 NOT_PRODUCT(_patch_code_slowcase_cnt++;) | |
746 | |
747 ResourceMark rm(thread); | |
748 RegisterMap reg_map(thread, false); | |
749 frame runtime_frame = thread->last_frame(); | |
750 frame caller_frame = runtime_frame.sender(®_map); | |
751 | |
752 // last java frame on stack | |
753 vframeStream vfst(thread, true); | |
754 assert(!vfst.at_end(), "Java frame must exist"); | |
755 | |
756 methodHandle caller_method(THREAD, vfst.method()); | |
757 // Note that caller_method->code() may not be same as caller_code because of OSR's | |
758 // Note also that in the presence of inlining it is not guaranteed | |
759 // that caller_method() == caller_code->method() | |
760 | |
761 | |
762 int bci = vfst.bci(); | |
763 | |
764 Events::log("patch_code @ " INTPTR_FORMAT , caller_frame.pc()); | |
765 | |
766 Bytecodes::Code code = Bytecode_at(caller_method->bcp_from(bci))->java_code(); | |
767 | |
768 #ifndef PRODUCT | |
769 // this is used by assertions in the access_field_patching_id | |
770 BasicType patch_field_type = T_ILLEGAL; | |
771 #endif // PRODUCT | |
772 bool deoptimize_for_volatile = false; | |
773 int patch_field_offset = -1; | |
774 KlassHandle init_klass(THREAD, klassOop(NULL)); // klass needed by access_field_patching code | |
775 Handle load_klass(THREAD, NULL); // oop needed by load_klass_patching code | |
776 if (stub_id == Runtime1::access_field_patching_id) { | |
777 | |
778 Bytecode_field* field_access = Bytecode_field_at(caller_method(), caller_method->bcp_from(bci)); | |
779 FieldAccessInfo result; // initialize class if needed | |
780 Bytecodes::Code code = field_access->code(); | |
781 constantPoolHandle constants(THREAD, caller_method->constants()); | |
782 LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK); | |
783 patch_field_offset = result.field_offset(); | |
784 | |
785 // If we're patching a field which is volatile then at compile it | |
786 // must not have been know to be volatile, so the generated code | |
787 // isn't correct for a volatile reference. The nmethod has to be | |
788 // deoptimized so that the code can be regenerated correctly. | |
789 // This check is only needed for access_field_patching since this | |
790 // is the path for patching field offsets. load_klass is only | |
791 // used for patching references to oops which don't need special | |
792 // handling in the volatile case. | |
793 deoptimize_for_volatile = result.access_flags().is_volatile(); | |
794 | |
795 #ifndef PRODUCT | |
796 patch_field_type = result.field_type(); | |
797 #endif | |
798 } else if (stub_id == Runtime1::load_klass_patching_id) { | |
799 oop k; | |
800 switch (code) { | |
801 case Bytecodes::_putstatic: | |
802 case Bytecodes::_getstatic: | |
803 { klassOop klass = resolve_field_return_klass(caller_method, bci, CHECK); | |
804 // Save a reference to the class that has to be checked for initialization | |
805 init_klass = KlassHandle(THREAD, klass); | |
806 k = klass; | |
807 } | |
808 break; | |
809 case Bytecodes::_new: | |
810 { Bytecode_new* bnew = Bytecode_new_at(caller_method->bcp_from(bci)); | |
811 k = caller_method->constants()->klass_at(bnew->index(), CHECK); | |
812 } | |
813 break; | |
814 case Bytecodes::_multianewarray: | |
815 { Bytecode_multianewarray* mna = Bytecode_multianewarray_at(caller_method->bcp_from(bci)); | |
816 k = caller_method->constants()->klass_at(mna->index(), CHECK); | |
817 } | |
818 break; | |
819 case Bytecodes::_instanceof: | |
820 { Bytecode_instanceof* io = Bytecode_instanceof_at(caller_method->bcp_from(bci)); | |
821 k = caller_method->constants()->klass_at(io->index(), CHECK); | |
822 } | |
823 break; | |
824 case Bytecodes::_checkcast: | |
825 { Bytecode_checkcast* cc = Bytecode_checkcast_at(caller_method->bcp_from(bci)); | |
826 k = caller_method->constants()->klass_at(cc->index(), CHECK); | |
827 } | |
828 break; | |
829 case Bytecodes::_anewarray: | |
830 { Bytecode_anewarray* anew = Bytecode_anewarray_at(caller_method->bcp_from(bci)); | |
831 klassOop ek = caller_method->constants()->klass_at(anew->index(), CHECK); | |
832 k = Klass::cast(ek)->array_klass(CHECK); | |
833 } | |
834 break; | |
835 case Bytecodes::_ldc: | |
836 case Bytecodes::_ldc_w: | |
837 { | |
838 Bytecode_loadconstant* cc = Bytecode_loadconstant_at(caller_method(), | |
839 caller_method->bcp_from(bci)); | |
840 klassOop resolved = caller_method->constants()->klass_at(cc->index(), CHECK); | |
841 // ldc wants the java mirror. | |
842 k = resolved->klass_part()->java_mirror(); | |
843 } | |
844 break; | |
845 default: Unimplemented(); | |
846 } | |
847 // convert to handle | |
848 load_klass = Handle(THREAD, k); | |
849 } else { | |
850 ShouldNotReachHere(); | |
851 } | |
852 | |
853 if (deoptimize_for_volatile) { | |
854 // At compile time we assumed the field wasn't volatile but after | |
855 // loading it turns out it was volatile so we have to throw the | |
856 // compiled code out and let it be regenerated. | |
857 if (TracePatching) { | |
858 tty->print_cr("Deoptimizing for patching volatile field reference"); | |
859 } | |
860 VM_DeoptimizeFrame deopt(thread, caller_frame.id()); | |
861 VMThread::execute(&deopt); | |
862 | |
863 // Return to the now deoptimized frame. | |
864 } | |
865 | |
866 | |
867 // Now copy code back | |
868 | |
869 { | |
870 MutexLockerEx ml_patch (Patching_lock, Mutex::_no_safepoint_check_flag); | |
871 // | |
872 // Deoptimization may have happened while we waited for the lock. | |
873 // In that case we don't bother to do any patching we just return | |
874 // and let the deopt happen | |
875 if (!caller_is_deopted()) { | |
876 NativeGeneralJump* jump = nativeGeneralJump_at(caller_frame.pc()); | |
877 address instr_pc = jump->jump_destination(); | |
878 NativeInstruction* ni = nativeInstruction_at(instr_pc); | |
879 if (ni->is_jump() ) { | |
880 // the jump has not been patched yet | |
881 // The jump destination is slow case and therefore not part of the stubs | |
882 // (stubs are only for StaticCalls) | |
883 | |
884 // format of buffer | |
885 // .... | |
886 // instr byte 0 <-- copy_buff | |
887 // instr byte 1 | |
888 // .. | |
889 // instr byte n-1 | |
890 // n | |
891 // .... <-- call destination | |
892 | |
893 address stub_location = caller_frame.pc() + PatchingStub::patch_info_offset(); | |
894 unsigned char* byte_count = (unsigned char*) (stub_location - 1); | |
895 unsigned char* byte_skip = (unsigned char*) (stub_location - 2); | |
896 unsigned char* being_initialized_entry_offset = (unsigned char*) (stub_location - 3); | |
897 address copy_buff = stub_location - *byte_skip - *byte_count; | |
898 address being_initialized_entry = stub_location - *being_initialized_entry_offset; | |
899 if (TracePatching) { | |
900 tty->print_cr(" Patching %s at bci %d at address 0x%x (%s)", Bytecodes::name(code), bci, | |
901 instr_pc, (stub_id == Runtime1::access_field_patching_id) ? "field" : "klass"); | |
902 nmethod* caller_code = CodeCache::find_nmethod(caller_frame.pc()); | |
903 assert(caller_code != NULL, "nmethod not found"); | |
904 | |
905 // NOTE we use pc() not original_pc() because we already know they are | |
906 // identical otherwise we'd have never entered this block of code | |
907 | |
908 OopMap* map = caller_code->oop_map_for_return_address(caller_frame.pc()); | |
909 assert(map != NULL, "null check"); | |
910 map->print(); | |
911 tty->cr(); | |
912 | |
913 Disassembler::decode(copy_buff, copy_buff + *byte_count, tty); | |
914 } | |
915 // depending on the code below, do_patch says whether to copy the patch body back into the nmethod | |
916 bool do_patch = true; | |
917 if (stub_id == Runtime1::access_field_patching_id) { | |
918 // The offset may not be correct if the class was not loaded at code generation time. | |
919 // Set it now. | |
920 NativeMovRegMem* n_move = nativeMovRegMem_at(copy_buff); | |
921 assert(n_move->offset() == 0 || (n_move->offset() == 4 && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG)), "illegal offset for type"); | |
922 assert(patch_field_offset >= 0, "illegal offset"); | |
923 n_move->add_offset_in_bytes(patch_field_offset); | |
924 } else if (stub_id == Runtime1::load_klass_patching_id) { | |
925 // If a getstatic or putstatic is referencing a klass which | |
926 // isn't fully initialized, the patch body isn't copied into | |
927 // place until initialization is complete. In this case the | |
928 // patch site is setup so that any threads besides the | |
929 // initializing thread are forced to come into the VM and | |
930 // block. | |
931 do_patch = (code != Bytecodes::_getstatic && code != Bytecodes::_putstatic) || | |
932 instanceKlass::cast(init_klass())->is_initialized(); | |
933 NativeGeneralJump* jump = nativeGeneralJump_at(instr_pc); | |
934 if (jump->jump_destination() == being_initialized_entry) { | |
935 assert(do_patch == true, "initialization must be complete at this point"); | |
936 } else { | |
937 // patch the instruction <move reg, klass> | |
938 NativeMovConstReg* n_copy = nativeMovConstReg_at(copy_buff); | |
939 assert(n_copy->data() == 0, "illegal init value"); | |
940 assert(load_klass() != NULL, "klass not set"); | |
941 n_copy->set_data((intx) (load_klass())); | |
942 | |
943 if (TracePatching) { | |
944 Disassembler::decode(copy_buff, copy_buff + *byte_count, tty); | |
945 } | |
946 | |
947 #ifdef SPARC | |
948 // Update the oop location in the nmethod with the proper | |
949 // oop. When the code was generated, a NULL was stuffed | |
950 // in the oop table and that table needs to be update to | |
951 // have the right value. On intel the value is kept | |
952 // directly in the instruction instead of in the oop | |
953 // table, so set_data above effectively updated the value. | |
954 nmethod* nm = CodeCache::find_nmethod(instr_pc); | |
955 assert(nm != NULL, "invalid nmethod_pc"); | |
956 RelocIterator oops(nm, copy_buff, copy_buff + 1); | |
957 bool found = false; | |
958 while (oops.next() && !found) { | |
959 if (oops.type() == relocInfo::oop_type) { | |
960 oop_Relocation* r = oops.oop_reloc(); | |
961 oop* oop_adr = r->oop_addr(); | |
962 *oop_adr = load_klass(); | |
963 r->fix_oop_relocation(); | |
964 found = true; | |
965 } | |
966 } | |
967 assert(found, "the oop must exist!"); | |
968 #endif | |
969 | |
970 } | |
971 } else { | |
972 ShouldNotReachHere(); | |
973 } | |
974 if (do_patch) { | |
975 // replace instructions | |
976 // first replace the tail, then the call | |
977 for (int i = NativeCall::instruction_size; i < *byte_count; i++) { | |
978 address ptr = copy_buff + i; | |
979 int a_byte = (*ptr) & 0xFF; | |
980 address dst = instr_pc + i; | |
981 *(unsigned char*)dst = (unsigned char) a_byte; | |
982 } | |
983 ICache::invalidate_range(instr_pc, *byte_count); | |
984 NativeGeneralJump::replace_mt_safe(instr_pc, copy_buff); | |
985 | |
986 if (stub_id == Runtime1::load_klass_patching_id) { | |
987 // update relocInfo to oop | |
988 nmethod* nm = CodeCache::find_nmethod(instr_pc); | |
989 assert(nm != NULL, "invalid nmethod_pc"); | |
990 | |
991 // The old patch site is now a move instruction so update | |
992 // the reloc info so that it will get updated during | |
993 // future GCs. | |
994 RelocIterator iter(nm, (address)instr_pc, (address)(instr_pc + 1)); | |
995 relocInfo::change_reloc_info_for_address(&iter, (address) instr_pc, | |
996 relocInfo::none, relocInfo::oop_type); | |
997 #ifdef SPARC | |
998 // Sparc takes two relocations for an oop so update the second one. | |
999 address instr_pc2 = instr_pc + NativeMovConstReg::add_offset; | |
1000 RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1); | |
1001 relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2, | |
1002 relocInfo::none, relocInfo::oop_type); | |
1003 #endif | |
1004 } | |
1005 | |
1006 } else { | |
1007 ICache::invalidate_range(copy_buff, *byte_count); | |
1008 NativeGeneralJump::insert_unconditional(instr_pc, being_initialized_entry); | |
1009 } | |
1010 } | |
1011 } | |
1012 } | |
1013 JRT_END | |
1014 | |
1015 // | |
1016 // Entry point for compiled code. We want to patch a nmethod. | |
1017 // We don't do a normal VM transition here because we want to | |
1018 // know after the patching is complete and any safepoint(s) are taken | |
1019 // if the calling nmethod was deoptimized. We do this by calling a | |
1020 // helper method which does the normal VM transition and when it | |
1021 // completes we can check for deoptimization. This simplifies the | |
1022 // assembly code in the cpu directories. | |
1023 // | |
1024 int Runtime1::move_klass_patching(JavaThread* thread) { | |
1025 // | |
1026 // NOTE: we are still in Java | |
1027 // | |
1028 Thread* THREAD = thread; | |
1029 debug_only(NoHandleMark nhm;) | |
1030 { | |
1031 // Enter VM mode | |
1032 | |
1033 ResetNoHandleMark rnhm; | |
1034 patch_code(thread, load_klass_patching_id); | |
1035 } | |
1036 // Back in JAVA, use no oops DON'T safepoint | |
1037 | |
1038 // Return true if calling code is deoptimized | |
1039 | |
1040 return caller_is_deopted(); | |
1041 } | |
1042 | |
1043 // | |
1044 // Entry point for compiled code. We want to patch a nmethod. | |
1045 // We don't do a normal VM transition here because we want to | |
1046 // know after the patching is complete and any safepoint(s) are taken | |
1047 // if the calling nmethod was deoptimized. We do this by calling a | |
1048 // helper method which does the normal VM transition and when it | |
1049 // completes we can check for deoptimization. This simplifies the | |
1050 // assembly code in the cpu directories. | |
1051 // | |
1052 | |
1053 int Runtime1::access_field_patching(JavaThread* thread) { | |
1054 // | |
1055 // NOTE: we are still in Java | |
1056 // | |
1057 Thread* THREAD = thread; | |
1058 debug_only(NoHandleMark nhm;) | |
1059 { | |
1060 // Enter VM mode | |
1061 | |
1062 ResetNoHandleMark rnhm; | |
1063 patch_code(thread, access_field_patching_id); | |
1064 } | |
1065 // Back in JAVA, use no oops DON'T safepoint | |
1066 | |
1067 // Return true if calling code is deoptimized | |
1068 | |
1069 return caller_is_deopted(); | |
1070 JRT_END | |
1071 | |
1072 | |
1073 JRT_LEAF(void, Runtime1::trace_block_entry(jint block_id)) | |
1074 // for now we just print out the block id | |
1075 tty->print("%d ", block_id); | |
1076 JRT_END | |
1077 | |
1078 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1079 // Array copy return codes. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1080 enum { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1081 ac_failed = -1, // arraycopy failed |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1082 ac_ok = 0 // arraycopy succeeded |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1083 }; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1084 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1085 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1086 template <class T> int obj_arraycopy_work(oopDesc* src, T* src_addr, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1087 oopDesc* dst, T* dst_addr, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1088 int length) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1089 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1090 // For performance reasons, we assume we are using a card marking write |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1091 // barrier. The assert will fail if this is not the case. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1092 // Note that we use the non-virtual inlineable variant of write_ref_array. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1093 BarrierSet* bs = Universe::heap()->barrier_set(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1094 assert(bs->has_write_ref_array_opt(), |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1095 "Barrier set must have ref array opt"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1096 if (src == dst) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1097 // same object, no check |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1098 Copy::conjoint_oops_atomic(src_addr, dst_addr, length); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1099 bs->write_ref_array(MemRegion((HeapWord*)dst_addr, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1100 (HeapWord*)(dst_addr + length))); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1101 return ac_ok; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1102 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1103 klassOop bound = objArrayKlass::cast(dst->klass())->element_klass(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1104 klassOop stype = objArrayKlass::cast(src->klass())->element_klass(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1105 if (stype == bound || Klass::cast(stype)->is_subtype_of(bound)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1106 // Elements are guaranteed to be subtypes, so no check necessary |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1107 Copy::conjoint_oops_atomic(src_addr, dst_addr, length); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1108 bs->write_ref_array(MemRegion((HeapWord*)dst_addr, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1109 (HeapWord*)(dst_addr + length))); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1110 return ac_ok; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1111 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1112 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1113 return ac_failed; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1114 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1115 |
0 | 1116 // fast and direct copy of arrays; returning -1, means that an exception may be thrown |
1117 // and we did not copy anything | |
1118 JRT_LEAF(int, Runtime1::arraycopy(oopDesc* src, int src_pos, oopDesc* dst, int dst_pos, int length)) | |
1119 #ifndef PRODUCT | |
1120 _generic_arraycopy_cnt++; // Slow-path oop array copy | |
1121 #endif | |
1122 | |
1123 if (src == NULL || dst == NULL || src_pos < 0 || dst_pos < 0 || length < 0) return ac_failed; | |
1124 if (!dst->is_array() || !src->is_array()) return ac_failed; | |
1125 if ((unsigned int) arrayOop(src)->length() < (unsigned int)src_pos + (unsigned int)length) return ac_failed; | |
1126 if ((unsigned int) arrayOop(dst)->length() < (unsigned int)dst_pos + (unsigned int)length) return ac_failed; | |
1127 | |
1128 if (length == 0) return ac_ok; | |
1129 if (src->is_typeArray()) { | |
1130 const klassOop klass_oop = src->klass(); | |
1131 if (klass_oop != dst->klass()) return ac_failed; | |
1132 typeArrayKlass* klass = typeArrayKlass::cast(klass_oop); | |
1133 const int l2es = klass->log2_element_size(); | |
1134 const int ihs = klass->array_header_in_bytes() / wordSize; | |
1135 char* src_addr = (char*) ((oopDesc**)src + ihs) + (src_pos << l2es); | |
1136 char* dst_addr = (char*) ((oopDesc**)dst + ihs) + (dst_pos << l2es); | |
1137 // Potential problem: memmove is not guaranteed to be word atomic | |
1138 // Revisit in Merlin | |
1139 memmove(dst_addr, src_addr, length << l2es); | |
1140 return ac_ok; | |
1141 } else if (src->is_objArray() && dst->is_objArray()) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1142 if (UseCompressedOops) { // will need for tiered |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1143 narrowOop *src_addr = objArrayOop(src)->obj_at_addr<narrowOop>(src_pos); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1144 narrowOop *dst_addr = objArrayOop(dst)->obj_at_addr<narrowOop>(dst_pos); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1145 return obj_arraycopy_work(src, src_addr, dst, dst_addr, length); |
0 | 1146 } else { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1147 oop *src_addr = objArrayOop(src)->obj_at_addr<oop>(src_pos); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1148 oop *dst_addr = objArrayOop(dst)->obj_at_addr<oop>(dst_pos); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1149 return obj_arraycopy_work(src, src_addr, dst, dst_addr, length); |
0 | 1150 } |
1151 } | |
1152 return ac_failed; | |
1153 JRT_END | |
1154 | |
1155 | |
1156 JRT_LEAF(void, Runtime1::primitive_arraycopy(HeapWord* src, HeapWord* dst, int length)) | |
1157 #ifndef PRODUCT | |
1158 _primitive_arraycopy_cnt++; | |
1159 #endif | |
1160 | |
1161 if (length == 0) return; | |
1162 // Not guaranteed to be word atomic, but that doesn't matter | |
1163 // for anything but an oop array, which is covered by oop_arraycopy. | |
1164 Copy::conjoint_bytes(src, dst, length); | |
1165 JRT_END | |
1166 | |
1167 JRT_LEAF(void, Runtime1::oop_arraycopy(HeapWord* src, HeapWord* dst, int num)) | |
1168 #ifndef PRODUCT | |
1169 _oop_arraycopy_cnt++; | |
1170 #endif | |
1171 | |
1172 if (num == 0) return; | |
1173 Copy::conjoint_oops_atomic((oop*) src, (oop*) dst, num); | |
1174 BarrierSet* bs = Universe::heap()->barrier_set(); | |
1175 bs->write_ref_array(MemRegion(dst, dst + num)); | |
1176 JRT_END | |
1177 | |
1178 | |
1179 #ifndef PRODUCT | |
1180 void Runtime1::print_statistics() { | |
1181 tty->print_cr("C1 Runtime statistics:"); | |
1182 tty->print_cr(" _resolve_invoke_virtual_cnt: %d", SharedRuntime::_resolve_virtual_ctr); | |
1183 tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %d", SharedRuntime::_resolve_opt_virtual_ctr); | |
1184 tty->print_cr(" _resolve_invoke_static_cnt: %d", SharedRuntime::_resolve_static_ctr); | |
1185 tty->print_cr(" _handle_wrong_method_cnt: %d", SharedRuntime::_wrong_method_ctr); | |
1186 tty->print_cr(" _ic_miss_cnt: %d", SharedRuntime::_ic_miss_ctr); | |
1187 tty->print_cr(" _generic_arraycopy_cnt: %d", _generic_arraycopy_cnt); | |
1188 tty->print_cr(" _primitive_arraycopy_cnt: %d", _primitive_arraycopy_cnt); | |
1189 tty->print_cr(" _oop_arraycopy_cnt: %d", _oop_arraycopy_cnt); | |
1190 tty->print_cr(" _arraycopy_slowcase_cnt: %d", _arraycopy_slowcase_cnt); | |
1191 | |
1192 tty->print_cr(" _new_type_array_slowcase_cnt: %d", _new_type_array_slowcase_cnt); | |
1193 tty->print_cr(" _new_object_array_slowcase_cnt: %d", _new_object_array_slowcase_cnt); | |
1194 tty->print_cr(" _new_instance_slowcase_cnt: %d", _new_instance_slowcase_cnt); | |
1195 tty->print_cr(" _new_multi_array_slowcase_cnt: %d", _new_multi_array_slowcase_cnt); | |
1196 tty->print_cr(" _monitorenter_slowcase_cnt: %d", _monitorenter_slowcase_cnt); | |
1197 tty->print_cr(" _monitorexit_slowcase_cnt: %d", _monitorexit_slowcase_cnt); | |
1198 tty->print_cr(" _patch_code_slowcase_cnt: %d", _patch_code_slowcase_cnt); | |
1199 | |
1200 tty->print_cr(" _throw_range_check_exception_count: %d:", _throw_range_check_exception_count); | |
1201 tty->print_cr(" _throw_index_exception_count: %d:", _throw_index_exception_count); | |
1202 tty->print_cr(" _throw_div0_exception_count: %d:", _throw_div0_exception_count); | |
1203 tty->print_cr(" _throw_null_pointer_exception_count: %d:", _throw_null_pointer_exception_count); | |
1204 tty->print_cr(" _throw_class_cast_exception_count: %d:", _throw_class_cast_exception_count); | |
1205 tty->print_cr(" _throw_incompatible_class_change_error_count: %d:", _throw_incompatible_class_change_error_count); | |
1206 tty->print_cr(" _throw_array_store_exception_count: %d:", _throw_array_store_exception_count); | |
1207 tty->print_cr(" _throw_count: %d:", _throw_count); | |
1208 | |
1209 SharedRuntime::print_ic_miss_histogram(); | |
1210 tty->cr(); | |
1211 } | |
1212 #endif // PRODUCT |