Skip to content

Commit 8a64595

Browse files
author
Doug Simon
committed
8346282: [JVMCI] Add failure reason support to UnresolvedJava/Type/Method/Field
Reviewed-by: never, yzheng
1 parent 725079b commit 8a64595

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,10 @@ public JavaField lookupField(int rawIndex, ResolvedJavaMethod method, int opcode
798798
HotSpotResolvedObjectTypeImpl resolvedHolder;
799799
try {
800800
resolvedHolder = compilerToVM().resolveFieldInPool(this, rawIndex, (HotSpotResolvedJavaMethodImpl) method, (byte) opcode, info);
801-
} catch (Throwable t) {
802-
resolvedHolder = null;
801+
} catch (Throwable cause) {
802+
return new UnresolvedJavaField(fieldHolder, lookupUtf8(getNameRefIndexAt(nameAndTypeIndex)), type, cause);
803803
}
804804
if (resolvedHolder == null) {
805-
// There was an exception resolving the field or it returned null so return an unresolved field.
806805
return new UnresolvedJavaField(fieldHolder, lookupUtf8(getNameRefIndexAt(nameAndTypeIndex)), type);
807806
}
808807
final int flags = info[0];

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaField.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,10 +31,27 @@ public final class UnresolvedJavaField implements JavaField {
3131
private final JavaType holder;
3232
private final JavaType type;
3333

34-
public UnresolvedJavaField(JavaType holder, String name, JavaType type) {
34+
/**
35+
* The reason field resolution failed. Can be null.
36+
*/
37+
private final Throwable cause;
38+
39+
public UnresolvedJavaField(JavaType holder, String name, JavaType type, Throwable cause) {
3540
this.name = name;
3641
this.type = type;
3742
this.holder = holder;
43+
this.cause = cause;
44+
}
45+
46+
public UnresolvedJavaField(JavaType holder, String name, JavaType type) {
47+
this(holder, name, type, null);
48+
}
49+
50+
/**
51+
* Gets the exception, if any, representing the reason field resolution resulted in this object.
52+
*/
53+
public Throwable getCause() {
54+
return cause;
3855
}
3956

4057
@Override

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaMethod.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,10 +31,27 @@ public final class UnresolvedJavaMethod implements JavaMethod {
3131
private final Signature signature;
3232
protected JavaType holder;
3333

34-
public UnresolvedJavaMethod(String name, Signature signature, JavaType holder) {
34+
/**
35+
* The reason method resolution failed. Can be null.
36+
*/
37+
private final Throwable cause;
38+
39+
public UnresolvedJavaMethod(String name, Signature signature, JavaType holder, Throwable cause) {
3540
this.name = name;
3641
this.holder = holder;
3742
this.signature = signature;
43+
this.cause = cause;
44+
}
45+
46+
public UnresolvedJavaMethod(String name, Signature signature, JavaType holder) {
47+
this(name, signature, holder, null);
48+
}
49+
50+
/**
51+
* Gets the exception, if any, representing the reason method resolution resulted in this object.
52+
*/
53+
public Throwable getCause() {
54+
return cause;
3855
}
3956

4057
@Override

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaType.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,34 +28,54 @@
2828
public final class UnresolvedJavaType implements JavaType {
2929
private final String name;
3030

31+
/**
32+
* The reason type resolution failed. Can be null.
33+
*/
34+
private final Throwable cause;
35+
3136
@Override
3237
public String getName() {
3338
return name;
3439
}
3540

36-
private UnresolvedJavaType(String name) {
41+
private UnresolvedJavaType(String name, Throwable cause) {
3742
this.name = name;
43+
this.cause = cause;
3844
assert name.length() == 1 && JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0)) != null || name.charAt(0) == '[' || name.charAt(name.length() - 1) == ';' : name;
3945
}
4046

4147
/**
4248
* Creates an unresolved type for a valid {@link JavaType#getName() type name}.
4349
*/
4450
public static UnresolvedJavaType create(String name) {
45-
return new UnresolvedJavaType(name);
51+
return new UnresolvedJavaType(name, null);
52+
}
53+
54+
/**
55+
* Creates an unresolved type for a valid {@link JavaType#getName() type name}.
56+
*/
57+
public static UnresolvedJavaType create(String name, Throwable cause) {
58+
return new UnresolvedJavaType(name, cause);
59+
}
60+
61+
/**
62+
* Gets the exception, if any, representing the reason type resolution resulted in this object.
63+
*/
64+
public Throwable getCause() {
65+
return cause;
4666
}
4767

4868
@Override
4969
public JavaType getComponentType() {
5070
if (getName().charAt(0) == '[') {
51-
return new UnresolvedJavaType(getName().substring(1));
71+
return new UnresolvedJavaType(getName().substring(1), null);
5272
}
5373
return null;
5474
}
5575

5676
@Override
5777
public JavaType getArrayClass() {
58-
return new UnresolvedJavaType('[' + getName());
78+
return new UnresolvedJavaType('[' + getName(), null);
5979
}
6080

6181
@Override

0 commit comments

Comments
 (0)