Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkRuntime.cpp
32285 views
/*1* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.2* Copyright 2008, 2009, 2010 Red Hat, Inc.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "runtime/biasedLocking.hpp"27#include "runtime/deoptimization.hpp"28#include "runtime/thread.hpp"29#include "shark/llvmHeaders.hpp"30#include "shark/sharkRuntime.hpp"31#ifdef TARGET_ARCH_zero32# include "stack_zero.inline.hpp"33#endif3435using namespace llvm;3637JRT_ENTRY(int, SharkRuntime::find_exception_handler(JavaThread* thread,38int* indexes,39int num_indexes))40constantPoolHandle pool(thread, method(thread)->constants());41KlassHandle exc_klass(thread, ((oop) tos_at(thread, 0))->klass());4243for (int i = 0; i < num_indexes; i++) {44Klass* tmp = pool->klass_at(indexes[i], CHECK_0);45KlassHandle chk_klass(thread, tmp);4647if (exc_klass() == chk_klass())48return i;4950if (exc_klass()->is_subtype_of(chk_klass()))51return i;52}5354return -1;55JRT_END5657JRT_ENTRY(void, SharkRuntime::monitorenter(JavaThread* thread,58BasicObjectLock* lock))59if (PrintBiasedLockingStatistics)60Atomic::inc(BiasedLocking::slow_path_entry_count_addr());6162Handle object(thread, lock->obj());63assert(Universe::heap()->is_in_reserved_or_null(object()), "should be");64if (UseBiasedLocking) {65// Retry fast entry if bias is revoked to avoid unnecessary inflation66ObjectSynchronizer::fast_enter(object, lock->lock(), true, CHECK);67} else {68ObjectSynchronizer::slow_enter(object, lock->lock(), CHECK);69}70assert(Universe::heap()->is_in_reserved_or_null(lock->obj()), "should be");71JRT_END7273JRT_ENTRY(void, SharkRuntime::monitorexit(JavaThread* thread,74BasicObjectLock* lock))75Handle object(thread, lock->obj());76assert(Universe::heap()->is_in_reserved_or_null(object()), "should be");77if (lock == NULL || object()->is_unlocked()) {78THROW(vmSymbols::java_lang_IllegalMonitorStateException());79}80ObjectSynchronizer::slow_exit(object(), lock->lock(), thread);81JRT_END8283JRT_ENTRY(void, SharkRuntime::new_instance(JavaThread* thread, int index))84Klass* k_oop = method(thread)->constants()->klass_at(index, CHECK);85instanceKlassHandle klass(THREAD, k_oop);8687// Make sure we are not instantiating an abstract klass88klass->check_valid_for_instantiation(true, CHECK);8990// Make sure klass is initialized91klass->initialize(CHECK);9293// At this point the class may not be fully initialized94// because of recursive initialization. If it is fully95// initialized & has_finalized is not set, we rewrite96// it into its fast version (Note: no locking is needed97// here since this is an atomic byte write and can be98// done more than once).99//100// Note: In case of classes with has_finalized we don't101// rewrite since that saves us an extra check in102// the fast version which then would call the103// slow version anyway (and do a call back into104// Java).105// If we have a breakpoint, then we don't rewrite106// because the _breakpoint bytecode would be lost.107oop obj = klass->allocate_instance(CHECK);108thread->set_vm_result(obj);109JRT_END110111JRT_ENTRY(void, SharkRuntime::newarray(JavaThread* thread,112BasicType type,113int size))114oop obj = oopFactory::new_typeArray(type, size, CHECK);115thread->set_vm_result(obj);116JRT_END117118JRT_ENTRY(void, SharkRuntime::anewarray(JavaThread* thread,119int index,120int size))121Klass* klass = method(thread)->constants()->klass_at(index, CHECK);122objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);123thread->set_vm_result(obj);124JRT_END125126JRT_ENTRY(void, SharkRuntime::multianewarray(JavaThread* thread,127int index,128int ndims,129int* dims))130Klass* klass = method(thread)->constants()->klass_at(index, CHECK);131oop obj = ArrayKlass::cast(klass)->multi_allocate(ndims, dims, CHECK);132thread->set_vm_result(obj);133JRT_END134135JRT_ENTRY(void, SharkRuntime::register_finalizer(JavaThread* thread,136oop object))137assert(object->is_oop(), "should be");138assert(object->klass()->has_finalizer(), "should have");139InstanceKlass::register_finalizer(instanceOop(object), CHECK);140JRT_END141142JRT_ENTRY(void, SharkRuntime::throw_ArithmeticException(JavaThread* thread,143const char* file,144int line))145Exceptions::_throw_msg(146thread, file, line,147vmSymbols::java_lang_ArithmeticException(),148"");149JRT_END150151JRT_ENTRY(void, SharkRuntime::throw_ArrayIndexOutOfBoundsException(152JavaThread* thread,153const char* file,154int line,155int index))156char msg[jintAsStringSize];157snprintf(msg, sizeof(msg), "%d", index);158Exceptions::_throw_msg(159thread, file, line,160vmSymbols::java_lang_ArrayIndexOutOfBoundsException(),161msg);162JRT_END163164JRT_ENTRY(void, SharkRuntime::throw_ClassCastException(JavaThread* thread,165const char* file,166int line))167Exceptions::_throw_msg(168thread, file, line,169vmSymbols::java_lang_ClassCastException(),170"");171JRT_END172173JRT_ENTRY(void, SharkRuntime::throw_NullPointerException(JavaThread* thread,174const char* file,175int line))176Exceptions::_throw_msg(177thread, file, line,178vmSymbols::java_lang_NullPointerException(),179"");180JRT_END181182// Non-VM calls183// Nothing in these must ever GC!184185void SharkRuntime::dump(const char *name, intptr_t value) {186oop valueOop = (oop) value;187tty->print("%s = ", name);188if (valueOop->is_oop(true))189valueOop->print_on(tty);190else if (value >= ' ' && value <= '~')191tty->print("'%c' (%d)", value, value);192else193tty->print("%p", value);194tty->print_cr("");195}196197bool SharkRuntime::is_subtype_of(Klass* check_klass, Klass* object_klass) {198return object_klass->is_subtype_of(check_klass);199}200201int SharkRuntime::uncommon_trap(JavaThread* thread, int trap_request) {202Thread *THREAD = thread;203204// In C2, uncommon_trap_blob creates a frame, so all the various205// deoptimization functions expect to find the frame of the method206// being deopted one frame down on the stack. We create a dummy207// frame to mirror this.208FakeStubFrame *stubframe = FakeStubFrame::build(CHECK_0);209thread->push_zero_frame(stubframe);210211// Initiate the trap212thread->set_last_Java_frame();213Deoptimization::UnrollBlock *urb =214Deoptimization::uncommon_trap(thread, trap_request);215thread->reset_last_Java_frame();216217// Pop our dummy frame and the frame being deoptimized218thread->pop_zero_frame();219thread->pop_zero_frame();220221// Push skeleton frames222int number_of_frames = urb->number_of_frames();223for (int i = 0; i < number_of_frames; i++) {224intptr_t size = urb->frame_sizes()[i];225InterpreterFrame *frame = InterpreterFrame::build(size, CHECK_0);226thread->push_zero_frame(frame);227}228229// Push another dummy frame230stubframe = FakeStubFrame::build(CHECK_0);231thread->push_zero_frame(stubframe);232233// Fill in the skeleton frames234thread->set_last_Java_frame();235Deoptimization::unpack_frames(thread, Deoptimization::Unpack_uncommon_trap);236thread->reset_last_Java_frame();237238// Pop our dummy frame239thread->pop_zero_frame();240241// Fall back into the interpreter242return number_of_frames;243}244245FakeStubFrame* FakeStubFrame::build(TRAPS) {246ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();247stack->overflow_check(header_words, CHECK_NULL);248249stack->push(0); // next_frame, filled in later250intptr_t *fp = stack->sp();251assert(fp - stack->sp() == next_frame_off, "should be");252253stack->push(FAKE_STUB_FRAME);254assert(fp - stack->sp() == frame_type_off, "should be");255256return (FakeStubFrame *) fp;257}258259260