SmartThings specific support to reduce state space
[jpf-core.git] / src / main / gov / nasa / jpf / vm / serialize / DebugCFSerializer.java
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.vm.serialize;
20
21 import java.io.OutputStream;
22
23 import gov.nasa.jpf.util.FinalBitSet;
24 import gov.nasa.jpf.vm.DebugStateSerializer;
25 import gov.nasa.jpf.vm.ElementInfo;
26 import gov.nasa.jpf.vm.JPFOutputStream;
27 import gov.nasa.jpf.vm.NativeStateHolder;
28 import gov.nasa.jpf.vm.StackFrame;
29 import gov.nasa.jpf.vm.StaticElementInfo;
30 import gov.nasa.jpf.vm.ThreadInfo;
31
32 /**
33  * a CFSerializer that stores the serialized program state in a 
34  * readable/diffable format.
35  * 
36  * Automatically used by Debug..StateSet if the configured vm.storage.class is .vm.DebugJenkinsStateSet 
37  */
38 public class DebugCFSerializer extends CFSerializer implements DebugStateSerializer {
39
40   JPFOutputStream os;
41   
42   // this is for debugging purposes only
43   public DebugCFSerializer() {
44     os = new JPFOutputStream(System.out);
45   }
46   
47   @Override
48   public void setOutputStream (OutputStream s){
49     os = new JPFOutputStream(s);
50   }
51   
52   @Override
53   protected int[] computeStoringData() {    
54     os.printCommentLine("------------------------ serialized state");
55     return super.computeStoringData();
56   }
57   
58   @Override
59   protected void processReferenceQueue(){
60     os.println();
61     os.printCommentLine("--- heap");
62     os.println();
63     super.processReferenceQueue();
64   }
65   
66   @Override
67   public void process (ElementInfo ei) {
68     super.process( ei);
69     
70     FinalBitSet filtered = !ei.isArray() ? getInstanceFilterMask(ei.getClassInfo()) : null;
71     os.print(ei, filtered);
72     os.println();
73   }
74   
75   @Override
76   protected void serializeClassLoaders(){
77     os.println();
78     os.printCommentLine("--- classes");
79     os.println();
80     super.serializeClassLoaders();
81   }
82   
83   @Override
84   protected void serializeClass (StaticElementInfo sei){
85     super.serializeClass(sei);
86     
87     FinalBitSet filtered = getStaticFilterMask(sei.getClassInfo());
88     os.print(sei, filtered);
89     os.println();    
90   }
91   
92   @Override
93   protected void serializeStackFrames(){
94     os.println();
95     os.printCommentLine("--- threads");
96     os.println();
97     super.serializeStackFrames();
98   }
99   
100   @Override
101   protected void serializeStackFrames(ThreadInfo ti){
102     os.println();
103     os.print(ti);
104     os.println();
105     super.serializeStackFrames(ti);
106   }
107   
108   @Override
109   protected void serializeFrame(StackFrame frame){
110     os.print(frame);
111     os.println();
112     super.serializeFrame(frame);
113   }
114   
115   @Override
116   protected void serializeNativeStateHolders(){
117     os.println();
118     os.printCommentLine("--- native state holders");
119     os.println();
120     super.serializeNativeStateHolders();
121   }
122   
123   @Override
124   protected void serializeNativeStateHolder (NativeStateHolder nsh){
125     os.print(nsh);
126     os.println();
127     super.serializeNativeStateHolder(nsh);
128   }
129   
130 }