runtime.cpp revision 2073
0N/A/*
1472N/A * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "classfile/vmSymbols.hpp"
1879N/A#include "code/compiledIC.hpp"
1879N/A#include "code/icBuffer.hpp"
1879N/A#include "code/nmethod.hpp"
1879N/A#include "code/pcDesc.hpp"
1879N/A#include "code/scopeDesc.hpp"
1879N/A#include "code/vtableStubs.hpp"
1879N/A#include "compiler/compileBroker.hpp"
1879N/A#include "compiler/compilerOracle.hpp"
1879N/A#include "compiler/oopMap.hpp"
1879N/A#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
1879N/A#include "gc_implementation/g1/heapRegion.hpp"
1879N/A#include "gc_interface/collectedHeap.hpp"
1879N/A#include "interpreter/bytecode.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "interpreter/linkResolver.hpp"
1879N/A#include "memory/barrierSet.hpp"
1879N/A#include "memory/gcLocker.inline.hpp"
1879N/A#include "memory/oopFactory.hpp"
1879N/A#include "oops/objArrayKlass.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "opto/addnode.hpp"
1879N/A#include "opto/callnode.hpp"
1879N/A#include "opto/cfgnode.hpp"
1879N/A#include "opto/connode.hpp"
1879N/A#include "opto/graphKit.hpp"
1879N/A#include "opto/machnode.hpp"
1879N/A#include "opto/matcher.hpp"
1879N/A#include "opto/memnode.hpp"
1879N/A#include "opto/mulnode.hpp"
1879N/A#include "opto/runtime.hpp"
1879N/A#include "opto/subnode.hpp"
1879N/A#include "runtime/fprofiler.hpp"
1879N/A#include "runtime/handles.inline.hpp"
1879N/A#include "runtime/interfaceSupport.hpp"
1879N/A#include "runtime/javaCalls.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
1879N/A#include "runtime/signature.hpp"
1879N/A#include "runtime/threadCritical.hpp"
1879N/A#include "runtime/vframe.hpp"
1879N/A#include "runtime/vframeArray.hpp"
1879N/A#include "runtime/vframe_hp.hpp"
1879N/A#include "utilities/copy.hpp"
1879N/A#include "utilities/preserveException.hpp"
1879N/A#ifdef TARGET_ARCH_MODEL_x86_32
1879N/A# include "adfiles/ad_x86_32.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_x86_64
1879N/A# include "adfiles/ad_x86_64.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_sparc
1879N/A# include "adfiles/ad_sparc.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_zero
1879N/A# include "adfiles/ad_zero.hpp"
1879N/A#endif
2073N/A#ifdef TARGET_ARCH_MODEL_arm
2073N/A# include "adfiles/ad_arm.hpp"
2073N/A#endif
2073N/A#ifdef TARGET_ARCH_MODEL_ppc
2073N/A# include "adfiles/ad_ppc.hpp"
2073N/A#endif
0N/A
0N/A
0N/A// For debugging purposes:
0N/A// To force FullGCALot inside a runtime function, add the following two lines
0N/A//
0N/A// Universe::release_fullgc_alot_dummy();
0N/A// MarkSweep::invoke(0, "Debugging");
0N/A//
0N/A// At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
0N/A
0N/A
0N/A
0N/A
0N/A// Compiled code entry points
0N/Aaddress OptoRuntime::_new_instance_Java = NULL;
0N/Aaddress OptoRuntime::_new_array_Java = NULL;
0N/Aaddress OptoRuntime::_multianewarray2_Java = NULL;
0N/Aaddress OptoRuntime::_multianewarray3_Java = NULL;
0N/Aaddress OptoRuntime::_multianewarray4_Java = NULL;
0N/Aaddress OptoRuntime::_multianewarray5_Java = NULL;
342N/Aaddress OptoRuntime::_g1_wb_pre_Java = NULL;
342N/Aaddress OptoRuntime::_g1_wb_post_Java = NULL;
0N/Aaddress OptoRuntime::_vtable_must_compile_Java = NULL;
0N/Aaddress OptoRuntime::_complete_monitor_locking_Java = NULL;
0N/Aaddress OptoRuntime::_rethrow_Java = NULL;
0N/A
0N/Aaddress OptoRuntime::_slow_arraycopy_Java = NULL;
0N/Aaddress OptoRuntime::_register_finalizer_Java = NULL;
0N/A
0N/A# ifdef ENABLE_ZAP_DEAD_LOCALS
0N/Aaddress OptoRuntime::_zap_dead_Java_locals_Java = NULL;
0N/Aaddress OptoRuntime::_zap_dead_native_locals_Java = NULL;
0N/A# endif
0N/A
0N/A
0N/A// This should be called in an assertion at the start of OptoRuntime routines
0N/A// which are entered from compiled code (all of them)
0N/A#ifndef PRODUCT
0N/Astatic bool check_compiled_frame(JavaThread* thread) {
0N/A assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
0N/A#ifdef ASSERT
0N/A RegisterMap map(thread, false);
0N/A frame caller = thread->last_frame().sender(&map);
0N/A assert(caller.is_compiled_frame(), "not being called from compiled like code");
0N/A#endif /* ASSERT */
0N/A return true;
0N/A}
0N/A#endif
0N/A
0N/A
0N/A#define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, save_arg_regs, return_pc) \
0N/A var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, save_arg_regs, return_pc)
0N/A
0N/Avoid OptoRuntime::generate(ciEnv* env) {
0N/A
0N/A generate_exception_blob();
0N/A
0N/A // Note: tls: Means fetching the return oop out of the thread-local storage
0N/A //
0N/A // variable/name type-function-gen , runtime method ,fncy_jp, tls,save_args,retpc
0N/A // -------------------------------------------------------------------------------------------------------------------------------
0N/A gen(env, _new_instance_Java , new_instance_Type , new_instance_C , 0 , true , false, false);
0N/A gen(env, _new_array_Java , new_array_Type , new_array_C , 0 , true , false, false);
0N/A gen(env, _multianewarray2_Java , multianewarray2_Type , multianewarray2_C , 0 , true , false, false);
0N/A gen(env, _multianewarray3_Java , multianewarray3_Type , multianewarray3_C , 0 , true , false, false);
0N/A gen(env, _multianewarray4_Java , multianewarray4_Type , multianewarray4_C , 0 , true , false, false);
0N/A gen(env, _multianewarray5_Java , multianewarray5_Type , multianewarray5_C , 0 , true , false, false);
342N/A gen(env, _g1_wb_pre_Java , g1_wb_pre_Type , SharedRuntime::g1_wb_pre , 0 , false, false, false);
342N/A gen(env, _g1_wb_post_Java , g1_wb_post_Type , SharedRuntime::g1_wb_post , 0 , false, false, false);
0N/A gen(env, _complete_monitor_locking_Java , complete_monitor_enter_Type , SharedRuntime::complete_monitor_locking_C , 0 , false, false, false);
0N/A gen(env, _rethrow_Java , rethrow_Type , rethrow_C , 2 , true , false, true );
0N/A
0N/A gen(env, _slow_arraycopy_Java , slow_arraycopy_Type , SharedRuntime::slow_arraycopy_C , 0 , false, false, false);
0N/A gen(env, _register_finalizer_Java , register_finalizer_Type , register_finalizer , 0 , false, false, false);
0N/A
0N/A# ifdef ENABLE_ZAP_DEAD_LOCALS
0N/A gen(env, _zap_dead_Java_locals_Java , zap_dead_locals_Type , zap_dead_Java_locals_C , 0 , false, true , false );
0N/A gen(env, _zap_dead_native_locals_Java , zap_dead_locals_Type , zap_dead_native_locals_C , 0 , false, true , false );
0N/A# endif
0N/A
0N/A}
0N/A
0N/A#undef gen
0N/A
0N/A
0N/A// Helper method to do generation of RunTimeStub's
0N/Aaddress OptoRuntime::generate_stub( ciEnv* env,
0N/A TypeFunc_generator gen, address C_function,
0N/A const char *name, int is_fancy_jump,
0N/A bool pass_tls,
0N/A bool save_argument_registers,
0N/A bool return_pc ) {
0N/A ResourceMark rm;
0N/A Compile C( env, gen, C_function, name, is_fancy_jump, pass_tls, save_argument_registers, return_pc );
0N/A return C.stub_entry_point();
0N/A}
0N/A
0N/Aconst char* OptoRuntime::stub_name(address entry) {
0N/A#ifndef PRODUCT
0N/A CodeBlob* cb = CodeCache::find_blob(entry);
0N/A RuntimeStub* rs =(RuntimeStub *)cb;
0N/A assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");
0N/A return rs->name();
0N/A#else
0N/A // Fast implementation for product mode (maybe it should be inlined too)
0N/A return "runtime stub";
0N/A#endif
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A// Opto compiler runtime routines
0N/A//=============================================================================
0N/A
0N/A
0N/A//=============================allocation======================================
0N/A// We failed the fast-path allocation. Now we need to do a scavenge or GC
0N/A// and try allocation again.
0N/A
1166N/Avoid OptoRuntime::new_store_pre_barrier(JavaThread* thread) {
0N/A // After any safepoint, just before going back to compiled code,
1027N/A // we inform the GC that we will be doing initializing writes to
1027N/A // this object in the future without emitting card-marks, so
1027N/A // GC may take any compensating steps.
1027N/A // NOTE: Keep this code consistent with GraphKit::store_barrier.
0N/A
0N/A oop new_obj = thread->vm_result();
0N/A if (new_obj == NULL) return;
0N/A
0N/A assert(Universe::heap()->can_elide_tlab_store_barriers(),
0N/A "compiler must check this first");
1027N/A // GC may decide to give back a safer copy of new_obj.
1166N/A new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj);
0N/A thread->set_vm_result(new_obj);
0N/A}
0N/A
0N/A// object allocation
0N/AJRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(klassOopDesc* klass, JavaThread* thread))
0N/A JRT_BLOCK;
0N/A#ifndef PRODUCT
0N/A SharedRuntime::_new_instance_ctr++; // new instance requires GC
0N/A#endif
0N/A assert(check_compiled_frame(thread), "incorrect caller");
0N/A
0N/A // These checks are cheap to make and support reflective allocation.
0N/A int lh = Klass::cast(klass)->layout_helper();
0N/A if (Klass::layout_helper_needs_slow_path(lh)
0N/A || !instanceKlass::cast(klass)->is_initialized()) {
0N/A KlassHandle kh(THREAD, klass);
0N/A kh->check_valid_for_instantiation(false, THREAD);
0N/A if (!HAS_PENDING_EXCEPTION) {
0N/A instanceKlass::cast(kh())->initialize(THREAD);
0N/A }
0N/A if (!HAS_PENDING_EXCEPTION) {
0N/A klass = kh();
0N/A } else {
0N/A klass = NULL;
0N/A }
0N/A }
0N/A
0N/A if (klass != NULL) {
0N/A // Scavenge and allocate an instance.
0N/A oop result = instanceKlass::cast(klass)->allocate_instance(THREAD);
0N/A thread->set_vm_result(result);
0N/A
0N/A // Pass oops back through thread local storage. Our apparent type to Java
0N/A // is that we return an oop, but we can block on exit from this routine and
0N/A // a GC can trash the oop in C's return register. The generated stub will
0N/A // fetch the oop from TLS after any possible GC.
0N/A }
0N/A
0N/A deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
0N/A JRT_BLOCK_END;
0N/A
0N/A if (GraphKit::use_ReduceInitialCardMarks()) {
1027N/A // inform GC that we won't do card marks for initializing writes.
1166N/A new_store_pre_barrier(thread);
0N/A }
0N/AJRT_END
0N/A
0N/A
0N/A// array allocation
0N/AJRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(klassOopDesc* array_type, int len, JavaThread *thread))
0N/A JRT_BLOCK;
0N/A#ifndef PRODUCT
0N/A SharedRuntime::_new_array_ctr++; // new array requires GC
0N/A#endif
0N/A assert(check_compiled_frame(thread), "incorrect caller");
0N/A
0N/A // Scavenge and allocate an instance.
0N/A oop result;
0N/A
0N/A if (Klass::cast(array_type)->oop_is_typeArray()) {
0N/A // The oopFactory likes to work with the element type.
0N/A // (We could bypass the oopFactory, since it doesn't add much value.)
0N/A BasicType elem_type = typeArrayKlass::cast(array_type)->element_type();
0N/A result = oopFactory::new_typeArray(elem_type, len, THREAD);
0N/A } else {
0N/A // Although the oopFactory likes to work with the elem_type,
0N/A // the compiler prefers the array_type, since it must already have
0N/A // that latter value in hand for the fast path.
0N/A klassOopDesc* elem_type = objArrayKlass::cast(array_type)->element_klass();
0N/A result = oopFactory::new_objArray(elem_type, len, THREAD);
0N/A }
0N/A
0N/A // Pass oops back through thread local storage. Our apparent type to Java
0N/A // is that we return an oop, but we can block on exit from this routine and
0N/A // a GC can trash the oop in C's return register. The generated stub will
0N/A // fetch the oop from TLS after any possible GC.
0N/A deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
0N/A thread->set_vm_result(result);
0N/A JRT_BLOCK_END;
0N/A
0N/A if (GraphKit::use_ReduceInitialCardMarks()) {
1027N/A // inform GC that we won't do card marks for initializing writes.
1166N/A new_store_pre_barrier(thread);
0N/A }
0N/AJRT_END
0N/A
0N/A// Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
0N/A
0N/A// multianewarray for 2 dimensions
0N/AJRT_ENTRY(void, OptoRuntime::multianewarray2_C(klassOopDesc* elem_type, int len1, int len2, JavaThread *thread))
0N/A#ifndef PRODUCT
0N/A SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
0N/A#endif
0N/A assert(check_compiled_frame(thread), "incorrect caller");
0N/A assert(oop(elem_type)->is_klass(), "not a class");
0N/A jint dims[2];
0N/A dims[0] = len1;
0N/A dims[1] = len2;
0N/A oop obj = arrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
0N/A deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
0N/A thread->set_vm_result(obj);
0N/AJRT_END
0N/A
0N/A// multianewarray for 3 dimensions
0N/AJRT_ENTRY(void, OptoRuntime::multianewarray3_C(klassOopDesc* elem_type, int len1, int len2, int len3, JavaThread *thread))
0N/A#ifndef PRODUCT
0N/A SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
0N/A#endif
0N/A assert(check_compiled_frame(thread), "incorrect caller");
0N/A assert(oop(elem_type)->is_klass(), "not a class");
0N/A jint dims[3];
0N/A dims[0] = len1;
0N/A dims[1] = len2;
0N/A dims[2] = len3;
0N/A oop obj = arrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
0N/A deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
0N/A thread->set_vm_result(obj);
0N/AJRT_END
0N/A
0N/A// multianewarray for 4 dimensions
0N/AJRT_ENTRY(void, OptoRuntime::multianewarray4_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, JavaThread *thread))
0N/A#ifndef PRODUCT
0N/A SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
0N/A#endif
0N/A assert(check_compiled_frame(thread), "incorrect caller");
0N/A assert(oop(elem_type)->is_klass(), "not a class");
0N/A jint dims[4];
0N/A dims[0] = len1;
0N/A dims[1] = len2;
0N/A dims[2] = len3;
0N/A dims[3] = len4;
0N/A oop obj = arrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
0N/A deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
0N/A thread->set_vm_result(obj);
0N/AJRT_END
0N/A
0N/A// multianewarray for 5 dimensions
0N/AJRT_ENTRY(void, OptoRuntime::multianewarray5_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread *thread))
0N/A#ifndef PRODUCT
0N/A SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension
0N/A#endif
0N/A assert(check_compiled_frame(thread), "incorrect caller");
0N/A assert(oop(elem_type)->is_klass(), "not a class");
0N/A jint dims[5];
0N/A dims[0] = len1;
0N/A dims[1] = len2;
0N/A dims[2] = len3;
0N/A dims[3] = len4;
0N/A dims[4] = len5;
0N/A oop obj = arrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
0N/A deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
0N/A thread->set_vm_result(obj);
0N/AJRT_END
0N/A
0N/Aconst TypeFunc *OptoRuntime::new_instance_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
0N/A
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/A
0N/Aconst TypeFunc *OptoRuntime::athrow_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(0);
0N/A
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/A
0N/Aconst TypeFunc *OptoRuntime::new_array_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
0N/A fields[TypeFunc::Parms+1] = TypeInt::INT; // array size
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
0N/A
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/Aconst TypeFunc *OptoRuntime::multianewarray_Type(int ndim) {
0N/A // create input type (domain)
0N/A const int nargs = ndim + 1;
0N/A const Type **fields = TypeTuple::fields(nargs);
0N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
0N/A for( int i = 1; i < nargs; i++ )
0N/A fields[TypeFunc::Parms + i] = TypeInt::INT; // array size
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/Aconst TypeFunc *OptoRuntime::multianewarray2_Type() {
0N/A return multianewarray_Type(2);
0N/A}
0N/A
0N/Aconst TypeFunc *OptoRuntime::multianewarray3_Type() {
0N/A return multianewarray_Type(3);
0N/A}
0N/A
0N/Aconst TypeFunc *OptoRuntime::multianewarray4_Type() {
0N/A return multianewarray_Type(4);
0N/A}
0N/A
0N/Aconst TypeFunc *OptoRuntime::multianewarray5_Type() {
0N/A return multianewarray_Type(5);
0N/A}
0N/A
342N/Aconst TypeFunc *OptoRuntime::g1_wb_pre_Type() {
342N/A const Type **fields = TypeTuple::fields(2);
342N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
342N/A fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
342N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
342N/A
342N/A // create result type (range)
342N/A fields = TypeTuple::fields(0);
342N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
342N/A
342N/A return TypeFunc::make(domain, range);
342N/A}
342N/A
342N/Aconst TypeFunc *OptoRuntime::g1_wb_post_Type() {
342N/A
342N/A const Type **fields = TypeTuple::fields(2);
342N/A fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Card addr
342N/A fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
342N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
342N/A
342N/A // create result type (range)
342N/A fields = TypeTuple::fields(0);
342N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
342N/A
342N/A return TypeFunc::make(domain, range);
342N/A}
342N/A
0N/Aconst TypeFunc *OptoRuntime::uncommon_trap_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(1);
2062N/A // Symbol* name of class to be loaded
0N/A fields[TypeFunc::Parms+0] = TypeInt::INT;
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(0);
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/A# ifdef ENABLE_ZAP_DEAD_LOCALS
0N/A// Type used for stub generation for zap_dead_locals.
0N/A// No inputs or outputs
0N/Aconst TypeFunc *OptoRuntime::zap_dead_locals_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(0);
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms,fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(0);
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms,fields);
0N/A
0N/A return TypeFunc::make(domain,range);
0N/A}
0N/A# endif
0N/A
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Monitor Handling
0N/Aconst TypeFunc *OptoRuntime::complete_monitor_enter_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
0N/A fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(0);
0N/A
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
0N/A
0N/A return TypeFunc::make(domain,range);
0N/A}
0N/A
0N/A
0N/A//-----------------------------------------------------------------------------
0N/Aconst TypeFunc *OptoRuntime::complete_monitor_exit_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
0N/A fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(0);
0N/A
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
0N/A
0N/A return TypeFunc::make(domain,range);
0N/A}
0N/A
0N/Aconst TypeFunc* OptoRuntime::flush_windows_Type() {
0N/A // create input type (domain)
0N/A const Type** fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = NULL; // void
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
0N/A
0N/A // create result type
0N/A fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = NULL; // void
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/Aconst TypeFunc* OptoRuntime::l2f_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = TypeLong::LONG;
0N/A fields[TypeFunc::Parms+1] = Type::HALF;
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = Type::FLOAT;
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/Aconst TypeFunc* OptoRuntime::modf_Type() {
0N/A const Type **fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = Type::FLOAT;
0N/A fields[TypeFunc::Parms+1] = Type::FLOAT;
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = Type::FLOAT;
0N/A
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/Aconst TypeFunc *OptoRuntime::Math_D_D_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(2);
2062N/A // Symbol* name of class to be loaded
0N/A fields[TypeFunc::Parms+0] = Type::DOUBLE;
0N/A fields[TypeFunc::Parms+1] = Type::HALF;
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = Type::DOUBLE;
0N/A fields[TypeFunc::Parms+1] = Type::HALF;
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/Aconst TypeFunc* OptoRuntime::Math_DD_D_Type() {
0N/A const Type **fields = TypeTuple::fields(4);
0N/A fields[TypeFunc::Parms+0] = Type::DOUBLE;
0N/A fields[TypeFunc::Parms+1] = Type::HALF;
0N/A fields[TypeFunc::Parms+2] = Type::DOUBLE;
0N/A fields[TypeFunc::Parms+3] = Type::HALF;
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = Type::DOUBLE;
0N/A fields[TypeFunc::Parms+1] = Type::HALF;
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/A//-------------- currentTimeMillis
0N/A
0N/Aconst TypeFunc* OptoRuntime::current_time_millis_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(0);
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = TypeLong::LONG;
0N/A fields[TypeFunc::Parms+1] = Type::HALF;
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/A// arraycopy stub variations:
0N/Aenum ArrayCopyType {
0N/A ac_fast, // void(ptr, ptr, size_t)
0N/A ac_checkcast, // int(ptr, ptr, size_t, size_t, ptr)
0N/A ac_slow, // void(ptr, int, ptr, int, int)
0N/A ac_generic // int(ptr, int, ptr, int, int)
0N/A};
0N/A
0N/Astatic const TypeFunc* make_arraycopy_Type(ArrayCopyType act) {
0N/A // create input type (domain)
0N/A int num_args = (act == ac_fast ? 3 : 5);
0N/A int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0);
0N/A int argcnt = num_args;
0N/A LP64_ONLY(argcnt += num_size_args); // halfwords for lengths
0N/A const Type** fields = TypeTuple::fields(argcnt);
0N/A int argp = TypeFunc::Parms;
0N/A fields[argp++] = TypePtr::NOTNULL; // src
0N/A if (num_size_args == 0) {
0N/A fields[argp++] = TypeInt::INT; // src_pos
0N/A }
0N/A fields[argp++] = TypePtr::NOTNULL; // dest
0N/A if (num_size_args == 0) {
0N/A fields[argp++] = TypeInt::INT; // dest_pos
0N/A fields[argp++] = TypeInt::INT; // length
0N/A }
0N/A while (num_size_args-- > 0) {
0N/A fields[argp++] = TypeX_X; // size in whatevers (size_t)
0N/A LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
0N/A }
0N/A if (act == ac_checkcast) {
0N/A fields[argp++] = TypePtr::NOTNULL; // super_klass
0N/A }
0N/A assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act");
0N/A const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
0N/A
0N/A // create result type if needed
0N/A int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0);
0N/A fields = TypeTuple::fields(1);
0N/A if (retcnt == 0)
0N/A fields[TypeFunc::Parms+0] = NULL; // void
0N/A else
0N/A fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed
0N/A const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields);
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/Aconst TypeFunc* OptoRuntime::fast_arraycopy_Type() {
0N/A // This signature is simple: Two base pointers and a size_t.
0N/A return make_arraycopy_Type(ac_fast);
0N/A}
0N/A
0N/Aconst TypeFunc* OptoRuntime::checkcast_arraycopy_Type() {
0N/A // An extension of fast_arraycopy_Type which adds type checking.
0N/A return make_arraycopy_Type(ac_checkcast);
0N/A}
0N/A
0N/Aconst TypeFunc* OptoRuntime::slow_arraycopy_Type() {
0N/A // This signature is exactly the same as System.arraycopy.
0N/A // There are no intptr_t (int/long) arguments.
0N/A return make_arraycopy_Type(ac_slow);
0N/A}
0N/A
0N/Aconst TypeFunc* OptoRuntime::generic_arraycopy_Type() {
0N/A // This signature is like System.arraycopy, except that it returns status.
0N/A return make_arraycopy_Type(ac_generic);
0N/A}
0N/A
0N/A
1683N/Aconst TypeFunc* OptoRuntime::array_fill_Type() {
1764N/A // create input type (domain): pointer, int, size_t
1764N/A const Type** fields = TypeTuple::fields(3 LP64_ONLY( + 1));
1764N/A int argp = TypeFunc::Parms;
1764N/A fields[argp++] = TypePtr::NOTNULL;
1764N/A fields[argp++] = TypeInt::INT;
1764N/A fields[argp++] = TypeX_X; // size in whatevers (size_t)
1764N/A LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
1764N/A const TypeTuple *domain = TypeTuple::make(argp, fields);
1683N/A
1683N/A // create result type
1683N/A fields = TypeTuple::fields(1);
1683N/A fields[TypeFunc::Parms+0] = NULL; // void
1683N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
1683N/A
1683N/A return TypeFunc::make(domain, range);
1683N/A}
1683N/A
0N/A//------------- Interpreter state access for on stack replacement
0N/Aconst TypeFunc* OptoRuntime::osr_end_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A // create result type
0N/A fields = TypeTuple::fields(1);
0N/A // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop
0N/A fields[TypeFunc::Parms+0] = NULL; // void
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/A//-------------- methodData update helpers
0N/A
0N/Aconst TypeFunc* OptoRuntime::profile_receiver_type_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = TypeAryPtr::NOTNULL; // methodData pointer
0N/A fields[TypeFunc::Parms+1] = TypeInstPtr::BOTTOM; // receiver oop
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
0N/A
0N/A // create result type
0N/A fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = NULL; // void
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
0N/A return TypeFunc::make(domain,range);
0N/A}
0N/A
0N/AJRT_LEAF(void, OptoRuntime::profile_receiver_type_C(DataLayout* data, oopDesc* receiver))
0N/A if (receiver == NULL) return;
0N/A klassOop receiver_klass = receiver->klass();
0N/A
0N/A intptr_t* mdp = ((intptr_t*)(data)) + DataLayout::header_size_in_cells();
0N/A int empty_row = -1; // free row, if any is encountered
0N/A
0N/A // ReceiverTypeData* vc = new ReceiverTypeData(mdp);
0N/A for (uint row = 0; row < ReceiverTypeData::row_limit(); row++) {
0N/A // if (vc->receiver(row) == receiver_klass)
0N/A int receiver_off = ReceiverTypeData::receiver_cell_index(row);
0N/A intptr_t row_recv = *(mdp + receiver_off);
0N/A if (row_recv == (intptr_t) receiver_klass) {
0N/A // vc->set_receiver_count(row, vc->receiver_count(row) + DataLayout::counter_increment);
0N/A int count_off = ReceiverTypeData::receiver_count_cell_index(row);
0N/A *(mdp + count_off) += DataLayout::counter_increment;
0N/A return;
0N/A } else if (row_recv == 0) {
0N/A // else if (vc->receiver(row) == NULL)
0N/A empty_row = (int) row;
0N/A }
0N/A }
0N/A
0N/A if (empty_row != -1) {
0N/A int receiver_off = ReceiverTypeData::receiver_cell_index(empty_row);
0N/A // vc->set_receiver(empty_row, receiver_klass);
0N/A *(mdp + receiver_off) = (intptr_t) receiver_klass;
0N/A // vc->set_receiver_count(empty_row, DataLayout::counter_increment);
0N/A int count_off = ReceiverTypeData::receiver_count_cell_index(empty_row);
0N/A *(mdp + count_off) = DataLayout::counter_increment;
1206N/A } else {
1206N/A // Receiver did not match any saved receiver and there is no empty row for it.
1251N/A // Increment total counter to indicate polymorphic case.
1206N/A intptr_t* count_p = (intptr_t*)(((byte*)(data)) + in_bytes(CounterData::count_offset()));
1206N/A *count_p += DataLayout::counter_increment;
0N/A }
0N/AJRT_END
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// implicit exception support.
0N/A
0N/Astatic void report_null_exception_in_code_cache(address exception_pc) {
0N/A ResourceMark rm;
0N/A CodeBlob* n = CodeCache::find_blob(exception_pc);
0N/A if (n != NULL) {
0N/A tty->print_cr("#");
0N/A tty->print_cr("# HotSpot Runtime Error, null exception in generated code");
0N/A tty->print_cr("#");
0N/A tty->print_cr("# pc where exception happened = " INTPTR_FORMAT, exception_pc);
0N/A
0N/A if (n->is_nmethod()) {
0N/A methodOop method = ((nmethod*)n)->method();
0N/A tty->print_cr("# Method where it happened %s.%s ", Klass::cast(method->method_holder())->name()->as_C_string(), method->name()->as_C_string());
0N/A tty->print_cr("#");
0N/A if (ShowMessageBoxOnError && UpdateHotSpotCompilerFileOnError) {
0N/A const char* title = "HotSpot Runtime Error";
0N/A const char* question = "Do you want to exclude compilation of this method in future runs?";
0N/A if (os::message_box(title, question)) {
0N/A CompilerOracle::append_comment_to_file("");
0N/A CompilerOracle::append_comment_to_file("Null exception in compiled code resulted in the following exclude");
0N/A CompilerOracle::append_comment_to_file("");
0N/A CompilerOracle::append_exclude_to_file(method);
0N/A tty->print_cr("#");
0N/A tty->print_cr("# %s has been updated to exclude the specified method", CompileCommandFile);
0N/A tty->print_cr("#");
0N/A }
0N/A }
0N/A fatal("Implicit null exception happened in compiled method");
0N/A } else {
0N/A n->print();
0N/A fatal("Implicit null exception happened in generated stub");
0N/A }
0N/A }
0N/A fatal("Implicit null exception at wrong place");
0N/A}
0N/A
0N/A
0N/A//-------------------------------------------------------------------------------------
0N/A// register policy
0N/A
0N/Abool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) {
0N/A assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
0N/A switch (register_save_policy[reg]) {
0N/A case 'C': return false; //SOC
0N/A case 'E': return true ; //SOE
0N/A case 'N': return false; //NS
0N/A case 'A': return false; //AS
0N/A }
0N/A ShouldNotReachHere();
0N/A return false;
0N/A}
0N/A
0N/A//-----------------------------------------------------------------------
0N/A// Exceptions
0N/A//
0N/A
0N/Astatic void trace_exception(oop exception_oop, address exception_pc, const char* msg) PRODUCT_RETURN;
0N/A
0N/A// The method is an entry that is always called by a C++ method not
0N/A// directly from compiled code. Compiled code will call the C++ method following.
0N/A// We can't allow async exception to be installed during exception processing.
0N/AJRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* thread, nmethod* &nm))
0N/A
0N/A // Do not confuse exception_oop with pending_exception. The exception_oop
0N/A // is only used to pass arguments into the method. Not for general
0N/A // exception handling. DO NOT CHANGE IT to use pending_exception, since
0N/A // the runtime stubs checks this on exit.
0N/A assert(thread->exception_oop() != NULL, "exception oop is found");
0N/A address handler_address = NULL;
0N/A
0N/A Handle exception(thread, thread->exception_oop());
0N/A
0N/A if (TraceExceptions) {
0N/A trace_exception(exception(), thread->exception_pc(), "");
0N/A }
0N/A // for AbortVMOnException flag
0N/A NOT_PRODUCT(Exceptions::debug_check_abort(exception));
0N/A
0N/A #ifdef ASSERT
1142N/A if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
0N/A // should throw an exception here
0N/A ShouldNotReachHere();
0N/A }
0N/A #endif
0N/A
0N/A
0N/A // new exception handling: this method is entered only from adapters
0N/A // exceptions from compiled java methods are handled in compiled code
0N/A // using rethrow node
0N/A
0N/A address pc = thread->exception_pc();
0N/A nm = CodeCache::find_nmethod(pc);
0N/A assert(nm != NULL, "No NMethod found");
0N/A if (nm->is_native_method()) {
0N/A fatal("Native mathod should not have path to exception handling");
0N/A } else {
0N/A // we are switching to old paradigm: search for exception handler in caller_frame
0N/A // instead in exception handler of caller_frame.sender()
0N/A
1213N/A if (JvmtiExport::can_post_on_exceptions()) {
0N/A // "Full-speed catching" is not necessary here,
0N/A // since we're notifying the VM on every catch.
0N/A // Force deoptimization and the rest of the lookup
0N/A // will be fine.
0N/A deoptimize_caller_frame(thread, true);
0N/A }
0N/A
0N/A // Check the stack guard pages. If enabled, look for handler in this frame;
0N/A // otherwise, forcibly unwind the frame.
0N/A //
0N/A // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate.
0N/A bool force_unwind = !thread->reguard_stack();
0N/A bool deopting = false;
0N/A if (nm->is_deopt_pc(pc)) {
0N/A deopting = true;
0N/A RegisterMap map(thread, false);
0N/A frame deoptee = thread->last_frame().sender(&map);
0N/A assert(deoptee.is_deoptimized_frame(), "must be deopted");
0N/A // Adjust the pc back to the original throwing pc
0N/A pc = deoptee.pc();
0N/A }
0N/A
0N/A // If we are forcing an unwind because of stack overflow then deopt is
0N/A // irrelevant sice we are throwing the frame away anyway.
0N/A
0N/A if (deopting && !force_unwind) {
0N/A handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
0N/A } else {
0N/A
0N/A handler_address =
0N/A force_unwind ? NULL : nm->handler_for_exception_and_pc(exception, pc);
0N/A
0N/A if (handler_address == NULL) {
0N/A handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true);
0N/A assert (handler_address != NULL, "must have compiled handler");
0N/A // Update the exception cache only when the unwind was not forced.
0N/A if (!force_unwind) {
0N/A nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
0N/A }
0N/A } else {
0N/A assert(handler_address == SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true), "Must be the same");
0N/A }
0N/A }
0N/A
0N/A thread->set_exception_pc(pc);
0N/A thread->set_exception_handler_pc(handler_address);
0N/A thread->set_exception_stack_size(0);
1135N/A
1295N/A // Check if the exception PC is a MethodHandle call site.
1368N/A thread->set_is_method_handle_return(nm->is_method_handle_return(pc));
0N/A }
0N/A
0N/A // Restore correct return pc. Was saved above.
0N/A thread->set_exception_oop(exception());
0N/A return handler_address;
0N/A
0N/AJRT_END
0N/A
0N/A// We are entering here from exception_blob
0N/A// If there is a compiled exception handler in this method, we will continue there;
0N/A// otherwise we will unwind the stack and continue at the caller of top frame method
0N/A// Note we enter without the usual JRT wrapper. We will call a helper routine that
0N/A// will do the normal VM entry. We do it this way so that we can see if the nmethod
0N/A// we looked up the handler for has been deoptimized in the meantime. If it has been
0N/A// we must not use the handler and instread return the deopt blob.
0N/Aaddress OptoRuntime::handle_exception_C(JavaThread* thread) {
0N/A//
0N/A// We are in Java not VM and in debug mode we have a NoHandleMark
0N/A//
0N/A#ifndef PRODUCT
0N/A SharedRuntime::_find_handler_ctr++; // find exception handler
0N/A#endif
0N/A debug_only(NoHandleMark __hm;)
0N/A nmethod* nm = NULL;
0N/A address handler_address = NULL;
0N/A {
0N/A // Enter the VM
0N/A
0N/A ResetNoHandleMark rnhm;
0N/A handler_address = handle_exception_C_helper(thread, nm);
0N/A }
0N/A
0N/A // Back in java: Use no oops, DON'T safepoint
0N/A
0N/A // Now check to see if the handler we are returning is in a now
0N/A // deoptimized frame
0N/A
0N/A if (nm != NULL) {
0N/A RegisterMap map(thread, false);
0N/A frame caller = thread->last_frame().sender(&map);
0N/A#ifdef ASSERT
0N/A assert(caller.is_compiled_frame(), "must be");
0N/A#endif // ASSERT
0N/A if (caller.is_deoptimized_frame()) {
0N/A handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
0N/A }
0N/A }
0N/A return handler_address;
0N/A}
0N/A
0N/A//------------------------------rethrow----------------------------------------
0N/A// We get here after compiled code has executed a 'RethrowNode'. The callee
0N/A// is either throwing or rethrowing an exception. The callee-save registers
0N/A// have been restored, synchronized objects have been unlocked and the callee
0N/A// stack frame has been removed. The return address was passed in.
0N/A// Exception oop is passed as the 1st argument. This routine is then called
0N/A// from the stub. On exit, we know where to jump in the caller's code.
0N/A// After this C code exits, the stub will pop his frame and end in a jump
0N/A// (instead of a return). We enter the caller's default handler.
0N/A//
0N/A// This must be JRT_LEAF:
0N/A// - caller will not change its state as we cannot block on exit,
0N/A// therefore raw_exception_handler_for_return_address is all it takes
0N/A// to handle deoptimized blobs
0N/A//
0N/A// However, there needs to be a safepoint check in the middle! So compiled
0N/A// safepoints are completely watertight.
0N/A//
0N/A// Thus, it cannot be a leaf since it contains the No_GC_Verifier.
0N/A//
0N/A// *THIS IS NOT RECOMMENDED PROGRAMMING STYLE*
0N/A//
0N/Aaddress OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) {
0N/A#ifndef PRODUCT
0N/A SharedRuntime::_rethrow_ctr++; // count rethrows
0N/A#endif
0N/A assert (exception != NULL, "should have thrown a NULLPointerException");
0N/A#ifdef ASSERT
1142N/A if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
0N/A // should throw an exception here
0N/A ShouldNotReachHere();
0N/A }
0N/A#endif
0N/A
0N/A thread->set_vm_result(exception);
0N/A // Frame not compiled (handles deoptimization blob)
1295N/A return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc);
0N/A}
0N/A
0N/A
0N/Aconst TypeFunc *OptoRuntime::rethrow_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
0N/A
0N/A return TypeFunc::make(domain, range);
0N/A}
0N/A
0N/A
0N/Avoid OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) {
0N/A // Deoptimize frame
0N/A if (doit) {
0N/A // Called from within the owner thread, so no need for safepoint
0N/A RegisterMap reg_map(thread);
0N/A frame stub_frame = thread->last_frame();
0N/A assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
0N/A frame caller_frame = stub_frame.sender(&reg_map);
0N/A
1213N/A // bypass VM_DeoptimizeFrame and deoptimize the frame directly
1213N/A Deoptimization::deoptimize_frame(thread, caller_frame.id());
0N/A }
0N/A}
0N/A
0N/A
0N/Aconst TypeFunc *OptoRuntime::register_finalizer_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(1);
0N/A fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
0N/A // // The JavaThread* is passed to each routine as the last argument
0N/A // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(0);
0N/A
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
0N/A
0N/A return TypeFunc::make(domain,range);
0N/A}
0N/A
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Dtrace support. entry and exit probes have the same signature
0N/Aconst TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
0N/A fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // methodOop; Method we are entering
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(0);
0N/A
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
0N/A
0N/A return TypeFunc::make(domain,range);
0N/A}
0N/A
0N/Aconst TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
0N/A // create input type (domain)
0N/A const Type **fields = TypeTuple::fields(2);
0N/A fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
0N/A fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
0N/A
0N/A const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
0N/A
0N/A // create result type (range)
0N/A fields = TypeTuple::fields(0);
0N/A
0N/A const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
0N/A
0N/A return TypeFunc::make(domain,range);
0N/A}
0N/A
0N/A
0N/AJRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* thread))
0N/A assert(obj->is_oop(), "must be a valid oop");
0N/A assert(obj->klass()->klass_part()->has_finalizer(), "shouldn't be here otherwise");
0N/A instanceKlass::register_finalizer(instanceOop(obj), CHECK);
0N/AJRT_END
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A
0N/ANamedCounter * volatile OptoRuntime::_named_counters = NULL;
0N/A
0N/A//
0N/A// dump the collected NamedCounters.
0N/A//
0N/Avoid OptoRuntime::print_named_counters() {
0N/A int total_lock_count = 0;
0N/A int eliminated_lock_count = 0;
0N/A
0N/A NamedCounter* c = _named_counters;
0N/A while (c) {
0N/A if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
0N/A int count = c->count();
0N/A if (count > 0) {
0N/A bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
0N/A if (Verbose) {
0N/A tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
0N/A }
0N/A total_lock_count += count;
0N/A if (eliminated) {
0N/A eliminated_lock_count += count;
0N/A }
0N/A }
0N/A } else if (c->tag() == NamedCounter::BiasedLockingCounter) {
0N/A BiasedLockingCounters* blc = ((BiasedLockingNamedCounter*)c)->counters();
0N/A if (blc->nonzero()) {
0N/A tty->print_cr("%s", c->name());
0N/A blc->print_on(tty);
0N/A }
0N/A }
0N/A c = c->next();
0N/A }
0N/A if (total_lock_count > 0) {
0N/A tty->print_cr("dynamic locks: %d", total_lock_count);
0N/A if (eliminated_lock_count) {
0N/A tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
0N/A (int)(eliminated_lock_count * 100.0 / total_lock_count));
0N/A }
0N/A }
0N/A}
0N/A
0N/A//
0N/A// Allocate a new NamedCounter. The JVMState is used to generate the
0N/A// name which consists of method@line for the inlining tree.
0N/A//
0N/A
0N/ANamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
0N/A int max_depth = youngest_jvms->depth();
0N/A
0N/A // Visit scopes from youngest to oldest.
0N/A bool first = true;
0N/A stringStream st;
0N/A for (int depth = max_depth; depth >= 1; depth--) {
0N/A JVMState* jvms = youngest_jvms->of_depth(depth);
0N/A ciMethod* m = jvms->has_method() ? jvms->method() : NULL;
0N/A if (!first) {
0N/A st.print(" ");
0N/A } else {
0N/A first = false;
0N/A }
0N/A int bci = jvms->bci();
0N/A if (bci < 0) bci = 0;
0N/A st.print("%s.%s@%d", m->holder()->name()->as_utf8(), m->name()->as_utf8(), bci);
0N/A // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
0N/A }
0N/A NamedCounter* c;
0N/A if (tag == NamedCounter::BiasedLockingCounter) {
0N/A c = new BiasedLockingNamedCounter(strdup(st.as_string()));
0N/A } else {
0N/A c = new NamedCounter(strdup(st.as_string()), tag);
0N/A }
0N/A
0N/A // atomically add the new counter to the head of the list. We only
0N/A // add counters so this is safe.
0N/A NamedCounter* head;
0N/A do {
0N/A head = _named_counters;
0N/A c->set_next(head);
0N/A } while (Atomic::cmpxchg_ptr(c, &_named_counters, head) != head);
0N/A return c;
0N/A}
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Non-product code
0N/A#ifndef PRODUCT
0N/A
0N/Aint trace_exception_counter = 0;
0N/Astatic void trace_exception(oop exception_oop, address exception_pc, const char* msg) {
0N/A ttyLocker ttyl;
0N/A trace_exception_counter++;
0N/A tty->print("%d [Exception (%s): ", trace_exception_counter, msg);
0N/A exception_oop->print_value();
0N/A tty->print(" in ");
0N/A CodeBlob* blob = CodeCache::find_blob(exception_pc);
0N/A if (blob->is_nmethod()) {
0N/A ((nmethod*)blob)->method()->print_value();
0N/A } else if (blob->is_runtime_stub()) {
0N/A tty->print("<runtime-stub>");
0N/A } else {
0N/A tty->print("<unknown>");
0N/A }
0N/A tty->print(" at " INTPTR_FORMAT, exception_pc);
0N/A tty->print_cr("]");
0N/A}
0N/A
0N/A#endif // PRODUCT
0N/A
0N/A
0N/A# ifdef ENABLE_ZAP_DEAD_LOCALS
0N/A// Called from call sites in compiled code with oop maps (actually safepoints)
0N/A// Zaps dead locals in first java frame.
0N/A// Is entry because may need to lock to generate oop maps
0N/A// Currently, only used for compiler frames, but someday may be used
0N/A// for interpreter frames, too.
0N/A
0N/Aint OptoRuntime::ZapDeadCompiledLocals_count = 0;
0N/A
0N/A// avoid pointers to member funcs with these helpers
0N/Astatic bool is_java_frame( frame* f) { return f->is_java_frame(); }
0N/Astatic bool is_native_frame(frame* f) { return f->is_native_frame(); }
0N/A
0N/A
0N/Avoid OptoRuntime::zap_dead_java_or_native_locals(JavaThread* thread,
0N/A bool (*is_this_the_right_frame_to_zap)(frame*)) {
0N/A assert(JavaThread::current() == thread, "is this needed?");
0N/A
0N/A if ( !ZapDeadCompiledLocals ) return;
0N/A
0N/A bool skip = false;
0N/A
0N/A if ( ZapDeadCompiledLocalsFirst == 0 ) ; // nothing special
0N/A else if ( ZapDeadCompiledLocalsFirst > ZapDeadCompiledLocals_count ) skip = true;
0N/A else if ( ZapDeadCompiledLocalsFirst == ZapDeadCompiledLocals_count )
0N/A warning("starting zapping after skipping");
0N/A
0N/A if ( ZapDeadCompiledLocalsLast == -1 ) ; // nothing special
0N/A else if ( ZapDeadCompiledLocalsLast < ZapDeadCompiledLocals_count ) skip = true;
0N/A else if ( ZapDeadCompiledLocalsLast == ZapDeadCompiledLocals_count )
0N/A warning("about to zap last zap");
0N/A
0N/A ++ZapDeadCompiledLocals_count; // counts skipped zaps, too
0N/A
0N/A if ( skip ) return;
0N/A
0N/A // find java frame and zap it
0N/A
0N/A for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) {
0N/A if (is_this_the_right_frame_to_zap(sfs.current()) ) {
0N/A sfs.current()->zap_dead_locals(thread, sfs.register_map());
0N/A return;
0N/A }
0N/A }
0N/A warning("no frame found to zap in zap_dead_Java_locals_C");
0N/A}
0N/A
0N/AJRT_LEAF(void, OptoRuntime::zap_dead_Java_locals_C(JavaThread* thread))
0N/A zap_dead_java_or_native_locals(thread, is_java_frame);
0N/AJRT_END
0N/A
0N/A// The following does not work because for one thing, the
0N/A// thread state is wrong; it expects java, but it is native.
605N/A// Also, the invariants in a native stub are different and
0N/A// I'm not sure it is safe to have a MachCalRuntimeDirectNode
0N/A// in there.
0N/A// So for now, we do not zap in native stubs.
0N/A
0N/AJRT_LEAF(void, OptoRuntime::zap_dead_native_locals_C(JavaThread* thread))
0N/A zap_dead_java_or_native_locals(thread, is_native_frame);
0N/AJRT_END
0N/A
0N/A# endif