Mercurial > hg > Members > kono > jpf-core
comparison src/tests/gov/nasa/jpf/test/mc/basic/OVHeapTest.java @ 0:61d41facf527
initial v8 import (history reset)
author | Peter Mehlitz <Peter.C.Mehlitz@nasa.gov> |
---|---|
date | Fri, 23 Jan 2015 10:14:01 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:61d41facf527 |
---|---|
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.test.mc.basic; | |
20 | |
21 import org.junit.Test; | |
22 | |
23 import gov.nasa.jpf.util.test.TestJPF; | |
24 import gov.nasa.jpf.vm.Verify; | |
25 | |
26 /** | |
27 * unit test for OVHeap | |
28 */ | |
29 public class OVHeapTest extends TestJPF { | |
30 | |
31 static int getReferenceValue (Object o) { | |
32 int h = System.identityHashCode(o); | |
33 return h ^ 0xABCD; // revert the ABCD hash component | |
34 } | |
35 | |
36 static void checkRef (String msg, String key, int ref) { | |
37 System.out.printf("%s ,object: %s, ref: %d", msg, key, ref); | |
38 | |
39 int v = Verify.getValue(key); | |
40 if (v == Verify.NO_VALUE) { | |
41 Verify.putValue(key, ref); | |
42 System.out.println(" new"); | |
43 } else { | |
44 if (v == ref) { | |
45 System.out.println(" seen"); | |
46 } else { | |
47 fail("different reference values, had:" + v + ", new:" + ref); | |
48 } | |
49 } | |
50 } | |
51 | |
52 static class X { | |
53 String id; | |
54 | |
55 X (String id){ | |
56 this.id = id; | |
57 } | |
58 } | |
59 | |
60 static class Y extends X { | |
61 Y (String id){ | |
62 super(id); | |
63 } | |
64 } | |
65 | |
66 X allocX (String id) { | |
67 return new X(id); | |
68 } | |
69 | |
70 @Test | |
71 public void testSGOIDs() { | |
72 if (verifyNoPropertyViolation("+vm.heap.class=.vm.OVHeap")) { | |
73 Thread t = new Thread() { | |
74 @Override | |
75 public void run() { | |
76 Class<?> cls = X.class; | |
77 checkRef("from T ", "X.class", getReferenceValue(cls)); | |
78 | |
79 X x1 = new X("t-x1"); | |
80 checkRef("from T ", x1.id, getReferenceValue(x1)); | |
81 | |
82 Thread.yield(); // CG #3 | |
83 | |
84 Y y1 = new Y("t-y1"); | |
85 checkRef("from T ", y1.id, getReferenceValue(y1)); | |
86 } | |
87 }; | |
88 | |
89 t.start(); // CG #1 | |
90 | |
91 Class<?> clsY = Y.class; | |
92 checkRef("from M ", "Y.class", getReferenceValue(clsY)); | |
93 | |
94 Class<?> clsX = X.class; | |
95 checkRef("from M ", "X.class", getReferenceValue(clsX)); | |
96 | |
97 int n = Verify.getInt(1, 3); // CG #2 | |
98 System.out.println("-- M next X[] arraysize = " + n); | |
99 X[] xs = new X[n]; | |
100 for (int i=0; i<xs.length; i++) { | |
101 xs[i] = new X("xs-" + i); | |
102 checkRef("from M ", xs[i].id, getReferenceValue(xs[i])); | |
103 } | |
104 | |
105 Y y1 = new Y("m-y1"); | |
106 checkRef("from M ", y1.id, getReferenceValue(y1)); | |
107 | |
108 X x1 = new Y("m-x1"); | |
109 checkRef("from M ", x1.id, getReferenceValue(x1)); | |
110 } | |
111 } | |
112 } |