src/share/vm/shark/sharkNativeWrapper.hpp

Wed, 11 Aug 2010 05:51:21 -0700

author
twisti
date
Wed, 11 Aug 2010 05:51:21 -0700
changeset 2047
d2ede61b7a12
child 2314
f95d63e2154a
permissions
-rw-r--r--

6976186: integrate Shark HotSpot changes
Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure.
Reviewed-by: kvn, twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

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

mercurial