Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLException.java @ 18481:f91e40c4bb47
Create separate stamps for Klass* and Method*, and make them hotspot specific.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Thu, 20 Nov 2014 15:23:46 +0100 |
parents | 158c9ba66e45 |
children |
rev | line source |
---|---|
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
24 |
17004
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
25 import java.util.*; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
26 |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
27 import com.oracle.truffle.api.*; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
28 import com.oracle.truffle.api.frame.*; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
29 import com.oracle.truffle.api.nodes.*; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
30 import com.oracle.truffle.api.source.*; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
31 import com.oracle.truffle.sl.nodes.*; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
32 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
33 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
34 * SL does not need a sophisticated error checking and reporting mechanism, so all unexpected |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
35 * conditions just abort execution. This exception class is used when we abort from within the SL |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
36 * implementation. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
37 */ |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
38 public class SLException extends RuntimeException { |
17004
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
39 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
40 private static final long serialVersionUID = -6799734410727348507L; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
41 |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
42 public SLException(String message) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
43 super(message); |
17004
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
44 initCause(new Throwable("Java stack trace")); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
45 } |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
46 |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
47 @Override |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
48 public synchronized Throwable fillInStackTrace() { |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
49 return fillInSLStackTrace(this); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
50 } |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
51 |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
52 /** |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
53 * Uses the Truffle API to iterate the stack frames and to create and set Java |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
54 * {@link StackTraceElement} elements based on the source sections of the call nodes on the |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
55 * stack. |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
56 */ |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
57 static Throwable fillInSLStackTrace(Throwable t) { |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
58 final List<StackTraceElement> stackTrace = new ArrayList<>(); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
59 Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Void>() { |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
60 public Void visitFrame(FrameInstance frame) { |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
61 Node callNode = frame.getCallNode(); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
62 if (callNode == null) { |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
63 return null; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
64 } |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
65 RootNode root = callNode.getRootNode(); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
66 |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
67 /* |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
68 * There should be no RootNodes other than SLRootNodes on the stack. Just for the |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
69 * case if this would change. |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
70 */ |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
71 String methodName = "$unknownFunction"; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
72 if (root instanceof SLRootNode) { |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
73 methodName = ((SLRootNode) root).getName(); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
74 } |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
75 |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
76 SourceSection sourceSection = callNode.getEncapsulatingSourceSection(); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
77 Source source = sourceSection != null ? sourceSection.getSource() : null; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
78 String sourceName = source != null ? source.getName() : null; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
79 int lineNumber; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
80 try { |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
81 lineNumber = sourceSection != null ? sourceSection.getLineLocation().getLineNumber() : -1; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
82 } catch (UnsupportedOperationException e) { |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
83 /* |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
84 * SourceSection#getLineLocation() may throw an UnsupportedOperationException. |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
85 */ |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
86 lineNumber = -1; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
87 } |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
88 stackTrace.add(new StackTraceElement("SL", methodName, sourceName, lineNumber)); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
89 return null; |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
90 } |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
91 }); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
92 t.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); |
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
13821
diff
changeset
|
93 return t; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
94 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
95 } |