Skip to content

Commit

Permalink
[GR-44976] Fixes to Espresso JDWP transient.
Browse files Browse the repository at this point in the history
PullRequest: graal/16329
  • Loading branch information
javeleon committed Dec 13, 2023
2 parents 2889f36 + 228fe44 commit dde2dcc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class ExtensionFieldsMetadata {
@CompilationFinal(dimensions = 1) private Field[] addedInstanceFields = Field.EMPTY_ARRAY;
@CompilationFinal(dimensions = 1) private Field[] addedStaticFields = Field.EMPTY_ARRAY;

void addNewStaticFields(ObjectKlass.KlassVersion holder, List<ParserField> newFields, RuntimeConstantPool pool, Map<ParserField, Field> compatibleFields,
synchronized void addNewStaticFields(ObjectKlass.KlassVersion holder, List<ParserField> newFields, RuntimeConstantPool pool, Map<ParserField, Field> compatibleFields,
ClassRedefinition classRedefinition) {
CompilerAsserts.neverPartOfCompilation();

Expand All @@ -53,7 +53,7 @@ void addNewStaticFields(ObjectKlass.KlassVersion holder, List<ParserField> newFi
}
}

void addNewInstanceFields(ObjectKlass.KlassVersion holder, List<ParserField> newFields, RuntimeConstantPool pool, Map<ParserField, Field> compatibleFields,
synchronized void addNewInstanceFields(ObjectKlass.KlassVersion holder, List<ParserField> newFields, RuntimeConstantPool pool, Map<ParserField, Field> compatibleFields,
ClassRedefinition classRedefinition) {
CompilerAsserts.neverPartOfCompilation();

Expand All @@ -68,7 +68,7 @@ void addNewInstanceFields(ObjectKlass.KlassVersion holder, List<ParserField> new
}
}

void addNewInstanceField(Field toAdd) {
synchronized void addNewInstanceField(Field toAdd) {
int nextIndex = addedInstanceFields.length;
addedInstanceFields = Arrays.copyOf(addedInstanceFields, addedInstanceFields.length + 1);
addedInstanceFields[nextIndex] = toAdd;
Expand Down Expand Up @@ -107,7 +107,7 @@ private static List<Field> initNewFields(ObjectKlass.KlassVersion holder, List<P
return toAdd;
}

Field[] getDeclaredAddedFields() {
synchronized Field[] getDeclaredAddedFields() {
int instanceFieldslength = addedInstanceFields.length;
int staticFieldsLength = addedStaticFields.length;
Field[] result = new Field[instanceFieldslength + staticFieldsLength];
Expand All @@ -116,15 +116,15 @@ Field[] getDeclaredAddedFields() {
return result;
}

Field[] getAddedStaticFields() {
return addedStaticFields;
synchronized Field[] getAddedStaticFields() {
return addedStaticFields.clone();
}

Field[] getAddedInstanceFields() {
return addedInstanceFields;
synchronized Field[] getAddedInstanceFields() {
return addedInstanceFields.clone();
}

Field getStaticFieldAtSlot(int slot) {
synchronized Field getStaticFieldAtSlot(int slot) {
Field field = binarySearch(addedStaticFields, slot);
if (field != null) {
return field;
Expand All @@ -134,7 +134,7 @@ Field getStaticFieldAtSlot(int slot) {
}
}

Field getInstanceFieldAtSlot(int slot) {
synchronized Field getInstanceFieldAtSlot(int slot) {
return binarySearch(addedInstanceFields, slot);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ private static boolean isEnumValuesField(LinkedField lkStaticFields) {
private void addSubType(ObjectKlass objectKlass) {
// We only build subtypes model iff jdwp is enabled
if (getContext().getEspressoEnv().JDWPOptions != null) {
if (this == getMeta().java_lang_Object) {
// skip collecting subtypes for j.l.Object because that can't ever change at runtime
return;
}
if (subTypes == null) {
synchronized (this) {
// double-checked locking
Expand All @@ -253,7 +257,10 @@ private void addSubType(ObjectKlass objectKlass) {
}

public void removeAsSubType() {
getSuperKlass().removeSubType(this);
if (getSuperKlass() != getMeta().java_lang_Object) {
// we're not collecting subtypes of j.l.Object because that can't ever change at runtime
getSuperKlass().removeSubType(this);
}
for (ObjectKlass superInterface : getSuperInterfaces()) {
superInterface.removeSubType(this);
}
Expand Down Expand Up @@ -816,7 +823,7 @@ public Method.MethodVersion[] getDeclaredMethodVersions() {

@Override
public Field[] getDeclaredFields() {
// Speculate that there are no hidden fields
// Speculate that there are no hidden nor removed fields
Field[] declaredFields = new Field[staticFieldTable.length + fieldTable.length - localFieldTableIndex];
int insertionIndex = 0;
for (int i = 0; i < staticFieldTable.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1393,10 +1393,14 @@ private List<DebuggerNode> collectDebuggerNodes(DebuggerNode source, SuspendAnch

private List<DebuggerNode> collectDebuggerNodes(Node iNode, SuspendAnchor suspendAnchor) {
List<DebuggerNode> nodes = new ArrayList<>();
for (EventBinding<?> binding : allBindings) {
DebuggerNode node = (DebuggerNode) debugger.getInstrumenter().lookupExecutionEventNode(iNode, binding);
if (node != null && node.isActiveAt(suspendAnchor)) {
nodes.add(node);
synchronized (allBindings) {
// allBindings is a synchronized set, but we still need to synchronize
// iteration against manipulations, to avoid ConcurrentModificationExceptions
for (EventBinding<?> binding : allBindings) {
DebuggerNode node = (DebuggerNode) debugger.getInstrumenter().lookupExecutionEventNode(iNode, binding);
if (node != null && node.isActiveAt(suspendAnchor)) {
nodes.add(node);
}
}
}
return nodes;
Expand Down

0 comments on commit dde2dcc

Please sign in to comment.