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