src/cpu/zero/vm/stack_zero.hpp

Fri, 12 Feb 2010 10:34:11 -0800

author
kvn
date
Fri, 12 Feb 2010 10:34:11 -0800
changeset 1691
c09ee209b65c
parent 1445
354d3184f6b2
child 1814
f9271ff9d324
permissions
-rw-r--r--

6926048: Improve Zero performance
Summary: Make Zero figure out result types in a similar way to C++ interpreter implementation.
Reviewed-by: kvn
Contributed-by: gbenson@redhat.com

     1 /*
     2  * Copyright 2003-2007 Sun Microsystems, Inc.  All Rights Reserved.
     3  * Copyright 2008, 2009 Red Hat, Inc.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     9  *
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    13  * version 2 for more details (a copy is included in the LICENSE file that
    14  * accompanied this code).
    15  *
    16  * You should have received a copy of the GNU General Public License version
    17  * 2 along with this work; if not, write to the Free Software Foundation,
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    19  *
    20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    21  * CA 95054 USA or visit www.sun.com if you need additional information or
    22  * have any questions.
    23  *
    24  */
    26 class ZeroStack {
    27  private:
    28   intptr_t *_base; // the last available word
    29   intptr_t *_top;  // the word past the end of the stack
    30   intptr_t *_sp;   // the top word on the stack
    32  public:
    33   ZeroStack()
    34     : _base(NULL), _top(NULL), _sp(NULL) {}
    36   bool needs_setup() const {
    37     return _base == NULL;
    38   }
    40   void setup(void *mem, size_t size) {
    41     assert(needs_setup(), "already set up");
    42     assert(!(size & WordAlignmentMask), "unaligned");
    44     _base = (intptr_t *) mem;
    45     _top  = _base + (size >> LogBytesPerWord);
    46     _sp   = _top;
    47   }
    48   void teardown() {
    49     assert(!needs_setup(), "not set up");
    50     assert(_sp == _top, "stuff on stack at teardown");
    52     _base = NULL;
    53     _top  = NULL;
    54     _sp   = NULL;
    55   }
    57   intptr_t *sp() const {
    58     return _sp;
    59   }
    60   void set_sp(intptr_t *new_sp) {
    61     assert(_top >= new_sp && new_sp >= _base, "bad stack pointer");
    62     _sp = new_sp;
    63   }
    65   int available_words() const {
    66     return _sp - _base;
    67   }
    69   void push(intptr_t value) {
    70     assert(_sp > _base, "stack overflow");
    71     *(--_sp) = value;
    72   }
    73   intptr_t pop() {
    74     assert(_sp < _top, "stack underflow");
    75     return *(_sp++);
    76   }
    78   void *alloc(size_t size) {
    79     int count = align_size_up(size, wordSize) >> LogBytesPerWord;
    80     assert(count <= available_words(), "stack overflow");
    81     return _sp -= count;
    82   }
    84  public:
    85   static ByteSize base_offset() {
    86     return byte_offset_of(ZeroStack, _base);
    87   }
    88   static ByteSize top_offset() {
    89     return byte_offset_of(ZeroStack, _top);
    90   }
    91   static ByteSize sp_offset() {
    92     return byte_offset_of(ZeroStack, _sp);
    93   }
    94 };
    97 class EntryFrame;
    98 class InterpreterFrame;
    99 class SharkFrame;
   100 class FakeStubFrame;
   102 //
   103 // |  ...               |
   104 // +--------------------+  ------------------
   105 // |  ...               |       low addresses
   106 // | frame_type         |
   107 // | next_frame         |      high addresses
   108 // +--------------------+  ------------------
   109 // |  ...               |
   111 class ZeroFrame {
   112   friend class frame;
   113   friend class ZeroStackPrinter;
   115  protected:
   116   ZeroFrame() {
   117     ShouldNotCallThis();
   118   }
   120   enum Layout {
   121     next_frame_off,
   122     frame_type_off,
   123     jf_header_words
   124   };
   126   enum FrameType {
   127     ENTRY_FRAME = 1,
   128     INTERPRETER_FRAME,
   129     SHARK_FRAME,
   130     FAKE_STUB_FRAME
   131   };
   133  protected:
   134   intptr_t *addr_of_word(int offset) const {
   135     return (intptr_t *) this - offset;
   136   }
   137   intptr_t value_of_word(int offset) const {
   138     return *addr_of_word(offset);
   139   }
   141  public:
   142   ZeroFrame *next() const {
   143     return (ZeroFrame *) value_of_word(next_frame_off);
   144   }
   146  protected:
   147   FrameType type() const {
   148     return (FrameType) value_of_word(frame_type_off);
   149   }
   151  public:
   152   bool is_entry_frame() const {
   153     return type() == ENTRY_FRAME;
   154   }
   155   bool is_interpreter_frame() const {
   156     return type() == INTERPRETER_FRAME;
   157   }
   158   bool is_shark_frame() const {
   159     return type() == SHARK_FRAME;
   160   }
   161   bool is_fake_stub_frame() const {
   162     return type() == FAKE_STUB_FRAME;
   163   }
   165  public:
   166   EntryFrame *as_entry_frame() const {
   167     assert(is_entry_frame(), "should be");
   168     return (EntryFrame *) this;
   169   }
   170   InterpreterFrame *as_interpreter_frame() const {
   171     assert(is_interpreter_frame(), "should be");
   172     return (InterpreterFrame *) this;
   173   }
   174   SharkFrame *as_shark_frame() const {
   175     assert(is_shark_frame(), "should be");
   176     return (SharkFrame *) this;
   177   }
   178   FakeStubFrame *as_fake_stub_frame() const {
   179     assert(is_fake_stub_frame(), "should be");
   180     return (FakeStubFrame *) this;
   181   }
   183  public:
   184   void identify_word(int   frame_index,
   185                      int   offset,
   186                      char* fieldbuf,
   187                      char* valuebuf,
   188                      int   buflen) const;
   190  protected:
   191   void identify_vp_word(int       frame_index,
   192                         intptr_t* addr,
   193                         intptr_t* monitor_base,
   194                         intptr_t* stack_base,
   195                         char*     fieldbuf,
   196                         int       buflen) const;
   197 };

mercurial