2 JPC-RR: A x86 PC Hardware Emulator
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009 H. Ilari Liusvaara
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as published by
10 the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Based on JPC x86 PC Hardware emulator,
22 A project from the Physics Dept, The University of Oxford
24 Details about original JPC can be found at:
26 www-jpc.physics.ox.ac.uk
30 package org
.jpc
.emulator
;
34 public class StatusDumper
37 java
.util
.HashMap
<String
, Integer
> nextObjectNumber
;
38 PrintStream underlyingPrintStream
;
39 static final Boolean TRUE
;
40 static final Boolean FALSE
;
41 java
.util
.HashMap
<String
, Boolean
> seenObjects
;
42 java
.util
.HashMap
<Integer
, ObjectListEntry
> chainingLists
;
45 static class ObjectListEntry
49 public ObjectListEntry next
;
54 TRUE
= new Boolean(true);
55 FALSE
= new Boolean(false);
58 public StatusDumper(PrintStream ps
)
61 nextObjectNumber
= new java
.util
.HashMap
<String
, Integer
>();
62 underlyingPrintStream
= ps
;
63 seenObjects
= new java
.util
.HashMap
<String
, Boolean
>();
64 chainingLists
= new java
.util
.HashMap
<Integer
, ObjectListEntry
>();
68 public int dumpedObjects()
73 public void println(String S
)
76 for(int i
= 0; i
< extraIndent
; i
++)
79 underlyingPrintStream
.println(X
);
82 public void printArray(boolean[] A
, String N
)
85 println("\t" + N
+ " null");
88 println("\t" + N
+ ":");
90 for(int i
= 0; i
< A
.length
; i
++) {
101 public void printArray(byte[] A
, String N
)
104 println("\t" + N
+ " null");
107 println("\t" + N
+ ":");
109 for(int i
= 0; i
< A
.length
; i
++) {
120 public void printArray(int[] A
, String N
)
123 println("\t" + N
+ " null");
126 println("\t" + N
+ ":");
128 for(int i
= 0; i
< A
.length
; i
++) {
139 public void printArray(long[] A
, String N
)
142 println("\t" + N
+ " null");
145 println("\t" + N
+ ":");
147 for(int i
= 0; i
< A
.length
; i
++) {
158 private void addObject(Object O
, String n
)
160 Integer hcode
= new Integer(O
.hashCode());
161 ObjectListEntry e
= new ObjectListEntry();
165 if(!chainingLists
.containsKey(hcode
)) {
166 chainingLists
.put(hcode
, e
);
168 e
.next
= chainingLists
.get(hcode
);
169 chainingLists
.put(hcode
, e
);
173 private String
lookupObject(Object O
)
175 Integer hcode
= new Integer(O
.hashCode());
176 if(!chainingLists
.containsKey(hcode
))
178 ObjectListEntry e
= chainingLists
.get(hcode
);
187 public String
objectNumber(Object O
)
190 boolean isNew
= false;
195 assignedNum
= lookupObject(O
);
196 if(assignedNum
== null)
200 String cName
= O
.getClass().getName();
201 if(!nextObjectNumber
.containsKey(cName
)) {
202 nextObjectNumber
.put(cName
, new Integer(1));
203 assignedNum
= cName
+ "-1";
205 int seqno
= nextObjectNumber
.get(cName
).intValue();
206 nextObjectNumber
.put(cName
, new Integer(seqno
+ 1));
207 assignedNum
= cName
+ "-" + (seqno
+ 1);
209 addObject(O
, assignedNum
);
210 seenObjects
.put(assignedNum
, FALSE
);
215 public boolean dumped(Object O
)
217 boolean seenBefore
= false;
218 String obj
= objectNumber(O
);
220 seenBefore
= seenObjects
.get(obj
).booleanValue();
223 seenObjects
.put(obj
, TRUE
);
230 public void endObject()
232 println("--- END OF OBJECT ---");