src/share/vm/opto/runtime.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 8604
04d83ba48607
child 9041
95a08233f46c
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

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

mercurial