Mercurial > hg > truffle
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLStackTraceBuiltin.java @ 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.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Tue, 26 May 2015 19:11:36 +0200 |
parents | b4e38f4ca414 |
children | 0a00a5bd7c70 |
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() { |
abe7128ca473
SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
15564
diff
changeset
|
42 super(new NullSourceSection("SL builtin", "stacktrace")); |
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() { |
f675818d9ad0
new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
52 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 |
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
|
54 Truffle.getRuntime().iterateFrames(frameInstance -> { |
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
|
55 CallTarget callTarget = frameInstance.getCallTarget(); |
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
|
56 Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY, true); |
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
|
57 RootNode rn = ((RootCallTarget) callTarget).getRootNode(); |
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
|
58 if (rn.getClass().getName().contains("SLFunctionForeignAccess")) { |
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
|
59 return 1; |
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
|
60 } |
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
|
61 if (str.length() > 0) { |
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
|
62 str.append(System.getProperty("line.separator")); |
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
|
63 } |
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
|
64 str.append("Frame: ").append(rn.toString()); |
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
|
65 FrameDescriptor frameDescriptor = frame.getFrameDescriptor(); |
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
|
66 frameDescriptor.getSlots().stream().forEach((s) -> { |
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
|
67 str.append(", ").append(s.getIdentifier()).append("=").append(frame.getValue(s)); |
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
|
68 }); |
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
|
69 return null; |
f6ac86d3334e
Change API for stack walking to a visitor: TruffleRuntime#iterateFrames replaces TruffleRuntime#getStackTrace
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15564
diff
changeset
|
70 }); |
15064
f675818d9ad0
new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
71 return str.toString(); |
f675818d9ad0
new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
72 } |
f675818d9ad0
new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
73 } |