src/share/vm/shark/sharkStack.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

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 2008, 2009, 2010 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_SHARKSTACK_HPP
aoqi@0 27 #define SHARE_VM_SHARK_SHARKSTACK_HPP
aoqi@0 28
aoqi@0 29 #include "shark/llvmHeaders.hpp"
aoqi@0 30 #include "shark/sharkInvariants.hpp"
aoqi@0 31 #include "shark/sharkType.hpp"
aoqi@0 32
aoqi@0 33 class SharkFunction;
aoqi@0 34 class SharkNativeWrapper;
aoqi@0 35 class SharkStackWithNormalFrame;
aoqi@0 36 class SharkStackWithNativeFrame;
aoqi@0 37
aoqi@0 38 class SharkStack : public SharkCompileInvariants {
aoqi@0 39 public:
aoqi@0 40 static SharkStack* CreateBuildAndPushFrame(
aoqi@0 41 SharkFunction* function, llvm::Value* method);
aoqi@0 42 static SharkStack* CreateBuildAndPushFrame(
aoqi@0 43 SharkNativeWrapper* wrapper, llvm::Value* method);
aoqi@0 44
aoqi@0 45 protected:
aoqi@0 46 SharkStack(const SharkCompileInvariants* parent)
aoqi@0 47 : SharkCompileInvariants(parent) {}
aoqi@0 48
aoqi@0 49 protected:
aoqi@0 50 void initialize(llvm::Value* method);
aoqi@0 51
aoqi@0 52 protected:
aoqi@0 53 void CreateStackOverflowCheck(llvm::Value* sp);
aoqi@0 54
aoqi@0 55 // Properties of the method being compiled
aoqi@0 56 protected:
aoqi@0 57 virtual int arg_size() const = 0;
aoqi@0 58 virtual int max_locals() const = 0;
aoqi@0 59 virtual int max_stack() const = 0;
aoqi@0 60 virtual int max_monitors() const = 0;
aoqi@0 61
aoqi@0 62 // BasicBlock creation
aoqi@0 63 protected:
aoqi@0 64 virtual llvm::BasicBlock* CreateBlock(const char* name = "") const = 0;
aoqi@0 65
aoqi@0 66 // Interpreter entry point for bailouts
aoqi@0 67 protected:
aoqi@0 68 virtual address interpreter_entry_point() const = 0;
aoqi@0 69
aoqi@0 70 // Interface with the Zero stack
aoqi@0 71 private:
aoqi@0 72 llvm::Value* zero_stack() const {
aoqi@0 73 return builder()->CreateAddressOfStructEntry(
aoqi@0 74 thread(),
aoqi@0 75 JavaThread::zero_stack_offset(),
aoqi@0 76 SharkType::zeroStack_type(),
aoqi@0 77 "zero_stack");
aoqi@0 78 }
aoqi@0 79 llvm::Value* stack_base() const {
aoqi@0 80 return builder()->CreateValueOfStructEntry(
aoqi@0 81 zero_stack(),
aoqi@0 82 ZeroStack::base_offset(),
aoqi@0 83 SharkType::intptr_type(),
aoqi@0 84 "stack_base");
aoqi@0 85 }
aoqi@0 86 llvm::Value* stack_pointer_addr() const {
aoqi@0 87 return builder()->CreateAddressOfStructEntry(
aoqi@0 88 zero_stack(),
aoqi@0 89 ZeroStack::sp_offset(),
aoqi@0 90 llvm::PointerType::getUnqual(SharkType::intptr_type()),
aoqi@0 91 "stack_pointer_addr");
aoqi@0 92 }
aoqi@0 93 llvm::Value* frame_pointer_addr() const {
aoqi@0 94 return builder()->CreateAddressOfStructEntry(
aoqi@0 95 thread(),
aoqi@0 96 JavaThread::top_zero_frame_offset(),
aoqi@0 97 llvm::PointerType::getUnqual(SharkType::intptr_type()),
aoqi@0 98 "frame_pointer_addr");
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 public:
aoqi@0 102 llvm::LoadInst* CreateLoadStackPointer(const char *name = "") {
aoqi@0 103 return builder()->CreateLoad(stack_pointer_addr(), name);
aoqi@0 104 }
aoqi@0 105 llvm::StoreInst* CreateStoreStackPointer(llvm::Value* value) {
aoqi@0 106 return builder()->CreateStore(value, stack_pointer_addr());
aoqi@0 107 }
aoqi@0 108 llvm::LoadInst* CreateLoadFramePointer(const char *name = "") {
aoqi@0 109 return builder()->CreateLoad(frame_pointer_addr(), name);
aoqi@0 110 }
aoqi@0 111 llvm::StoreInst* CreateStoreFramePointer(llvm::Value* value) {
aoqi@0 112 return builder()->CreateStore(value, frame_pointer_addr());
aoqi@0 113 }
aoqi@0 114 llvm::Value* CreatePopFrame(int result_slots);
aoqi@0 115
aoqi@0 116 // Interface with the frame anchor
aoqi@0 117 private:
aoqi@0 118 llvm::Value* last_Java_sp_addr() const {
aoqi@0 119 return builder()->CreateAddressOfStructEntry(
aoqi@0 120 thread(),
aoqi@0 121 JavaThread::last_Java_sp_offset(),
aoqi@0 122 llvm::PointerType::getUnqual(SharkType::intptr_type()),
aoqi@0 123 "last_Java_sp_addr");
aoqi@0 124 }
aoqi@0 125 llvm::Value* last_Java_fp_addr() const {
aoqi@0 126 return builder()->CreateAddressOfStructEntry(
aoqi@0 127 thread(),
aoqi@0 128 JavaThread::last_Java_fp_offset(),
aoqi@0 129 llvm::PointerType::getUnqual(SharkType::intptr_type()),
aoqi@0 130 "last_Java_fp_addr");
aoqi@0 131 }
aoqi@0 132
aoqi@0 133 public:
aoqi@0 134 void CreateSetLastJavaFrame() {
aoqi@0 135 // Note that whenever _last_Java_sp != NULL other anchor fields
aoqi@0 136 // must be valid. The profiler apparently depends on this.
aoqi@0 137 NOT_PRODUCT(CreateAssertLastJavaSPIsNull());
aoqi@0 138 builder()->CreateStore(CreateLoadFramePointer(), last_Java_fp_addr());
aoqi@0 139 // XXX There's last_Java_pc as well, but I don't think anything uses it
aoqi@0 140 // Also XXX: should we fence here? Zero doesn't...
aoqi@0 141 builder()->CreateStore(CreateLoadStackPointer(), last_Java_sp_addr());
aoqi@0 142 // Also also XXX: we could probably cache the sp (and the fp we know??)
aoqi@0 143 }
aoqi@0 144 void CreateResetLastJavaFrame() {
aoqi@0 145 builder()->CreateStore(LLVMValue::intptr_constant(0), last_Java_sp_addr());
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 private:
aoqi@0 149 void CreateAssertLastJavaSPIsNull() const PRODUCT_RETURN;
aoqi@0 150
aoqi@0 151 // Our method's frame
aoqi@0 152 private:
aoqi@0 153 llvm::Value* _frame;
aoqi@0 154 int _extended_frame_size;
aoqi@0 155 int _stack_slots_offset;
aoqi@0 156
aoqi@0 157 public:
aoqi@0 158 int extended_frame_size() const {
aoqi@0 159 return _extended_frame_size;
aoqi@0 160 }
aoqi@0 161 int oopmap_frame_size() const {
aoqi@0 162 return extended_frame_size() - arg_size();
aoqi@0 163 }
aoqi@0 164
aoqi@0 165 // Offsets of things in the frame
aoqi@0 166 private:
aoqi@0 167 int _monitors_slots_offset;
aoqi@0 168 int _oop_tmp_slot_offset;
aoqi@0 169 int _method_slot_offset;
aoqi@0 170 int _pc_slot_offset;
aoqi@0 171 int _locals_slots_offset;
aoqi@0 172
aoqi@0 173 public:
aoqi@0 174 int stack_slots_offset() const {
aoqi@0 175 return _stack_slots_offset;
aoqi@0 176 }
aoqi@0 177 int oop_tmp_slot_offset() const {
aoqi@0 178 return _oop_tmp_slot_offset;
aoqi@0 179 }
aoqi@0 180 int method_slot_offset() const {
aoqi@0 181 return _method_slot_offset;
aoqi@0 182 }
aoqi@0 183 int pc_slot_offset() const {
aoqi@0 184 return _pc_slot_offset;
aoqi@0 185 }
aoqi@0 186 int locals_slots_offset() const {
aoqi@0 187 return _locals_slots_offset;
aoqi@0 188 }
aoqi@0 189 int monitor_offset(int index) const {
aoqi@0 190 assert(index >= 0 && index < max_monitors(), "invalid monitor index");
aoqi@0 191 return _monitors_slots_offset +
aoqi@0 192 (max_monitors() - 1 - index) * frame::interpreter_frame_monitor_size();
aoqi@0 193 }
aoqi@0 194 int monitor_object_offset(int index) const {
aoqi@0 195 return monitor_offset(index) +
aoqi@0 196 (BasicObjectLock::obj_offset_in_bytes() >> LogBytesPerWord);
aoqi@0 197 }
aoqi@0 198 int monitor_header_offset(int index) const {
aoqi@0 199 return monitor_offset(index) +
aoqi@0 200 ((BasicObjectLock::lock_offset_in_bytes() +
aoqi@0 201 BasicLock::displaced_header_offset_in_bytes()) >> LogBytesPerWord);
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 // Addresses of things in the frame
aoqi@0 205 public:
aoqi@0 206 llvm::Value* slot_addr(int offset,
aoqi@0 207 llvm::Type* type = NULL,
aoqi@0 208 const char* name = "") const;
aoqi@0 209
aoqi@0 210 llvm::Value* monitor_addr(int index) const {
aoqi@0 211 return slot_addr(
aoqi@0 212 monitor_offset(index),
aoqi@0 213 SharkType::monitor_type(),
aoqi@0 214 "monitor");
aoqi@0 215 }
aoqi@0 216 llvm::Value* monitor_object_addr(int index) const {
aoqi@0 217 return slot_addr(
aoqi@0 218 monitor_object_offset(index),
aoqi@0 219 SharkType::oop_type(),
aoqi@0 220 "object_addr");
aoqi@0 221 }
aoqi@0 222 llvm::Value* monitor_header_addr(int index) const {
aoqi@0 223 return slot_addr(
aoqi@0 224 monitor_header_offset(index),
aoqi@0 225 SharkType::intptr_type(),
aoqi@0 226 "displaced_header_addr");
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 // oopmap helpers
aoqi@0 230 public:
aoqi@0 231 static int oopmap_slot_munge(int offset) {
aoqi@0 232 return offset << (LogBytesPerWord - LogBytesPerInt);
aoqi@0 233 }
aoqi@0 234 static VMReg slot2reg(int offset) {
aoqi@0 235 return VMRegImpl::stack2reg(oopmap_slot_munge(offset));
aoqi@0 236 }
aoqi@0 237 };
aoqi@0 238
aoqi@0 239 class SharkStackWithNormalFrame : public SharkStack {
aoqi@0 240 friend class SharkStack;
aoqi@0 241
aoqi@0 242 protected:
aoqi@0 243 SharkStackWithNormalFrame(SharkFunction* function, llvm::Value* method);
aoqi@0 244
aoqi@0 245 private:
aoqi@0 246 SharkFunction* _function;
aoqi@0 247
aoqi@0 248 private:
aoqi@0 249 SharkFunction* function() const {
aoqi@0 250 return _function;
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 // Properties of the method being compiled
aoqi@0 254 private:
aoqi@0 255 int arg_size() const;
aoqi@0 256 int max_locals() const;
aoqi@0 257 int max_stack() const;
aoqi@0 258 int max_monitors() const;
aoqi@0 259
aoqi@0 260 // BasicBlock creation
aoqi@0 261 private:
aoqi@0 262 llvm::BasicBlock* CreateBlock(const char* name = "") const;
aoqi@0 263
aoqi@0 264 // Interpreter entry point for bailouts
aoqi@0 265 private:
aoqi@0 266 address interpreter_entry_point() const;
aoqi@0 267 };
aoqi@0 268
aoqi@0 269 class SharkStackWithNativeFrame : public SharkStack {
aoqi@0 270 friend class SharkStack;
aoqi@0 271
aoqi@0 272 protected:
aoqi@0 273 SharkStackWithNativeFrame(SharkNativeWrapper* wrapper, llvm::Value* method);
aoqi@0 274
aoqi@0 275 private:
aoqi@0 276 SharkNativeWrapper* _wrapper;
aoqi@0 277
aoqi@0 278 private:
aoqi@0 279 SharkNativeWrapper* wrapper() const {
aoqi@0 280 return _wrapper;
aoqi@0 281 }
aoqi@0 282
aoqi@0 283 // Properties of the method being compiled
aoqi@0 284 private:
aoqi@0 285 int arg_size() const;
aoqi@0 286 int max_locals() const;
aoqi@0 287 int max_stack() const;
aoqi@0 288 int max_monitors() const;
aoqi@0 289
aoqi@0 290 // BasicBlock creation
aoqi@0 291 private:
aoqi@0 292 llvm::BasicBlock* CreateBlock(const char* name = "") const;
aoqi@0 293
aoqi@0 294 // Interpreter entry point for bailouts
aoqi@0 295 private:
aoqi@0 296 address interpreter_entry_point() const;
aoqi@0 297 };
aoqi@0 298
aoqi@0 299 #endif // SHARE_VM_SHARK_SHARKSTACK_HPP

mercurial