Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * Copyright 2009 Red Hat, Inc. |
aoqi@0 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 5 | * |
aoqi@0 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 8 | * published by the Free Software Foundation. |
aoqi@0 | 9 | * |
aoqi@0 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 14 | * accompanied this code). |
aoqi@0 | 15 | * |
aoqi@0 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 19 | * |
aoqi@0 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 22 | * questions. |
aoqi@0 | 23 | * |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | #ifndef SHARE_VM_SHARK_SHARKNATIVEWRAPPER_HPP |
aoqi@0 | 27 | #define SHARE_VM_SHARK_SHARKNATIVEWRAPPER_HPP |
aoqi@0 | 28 | |
aoqi@0 | 29 | #include "runtime/handles.hpp" |
aoqi@0 | 30 | #include "shark/llvmHeaders.hpp" |
aoqi@0 | 31 | #include "shark/sharkBuilder.hpp" |
aoqi@0 | 32 | #include "shark/sharkContext.hpp" |
aoqi@0 | 33 | #include "shark/sharkInvariants.hpp" |
aoqi@0 | 34 | #include "shark/sharkStack.hpp" |
aoqi@0 | 35 | |
aoqi@0 | 36 | class SharkNativeWrapper : public SharkCompileInvariants { |
aoqi@0 | 37 | friend class SharkStackWithNativeFrame; |
aoqi@0 | 38 | |
aoqi@0 | 39 | public: |
aoqi@0 | 40 | static SharkNativeWrapper* build(SharkBuilder* builder, |
aoqi@0 | 41 | methodHandle target, |
aoqi@0 | 42 | const char* name, |
aoqi@0 | 43 | BasicType* arg_types, |
aoqi@0 | 44 | BasicType return_type) { |
aoqi@0 | 45 | return new SharkNativeWrapper(builder, |
aoqi@0 | 46 | target, |
aoqi@0 | 47 | name, |
aoqi@0 | 48 | arg_types, |
aoqi@0 | 49 | return_type); |
aoqi@0 | 50 | } |
aoqi@0 | 51 | |
aoqi@0 | 52 | private: |
aoqi@0 | 53 | SharkNativeWrapper(SharkBuilder* builder, |
aoqi@0 | 54 | methodHandle target, |
aoqi@0 | 55 | const char* name, |
aoqi@0 | 56 | BasicType* arg_types, |
aoqi@0 | 57 | BasicType return_type) |
aoqi@0 | 58 | : SharkCompileInvariants(NULL, builder), |
aoqi@0 | 59 | _target(target), |
aoqi@0 | 60 | _arg_types(arg_types), |
aoqi@0 | 61 | _return_type(return_type), |
aoqi@0 | 62 | _lock_slot_offset(0) { initialize(name); } |
aoqi@0 | 63 | |
aoqi@0 | 64 | private: |
aoqi@0 | 65 | void initialize(const char* name); |
aoqi@0 | 66 | |
aoqi@0 | 67 | private: |
aoqi@0 | 68 | methodHandle _target; |
aoqi@0 | 69 | BasicType* _arg_types; |
aoqi@0 | 70 | BasicType _return_type; |
aoqi@0 | 71 | llvm::Function* _function; |
aoqi@0 | 72 | SharkStack* _stack; |
aoqi@0 | 73 | llvm::Value* _oop_tmp_slot; |
aoqi@0 | 74 | OopMapSet* _oop_maps; |
aoqi@0 | 75 | int _receiver_slot_offset; |
aoqi@0 | 76 | int _lock_slot_offset; |
aoqi@0 | 77 | |
aoqi@0 | 78 | // The method being compiled. |
aoqi@0 | 79 | protected: |
aoqi@0 | 80 | methodHandle target() const { |
aoqi@0 | 81 | return _target; |
aoqi@0 | 82 | } |
aoqi@0 | 83 | |
aoqi@0 | 84 | // Properties of the method. |
aoqi@0 | 85 | protected: |
aoqi@0 | 86 | int arg_size() const { |
aoqi@0 | 87 | return target()->size_of_parameters(); |
aoqi@0 | 88 | } |
aoqi@0 | 89 | BasicType arg_type(int i) const { |
aoqi@0 | 90 | return _arg_types[i]; |
aoqi@0 | 91 | } |
aoqi@0 | 92 | BasicType return_type() const { |
aoqi@0 | 93 | return _return_type; |
aoqi@0 | 94 | } |
aoqi@0 | 95 | bool is_static() const { |
aoqi@0 | 96 | return target()->is_static(); |
aoqi@0 | 97 | } |
aoqi@0 | 98 | bool is_synchronized() const { |
aoqi@0 | 99 | return target()->is_synchronized(); |
aoqi@0 | 100 | } |
aoqi@0 | 101 | bool is_returning_oop() const { |
aoqi@0 | 102 | return target()->is_returning_oop(); |
aoqi@0 | 103 | } |
aoqi@0 | 104 | |
aoqi@0 | 105 | // The LLVM function we are building. |
aoqi@0 | 106 | public: |
aoqi@0 | 107 | llvm::Function* function() const { |
aoqi@0 | 108 | return _function; |
aoqi@0 | 109 | } |
aoqi@0 | 110 | |
aoqi@0 | 111 | // The Zero stack and our frame on it. |
aoqi@0 | 112 | protected: |
aoqi@0 | 113 | SharkStack* stack() const { |
aoqi@0 | 114 | return _stack; |
aoqi@0 | 115 | } |
aoqi@0 | 116 | |
aoqi@0 | 117 | // Temporary oop storage. |
aoqi@0 | 118 | protected: |
aoqi@0 | 119 | llvm::Value* oop_tmp_slot() const { |
aoqi@0 | 120 | assert(is_static() || is_returning_oop(), "should be"); |
aoqi@0 | 121 | return _oop_tmp_slot; |
aoqi@0 | 122 | } |
aoqi@0 | 123 | |
aoqi@0 | 124 | // Information required by nmethod::new_native_nmethod(). |
aoqi@0 | 125 | public: |
aoqi@0 | 126 | int frame_size() const { |
aoqi@0 | 127 | return stack()->oopmap_frame_size(); |
aoqi@0 | 128 | } |
aoqi@0 | 129 | ByteSize receiver_offset() const { |
aoqi@0 | 130 | return in_ByteSize(_receiver_slot_offset * wordSize); |
aoqi@0 | 131 | } |
aoqi@0 | 132 | ByteSize lock_offset() const { |
aoqi@0 | 133 | return in_ByteSize(_lock_slot_offset * wordSize); |
aoqi@0 | 134 | } |
aoqi@0 | 135 | OopMapSet* oop_maps() const { |
aoqi@0 | 136 | return _oop_maps; |
aoqi@0 | 137 | } |
aoqi@0 | 138 | |
aoqi@0 | 139 | // Helpers. |
aoqi@0 | 140 | private: |
aoqi@0 | 141 | llvm::BasicBlock* CreateBlock(const char* name = "") const { |
aoqi@0 | 142 | return llvm::BasicBlock::Create(SharkContext::current(), name, function()); |
aoqi@0 | 143 | } |
aoqi@0 | 144 | llvm::Value* thread_state_address() const { |
aoqi@0 | 145 | return builder()->CreateAddressOfStructEntry( |
aoqi@0 | 146 | thread(), JavaThread::thread_state_offset(), |
aoqi@0 | 147 | llvm::PointerType::getUnqual(SharkType::jint_type()), |
aoqi@0 | 148 | "thread_state_address"); |
aoqi@0 | 149 | } |
aoqi@0 | 150 | llvm::Value* pending_exception_address() const { |
aoqi@0 | 151 | return builder()->CreateAddressOfStructEntry( |
aoqi@0 | 152 | thread(), Thread::pending_exception_offset(), |
aoqi@0 | 153 | llvm::PointerType::getUnqual(SharkType::oop_type()), |
aoqi@0 | 154 | "pending_exception_address"); |
aoqi@0 | 155 | } |
aoqi@0 | 156 | void CreateSetThreadState(JavaThreadState state) const { |
aoqi@0 | 157 | builder()->CreateStore( |
aoqi@0 | 158 | LLVMValue::jint_constant(state), thread_state_address()); |
aoqi@0 | 159 | } |
aoqi@0 | 160 | void CreateWriteMemorySerializePage() const { |
aoqi@0 | 161 | builder()->CreateStore( |
aoqi@0 | 162 | LLVMValue::jint_constant(1), |
aoqi@0 | 163 | builder()->CreateIntToPtr( |
aoqi@0 | 164 | builder()->CreateAdd( |
aoqi@0 | 165 | LLVMValue::intptr_constant( |
aoqi@0 | 166 | (intptr_t) os::get_memory_serialize_page()), |
aoqi@0 | 167 | builder()->CreateAnd( |
aoqi@0 | 168 | builder()->CreateLShr( |
aoqi@0 | 169 | builder()->CreatePtrToInt(thread(), SharkType::intptr_type()), |
aoqi@0 | 170 | LLVMValue::intptr_constant(os::get_serialize_page_shift_count())), |
aoqi@0 | 171 | LLVMValue::intptr_constant(os::get_serialize_page_mask()))), |
aoqi@0 | 172 | llvm::PointerType::getUnqual(SharkType::jint_type()))); |
aoqi@0 | 173 | } |
aoqi@0 | 174 | void CreateResetHandleBlock() const { |
aoqi@0 | 175 | llvm::Value *active_handles = builder()->CreateValueOfStructEntry( |
aoqi@0 | 176 | thread(), |
aoqi@0 | 177 | JavaThread::active_handles_offset(), |
aoqi@0 | 178 | SharkType::jniHandleBlock_type(), |
aoqi@0 | 179 | "active_handles"); |
aoqi@0 | 180 | builder()->CreateStore( |
aoqi@0 | 181 | LLVMValue::intptr_constant(0), |
aoqi@0 | 182 | builder()->CreateAddressOfStructEntry( |
aoqi@0 | 183 | active_handles, |
aoqi@0 | 184 | in_ByteSize(JNIHandleBlock::top_offset_in_bytes()), |
aoqi@0 | 185 | llvm::PointerType::getUnqual(SharkType::intptr_type()), |
aoqi@0 | 186 | "top")); |
aoqi@0 | 187 | } |
aoqi@0 | 188 | llvm::LoadInst* CreateLoadPendingException() const { |
aoqi@0 | 189 | return builder()->CreateLoad( |
aoqi@0 | 190 | pending_exception_address(), "pending_exception"); |
aoqi@0 | 191 | } |
aoqi@0 | 192 | }; |
aoqi@0 | 193 | |
aoqi@0 | 194 | #endif // SHARE_VM_SHARK_SHARKNATIVEWRAPPER_HPP |