1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/zero/vm/stack_zero.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,226 @@ 1.4 +/* 1.5 + * Copyright (c) 2003, 2010, 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 +#ifndef CPU_ZERO_VM_STACK_ZERO_HPP 1.30 +#define CPU_ZERO_VM_STACK_ZERO_HPP 1.31 + 1.32 +#include "utilities/sizes.hpp" 1.33 + 1.34 +class ZeroStack { 1.35 + private: 1.36 + intptr_t *_base; // the last available word 1.37 + intptr_t *_top; // the word past the end of the stack 1.38 + intptr_t *_sp; // the top word on the stack 1.39 + 1.40 + private: 1.41 + int _shadow_pages_size; // how much ABI stack must we keep free? 1.42 + 1.43 + public: 1.44 + ZeroStack() 1.45 + : _base(NULL), _top(NULL), _sp(NULL) { 1.46 + _shadow_pages_size = StackShadowPages * os::vm_page_size(); 1.47 + } 1.48 + 1.49 + bool needs_setup() const { 1.50 + return _base == NULL; 1.51 + } 1.52 + 1.53 + int suggest_size(Thread *thread) const; 1.54 + 1.55 + void setup(void *mem, size_t size) { 1.56 + assert(needs_setup(), "already set up"); 1.57 + assert(!(size & WordAlignmentMask), "unaligned"); 1.58 + 1.59 + _base = (intptr_t *) mem; 1.60 + _top = _base + (size >> LogBytesPerWord); 1.61 + _sp = _top; 1.62 + } 1.63 + void teardown() { 1.64 + assert(!needs_setup(), "not set up"); 1.65 + assert(_sp == _top, "stuff on stack at teardown"); 1.66 + 1.67 + _base = NULL; 1.68 + _top = NULL; 1.69 + _sp = NULL; 1.70 + } 1.71 + 1.72 + intptr_t *sp() const { 1.73 + return _sp; 1.74 + } 1.75 + void set_sp(intptr_t *new_sp) { 1.76 + assert(_top >= new_sp && new_sp >= _base, "bad stack pointer"); 1.77 + _sp = new_sp; 1.78 + } 1.79 + 1.80 + int total_words() const { 1.81 + return _top - _base; 1.82 + } 1.83 + int available_words() const { 1.84 + return _sp - _base; 1.85 + } 1.86 + 1.87 + void push(intptr_t value) { 1.88 + assert(_sp > _base, "stack overflow"); 1.89 + *(--_sp) = value; 1.90 + } 1.91 + intptr_t pop() { 1.92 + assert(_sp < _top, "stack underflow"); 1.93 + return *(_sp++); 1.94 + } 1.95 + 1.96 + void *alloc(size_t size) { 1.97 + int count = align_size_up(size, wordSize) >> LogBytesPerWord; 1.98 + assert(count <= available_words(), "stack overflow"); 1.99 + return _sp -= count; 1.100 + } 1.101 + 1.102 + int shadow_pages_size() const { 1.103 + return _shadow_pages_size; 1.104 + } 1.105 + int abi_stack_available(Thread *thread) const; 1.106 + 1.107 + public: 1.108 + void overflow_check(int required_words, TRAPS); 1.109 + static void handle_overflow(TRAPS); 1.110 + 1.111 + public: 1.112 + void zap(int c) PRODUCT_RETURN; 1.113 + 1.114 + public: 1.115 + static ByteSize base_offset() { 1.116 + return byte_offset_of(ZeroStack, _base); 1.117 + } 1.118 + static ByteSize top_offset() { 1.119 + return byte_offset_of(ZeroStack, _top); 1.120 + } 1.121 + static ByteSize sp_offset() { 1.122 + return byte_offset_of(ZeroStack, _sp); 1.123 + } 1.124 +}; 1.125 + 1.126 + 1.127 +class EntryFrame; 1.128 +class InterpreterFrame; 1.129 +class SharkFrame; 1.130 +class FakeStubFrame; 1.131 + 1.132 +// 1.133 +// | ... | 1.134 +// +--------------------+ ------------------ 1.135 +// | ... | low addresses 1.136 +// | frame_type | 1.137 +// | next_frame | high addresses 1.138 +// +--------------------+ ------------------ 1.139 +// | ... | 1.140 + 1.141 +class ZeroFrame { 1.142 + friend class frame; 1.143 + friend class ZeroStackPrinter; 1.144 + 1.145 + protected: 1.146 + ZeroFrame() { 1.147 + ShouldNotCallThis(); 1.148 + } 1.149 + 1.150 + enum Layout { 1.151 + next_frame_off, 1.152 + frame_type_off, 1.153 + jf_header_words 1.154 + }; 1.155 + 1.156 + enum FrameType { 1.157 + ENTRY_FRAME = 1, 1.158 + INTERPRETER_FRAME, 1.159 + SHARK_FRAME, 1.160 + FAKE_STUB_FRAME 1.161 + }; 1.162 + 1.163 + protected: 1.164 + intptr_t *addr_of_word(int offset) const { 1.165 + return (intptr_t *) this - offset; 1.166 + } 1.167 + intptr_t value_of_word(int offset) const { 1.168 + return *addr_of_word(offset); 1.169 + } 1.170 + 1.171 + public: 1.172 + ZeroFrame *next() const { 1.173 + return (ZeroFrame *) value_of_word(next_frame_off); 1.174 + } 1.175 + 1.176 + protected: 1.177 + FrameType type() const { 1.178 + return (FrameType) value_of_word(frame_type_off); 1.179 + } 1.180 + 1.181 + public: 1.182 + bool is_entry_frame() const { 1.183 + return type() == ENTRY_FRAME; 1.184 + } 1.185 + bool is_interpreter_frame() const { 1.186 + return type() == INTERPRETER_FRAME; 1.187 + } 1.188 + bool is_shark_frame() const { 1.189 + return type() == SHARK_FRAME; 1.190 + } 1.191 + bool is_fake_stub_frame() const { 1.192 + return type() == FAKE_STUB_FRAME; 1.193 + } 1.194 + 1.195 + public: 1.196 + EntryFrame *as_entry_frame() const { 1.197 + assert(is_entry_frame(), "should be"); 1.198 + return (EntryFrame *) this; 1.199 + } 1.200 + InterpreterFrame *as_interpreter_frame() const { 1.201 + assert(is_interpreter_frame(), "should be"); 1.202 + return (InterpreterFrame *) this; 1.203 + } 1.204 + SharkFrame *as_shark_frame() const { 1.205 + assert(is_shark_frame(), "should be"); 1.206 + return (SharkFrame *) this; 1.207 + } 1.208 + FakeStubFrame *as_fake_stub_frame() const { 1.209 + assert(is_fake_stub_frame(), "should be"); 1.210 + return (FakeStubFrame *) this; 1.211 + } 1.212 + 1.213 + public: 1.214 + void identify_word(int frame_index, 1.215 + int offset, 1.216 + char* fieldbuf, 1.217 + char* valuebuf, 1.218 + int buflen) const; 1.219 + 1.220 + protected: 1.221 + void identify_vp_word(int frame_index, 1.222 + intptr_t* addr, 1.223 + intptr_t* monitor_base, 1.224 + intptr_t* stack_base, 1.225 + char* fieldbuf, 1.226 + int buflen) const; 1.227 +}; 1.228 + 1.229 +#endif // CPU_ZERO_VM_STACK_ZERO_HPP