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.
18 package gov.nasa.jpf.vm;
20 import gov.nasa.jpf.Config;
21 import gov.nasa.jpf.util.IntTable;
24 * abstract Heap trait that implements SGOIDs by means of a search global
25 * Allocation map and a state managed allocCount map
27 * NOTE - a reference value of 0 represents null and therefore is not a valid SGOID
29 public abstract class GenericSGOIDHeap extends GenericHeap {
31 static class GenericSGOIDHeapMemento extends GenericHeapMemento {
32 IntTable.Snapshot<AllocationContext> ctxSnap;
34 GenericSGOIDHeapMemento (GenericSGOIDHeap heap) {
37 ctxSnap = heap.allocCounts.getSnapshot();
41 public Heap restore(Heap inSitu) {
42 super.restore( inSitu);
44 GenericSGOIDHeap heap = (GenericSGOIDHeap) inSitu;
45 heap.allocCounts.restore(ctxSnap);
51 // these are search global
52 protected int nextSgoid;
53 protected IntTable<Allocation> sgoids;
55 // this is state managed
56 // NOTE - this has to be included in the mementos of concrete Heap implementations
57 protected IntTable<AllocationContext> allocCounts;
59 protected GenericSGOIDHeap (Config config, KernelState ks){
63 initAllocationContext(config);
64 sgoids = new IntTable<Allocation>();
67 allocCounts = new IntTable<AllocationContext>();
71 //--- to be overridden by subclasses that use different AllocationContext implementations
73 protected void initAllocationContext(Config config) {
74 HashedAllocationContext.init(config);
75 //PreciseAllocationContext.init(config);
78 // these are always called directly from the allocation primitive, i.e. the allocating site is at a fixed
79 // stack offset (callers caller)
81 protected AllocationContext getSUTAllocationContext (ClassInfo ci, ThreadInfo ti) {
82 return HashedAllocationContext.getSUTAllocationContext(ci, ti);
83 //return PreciseAllocationContext.getSUTAllocationContext(ci, ti);
86 protected AllocationContext getSystemAllocationContext (ClassInfo ci, ThreadInfo ti, int anchor) {
87 return HashedAllocationContext.getSystemAllocationContext(ci, ti, anchor);
88 //return PreciseAllocationContext.getSystemAllocationContext(ci, ti, anchor);
93 protected int getNewElementInfoIndex (AllocationContext ctx) {
97 IntTable.Entry<AllocationContext> cntEntry = allocCounts.getInc(ctx);
100 Allocation alloc = new Allocation(ctx, cnt);
102 IntTable.Entry<Allocation> sgoidEntry = sgoids.get(alloc);
103 if (sgoidEntry != null) { // we already had this one
104 idx = sgoidEntry.val;
106 } else { // new entry
108 sgoids.put(alloc, idx);
111 // sanity check - we do this here (and not in our super class) since we know how elements are stored
112 // assert get(idx) == null;