Skip to content

Commit 2628683

Browse files
committed
Bring back instrumentation to the compile path to support decompiling
for debugging
1 parent 1c91f37 commit 2628683

File tree

2 files changed

+73
-29
lines changed

2 files changed

+73
-29
lines changed

src/jvm/clojure/lang/Compiler.java

+44-3
Original file line numberDiff line numberDiff line change
@@ -7470,12 +7470,17 @@ public static Object eval(Object form, boolean freshLoader) {
74707470
Object column = (meta != null ? meta.valAt(RT.COLUMN_KEY, COLUMN.deref()) : COLUMN.deref());
74717471

74727472
IPersistentMap bindings = RT.mapUniqueKeys(LINE, line, COLUMN, column);
7473+
7474+
// [STORM] For each evaluation, before macroexpanding :
7475+
// We add this same code on the compile path
7476+
// Supporting the compile path is useful only for debugging, like using
7477+
// clj-java-decompiler
7478+
// ------------------------------------------------------------------------
74737479

74747480
Integer formId = null;
74757481
HashSet<String> formCoords = null;
74767482
Object origForm = form;
7477-
7478-
// [STORM] For each evaluation, before macroexpanding :
7483+
74797484
if (form != null &&
74807485
!Emitter.skipInstrumentation(munge(currentNS().toString()))) {
74817486
if (!Utils.isAnnoyingLeinNreplForm(origForm)) {
@@ -7494,6 +7499,7 @@ public static Object eval(Object form, boolean freshLoader) {
74947499
System.out.println("ClojureStorm: skipping lein initialization form instrumentation being evaluated in " + currentNS().toString());
74957500
}
74967501
}
7502+
// ------------------------------------------------------------------------
74977503
if(meta != null) {
74987504
Object eval_file = meta.valAt(RT.EVAL_FILE_KEY);
74997505
if(eval_file != null) {
@@ -8175,15 +8181,50 @@ CONSTANT_IDS, new IdentityHashMap(),
81758181
for(Object r = LispReader.read(pushbackReader, false, EOF, false, readerOpts); r != EOF;
81768182
r = LispReader.read(pushbackReader, false, EOF, false, readerOpts))
81778183
{
8178-
8184+
8185+
// [STORM] For each evaluation, before macroexpanding :
8186+
// We add this same code on the compile path
8187+
// Supporting the compile path is useful only for debugging, like using
8188+
// clj-java-decompiler
8189+
// ------------------------------------------------------------------------
8190+
8191+
Object origForm = r;
8192+
Integer formId = null;
8193+
HashSet<String> formCoords = null;
8194+
boolean stormPushedBindings = false;
8195+
if (r != null &&
8196+
!Emitter.skipInstrumentation(munge(currentNS().toString()))) {
8197+
if (!Utils.isAnnoyingLeinNreplForm(origForm)) {
8198+
// Calculate the form id
8199+
formId = r.hashCode();
8200+
formCoords = new HashSet();
8201+
8202+
// Tag the coords
8203+
r = Utils.tagStormCoord(r);
8204+
8205+
// Bind FORM_ID so everything down the road knows what form
8206+
// they belong to
8207+
Var.pushThreadBindings(
8208+
RT.mapUniqueKeys(FORM_ID, formId,
8209+
FORM_COORDS, formCoords));
8210+
stormPushedBindings = true;
8211+
} else {
8212+
System.out.println("ClojureStorm: skipping lein initialization form instrumentation being evaluated in " + currentNS().toString());
8213+
}
8214+
}
8215+
// ------------------------------------------------------------------------
81798216
LINE_AFTER.set(pushbackReader.getLineNumber());
81808217
COLUMN_AFTER.set(pushbackReader.getColumnNumber());
81818218
compile1(gen, objx, r);
81828219
LINE_BEFORE.set(pushbackReader.getLineNumber());
81838220
COLUMN_BEFORE.set(pushbackReader.getColumnNumber());
81848221

8222+
if (stormPushedBindings) Var.popThreadBindings();
81858223
}
81868224

8225+
// generate forms registration
8226+
Emitter.emitFormsRegistration(gen, forms, sourcePath);
8227+
81878228
//end of load
81888229
gen.returnValue();
81898230
gen.endMethod();

src/jvm/clojure/storm/Emitter.java

+29-26
Original file line numberDiff line numberDiff line change
@@ -415,30 +415,33 @@ public static void emitBindTraces(GeneratorAdapter gen, ObjExpr objx, IPersisten
415415
}
416416
}
417417

418-
// public static void emitFormsRegistration(GeneratorAdapter gen, List<Object> forms, String sourcePath) {
419-
// Namespace ns = (Namespace) RT.CURRENT_NS.deref();
420-
// String fns = ns.getName().toString();
421-
422-
// if (!skipInstrumentation(Compiler.munge(fns))) {
423-
// for (Object form : forms) {
424-
// IPersistentMap fmeta = RT.meta(form);
425-
// if (fmeta != null) {
426-
// int fline = -1;
427-
// // when using the decompiler this is being returned as a Long and throwing a cast error
428-
// // so lets hack it like this
429-
// Object oline = fmeta.valAt(LINE_KEY);
430-
// if (oline instanceof Integer) {
431-
// fline = (Integer) oline;
432-
// }
433-
434-
// int fid = form.hashCode();
435-
// gen.push(fid);
436-
// gen.push(fline);
437-
// gen.push(fns);
438-
// gen.push(sourcePath);
439-
// gen.invokeStatic(TRACER_CLASS_TYPE, Method.getMethod("void registerFormLocation(int, int, String, String)"));
440-
// }
441-
// }
442-
// }
443-
// }
418+
// This is only for the compile path (when calling clojure compile).
419+
// Supporting the compile path is useful only for debugging, like using
420+
// clj-java-decompiler
421+
public static void emitFormsRegistration(GeneratorAdapter gen, List<Object> forms, String sourcePath) {
422+
Namespace ns = (Namespace) RT.CURRENT_NS.deref();
423+
String fns = ns.getName().toString();
424+
425+
if (!skipInstrumentation(Compiler.munge(fns))) {
426+
for (Object form : forms) {
427+
IPersistentMap fmeta = RT.meta(form);
428+
if (fmeta != null) {
429+
int fline = -1;
430+
// when using the decompiler this is being returned as a Long and throwing a cast error
431+
// so lets hack it like this
432+
Object oline = fmeta.valAt(LINE_KEY);
433+
if (oline instanceof Integer) {
434+
fline = (Integer) oline;
435+
}
436+
437+
int fid = form.hashCode();
438+
gen.push(fid);
439+
gen.push(fline);
440+
gen.push(fns);
441+
gen.push(sourcePath);
442+
gen.invokeStatic(TRACER_CLASS_TYPE, Method.getMethod("void registerFormLocation(int, int, String, String)"));
443+
}
444+
}
445+
}
446+
}
444447
}

0 commit comments

Comments
 (0)