annotate truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLStackTraceBuiltin.java @ 21987:b2d1c8ff592a

Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 01 Jul 2015 10:23:36 +0200
parents 9c8c0937da41
children c07e64ecb528
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15064
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
1 /*
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
4 *
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
8 *
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
13 * accompanied this code).
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
14 *
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
18 *
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
21 * questions.
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
22 */
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
23 package com.oracle.truffle.sl.builtins;
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
24
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
25 import com.oracle.truffle.api.*;
18130
b4e38f4ca414 Truffle: rename @SlowPath to @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 17349
diff changeset
26 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
15064
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
27 import com.oracle.truffle.api.dsl.*;
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
28 import com.oracle.truffle.api.frame.*;
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
29 import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
30 import com.oracle.truffle.api.nodes.*;
16512
abe7128ca473 SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15564
diff changeset
31 import com.oracle.truffle.api.source.*;
15064
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
32
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
33 /**
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
34 * Returns a string representation of the current stack. This includes the {@link CallTarget}s and
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
35 * the contents of the {@link Frame}. Note that this is implemented as a slow path by passing
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
36 * {@code true} to {@link FrameInstance#getFrame(FrameAccess, boolean)}.
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
37 */
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
38 @NodeInfo(shortName = "stacktrace")
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
39 public abstract class SLStackTraceBuiltin extends SLBuiltinNode {
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
40
16512
abe7128ca473 SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15564
diff changeset
41 public SLStackTraceBuiltin() {
21987
b2d1c8ff592a Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
42 super(SourceSection.createUnavailable("SL builtin", "stacktrace"));
16512
abe7128ca473 SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15564
diff changeset
43 }
abe7128ca473 SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15564
diff changeset
44
15064
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
45 @Specialization
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
46 public String trace() {
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
47 return createStackTrace();
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
48 }
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
49
18130
b4e38f4ca414 Truffle: rename @SlowPath to @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 17349
diff changeset
50 @TruffleBoundary
15064
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
51 private static String createStackTrace() {
21941
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
52 final StringBuilder str = new StringBuilder();
15097
a1b0d7a1ef40 SL: Make SLStackTraceBuilting comfortable with non-graal runtimes.
Christian Humer <christian.humer@gmail.com>
parents: 15088
diff changeset
53
21941
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
54 Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Integer>() {
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
55 @Override
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
56 public Integer visitFrame(FrameInstance frameInstance) {
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
57 CallTarget callTarget = frameInstance.getCallTarget();
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
58 Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY, true);
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
59 RootNode rn = ((RootCallTarget) callTarget).getRootNode();
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
60 if (rn.getClass().getName().contains("SLFunctionForeignAccess")) {
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
61 return 1;
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
62 }
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
63 if (str.length() > 0) {
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
64 str.append(System.getProperty("line.separator"));
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
65 }
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
66 str.append("Frame: ").append(rn.toString());
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
67 FrameDescriptor frameDescriptor = frame.getFrameDescriptor();
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
68 for (FrameSlot s : frameDescriptor.getSlots()) {
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
69 str.append(", ").append(s.getIdentifier()).append("=").append(frame.getValue(s));
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
70 }
0a00a5bd7c70 Need to expose also TRUFFLE-SL as Graal tests against that language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21490
diff changeset
71 return null;
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 18130
diff changeset
72 }
16529
f6ac86d3334e Change API for stack walking to a visitor: TruffleRuntime#iterateFrames replaces TruffleRuntime#getStackTrace
Christian Wimmer <christian.wimmer@oracle.com>
parents: 15564
diff changeset
73 });
15064
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
74 return str.toString();
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
75 }
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
76 }