annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java@9c4168877444
children 169f5c55704c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
19309
c386ace07981 Truffle: move unsafe access methods out of CompilerDirectives
Andreas Woess <andreas.woess@oracle.com>
parents: 19013
diff changeset
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
11279
494b818b527c Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11269
diff changeset
7 * published by the Free Software Foundation. Oracle designates this
494b818b527c Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11269
diff changeset
8 * particular file as subject to the "Classpath" exception as provided
494b818b527c Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11269
diff changeset
9 * by Oracle in the LICENSE file that accompanied this code.
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 *
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * This code is distributed in the hope that it will be useful, but WITHOUT
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 * version 2 for more details (a copy is included in the LICENSE file that
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * accompanied this code).
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 *
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License version
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 * 2 along with this work; if not, write to the Free Software Foundation,
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 *
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 * or visit www.oracle.com if you need additional information or have any
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 * questions.
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24 */
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 package com.oracle.truffle.api;
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
9313
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
27 import java.lang.annotation.*;
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 import java.util.concurrent.*;
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 /**
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 * Directives that influence the optimizations of the Truffle compiler. All of the operations have
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 * no effect when executed in the Truffle interpreter.
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 */
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11897
diff changeset
34 public final class CompilerDirectives {
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
36 public static final double LIKELY_PROBABILITY = 0.75;
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
37 public static final double UNLIKELY_PROBABILITY = 1.0 - LIKELY_PROBABILITY;
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
38
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
39 public static final double SLOWPATH_PROBABILITY = 0.0001;
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
40 public static final double FASTPATH_PROBABILITY = 1.0 - SLOWPATH_PROBABILITY;
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 /**
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 * Directive for the compiler to discontinue compilation at this code position and instead
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 * insert a transfer to the interpreter.
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 */
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 public static void transferToInterpreter() {
16535
ada0a7729b6f Truffle: introduce debug option to print the stack trace when transferring to the interpreter
Andreas Woess <andreas.woess@jku.at>
parents: 15230
diff changeset
47 if (inInterpreter()) {
ada0a7729b6f Truffle: introduce debug option to print the stack trace when transferring to the interpreter
Andreas Woess <andreas.woess@jku.at>
parents: 15230
diff changeset
48 Truffle.getRuntime().notifyTransferToInterpreter();
ada0a7729b6f Truffle: introduce debug option to print the stack trace when transferring to the interpreter
Andreas Woess <andreas.woess@jku.at>
parents: 15230
diff changeset
49 }
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 }
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 /**
12770
3e013f4512de temporary addition of CompilerDirectives.transferToInterpreterAndInvalidate()
Michael Haupt <michael.haupt@oracle.com>
parents: 12408
diff changeset
53 * Directive for the compiler to discontinue compilation at this code position and instead
3e013f4512de temporary addition of CompilerDirectives.transferToInterpreterAndInvalidate()
Michael Haupt <michael.haupt@oracle.com>
parents: 12408
diff changeset
54 * insert a transfer to the interpreter, invalidating the currently executing machine code.
3e013f4512de temporary addition of CompilerDirectives.transferToInterpreterAndInvalidate()
Michael Haupt <michael.haupt@oracle.com>
parents: 12408
diff changeset
55 */
3e013f4512de temporary addition of CompilerDirectives.transferToInterpreterAndInvalidate()
Michael Haupt <michael.haupt@oracle.com>
parents: 12408
diff changeset
56 public static void transferToInterpreterAndInvalidate() {
16535
ada0a7729b6f Truffle: introduce debug option to print the stack trace when transferring to the interpreter
Andreas Woess <andreas.woess@jku.at>
parents: 15230
diff changeset
57 if (inInterpreter()) {
ada0a7729b6f Truffle: introduce debug option to print the stack trace when transferring to the interpreter
Andreas Woess <andreas.woess@jku.at>
parents: 15230
diff changeset
58 Truffle.getRuntime().notifyTransferToInterpreter();
ada0a7729b6f Truffle: introduce debug option to print the stack trace when transferring to the interpreter
Andreas Woess <andreas.woess@jku.at>
parents: 15230
diff changeset
59 }
12770
3e013f4512de temporary addition of CompilerDirectives.transferToInterpreterAndInvalidate()
Michael Haupt <michael.haupt@oracle.com>
parents: 12408
diff changeset
60 }
3e013f4512de temporary addition of CompilerDirectives.transferToInterpreterAndInvalidate()
Michael Haupt <michael.haupt@oracle.com>
parents: 12408
diff changeset
61
3e013f4512de temporary addition of CompilerDirectives.transferToInterpreterAndInvalidate()
Michael Haupt <michael.haupt@oracle.com>
parents: 12408
diff changeset
62 /**
11269
f00c85ee46a2 Truffle: add CompilerDirectives.inInterpreter()
Andreas Woess <andreas.woess@jku.at>
parents: 10687
diff changeset
63 * Returns a boolean value indicating whether the method is executed in the interpreter.
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
64 *
11269
f00c85ee46a2 Truffle: add CompilerDirectives.inInterpreter()
Andreas Woess <andreas.woess@jku.at>
parents: 10687
diff changeset
65 * @return {@code true} when executed in the interpreter, {@code false} in compiled code.
f00c85ee46a2 Truffle: add CompilerDirectives.inInterpreter()
Andreas Woess <andreas.woess@jku.at>
parents: 10687
diff changeset
66 */
f00c85ee46a2 Truffle: add CompilerDirectives.inInterpreter()
Andreas Woess <andreas.woess@jku.at>
parents: 10687
diff changeset
67 public static boolean inInterpreter() {
f00c85ee46a2 Truffle: add CompilerDirectives.inInterpreter()
Andreas Woess <andreas.woess@jku.at>
parents: 10687
diff changeset
68 return true;
f00c85ee46a2 Truffle: add CompilerDirectives.inInterpreter()
Andreas Woess <andreas.woess@jku.at>
parents: 10687
diff changeset
69 }
f00c85ee46a2 Truffle: add CompilerDirectives.inInterpreter()
Andreas Woess <andreas.woess@jku.at>
parents: 10687
diff changeset
70
f00c85ee46a2 Truffle: add CompilerDirectives.inInterpreter()
Andreas Woess <andreas.woess@jku.at>
parents: 10687
diff changeset
71 /**
15230
df724f63f776 Truffle API: Introduce new compiler directive inCompiledCode() as the negation of inInterpreter().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15064
diff changeset
72 * Returns a boolean value indicating whether the method is executed in the compiled code.
df724f63f776 Truffle API: Introduce new compiler directive inCompiledCode() as the negation of inInterpreter().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15064
diff changeset
73 *
df724f63f776 Truffle API: Introduce new compiler directive inCompiledCode() as the negation of inInterpreter().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15064
diff changeset
74 * @return {@code false} when executed in the interpreter, {@code true} in compiled code.
df724f63f776 Truffle API: Introduce new compiler directive inCompiledCode() as the negation of inInterpreter().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15064
diff changeset
75 */
df724f63f776 Truffle API: Introduce new compiler directive inCompiledCode() as the negation of inInterpreter().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15064
diff changeset
76 public static boolean inCompiledCode() {
df724f63f776 Truffle API: Introduce new compiler directive inCompiledCode() as the negation of inInterpreter().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15064
diff changeset
77 return false;
df724f63f776 Truffle API: Introduce new compiler directive inCompiledCode() as the negation of inInterpreter().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15064
diff changeset
78 }
df724f63f776 Truffle API: Introduce new compiler directive inCompiledCode() as the negation of inInterpreter().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15064
diff changeset
79
df724f63f776 Truffle API: Introduce new compiler directive inCompiledCode() as the negation of inInterpreter().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15064
diff changeset
80 /**
17444
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
81 * Returns a boolean indicating whether or not a given value is seen as constant in optimized
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
82 * code. If this method is called in the interpreter this method will always return
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19309
diff changeset
83 * <code>true</code>.
17444
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
84 *
18309
d079b2af3a15 Truffle: more explicit warning about isCompilationConstant.
Chris Seaton <chris.seaton@oracle.com>
parents: 18219
diff changeset
85 * Note that optimizations that a compiler will apply to code that is conditional on
d079b2af3a15 Truffle: more explicit warning about isCompilationConstant.
Chris Seaton <chris.seaton@oracle.com>
parents: 18219
diff changeset
86 * <code>isCompilationConstant</code> may be limited. For this reason
d079b2af3a15 Truffle: more explicit warning about isCompilationConstant.
Chris Seaton <chris.seaton@oracle.com>
parents: 18219
diff changeset
87 * <code>isCompilationConstant</code> is not recommended for use to select between alternate
d079b2af3a15 Truffle: more explicit warning about isCompilationConstant.
Chris Seaton <chris.seaton@oracle.com>
parents: 18219
diff changeset
88 * implementations of functionality depending on whether a value is constant. Instead, it is
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19309
diff changeset
89 * intended for use as a diagnostic mechanism.
18309
d079b2af3a15 Truffle: more explicit warning about isCompilationConstant.
Chris Seaton <chris.seaton@oracle.com>
parents: 18219
diff changeset
90 *
17444
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
91 * @param value
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
92 * @return {@code true} when given value is seen as compilation constant, {@code false} if not
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
93 * compilation constant.
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
94 */
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
95 public static boolean isCompilationConstant(Object value) {
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19309
diff changeset
96 return CompilerDirectives.inInterpreter();
17444
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
97 }
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
98
2834b4432586 Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents: 16535
diff changeset
99 /**
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 * Directive for the compiler that the given runnable should only be executed in the interpreter
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 * and ignored in the compiled code.
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
102 *
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 * @param runnable the closure that should only be executed in the interpreter
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 */
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 public static void interpreterOnly(Runnable runnable) {
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 runnable.run();
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 }
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 /**
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 * Directive for the compiler that the given callable should only be executed in the
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111 * interpreter.
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
112 *
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113 * @param callable the closure that should only be executed in the interpreter
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 * @return the result of executing the closure in the interpreter and null in the compiled code
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 * @throws Exception If the closure throws an exception when executed in the interpreter.
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116 */
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117 public static <T> T interpreterOnly(Callable<T> callable) throws Exception {
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 return callable.call();
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119 }
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121 /**
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
122 * Injects a probability for the given condition into the probability information of the
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
123 * immediately succeeding branch instruction for the condition. The probability must be a value
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
124 * between 0.0 and 1.0 (inclusive). The condition should not be a combined condition.
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
125 *
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
126 * Example usage immediately before an if statement (it specifies that the likelihood for a to
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
127 * be greater than b is 90%):
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
128 *
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
129 * <code>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 14880
diff changeset
130 * if (injectBranchProbability(0.9, a &gt; b)) {
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
131 * // ...
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
132 * }
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
133 * </code>
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
134 *
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
135 * Example usage for a combined condition (it specifies that the likelihood for a to be greater
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
136 * than b is 90% and under the assumption that this is true, the likelihood for a being 0 is
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
137 * 10%):
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
138 *
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
139 * <code>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 14880
diff changeset
140 * if (injectBranchProbability(0.9, a &gt; b) &amp;&amp; injectBranchProbability(0.1, a == 0)) {
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
141 * // ...
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
142 * }
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
143 * </code>
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
144 *
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
145 * There are predefined constants for commonly used probabilities (see
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
146 * {@link #LIKELY_PROBABILITY} , {@link #UNLIKELY_PROBABILITY}, {@link #SLOWPATH_PROBABILITY},
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
147 * {@link #FASTPATH_PROBABILITY} ).
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
148 *
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149 * @param probability the probability value between 0.0 and 1.0 that should be injected
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150 */
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
151 public static boolean injectBranchProbability(double probability, boolean condition) {
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152 assert probability >= 0.0 && probability <= 1.0;
9319
1188b7c42196 Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9313
diff changeset
153 return condition;
9244
8f540423a5be Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 }
9282
f5e58a1eca55 Added method CompilerDirectives.bailout to the Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9244
diff changeset
155
f5e58a1eca55 Added method CompilerDirectives.bailout to the Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9244
diff changeset
156 /**
f5e58a1eca55 Added method CompilerDirectives.bailout to the Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9244
diff changeset
157 * Bails out of a compilation (e.g., for guest language features that should never be compiled).
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 13956
diff changeset
158 *
9282
f5e58a1eca55 Added method CompilerDirectives.bailout to the Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9244
diff changeset
159 * @param reason the reason for the bailout
f5e58a1eca55 Added method CompilerDirectives.bailout to the Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9244
diff changeset
160 */
f5e58a1eca55 Added method CompilerDirectives.bailout to the Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9244
diff changeset
161 public static void bailout(String reason) {
f5e58a1eca55 Added method CompilerDirectives.bailout to the Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9244
diff changeset
162 }
9313
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
163
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
164 /**
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
165 * Marks fields that should be considered final for a Truffle compilation although they are not
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
166 * final while executing in the interpreter.
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
167 */
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
168 @Retention(RetentionPolicy.RUNTIME)
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
169 @Target({ElementType.FIELD})
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
170 public @interface CompilationFinal {
6369d37b37d1 Added annotation CompilerDirectives.CompilationFinal for fields that should be considered final during compilation, but are not final while executing in the Truffle interpreter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9283
diff changeset
171 }
9349
0fccad3ce40d Introduce CompilerDirectives.Unsafe. Mark Frame.getArguments method as unsafe.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9319
diff changeset
172
0fccad3ce40d Introduce CompilerDirectives.Unsafe. Mark Frame.getArguments method as unsafe.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9319
diff changeset
173 /**
18130
b4e38f4ca414 Truffle: rename @SlowPath to @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 17444
diff changeset
174 * Marks a method that it is considered as a boundary for Truffle partial evaluation.
10687
d2055a110396 Introduce CompilerDirectives.SlowPath annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10650
diff changeset
175 */
d2055a110396 Introduce CompilerDirectives.SlowPath annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10650
diff changeset
176 @Retention(RetentionPolicy.RUNTIME)
19013
f7375de5eaa0 Truffle: allow @TruffleBoundary on constructors
Andreas Woess <andreas.woess@jku.at>
parents: 18906
diff changeset
177 @Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
18130
b4e38f4ca414 Truffle: rename @SlowPath to @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 17444
diff changeset
178 public @interface TruffleBoundary {
10687
d2055a110396 Introduce CompilerDirectives.SlowPath annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10650
diff changeset
179 }
11495
3662471dcfaa Introduce CompilerDirectives.ValueType annotation in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11322
diff changeset
180
3662471dcfaa Introduce CompilerDirectives.ValueType annotation in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11322
diff changeset
181 /**
3662471dcfaa Introduce CompilerDirectives.ValueType annotation in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11322
diff changeset
182 * Marks classes as value types. Reference comparisons (==) between instances of those classes
3662471dcfaa Introduce CompilerDirectives.ValueType annotation in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11322
diff changeset
183 * have undefined semantics and can either return true or false.
3662471dcfaa Introduce CompilerDirectives.ValueType annotation in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11322
diff changeset
184 */
3662471dcfaa Introduce CompilerDirectives.ValueType annotation in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11322
diff changeset
185 @Retention(RetentionPolicy.RUNTIME)
3662471dcfaa Introduce CompilerDirectives.ValueType annotation in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11322
diff changeset
186 @Target({ElementType.TYPE})
3662471dcfaa Introduce CompilerDirectives.ValueType annotation in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11322
diff changeset
187 public @interface ValueType {
3662471dcfaa Introduce CompilerDirectives.ValueType annotation in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11322
diff changeset
188 }
15064
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
189
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
190 /**
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
191 * Ensures that the given object is not virtual, i.e., not removed by Escape Analysis at the
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
192 * point of this call.
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
193 *
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
194 * @param obj the object to exclude from Escape Analysis
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
195 */
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
196 public static void materialize(Object obj) {
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
197 }
9283
159ac409c27a Fix new line at end of file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9282
diff changeset
198 }