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