Skip to content

Commit

Permalink
move KlassMap to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareCobbler committed Dec 12, 2024
1 parent 9b3aa9a commit 5e2768f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 63 deletions.
2 changes: 1 addition & 1 deletion luceedebug/src/main/java/luceedebug/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static Map<String, Integer> linearizedCoreInjectClasses() {
result.put("luceedebug.coreinject.ClosureScopeLocalScopeAccessorShim", 0);
result.put("luceedebug.coreinject.ComponentScopeMarkerTraitShim", 0);
result.put("luceedebug.coreinject.LuceeVm$SteppingState", 0);
result.put("luceedebug.coreinject.LuceeVm$KlassMap", 0);
result.put("luceedebug.coreinject.KlassMap", 0);
result.put("luceedebug.coreinject.LuceeVm$JdwpWorker", 0);
result.put("luceedebug.coreinject.ValTracker$TaggedObject", 0);
result.put("luceedebug.coreinject.DebugEntity", 0);
Expand Down
71 changes: 71 additions & 0 deletions luceedebug/src/main/java/luceedebug/coreinject/KlassMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package luceedebug.coreinject;

import java.util.HashMap;

import luceedebug.Config;
import luceedebug.OriginalAndTransformedString;

import com.sun.jdi.*;

class KlassMap {
/**
* original -> original
*
* transformed -> canonicalized as per fs config
*/
final public OriginalAndTransformedString sourceName;
final public HashMap<Integer, Location> lineMap;
private final ClassObjectReference objRef;

final public ReferenceType refType;

private KlassMap(Config config, ReferenceType refType) throws AbsentInformationException {
objRef = refType.classObject();

String sourceName = refType.sourceName();
var lineMap = new HashMap<Integer, Location>();

for (var loc : refType.allLineLocations()) {
lineMap.put(loc.lineNumber(), loc);
}

this.sourceName = new OriginalAndTransformedString(
sourceName,
Config.canonicalizeFileName(sourceName)
);
this.lineMap = lineMap;
this.refType = refType;
}

boolean isCollected() {
return objRef.isCollected();
}

/**
* May return null if ReferenceType throws an AbsentInformationException, which the caller
* should interpret as "we can't do anything meaningful with this file"
*/
static KlassMap maybeNull_tryBuildKlassMap(Config config, ReferenceType refType) {
try {
return new KlassMap(config, refType);
}
catch (AbsentInformationException e) {
return null;
}
catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}

// unreachable
return null;
}

@Override
public boolean equals(Object e) {
if (e instanceof KlassMap) {
return ((KlassMap)e).sourceName.equals(this.sourceName);
}
return false;
}
}
63 changes: 1 addition & 62 deletions luceedebug/src/main/java/luceedebug/coreinject/LuceeVm.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -720,66 +719,6 @@ public IDebugEntity[] getIndexedVariables(long ID) {
return GlobalIDebugManagerHolder.debugManager.getVariables(ID, IDebugEntity.DebugEntityType.INDEXED);
}

static private class KlassMap {
/**
* original -> original
*
* transformed -> canonicalized as per fs config
*/
final public OriginalAndTransformedString sourceName;
final public HashMap<Integer, Location> lineMap;
private final ClassObjectReference objRef;

@SuppressWarnings("unused")
final public ReferenceType refType;

private KlassMap(Config config, ReferenceType refType) throws AbsentInformationException {
objRef = refType.classObject();

String sourceName = refType.sourceName();
var lineMap = new HashMap<Integer, Location>();

for (var loc : refType.allLineLocations()) {
lineMap.put(loc.lineNumber(), loc);
}

this.sourceName = new OriginalAndTransformedString(
sourceName,
Config.canonicalizeFileName(sourceName)
);
this.lineMap = lineMap;
this.refType = refType;
}

/**
* May return null if ReferenceType throws an AbsentInformationException, which the caller
* should interpret as "we can't do anything meaningful with this file"
*/
static KlassMap maybeNull_tryBuildKlassMap(Config config, ReferenceType refType) {
try {
return new KlassMap(config, refType);
}
catch (AbsentInformationException e) {
return null;
}
catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}

// unreachable
return null;
}

@Override
public boolean equals(Object e) {
if (e instanceof KlassMap) {
return ((KlassMap)e).sourceName.equals(this.sourceName);
}
return false;
}
}

private AtomicInteger breakpointID = new AtomicInteger();
private int nextBreakpointID() {
return breakpointID.incrementAndGet();
Expand Down Expand Up @@ -875,7 +814,7 @@ private IBreakpoint[] __internal__bindBreakpoints(String serverAbsPath, BpLineAn
List<KlassMap> garbageCollectedKlassMaps = new ArrayList<>();

for (KlassMap mapping : klassMapSet) {
if (mapping.objRef.isCollected()) {
if (mapping.isCollected()) {
// This still leaves us with a little race where it gets collected after this,
// but before we start adding breakpoints to the gc'd class.
garbageCollectedKlassMaps.add(mapping);
Expand Down

0 comments on commit 5e2768f

Please sign in to comment.