Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/opto/runtime.cpp
+++ new/src/share/vm/opto/runtime.cpp
1 1 /*
2 2 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "classfile/systemDictionary.hpp"
27 27 #include "classfile/vmSymbols.hpp"
28 28 #include "code/compiledIC.hpp"
29 29 #include "code/icBuffer.hpp"
30 30 #include "code/nmethod.hpp"
31 31 #include "code/pcDesc.hpp"
32 32 #include "code/scopeDesc.hpp"
33 33 #include "code/vtableStubs.hpp"
34 34 #include "compiler/compileBroker.hpp"
35 35 #include "compiler/compilerOracle.hpp"
36 36 #include "compiler/oopMap.hpp"
37 37 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
38 38 #include "gc_implementation/g1/heapRegion.hpp"
39 39 #include "gc_interface/collectedHeap.hpp"
40 40 #include "interpreter/bytecode.hpp"
41 41 #include "interpreter/interpreter.hpp"
42 42 #include "interpreter/linkResolver.hpp"
43 43 #include "memory/barrierSet.hpp"
44 44 #include "memory/gcLocker.inline.hpp"
45 45 #include "memory/oopFactory.hpp"
46 46 #include "oops/objArrayKlass.hpp"
47 47 #include "oops/oop.inline.hpp"
48 48 #include "opto/addnode.hpp"
49 49 #include "opto/callnode.hpp"
50 50 #include "opto/cfgnode.hpp"
51 51 #include "opto/connode.hpp"
52 52 #include "opto/graphKit.hpp"
53 53 #include "opto/machnode.hpp"
54 54 #include "opto/matcher.hpp"
55 55 #include "opto/memnode.hpp"
56 56 #include "opto/mulnode.hpp"
57 57 #include "opto/runtime.hpp"
58 58 #include "opto/subnode.hpp"
59 59 #include "runtime/fprofiler.hpp"
60 60 #include "runtime/handles.inline.hpp"
61 61 #include "runtime/interfaceSupport.hpp"
62 62 #include "runtime/javaCalls.hpp"
63 63 #include "runtime/sharedRuntime.hpp"
64 64 #include "runtime/signature.hpp"
65 65 #include "runtime/threadCritical.hpp"
66 66 #include "runtime/vframe.hpp"
67 67 #include "runtime/vframeArray.hpp"
68 68 #include "runtime/vframe_hp.hpp"
69 69 #include "utilities/copy.hpp"
70 70 #include "utilities/preserveException.hpp"
71 71 #ifdef TARGET_ARCH_MODEL_x86_32
72 72 # include "adfiles/ad_x86_32.hpp"
73 73 #endif
74 74 #ifdef TARGET_ARCH_MODEL_x86_64
75 75 # include "adfiles/ad_x86_64.hpp"
76 76 #endif
77 77 #ifdef TARGET_ARCH_MODEL_sparc
78 78 # include "adfiles/ad_sparc.hpp"
79 79 #endif
80 80 #ifdef TARGET_ARCH_MODEL_zero
81 81 # include "adfiles/ad_zero.hpp"
82 82 #endif
83 83 #ifdef TARGET_ARCH_MODEL_arm
84 84 # include "adfiles/ad_arm.hpp"
85 85 #endif
86 86 #ifdef TARGET_ARCH_MODEL_ppc
87 87 # include "adfiles/ad_ppc.hpp"
88 88 #endif
89 89
90 90
91 91 // For debugging purposes:
92 92 // To force FullGCALot inside a runtime function, add the following two lines
93 93 //
94 94 // Universe::release_fullgc_alot_dummy();
95 95 // MarkSweep::invoke(0, "Debugging");
96 96 //
97 97 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
98 98
↓ open down ↓ |
98 lines elided |
↑ open up ↑ |
99 99
100 100
101 101
102 102 // Compiled code entry points
103 103 address OptoRuntime::_new_instance_Java = NULL;
104 104 address OptoRuntime::_new_array_Java = NULL;
105 105 address OptoRuntime::_multianewarray2_Java = NULL;
106 106 address OptoRuntime::_multianewarray3_Java = NULL;
107 107 address OptoRuntime::_multianewarray4_Java = NULL;
108 108 address OptoRuntime::_multianewarray5_Java = NULL;
109 +address OptoRuntime::_multianewarrayN_Java = NULL;
109 110 address OptoRuntime::_g1_wb_pre_Java = NULL;
110 111 address OptoRuntime::_g1_wb_post_Java = NULL;
111 112 address OptoRuntime::_vtable_must_compile_Java = NULL;
112 113 address OptoRuntime::_complete_monitor_locking_Java = NULL;
113 114 address OptoRuntime::_rethrow_Java = NULL;
114 115
115 116 address OptoRuntime::_slow_arraycopy_Java = NULL;
116 117 address OptoRuntime::_register_finalizer_Java = NULL;
117 118
118 119 # ifdef ENABLE_ZAP_DEAD_LOCALS
119 120 address OptoRuntime::_zap_dead_Java_locals_Java = NULL;
120 121 address OptoRuntime::_zap_dead_native_locals_Java = NULL;
121 122 # endif
122 123
123 124 ExceptionBlob* OptoRuntime::_exception_blob;
124 125
125 126 // This should be called in an assertion at the start of OptoRuntime routines
126 127 // which are entered from compiled code (all of them)
127 128 #ifndef PRODUCT
128 129 static bool check_compiled_frame(JavaThread* thread) {
129 130 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
130 131 #ifdef ASSERT
131 132 RegisterMap map(thread, false);
132 133 frame caller = thread->last_frame().sender(&map);
133 134 assert(caller.is_compiled_frame(), "not being called from compiled like code");
134 135 #endif /* ASSERT */
135 136 return true;
136 137 }
137 138 #endif
138 139
139 140
140 141 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, save_arg_regs, return_pc) \
141 142 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, save_arg_regs, return_pc)
142 143
143 144 void OptoRuntime::generate(ciEnv* env) {
144 145
145 146 generate_exception_blob();
146 147
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
147 148 // Note: tls: Means fetching the return oop out of the thread-local storage
148 149 //
149 150 // variable/name type-function-gen , runtime method ,fncy_jp, tls,save_args,retpc
150 151 // -------------------------------------------------------------------------------------------------------------------------------
151 152 gen(env, _new_instance_Java , new_instance_Type , new_instance_C , 0 , true , false, false);
152 153 gen(env, _new_array_Java , new_array_Type , new_array_C , 0 , true , false, false);
153 154 gen(env, _multianewarray2_Java , multianewarray2_Type , multianewarray2_C , 0 , true , false, false);
154 155 gen(env, _multianewarray3_Java , multianewarray3_Type , multianewarray3_C , 0 , true , false, false);
155 156 gen(env, _multianewarray4_Java , multianewarray4_Type , multianewarray4_C , 0 , true , false, false);
156 157 gen(env, _multianewarray5_Java , multianewarray5_Type , multianewarray5_C , 0 , true , false, false);
158 + gen(env, _multianewarrayN_Java , multianewarrayN_Type , multianewarrayN_C , 0 , true , false, false);
157 159 gen(env, _g1_wb_pre_Java , g1_wb_pre_Type , SharedRuntime::g1_wb_pre , 0 , false, false, false);
158 160 gen(env, _g1_wb_post_Java , g1_wb_post_Type , SharedRuntime::g1_wb_post , 0 , false, false, false);
159 161 gen(env, _complete_monitor_locking_Java , complete_monitor_enter_Type , SharedRuntime::complete_monitor_locking_C , 0 , false, false, false);
160 162 gen(env, _rethrow_Java , rethrow_Type , rethrow_C , 2 , true , false, true );
161 163
162 164 gen(env, _slow_arraycopy_Java , slow_arraycopy_Type , SharedRuntime::slow_arraycopy_C , 0 , false, false, false);
163 165 gen(env, _register_finalizer_Java , register_finalizer_Type , register_finalizer , 0 , false, false, false);
164 166
165 167 # ifdef ENABLE_ZAP_DEAD_LOCALS
166 168 gen(env, _zap_dead_Java_locals_Java , zap_dead_locals_Type , zap_dead_Java_locals_C , 0 , false, true , false );
167 169 gen(env, _zap_dead_native_locals_Java , zap_dead_locals_Type , zap_dead_native_locals_C , 0 , false, true , false );
168 170 # endif
169 171
170 172 }
171 173
172 174 #undef gen
173 175
174 176
175 177 // Helper method to do generation of RunTimeStub's
176 178 address OptoRuntime::generate_stub( ciEnv* env,
177 179 TypeFunc_generator gen, address C_function,
178 180 const char *name, int is_fancy_jump,
179 181 bool pass_tls,
180 182 bool save_argument_registers,
181 183 bool return_pc ) {
182 184 ResourceMark rm;
183 185 Compile C( env, gen, C_function, name, is_fancy_jump, pass_tls, save_argument_registers, return_pc );
184 186 return C.stub_entry_point();
185 187 }
186 188
187 189 const char* OptoRuntime::stub_name(address entry) {
188 190 #ifndef PRODUCT
189 191 CodeBlob* cb = CodeCache::find_blob(entry);
190 192 RuntimeStub* rs =(RuntimeStub *)cb;
191 193 assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");
192 194 return rs->name();
193 195 #else
194 196 // Fast implementation for product mode (maybe it should be inlined too)
195 197 return "runtime stub";
196 198 #endif
197 199 }
198 200
199 201
200 202 //=============================================================================
201 203 // Opto compiler runtime routines
202 204 //=============================================================================
203 205
204 206
205 207 //=============================allocation======================================
206 208 // We failed the fast-path allocation. Now we need to do a scavenge or GC
207 209 // and try allocation again.
208 210
209 211 void OptoRuntime::new_store_pre_barrier(JavaThread* thread) {
210 212 // After any safepoint, just before going back to compiled code,
211 213 // we inform the GC that we will be doing initializing writes to
212 214 // this object in the future without emitting card-marks, so
213 215 // GC may take any compensating steps.
214 216 // NOTE: Keep this code consistent with GraphKit::store_barrier.
215 217
216 218 oop new_obj = thread->vm_result();
217 219 if (new_obj == NULL) return;
218 220
219 221 assert(Universe::heap()->can_elide_tlab_store_barriers(),
220 222 "compiler must check this first");
221 223 // GC may decide to give back a safer copy of new_obj.
222 224 new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj);
223 225 thread->set_vm_result(new_obj);
224 226 }
225 227
226 228 // object allocation
227 229 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(klassOopDesc* klass, JavaThread* thread))
228 230 JRT_BLOCK;
229 231 #ifndef PRODUCT
230 232 SharedRuntime::_new_instance_ctr++; // new instance requires GC
231 233 #endif
232 234 assert(check_compiled_frame(thread), "incorrect caller");
233 235
234 236 // These checks are cheap to make and support reflective allocation.
235 237 int lh = Klass::cast(klass)->layout_helper();
236 238 if (Klass::layout_helper_needs_slow_path(lh)
237 239 || !instanceKlass::cast(klass)->is_initialized()) {
238 240 KlassHandle kh(THREAD, klass);
239 241 kh->check_valid_for_instantiation(false, THREAD);
240 242 if (!HAS_PENDING_EXCEPTION) {
241 243 instanceKlass::cast(kh())->initialize(THREAD);
242 244 }
243 245 if (!HAS_PENDING_EXCEPTION) {
244 246 klass = kh();
245 247 } else {
246 248 klass = NULL;
247 249 }
248 250 }
249 251
250 252 if (klass != NULL) {
251 253 // Scavenge and allocate an instance.
252 254 oop result = instanceKlass::cast(klass)->allocate_instance(THREAD);
253 255 thread->set_vm_result(result);
254 256
255 257 // Pass oops back through thread local storage. Our apparent type to Java
256 258 // is that we return an oop, but we can block on exit from this routine and
257 259 // a GC can trash the oop in C's return register. The generated stub will
258 260 // fetch the oop from TLS after any possible GC.
259 261 }
260 262
261 263 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
262 264 JRT_BLOCK_END;
263 265
264 266 if (GraphKit::use_ReduceInitialCardMarks()) {
265 267 // inform GC that we won't do card marks for initializing writes.
266 268 new_store_pre_barrier(thread);
267 269 }
268 270 JRT_END
269 271
270 272
271 273 // array allocation
272 274 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(klassOopDesc* array_type, int len, JavaThread *thread))
273 275 JRT_BLOCK;
274 276 #ifndef PRODUCT
275 277 SharedRuntime::_new_array_ctr++; // new array requires GC
276 278 #endif
277 279 assert(check_compiled_frame(thread), "incorrect caller");
278 280
279 281 // Scavenge and allocate an instance.
280 282 oop result;
281 283
282 284 if (Klass::cast(array_type)->oop_is_typeArray()) {
283 285 // The oopFactory likes to work with the element type.
284 286 // (We could bypass the oopFactory, since it doesn't add much value.)
285 287 BasicType elem_type = typeArrayKlass::cast(array_type)->element_type();
286 288 result = oopFactory::new_typeArray(elem_type, len, THREAD);
287 289 } else {
288 290 // Although the oopFactory likes to work with the elem_type,
289 291 // the compiler prefers the array_type, since it must already have
290 292 // that latter value in hand for the fast path.
291 293 klassOopDesc* elem_type = objArrayKlass::cast(array_type)->element_klass();
292 294 result = oopFactory::new_objArray(elem_type, len, THREAD);
293 295 }
294 296
295 297 // Pass oops back through thread local storage. Our apparent type to Java
296 298 // is that we return an oop, but we can block on exit from this routine and
297 299 // a GC can trash the oop in C's return register. The generated stub will
298 300 // fetch the oop from TLS after any possible GC.
299 301 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
300 302 thread->set_vm_result(result);
301 303 JRT_BLOCK_END;
302 304
303 305 if (GraphKit::use_ReduceInitialCardMarks()) {
304 306 // inform GC that we won't do card marks for initializing writes.
305 307 new_store_pre_barrier(thread);
306 308 }
307 309 JRT_END
308 310
309 311 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
310 312
311 313 // multianewarray for 2 dimensions
312 314 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(klassOopDesc* elem_type, int len1, int len2, JavaThread *thread))
313 315 #ifndef PRODUCT
314 316 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
315 317 #endif
316 318 assert(check_compiled_frame(thread), "incorrect caller");
317 319 assert(oop(elem_type)->is_klass(), "not a class");
318 320 jint dims[2];
319 321 dims[0] = len1;
320 322 dims[1] = len2;
321 323 oop obj = arrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
322 324 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
323 325 thread->set_vm_result(obj);
324 326 JRT_END
325 327
326 328 // multianewarray for 3 dimensions
327 329 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(klassOopDesc* elem_type, int len1, int len2, int len3, JavaThread *thread))
328 330 #ifndef PRODUCT
329 331 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
330 332 #endif
331 333 assert(check_compiled_frame(thread), "incorrect caller");
332 334 assert(oop(elem_type)->is_klass(), "not a class");
333 335 jint dims[3];
334 336 dims[0] = len1;
335 337 dims[1] = len2;
336 338 dims[2] = len3;
337 339 oop obj = arrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
338 340 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
339 341 thread->set_vm_result(obj);
340 342 JRT_END
341 343
342 344 // multianewarray for 4 dimensions
343 345 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, JavaThread *thread))
344 346 #ifndef PRODUCT
345 347 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
346 348 #endif
347 349 assert(check_compiled_frame(thread), "incorrect caller");
348 350 assert(oop(elem_type)->is_klass(), "not a class");
349 351 jint dims[4];
350 352 dims[0] = len1;
351 353 dims[1] = len2;
352 354 dims[2] = len3;
353 355 dims[3] = len4;
354 356 oop obj = arrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
355 357 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
356 358 thread->set_vm_result(obj);
357 359 JRT_END
358 360
359 361 // multianewarray for 5 dimensions
360 362 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread *thread))
361 363 #ifndef PRODUCT
362 364 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension
363 365 #endif
364 366 assert(check_compiled_frame(thread), "incorrect caller");
365 367 assert(oop(elem_type)->is_klass(), "not a class");
366 368 jint dims[5];
↓ open down ↓ |
200 lines elided |
↑ open up ↑ |
367 369 dims[0] = len1;
368 370 dims[1] = len2;
369 371 dims[2] = len3;
370 372 dims[3] = len4;
371 373 dims[4] = len5;
372 374 oop obj = arrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
373 375 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
374 376 thread->set_vm_result(obj);
375 377 JRT_END
376 378
379 +JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(klassOopDesc* elem_type, arrayOopDesc* dims, JavaThread *thread))
380 + assert(check_compiled_frame(thread), "incorrect caller");
381 + assert(oop(elem_type)->is_klass(), "not a class");
382 + assert(oop(dims)->is_typeArray(), "not an array");
383 +
384 + ResourceMark rm;
385 + jint len = dims->length();
386 + assert(len > 0, "Dimensions array should contain data");
387 + jint *j_dims = typeArrayOop(dims)->int_at_addr(0);
388 + jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
389 + Copy::conjoint_jints_atomic(j_dims, c_dims, len);
390 +
391 + oop obj = arrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
392 + deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
393 + thread->set_vm_result(obj);
394 +JRT_END
395 +
396 +
377 397 const TypeFunc *OptoRuntime::new_instance_Type() {
378 398 // create input type (domain)
379 399 const Type **fields = TypeTuple::fields(1);
380 400 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
381 401 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
382 402
383 403 // create result type (range)
384 404 fields = TypeTuple::fields(1);
385 405 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
386 406
387 407 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
388 408
389 409 return TypeFunc::make(domain, range);
390 410 }
391 411
392 412
393 413 const TypeFunc *OptoRuntime::athrow_Type() {
394 414 // create input type (domain)
395 415 const Type **fields = TypeTuple::fields(1);
396 416 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
397 417 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
398 418
399 419 // create result type (range)
400 420 fields = TypeTuple::fields(0);
401 421
402 422 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
403 423
404 424 return TypeFunc::make(domain, range);
405 425 }
406 426
407 427
408 428 const TypeFunc *OptoRuntime::new_array_Type() {
409 429 // create input type (domain)
410 430 const Type **fields = TypeTuple::fields(2);
411 431 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
412 432 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size
413 433 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
414 434
415 435 // create result type (range)
416 436 fields = TypeTuple::fields(1);
417 437 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
418 438
419 439 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
420 440
421 441 return TypeFunc::make(domain, range);
422 442 }
423 443
424 444 const TypeFunc *OptoRuntime::multianewarray_Type(int ndim) {
425 445 // create input type (domain)
426 446 const int nargs = ndim + 1;
427 447 const Type **fields = TypeTuple::fields(nargs);
428 448 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
429 449 for( int i = 1; i < nargs; i++ )
430 450 fields[TypeFunc::Parms + i] = TypeInt::INT; // array size
431 451 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields);
432 452
433 453 // create result type (range)
434 454 fields = TypeTuple::fields(1);
435 455 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
436 456 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
437 457
438 458 return TypeFunc::make(domain, range);
439 459 }
440 460
441 461 const TypeFunc *OptoRuntime::multianewarray2_Type() {
442 462 return multianewarray_Type(2);
443 463 }
444 464
445 465 const TypeFunc *OptoRuntime::multianewarray3_Type() {
446 466 return multianewarray_Type(3);
↓ open down ↓ |
60 lines elided |
↑ open up ↑ |
447 467 }
448 468
449 469 const TypeFunc *OptoRuntime::multianewarray4_Type() {
450 470 return multianewarray_Type(4);
451 471 }
452 472
453 473 const TypeFunc *OptoRuntime::multianewarray5_Type() {
454 474 return multianewarray_Type(5);
455 475 }
456 476
477 +const TypeFunc *OptoRuntime::multianewarrayN_Type() {
478 + // create input type (domain)
479 + const Type **fields = TypeTuple::fields(2);
480 + fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
481 + fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // array of dim sizes
482 + const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
483 +
484 + // create result type (range)
485 + fields = TypeTuple::fields(1);
486 + fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
487 + const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
488 +
489 + return TypeFunc::make(domain, range);
490 +}
491 +
457 492 const TypeFunc *OptoRuntime::g1_wb_pre_Type() {
458 493 const Type **fields = TypeTuple::fields(2);
459 494 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
460 495 fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
461 496 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
462 497
463 498 // create result type (range)
464 499 fields = TypeTuple::fields(0);
465 500 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
466 501
467 502 return TypeFunc::make(domain, range);
468 503 }
469 504
470 505 const TypeFunc *OptoRuntime::g1_wb_post_Type() {
471 506
472 507 const Type **fields = TypeTuple::fields(2);
473 508 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Card addr
474 509 fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
475 510 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
476 511
477 512 // create result type (range)
478 513 fields = TypeTuple::fields(0);
479 514 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
480 515
481 516 return TypeFunc::make(domain, range);
482 517 }
483 518
484 519 const TypeFunc *OptoRuntime::uncommon_trap_Type() {
485 520 // create input type (domain)
486 521 const Type **fields = TypeTuple::fields(1);
487 522 // Symbol* name of class to be loaded
488 523 fields[TypeFunc::Parms+0] = TypeInt::INT;
489 524 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
490 525
491 526 // create result type (range)
492 527 fields = TypeTuple::fields(0);
493 528 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
494 529
495 530 return TypeFunc::make(domain, range);
496 531 }
497 532
498 533 # ifdef ENABLE_ZAP_DEAD_LOCALS
499 534 // Type used for stub generation for zap_dead_locals.
500 535 // No inputs or outputs
501 536 const TypeFunc *OptoRuntime::zap_dead_locals_Type() {
502 537 // create input type (domain)
503 538 const Type **fields = TypeTuple::fields(0);
504 539 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms,fields);
505 540
506 541 // create result type (range)
507 542 fields = TypeTuple::fields(0);
508 543 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms,fields);
509 544
510 545 return TypeFunc::make(domain,range);
511 546 }
512 547 # endif
513 548
514 549
515 550 //-----------------------------------------------------------------------------
516 551 // Monitor Handling
517 552 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {
518 553 // create input type (domain)
519 554 const Type **fields = TypeTuple::fields(2);
520 555 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
521 556 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
522 557 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
523 558
524 559 // create result type (range)
525 560 fields = TypeTuple::fields(0);
526 561
527 562 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
528 563
529 564 return TypeFunc::make(domain,range);
530 565 }
531 566
532 567
533 568 //-----------------------------------------------------------------------------
534 569 const TypeFunc *OptoRuntime::complete_monitor_exit_Type() {
535 570 // create input type (domain)
536 571 const Type **fields = TypeTuple::fields(2);
537 572 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
538 573 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
539 574 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
540 575
541 576 // create result type (range)
542 577 fields = TypeTuple::fields(0);
543 578
544 579 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
545 580
546 581 return TypeFunc::make(domain,range);
547 582 }
548 583
549 584 const TypeFunc* OptoRuntime::flush_windows_Type() {
550 585 // create input type (domain)
551 586 const Type** fields = TypeTuple::fields(1);
552 587 fields[TypeFunc::Parms+0] = NULL; // void
553 588 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
554 589
555 590 // create result type
556 591 fields = TypeTuple::fields(1);
557 592 fields[TypeFunc::Parms+0] = NULL; // void
558 593 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
559 594
560 595 return TypeFunc::make(domain, range);
561 596 }
562 597
563 598 const TypeFunc* OptoRuntime::l2f_Type() {
564 599 // create input type (domain)
565 600 const Type **fields = TypeTuple::fields(2);
566 601 fields[TypeFunc::Parms+0] = TypeLong::LONG;
567 602 fields[TypeFunc::Parms+1] = Type::HALF;
568 603 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
569 604
570 605 // create result type (range)
571 606 fields = TypeTuple::fields(1);
572 607 fields[TypeFunc::Parms+0] = Type::FLOAT;
573 608 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
574 609
575 610 return TypeFunc::make(domain, range);
576 611 }
577 612
578 613 const TypeFunc* OptoRuntime::modf_Type() {
579 614 const Type **fields = TypeTuple::fields(2);
580 615 fields[TypeFunc::Parms+0] = Type::FLOAT;
581 616 fields[TypeFunc::Parms+1] = Type::FLOAT;
582 617 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
583 618
584 619 // create result type (range)
585 620 fields = TypeTuple::fields(1);
586 621 fields[TypeFunc::Parms+0] = Type::FLOAT;
587 622
588 623 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
589 624
590 625 return TypeFunc::make(domain, range);
591 626 }
592 627
593 628 const TypeFunc *OptoRuntime::Math_D_D_Type() {
594 629 // create input type (domain)
595 630 const Type **fields = TypeTuple::fields(2);
596 631 // Symbol* name of class to be loaded
597 632 fields[TypeFunc::Parms+0] = Type::DOUBLE;
598 633 fields[TypeFunc::Parms+1] = Type::HALF;
599 634 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
600 635
601 636 // create result type (range)
602 637 fields = TypeTuple::fields(2);
603 638 fields[TypeFunc::Parms+0] = Type::DOUBLE;
604 639 fields[TypeFunc::Parms+1] = Type::HALF;
605 640 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
606 641
607 642 return TypeFunc::make(domain, range);
608 643 }
609 644
610 645 const TypeFunc* OptoRuntime::Math_DD_D_Type() {
611 646 const Type **fields = TypeTuple::fields(4);
612 647 fields[TypeFunc::Parms+0] = Type::DOUBLE;
613 648 fields[TypeFunc::Parms+1] = Type::HALF;
614 649 fields[TypeFunc::Parms+2] = Type::DOUBLE;
615 650 fields[TypeFunc::Parms+3] = Type::HALF;
616 651 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
617 652
618 653 // create result type (range)
619 654 fields = TypeTuple::fields(2);
620 655 fields[TypeFunc::Parms+0] = Type::DOUBLE;
621 656 fields[TypeFunc::Parms+1] = Type::HALF;
622 657 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
623 658
624 659 return TypeFunc::make(domain, range);
625 660 }
626 661
627 662 //-------------- currentTimeMillis
628 663
629 664 const TypeFunc* OptoRuntime::current_time_millis_Type() {
630 665 // create input type (domain)
631 666 const Type **fields = TypeTuple::fields(0);
632 667 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
633 668
634 669 // create result type (range)
635 670 fields = TypeTuple::fields(2);
636 671 fields[TypeFunc::Parms+0] = TypeLong::LONG;
637 672 fields[TypeFunc::Parms+1] = Type::HALF;
638 673 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
639 674
640 675 return TypeFunc::make(domain, range);
641 676 }
642 677
643 678 // arraycopy stub variations:
644 679 enum ArrayCopyType {
645 680 ac_fast, // void(ptr, ptr, size_t)
646 681 ac_checkcast, // int(ptr, ptr, size_t, size_t, ptr)
647 682 ac_slow, // void(ptr, int, ptr, int, int)
648 683 ac_generic // int(ptr, int, ptr, int, int)
649 684 };
650 685
651 686 static const TypeFunc* make_arraycopy_Type(ArrayCopyType act) {
652 687 // create input type (domain)
653 688 int num_args = (act == ac_fast ? 3 : 5);
654 689 int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0);
655 690 int argcnt = num_args;
656 691 LP64_ONLY(argcnt += num_size_args); // halfwords for lengths
657 692 const Type** fields = TypeTuple::fields(argcnt);
658 693 int argp = TypeFunc::Parms;
659 694 fields[argp++] = TypePtr::NOTNULL; // src
660 695 if (num_size_args == 0) {
661 696 fields[argp++] = TypeInt::INT; // src_pos
662 697 }
663 698 fields[argp++] = TypePtr::NOTNULL; // dest
664 699 if (num_size_args == 0) {
665 700 fields[argp++] = TypeInt::INT; // dest_pos
666 701 fields[argp++] = TypeInt::INT; // length
667 702 }
668 703 while (num_size_args-- > 0) {
669 704 fields[argp++] = TypeX_X; // size in whatevers (size_t)
670 705 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
671 706 }
672 707 if (act == ac_checkcast) {
673 708 fields[argp++] = TypePtr::NOTNULL; // super_klass
674 709 }
675 710 assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act");
676 711 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
677 712
678 713 // create result type if needed
679 714 int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0);
680 715 fields = TypeTuple::fields(1);
681 716 if (retcnt == 0)
682 717 fields[TypeFunc::Parms+0] = NULL; // void
683 718 else
684 719 fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed
685 720 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields);
686 721 return TypeFunc::make(domain, range);
687 722 }
688 723
689 724 const TypeFunc* OptoRuntime::fast_arraycopy_Type() {
690 725 // This signature is simple: Two base pointers and a size_t.
691 726 return make_arraycopy_Type(ac_fast);
692 727 }
693 728
694 729 const TypeFunc* OptoRuntime::checkcast_arraycopy_Type() {
695 730 // An extension of fast_arraycopy_Type which adds type checking.
696 731 return make_arraycopy_Type(ac_checkcast);
697 732 }
698 733
699 734 const TypeFunc* OptoRuntime::slow_arraycopy_Type() {
700 735 // This signature is exactly the same as System.arraycopy.
701 736 // There are no intptr_t (int/long) arguments.
702 737 return make_arraycopy_Type(ac_slow);
703 738 }
704 739
705 740 const TypeFunc* OptoRuntime::generic_arraycopy_Type() {
706 741 // This signature is like System.arraycopy, except that it returns status.
707 742 return make_arraycopy_Type(ac_generic);
708 743 }
709 744
710 745
711 746 const TypeFunc* OptoRuntime::array_fill_Type() {
712 747 // create input type (domain): pointer, int, size_t
713 748 const Type** fields = TypeTuple::fields(3 LP64_ONLY( + 1));
714 749 int argp = TypeFunc::Parms;
715 750 fields[argp++] = TypePtr::NOTNULL;
716 751 fields[argp++] = TypeInt::INT;
717 752 fields[argp++] = TypeX_X; // size in whatevers (size_t)
718 753 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
719 754 const TypeTuple *domain = TypeTuple::make(argp, fields);
720 755
721 756 // create result type
722 757 fields = TypeTuple::fields(1);
723 758 fields[TypeFunc::Parms+0] = NULL; // void
724 759 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
725 760
726 761 return TypeFunc::make(domain, range);
727 762 }
728 763
729 764 //------------- Interpreter state access for on stack replacement
730 765 const TypeFunc* OptoRuntime::osr_end_Type() {
731 766 // create input type (domain)
732 767 const Type **fields = TypeTuple::fields(1);
733 768 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf
734 769 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
735 770
736 771 // create result type
737 772 fields = TypeTuple::fields(1);
738 773 // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop
739 774 fields[TypeFunc::Parms+0] = NULL; // void
740 775 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
741 776 return TypeFunc::make(domain, range);
742 777 }
743 778
744 779 //-------------- methodData update helpers
745 780
746 781 const TypeFunc* OptoRuntime::profile_receiver_type_Type() {
747 782 // create input type (domain)
748 783 const Type **fields = TypeTuple::fields(2);
749 784 fields[TypeFunc::Parms+0] = TypeAryPtr::NOTNULL; // methodData pointer
750 785 fields[TypeFunc::Parms+1] = TypeInstPtr::BOTTOM; // receiver oop
751 786 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
752 787
753 788 // create result type
754 789 fields = TypeTuple::fields(1);
755 790 fields[TypeFunc::Parms+0] = NULL; // void
756 791 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
757 792 return TypeFunc::make(domain,range);
758 793 }
759 794
760 795 JRT_LEAF(void, OptoRuntime::profile_receiver_type_C(DataLayout* data, oopDesc* receiver))
761 796 if (receiver == NULL) return;
762 797 klassOop receiver_klass = receiver->klass();
763 798
764 799 intptr_t* mdp = ((intptr_t*)(data)) + DataLayout::header_size_in_cells();
765 800 int empty_row = -1; // free row, if any is encountered
766 801
767 802 // ReceiverTypeData* vc = new ReceiverTypeData(mdp);
768 803 for (uint row = 0; row < ReceiverTypeData::row_limit(); row++) {
769 804 // if (vc->receiver(row) == receiver_klass)
770 805 int receiver_off = ReceiverTypeData::receiver_cell_index(row);
771 806 intptr_t row_recv = *(mdp + receiver_off);
772 807 if (row_recv == (intptr_t) receiver_klass) {
773 808 // vc->set_receiver_count(row, vc->receiver_count(row) + DataLayout::counter_increment);
774 809 int count_off = ReceiverTypeData::receiver_count_cell_index(row);
775 810 *(mdp + count_off) += DataLayout::counter_increment;
776 811 return;
777 812 } else if (row_recv == 0) {
778 813 // else if (vc->receiver(row) == NULL)
779 814 empty_row = (int) row;
780 815 }
781 816 }
782 817
783 818 if (empty_row != -1) {
784 819 int receiver_off = ReceiverTypeData::receiver_cell_index(empty_row);
785 820 // vc->set_receiver(empty_row, receiver_klass);
786 821 *(mdp + receiver_off) = (intptr_t) receiver_klass;
787 822 // vc->set_receiver_count(empty_row, DataLayout::counter_increment);
788 823 int count_off = ReceiverTypeData::receiver_count_cell_index(empty_row);
789 824 *(mdp + count_off) = DataLayout::counter_increment;
790 825 } else {
791 826 // Receiver did not match any saved receiver and there is no empty row for it.
792 827 // Increment total counter to indicate polymorphic case.
793 828 intptr_t* count_p = (intptr_t*)(((byte*)(data)) + in_bytes(CounterData::count_offset()));
794 829 *count_p += DataLayout::counter_increment;
795 830 }
796 831 JRT_END
797 832
798 833 //-----------------------------------------------------------------------------
799 834 // implicit exception support.
800 835
801 836 static void report_null_exception_in_code_cache(address exception_pc) {
802 837 ResourceMark rm;
803 838 CodeBlob* n = CodeCache::find_blob(exception_pc);
804 839 if (n != NULL) {
805 840 tty->print_cr("#");
806 841 tty->print_cr("# HotSpot Runtime Error, null exception in generated code");
807 842 tty->print_cr("#");
808 843 tty->print_cr("# pc where exception happened = " INTPTR_FORMAT, exception_pc);
809 844
810 845 if (n->is_nmethod()) {
811 846 methodOop method = ((nmethod*)n)->method();
812 847 tty->print_cr("# Method where it happened %s.%s ", Klass::cast(method->method_holder())->name()->as_C_string(), method->name()->as_C_string());
813 848 tty->print_cr("#");
814 849 if (ShowMessageBoxOnError && UpdateHotSpotCompilerFileOnError) {
815 850 const char* title = "HotSpot Runtime Error";
816 851 const char* question = "Do you want to exclude compilation of this method in future runs?";
817 852 if (os::message_box(title, question)) {
818 853 CompilerOracle::append_comment_to_file("");
819 854 CompilerOracle::append_comment_to_file("Null exception in compiled code resulted in the following exclude");
820 855 CompilerOracle::append_comment_to_file("");
821 856 CompilerOracle::append_exclude_to_file(method);
822 857 tty->print_cr("#");
823 858 tty->print_cr("# %s has been updated to exclude the specified method", CompileCommandFile);
824 859 tty->print_cr("#");
825 860 }
826 861 }
827 862 fatal("Implicit null exception happened in compiled method");
828 863 } else {
829 864 n->print();
830 865 fatal("Implicit null exception happened in generated stub");
831 866 }
832 867 }
833 868 fatal("Implicit null exception at wrong place");
834 869 }
835 870
836 871
837 872 //-------------------------------------------------------------------------------------
838 873 // register policy
839 874
840 875 bool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) {
841 876 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
842 877 switch (register_save_policy[reg]) {
843 878 case 'C': return false; //SOC
844 879 case 'E': return true ; //SOE
845 880 case 'N': return false; //NS
846 881 case 'A': return false; //AS
847 882 }
848 883 ShouldNotReachHere();
849 884 return false;
850 885 }
851 886
852 887 //-----------------------------------------------------------------------
853 888 // Exceptions
854 889 //
855 890
856 891 static void trace_exception(oop exception_oop, address exception_pc, const char* msg) PRODUCT_RETURN;
857 892
858 893 // The method is an entry that is always called by a C++ method not
859 894 // directly from compiled code. Compiled code will call the C++ method following.
860 895 // We can't allow async exception to be installed during exception processing.
861 896 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* thread, nmethod* &nm))
862 897
863 898 // Do not confuse exception_oop with pending_exception. The exception_oop
864 899 // is only used to pass arguments into the method. Not for general
865 900 // exception handling. DO NOT CHANGE IT to use pending_exception, since
866 901 // the runtime stubs checks this on exit.
867 902 assert(thread->exception_oop() != NULL, "exception oop is found");
868 903 address handler_address = NULL;
869 904
870 905 Handle exception(thread, thread->exception_oop());
871 906
872 907 if (TraceExceptions) {
873 908 trace_exception(exception(), thread->exception_pc(), "");
874 909 }
875 910 // for AbortVMOnException flag
876 911 NOT_PRODUCT(Exceptions::debug_check_abort(exception));
877 912
878 913 #ifdef ASSERT
879 914 if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
880 915 // should throw an exception here
881 916 ShouldNotReachHere();
882 917 }
883 918 #endif
884 919
885 920
886 921 // new exception handling: this method is entered only from adapters
887 922 // exceptions from compiled java methods are handled in compiled code
888 923 // using rethrow node
889 924
890 925 address pc = thread->exception_pc();
891 926 nm = CodeCache::find_nmethod(pc);
892 927 assert(nm != NULL, "No NMethod found");
893 928 if (nm->is_native_method()) {
894 929 fatal("Native mathod should not have path to exception handling");
895 930 } else {
896 931 // we are switching to old paradigm: search for exception handler in caller_frame
897 932 // instead in exception handler of caller_frame.sender()
898 933
899 934 if (JvmtiExport::can_post_on_exceptions()) {
900 935 // "Full-speed catching" is not necessary here,
901 936 // since we're notifying the VM on every catch.
902 937 // Force deoptimization and the rest of the lookup
903 938 // will be fine.
904 939 deoptimize_caller_frame(thread, true);
905 940 }
906 941
907 942 // Check the stack guard pages. If enabled, look for handler in this frame;
908 943 // otherwise, forcibly unwind the frame.
909 944 //
910 945 // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate.
911 946 bool force_unwind = !thread->reguard_stack();
912 947 bool deopting = false;
913 948 if (nm->is_deopt_pc(pc)) {
914 949 deopting = true;
915 950 RegisterMap map(thread, false);
916 951 frame deoptee = thread->last_frame().sender(&map);
917 952 assert(deoptee.is_deoptimized_frame(), "must be deopted");
918 953 // Adjust the pc back to the original throwing pc
919 954 pc = deoptee.pc();
920 955 }
921 956
922 957 // If we are forcing an unwind because of stack overflow then deopt is
923 958 // irrelevant sice we are throwing the frame away anyway.
924 959
925 960 if (deopting && !force_unwind) {
926 961 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
927 962 } else {
928 963
929 964 handler_address =
930 965 force_unwind ? NULL : nm->handler_for_exception_and_pc(exception, pc);
931 966
932 967 if (handler_address == NULL) {
933 968 handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true);
934 969 assert (handler_address != NULL, "must have compiled handler");
935 970 // Update the exception cache only when the unwind was not forced.
936 971 if (!force_unwind) {
937 972 nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
938 973 }
939 974 } else {
940 975 assert(handler_address == SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true), "Must be the same");
941 976 }
942 977 }
943 978
944 979 thread->set_exception_pc(pc);
945 980 thread->set_exception_handler_pc(handler_address);
946 981 thread->set_exception_stack_size(0);
947 982
948 983 // Check if the exception PC is a MethodHandle call site.
949 984 thread->set_is_method_handle_return(nm->is_method_handle_return(pc));
950 985 }
951 986
952 987 // Restore correct return pc. Was saved above.
953 988 thread->set_exception_oop(exception());
954 989 return handler_address;
955 990
956 991 JRT_END
957 992
958 993 // We are entering here from exception_blob
959 994 // If there is a compiled exception handler in this method, we will continue there;
960 995 // otherwise we will unwind the stack and continue at the caller of top frame method
961 996 // Note we enter without the usual JRT wrapper. We will call a helper routine that
962 997 // will do the normal VM entry. We do it this way so that we can see if the nmethod
963 998 // we looked up the handler for has been deoptimized in the meantime. If it has been
964 999 // we must not use the handler and instread return the deopt blob.
965 1000 address OptoRuntime::handle_exception_C(JavaThread* thread) {
966 1001 //
967 1002 // We are in Java not VM and in debug mode we have a NoHandleMark
968 1003 //
969 1004 #ifndef PRODUCT
970 1005 SharedRuntime::_find_handler_ctr++; // find exception handler
971 1006 #endif
972 1007 debug_only(NoHandleMark __hm;)
973 1008 nmethod* nm = NULL;
974 1009 address handler_address = NULL;
975 1010 {
976 1011 // Enter the VM
977 1012
978 1013 ResetNoHandleMark rnhm;
979 1014 handler_address = handle_exception_C_helper(thread, nm);
980 1015 }
981 1016
982 1017 // Back in java: Use no oops, DON'T safepoint
983 1018
984 1019 // Now check to see if the handler we are returning is in a now
985 1020 // deoptimized frame
986 1021
987 1022 if (nm != NULL) {
988 1023 RegisterMap map(thread, false);
989 1024 frame caller = thread->last_frame().sender(&map);
990 1025 #ifdef ASSERT
991 1026 assert(caller.is_compiled_frame(), "must be");
992 1027 #endif // ASSERT
993 1028 if (caller.is_deoptimized_frame()) {
994 1029 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
995 1030 }
996 1031 }
997 1032 return handler_address;
998 1033 }
999 1034
1000 1035 //------------------------------rethrow----------------------------------------
1001 1036 // We get here after compiled code has executed a 'RethrowNode'. The callee
1002 1037 // is either throwing or rethrowing an exception. The callee-save registers
1003 1038 // have been restored, synchronized objects have been unlocked and the callee
1004 1039 // stack frame has been removed. The return address was passed in.
1005 1040 // Exception oop is passed as the 1st argument. This routine is then called
1006 1041 // from the stub. On exit, we know where to jump in the caller's code.
1007 1042 // After this C code exits, the stub will pop his frame and end in a jump
1008 1043 // (instead of a return). We enter the caller's default handler.
1009 1044 //
1010 1045 // This must be JRT_LEAF:
1011 1046 // - caller will not change its state as we cannot block on exit,
1012 1047 // therefore raw_exception_handler_for_return_address is all it takes
1013 1048 // to handle deoptimized blobs
1014 1049 //
1015 1050 // However, there needs to be a safepoint check in the middle! So compiled
1016 1051 // safepoints are completely watertight.
1017 1052 //
1018 1053 // Thus, it cannot be a leaf since it contains the No_GC_Verifier.
1019 1054 //
1020 1055 // *THIS IS NOT RECOMMENDED PROGRAMMING STYLE*
1021 1056 //
1022 1057 address OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) {
1023 1058 #ifndef PRODUCT
1024 1059 SharedRuntime::_rethrow_ctr++; // count rethrows
1025 1060 #endif
1026 1061 assert (exception != NULL, "should have thrown a NULLPointerException");
1027 1062 #ifdef ASSERT
1028 1063 if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
1029 1064 // should throw an exception here
1030 1065 ShouldNotReachHere();
1031 1066 }
1032 1067 #endif
1033 1068
1034 1069 thread->set_vm_result(exception);
1035 1070 // Frame not compiled (handles deoptimization blob)
1036 1071 return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc);
1037 1072 }
1038 1073
1039 1074
1040 1075 const TypeFunc *OptoRuntime::rethrow_Type() {
1041 1076 // create input type (domain)
1042 1077 const Type **fields = TypeTuple::fields(1);
1043 1078 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1044 1079 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1045 1080
1046 1081 // create result type (range)
1047 1082 fields = TypeTuple::fields(1);
1048 1083 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1049 1084 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
1050 1085
1051 1086 return TypeFunc::make(domain, range);
1052 1087 }
1053 1088
1054 1089
1055 1090 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) {
1056 1091 // Deoptimize frame
1057 1092 if (doit) {
1058 1093 // Called from within the owner thread, so no need for safepoint
1059 1094 RegisterMap reg_map(thread);
1060 1095 frame stub_frame = thread->last_frame();
1061 1096 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1062 1097 frame caller_frame = stub_frame.sender(®_map);
1063 1098
1064 1099 // bypass VM_DeoptimizeFrame and deoptimize the frame directly
1065 1100 Deoptimization::deoptimize_frame(thread, caller_frame.id());
1066 1101 }
1067 1102 }
1068 1103
1069 1104
1070 1105 const TypeFunc *OptoRuntime::register_finalizer_Type() {
1071 1106 // create input type (domain)
1072 1107 const Type **fields = TypeTuple::fields(1);
1073 1108 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
1074 1109 // // The JavaThread* is passed to each routine as the last argument
1075 1110 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
1076 1111 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1077 1112
1078 1113 // create result type (range)
1079 1114 fields = TypeTuple::fields(0);
1080 1115
1081 1116 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1082 1117
1083 1118 return TypeFunc::make(domain,range);
1084 1119 }
1085 1120
1086 1121
1087 1122 //-----------------------------------------------------------------------------
1088 1123 // Dtrace support. entry and exit probes have the same signature
1089 1124 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
1090 1125 // create input type (domain)
1091 1126 const Type **fields = TypeTuple::fields(2);
1092 1127 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1093 1128 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // methodOop; Method we are entering
1094 1129 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1095 1130
1096 1131 // create result type (range)
1097 1132 fields = TypeTuple::fields(0);
1098 1133
1099 1134 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1100 1135
1101 1136 return TypeFunc::make(domain,range);
1102 1137 }
1103 1138
1104 1139 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1105 1140 // create input type (domain)
1106 1141 const Type **fields = TypeTuple::fields(2);
1107 1142 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1108 1143 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
1109 1144
1110 1145 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1111 1146
1112 1147 // create result type (range)
1113 1148 fields = TypeTuple::fields(0);
1114 1149
1115 1150 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1116 1151
1117 1152 return TypeFunc::make(domain,range);
1118 1153 }
1119 1154
1120 1155
1121 1156 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* thread))
1122 1157 assert(obj->is_oop(), "must be a valid oop");
1123 1158 assert(obj->klass()->klass_part()->has_finalizer(), "shouldn't be here otherwise");
1124 1159 instanceKlass::register_finalizer(instanceOop(obj), CHECK);
1125 1160 JRT_END
1126 1161
1127 1162 //-----------------------------------------------------------------------------
1128 1163
1129 1164 NamedCounter * volatile OptoRuntime::_named_counters = NULL;
1130 1165
1131 1166 //
1132 1167 // dump the collected NamedCounters.
1133 1168 //
1134 1169 void OptoRuntime::print_named_counters() {
1135 1170 int total_lock_count = 0;
1136 1171 int eliminated_lock_count = 0;
1137 1172
1138 1173 NamedCounter* c = _named_counters;
1139 1174 while (c) {
1140 1175 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1141 1176 int count = c->count();
1142 1177 if (count > 0) {
1143 1178 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1144 1179 if (Verbose) {
1145 1180 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1146 1181 }
1147 1182 total_lock_count += count;
1148 1183 if (eliminated) {
1149 1184 eliminated_lock_count += count;
1150 1185 }
1151 1186 }
1152 1187 } else if (c->tag() == NamedCounter::BiasedLockingCounter) {
1153 1188 BiasedLockingCounters* blc = ((BiasedLockingNamedCounter*)c)->counters();
1154 1189 if (blc->nonzero()) {
1155 1190 tty->print_cr("%s", c->name());
1156 1191 blc->print_on(tty);
1157 1192 }
1158 1193 }
1159 1194 c = c->next();
1160 1195 }
1161 1196 if (total_lock_count > 0) {
1162 1197 tty->print_cr("dynamic locks: %d", total_lock_count);
1163 1198 if (eliminated_lock_count) {
1164 1199 tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
1165 1200 (int)(eliminated_lock_count * 100.0 / total_lock_count));
1166 1201 }
1167 1202 }
1168 1203 }
1169 1204
1170 1205 //
1171 1206 // Allocate a new NamedCounter. The JVMState is used to generate the
1172 1207 // name which consists of method@line for the inlining tree.
1173 1208 //
1174 1209
1175 1210 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
1176 1211 int max_depth = youngest_jvms->depth();
1177 1212
1178 1213 // Visit scopes from youngest to oldest.
1179 1214 bool first = true;
1180 1215 stringStream st;
1181 1216 for (int depth = max_depth; depth >= 1; depth--) {
1182 1217 JVMState* jvms = youngest_jvms->of_depth(depth);
1183 1218 ciMethod* m = jvms->has_method() ? jvms->method() : NULL;
1184 1219 if (!first) {
1185 1220 st.print(" ");
1186 1221 } else {
1187 1222 first = false;
1188 1223 }
1189 1224 int bci = jvms->bci();
1190 1225 if (bci < 0) bci = 0;
1191 1226 st.print("%s.%s@%d", m->holder()->name()->as_utf8(), m->name()->as_utf8(), bci);
1192 1227 // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
1193 1228 }
1194 1229 NamedCounter* c;
1195 1230 if (tag == NamedCounter::BiasedLockingCounter) {
1196 1231 c = new BiasedLockingNamedCounter(strdup(st.as_string()));
1197 1232 } else {
1198 1233 c = new NamedCounter(strdup(st.as_string()), tag);
1199 1234 }
1200 1235
1201 1236 // atomically add the new counter to the head of the list. We only
1202 1237 // add counters so this is safe.
1203 1238 NamedCounter* head;
1204 1239 do {
1205 1240 head = _named_counters;
1206 1241 c->set_next(head);
1207 1242 } while (Atomic::cmpxchg_ptr(c, &_named_counters, head) != head);
1208 1243 return c;
1209 1244 }
1210 1245
1211 1246 //-----------------------------------------------------------------------------
1212 1247 // Non-product code
1213 1248 #ifndef PRODUCT
1214 1249
1215 1250 int trace_exception_counter = 0;
1216 1251 static void trace_exception(oop exception_oop, address exception_pc, const char* msg) {
1217 1252 ttyLocker ttyl;
1218 1253 trace_exception_counter++;
1219 1254 tty->print("%d [Exception (%s): ", trace_exception_counter, msg);
1220 1255 exception_oop->print_value();
1221 1256 tty->print(" in ");
1222 1257 CodeBlob* blob = CodeCache::find_blob(exception_pc);
1223 1258 if (blob->is_nmethod()) {
1224 1259 ((nmethod*)blob)->method()->print_value();
1225 1260 } else if (blob->is_runtime_stub()) {
1226 1261 tty->print("<runtime-stub>");
1227 1262 } else {
1228 1263 tty->print("<unknown>");
1229 1264 }
1230 1265 tty->print(" at " INTPTR_FORMAT, exception_pc);
1231 1266 tty->print_cr("]");
1232 1267 }
1233 1268
1234 1269 #endif // PRODUCT
1235 1270
1236 1271
1237 1272 # ifdef ENABLE_ZAP_DEAD_LOCALS
1238 1273 // Called from call sites in compiled code with oop maps (actually safepoints)
1239 1274 // Zaps dead locals in first java frame.
1240 1275 // Is entry because may need to lock to generate oop maps
1241 1276 // Currently, only used for compiler frames, but someday may be used
1242 1277 // for interpreter frames, too.
1243 1278
1244 1279 int OptoRuntime::ZapDeadCompiledLocals_count = 0;
1245 1280
1246 1281 // avoid pointers to member funcs with these helpers
1247 1282 static bool is_java_frame( frame* f) { return f->is_java_frame(); }
1248 1283 static bool is_native_frame(frame* f) { return f->is_native_frame(); }
1249 1284
1250 1285
1251 1286 void OptoRuntime::zap_dead_java_or_native_locals(JavaThread* thread,
1252 1287 bool (*is_this_the_right_frame_to_zap)(frame*)) {
1253 1288 assert(JavaThread::current() == thread, "is this needed?");
1254 1289
1255 1290 if ( !ZapDeadCompiledLocals ) return;
1256 1291
1257 1292 bool skip = false;
1258 1293
1259 1294 if ( ZapDeadCompiledLocalsFirst == 0 ) ; // nothing special
1260 1295 else if ( ZapDeadCompiledLocalsFirst > ZapDeadCompiledLocals_count ) skip = true;
1261 1296 else if ( ZapDeadCompiledLocalsFirst == ZapDeadCompiledLocals_count )
1262 1297 warning("starting zapping after skipping");
1263 1298
1264 1299 if ( ZapDeadCompiledLocalsLast == -1 ) ; // nothing special
1265 1300 else if ( ZapDeadCompiledLocalsLast < ZapDeadCompiledLocals_count ) skip = true;
1266 1301 else if ( ZapDeadCompiledLocalsLast == ZapDeadCompiledLocals_count )
1267 1302 warning("about to zap last zap");
1268 1303
1269 1304 ++ZapDeadCompiledLocals_count; // counts skipped zaps, too
1270 1305
1271 1306 if ( skip ) return;
1272 1307
1273 1308 // find java frame and zap it
1274 1309
1275 1310 for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) {
1276 1311 if (is_this_the_right_frame_to_zap(sfs.current()) ) {
1277 1312 sfs.current()->zap_dead_locals(thread, sfs.register_map());
1278 1313 return;
1279 1314 }
1280 1315 }
1281 1316 warning("no frame found to zap in zap_dead_Java_locals_C");
1282 1317 }
1283 1318
1284 1319 JRT_LEAF(void, OptoRuntime::zap_dead_Java_locals_C(JavaThread* thread))
1285 1320 zap_dead_java_or_native_locals(thread, is_java_frame);
1286 1321 JRT_END
1287 1322
1288 1323 // The following does not work because for one thing, the
1289 1324 // thread state is wrong; it expects java, but it is native.
1290 1325 // Also, the invariants in a native stub are different and
1291 1326 // I'm not sure it is safe to have a MachCalRuntimeDirectNode
1292 1327 // in there.
1293 1328 // So for now, we do not zap in native stubs.
1294 1329
1295 1330 JRT_LEAF(void, OptoRuntime::zap_dead_native_locals_C(JavaThread* thread))
1296 1331 zap_dead_java_or_native_locals(thread, is_native_frame);
1297 1332 JRT_END
1298 1333
1299 1334 # endif
↓ open down ↓ |
833 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX