annotate truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/HashLanguage.java @ 22385:0e86a9f324bf

Capturing the current state of Source->CallTarget caching in a test
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 19 Nov 2015 09:29:24 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22385
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
1 /*
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
4 *
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
8 *
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
13 * accompanied this code).
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
14 *
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
18 *
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
21 * questions.
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
22 */
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
23 package com.oracle.truffle.api.test.vm;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
24
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
25 import com.oracle.truffle.api.CallTarget;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
26 import com.oracle.truffle.api.Truffle;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
27 import com.oracle.truffle.api.TruffleLanguage;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
28 import com.oracle.truffle.api.TruffleLanguage.Env;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
29 import com.oracle.truffle.api.frame.MaterializedFrame;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
30 import com.oracle.truffle.api.frame.VirtualFrame;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
31 import com.oracle.truffle.api.instrument.Visualizer;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
32 import com.oracle.truffle.api.instrument.WrapperNode;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
33 import com.oracle.truffle.api.nodes.Node;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
34 import com.oracle.truffle.api.nodes.RootNode;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
35 import com.oracle.truffle.api.source.Source;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
36 import java.io.IOException;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
37
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
38 @TruffleLanguage.Registration(name = "Hash", mimeType = "application/x-test-hash", version = "1.0")
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
39 public class HashLanguage extends TruffleLanguage<Env> {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
40 public static final HashLanguage INSTANCE = new HashLanguage();
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
41
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
42 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
43 protected Env createContext(Env env) {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
44 return env;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
45 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
46
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
47 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
48 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
49 return Truffle.getRuntime().createCallTarget(new HashNode(this, code));
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
50 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
51
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
52 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
53 protected Object findExportedSymbol(Env context, String globalName, boolean onlyExplicit) {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
54 return null;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
55 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
56
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
57 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
58 protected Object getLanguageGlobal(Env context) {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
59 return null;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
60 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
61
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
62 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
63 protected boolean isObjectOfLanguage(Object object) {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
64 return false;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
65 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
66
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
67 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
68 protected Visualizer getVisualizer() {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
69 return null;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
70 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
71
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
72 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
73 protected boolean isInstrumentable(Node node) {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
74 return false;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
75 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
76
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
77 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
78 protected WrapperNode createWrapperNode(Node node) {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
79 throw new UnsupportedOperationException();
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
80 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
81
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
82 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
83 protected Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws IOException {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
84 throw new UnsupportedOperationException("Not supported yet."); // To change body of
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
85 // generated methods, choose
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
86 // Tools | Templates.
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
87 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
88
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
89 private static class HashNode extends RootNode {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
90 private static int counter;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
91 private final Source code;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
92 private final int id;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
93
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
94 public HashNode(HashLanguage hash, Source code) {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
95 super(hash.getClass(), null, null);
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
96 this.code = code;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
97 id = ++counter;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
98 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
99
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
100 @Override
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
101 public Object execute(VirtualFrame frame) {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
102 return System.identityHashCode(this) + "@" + code.getCode() + " @ " + id;
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
103 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
104 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
105
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
106 @TruffleLanguage.Registration(name = "AltHash", mimeType = "application/x-test-hash-alt", version = "1.0")
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
107 public static final class SubLang extends HashLanguage {
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
108 public static final SubLang INSTANCE = new SubLang();
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
109 }
0e86a9f324bf Capturing the current state of Source->CallTarget caching in a test
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
110 }