Skip to content

Commit 66a14bc

Browse files
move DebugFrame to luceedebug.coreinject.frame package
1 parent 6ad6f52 commit 66a14bc

File tree

6 files changed

+73
-35
lines changed

6 files changed

+73
-35
lines changed

luceedebug/src/main/java/luceedebug/coreinject/CfValueDebuggerBridge.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
import lucee.runtime.type.Array;
1616
import luceedebug.ICfValueDebuggerBridge;
1717
import luceedebug.IDebugEntity;
18+
import luceedebug.coreinject.frame.DebugFrame;
1819

19-
class CfValueDebuggerBridge implements ICfValueDebuggerBridge {
20+
public class CfValueDebuggerBridge implements ICfValueDebuggerBridge {
2021
// Pin some ephemeral evaluated things so they don't get GC'd immediately.
2122
// It would be better to pin them to a "session" or something with a meaningful lifetime,
2223
// rather than hope they live long enough in this cache to be useful.
@@ -27,7 +28,7 @@ class CfValueDebuggerBridge implements ICfValueDebuggerBridge {
2728
.maximumSize(50)
2829
.expireAfterWrite(10, TimeUnit.MINUTES)
2930
.build();
30-
static void pin(Object obj) {
31+
public static void pin(Object obj) {
3132
pinnedObjects.put(System.identityHashCode(obj), obj);
3233
}
3334

@@ -45,10 +46,10 @@ public long getID() {
4546
return id;
4647
}
4748

48-
static class MarkerTrait {
49-
static class Scope {
49+
public static class MarkerTrait {
50+
public static class Scope {
5051
public final Map<?,?> scopelike;
51-
Scope(Map<?,?> scopelike) {
52+
public Scope(Map<?,?> scopelike) {
5253
this.scopelike = scopelike;
5354
}
5455
}

luceedebug/src/main/java/luceedebug/coreinject/DebugEntity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import luceedebug.*;
44

55
public class DebugEntity implements IDebugEntity {
6-
String name;
7-
String value;
8-
int namedVariables;
9-
int indexedVariables;
10-
boolean expensive;
11-
long variablesReference;
6+
public String name;
7+
public String value;
8+
public int namedVariables;
9+
public int indexedVariables;
10+
public boolean expensive;
11+
public long variablesReference;
1212

1313
public String getName() { return name; }
1414
public String getValue() { return value; }

luceedebug/src/main/java/luceedebug/coreinject/DebugManager.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import luceedebug.IDebugEntity;
3333
import luceedebug.IDebugFrame;
3434
import luceedebug.IDebugManager;
35+
import luceedebug.coreinject.frame.DebugFrame;
3536

3637
public class DebugManager implements IDebugManager {
3738

@@ -662,10 +663,10 @@ private DebugFrame getTopmostFrame(Thread thread) {
662663
}
663664

664665
public void pushCfFrame(PageContext pageContext, String sourceFilePath) {
665-
pushCfFrame_worker(pageContext, sourceFilePath);
666+
maybe_pushCfFrame_worker(pageContext, sourceFilePath);
666667
}
667668

668-
private DebugFrame pushCfFrame_worker(PageContext pageContext, String sourceFilePath) {
669+
private DebugFrame maybe_pushCfFrame_worker(PageContext pageContext, String sourceFilePath) {
669670
Thread currentThread = Thread.currentThread();
670671

671672
ArrayList<DebugFrame> stack = cfStackByThread.get(currentThread);
@@ -681,7 +682,12 @@ private DebugFrame pushCfFrame_worker(PageContext pageContext, String sourceFile
681682
}
682683

683684
final int depth = stack.size(); // first frame is frame 0, and prior to pushing the first frame the stack is length 0; next frame is frame 1, and prior to pushing it the stack is of length 1, ...
684-
final DebugFrame frame = new DebugFrame(sourceFilePath, depth, valTracker, pageContext);
685+
686+
final DebugFrame frame = DebugFrame.maybeMakeFrame(sourceFilePath, depth, valTracker, pageContext);
687+
688+
if (frame == null) {
689+
return null;
690+
}
685691

686692
stack.add(frame);
687693

@@ -696,7 +702,11 @@ private DebugFrame pushCfFrame_worker(PageContext pageContext, String sourceFile
696702
}
697703

698704
public void pushCfFunctionDefaultValueInitializationFrame(lucee.runtime.PageContext pageContext, String sourceFilePath) {
699-
DebugFrame frame = pushCfFrame_worker(pageContext, sourceFilePath);
705+
DebugFrame frame = maybe_pushCfFrame_worker(pageContext, sourceFilePath);
706+
if (frame == null) {
707+
return;
708+
}
709+
700710
frame.isUdfDefaultValueInitFrame = true;
701711
}
702712

luceedebug/src/main/java/luceedebug/coreinject/ExprEvaluator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import lucee.runtime.PageContext;
1010
import luceedebug.Either;
11+
import luceedebug.coreinject.frame.DebugFrame;
1112

1213
import static luceedebug.coreinject.Utils.terminate;
1314

luceedebug/src/main/java/luceedebug/coreinject/UnsafeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import lucee.runtime.exp.PageException;
44

5-
class UnsafeUtils {
5+
public class UnsafeUtils {
66
@SuppressWarnings("unchecked")
77
static <T> T uncheckedCast(Object e) {
88
return (T)e;

luceedebug/src/main/java/luceedebug/coreinject/DebugFrame.java renamed to luceedebug/src/main/java/luceedebug/coreinject/frame/DebugFrame.java

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package luceedebug.coreinject;
1+
package luceedebug.coreinject.frame;
22

33
import lucee.runtime.PageContext;
44
import lucee.runtime.PageContextImpl;
@@ -18,7 +18,13 @@
1818
import com.google.common.collect.MapMaker;
1919

2020
import luceedebug.*;
21+
import luceedebug.coreinject.CfValueDebuggerBridge;
22+
import luceedebug.coreinject.ClosureScopeLocalScopeAccessorShim;
23+
import luceedebug.coreinject.DebugEntity;
24+
import luceedebug.coreinject.UnsafeUtils;
25+
import luceedebug.coreinject.ValTracker;
2126
import luceedebug.coreinject.CfValueDebuggerBridge.MarkerTrait;
27+
import luceedebug.coreinject.CfValueDebuggerBridge.MarkerTrait.Scope;
2228

2329
public class DebugFrame implements IDebugFrame {
2430
static private AtomicLong nextId = new AtomicLong(0);
@@ -63,6 +69,8 @@ void pin(Object obj) {
6369
refsToKeepAlive_.add(obj);
6470
}
6571

72+
static ThreadLocal<Boolean> isPushingFrame = ThreadLocal.withInitial(() -> false);
73+
6674
// hold strong refs to scopes, because PageContext will swap them out as frames change (variables, local, this)
6775
// (application, server and etc. maybe could be held as globals)
6876
// We don't want to construct tracked refs to them until a debugger asks for them, because it is expensive
@@ -76,21 +84,21 @@ void pin(Object obj) {
7684
// the engine is truly do with its "frame". Fallback here would be use a WeakRef<> but it doesn't
7785
// seem necessary.
7886
//
79-
static class FrameContext {
80-
final PageContext pageContext;
81-
82-
final lucee.runtime.type.scope.Scope application;
83-
final lucee.runtime.type.scope.Argument arguments;
84-
final lucee.runtime.type.scope.Scope form;
85-
final lucee.runtime.type.scope.Local local;
86-
final lucee.runtime.type.scope.Scope request;
87-
final lucee.runtime.type.scope.Scope session;
88-
final lucee.runtime.type.scope.Scope server;
89-
final lucee.runtime.type.scope.Scope url;
90-
final lucee.runtime.type.scope.Variables variables;
87+
public static class FrameContext {
88+
final public PageContext pageContext;
89+
90+
public final lucee.runtime.type.scope.Scope application;
91+
public final lucee.runtime.type.scope.Argument arguments;
92+
public final lucee.runtime.type.scope.Scope form;
93+
public final lucee.runtime.type.scope.Local local;
94+
public final lucee.runtime.type.scope.Scope request;
95+
public final lucee.runtime.type.scope.Scope session;
96+
public final lucee.runtime.type.scope.Scope server;
97+
public final lucee.runtime.type.scope.Scope url;
98+
public final lucee.runtime.type.scope.Variables variables;
9199
// n.b. the `this` scope does not derive from Scope
92-
final lucee.runtime.type.Struct this_;
93-
final lucee.runtime.type.scope.Scope static_;
100+
public final lucee.runtime.type.Struct this_;
101+
public final lucee.runtime.type.scope.Scope static_;
94102

95103
// lazy init because it (might?) be expensive to walk scope chains eagerly every frame
96104
private ArrayList<lucee.runtime.type.scope.ClosureScope> capturedScopeChain = null;
@@ -104,7 +112,7 @@ static class FrameContext {
104112
// expensive exceptions on literally every frame, e.g. if a scope is disabled by the engine and trying to touch it
105113
// throws an ExpressionException.
106114
//
107-
FrameContext(PageContext pageContext) {
115+
private FrameContext(PageContext pageContext) {
108116
this.pageContext = pageContext;
109117
this.application = getScopelikeOrNull(() -> pageContext.applicationScope());
110118
this.arguments = getScopelikeOrNull(() -> pageContext.argumentsScope());
@@ -217,11 +225,29 @@ public <T> T doWorkInThisFrame(Supplier<T> f) {
217225
}
218226
}
219227

220-
public DebugFrame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext) {
228+
// DebugFrame >: DummyFrame | Frame
229+
static private DebugFrame dummyFrame = new DebugFrame("null", 0, null, null);
230+
231+
static public DebugFrame maybeMakeFrame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext) {
232+
if (isPushingFrame.get()) {
233+
return null;
234+
}
235+
else {
236+
try {
237+
isPushingFrame.set(true);
238+
return new DebugFrame(sourceFilePath, depth, valTracker, pageContext, DebugFrame.tryGetFrameName(pageContext));
239+
}
240+
finally {
241+
isPushingFrame.set(false);
242+
}
243+
}
244+
}
245+
246+
private DebugFrame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext) {
221247
this(sourceFilePath, depth, valTracker, pageContext, DebugFrame.tryGetFrameName(pageContext));
222248
}
223249

224-
public DebugFrame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext, String name) {
250+
private DebugFrame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext, String name) {
225251
this.frameContext_ = new FrameContext(pageContext);
226252
this.sourceFilePath = Objects.requireNonNull(sourceFilePath);
227253
this.valTracker = Objects.requireNonNull(valTracker);
@@ -321,7 +347,7 @@ public IDebugEntity[] getScopes() {
321347
return result;
322348
}
323349

324-
CfValueDebuggerBridge trackEvalResult(Object obj) {
350+
public CfValueDebuggerBridge trackEvalResult(Object obj) {
325351
var v = new CfValueDebuggerBridge(this, obj);
326352
CfValueDebuggerBridge.pin(obj);
327353
return v;

0 commit comments

Comments
 (0)