Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java @ 9244:8f540423a5be
Added two new classes to the Truffle API: CompilerDirectives and CompilerAsserts.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 23 Apr 2013 11:20:53 +0200 |
parents | |
children | f5e58a1eca55 |
comparison
equal
deleted
inserted
replaced
9243:136cc8fd8890 | 9244:8f540423a5be |
---|---|
1 /* | |
2 * Copyright (c) 2013, 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 */ | |
23 package com.oracle.truffle.api; | |
24 | |
25 import java.util.concurrent.*; | |
26 | |
27 /** | |
28 * Directives that influence the optimizations of the Truffle compiler. All of the operations have | |
29 * no effect when executed in the Truffle interpreter. | |
30 */ | |
31 public class CompilerDirectives { | |
32 | |
33 private static final double SLOWPATH_PROBABILITY = 0.0001; | |
34 | |
35 /** | |
36 * Directive for the compiler to discontinue compilation at this code position and instead | |
37 * insert a transfer to the interpreter. | |
38 */ | |
39 public static void transferToInterpreter() { | |
40 } | |
41 | |
42 /** | |
43 * Directive for the compiler that the given runnable should only be executed in the interpreter | |
44 * and ignored in the compiled code. | |
45 * | |
46 * @param runnable the closure that should only be executed in the interpreter | |
47 */ | |
48 public static void interpreterOnly(Runnable runnable) { | |
49 runnable.run(); | |
50 } | |
51 | |
52 /** | |
53 * Directive for the compiler that the given callable should only be executed in the | |
54 * interpreter. | |
55 * | |
56 * @param callable the closure that should only be executed in the interpreter | |
57 * @return the result of executing the closure in the interpreter and null in the compiled code | |
58 * @throws Exception If the closure throws an exception when executed in the interpreter. | |
59 */ | |
60 public static <T> T interpreterOnly(Callable<T> callable) throws Exception { | |
61 return callable.call(); | |
62 } | |
63 | |
64 /** | |
65 * Directive for the compiler that the current path has a very low probability to be executed. | |
66 */ | |
67 public static void slowpath() { | |
68 injectBranchProbability(SLOWPATH_PROBABILITY); | |
69 } | |
70 | |
71 /** | |
72 * Injects a probability for the current path into the probability information of the | |
73 * immediately preceeding branch instruction. | |
74 * | |
75 * @param probability the probability value between 0.0 and 1.0 that should be injected | |
76 */ | |
77 public static void injectBranchProbability(double probability) { | |
78 assert probability >= 0.0 && probability <= 1.0; | |
79 } | |
80 } |