Skip to content

Commit 0cf55b5

Browse files
committed
DebugInfo test extensions for nested inlined methods
1 parent 78c775b commit 0cf55b5

File tree

3 files changed

+186
-33
lines changed

3 files changed

+186
-33
lines changed

substratevm/mx.substratevm/testhello.py

Lines changed: 130 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -169,27 +169,28 @@ def test():
169169
# enable pretty printing of structures
170170
execute("set print pretty on")
171171
# set a break point at hello.Hello::main
172-
# expect "Breakpoint 1 at 0x[0-9a-f]+: file hello.Hello.java, line 67."
172+
# expect "Breakpoint 1 at 0x[0-9a-f]+: file hello.Hello.java, line 70."
173173
exec_string = execute("break hello.Hello::main")
174-
rexp = r"Breakpoint 1 at %s: file hello/Hello\.java, line 67\."%address_pattern
174+
rexp = r"Breakpoint 1 at %s: file hello/Hello\.java, line 70\."%address_pattern
175175
checker = Checker('break main', rexp)
176176
checker.check(exec_string)
177177

178-
# run the program
178+
# run the program till the breakpoint
179179
execute("run")
180+
execute("delete breakpoints")
180181

181182
# list the line at the breakpoint
182-
# expect "67 Greeter greeter = Greeter.greeter(args);"
183+
# expect "70 Greeter greeter = Greeter.greeter(args);"
183184
exec_string = execute("list")
184-
checker = Checker(r"list bp 1", "67%sGreeter greeter = Greeter\.greeter\(args\);"%spaces_pattern)
185+
checker = Checker(r"list bp 1", "70%sGreeter greeter = Greeter\.greeter\(args\);"%spaces_pattern)
185186
checker.check(exec_string, skip_fails=False)
186187

