RexxListTable.cpp
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 RexxListTable.cpp */
40 /* */
41 /* Primitive List Table Class */
42 /* */
43 /******************************************************************************/
44 #include "RexxCore.h"
45 #include "ListClass.hpp"
46 
47 void RexxListTable::live(size_t liveMark)
48 /******************************************************************************/
49 /* Function: Normal garbage collection live marking */
50 /******************************************************************************/
51 {
52  for (size_t index = 0; index < this->size; index++)
53  {
54  /* mark an element */
55  memory_mark(this->elements[index].value);
56  }
57 }
58 
60 /******************************************************************************/
61 /* Function: Generalized object marking */
62 /******************************************************************************/
63 {
64  /* loop through our table */
65  for (size_t index = 0; index < this->size; index++)
66  {
67  /* mark an element */
68  memory_mark_general(this->elements[index].value);
69  }
70 }
71 
73 /******************************************************************************/
74 /* Function: Flatten an object */
75 /******************************************************************************/
76 {
78 
79  for (size_t i = this->size; i > 0 ; i--)
80  {
81  flatten_reference(newThis->elements[i - 1].value, envelope);
82  }
83 
85 }
86 
87 
88 void *RexxListTable::operator new(size_t size, size_t initialSize)
89 /******************************************************************************/
90 /* Function: Construct and initialized a new list item */
91 /******************************************************************************/
92 {
93  /* Get new object */
94  RexxListTable *newTable = (RexxListTable *)new_object(size + sizeof(LISTENTRY) * (initialSize - 1), T_ListTable);
95  newTable->size = initialSize;
96  return newTable; /* return the new list item */
97 }
98 
99 
100 void *RexxListTable::operator new(size_t size, size_t initialSize, size_t companionSize)
101 /******************************************************************************/
102 /* Function: Construct and initialized a new list item */
103 /******************************************************************************/
104 {
105  /* Compute size of hash tab object */
106  size_t bytes = roundObjectBoundary(size + (sizeof(LISTENTRY) * (initialSize - 1)));
107  /* make sure we've got proper sizes for each of the object parts. */
108  companionSize = roundObjectBoundary(companionSize);
109  /* Get space for two objects */
110  /* Get new object */
111  RexxList *newList = (RexxList *)new_object(bytes + companionSize);
112  /* address the list table */
113  RexxListTable *newTable = (RexxListTable *)(((char *)newList) + companionSize);
114  /* compute total size of the list */
115  /* table (allowing for possible */
116  /* over allocation by the memory */
117  /* manager */
118  bytes = newList->getObjectSize() - companionSize;
119 
120  // initialize the hash table object
122  /* reduce the companion size */
123  newList->setObjectSize(companionSize);
124  newTable->size = initialSize; /* fill in the initial size */
125  /* hook the list into the companion */
126  /* OrefSet is not used, because the */
127  /* companion object is not fully set */
128  newList->table = newTable; /* up yet (no behaviour) */
129  return newList; /* return the new list item */
130 }
131 
@ T_ListTable
#define TheListTableBehaviour
RexxMemory memoryObject
Definition: RexxMemory.cpp:86
#define memory_mark(oref)
Definition: RexxMemory.hpp:450
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:436
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:498
size_t roundObjectBoundary(size_t n)
Definition: RexxMemory.hpp:95
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:451
#define cleanUpFlatten
Definition: RexxMemory.hpp:484
#define setUpFlatten(type)
Definition: RexxMemory.hpp:478
void setObjectSize(size_t s)
RexxListTable * table
Definition: ListClass.hpp:138
void liveGeneral(int reason)
LISTENTRY elements[1]
void flatten(RexxEnvelope *)
void live(size_t)
static void * virtualFunctionTable[]
Definition: RexxMemory.hpp:301
size_t markWord
Definition: RexxMemory.hpp:304