1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkStack.cpp Wed Aug 11 05:51:21 2010 -0700 1.3 @@ -0,0 +1,263 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2008, 2009, 2010 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 +#include "incls/_precompiled.incl" 1.30 +#include "incls/_sharkStack.cpp.incl" 1.31 + 1.32 +using namespace llvm; 1.33 + 1.34 +void SharkStack::initialize(Value* method) { 1.35 + bool setup_sp_and_method = (method != NULL); 1.36 + 1.37 + int locals_words = max_locals(); 1.38 + int extra_locals = locals_words - arg_size(); 1.39 + int header_words = SharkFrame::header_words; 1.40 + int monitor_words = max_monitors()*frame::interpreter_frame_monitor_size(); 1.41 + int stack_words = max_stack(); 1.42 + int frame_words = header_words + monitor_words + stack_words; 1.43 + 1.44 + _extended_frame_size = frame_words + locals_words; 1.45 + 1.46 + // Update the stack pointer 1.47 + Value *stack_pointer = builder()->CreateSub( 1.48 + CreateLoadStackPointer(), 1.49 + LLVMValue::intptr_constant((frame_words + extra_locals) * wordSize)); 1.50 + CreateStackOverflowCheck(stack_pointer); 1.51 + if (setup_sp_and_method) 1.52 + CreateStoreStackPointer(stack_pointer); 1.53 + 1.54 + // Create the frame 1.55 + _frame = builder()->CreateIntToPtr( 1.56 + stack_pointer, 1.57 + PointerType::getUnqual( 1.58 + ArrayType::get(SharkType::intptr_type(), extended_frame_size())), 1.59 + "frame"); 1.60 + int offset = 0; 1.61 + 1.62 + // Expression stack 1.63 + _stack_slots_offset = offset; 1.64 + offset += stack_words; 1.65 + 1.66 + // Monitors 1.67 + _monitors_slots_offset = offset; 1.68 + offset += monitor_words; 1.69 + 1.70 + // Temporary oop slot 1.71 + _oop_tmp_slot_offset = offset++; 1.72 + 1.73 + // Method pointer 1.74 + _method_slot_offset = offset++; 1.75 + if (setup_sp_and_method) { 1.76 + builder()->CreateStore( 1.77 + method, slot_addr(method_slot_offset(), SharkType::methodOop_type())); 1.78 + } 1.79 + 1.80 + // Unextended SP 1.81 + builder()->CreateStore(stack_pointer, slot_addr(offset++)); 1.82 + 1.83 + // PC 1.84 + _pc_slot_offset = offset++; 1.85 + 1.86 + // Frame header 1.87 + builder()->CreateStore( 1.88 + LLVMValue::intptr_constant(ZeroFrame::SHARK_FRAME), slot_addr(offset++)); 1.89 + Value *fp = slot_addr(offset++); 1.90 + 1.91 + // Local variables 1.92 + _locals_slots_offset = offset; 1.93 + offset += locals_words; 1.94 + 1.95 + // Push the frame 1.96 + assert(offset == extended_frame_size(), "should do"); 1.97 + builder()->CreateStore(CreateLoadFramePointer(), fp); 1.98 + CreateStoreFramePointer( 1.99 + builder()->CreatePtrToInt(fp, SharkType::intptr_type())); 1.100 +} 1.101 + 1.102 +// This function should match ZeroStack::overflow_check 1.103 +void SharkStack::CreateStackOverflowCheck(Value* sp) { 1.104 + BasicBlock *zero_ok = CreateBlock("zero_stack_ok"); 1.105 + BasicBlock *overflow = CreateBlock("stack_overflow"); 1.106 + BasicBlock *abi_ok = CreateBlock("abi_stack_ok"); 1.107 + 1.108 + // Check the Zero stack 1.109 + builder()->CreateCondBr( 1.110 + builder()->CreateICmpULT(sp, stack_base()), 1.111 + overflow, zero_ok); 1.112 + 1.113 + // Check the ABI stack 1.114 + builder()->SetInsertPoint(zero_ok); 1.115 + Value *stack_top = builder()->CreateSub( 1.116 + builder()->CreateValueOfStructEntry( 1.117 + thread(), 1.118 + Thread::stack_base_offset(), 1.119 + SharkType::intptr_type(), 1.120 + "abi_base"), 1.121 + builder()->CreateValueOfStructEntry( 1.122 + thread(), 1.123 + Thread::stack_size_offset(), 1.124 + SharkType::intptr_type(), 1.125 + "abi_size")); 1.126 + Value *free_stack = builder()->CreateSub( 1.127 + builder()->CreatePtrToInt( 1.128 + builder()->CreateGetFrameAddress(), 1.129 + SharkType::intptr_type(), 1.130 + "abi_sp"), 1.131 + stack_top); 1.132 + builder()->CreateCondBr( 1.133 + builder()->CreateICmpULT( 1.134 + free_stack, 1.135 + LLVMValue::intptr_constant(StackShadowPages * os::vm_page_size())), 1.136 + overflow, abi_ok); 1.137 + 1.138 + // Handle overflows 1.139 + builder()->SetInsertPoint(overflow); 1.140 + builder()->CreateCall(builder()->throw_StackOverflowError(), thread()); 1.141 + builder()->CreateRet(LLVMValue::jint_constant(0)); 1.142 + 1.143 + builder()->SetInsertPoint(abi_ok); 1.144 +} 1.145 + 1.146 +Value* SharkStack::CreatePopFrame(int result_slots) { 1.147 + assert(result_slots >= 0 && result_slots <= 2, "should be"); 1.148 + int locals_to_pop = max_locals() - result_slots; 1.149 + 1.150 + Value *fp = CreateLoadFramePointer(); 1.151 + Value *sp = builder()->CreateAdd( 1.152 + fp, 1.153 + LLVMValue::intptr_constant((1 + locals_to_pop) * wordSize)); 1.154 + 1.155 + CreateStoreStackPointer(sp); 1.156 + CreateStoreFramePointer( 1.157 + builder()->CreateLoad( 1.158 + builder()->CreateIntToPtr( 1.159 + fp, PointerType::getUnqual(SharkType::intptr_type())))); 1.160 + 1.161 + return sp; 1.162 +} 1.163 + 1.164 +Value* SharkStack::slot_addr(int offset, 1.165 + const Type* type, 1.166 + const char* name) const { 1.167 + bool needs_cast = type && type != SharkType::intptr_type(); 1.168 + 1.169 + Value* result = builder()->CreateStructGEP( 1.170 + _frame, offset, needs_cast ? "" : name); 1.171 + 1.172 + if (needs_cast) { 1.173 + result = builder()->CreateBitCast( 1.174 + result, PointerType::getUnqual(type), name); 1.175 + } 1.176 + return result; 1.177 +} 1.178 + 1.179 +// The bits that differentiate stacks with normal and native frames on top 1.180 + 1.181 +SharkStack* SharkStack::CreateBuildAndPushFrame(SharkFunction* function, 1.182 + Value* method) { 1.183 + return new SharkStackWithNormalFrame(function, method); 1.184 +} 1.185 +SharkStack* SharkStack::CreateBuildAndPushFrame(SharkNativeWrapper* wrapper, 1.186 + Value* method) { 1.187 + return new SharkStackWithNativeFrame(wrapper, method); 1.188 +} 1.189 + 1.190 +SharkStackWithNormalFrame::SharkStackWithNormalFrame(SharkFunction* function, 1.191 + Value* method) 1.192 + : SharkStack(function), _function(function) { 1.193 + // For normal frames, the stack pointer and the method slot will 1.194 + // be set during each decache, so it is not necessary to do them 1.195 + // at the time the frame is created. However, we set them for 1.196 + // non-PRODUCT builds to make crash dumps easier to understand. 1.197 + initialize(PRODUCT_ONLY(NULL) NOT_PRODUCT(method)); 1.198 +} 1.199 +SharkStackWithNativeFrame::SharkStackWithNativeFrame(SharkNativeWrapper* wrp, 1.200 + Value* method) 1.201 + : SharkStack(wrp), _wrapper(wrp) { 1.202 + initialize(method); 1.203 +} 1.204 + 1.205 +int SharkStackWithNormalFrame::arg_size() const { 1.206 + return function()->arg_size(); 1.207 +} 1.208 +int SharkStackWithNativeFrame::arg_size() const { 1.209 + return wrapper()->arg_size(); 1.210 +} 1.211 + 1.212 +int SharkStackWithNormalFrame::max_locals() const { 1.213 + return function()->max_locals(); 1.214 +} 1.215 +int SharkStackWithNativeFrame::max_locals() const { 1.216 + return wrapper()->arg_size(); 1.217 +} 1.218 + 1.219 +int SharkStackWithNormalFrame::max_stack() const { 1.220 + return function()->max_stack(); 1.221 +} 1.222 +int SharkStackWithNativeFrame::max_stack() const { 1.223 + return 0; 1.224 +} 1.225 + 1.226 +int SharkStackWithNormalFrame::max_monitors() const { 1.227 + return function()->max_monitors(); 1.228 +} 1.229 +int SharkStackWithNativeFrame::max_monitors() const { 1.230 + return wrapper()->is_synchronized() ? 1 : 0; 1.231 +} 1.232 + 1.233 +BasicBlock* SharkStackWithNormalFrame::CreateBlock(const char* name) const { 1.234 + return function()->CreateBlock(name); 1.235 +} 1.236 +BasicBlock* SharkStackWithNativeFrame::CreateBlock(const char* name) const { 1.237 + return wrapper()->CreateBlock(name); 1.238 +} 1.239 + 1.240 +address SharkStackWithNormalFrame::interpreter_entry_point() const { 1.241 + return (address) CppInterpreter::normal_entry; 1.242 +} 1.243 +address SharkStackWithNativeFrame::interpreter_entry_point() const { 1.244 + return (address) CppInterpreter::native_entry; 1.245 +} 1.246 + 1.247 +#ifndef PRODUCT 1.248 +void SharkStack::CreateAssertLastJavaSPIsNull() const { 1.249 +#ifdef ASSERT 1.250 + BasicBlock *fail = CreateBlock("assert_failed"); 1.251 + BasicBlock *pass = CreateBlock("assert_ok"); 1.252 + 1.253 + builder()->CreateCondBr( 1.254 + builder()->CreateICmpEQ( 1.255 + builder()->CreateLoad(last_Java_sp_addr()), 1.256 + LLVMValue::intptr_constant(0)), 1.257 + pass, fail); 1.258 + 1.259 + builder()->SetInsertPoint(fail); 1.260 + builder()->CreateShouldNotReachHere(__FILE__, __LINE__); 1.261 + builder()->CreateUnreachable(); 1.262 + 1.263 + builder()->SetInsertPoint(pass); 1.264 +#endif // ASSERT 1.265 +} 1.266 +#endif // !PRODUCT