ooRexx  4.2.0-source
About: ooRexx (Open Object Rexx) is a free implementation of Object Rexx. Object Rexx is an enhancement of the classic Rexx interpreter; a full-featured programming language with a human-oriented syntax.
  Fossies Dox: ooRexx-4.2.0-source.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

RexxActivationStack.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Kernel RexxActivationStack.hpp */
40 /* */
41 /* Primitive Activation Stack Frame Definitions */
42 /* */
43 /******************************************************************************/
44 
45 #ifndef Included_RexxActivationStack
46 #define Included_RexxActivationStack
47 
48 
50  public:
51  inline void *operator new(size_t size, void *ptr) { return ptr;};
52  inline void operator delete(void *) { ; }
53  inline void operator delete(void *, void *) { ; }
54 
56  inline RexxActivationFrameBuffer(RESTORETYPE restoreType) { ; }
57  void live(size_t);
58  void liveGeneral(int reason);
59  void flatten(RexxEnvelope *);
60 
61  inline bool hasCapacity(size_t entries) { return size - next >= entries; }
62  inline RexxObject **allocateFrame(size_t entries)
63  {
64  RexxObject **frame = &buffer[next];
65  next += entries;
66  return frame;
67  }
68 
69  inline bool contains(RexxObject **frame)
70  {
71  return frame >= &buffer[0] && frame <= &buffer[size];
72  }
73 
74  inline void releaseFrame(RexxObject **frame)
75  {
76  next = frame - &buffer[0];
77  }
78 
80  {
81  previous = p; // chain this up
82  }
83 
84 
85  inline void reset() { next = 0; } // reset a cached frame buffer
86 
88 
89  static RexxActivationFrameBuffer *newInstance(size_t);
90 
91 protected:
92 
93 
94  size_t size; /* size of the buffer (in slots) */
95  size_t next; /* location of next allocation */
96  RexxActivationFrameBuffer *previous;/* previous entry in the stack */
97  RexxObject *buffer[1]; /* start of the buffer location */
98 };
99 
100 
102  public:
103 
104  enum { DefaultFrameBufferSize = 2048 };
105 
106  inline void *operator new(size_t size, void *ptr) { return ptr;};
108  void live(size_t);
109  void liveGeneral(int reason);
110 
111  void init();
112  void expandCapacity(size_t entries);
113 
114  inline void ensureCapacity(size_t entries) { if (!current->hasCapacity(entries)) { expandCapacity(entries); } }
115  inline RexxObject **allocateFrame(size_t entries)
116  {
117  /* make sure we have space first */
118  ensureCapacity(entries);
119  /* now allocate from the current stack buffer */
120  return current->allocateFrame(entries);
121  }
122  void releaseFrame(RexxObject **frame)
123  {
124  /* we may be popping back one or more buffers. We deactivate */
125  /* the newer ones */
126  while (!current->contains(frame)) {
127  /* we need to pop at least one buffer off of the stack */
129  current = released->getPrevious();
130  /* we'll keep at least one buffer around for reuse. If */
131  /* we've already got one in the cache, just let this one */
132  /* get GCed. */
133  if (unused == OREF_NULL) {
134  unused = released;
135  unused->reset(); // reset to clean state
136  }
137  }
138 
139  /* now back this up to the release point */
140  current->releaseFrame(frame);
141  }
142 
143 protected:
144 
147 };
148 
149 
151 
152 #endif
RexxActivationFrameBuffer
Definition: RexxActivationStack.hpp:49
RexxActivationStack::RexxActivationStack
RexxActivationStack()
Definition: RexxActivationStack.hpp:107
RexxActivationStack::allocateFrame
RexxObject ** allocateFrame(size_t entries)
Definition: RexxActivationStack.hpp:115
RexxInternalObject
Definition: ObjectClass.hpp:206
RexxActivationStack::current
RexxActivationFrameBuffer * current
Definition: RexxActivationStack.hpp:145
RexxActivationFrameBuffer::flatten
void flatten(RexxEnvelope *)
Definition: RexxActivationStack.cpp:74
RexxActivationStack::liveGeneral
void liveGeneral(int reason)
Definition: RexxActivationStack.cpp:98
RexxActivationStack::init
void init()
Definition: RexxActivationStack.cpp:107
RexxActivationStack::ensureCapacity
void ensureCapacity(size_t entries)
Definition: RexxActivationStack.hpp:114
RexxActivationStack
Definition: RexxActivationStack.hpp:101
RexxActivationFrameBuffer::RexxActivationFrameBuffer
RexxActivationFrameBuffer(RESTORETYPE restoreType)
Definition: RexxActivationStack.hpp:56
RexxActivationFrameBuffer::size
size_t size
Definition: RexxActivationStack.hpp:94
RexxActivationFrameBuffer::RexxActivationFrameBuffer
RexxActivationFrameBuffer()
Definition: RexxActivationStack.hpp:55
RexxEnvelope
Definition: RexxEnvelope.hpp:53
new_activationFrameBuffer
RexxActivationFrameBuffer * new_activationFrameBuffer(size_t s)
Definition: RexxActivationStack.hpp:150
RexxActivationStack::unused
RexxActivationFrameBuffer * unused
Definition: RexxActivationStack.hpp:146
RexxActivationFrameBuffer::reset
void reset()
Definition: RexxActivationStack.hpp:85
RexxActivationFrameBuffer::allocateFrame
RexxObject ** allocateFrame(size_t entries)
Definition: RexxActivationStack.hpp:62
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
RexxActivationFrameBuffer::push
void push(RexxActivationFrameBuffer *p)
Definition: RexxActivationStack.hpp:79
RexxActivationStack::DefaultFrameBufferSize
Definition: RexxActivationStack.hpp:104
RexxActivationFrameBuffer::newInstance
static RexxActivationFrameBuffer * newInstance(size_t)
Definition: RexxActivationStack.cpp:145
RexxActivationFrameBuffer::liveGeneral
void liveGeneral(int reason)
Definition: RexxActivationStack.cpp:66
RexxActivationFrameBuffer::previous
RexxActivationFrameBuffer * previous
Definition: RexxActivationStack.hpp:96
RexxActivationStack::releaseFrame
void releaseFrame(RexxObject **frame)
Definition: RexxActivationStack.hpp:122
RexxActivationFrameBuffer::buffer
RexxObject * buffer[1]
Definition: RexxActivationStack.hpp:97
RexxActivationFrameBuffer::live
void live(size_t)
Definition: RexxActivationStack.cpp:56
RexxActivationFrameBuffer::contains
bool contains(RexxObject **frame)
Definition: RexxActivationStack.hpp:69
RexxActivationStack::expandCapacity
void expandCapacity(size_t entries)
Definition: RexxActivationStack.cpp:117
RexxActivationStack::live
void live(size_t)
Definition: RexxActivationStack.cpp:89
RexxActivationFrameBuffer::next
size_t next
Definition: RexxActivationStack.hpp:95
RexxActivationFrameBuffer::getPrevious
RexxActivationFrameBuffer * getPrevious()
Definition: RexxActivationStack.hpp:87
RESTORETYPE
RESTORETYPE
Definition: ObjectClass.hpp:80
RexxActivationFrameBuffer::releaseFrame
void releaseFrame(RexxObject **frame)
Definition: RexxActivationStack.hpp:74
RexxActivationFrameBuffer::hasCapacity
bool hasCapacity(size_t entries)
Definition: RexxActivationStack.hpp:61
RexxObject
Definition: ObjectClass.hpp:311