Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-61443] [GR-61549] Fix which resolution errors are remembered in the constant pool. #10606

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.oracle.truffle.espresso.classfile.ConstantPool.Tag;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Validation;
import com.oracle.truffle.espresso.classfile.descriptors.ValidationException;

/**
Expand All @@ -40,10 +39,6 @@ static ImmutableClassConstant create(int classNameIndex) {
return new Index(classNameIndex);
}

static ImmutableClassConstant withString(Symbol<Name> name) {
return new WithString(name);
}

@Override
default Tag tag() {
return Tag.CLASS;
Expand Down Expand Up @@ -93,30 +88,4 @@ public void dump(ByteBuffer buf) {
buf.putChar(classNameIndex);
}
}

final class WithString implements ImmutableClassConstant, Resolvable {
private final Symbol<Name> name;

WithString(Symbol<Name> name) {
this.name = name;
}

@Override
public Symbol<Name> getName(ConstantPool pool) {
return name;
}

@Override
public void validate(ConstantPool pool) throws ValidationException {
// No UTF8 entry: cannot cache validation.
if (!Validation.validModifiedUTF8(name) || !Validation.validClassNameEntry(name)) {
throw ValidationException.raise("Invalid class name entry: " + name);
}
}

@Override
public void dump(ByteBuffer buf) {
buf.putChar((char) 0);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,24 +22,21 @@
*/
package com.oracle.truffle.espresso.constantpool;

import com.oracle.truffle.espresso.classfile.constantpool.Resolvable;
import com.oracle.truffle.espresso.runtime.EspressoException;

public final class CallSiteLinkingFailure extends RuntimeException {
private static final long serialVersionUID = 2567495832103023693L;

public final EspressoException cause;

public CallSiteLinkingFailure(EspressoException cause) {
this.cause = cause;
public abstract class AbstractFailedConstant extends AbstractStickyFailure implements Resolvable.ResolvedConstant {
public AbstractFailedConstant(EspressoException failure) {
super(failure);
}

public FailInvokeDynamicConstant failConstant() {
return new FailInvokeDynamicConstant(cause);
@Override
public final Object value() {
throw fail();
}

@Override
@SuppressWarnings("sync-override")
public Throwable fillInStackTrace() {
return this;
public boolean isSuccess() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.espresso.constantpool;

import com.oracle.truffle.espresso.impl.ObjectKlass;
import com.oracle.truffle.espresso.meta.Meta;
import com.oracle.truffle.espresso.runtime.EspressoException;
import com.oracle.truffle.espresso.runtime.staticobject.StaticObject;

public abstract class AbstractStickyFailure {
private final EspressoException originalWrappedException;

public AbstractStickyFailure(EspressoException failure) {
assert failure.getGuestException().getKlass().getMeta().java_lang_LinkageError.isAssignableFrom(failure.getGuestException().getKlass());
originalWrappedException = failure;
}

public EspressoException fail() {
StaticObject originalException = originalWrappedException.getGuestException();
ObjectKlass exceptionType = (ObjectKlass) originalException.getKlass();
if (StaticObject.isNull(exceptionType.getDefiningClassLoader())) {
StaticObject message = EspressoException.getGuestMessage(originalException);
StaticObject cause = EspressoException.getGuestCause(originalException);
StaticObject exception;
if (StaticObject.notNull(message)) {
exception = Meta.initExceptionWithMessage(exceptionType, message);
} else {
exception = Meta.initException(exceptionType);
}
Meta meta = exceptionType.getMeta();
if (StaticObject.notNull(cause)) {
meta.java_lang_Throwable_initCause.invokeDirectVirtual(exception, cause);
}
throw meta.throwException(exception);
} else {
throw originalWrappedException;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,42 +22,8 @@
*/
package com.oracle.truffle.espresso.constantpool;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Type;
import com.oracle.truffle.espresso.impl.Method;
import com.oracle.truffle.espresso.runtime.staticobject.StaticObject;

public final class CallSiteLink {
private final Method method;
private final int bci;
final StaticObject memberName;
final StaticObject unboxedAppendix;

@CompilationFinal(dimensions = 1) //
final Symbol<Type>[] parsedSignature;

public CallSiteLink(Method method, int bci, StaticObject memberName, StaticObject unboxedAppendix, Symbol<Type>[] parsedSignature) {
this.method = method;
this.bci = bci;
this.memberName = memberName;
this.unboxedAppendix = unboxedAppendix;
this.parsedSignature = parsedSignature;
}

public StaticObject getMemberName() {
return memberName;
}

public StaticObject getUnboxedAppendix() {
return unboxedAppendix;
}

public Symbol<Type>[] getParsedSignature() {
return parsedSignature;
}

public boolean matchesCallSite(Method siteMethod, int siteBci) {
return bci == siteBci && method == siteMethod;
}
public sealed interface CallSiteLink permits FailedCallSiteLink, SuccessfulCallSiteLink {
boolean matchesCallSite(Method siteMethod, int siteBci);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,33 +22,21 @@
*/
package com.oracle.truffle.espresso.constantpool;

import java.nio.ByteBuffer;
import java.util.Objects;
import com.oracle.truffle.espresso.impl.Method;
import com.oracle.truffle.espresso.runtime.EspressoException;

import com.oracle.truffle.espresso.classfile.constantpool.ClassConstant;
import com.oracle.truffle.espresso.classfile.constantpool.Resolvable;
import com.oracle.truffle.espresso.impl.Klass;
public final class FailedCallSiteLink extends AbstractStickyFailure implements CallSiteLink {
private final Method method;
private final int bci;

/**
* Constant Pool patching inserts already resolved constants in the constant pool. However, at the
* time of patching, we do not have a Runtime CP. Therefore, we help the CP by inserting a
* Pre-Resolved constant.
* <p>
* This is also used to Pre-resolve anonymous classes.
*/
public final class PreResolvedClassConstant implements ClassConstant, Resolvable {
private final Klass resolved;

PreResolvedClassConstant(Klass resolved) {
this.resolved = Objects.requireNonNull(resolved);
}

public Klass getResolved() {
return resolved;
public FailedCallSiteLink(Method method, int bci, EspressoException failure) {
super(failure);
this.method = method;
this.bci = bci;
}

@Override
public void dump(ByteBuffer buf) {
buf.putChar((char) 0);
public boolean matchesCallSite(Method siteMethod, int siteBci) {
return bci == siteBci && method == siteMethod;
}
}
Loading