01: //
02: // Copyright (C) 2005 United States Government as represented by the
03: // Administrator of the National Aeronautics and Space Administration
04: // (NASA). All Rights Reserved.
05: //
06: // This software is distributed under the NASA Open Source Agreement
07: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
08: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
09: // directory tree for the complete NOSA document.
10: //
11: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18: //
19: package gov.nasa.jpf.jvm;
20:
21: import java.util.Hashtable;
22:
23: /**
24: * DynamicMap is a mapping table used to achieve heap symmetry,
25: * associating thread/pc specific DynamicMapIndex objects with their
26: * corresponding DynamicArea elements[] index.
27: *
28: * If we keep it, this should really use a IntHashmap instead of a Hashtable
29: */
30: class DynamicMap {
31: static Hashtable mapping = new Hashtable();
32: static int counter = 0;
33:
34: public static int getEntry(DynamicMapIndex dmi) {
35: return ((Integer) mapping.get(dmi)).intValue();
36: }
37:
38: public static synchronized int addEntry(DynamicMapIndex dmi) {
39: int idx;
40: Integer index = (Integer) mapping.get(dmi);
41:
42: if (index != null) {
43: return index.intValue();
44: }
45:
46: idx = counter;
47: mapping.put(dmi.clone(), new Integer(idx)); // <?> pcm - dmi.clone() ?
48: counter++;
49:
50: return idx;
51: }
52:
53: public static boolean hasEntry(DynamicMapIndex dmi) {
54: return mapping.containsKey(dmi);
55: }
56:
57: public static synchronized void init() {
58: mapping = new Hashtable();
59: counter = 0;
60: }
61: }
|