Skip to content

Commit 09773da

Browse files
committed
GH-628 added support for new location using EnterpriseLayout
1 parent 41dceaf commit 09773da

File tree

1 file changed

+76
-1
lines changed
  • visualvm/heapviewer.truffle/src/org/graalvm/visualvm/heapviewer/truffle/dynamicobject

1 file changed

+76
-1
lines changed

visualvm/heapviewer.truffle/src/org/graalvm/visualvm/heapviewer/truffle/dynamicobject/DynamicObject.java

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class DynamicObject extends TruffleObject.InstanceBased {
5858
private static final String ENTERPRISE_PACKAGE = "com.oracle.truffle.object.enterprise"; // NOI18N
5959
private static final String ENTERPRISE_LOCATION_TOP_CLASS = ENTERPRISE_PACKAGE+".EnterpriseLocations"; // NOI18N
6060
private static final String ENTERPRISE_FIELD_LOCATION_FQN = ENTERPRISE_LOCATION_TOP_CLASS+"$FieldLocation"; // NOI18N
61+
private static final String ENTERPRISE_FIELD_INFO_FQN = ENTERPRISE_PACKAGE + ".EnterpriseLayout$FieldInfo"; // NOI18N
6162
private static final String PROPERTY_MAP_FQN = "com.oracle.truffle.object.ConsListPropertyMap"; // NOI18N
6263
private static final String TRIE_PROPERTY_MAP_FQN = "com.oracle.truffle.object.TriePropertyMap"; // NOI18N
6364
private static final String PROPERTY_FQN = "com.oracle.truffle.object.PropertyImpl"; // NOI18N
@@ -434,6 +435,24 @@ private static boolean isEterpriseFieldLocationObjSubClass(Instance dynObj) {
434435
return isSubClassOf(dynObj, ENTERPRISE_FIELD_LOCATION_FQN);
435436
}
436437

438+
private static boolean isEterpriseFieldInfoObjSubClass(Instance dynObj) {
439+
if (dynObj != null)
440+
return ENTERPRISE_FIELD_INFO_FQN.equals(dynObj.getJavaClass().getName());
441+
return false;
442+
}
443+
444+
private static boolean hasFieldInfo(Instance loc) {
445+
for (FieldValue fv : loc.getFieldValues()) {
446+
if (fv instanceof ObjectFieldValue) {
447+
Instance fi = ((ObjectFieldValue)fv).getInstance();
448+
if (isEterpriseFieldInfoObjSubClass(fi)) {
449+
return true;
450+
}
451+
}
452+
}
453+
return false;
454+
}
455+
437456
private static class Property implements Field {
438457

439458
Instance property;
@@ -874,6 +893,31 @@ private FieldValue getObfuscatedEnperpriseValue(Instance loc, String className,
874893
return getObfuscatedEnterpriseFieldLocation(dynamicObject, loc, locIndex, locType, locAllowInt);
875894
}
876895
}
896+
if (hasFieldInfo(loc)) {
897+
Integer locIndex = null;
898+
Instance finfo = null;
899+
Boolean locAllowInt = null;
900+
901+
for (Object obj : fields) {
902+
FieldValue fv = (FieldValue) obj;
903+
Field f = fv.getField();
904+
String typeName = f.getType().getName();
905+
906+
if ("object".equals(typeName)) { // NOI18N
907+
Instance val = ((ObjectFieldValue)fv).getInstance();
908+
if (isEterpriseFieldInfoObjSubClass(val)) {
909+
finfo = val;
910+
}
911+
} else if ("boolean".equals(typeName) && fields.size()==3 && f.getDeclaringClass().getSubClasses().size()==1) {
912+
locAllowInt = (Boolean) loc.getValueOfField(f.getName());
913+
} else if ("int".equals(typeName)) { // NOI18N
914+
locIndex = (Integer) loc.getValueOfField(f.getName());
915+
}
916+
}
917+
if (locIndex != null && finfo != null) {
918+
return getObfuscatedEnterpriseFieldLocation(dynamicObject, loc, locIndex, finfo, locAllowInt);
919+
}
920+
}
877921
if (fields.size() >= 2) {
878922
// ArrayLocation
879923
Integer locIndex = null;
@@ -932,7 +976,29 @@ private FieldValue getObfuscatedEnterpriseArrayLocation(Instance dynamicObject,
932976
return null;
933977
}
934978

935-
private FieldValue getObfuscatedEnterpriseFieldLocation(Instance dynamicObject, Instance loc, Integer index, Instance type, Boolean allowInt) {
979+
private FieldValue getObfuscatedEnterpriseFieldLocation(Instance dynamicObject, Instance loc, Integer index, Instance field_type, Boolean allowInt) {
980+
Instance type = field_type;
981+
if (isEterpriseFieldInfoObjSubClass(field_type)) {
982+
String fieldName = null;
983+
JavaClass fieldType = null;
984+
for (FieldValue fv : field_type.getFieldValues()) {
985+
if (fv instanceof ObjectFieldValue) {
986+
Instance val = ((ObjectFieldValue)fv).getInstance();
987+
if (val == null) continue;
988+
String valName = val.getJavaClass().getName();
989+
if (valName.equals(String.class.getName())) {
990+
fieldName = DetailsSupport.getDetailsString(val);
991+
} else if ("tclass".equals(fv.getField().getName())) {
992+
type = val;
993+
} else if (valName.equals(Class.class.getName())) {
994+
fieldType = val.getJavaClass().getHeap().getJavaClassByID(val.getInstanceId());
995+
}
996+
}
997+
}
998+
assert type.getInstanceId() == dynamicObject.getJavaClass().getJavaClassId();
999+
if (fieldName != null)
1000+
return getDynamicObjectField(dynamicObject, fieldName, fieldType);
1001+
}
9361002
if (type != null) { // TypedObjectFieldLocation
9371003
if (index.intValue() == 0) { // test for type Object[]
9381004
long typeClassId = type.getInstanceId(); // NOI18N
@@ -996,6 +1062,15 @@ private boolean isLayoutObjectArrayLocation(Instance location, JavaClass valueCl
9961062
return false;
9971063
}
9981064

1065+
private FieldValue getDynamicObjectField(Instance dynamicObject, String fname, JavaClass fieldType) {
1066+
for (FieldValue fv : dynamicObject.getFieldValues()) {
1067+
if (fv.getField().getName().equals(fname)) {
1068+
return createFieldValue(dynamicObject, fv);
1069+
}
1070+
}
1071+
throw new IllegalArgumentException(fname);
1072+
}
1073+
9991074
private FieldValue getDynamicObjectPrimitiveField(Instance dynamicObject, int index) {
10001075
return getDynamicObjectField(dynamicObject, index, false);
10011076
}

0 commit comments

Comments
 (0)