2828import edu .columbia .cs .psl .chroniclerj .visitor .NonDeterministicLoggingClassVisitor ;
2929
3030public class PreMain {
31- static boolean replay ;
31+ public static boolean replay ;
32+
3233 private static final class HackyClassWriter extends ClassWriter {
3334
3435 private HackyClassWriter (ClassReader classReader , int flags ) {
@@ -39,6 +40,7 @@ protected String getCommonSuperClass(String type1, String type2) {
3940 return "java/lang/Object" ;
4041 }
4142 }
43+
4244 static class ChroniclerTransformer implements ClassFileTransformer {
4345 @ Override
4446 public byte [] transform (ClassLoader loader , String className , Class <?> classBeingRedefined , ProtectionDomain protectionDomain , byte [] classfileBuffer ) throws IllegalClassFormatException {
@@ -67,20 +69,22 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
6769 }
6870 } else {
6971 ClassReader cr = new ClassReader (classfileBuffer );
72+ className = cr .getClassName ();
7073 if (isIgnoredClass (cr .getClassName ()))
7174 return null ;
7275 if (DEBUG )
7376 System .out .println ("Inst: " + cr .getClassName ());
74-
77+
7578 boolean skipFrames = false ;
76- ClassNode cn = new ClassNode ();
79+ ClassNode cn = new ClassNode ();
7780 cr .accept (cn , ClassReader .SKIP_CODE );
7881 if (cn .version >= 100 || cn .version <= 50 || className .endsWith ("$Access4JacksonSerializer" ) || className .endsWith ("$Access4JacksonDeSerializer" ))
7982 skipFrames = true ;
8083
81- if (skipFrames )
82- {
83- //This class is old enough to not guarantee frames. Generate new frames for analysis reasons, then make sure to not emit ANY frames.
84+ if (skipFrames ) {
85+ // This class is old enough to not guarantee frames.
86+ // Generate new frames for analysis reasons, then make sure
87+ // to not emit ANY frames.
8488 ClassWriter cw = new HackyClassWriter (cr , ClassWriter .COMPUTE_MAXS | ClassWriter .COMPUTE_FRAMES );
8589 cr .accept (new ClassVisitor (Opcodes .ASM5 , cw ) {
8690 @ Override
@@ -90,11 +94,11 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
9094 }, 0 );
9195 cr = new ClassReader (cw .toByteArray ());
9296 }
93-
94- try {
97+
98+ try {
9599 ClassWriter cw = new ClassWriter (ClassWriter .COMPUTE_MAXS );
96- NonDeterministicLoggingClassVisitor cv = new NonDeterministicLoggingClassVisitor (new SerialVersionUIDAdder (cw ), skipFrames );
97- CallbackDuplicatingClassVisitor callbackDuplicator = new CallbackDuplicatingClassVisitor (cv , skipFrames );
100+ NonDeterministicLoggingClassVisitor cv = new NonDeterministicLoggingClassVisitor (new SerialVersionUIDAdder (cw ));
101+ CallbackDuplicatingClassVisitor callbackDuplicator = new CallbackDuplicatingClassVisitor (cv );
98102
99103 cr .accept (callbackDuplicator , ClassReader .EXPAND_FRAMES );
100104 if (DEBUG ) {
@@ -110,31 +114,33 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
110114 return cw .toByteArray ();
111115 } catch (Throwable t ) {
112116 t .printStackTrace ();
113- if (DEBUG ) {
114- TraceClassVisitor tcv = null ;
115- PrintWriter fw = null ;
116- try {
117- File f = new File ("z.class" );
117+
118+ TraceClassVisitor tcv = null ;
119+ PrintWriter fw = null ;
120+ try {
121+ File f = new File ("z.class" );
122+ if (f .getParentFile () != null )
118123 f .getParentFile ().mkdirs ();
119- f .delete ();
120- FileOutputStream fos = new FileOutputStream (f );
121- fos .write (classfileBuffer );
122- fos .close ();
123- fw = new PrintWriter ("lastClass.txt" );
124-
125- tcv = new TraceClassVisitor (fw );
126- NonDeterministicLoggingClassVisitor cv = new NonDeterministicLoggingClassVisitor (new SerialVersionUIDAdder (tcv ), skipFrames );
127- CallbackDuplicatingClassVisitor callbackDuplicator = new CallbackDuplicatingClassVisitor (cv , skipFrames );
128-
129- cr .accept (callbackDuplicator , ClassReader .EXPAND_FRAMES );
130-
131- } catch (Throwable t2 ) {
132- t2 .printStackTrace ();
133- } finally {
134- tcv . visitEnd ();
135- fw . close ();
136- }
124+ f .delete ();
125+ FileOutputStream fos = new FileOutputStream (f );
126+ fos .write (classfileBuffer );
127+ fos .close ();
128+ fw = new PrintWriter ("lastClass.txt" );
129+
130+ tcv = new TraceClassVisitor (fw );
131+ NonDeterministicLoggingClassVisitor cv = new NonDeterministicLoggingClassVisitor (new SerialVersionUIDAdder (tcv ));
132+ CallbackDuplicatingClassVisitor callbackDuplicator = new CallbackDuplicatingClassVisitor (cv );
133+
134+ cr .accept (callbackDuplicator , ClassReader .EXPAND_FRAMES );
135+
136+ } catch (Throwable t2 ) {
137+ t2 .printStackTrace ();
138+ } finally {
139+ if ( tcv != null )
140+ tcv . visitEnd ();
141+ fw . close ();
137142 }
143+
138144 return null ;
139145 }
140146 }
@@ -154,27 +160,25 @@ public static boolean isIgnoredClass(String className) {
154160
155161 static boolean DEBUG = false ;
156162 static String [] whiteList ;
157-
163+
158164 public static void premain (String _args , Instrumentation inst ) {
159165 if (_args != null ) {
160166 String [] args = _args .split ("," );
161167 for (String arg : args ) {
162168 String [] d = arg .split ("=" );
163- if (d [0 ].equals ("replay" ))
164- {
169+ if (d [0 ].equals ("replay" )) {
165170 replay = true ;
166171 if (ChroniclerJExportRunner .nameOverride != null )
167172 ReplayRunner .setupLogs (new String [] { ChroniclerJExportRunner .nameOverride });
168- }
169- else if (d [0 ].equals ("logFile" )) {
173+ } else if (d [0 ].equals ("logFile" )) {
170174 ChroniclerJExportRunner .nameOverride = d [1 ];
171- if (replay )
175+ if (replay )
172176 ReplayRunner .setupLogs (new String [] { ChroniclerJExportRunner .nameOverride });
173177 } else if (d [0 ].equals ("alwaysExport" )) {
174178 ChroniclerJExportRunner .registerShutdownHook ();
175179 } else if (d [0 ].equals ("debug" ))
176180 DEBUG = true ;
177- else if (d [0 ].equals ("quiet" ))
181+ else if (d [0 ].equals ("quiet" ))
178182 ChroniclerJExportRunner .QUIET = true ;
179183 else if (d [0 ].equals ("failsafe" )) {
180184 try {
@@ -194,19 +198,17 @@ else if (d[0].equals("failsafe")) {
194198 if (testClass == null )
195199 throw new IOException ("Couldn't find test config" );
196200 if (replay ) {
197- ChroniclerJExportRunner .nameOverride = "target/replays/" + testClass + ".crash" ;
198- ReplayRunner .setupLogs (new String []{ ChroniclerJExportRunner .nameOverride });
201+ ChroniclerJExportRunner .nameOverride = "target/replays/" + testClass + ".crash" ;
202+ ReplayRunner .setupLogs (new String [] { ChroniclerJExportRunner .nameOverride });
199203 } else {
200204 System .out .println ("Overriding test class: " + testClass );
201- ChroniclerJExportRunner .nameOverride = "target/replays/" + testClass + ".crash" ;
205+ ChroniclerJExportRunner .nameOverride = "target/replays/" + testClass + ".crash" ;
202206 }
203207 } catch (IOException ex ) {
204208 ex .printStackTrace ();
205209 System .err .println ("Unable to load in failsafe config" );
206210 }
207- }
208- else if (d [0 ].equals ("whitelist" ))
209- {
211+ } else if (d [0 ].equals ("whitelist" )) {
210212 whiteList = d [1 ].split (";" );
211213 }
212214 }
0 commit comments