Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkNativeWrapper.hpp
32285 views
/*1* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.2* Copyright 2009 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#ifndef SHARE_VM_SHARK_SHARKNATIVEWRAPPER_HPP26#define SHARE_VM_SHARK_SHARKNATIVEWRAPPER_HPP2728#include "runtime/handles.hpp"29#include "shark/llvmHeaders.hpp"30#include "shark/sharkBuilder.hpp"31#include "shark/sharkContext.hpp"32#include "shark/sharkInvariants.hpp"33#include "shark/sharkStack.hpp"3435class SharkNativeWrapper : public SharkCompileInvariants {36friend class SharkStackWithNativeFrame;3738public:39static SharkNativeWrapper* build(SharkBuilder* builder,40methodHandle target,41const char* name,42BasicType* arg_types,43BasicType return_type) {44return new SharkNativeWrapper(builder,45target,46name,47arg_types,48return_type);49}5051private:52SharkNativeWrapper(SharkBuilder* builder,53methodHandle target,54const char* name,55BasicType* arg_types,56BasicType return_type)57: SharkCompileInvariants(NULL, builder),58_target(target),59_arg_types(arg_types),60_return_type(return_type),61_lock_slot_offset(0) { initialize(name); }6263private:64void initialize(const char* name);6566private:67methodHandle _target;68BasicType* _arg_types;69BasicType _return_type;70llvm::Function* _function;71SharkStack* _stack;72llvm::Value* _oop_tmp_slot;73OopMapSet* _oop_maps;74int _receiver_slot_offset;75int _lock_slot_offset;7677// The method being compiled.78protected:79methodHandle target() const {80return _target;81}8283// Properties of the method.84protected:85int arg_size() const {86return target()->size_of_parameters();87}88BasicType arg_type(int i) const {89return _arg_types[i];90}91BasicType return_type() const {92return _return_type;93}94bool is_static() const {95return target()->is_static();96}97bool is_synchronized() const {98return target()->is_synchronized();99}100bool is_returning_oop() const {101return target()->is_returning_oop();102}103104// The LLVM function we are building.105public:106llvm::Function* function() const {107return _function;108}109110// The Zero stack and our frame on it.111protected:112SharkStack* stack() const {113return _stack;114}115116// Temporary oop storage.117protected:118llvm::Value* oop_tmp_slot() const {119assert(is_static() || is_returning_oop(), "should be");120return _oop_tmp_slot;121}122123// Information required by nmethod::new_native_nmethod().124public:125int frame_size() const {126return stack()->oopmap_frame_size();127}128ByteSize receiver_offset() const {129return in_ByteSize(_receiver_slot_offset * wordSize);130}131ByteSize lock_offset() const {132return in_ByteSize(_lock_slot_offset * wordSize);133}134OopMapSet* oop_maps() const {135return _oop_maps;136}137138// Helpers.139private:140llvm::BasicBlock* CreateBlock(const char* name = "") const {141return llvm::BasicBlock::Create(SharkContext::current(), name, function());142}143llvm::Value* thread_state_address() const {144return builder()->CreateAddressOfStructEntry(145thread(), JavaThread::thread_state_offset(),146llvm::PointerType::getUnqual(SharkType::jint_type()),147"thread_state_address");148}149llvm::Value* pending_exception_address() const {150return builder()->CreateAddressOfStructEntry(151thread(), Thread::pending_exception_offset(),152llvm::PointerType::getUnqual(SharkType::oop_type()),153"pending_exception_address");154}155void CreateSetThreadState(JavaThreadState state) const {156builder()->CreateStore(157LLVMValue::jint_constant(state), thread_state_address());158}159void CreateWriteMemorySerializePage() const {160builder()->CreateStore(161LLVMValue::jint_constant(1),162builder()->CreateIntToPtr(163builder()->CreateAdd(164LLVMValue::intptr_constant(165(intptr_t) os::get_memory_serialize_page()),166builder()->CreateAnd(167builder()->CreateLShr(168builder()->CreatePtrToInt(thread(), SharkType::intptr_type()),169LLVMValue::intptr_constant(os::get_serialize_page_shift_count())),170LLVMValue::intptr_constant(os::get_serialize_page_mask()))),171llvm::PointerType::getUnqual(SharkType::jint_type())));172}173void CreateResetHandleBlock() const {174llvm::Value *active_handles = builder()->CreateValueOfStructEntry(175thread(),176JavaThread::active_handles_offset(),177SharkType::jniHandleBlock_type(),178"active_handles");179builder()->CreateStore(180LLVMValue::intptr_constant(0),181builder()->CreateAddressOfStructEntry(182active_handles,183in_ByteSize(JNIHandleBlock::top_offset_in_bytes()),184llvm::PointerType::getUnqual(SharkType::intptr_type()),185"top"));186}187llvm::LoadInst* CreateLoadPendingException() const {188return builder()->CreateLoad(189pending_exception_address(), "pending_exception");190}191};192193#endif // SHARE_VM_SHARK_SHARKNATIVEWRAPPER_HPP194195196