jitcraft/Stack.h
changeset 12 75e385f68b7e
parent 10 0c3bcd50e361
child 14 0784ac5cc347
     1.1 --- a/jitcraft/Stack.h	Fri Jun 29 19:35:17 2012 -0700
     1.2 +++ b/jitcraft/Stack.h	Sat Jun 30 19:38:53 2012 -0700
     1.3 @@ -21,16 +21,19 @@
     1.4  #include <stddef.h>
     1.5  #include "Utility.h"
     1.6  #include "Code.h"
     1.7 -#include "UnsafeArray.h"
     1.8  
     1.9  namespace jc {
    1.10 +
    1.11 +class Object;
    1.12 +class Array;
    1.13      
    1.14  union LocalSlot
    1.15  {
    1.16      int i32;
    1.17      float f;
    1.18 -    void *p;
    1.19 -    UnsafeArray *unsafeArray;
    1.20 +    Address address;
    1.21 +    Object *obj;
    1.22 +    Array *array;
    1.23  };
    1.24  
    1.25  struct Top
    1.26 @@ -56,14 +59,14 @@
    1.27      Frame *prev_;
    1.28      bytecode *prevpc_;
    1.29      Code *code_;
    1.30 -    void *prevUnsafeStack_;
    1.31 +    Address lifoPosition_;
    1.32  
    1.33    public:
    1.34 -    Frame(Frame *prev, bytecode *prevpc, Code *code, void *prevUnsafeStack)
    1.35 +    Frame(Frame *prev, bytecode *prevpc, Code *code, Address lifoPosition)
    1.36        : prev_(prev),
    1.37          prevpc_(prevpc),
    1.38          code_(code),
    1.39 -        prevUnsafeStack_(prevUnsafeStack)
    1.40 +        lifoPosition_(lifoPosition)
    1.41      {
    1.42      }
    1.43  
    1.44 @@ -82,8 +85,8 @@
    1.45      bytecode *prevpc() const {
    1.46          return prevpc_;
    1.47      }
    1.48 -    void *prevUnsafeStack() const {
    1.49 -        return prevUnsafeStack_;
    1.50 +    Address lifoPosition() const {
    1.51 +        return lifoPosition_;
    1.52      }
    1.53      LocalSlot &arg(unsigned slot) {
    1.54          assert(slot < code()->nargs());
    1.55 @@ -121,51 +124,6 @@
    1.56      }
    1.57  };
    1.58  
    1.59 -// The unsafe stack is designed for structures which interop unsafely with C++.
    1.60 -// In this stack, buffers can be overrun, even inside the VM - but with two
    1.61 -// caveats:
    1.62 -//
    1.63 -//  The unsafe stack cannot hold safe references.
    1.64 -//  Indirect reads and writes from the unsafe stack cannot escape the unsafe
    1.65 -//  stack.
    1.66 -class UnsafeStack
    1.67 -{
    1.68 -    char *buffer_;
    1.69 -    char *pos_;
    1.70 -    char *end_;
    1.71 -
    1.72 -  private:
    1.73 -    static const size_t STACK_SIZE = 1024 * 1024;
    1.74 -
    1.75 -  public:
    1.76 -    UnsafeStack();
    1.77 -    ~UnsafeStack();
    1.78 -    bool initialize();
    1.79 -
    1.80 -  public:
    1.81 -    void *position() const {
    1.82 -        return pos_;
    1.83 -    }
    1.84 -    void *allocate(size_t nbytes) {
    1.85 -        nbytes = Align(nbytes, kMallocAlignment);
    1.86 -
    1.87 -        if (pos_ + nbytes > end_) {
    1.88 -            assert(false);
    1.89 -            return NULL;
    1.90 -        }
    1.91 -
    1.92 -        void *ptr = pos_;
    1.93 -        pos_ += nbytes;
    1.94 -        return ptr;
    1.95 -    }
    1.96 -
    1.97 -    void unwind(void *to) {
    1.98 -        char *p = (char *)to;
    1.99 -        assert(p < pos_ && p >= buffer_);
   1.100 -        pos_ = p;
   1.101 -    }
   1.102 -};
   1.103 -
   1.104  }
   1.105  
   1.106  #endif // _include_jc_stack_h_