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