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