94fc0f3aabd1cbadfda4026a009af4735caa5fc5
[jpf-core.git] / src / main / gov / nasa / jpf / vm / serialize / SmartThingsConfig.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 gov.nasa.jpf.Config;
22 import gov.nasa.jpf.annotation.FilterField;
23 import gov.nasa.jpf.annotation.FilterFrame;
24 import gov.nasa.jpf.vm.AnnotationInfo;
25 import gov.nasa.jpf.vm.FieldInfo;
26 import gov.nasa.jpf.vm.ClassInfo;
27 import gov.nasa.jpf.vm.MethodInfo;
28 import gov.nasa.jpf.vm.serialize.AmmendableFilterConfiguration.FieldAmmendment;
29 import gov.nasa.jpf.vm.serialize.AmmendableFilterConfiguration.FrameAmmendment;
30
31 public class SmartThingsConfig
32   implements FieldAmmendment, FrameAmmendment {
33
34   public boolean staticClass(ClassInfo ci) {
35     String pName = ci.getName();
36     if (pName.startsWith("java."))
37       return true;
38
39     if (pName.startsWith("sun."))
40       return true;
41
42     if (pName.startsWith("com.sun"))
43       return true;
44
45     if (pName.startsWith("org."))
46       return true;
47
48     if (pName.startsWith("groovy."))
49       return true;
50
51     if (pName.startsWith("groovyjarjarasm."))
52       return true;
53
54     if (pName.startsWith("gov."))
55       return true;
56
57     if (pName.startsWith("["))
58       return true;
59
60     return false;
61   }
62   public boolean ignoreClass(ClassInfo ci) {
63     String pName = ci.getName();
64     if (pName.startsWith("org")) {
65       if (pName.startsWith("org.codehaus.groovy")) {
66         //      System.out.println("Ignoring "+pName);
67         return true;
68       }
69       if (pName.startsWith("org.apache.groovy")) {
70         //      System.out.println("Ignoring "+pName);
71         return true;
72       }
73     } else if (pName.startsWith("java")) {
74       if (pName.startsWith("java.lang")) {
75         if (pName.startsWith("java.lang.reflect")) {
76           return true;
77         }
78         if (pName.startsWith("java.lang.ref")) {
79           return true;
80         }
81         if (pName.startsWith("java.lang.ClassLoader")) {
82           return true;
83         }
84         if (pName.startsWith("java.lang.Class"))
85           return true;
86         if (pName.startsWith("java.lang.Thread"))
87           return true;
88         if (pName.startsWith("java.lang.Package"))
89           return true;
90       } else {
91       if (pName.startsWith("java.util.concurrent")) {
92         //      System.out.println("Ignoring "+pName);
93         return true;
94       }
95       if (pName.startsWith("java.util.logging")) {
96         //      System.out.println("Ignoring "+pName);
97         return true;
98       }
99       if (pName.startsWith("java.beans")) {
100         return true;
101       }
102       if (pName.startsWith("java.io.OutputStreamWriter"))
103         return true;
104       if (pName.startsWith("java.io.PrintStream"))
105         return true;
106       if (pName.startsWith("java.io.BufferedWriter"))
107         return true;
108       }
109       if (pName.startsWith("java.nio.charset"))
110         return true;
111       
112     } else if (pName.startsWith("groovy")) {
113       if (pName.startsWith("groovy.lang")) {
114         //      System.out.println("Ignoring "+pName);
115         return true;
116       }
117       if (pName.startsWith("groovyjarjarasm.asm")) {
118         //      System.out.println("Ignoring "+pName);
119         return true;
120       }
121     }
122     if (pName.startsWith("com.sun.beans")) {
123       return true;
124     }
125     if (pName.startsWith("sun.reflect")) {
126       return true;
127     }
128     if (pName.startsWith("sun.misc.SharedSecrets"))
129       return true;
130     if (pName.startsWith("sun.util.logging"))
131       return true;
132     if (pName.startsWith("sun.net.www"))
133       return true;
134     if (pName.startsWith("gov.nasa"))
135       return true;
136     return false;
137   }
138   
139   @Override
140   public boolean ammendFieldInclusion(FieldInfo fi, boolean sofar) {
141     ClassInfo ci = fi.getClassInfo();
142     if (ignoreClass(ci))
143       return POLICY_IGNORE;
144     ClassInfo civ = fi.getTypeClassInfo();
145     if (ignoreClass(civ))
146       return POLICY_IGNORE;      
147     return sofar;
148   }
149
150   @Override
151   public FramePolicy ammendFramePolicy(MethodInfo mi, FramePolicy sofar) {
152     ClassInfo ci = mi.getClassInfo();
153     if (ignoreClass(ci)) {
154       sofar.includeLocals = false;
155       sofar.includeOps = false;
156       sofar.includePC = false;
157     } else {
158       //      System.out.println("Including M: " +mi);
159     }
160
161     return sofar;
162   }
163
164   public static final SmartThingsConfig instance = new SmartThingsConfig();
165 }