Skip to content

Commit

Permalink
oracle/graal#1725 reproducer
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkak committed Sep 13, 2024
1 parent 267303c commit a7e2b53
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 51 deletions.
34 changes: 16 additions & 18 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
# Reproducer for native-image issue

Reproducer of https://github.com/oracle/graal/issues/1725

```
cd /tmp
git clone --branch unreachable-unresolved-code https://github.com/zakkak/issue-reproducers reproducers
git clone --branch 2024-09-13-delete-no-class-def-found https://github.com/zakkak/issue-reproducers reproducers
cd reproducers
mvn package
export JAVA_HOME=/opt/jvms/graalvm-ce-java11-22.1.0
# run with Unreachable on the classpath
$JAVA_HOME/bin/java -cp target/classes Main
java -cp target/classes Main
# run with Unreachable not on the classpath
$JAVA_HOME/bin/java \
java \
-jar target/reproducer-1.0-SNAPSHOT.jar
# generate native-image with Unreachable not on the classpath
$JAVA_HOME/bin/native-image \
--link-at-build-time \
--initialize-at-build-time=. \
native-image \
--no-fallback \
-H:+ReportExceptionStackTraces \
-jar target/reproducer-1.0-SNAPSHOT.jar
# Run the generated image
# Run binary
./reproducer-1.0-SNAPSHOT
# generate native-image with Unreachable not on the classpath and pass --report-unsupported-elements-at-runtime
native-image \
--no-fallback \
--report-unsupported-elements-at-runtime \
-H:+ReportExceptionStackTraces \
-jar target/reproducer-1.0-SNAPSHOT.jar
# Build fails
```

To generate the IGV graph for main use
```
native-image --initialize-at-build-time=. --no-fallback -H:Dump=:1 -H:MethodFilter=Main.main -jar target/reproducer-1.0-SNAPSHOT.jar
```

and render it with
```
seafoam graal_dumps/2022.06.17.16.02.27.868/SubstrateHostedCompilation-3596\[Main.main\(String\[\]\)void\].bgv:0 render
```
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
<version>22.1.0</version>
<groupId>org.graalvm.sdk</groupId>
<artifactId>nativeimage</artifactId>
<version>23.1.0</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -55,7 +55,7 @@
</filters>
<artifactSet>
<excludes>
<exclude>org.graalvm.nativeimage:*</exclude>
<exclude>org.graalvm.*:*</exclude>
<exclude>*:*:tar.gz:</exclude>
</excludes>
</artifactSet>
Expand Down
34 changes: 7 additions & 27 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
import java.util.Random;

import com.oracle.svm.core.annotate.NeverInline;
import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.TargetClass;

public class Main {

static final ClassNotFoundException CNFE;

static
{
ClassNotFoundException cnfe;

try {
Class.forName("Unreachable");
cnfe = null;
} catch (ClassNotFoundException e) {
cnfe = e;
}

CNFE = cnfe;
}

@NeverInline("I want to see the BGV")
public static void main(String[] args) {
if (unreachableIsReachable()) {
Unreachable.reached();
}

System.out.println("Hello world!");
}
}

@Delete
@TargetClass(className = "Foo")
final class Target_Foo {

private static boolean unreachableIsReachable() {
return CNFE == null;
}
}

0 comments on commit a7e2b53

Please sign in to comment.