2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
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
10 * http://www.apache.org/licenses/LICENSE-2.0.
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.
19 package gov.nasa.jpf.vm;
21 import gov.nasa.jpf.util.HashPool;
22 import gov.nasa.jpf.util.IntTable.Entry;
23 import gov.nasa.jpf.util.WeakPool;
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);
30 /** Pool used to store collections of field values.*/
31 private WeakPool<Fields> fieldsPool = new WeakPool<Fields> (11);
33 /** Pool used to store the thread data.*/
34 private WeakPool<ThreadData> threadDataPool = new WeakPool<ThreadData>(8);
36 /** Pool used to store monitor states.*/
37 private WeakPool<Monitor> monitorPool = new WeakPool<Monitor> (8);
39 public StackFrame poolStackFrame(StackFrame o) {
40 StackFrame p = stackFramePool.pool(o);
41 if (VM.CHECK_CONSISTENCY) assert p.equals(o);
45 public Fields poolFields(Fields o) {
46 Fields p = fieldsPool.pool(o);
47 if (VM.CHECK_CONSISTENCY) assert p.equals(o);
51 public ThreadData poolThreadData(ThreadData o) {
52 ThreadData p = threadDataPool.pool(o);
53 if (VM.CHECK_CONSISTENCY) assert p.equals(o);
57 public Monitor poolMonitor(Monitor o) {
58 Monitor p = monitorPool.pool(o);
59 if (VM.CHECK_CONSISTENCY) assert p.equals(o);
64 static class AllIndexed {
65 /** Pool used to store the thread data.*/
66 private HashPool<ThreadData> threadDataPool = new HashPool<ThreadData>(8).addNull();
68 /** Pool used to store monitor states.*/
69 private HashPool<Monitor> monitorPool = new HashPool<Monitor> (8).addNull();
71 /** Pool used to store the stack frames.*/
72 private HashPool<StackFrame> stackFramePool = new HashPool<StackFrame>(11).addNull();
74 /** Pool used to store collections of field values.*/
75 private HashPool<Fields> fieldsPool = new HashPool<Fields> (11).addNull();
77 public StackFrame poolStackFrame(StackFrame o) {
78 StackFrame p = stackFramePool.get(o);
79 if (VM.CHECK_CONSISTENCY) assert p.equals(o);
83 public Fields poolFields(Fields o) {
84 return fieldsPool.get(o);
87 public ThreadData poolThreadData(ThreadData o) {
88 return threadDataPool.get(o);
91 public Monitor poolMonitor(Monitor o) {
92 return monitorPool.get(o);
95 public int getFieldsIndex(ElementInfo ei) {
96 Entry<Fields> entry = fieldsPool.getEntry(ei.getFields());
97 ei.restoreFields(entry.key);
101 public int getStackFrameIndex(StackFrame sf) {
102 return stackFramePool.getIndex(sf);
105 public int getThreadDataIndex(ThreadInfo ti) {
106 Entry<ThreadData> e = threadDataPool.getEntry(ti.threadData);
107 ti.threadData = e.key;
111 public int getMonitorIndex(ElementInfo ei) {
112 Entry<Monitor> entry = monitorPool.getEntry(ei.getMonitor());
113 ei.restoreMonitor(entry.key);
117 public Fields getFieldsAt(int idx) {
118 return fieldsPool.getObject(idx);
121 public StackFrame getStackFrameAt(int idx) {
122 return stackFramePool.getObject(idx);
125 public ThreadData getThreadDataAt(int idx) {
126 return threadDataPool.getObject(idx);
129 public Monitor getMonitorAt(int idx) {
130 return monitorPool.getObject(idx);