187188
# run a backtrace
188-
# expect "#0 hello.Hello.main(java.lang.String[] *).* at hello.Hello.java:67"
189+
# expect "#0 hello.Hello.main(java.lang.String[] *).* at hello.Hello.java:70"
189190
# expect "#1 0x[0-9a-f]+ in com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_.* at [a-z/]+/JavaMainWrapper.java:[0-9]+"
190191
exec_string = execute("backtrace")
191192
checker = Checker("backtrace hello.Hello::main",
192-
[r"#0%shello\.Hello::main\(java\.lang\.String\[\] \*\)%s at hello/Hello\.java:67"%(spaces_pattern, wildcard_pattern),
193+
[r"#0%shello\.Hello::main\(java\.lang\.String\[\] \*\)%s at hello/Hello\.java:70"%(spaces_pattern, wildcard_pattern),
193194
r"#1%s%s in com\.oracle\.svm\.core\.JavaMainWrapper::runCore%s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, address_pattern, wildcard_pattern, package_pattern),
194195
r"#2%s com\.oracle\.svm\.core\.JavaMainWrapper::run%s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, wildcard_pattern, package_pattern),
195196
r"#3%s%s in com\.oracle\.svm\.core\.code\.IsolateEnterStub::JavaMainWrapper_run_%s%s"%(spaces_pattern, address_pattern, hex_digits_pattern, wildcard_pattern)
@@ -266,14 +267,6 @@ def test():
266267
r"%s = 1000"%(wildcard_pattern))
267268
checker.check(exec_string, skip_fails=False)
268269

269-
270-
# set a break point at hello.Hello$DefaultGreeter::greet
271-
# expect "Breakpoint 2 at 0x[0-9a-f]+: file hello/Target_Hello_DefaultGreeter.java, line [0-9]+."
272-
exec_string = execute("break hello.Hello$DefaultGreeter::greet")
273-
rexp = r"Breakpoint 2 at %s: file hello/Target_hello_Hello_DefaultGreeter\.java, line %s\."%(address_pattern, digits_pattern)
274-
checker = Checker("break on substituted method", rexp)
275-
checker.check(exec_string, skip_fails=False)
276-
277270
# look up greet methods
278271
# expect "All functions matching regular expression "greet":"
279272
# expect ""
@@ -290,7 +283,7 @@ def test():
290283
r"File hello/Target_hello_Hello_DefaultGreeter\.java:",
291284
r"%svoid hello.Hello\$DefaultGreeter::greet\(void\);"%maybe_spaces_pattern]
292285
checker = Checker("info func greet", rexp)
293-
checker.check(exec_string, skip_fails=True)
286+
checker.check(exec_string)
294287

295288
# look up PrintStream.println methods
296289
# expect "All functions matching regular expression "java.io.PrintStream.println":"
@@ -303,20 +296,13 @@ def test():
303296
checker = Checker("info func java.io.PrintStream::println", rexp)
304297
checker.check(exec_string)
305298

306-
# set a break point at PrintStream.println(String)
307-
# expect "Breakpoint 3 at 0x[0-9a-f]+: java.base/java/io/PrintStream.java, line [0-9]+."
308-
exec_string = execute("break java.io.PrintStream::println(java.lang.String *)")
309-
rexp = r"Breakpoint 3 at %s: file .*java/io/PrintStream\.java, line %s\."%(address_pattern, digits_pattern)
310-
checker = Checker('break println', rexp)
311-
checker.check(exec_string, skip_fails=False)
312-
313299
# step into method call
314300
execute("step")
315301

316302
# list current line
317-
# expect "34 if (args.length == 0) {"
303+
# expect "37 if (args.length == 0) {"
318304
exec_string = execute("list")
319-
rexp = r"34%sif \(args\.length == 0\) {"%spaces_pattern
305+
rexp = r"37%sif \(args\.length == 0\) {"%spaces_pattern
320306
checker = Checker('list hello.Hello$Greeter.greeter', rexp)
321307
checker.check(exec_string, skip_fails=False)
322308

@@ -397,8 +383,8 @@ def test():
397383
# run a backtrace
398384
exec_string = execute("backtrace")
399385
checker = Checker("backtrace hello.Hello.Greeter::greeter",
400-
[r"#0%shello\.Hello\$Greeter::greeter\(java\.lang\.String\[\] \*\)%s at hello/Hello\.java:34"%(spaces_pattern, wildcard_pattern),
401-
r"#1%s%s in hello\.Hello::main\(java\.lang\.String\[\] \*\)%s at hello/Hello\.java:67"%(spaces_pattern, address_pattern, wildcard_pattern),
386+
[r"#0%shello\.Hello\$Greeter::greeter\(java\.lang\.String\[\] \*\)%s at hello/Hello\.java:37"%(spaces_pattern, wildcard_pattern),
387+
r"#1%s%s in hello\.Hello::main\(java\.lang\.String\[\] \*\)%s at hello/Hello\.java:70"%(spaces_pattern, address_pattern, wildcard_pattern),
402388
r"#2%s%s in com\.oracle\.svm\.core\.JavaMainWrapper::runCore%s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, address_pattern, wildcard_pattern, package_pattern),
403389
r"#3%scom\.oracle\.svm\.core\.JavaMainWrapper::run%s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, wildcard_pattern, package_pattern),
404390
r"#4%s%s in com\.oracle\.svm\.core\.code\.IsolateEnterStub::JavaMainWrapper_run_%s%s"%(spaces_pattern, address_pattern, hex_digits_pattern, wildcard_pattern)
@@ -421,16 +407,35 @@ def test():
421407
print(checker)
422408
sys.exit(1)
423409

424-
# continue to next 2 breakpoints
425-
execute("continue")
410+
# set breakpoint at substituted method hello.Hello$DefaultGreeter::greet
411+
# expect "Breakpoint 2 at 0x[0-9a-f]+: file hello/Target_Hello_DefaultGreeter.java, line [0-9]+."
412+
exec_string = execute("break hello.Hello$DefaultGreeter::greet")
413+
rexp = r"Breakpoint %s at %s: file hello/Target_hello_Hello_DefaultGreeter\.java, line %s\."%(digits_pattern, address_pattern, digits_pattern)
414+
checker = Checker("break on substituted method", rexp)
415+
checker.check(exec_string, skip_fails=False)
416+
execute("delete breakpoints")
417+
418+
# set a break point at standard library PrintStream.println(String)
419+
# expect "Breakpoint 3 at 0x[0-9a-f]+: java.base/java/io/PrintStream.java, line [0-9]+."
420+
exec_string = execute("break java.io.PrintStream::println(java.lang.String *)")
421+
rexp = r"Breakpoint %s at %s: file .*java/io/PrintStream\.java, line %s\."%(digits_pattern, address_pattern, digits_pattern)
422+
checker = Checker('break println', rexp)
423+
checker.check(exec_string, skip_fails=False)
424+
426425
execute("continue")
427426

428427
# run backtrace to check we are in java.io.PrintStream::println(java.lang.String)
429428
# expect "#0 java.io.PrintStream::println(java.lang.String).* at java.base/java/io/PrintStream.java:[0-9]+"
430-
exec_string = execute("backtrace 1")
431-
checker = Checker("backtrace 1 PrintStream::println",
432-
[r"#0%sjava\.io\.PrintStream::println\(java\.lang\.String \*\)%s at %sjava/io/PrintStream.java:%s"%(spaces_pattern, wildcard_pattern, wildcard_pattern, digits_pattern)])
433-
checker.check(exec_string, skip_fails=False)
429+
exec_string = execute("backtrace 5")
430+
rexp = [r"#0%sjava\.io\.PrintStream::println\(java\.lang\.String \*\)%s at %sjava/io/PrintStream.java:%s"%(spaces_pattern, wildcard_pattern, wildcard_pattern, digits_pattern),
431+
r"#1%s%s in hello\.SubstituteHelperClass::nestedGreet\(void\) \(\) at hello/Target_hello_Hello_DefaultGreeter\.java:59"%(spaces_pattern, address_pattern),
432+
# FIXME: Ideally we should see the folloing two lines in the backtrace as well!
433+
# r"#2%s%s in hello\.SubstituteHelperClass::staticInlineGreet\(void\) \(\) at hello/Target_hello_Hello_DefaultGreeter\.java:53"%(digits_pattern, spaces_pattern, address_pattern),
434+
# r"#3%s%s in hello\.SubstituteHelperClass::inlineGreet\(void\) \(\) at hello/Target_hello_Hello_DefaultGreeter\.java:48"%(digits_pattern, spaces_pattern, address_pattern),
435+
r"#%s%s%s in hello\.Hello\$DefaultGreeter::greet\(void\) \(\) at hello/Target_hello_Hello_DefaultGreeter\.java:39"%(digits_pattern, spaces_pattern, address_pattern),
436+
r"#%s%s%s in hello\.Hello::main\(java\.lang\.String\[\] \*\) \(\) at hello/Hello\.java:70"%(digits_pattern, spaces_pattern, address_pattern)]
437+
checker = Checker("backtrace PrintStream::println", rexp)
438+
checker.check(exec_string)
434439

435440
# list current line
436441
# expect "[0-9]+ synchronized (this) {"
@@ -486,6 +491,98 @@ def test():
486491
r"%s:%s\"java.io.PrintStream.*\""%(address_pattern, spaces_pattern))
487492
checker.check(exec_string, skip_fails=False)
488493

494+
###
495+
# Tests for inlined methods
496+
###
497+
498+
# print details of Hello type
499+
exec_string = execute("ptype 'hello.Hello'")
500+
rexp = [r"type = class hello\.Hello : public java\.lang\.Object {",
501+
# ptype lists inlined methods allthrough they are not listed with info func
502+
r"%sprivate:"%spaces_pattern,
503+
r"%sstatic void inlinedCallChain\(void\);"%spaces_pattern,
504+
r"%sstatic void inlinedMethod1\(void\);"%spaces_pattern,
505+
r"%sstatic void inlinedMethod2\(void\);"%spaces_pattern,
506+
r"%spublic:"%spaces_pattern,
507+
r"%sstatic void main\(java\.lang\.String\[\] \*\);"%spaces_pattern,
508+
r"%sprivate:"%spaces_pattern,
509+
r"%sstatic void notInlinedCallChain\(void\);"%spaces_pattern,
510+
r"%sstatic void notInlinedMethod1\(void\);"%spaces_pattern,
511+
r"%sstatic void notInlinedMethod2\(void\);"%spaces_pattern,
512+
r"}"]
513+
checker = Checker('ptype NamedGreeter', rexp)
514+
checker.check(exec_string, skip_fails=False)
515+
516+
# list methods matching regural expression "nlinedMethod", inlined methods are not listed
517+
exec_string = execute("info func nlinedMethod")
518+
rexp = [r"All functions matching regular expression \"nlinedMethod\":",
519+
r"File hello/Hello\.java:",
520+
r"%svoid hello\.Hello::notInlinedMethod1\(void\);"%spaces_pattern,
521+
r"%svoid hello\.Hello::notInlinedMethod2\(void\);"%spaces_pattern]
522+
checker = Checker('ptype info func nlinedMethod', rexp)
523+
checker.check(exec_string)
524+
525+
# list inlinedMethod1 and inlinedmethod2 and check that the listing maps to the inlined code instead of the
526+
# actual code
527+
rexp = [r"104%sSystem\.out\.println\(\"3 inlined calls deep\"\);"%spaces_pattern]
528+
checker = Checker('list inlinedMethod1', rexp)
529+
checker.check(execute("list inlinedMethod1"))
530+
checker = Checker('list inlinedMethod2', rexp)
531+
checker.check(execute("list inlinedMethod2"))
532+
533+
# Set breakpoint at inlined method and step through its nested inline methods
534+
exec_string = execute("break hello.Hello::inlinedCallChain")
535+
rexp = r"Breakpoint %s at %s: file hello/Hello\.java, line 104\."%(digits_pattern, address_pattern) # TODO this should be 94 instead of 104
536+
checker = Checker('break inlinedCallChain', rexp)
537+
checker.check(exec_string, skip_fails=False)
538+
539+
execute("continue")
540+
exec_string = execute("list")
541+
rexp = r"94%sinlinedMethod1\(\);"%spaces_pattern
542+
checker = Checker('hit break at inlinedCallChain', rexp)
543+
checker.check(exec_string, skip_fails=False)
544+
execute("step")
545+
exec_string = execute("list")
546+
rexp = r"99%sinlinedMethod2\(\);"%spaces_pattern
547+
checker = Checker('step in inlinedMethod1', rexp)
548+
checker.check(exec_string, skip_fails=False)
549+
execute("step")
550+
exec_string = execute("list")
551+
rexp = r"104%sSystem.out.println\(\"3 inlined calls deep\"\);"%spaces_pattern
552+
checker = Checker('step in inlinedMethod2', rexp)
553+
checker.check(exec_string, skip_fails=False)
554+
exec_string = execute("backtrace 4")
555+
rexp = [r"#0%shello\.Hello::inlinedMethod2 \(\) at hello/Hello\.java:104"%(spaces_pattern),
556+
r"#1%shello\.Hello::inlinedMethod1 \(\) at hello/Hello\.java:99"%(spaces_pattern),
557+
r"#2%shello\.Hello::inlinedCallChain \(\) at hello/Hello\.java:94"%(spaces_pattern),
558+
r"#3%shello\.Hello::main\(java\.lang\.String\[\] \*\) \(\) at hello/Hello\.java:72"%(spaces_pattern)]
559+
checker = Checker('backtrace in inlinedMethod2', rexp)
560+
checker.check(exec_string, skip_fails=False)
561+
562+
execute("delete breakpoints")
563+
564+
# set breakpoint at not inlined method and step through its nested callees
565+
exec_string = execute("break hello.Hello::notInlinedCallChain")
566+
rexp = r"Breakpoint %s at %s: file hello/Hello\.java, line 79\."%(digits_pattern, address_pattern)
567+
checker = Checker('break notInlinedCallChain', rexp)
568+
checker.check(exec_string, skip_fails=False)
569+
570+
execute("continue")
571+
exec_string = execute("list")
572+
rexp = r"79%snotInlinedMethod1\(\);"%spaces_pattern
573+
checker = Checker('hit break at notInlinedCallChain', rexp)
574+
checker.check(exec_string, skip_fails=False)
575+
execute("step")
576+
exec_string = execute("list")
577+
rexp = r"84%snotInlinedMethod2\(\);"%spaces_pattern
578+
checker = Checker('step in notInlinedMethod1', rexp)
579+
checker.check(exec_string, skip_fails=False)
580+
execute("step")
581+
exec_string = execute("list")
582+
rexp = r"89%sSystem.out.println\(\"3 not inlined calls deep\"\);"%spaces_pattern
583+
checker = Checker('step in notInlinedMethod2', rexp)
584+
checker.check(exec_string, skip_fails=False)
585+
489586
print(execute("quit 0"))
490587

491588
test()

substratevm/src/com.oracle.svm.test/src/hello/Hello.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
// Checkstyle: stop
3030

31+
import com.oracle.svm.core.annotate.AlwaysInline;
32+
import com.oracle.svm.core.annotate.NeverInline;
33+
3134
public class Hello {
3235
public abstract static class Greeter {
3336
static Greeter greeter(String[] args) {
@@ -66,6 +69,38 @@ public void greet() {
6669
public static void main(String[] args) {
6770
Greeter greeter = Greeter.greeter(args);
6871
greeter.greet();
72+
inlinedCallChain();
73+
notInlinedCallChain();
6974
System.exit(0);
7075
}
76+
77+
@NeverInline("For testing purposes")
78+
private static void notInlinedCallChain() {
79+
notInlinedMethod1();
80+
}
81+
82+
@NeverInline("For testing purposes")
83+
private static void notInlinedMethod1() {
84+
notInlinedMethod2();
85+
}
86+
87+
@NeverInline("For testing purposes")
88+
private static void notInlinedMethod2() {
89+
System.out.println("3 not inlined calls deep");
90+
}
91+
92+
@AlwaysInline("For testing purposes")
93+
private static void inlinedCallChain() {
94+
inlinedMethod1();
95+
}
96+
97+
@AlwaysInline("For testing purposes")
98+
private static void inlinedMethod1() {
99+
inlinedMethod2();
100+
}
101+
102+
@AlwaysInline("For testing purposes")
103+
private static void inlinedMethod2() {
104+
System.out.println("3 inlined calls deep");
105+
}
71106
}

substratevm/src/com.oracle.svm.test/src/hello/Target_hello_Hello_DefaultGreeter.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
package hello;
2828

29+
import com.oracle.svm.core.annotate.AlwaysInline;
30+
import com.oracle.svm.core.annotate.NeverInline;
2931
import com.oracle.svm.core.annotate.Substitute;
3032
import com.oracle.svm.core.annotate.TargetClass;
3133

@@ -34,6 +36,25 @@ final class Target_hello_Hello_DefaultGreeter {
3436
@SuppressWarnings("static-method")
3537
@Substitute
3638
public void greet() {
39+
SubstituteHelperClass substituteHelperClass = new SubstituteHelperClass();
40+
substituteHelperClass.inlineGreet();
41+
}
42+
43+
}
44+
45+
class SubstituteHelperClass {
46+
@AlwaysInline("For testing purposes")
47+
void inlineGreet() {
48+
staticInlineGreet();
49+
}
50+
51+
@AlwaysInline("For testing purposes")
52+
private static void staticInlineGreet() {
53+
nestedGreet();
54+
}
55+
56+
@NeverInline("For testing purposes")
57+
private static void nestedGreet() {
3758
// Checkstyle: stop
3859
System.out.println("Hello, substituted world!");
3960
// Checkstyle: resume

0 commit comments

Comments
 (0)