Skip to content

Commit 1a128ea

Browse files
Bugfixes after rebase
1 parent 1662eac commit 1a128ea

File tree

8 files changed

+57
-57
lines changed

8 files changed

+57
-57
lines changed

substratevm/debug/gdbpy/gdb-debughelpers.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,6 @@ def is_reachable(cls, this: hex, other: hex) -> bool:
158158
# create a flat list of all ancestors of each tested node
159159
test_nodes = [parent for node in test_nodes for parent in cls.parents.get(node, [])]
160160

161-
@classmethod
162-
def is_compressed(cls, t: gdb.Type) -> bool:
163-
type_name = cls.get_basic_type(t).name
164-
if type_name is None:
165-
# fallback to the GDB type printer for t
166-
type_name = str(t)
167-
# compressed types from a different classLoader have the format <loader_name>::_z_.<type_name>
168-
result = type_name.startswith(cls.compressed_ref_prefix) or ('::' + cls.compressed_ref_prefix) in type_name
169-
trace(f'<SVMUtil> - is_compressed({type_name}) = {result}')
170-
return result
171-
172161
@classmethod
173162
def is_primitive(cls, t: gdb.Type) -> bool:
174163
result = cls.get_basic_type(t).is_scalar
@@ -236,7 +225,7 @@ def __init__(self):
236225
self.object_type = gdb.lookup_type("java.lang.Object")
237226
self.object_header_type = gdb.lookup_type("_objhdr")
238227
self.stack_type = gdb.lookup_type("long")
239-
self.hub_type = gdb.lookup_type("java.lang.Class")
228+
self.hub_type = gdb.lookup_type("Encoded$Dynamic$Hub")
240229
self.classloader_type = gdb.lookup_type("java.lang.ClassLoader")
241230
self.wrapper_types = [gdb.lookup_type(f'java.lang.{x}') for x in
242231
["Byte", "Short", "Integer", "Long", "Float", "Double", "Boolean", "Character"]
@@ -267,9 +256,24 @@ def get_adr(self, obj: gdb.Value) -> int:
267256
def is_null(self, obj: gdb.Value) -> bool:
268257
return self.get_adr(obj) == 0
269258

259+
def is_compressed(self, t: gdb.Type) -> bool:
260+
# for the hub type we always want handle it as compressed as there is no clear distinction in debug info for
261+
# the hub field, and it may always have an expression in the type's data_location attribute
262+
if self.get_basic_type(t) == self.hub_type:
263+
return True
264+
265+
type_name = self.get_basic_type(t).name
266+
if type_name is None:
267+
# fallback to the GDB type printer for t
268+
type_name = str(t)
269+
# compressed types from a different classLoader have the format <loader_name>::_z_.<type_name>
270+
result = type_name.startswith(self.compressed_ref_prefix) or ('::' + self.compressed_ref_prefix) in type_name
271+
trace(f'<SVMUtil> - is_compressed({type_name}) = {result}')
272+
return result
273+
270274
def get_compressed_oop(self, obj: gdb.Value) -> int:
271275
# use compressed ref if available - only compute it if necessary
272-
if obj.type.code == gdb.TYPE_CODE_PTR and SVMUtil.is_compressed(obj.type):
276+
if obj.type.code == gdb.TYPE_CODE_PTR and self.is_compressed(obj.type):
273277
return int(obj)
274278

275279
obj_adr = self.get_adr(obj)
@@ -279,7 +283,7 @@ def get_compressed_oop(self, obj: gdb.Value) -> int:
279283
# recreate compressed oop from the object address
280284
# this reverses the uncompress expression from
281285
# com.oracle.objectfile.elf.dwarf.DwarfInfoSectionImpl#writeIndirectOopConversionExpression
282-
is_hub = self.get_basic_type(obj) == self.hub_type
286+
is_hub = self.get_basic_type(obj.type) == self.hub_type
283287
compression_shift = self.compression_shift
284288
num_reserved_bits = int.bit_count(self.reserved_bits_mask)
285289
num_alignment_bits = int.bit_count(self.object_alignment - 1)
@@ -299,7 +303,7 @@ def get_compressed_oop(self, obj: gdb.Value) -> int:
299303
return compressed_oop
300304

301305
def adr_str(self, obj: gdb.Value) -> str:
302-
if not svm_print_address.absolute_adr and SVMUtil.is_compressed(obj.type):
306+
if not svm_print_address.absolute_adr and self.is_compressed(obj.type):
303307
result = f' @z({hex(self.get_compressed_oop(obj))})'
304308
else:
305309
result = f' @({hex(self.get_adr(obj))})'
@@ -375,7 +379,7 @@ def get_java_string(self, obj: gdb.Value, gdb_output_string: bool = False) -> st
375379

376380
def get_hub_field(self, obj: gdb.Value) -> gdb.Value:
377381
try:
378-
return obj.cast(self.object_header_type)[self.hub_field_name]
382+
return self.cast_to(obj, self.object_header_type)[self.hub_field_name]
379383
except gdb.error:
380384
return self.null
381385

@@ -472,7 +476,7 @@ def get_rtt(self, obj: gdb.Value) -> gdb.Type:
472476
else:
473477
rtt = gdb.lookup_type(rtt_name)
474478

475-
if SVMUtil.is_compressed(obj.type) and not SVMUtil.is_compressed(rtt):
479+
if self.is_compressed(obj.type) and not self.is_compressed(rtt):
476480
rtt = self.get_compressed_type(rtt)
477481

478482
trace(f'<SVMUtil> - get_rtt({hex(self.get_adr(obj))}) = {rtt_name}')
@@ -483,7 +487,7 @@ def cast_to(self, obj: gdb.Value, t: gdb.Type) -> gdb.Value:
483487
return obj
484488

485489
# get objects address, take care of compressed oops
486-
if SVMUtil.is_compressed(t):
490+
if self.is_compressed(t):
487491
obj_oop = self.get_compressed_oop(obj)
488492
else:
489493
obj_oop = self.get_adr(obj)
@@ -501,7 +505,7 @@ def get_uncompressed_type(self, t: gdb.Type) -> gdb.Type:
501505
# compressed types only exist for java type which are either struct or union
502506
if t.code != gdb.TYPE_CODE_STRUCT and t.code != gdb.TYPE_CODE_UNION:
503507
return t
504-
result = self.get_base_class(t) if SVMUtil.is_compressed(t) else t
508+
result = self.get_base_class(t) if (self.is_compressed(t) and t != self.hub_type) else t
505509
trace(f'<SVMUtil> - get_uncompressed_type({t}) = {result}')
506510
return result
507511

@@ -546,7 +550,7 @@ def get_compressed_type(self, t: gdb.Type) -> gdb.Type:
546550
t = SVMUtil.get_basic_type(t)
547551
# compressed types only exist for java types which are either struct or union
548552
# do not compress types that already have the compressed prefix
549-
if not self.is_java_type(t) or SVMUtil.is_compressed(t):
553+
if not self.is_java_type(t) or self.is_compressed(t):
550554
return t
551555

552556
type_name = t.name
@@ -688,7 +692,7 @@ def children(self) -> Iterable[object]:
688692
trace('<SVMPPClass> - children (class field iterator)')
689693
if self.__skip_children:
690694
return
691-
fields = [str(f.name) for f in SVMUtil.get_all_fields(self.__obj.type, svm_print_static_fields.value) if f.name != SVMUtil.hub_field_name]
695+
fields = [str(f.name) for f in SVMUtil.get_all_fields(self.__obj.type, svm_print_static_fields.value) if f.parent_type != self.__svm_util.object_header_type]
692696
for index, f in enumerate(fields):
693697
trace(f'<SVMPPClass> - children: field "{f}"')
694698
# apply custom limit only for java objects
@@ -1343,7 +1347,7 @@ def cast_to_rtt(self, obj: gdb.Value, obj_str: str) -> tuple: # tuple[gdb.Value
13431347
if static_type.name == rtt.name:
13441348
return obj, obj_str
13451349
else:
1346-
obj_oop = self.svm_util.get_compressed_oop(obj) if SVMUtil.is_compressed(rtt) else self.svm_util.get_adr(obj)
1350+
obj_oop = self.svm_util.get_compressed_oop(obj) if self.svm_util.is_compressed(rtt) else self.svm_util.get_adr(obj)
13471351
return obj, f"(('{rtt.name}' *)({obj_oop}))"
13481352

13491353
# Define the token specifications
@@ -1389,6 +1393,7 @@ def check(self, expected: str):
13891393
raise RuntimeError(f"{expected} expected after {self.expr[:self.t.end]} but got {self.sym}")
13901394

13911395
def parse(self, completion: bool = False) -> str:
1396+
self.svm_util = SVMUtil()
13921397
self.scan()
13931398
if self.sym == "" and completion:
13941399
raise self.AutoComplete(gdb.COMPLETE_EXPRESSION)
@@ -1539,7 +1544,7 @@ def params(self, completion: bool = False) -> str:
15391544
obj_str += self.t.val
15401545

15411546
obj = gdb.parse_and_eval(obj_str) # check if gdb can handle the current param
1542-
if self.svm_util.is_java_type(obj.type) and SVMUtil.is_compressed(obj.type):
1547+
if self.svm_util.is_java_type(obj.type) and self.svm_util.is_compressed(obj.type):
15431548
# uncompress compressed java params
15441549
obj_str = f"(('{self.svm_util.get_uncompressed_type(SVMUtil.get_basic_type(obj.type)).name}' *)({self.svm_util.get_adr(obj)}))"
15451550
param_str += obj_str
@@ -1565,8 +1570,6 @@ def array_index(self, completion: bool = False) -> str:
15651570
return i_obj_str
15661571

15671572
def complete(self, text: str, word: str): # -> list[str] | int:
1568-
self.svm_util = SVMUtil()
1569-
15701573
if not svm_print.value:
15711574
return gdb.COMPLETE_EXPRESSION
15721575

@@ -1580,8 +1583,6 @@ def complete(self, text: str, word: str): # -> list[str] | int:
15801583
return gdb.COMPLETE_NONE
15811584

15821585
def invoke(self, arg: str, from_tty: bool) -> None:
1583-
self.svm_util = SVMUtil()
1584-
15851586
if not svm_print.value:
15861587
gdb.execute(f"print {arg}")
15871588
return

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/DebugInfoBase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public abstract class DebugInfoBase {
182182
* The name of the type for header field hub which needs special case processing to remove tag
183183
* bits.
184184
*/
185-
public static final String HUB_TYPE_NAME = "java.lang.Class";
185+
public static final String HUB_TYPE_NAME = "Encoded$Dynamic$Hub";
186186
public static final String FOREIGN_METHOD_LIST_TYPE = "Foreign$Method$List";
187187

188188
public DebugInfoBase(ByteOrder byteOrder) {
@@ -312,7 +312,6 @@ public ClassEntry lookupClassClass() {
312312
return classClass;
313313
}
314314

315-
316315
/* Accessors to query the debug info model. */
317316
public ByteOrder getByteOrder() {
318317
return byteOrder;

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/HeaderTypeEntry.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828

2929
public class HeaderTypeEntry extends StructureTypeEntry {
3030

31-
private final FieldEntry hubField;
31+
private FieldEntry hubField;
3232

33-
public HeaderTypeEntry(String typeName, int size, long typeSignature, FieldEntry hubField) {
33+
public HeaderTypeEntry(String typeName, int size, long typeSignature) {
3434
super(typeName, size, -1, typeSignature, typeSignature, typeSignature);
35+
}
36+
37+
public void setHubField(FieldEntry hubField) {
3538
this.hubField = hubField;
3639
}
3740

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfInfoSectionImpl.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ private int writeHeaderType(DebugContext context, HeaderTypeEntry headerTypeEntr
455455
writeInt(pos - lengthPos, buffer, typeOffsetPos);
456456

457457
/* Write the type representing the object header. */
458-
name = headerTypeEntry.getTypeName();
458+
name = uniqueDebugString(headerTypeEntry.getTypeName());
459459
size = hubField.getSize();
460460
log(context, " [0x%08x] header type %s", pos, name);
461461
abbrevCode = AbbrevCode.OBJECT_HEADER;
@@ -486,7 +486,7 @@ private int writeHubField(DebugContext context, FieldEntry hubFieldEntry, int hu
486486
log(context, " [0x%08x] hub field", pos);
487487
log(context, " [0x%08x] <2> Abbrev Number %d", pos, abbrevCode.ordinal());
488488
pos = writeAbbrevCode(abbrevCode, buffer, pos);
489-
String fieldName = hubFieldEntry.fieldName();
489+
String fieldName = uniqueDebugString(hubFieldEntry.fieldName());
490490
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(fieldName), fieldName);
491491
pos = writeStrSectionOffset(fieldName, buffer, pos);
492492
log(context, " [0x%08x] type 0x%x (%s)", pos, hubTypeIdx, DwarfDebugInfo.HUB_TYPE_NAME);
@@ -967,8 +967,7 @@ private int writeForeignStructLayoutTypeUnit(DebugContext context, ForeignStruct
967967
AbbrevCode abbrevCode = AbbrevCode.FOREIGN_STRUCT;
968968
log(context, " [0x%08x] <1> Abbrev Number %d", pos, abbrevCode.ordinal());
969969
pos = writeAbbrevCode(abbrevCode, buffer, pos);
970-
String typedefName = foreignStructTypeEntry.getTypedefName();
971-
typedefName = uniqueDebugString(typedefName);
970+
String typedefName = uniqueDebugString(foreignStructTypeEntry.getTypedefName());
972971
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(typedefName), typedefName);
973972
pos = writeStrSectionOffset(typedefName, buffer, pos);
974973
log(context, " [0x%08x] byte_size 0x%x", pos, size);
@@ -1022,8 +1021,9 @@ private int writeInstanceClassInfo(DebugContext context, ClassEntry classEntry,
10221021
if (name == null) {
10231022
name = classEntry.getTypeName().replace('.', '/') + ".java";
10241023
}
1024+
name = uniqueDebugString(name);
10251025
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(name), name);
1026-
pos = writeStrSectionOffset(uniqueDebugString(name), buffer, pos);
1026+
pos = writeStrSectionOffset(name, buffer, pos);
10271027
String compilationDirectory = uniqueDebugString(dwarfSections.getCachePath());
10281028
log(context, " [0x%08x] comp_dir 0x%x (%s)", pos, debugStringIndex(compilationDirectory), compilationDirectory);
10291029
pos = writeStrSectionOffset(compilationDirectory, buffer, pos);
@@ -1318,8 +1318,7 @@ private int writeMethodDeclarations(DebugContext context, ClassEntry classEntry,
13181318

13191319
private int writeMethodDeclaration(DebugContext context, ClassEntry classEntry, MethodEntry method, boolean isInlined, byte[] buffer, int p) {
13201320
int pos = p;
1321-
String methodKey = method.getSymbolName();
1322-
String linkageName = uniqueDebugString(methodKey);
1321+
String linkageName = uniqueDebugString(method.getSymbolName());
13231322
setMethodDeclarationIndex(method, pos);
13241323
int modifiers = method.getModifiers();
13251324
boolean isStatic = Modifier.isStatic(modifiers);
@@ -1409,7 +1408,7 @@ private int writeMethodParameterDeclaration(DebugContext context, LocalEntry par
14091408
int pos = p;
14101409
log(context, " [0x%08x] method parameter declaration", pos);
14111410
AbbrevCode abbrevCode;
1412-
String paramName = paramInfo.name();
1411+
String paramName = uniqueDebugString(paramInfo.name());
14131412
TypeEntry paramType = paramInfo.type();
14141413
int line = paramInfo.getLine();
14151414
if (artificial) {
@@ -1422,7 +1421,7 @@ private int writeMethodParameterDeclaration(DebugContext context, LocalEntry par
14221421
log(context, " [0x%08x] <%d> Abbrev Number %d", pos, level, abbrevCode.ordinal());
14231422
pos = writeAbbrevCode(abbrevCode, buffer, pos);
14241423
log(context, " [0x%08x] name %s", pos, paramName);
1425-
pos = writeStrSectionOffset(uniqueDebugString(paramName), buffer, pos);
1424+
pos = writeStrSectionOffset(paramName, buffer, pos);
14261425
if (abbrevCode == AbbrevCode.METHOD_PARAMETER_DECLARATION_2) {
14271426
log(context, " [0x%08x] file 0x%x", pos, fileIdx);
14281427
pos = writeAttrData2((short) fileIdx, buffer, pos);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import java.nio.file.InvalidPathException;
3636
import java.nio.file.Path;
37-
import java.nio.file.Paths;
3837
import java.util.List;
3938
import java.util.UUID;
4039
import java.util.function.Predicate;
@@ -1039,7 +1038,7 @@ public static boolean useDebugInfoGeneration() {
10391038

10401039
private static void validateDebugInfoGenerationThreadCount(HostedOptionKey<Integer> optionKey) {
10411040
int value = optionKey.getValue();
1042-
if (value <= 0) {
1041+
if (value < 0) {
10431042
throw UserError.invalidOptionValue(optionKey, value, "The value must be bigger than 0");
10441043
}
10451044
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/debug/SharedDebugInfoProvider.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public abstract class SharedDebugInfoProvider implements DebugInfoProvider {
184184
protected final int referenceSize;
185185
protected final int pointerSize;
186186
protected final int objectAlignment;
187-
protected final int reservedBitsMask;
187+
protected final int reservedHubBitsMask;
188188

189189
/**
190190
* The {@code SharedType} for {@link Class}. This is the type that represents a dynamic hub in
@@ -294,7 +294,7 @@ public SharedDebugInfoProvider(DebugContext debug, RuntimeConfiguration runtimeC
294294
this.pointerSize = ConfigurationValues.getTarget().wordSize;
295295
this.referenceSize = getObjectLayout().getReferenceSize();
296296
this.objectAlignment = getObjectLayout().getAlignment();
297-
this.reservedBitsMask = Heap.getHeap().getObjectHeader().getReservedBitsMask();
297+
this.reservedHubBitsMask = Heap.getHeap().getObjectHeader().getReservedHubBitsMask();
298298
}
299299

300300
/**
@@ -334,8 +334,8 @@ public boolean isRuntimeCompilation() {
334334
}
335335

336336
@Override
337-
public int reservedBitsMask() {
338-
return reservedBitsMask;
337+
public int reservedHubBitsMask() {
338+
return reservedHubBitsMask;
339339
}
340340

341341
@Override
@@ -754,15 +754,14 @@ private void installHeaderTypeEntry() {
754754

755755
// create the header type entry similar to a class entry without a super type
756756
ObjectLayout ol = getObjectLayout();
757+
int hubOffset = ol.getHubOffset();
757758
headerTypeEntry = new HeaderTypeEntry(typeName, ol.getFirstFieldOffset(), typeSignature);
759+
headerTypeEntry.setHubField(createSyntheticFieldEntry("hub", headerTypeEntry, hubType, hubOffset, ol.getHubSize()));
758760

759-
// add synthetic fields that hold the location of the hub and the idHash if it is in the
760-
// object header
761-
headerTypeEntry.addField(createSyntheticFieldEntry("hub", headerTypeEntry, hubType, ol.getHubOffset(), referenceSize));
762-
if (ol.isIdentityHashFieldInObjectHeader()) {
763-
int idHashSize = ol.sizeInBytes(JavaKind.Int);
764-
headerTypeEntry.addField(createSyntheticFieldEntry("idHash", headerTypeEntry, (SharedType) metaAccess.lookupJavaType(JavaKind.Int.toJavaClass()), ol.getObjectHeaderIdentityHashOffset(),
765-
idHashSize));
761+
if (hubOffset > 0) {
762+
assert hubOffset == Integer.BYTES || hubOffset == Long.BYTES;
763+
JavaKind kind = hubOffset == Integer.BYTES ? JavaKind.Int : JavaKind.Long;
764+
headerTypeEntry.addField(createSyntheticFieldEntry("reserved", headerTypeEntry, (SharedType) metaAccess.lookupJavaType(kind.toJavaClass()), 0, hubOffset));
766765
}
767766
}
768767

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ class NativeImageDebugInfoProvider extends SharedDebugInfoProvider {
128128
this.nativeLibs = nativeLibs;
129129

130130
/* Offsets need to be adjusted relative to the heap base plus partition-specific offset. */
131-
NativeImageHeap.ObjectInfo primitiveFields = heap.getObjectInfo(StaticFieldsSupport.getStaticPrimitiveFields());
132-
NativeImageHeap.ObjectInfo objectFields = heap.getObjectInfo(StaticFieldsSupport.getStaticObjectFields());
131+
NativeImageHeap.ObjectInfo primitiveFields = heap.getObjectInfo(StaticFieldsSupport.getCurrentLayerStaticPrimitiveFields());
132+
NativeImageHeap.ObjectInfo objectFields = heap.getObjectInfo(StaticFieldsSupport.getCurrentLayerStaticObjectFields());
133133
primitiveStartOffset = (int) primitiveFields.getOffset();
134134
referenceStartOffset = (int) objectFields.getOffset();
135135

@@ -381,7 +381,7 @@ protected Stream<Pair<SharedMethod, CompilationResult>> codeInfo() {
381381
*/
382382
@Override
383383
protected Stream<Object> dataInfo() {
384-
return heap.getObjects().stream().filter(obj -> obj.getPartition().getStartOffset() > 0).map(obj -> obj);
384+
return heap.getObjects().stream().filter(obj -> !obj.getPartition().isFiller()).map(obj -> obj);
385385
}
386386

387387
@Override

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/debug/helper/test_cinterface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_print_from_java_shared_libray(self):
128128
exec_string = gdb_output("data")
129129
self.assertTrue(exec_string.startswith('my_data = {'), f"GDB output: '{exec_string}'")
130130
self.assertIn('f_primitive = 42', exec_string)
131-
self.assertIn('f_array = int32_t [4] = {...}', exec_string)
131+
self.assertIn('f_array = int [4] = {...}', exec_string)
132132
self.assertRegex(exec_string, f'f_cstr = 0x{hex_rexp.pattern} "Hello World"')
133133
self.assertRegex(exec_string, f'f_java_object_handle = 0x{hex_rexp.pattern}')
134134
self.assertRegex(exec_string, f'f_print_function = 0x{hex_rexp.pattern} <c_print>')

0 commit comments

Comments
 (0)