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 // TODO: Fix for Groovy's model-checking
125 // TODO: Change of sid assignment strategy since the previous one caused a bug with SmartThings object filtering
126 int ref = (useSid) ? ((int)ei.getSid()) : ei.getObjectRef();
127 ps.printf("@%x ", ref);
132 ps.print( Types.getTypeName(ci.getName()));
134 ps.print(ci.getName());
138 ps.print(ci.getName());
146 ei.getArrayFields().printElements(ps, maxElements);
151 printFields(ei, ci.getInstanceFields(), filterMask);
157 printFields( ei, ci.getDeclaredStaticFields(), filterMask);
162 public void print (ThreadInfo ti){
163 PrintUtils.printReference(ps, ti.getThreadObjectRef());
165 ps.print(ti.getStateDescription());
168 public void print (StackFrame frame){
169 MethodInfo mi = frame.getMethodInfo();
172 ps.print(frame.getDepth());
175 ps.print( mi.getFullName());
180 PrintUtils.printReference(ps, frame.getThis());
185 ps.print(frame.getPC().getInstructionIndex());
187 ps.print(",slots:[");
188 frame.printSlots(ps);
194 public void println(){
198 public void print (NativeStateHolder nsh){
201 ps.print(nsh.getHash());
205 public void write(int b) throws IOException {