1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkNativeWrapper.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,194 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2009 Red Hat, Inc. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#ifndef SHARE_VM_SHARK_SHARKNATIVEWRAPPER_HPP 1.30 +#define SHARE_VM_SHARK_SHARKNATIVEWRAPPER_HPP 1.31 + 1.32 +#include "runtime/handles.hpp" 1.33 +#include "shark/llvmHeaders.hpp" 1.34 +#include "shark/sharkBuilder.hpp" 1.35 +#include "shark/sharkContext.hpp" 1.36 +#include "shark/sharkInvariants.hpp" 1.37 +#include "shark/sharkStack.hpp" 1.38 + 1.39 +class SharkNativeWrapper : public SharkCompileInvariants { 1.40 + friend class SharkStackWithNativeFrame; 1.41 + 1.42 + public: 1.43 + static SharkNativeWrapper* build(SharkBuilder* builder, 1.44 + methodHandle target, 1.45 + const char* name, 1.46 + BasicType* arg_types, 1.47 + BasicType return_type) { 1.48 + return new SharkNativeWrapper(builder, 1.49 + target, 1.50 + name, 1.51 + arg_types, 1.52 + return_type); 1.53 + } 1.54 + 1.55 + private: 1.56 + SharkNativeWrapper(SharkBuilder* builder, 1.57 + methodHandle target, 1.58 + const char* name, 1.59 + BasicType* arg_types, 1.60 + BasicType return_type) 1.61 + : SharkCompileInvariants(NULL, builder), 1.62 + _target(target), 1.63 + _arg_types(arg_types), 1.64 + _return_type(return_type), 1.65 + _lock_slot_offset(0) { initialize(name); } 1.66 + 1.67 + private: 1.68 + void initialize(const char* name); 1.69 + 1.70 + private: 1.71 + methodHandle _target; 1.72 + BasicType* _arg_types; 1.73 + BasicType _return_type; 1.74 + llvm::Function* _function; 1.75 + SharkStack* _stack; 1.76 + llvm::Value* _oop_tmp_slot; 1.77 + OopMapSet* _oop_maps; 1.78 + int _receiver_slot_offset; 1.79 + int _lock_slot_offset; 1.80 + 1.81 + // The method being compiled. 1.82 + protected: 1.83 + methodHandle target() const { 1.84 + return _target; 1.85 + } 1.86 + 1.87 + // Properties of the method. 1.88 + protected: 1.89 + int arg_size() const { 1.90 + return target()->size_of_parameters(); 1.91 + } 1.92 + BasicType arg_type(int i) const { 1.93 + return _arg_types[i]; 1.94 + } 1.95 + BasicType return_type() const { 1.96 + return _return_type; 1.97 + } 1.98 + bool is_static() const { 1.99 + return target()->is_static(); 1.100 + } 1.101 + bool is_synchronized() const { 1.102 + return target()->is_synchronized(); 1.103 + } 1.104 + bool is_returning_oop() const { 1.105 + return target()->is_returning_oop(); 1.106 + } 1.107 + 1.108 + // The LLVM function we are building. 1.109 + public: 1.110 + llvm::Function* function() const { 1.111 + return _function; 1.112 + } 1.113 + 1.114 + // The Zero stack and our frame on it. 1.115 + protected: 1.116 + SharkStack* stack() const { 1.117 + return _stack; 1.118 + } 1.119 + 1.120 + // Temporary oop storage. 1.121 + protected: 1.122 + llvm::Value* oop_tmp_slot() const { 1.123 + assert(is_static() || is_returning_oop(), "should be"); 1.124 + return _oop_tmp_slot; 1.125 + } 1.126 + 1.127 + // Information required by nmethod::new_native_nmethod(). 1.128 + public: 1.129 + int frame_size() const { 1.130 + return stack()->oopmap_frame_size(); 1.131 + } 1.132 + ByteSize receiver_offset() const { 1.133 + return in_ByteSize(_receiver_slot_offset * wordSize); 1.134 + } 1.135 + ByteSize lock_offset() const { 1.136 + return in_ByteSize(_lock_slot_offset * wordSize); 1.137 + } 1.138 + OopMapSet* oop_maps() const { 1.139 + return _oop_maps; 1.140 + } 1.141 + 1.142 + // Helpers. 1.143 + private: 1.144 + llvm::BasicBlock* CreateBlock(const char* name = "") const { 1.145 + return llvm::BasicBlock::Create(SharkContext::current(), name, function()); 1.146 + } 1.147 + llvm::Value* thread_state_address() const { 1.148 + return builder()->CreateAddressOfStructEntry( 1.149 + thread(), JavaThread::thread_state_offset(), 1.150 + llvm::PointerType::getUnqual(SharkType::jint_type()), 1.151 + "thread_state_address"); 1.152 + } 1.153 + llvm::Value* pending_exception_address() const { 1.154 + return builder()->CreateAddressOfStructEntry( 1.155 + thread(), Thread::pending_exception_offset(), 1.156 + llvm::PointerType::getUnqual(SharkType::oop_type()), 1.157 + "pending_exception_address"); 1.158 + } 1.159 + void CreateSetThreadState(JavaThreadState state) const { 1.160 + builder()->CreateStore( 1.161 + LLVMValue::jint_constant(state), thread_state_address()); 1.162 + } 1.163 + void CreateWriteMemorySerializePage() const { 1.164 + builder()->CreateStore( 1.165 + LLVMValue::jint_constant(1), 1.166 + builder()->CreateIntToPtr( 1.167 + builder()->CreateAdd( 1.168 + LLVMValue::intptr_constant( 1.169 + (intptr_t) os::get_memory_serialize_page()), 1.170 + builder()->CreateAnd( 1.171 + builder()->CreateLShr( 1.172 + builder()->CreatePtrToInt(thread(), SharkType::intptr_type()), 1.173 + LLVMValue::intptr_constant(os::get_serialize_page_shift_count())), 1.174 + LLVMValue::intptr_constant(os::get_serialize_page_mask()))), 1.175 + llvm::PointerType::getUnqual(SharkType::jint_type()))); 1.176 + } 1.177 + void CreateResetHandleBlock() const { 1.178 + llvm::Value *active_handles = builder()->CreateValueOfStructEntry( 1.179 + thread(), 1.180 + JavaThread::active_handles_offset(), 1.181 + SharkType::jniHandleBlock_type(), 1.182 + "active_handles"); 1.183 + builder()->CreateStore( 1.184 + LLVMValue::intptr_constant(0), 1.185 + builder()->CreateAddressOfStructEntry( 1.186 + active_handles, 1.187 + in_ByteSize(JNIHandleBlock::top_offset_in_bytes()), 1.188 + llvm::PointerType::getUnqual(SharkType::intptr_type()), 1.189 + "top")); 1.190 + } 1.191 + llvm::LoadInst* CreateLoadPendingException() const { 1.192 + return builder()->CreateLoad( 1.193 + pending_exception_address(), "pending_exception"); 1.194 + } 1.195 +}; 1.196 + 1.197 +#endif // SHARE_VM_SHARK_SHARKNATIVEWRAPPER_HPP