package org.graalvm.compiler.hotspot.stubs;
import org.graalvm.compiler.api.replacements.Snippet;
import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
import org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil;
import org.graalvm.compiler.hotspot.word.KlassPointer;
import org.graalvm.compiler.options.OptionValues;
import jdk.vm.ci.code.Register;
public class ClassCastExceptionStub extends CreateExceptionStub {
public ClassCastExceptionStub(OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) {
super("createClassCastException", options, providers, linkage);
}
@Override
protected Object getConstantParameterValue(int index, String name) {
GraalError.guarantee(index == 2, "unknown parameter %s at index %d", name, index);
return providers.getRegisters().getThreadRegister();
}
@Snippet
private static Object createClassCastException(@Snippet.NonNullParameter Object object, KlassPointer targetKlass, @ConstantParameter Register threadRegister) {
KlassPointer objKlass = HotSpotReplacementsUtil.loadHub(object);
return createException(threadRegister, ClassCastException.class, objKlass, targetKlass);
}
}