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