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 java.io.IOException;
21 import java.io.OutputStream;
22 import java.io.PrintStream;
24 import gov.nasa.jpf.util.FinalBitSet;
25 import gov.nasa.jpf.util.PrintUtils;
28 * stream to write program state info in a readable and diff-able format.
29 * This is mostly intended for debugging, but could also at some point be
30 * used to restore such states.
32 * Currently supports heap objects, classes (static fields), threads and stack frames
34 public class JPFOutputStream extends OutputStream {
38 boolean useSid = false;
41 public JPFOutputStream (OutputStream os){
42 ps = new PrintStream(os);
45 public JPFOutputStream (PrintStream ps){
49 public JPFOutputStream (){
57 if (ps != System.err && ps != System.out){
62 public void printCommentLine(String msg){
67 public void print (ElementInfo ei, FieldInfo fi, boolean isFiltered){
68 ps.print(fi.getName());
75 switch (fi.getTypeCode()) {
77 ps.print(ei.getBooleanField(fi));
80 ps.print(ei.getByteField(fi));
83 PrintUtils.printCharLiteral(ps, ei.getCharField(fi));
86 ps.print(ei.getShortField(fi));
89 ps.print(ei.getIntField(fi));
92 ps.print(ei.getLongField(fi));
95 ps.print(ei.getFloatField(fi));
98 ps.print(ei.getDoubleField(fi));
101 case Types.T_REFERENCE:
103 PrintUtils.printReference(ps, ei.getReferenceField(fi));
109 protected void printFields (ElementInfo ei, FieldInfo[] fields, FinalBitSet filterMask){
111 for (int i = 0; i < fields.length; i++) {
115 print(ei, fields[i], (filterMask != null && filterMask.get(i)));
120 public void print (ElementInfo ei, FinalBitSet filterMask){
121 boolean isObject = ei.isObject();
122 ClassInfo ci = ei.getClassInfo();
124 int ref = (useSid) ? ((int)ei.getSid()) : ei.getObjectRef();
125 ps.printf("@%x ", ref);
130 ps.print( Types.getTypeName(ci.getName()));
132 ps.print(ci.getName());
136 ps.print(ci.getName());
144 ei.getArrayFields().printElements(ps, maxElements);
149 printFields(ei, ci.getInstanceFields(), filterMask);
155 printFields( ei, ci.getDeclaredStaticFields(), filterMask);
160 public void print (ThreadInfo ti){
161 PrintUtils.printReference(ps, ti.getThreadObjectRef());
163 ps.print(ti.getStateDescription());
166 public void print (StackFrame frame){
167 MethodInfo mi = frame.getMethodInfo();
170 ps.print(frame.getDepth());
173 ps.print( mi.getFullName());
178 PrintUtils.printReference(ps, frame.getThis());
183 ps.print(frame.getPC().getInstructionIndex());
185 ps.print(",slots:[");
186 frame.printSlots(ps);
192 public void println(){
196 public void print (NativeStateHolder nsh){
199 ps.print(nsh.getHash());
203 public void write(int b) throws IOException {