src/cpu/zero/vm/stack_zero.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 2314
f95d63e2154a
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 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 CPU_ZERO_VM_STACK_ZERO_HPP
aoqi@0 27 #define CPU_ZERO_VM_STACK_ZERO_HPP
aoqi@0 28
aoqi@0 29 #include "utilities/sizes.hpp"
aoqi@0 30
aoqi@0 31 class ZeroStack {
aoqi@0 32 private:
aoqi@0 33 intptr_t *_base; // the last available word
aoqi@0 34 intptr_t *_top; // the word past the end of the stack
aoqi@0 35 intptr_t *_sp; // the top word on the stack
aoqi@0 36
aoqi@0 37 private:
aoqi@0 38 int _shadow_pages_size; // how much ABI stack must we keep free?
aoqi@0 39
aoqi@0 40 public:
aoqi@0 41 ZeroStack()
aoqi@0 42 : _base(NULL), _top(NULL), _sp(NULL) {
aoqi@0 43 _shadow_pages_size = StackShadowPages * os::vm_page_size();
aoqi@0 44 }
aoqi@0 45
aoqi@0 46 bool needs_setup() const {
aoqi@0 47 return _base == NULL;
aoqi@0 48 }
aoqi@0 49
aoqi@0 50 int suggest_size(Thread *thread) const;
aoqi@0 51
aoqi@0 52 void setup(void *mem, size_t size) {
aoqi@0 53 assert(needs_setup(), "already set up");
aoqi@0 54 assert(!(size & WordAlignmentMask), "unaligned");
aoqi@0 55
aoqi@0 56 _base = (intptr_t *) mem;
aoqi@0 57 _top = _base + (size >> LogBytesPerWord);
aoqi@0 58 _sp = _top;
aoqi@0 59 }
aoqi@0 60 void teardown() {
aoqi@0 61 assert(!needs_setup(), "not set up");
aoqi@0 62 assert(_sp == _top, "stuff on stack at teardown");
aoqi@0 63
aoqi@0 64 _base = NULL;
aoqi@0 65 _top = NULL;
aoqi@0 66 _sp = NULL;
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 intptr_t *sp() const {
aoqi@0 70 return _sp;
aoqi@0 71 }
aoqi@0 72 void set_sp(intptr_t *new_sp) {
aoqi@0 73 assert(_top >= new_sp && new_sp >= _base, "bad stack pointer");
aoqi@0 74 _sp = new_sp;
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 int total_words() const {
aoqi@0 78 return _top - _base;
aoqi@0 79 }
aoqi@0 80 int available_words() const {
aoqi@0 81 return _sp - _base;
aoqi@0 82 }
aoqi@0 83
aoqi@0 84 void push(intptr_t value) {
aoqi@0 85 assert(_sp > _base, "stack overflow");
aoqi@0 86 *(--_sp) = value;
aoqi@0 87 }
aoqi@0 88 intptr_t pop() {
aoqi@0 89 assert(_sp < _top, "stack underflow");
aoqi@0 90 return *(_sp++);
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 void *alloc(size_t size) {
aoqi@0 94 int count = align_size_up(size, wordSize) >> LogBytesPerWord;
aoqi@0 95 assert(count <= available_words(), "stack overflow");
aoqi@0 96 return _sp -= count;
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 int shadow_pages_size() const {
aoqi@0 100 return _shadow_pages_size;
aoqi@0 101 }
aoqi@0 102 int abi_stack_available(Thread *thread) const;
aoqi@0 103
aoqi@0 104 public:
aoqi@0 105 void overflow_check(int required_words, TRAPS);
aoqi@0 106 static void handle_overflow(TRAPS);
aoqi@0 107
aoqi@0 108 public:
aoqi@0 109 void zap(int c) PRODUCT_RETURN;
aoqi@0 110
aoqi@0 111 public:
aoqi@0 112 static ByteSize base_offset() {
aoqi@0 113 return byte_offset_of(ZeroStack, _base);
aoqi@0 114 }
aoqi@0 115 static ByteSize top_offset() {
aoqi@0 116 return byte_offset_of(ZeroStack, _top);
aoqi@0 117 }
aoqi@0 118 static ByteSize sp_offset() {
aoqi@0 119 return byte_offset_of(ZeroStack, _sp);
aoqi@0 120 }
aoqi@0 121 };
aoqi@0 122
aoqi@0 123
aoqi@0 124 class EntryFrame;
aoqi@0 125 class InterpreterFrame;
aoqi@0 126 class SharkFrame;
aoqi@0 127 class FakeStubFrame;
aoqi@0 128
aoqi@0 129 //
aoqi@0 130 // | ... |
aoqi@0 131 // +--------------------+ ------------------
aoqi@0 132 // | ... | low addresses
aoqi@0 133 // | frame_type |
aoqi@0 134 // | next_frame | high addresses
aoqi@0 135 // +--------------------+ ------------------
aoqi@0 136 // | ... |
aoqi@0 137
aoqi@0 138 class ZeroFrame {
aoqi@0 139 friend class frame;
aoqi@0 140 friend class ZeroStackPrinter;
aoqi@0 141
aoqi@0 142 protected:
aoqi@0 143 ZeroFrame() {
aoqi@0 144 ShouldNotCallThis();
aoqi@0 145 }
aoqi@0 146
aoqi@0 147 enum Layout {
aoqi@0 148 next_frame_off,
aoqi@0 149 frame_type_off,
aoqi@0 150 jf_header_words
aoqi@0 151 };
aoqi@0 152
aoqi@0 153 enum FrameType {
aoqi@0 154 ENTRY_FRAME = 1,
aoqi@0 155 INTERPRETER_FRAME,
aoqi@0 156 SHARK_FRAME,
aoqi@0 157 FAKE_STUB_FRAME
aoqi@0 158 };
aoqi@0 159
aoqi@0 160 protected:
aoqi@0 161 intptr_t *addr_of_word(int offset) const {
aoqi@0 162 return (intptr_t *) this - offset;
aoqi@0 163 }
aoqi@0 164 intptr_t value_of_word(int offset) const {
aoqi@0 165 return *addr_of_word(offset);
aoqi@0 166 }
aoqi@0 167
aoqi@0 168 public:
aoqi@0 169 ZeroFrame *next() const {
aoqi@0 170 return (ZeroFrame *) value_of_word(next_frame_off);
aoqi@0 171 }
aoqi@0 172
aoqi@0 173 protected:
aoqi@0 174 FrameType type() const {
aoqi@0 175 return (FrameType) value_of_word(frame_type_off);
aoqi@0 176 }
aoqi@0 177
aoqi@0 178 public:
aoqi@0 179 bool is_entry_frame() const {
aoqi@0 180 return type() == ENTRY_FRAME;
aoqi@0 181 }
aoqi@0 182 bool is_interpreter_frame() const {
aoqi@0 183 return type() == INTERPRETER_FRAME;
aoqi@0 184 }
aoqi@0 185 bool is_shark_frame() const {
aoqi@0 186 return type() == SHARK_FRAME;
aoqi@0 187 }
aoqi@0 188 bool is_fake_stub_frame() const {
aoqi@0 189 return type() == FAKE_STUB_FRAME;
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 public:
aoqi@0 193 EntryFrame *as_entry_frame() const {
aoqi@0 194 assert(is_entry_frame(), "should be");
aoqi@0 195 return (EntryFrame *) this;
aoqi@0 196 }
aoqi@0 197 InterpreterFrame *as_interpreter_frame() const {
aoqi@0 198 assert(is_interpreter_frame(), "should be");
aoqi@0 199 return (InterpreterFrame *) this;
aoqi@0 200 }
aoqi@0 201 SharkFrame *as_shark_frame() const {
aoqi@0 202 assert(is_shark_frame(), "should be");
aoqi@0 203 return (SharkFrame *) this;
aoqi@0 204 }
aoqi@0 205 FakeStubFrame *as_fake_stub_frame() const {
aoqi@0 206 assert(is_fake_stub_frame(), "should be");
aoqi@0 207 return (FakeStubFrame *) this;
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 public:
aoqi@0 211 void identify_word(int frame_index,
aoqi@0 212 int offset,
aoqi@0 213 char* fieldbuf,
aoqi@0 214 char* valuebuf,
aoqi@0 215 int buflen) const;
aoqi@0 216
aoqi@0 217 protected:
aoqi@0 218 void identify_vp_word(int frame_index,
aoqi@0 219 intptr_t* addr,
aoqi@0 220 intptr_t* monitor_base,
aoqi@0 221 intptr_t* stack_base,
aoqi@0 222 char* fieldbuf,
aoqi@0 223 int buflen) const;
aoqi@0 224 };
aoqi@0 225
aoqi@0 226 #endif // CPU_ZERO_VM_STACK_ZERO_HPP

mercurial