runtime.cpp revision 3677
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * This code is free software; you can redistribute it and/or modify it
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * under the terms of the GNU General Public License version 2 only, as
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * published by the Free Software Foundation.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * This code is distributed in the hope that it will be useful, but WITHOUT
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * version 2 for more details (a copy is included in the LICENSE file that
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * accompanied this code).
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * You should have received a copy of the GNU General Public License version
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * 2 along with this work; if not, write to the Free Software Foundation,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * or visit www.oracle.com if you need additional information or have any
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * questions.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// For debugging purposes:
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// To force FullGCALot inside a runtime function, add the following two lines
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Universe::release_fullgc_alot_dummy();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// MarkSweep::invoke(0, "Debugging");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Compiled code entry points
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_new_array_nozero_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_multianewarray2_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_multianewarray3_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_multianewarray4_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_multianewarray5_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_multianewarrayN_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_vtable_must_compile_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_complete_monitor_locking_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_slow_arraycopy_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_register_finalizer_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_zap_dead_Java_locals_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkaddress OptoRuntime::_zap_dead_native_locals_Java = NULL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// This should be called in an assertion at the start of OptoRuntime routines
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// which are entered from compiled code (all of them)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkstatic bool check_compiled_frame(JavaThread* thread) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk frame caller = thread->last_frame().sender(&map);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk assert(caller.is_compiled_frame(), "not being called from compiled like code");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#endif /* ASSERT */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, save_arg_regs, return_pc) \
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, save_arg_regs, return_pc)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Note: tls: Means fetching the return oop out of the thread-local storage
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // variable/name type-function-gen , runtime method ,fncy_jp, tls,save_args,retpc
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // -------------------------------------------------------------------------------------------------------------------------------
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _new_instance_Java , new_instance_Type , new_instance_C , 0 , true , false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _new_array_Java , new_array_Type , new_array_C , 0 , true , false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _new_array_nozero_Java , new_array_Type , new_array_nozero_C , 0 , true , false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _multianewarray2_Java , multianewarray2_Type , multianewarray2_C , 0 , true , false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _multianewarray3_Java , multianewarray3_Type , multianewarray3_C , 0 , true , false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _multianewarray4_Java , multianewarray4_Type , multianewarray4_C , 0 , true , false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _multianewarray5_Java , multianewarray5_Type , multianewarray5_C , 0 , true , false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _multianewarrayN_Java , multianewarrayN_Type , multianewarrayN_C , 0 , true , false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _g1_wb_pre_Java , g1_wb_pre_Type , SharedRuntime::g1_wb_pre , 0 , false, false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _g1_wb_post_Java , g1_wb_post_Type , SharedRuntime::g1_wb_post , 0 , false, false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _complete_monitor_locking_Java , complete_monitor_enter_Type , SharedRuntime::complete_monitor_locking_C , 0 , false, false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _rethrow_Java , rethrow_Type , rethrow_C , 2 , true , false, true );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _slow_arraycopy_Java , slow_arraycopy_Type , SharedRuntime::slow_arraycopy_C , 0 , false, false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _register_finalizer_Java , register_finalizer_Type , register_finalizer , 0 , false, false, false);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _zap_dead_Java_locals_Java , zap_dead_locals_Type , zap_dead_Java_locals_C , 0 , false, true , false );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk gen(env, _zap_dead_native_locals_Java , zap_dead_locals_Type , zap_dead_native_locals_C , 0 , false, true , false );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Helper method to do generation of RunTimeStub's
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Compile C( env, gen, C_function, name, is_fancy_jump, pass_tls, save_argument_registers, return_pc );
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkconst char* OptoRuntime::stub_name(address entry) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Fast implementation for product mode (maybe it should be inlined too)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return "runtime stub";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//=============================================================================
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Opto compiler runtime routines
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//=============================================================================
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//=============================allocation======================================
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// We failed the fast-path allocation. Now we need to do a scavenge or GC
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// and try allocation again.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkvoid OptoRuntime::new_store_pre_barrier(JavaThread* thread) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // After any safepoint, just before going back to compiled code,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // we inform the GC that we will be doing initializing writes to
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // this object in the future without emitting card-marks, so
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // GC may take any compensating steps.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // NOTE: Keep this code consistent with GraphKit::store_barrier.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk assert(Universe::heap()->can_elide_tlab_store_barriers(),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "compiler must check this first");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // GC may decide to give back a safer copy of new_obj.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// object allocation
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkJRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(klassOopDesc* klass, JavaThread* thread))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk SharedRuntime::_new_instance_ctr++; // new instance requires GC
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk assert(check_compiled_frame(thread), "incorrect caller");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // These checks are cheap to make and support reflective allocation.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk || !instanceKlass::cast(klass)->is_initialized()) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk kh->check_valid_for_instantiation(false, THREAD);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Scavenge and allocate an instance.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk oop result = instanceKlass::cast(klass)->allocate_instance(THREAD);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Pass oops back through thread local storage. Our apparent type to Java
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // is that we return an oop, but we can block on exit from this routine and
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // a GC can trash the oop in C's return register. The generated stub will
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // fetch the oop from TLS after any possible GC.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // inform GC that we won't do card marks for initializing writes.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// array allocation
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkJRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(klassOopDesc* array_type, int len, JavaThread *thread))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk SharedRuntime::_new_array_ctr++; // new array requires GC
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk assert(check_compiled_frame(thread), "incorrect caller");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Scavenge and allocate an instance.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (Klass::cast(array_type)->oop_is_typeArray()) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // The oopFactory likes to work with the element type.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // (We could bypass the oopFactory, since it doesn't add much value.)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk BasicType elem_type = typeArrayKlass::cast(array_type)->element_type();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk result = oopFactory::new_typeArray(elem_type, len, THREAD);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Although the oopFactory likes to work with the elem_type,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // the compiler prefers the array_type, since it must already have
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // that latter value in hand for the fast path.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk klassOopDesc* elem_type = objArrayKlass::cast(array_type)->element_klass();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk result = oopFactory::new_objArray(elem_type, len, THREAD);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Pass oops back through thread local storage. Our apparent type to Java
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // is that we return an oop, but we can block on exit from this routine and
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // a GC can trash the oop in C's return register. The generated stub will
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // fetch the oop from TLS after any possible GC.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // inform GC that we won't do card marks for initializing writes.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// array allocation without zeroing
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkJRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(klassOopDesc* array_type, int len, JavaThread *thread))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk SharedRuntime::_new_array_ctr++; // new array requires GC
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk assert(check_compiled_frame(thread), "incorrect caller");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Scavenge and allocate an instance.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk assert(Klass::cast(array_type)->oop_is_typeArray(), "should be called only for type array");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // The oopFactory likes to work with the element type.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk BasicType elem_type = typeArrayKlass::cast(array_type)->element_type();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Pass oops back through thread local storage. Our apparent type to Java
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // is that we return an oop, but we can block on exit from this routine and
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // a GC can trash the oop in C's return register. The generated stub will
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // fetch the oop from TLS after any possible GC.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // inform GC that we won't do card marks for initializing writes.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Zero array here if the caller is deoptimized.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int size = ((typeArrayOop)result)->object_size();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk BasicType elem_type = typeArrayKlass::cast(array_type)->element_type();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk const size_t hs = arrayOopDesc::header_size(elem_type);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Align to next 8 bytes to avoid trashing arrays's length.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk const size_t aligned_hs = align_object_offset(hs);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Optimized zeroing.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// multianewarray for 2 dimensions
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkJRT_ENTRY(void, OptoRuntime::multianewarray2_C(klassOopDesc* elem_type, int len1, int len2, JavaThread *thread))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
JRT_ENTRY(void, OptoRuntime::multianewarray3_C(klassOopDesc* elem_type, int len1, int len2, int len3, JavaThread *thread))
#ifndef PRODUCT
JRT_ENTRY(void, OptoRuntime::multianewarray4_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, JavaThread *thread))
#ifndef PRODUCT
JRT_ENTRY(void, OptoRuntime::multianewarray5_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread *thread))
#ifndef PRODUCT
JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(klassOopDesc* elem_type, arrayOopDesc* dims, JavaThread *thread))
# ifdef ENABLE_ZAP_DEAD_LOCALS
enum ArrayCopyType {
if (num_size_args == 0) {
if (num_size_args == 0) {
while (num_size_args-- > 0) {
if (retcnt == 0)
} else if (row_recv == 0) {
if (n != NULL) {
if (n->is_nmethod()) {
tty->print_cr("# Method where it happened %s.%s ", Klass::cast(method->method_holder())->name()->as_C_string(), method->name()->as_C_string());
CompilerOracle::append_comment_to_file("Null exception in compiled code resulted in the following exclude");
n->print();
static void trace_exception(oop exception_oop, address exception_pc, const char* msg) PRODUCT_RETURN;
JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* thread, nmethod* &nm))
if (TraceExceptions) {
#ifdef ASSERT
// instead in exception handler of caller_frame.sender()
bool deopting = false;
deopting = true;
handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true);
assert(handler_address == SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true), "Must be the same");
return handler_address;
#ifndef PRODUCT
#ifdef ASSERT
return handler_address;
#ifndef PRODUCT
#ifdef ASSERT
if (doit) {
assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
int total_lock_count = 0;
int eliminated_lock_count = 0;
if (count > 0) {
if (Verbose) {
if (eliminated) {
c = c->next();
if (total_lock_count > 0) {
if (eliminated_lock_count) {
NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
bool first = true;
if (!first) {
first = false;
NamedCounter* c;
#ifndef PRODUCT
int trace_exception_counter = 0;
# ifdef ENABLE_ZAP_DEAD_LOCALS
if ( !ZapDeadCompiledLocals ) return;
bool skip = false;
if ( skip ) return;