Adding the old tracker variable for debugging/testing purposes.
[jpf-core.git] / src / main / gov / nasa / jpf / vm / CollapsePools.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18
19 package gov.nasa.jpf.vm;
20
21 import gov.nasa.jpf.util.HashPool;
22 import gov.nasa.jpf.util.IntTable.Entry;
23 import gov.nasa.jpf.util.WeakPool;
24
25 abstract class CollapsePools {
26   static class AllWeak {
27     /** Pool used to store the stack frames.*/
28     private WeakPool<StackFrame> stackFramePool = new WeakPool<StackFrame>(11);
29
30     /** Pool used to store collections of field values.*/
31     private WeakPool<Fields>     fieldsPool     = new WeakPool<Fields>    (11);
32
33     /** Pool used to store the thread data.*/
34     private WeakPool<ThreadData> threadDataPool = new WeakPool<ThreadData>(8);
35     
36     /** Pool used to store monitor states.*/
37     private WeakPool<Monitor>    monitorPool    = new WeakPool<Monitor>   (8);
38
39     public StackFrame poolStackFrame(StackFrame o) {
40       StackFrame p = stackFramePool.pool(o);
41       if (VM.CHECK_CONSISTENCY) assert p.equals(o);
42       return p;
43     }
44
45     public Fields poolFields(Fields o) {
46       Fields p = fieldsPool.pool(o);
47       if (VM.CHECK_CONSISTENCY) assert p.equals(o);
48       return p;
49     }
50
51     public ThreadData poolThreadData(ThreadData o) {
52       ThreadData p = threadDataPool.pool(o);
53       if (VM.CHECK_CONSISTENCY) assert p.equals(o);
54       return p;
55     }
56
57     public Monitor poolMonitor(Monitor o) {
58       Monitor p = monitorPool.pool(o);
59       if (VM.CHECK_CONSISTENCY) assert p.equals(o);
60       return p;
61     }
62   }
63   
64   static class AllIndexed {
65     /** Pool used to store the thread data.*/
66     private HashPool<ThreadData> threadDataPool = new HashPool<ThreadData>(8).addNull();
67
68     /** Pool used to store monitor states.*/
69     private HashPool<Monitor>    monitorPool    = new HashPool<Monitor>   (8).addNull();
70
71     /** Pool used to store the stack frames.*/
72     private HashPool<StackFrame> stackFramePool = new HashPool<StackFrame>(11).addNull();
73
74     /** Pool used to store collections of field values.*/
75     private HashPool<Fields>     fieldsPool     = new HashPool<Fields>    (11).addNull();
76     
77     public StackFrame poolStackFrame(StackFrame o) {
78       StackFrame p = stackFramePool.get(o);
79       if (VM.CHECK_CONSISTENCY) assert p.equals(o);
80       return p;
81     }
82
83     public Fields poolFields(Fields o) {
84       return fieldsPool.get(o);
85     }
86
87     public ThreadData poolThreadData(ThreadData o) {
88       return threadDataPool.get(o);
89     }
90
91     public Monitor poolMonitor(Monitor o) {
92       return monitorPool.get(o);
93     }
94
95     public int getFieldsIndex(ElementInfo ei) {
96       Entry<Fields> entry = fieldsPool.getEntry(ei.getFields());
97       ei.restoreFields(entry.key);
98       return entry.val;
99     }
100
101     public int getStackFrameIndex(StackFrame sf) {
102       return stackFramePool.getIndex(sf);
103     }
104
105     public int getThreadDataIndex(ThreadInfo ti) {
106       Entry<ThreadData> e = threadDataPool.getEntry(ti.threadData);
107       ti.threadData = e.key;
108       return e.val;
109     }
110     
111     public int getMonitorIndex(ElementInfo ei) {
112       Entry<Monitor> entry = monitorPool.getEntry(ei.getMonitor());
113       ei.restoreMonitor(entry.key);
114       return entry.val;
115     }
116     
117     public Fields getFieldsAt(int idx) {
118       return fieldsPool.getObject(idx);
119     }
120
121     public StackFrame getStackFrameAt(int idx) {
122       return stackFramePool.getObject(idx);
123     }
124
125     public ThreadData getThreadDataAt(int idx) {
126       return threadDataPool.getObject(idx);
127     }
128
129     public Monitor getMonitorAt(int idx) {
130       return monitorPool.getObject(idx);
131     }
132   }
133 }