43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.hotspot.stubs;
|
|
26 |
|
46640
|
27 |
import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.NativeCall;
|
43972
|
28 |
import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.DESTROYS_REGISTERS;
|
|
29 |
import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.SAFEPOINT;
|
|
30 |
import static org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProviderImpl.REEXECUTABLE;
|
|
31 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.clearPendingException;
|
|
32 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord;
|
49873
|
33 |
import static jdk.internal.vm.compiler.word.LocationIdentity.any;
|
43972
|
34 |
|
|
35 |
import org.graalvm.compiler.api.replacements.Fold;
|
|
36 |
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
|
|
37 |
import org.graalvm.compiler.graph.Node.ConstantNodeParameter;
|
|
38 |
import org.graalvm.compiler.graph.Node.NodeIntrinsic;
|
46640
|
39 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
43972
|
40 |
import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
|
|
41 |
import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProviderImpl;
|
|
42 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
|
|
43 |
import org.graalvm.compiler.hotspot.nodes.StubForeignCallNode;
|
|
44 |
import org.graalvm.compiler.hotspot.word.KlassPointer;
|
46344
|
45 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
46 |
import org.graalvm.compiler.replacements.nodes.CStringConstant;
|
|
47 |
import org.graalvm.compiler.word.Word;
|
|
48 |
|
|
49 |
import jdk.vm.ci.code.Register;
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Base class for stubs that create a runtime exception.
|
|
53 |
*/
|
|
54 |
public class CreateExceptionStub extends SnippetStub {
|
|
55 |
|
46344
|
56 |
protected CreateExceptionStub(String snippetMethodName, OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) {
|
|
57 |
super(snippetMethodName, options, providers, linkage);
|
43972
|
58 |
}
|
|
59 |
|
|
60 |
@Fold
|
|
61 |
static String getInternalClassName(Class<?> cls) {
|
|
62 |
return cls.getName().replace('.', '/');
|
|
63 |
}
|
|
64 |
|
|
65 |
private static Word classAsCString(Class<?> cls) {
|
|
66 |
return CStringConstant.cstring(getInternalClassName(cls));
|
|
67 |
}
|
|
68 |
|
|
69 |
protected static Object createException(Register threadRegister, Class<? extends Throwable> exception) {
|
|
70 |
Word message = null;
|
|
71 |
return createException(threadRegister, exception, message);
|
|
72 |
}
|
|
73 |
|
|
74 |
protected static Object createException(Register threadRegister, Class<? extends Throwable> exception, Word message) {
|
|
75 |
Word thread = registerAsWord(threadRegister);
|
|
76 |
throwAndPostJvmtiException(THROW_AND_POST_JVMTI_EXCEPTION, thread, classAsCString(exception), message);
|
|
77 |
return clearPendingException(thread);
|
|
78 |
}
|
|
79 |
|
|
80 |
protected static Object createException(Register threadRegister, Class<? extends Throwable> exception, KlassPointer klass) {
|
|
81 |
Word thread = registerAsWord(threadRegister);
|
|
82 |
throwKlassExternalNameException(THROW_KLASS_EXTERNAL_NAME_EXCEPTION, thread, classAsCString(exception), klass);
|
|
83 |
return clearPendingException(thread);
|
|
84 |
}
|
|
85 |
|
|
86 |
protected static Object createException(Register threadRegister, Class<? extends Throwable> exception, KlassPointer objKlass, KlassPointer targetKlass) {
|
|
87 |
Word thread = registerAsWord(threadRegister);
|
|
88 |
throwClassCastException(THROW_CLASS_CAST_EXCEPTION, thread, classAsCString(exception), objKlass, targetKlass);
|
|
89 |
return clearPendingException(thread);
|
|
90 |
}
|
|
91 |
|
|
92 |
private static final ForeignCallDescriptor THROW_AND_POST_JVMTI_EXCEPTION = new ForeignCallDescriptor("throw_and_post_jvmti_exception", void.class, Word.class, Word.class, Word.class);
|
|
93 |
private static final ForeignCallDescriptor THROW_KLASS_EXTERNAL_NAME_EXCEPTION = new ForeignCallDescriptor("throw_klass_external_name_exception", void.class, Word.class, Word.class,
|
|
94 |
KlassPointer.class);
|
|
95 |
private static final ForeignCallDescriptor THROW_CLASS_CAST_EXCEPTION = new ForeignCallDescriptor("throw_class_cast_exception", void.class, Word.class, Word.class, KlassPointer.class,
|
|
96 |
KlassPointer.class);
|
|
97 |
|
|
98 |
@NodeIntrinsic(StubForeignCallNode.class)
|
|
99 |
private static native void throwAndPostJvmtiException(@ConstantNodeParameter ForeignCallDescriptor d, Word thread, Word type, Word message);
|
|
100 |
|
|
101 |
@NodeIntrinsic(StubForeignCallNode.class)
|
|
102 |
private static native void throwKlassExternalNameException(@ConstantNodeParameter ForeignCallDescriptor d, Word thread, Word type, KlassPointer klass);
|
|
103 |
|
|
104 |
@NodeIntrinsic(StubForeignCallNode.class)
|
|
105 |
private static native void throwClassCastException(@ConstantNodeParameter ForeignCallDescriptor d, Word thread, Word type, KlassPointer objKlass, KlassPointer targetKlass);
|
|
106 |
|
|
107 |
public static void registerForeignCalls(GraalHotSpotVMConfig c, HotSpotForeignCallsProviderImpl foreignCalls) {
|
|
108 |
foreignCalls.registerForeignCall(THROW_AND_POST_JVMTI_EXCEPTION, c.throwAndPostJvmtiExceptionAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
|
|
109 |
foreignCalls.registerForeignCall(THROW_KLASS_EXTERNAL_NAME_EXCEPTION, c.throwKlassExternalNameExceptionAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
|
|
110 |
foreignCalls.registerForeignCall(THROW_CLASS_CAST_EXCEPTION, c.throwClassCastExceptionAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
|
|
111 |
}
|
|
112 |
}
|