Skip to content

Commit 56bf7be

Browse files
[GR-56009] Use stable lambda names in native image debug info.
PullRequest: graal/18404
2 parents cecd104 + 9563e1b commit 56bf7be

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2023, 2023, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -54,7 +54,6 @@
5454
import com.oracle.svm.hosted.c.info.SizableInfo;
5555
import com.oracle.svm.hosted.c.info.StructFieldInfo;
5656
import com.oracle.svm.hosted.c.info.StructInfo;
57-
import com.oracle.svm.hosted.lambda.LambdaSubstitutionType;
5857
import com.oracle.svm.hosted.meta.HostedField;
5958
import com.oracle.svm.hosted.meta.HostedMetaAccess;
6059
import com.oracle.svm.hosted.meta.HostedMethod;
@@ -171,12 +170,13 @@ protected static ResolvedJavaType getDeclaringClass(HostedField hostedField, boo
171170
}
172171

173172
protected static ResolvedJavaType getOriginal(HostedType hostedType) {
174-
/* partially unwrap then traverse through substitutions to the original */
173+
/*
174+
* partially unwrap then traverse through substitutions to the original. We don't want to
175+
* get the original type of LambdaSubstitutionType to keep the stable name
176+
*/
175177
ResolvedJavaType javaType = hostedType.getWrapped().getWrapped();
176178
if (javaType instanceof SubstitutionType) {
177179
return ((SubstitutionType) javaType).getOriginal();
178-
} else if (javaType instanceof LambdaSubstitutionType) {
179-
return ((LambdaSubstitutionType) javaType).getOriginal();
180180
} else if (javaType instanceof InjectedFieldsType) {
181181
return ((InjectedFieldsType) javaType).getOriginal();
182182
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/debug/helper/PrettyPrinterTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
*/
2525
package com.oracle.svm.test.debug.helper;
2626

27-
import com.oracle.svm.core.NeverInline;
28-
2927
import java.util.ArrayList;
3028
import java.util.HashMap;
3129
import java.util.List;
3230
import java.util.Map;
31+
import java.util.function.Function;
32+
33+
import com.oracle.svm.core.NeverInline;
3334

3435
public class PrettyPrinterTest {
3536

@@ -135,6 +136,12 @@ static void testHashMap(HashMap<String, String> strMap, Map<Object, Object> mixe
135136
System.out.print("");
136137
}
137138

139+
@SuppressWarnings("unused")
140+
@NeverInline("For testing purposes")
141+
static void testLambda(Function<String, String> lambda) {
142+
System.out.print("");
143+
}
144+
138145
static ExampleClass setupExampleObject(boolean recursive) {
139146
ExampleClass example = new ExampleClass();
140147
example.f10 = new ExampleClass(10, 20, (short) 30, '\40', (byte) 50, true, "60", Day.Sunday, new Object(), null);
@@ -163,5 +170,7 @@ public static void main(String[] args) {
163170
testArrayList(new ArrayList<>(List.of("this", "is", "a", "string", "list")), new ArrayList<>(List.of(1, 2L, "string")), nullList);
164171
testHashMap(new HashMap<>(Map.of("this", "one", "is", "two", "a", "three", "string", "four", "list", "five")),
165172
new HashMap<>(Map.of(1, new ExampleClass(), 2L, "string", (byte) 3, new ArrayList<>())));
173+
174+
testLambda(str -> str);
166175
}
167176
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def gdb_output(var: str, output_format: str = None) -> str:
7878
return gdb_execute('output{} {}'.format("" if output_format is None else "/" + output_format, var))
7979

8080

81+
def gdb_print_type(t: str) -> str:
82+
logger.info(f'Print type {t}')
83+
return gdb_execute(f'ptype {t}')
84+
85+
8186
def gdb_print(var: str, output_format: str = None) -> str:
8287
logger.info(f'Print variable {var}')
8388
return gdb_execute('print{} {}'.format("" if output_format is None else "/" + output_format, var))

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,20 @@ def test_mixed_hash_map(self):
377377
self.assertIn('[3] = java.util.ArrayList(0) = {...}', exec_string)
378378
self.assertTrue(exec_string.endswith('}'))
379379

380+
def test_lambda_type(self):
381+
gdb_set_breakpoint("com.oracle.svm.test.debug.helper.PrettyPrinterTest::testLambda")
382+
gdb_run()
383+
type_name = gdb_output("(('java.lang.Object' *)lambda).hub.name").strip('"') # strip enclosing quotes
384+
try:
385+
exec_string = gdb_print_type(f"'{type_name}'")
386+
print(type_name)
387+
print(exec_string)
388+
self.assertFalse(exec_string.startswith('No symbol'), "Lambda runtime type names do not match lambda type symbol names")
389+
self.assertTrue(exec_string.startswith(f'type = class {type_name}'), f"GDB output: '{exec_string}'")
390+
self.assertIn('java.lang.Object * apply(java.lang.Object *);', exec_string) # check for function
391+
except Exception:
392+
self.fail("Lambda runtime type names do not match lambda type symbol names")
393+
380394

381395
# redirect unittest output to terminal
382396
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.__stdout__))

0 commit comments

Comments
 (0)