com.oracle.truffle.api.test.StackTraceTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truffle-instrument-test Show documentation
Show all versions of truffle-instrument-test Show documentation
Instrumentation tests including InstrumentationTestLanguage.
The newest version!
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.api.test;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.Assert;
import org.junit.Test;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
public class StackTraceTest {
@Test
public void testFirstFrameIsCurrentFrame() {
CallTarget callTarget = createCallTarget(new ReturnStackTraceNode());
StackTrace stack = (StackTrace) callTarget.call();
Assert.assertEquals(1, stack.frames.size());
assertFrameEquals(stack.currentFrame, stack.frames.get(0));
}
@Test
public void testNoStackTrace() {
StackTrace stack = new StackTrace();
Assert.assertNull(stack.callerFrame);
Assert.assertNull(stack.currentFrame);
Assert.assertEquals(0, stack.frames.size());
}
@Test
public void testSingleStackTrace() {
CallTarget callTarget = createCallTarget(new ReturnStackTraceNode());
StackTrace stack = (StackTrace) callTarget.call();
Assert.assertEquals(1, stack.frames.size());
Assert.assertSame(callTarget, stack.currentFrame.getCallTarget());
Assert.assertNull(stack.currentFrame.getCallNode());
assertInvariants(stack);
}
@Test
public void testDirectStackTrace() {
CallTarget createStackTrace = createCallTarget(new ReturnStackTraceNode());
CallTarget call = createCallTarget(new TestCallWithDirectTargetNode(createStackTrace));
StackTrace stack = (StackTrace) call.call();
assertInvariants(stack);
Assert.assertEquals(2, stack.frames.size());
Assert.assertSame(createStackTrace, stack.currentFrame.getCallTarget());
Assert.assertNull(stack.currentFrame.getCallNode());
Assert.assertSame(call, stack.callerFrame.getCallTarget());
Assert.assertSame(findCallNode(call), stack.callerFrame.getCallNode());
}
@Test
public void testIndirectStackTrace() {
CallTarget createStackTrace = createCallTarget(new ReturnStackTraceNode());
CallTarget call = createCallTarget(new TestCallWithIndirectTargetNode(createStackTrace));
StackTrace stack = (StackTrace) call.call();
Assert.assertEquals(2, stack.frames.size());
Assert.assertSame(createStackTrace, stack.currentFrame.getCallTarget());
Assert.assertNull(stack.currentFrame.getCallNode());
Assert.assertSame(call, stack.callerFrame.getCallTarget());
Assert.assertSame(findCallNode(call), stack.callerFrame.getCallNode());
assertInvariants(stack);
}
@Test
public void testCallTargetStackTrace() {
CallTarget createStackTrace = createCallTarget(new ReturnStackTraceNode());
CallTarget call = createCallTarget(new TestCallWithCallTargetNode(createStackTrace));
StackTrace stack = (StackTrace) call.call();
assertInvariants(stack);
Assert.assertEquals(2, stack.frames.size());
Assert.assertSame(createStackTrace, stack.currentFrame.getCallTarget());
Assert.assertNull(stack.currentFrame.getCallNode());
Assert.assertSame(call, stack.callerFrame.getCallTarget());
Assert.assertNull(stack.callerFrame.getCallNode());
}
@Test
public void testCombinedStackTrace() {
CallTarget createStackTrace = createCallTarget(new ReturnStackTraceNode());
CallTarget callTarget = createCallTarget(new TestCallWithCallTargetNode(createStackTrace));
CallTarget indirect = createCallTarget(new TestCallWithIndirectTargetNode(callTarget));
CallTarget direct = createCallTarget(new TestCallWithDirectTargetNode(indirect));
StackTrace stack = (StackTrace) direct.call();
assertInvariants(stack);
Assert.assertEquals(4, stack.frames.size());
Assert.assertSame(createStackTrace, stack.currentFrame.getCallTarget());
Assert.assertNull(stack.currentFrame.getCallNode());
Assert.assertSame(callTarget, stack.callerFrame.getCallTarget());
Assert.assertNull(stack.callerFrame.getCallNode());
Assert.assertSame(indirect, stack.frames.get(2).getCallTarget());
Assert.assertSame(findCallNode(indirect), stack.frames.get(2).getCallNode());
Assert.assertSame(direct, stack.frames.get(3).getCallTarget());
Assert.assertSame(findCallNode(direct), stack.frames.get(3).getCallNode());
}
@Test
public void testFrameAccess() {
CallTarget callTarget = createCallTarget(new TestCallWithCallTargetNode(null));
CallTarget indirect = createCallTarget(new TestCallWithIndirectTargetNode(callTarget));
CallTarget direct = createCallTarget(new TestCallWithDirectTargetNode(indirect));
CallTarget test = createCallTarget(new TestCallNode(null) {
@Override
Object execute(VirtualFrame frame) {
Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor © 2015 - 2025 Weber Informatics LLC | Privacy Policy