Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/instrumentation api #1

Merged
merged 2 commits into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ hs_err_pid*.log
workingsets.xml
\.idea
*.swp
findbugs.results
.metadata/
/eclipseformat.backup.zip
39 changes: 36 additions & 3 deletions mx.truffle/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"sourceDirs" : ["src"],
"dependencies" : [
"com.oracle.truffle.api.interop.java",
"com.oracle.truffle.api.instrumentation",
],
"javaCompliance" : "1.7",
"workingSets" : "API,Truffle",
Expand Down Expand Up @@ -106,6 +107,8 @@
"sourceDirs" : ["src"],
"dependencies" : [
"com.oracle.truffle.api.dsl",
"com.oracle.truffle.api.interop",
"com.oracle.truffle.api.instrumentation",
"com.oracle.truffle.api.interop"
],
"checkstyle" : "com.oracle.truffle.dsl.processor",
Expand All @@ -122,6 +125,29 @@
"workingSets" : "API,Truffle",
},

"com.oracle.truffle.api.instrumentation" : {
"subDir" : "truffle",
"sourceDirs" : ["src"],
"dependencies" : ["com.oracle.truffle.api"],
"checkstyle" : "com.oracle.truffle.api",
"javaCompliance" : "1.7",
"workingSets" : "API,Truffle",
},

"com.oracle.truffle.api.instrumentation.test" : {
"subDir" : "truffle",
"sourceDirs" : ["src"],
"dependencies" : [
"com.oracle.truffle.api.vm",
"com.oracle.truffle.api.dsl.test",
"mx:JUNIT"
],
"checkstyle" : "com.oracle.truffle.api",
"annotationProcessors" : ["TRUFFLE_DSL_PROCESSOR"],
"javaCompliance" : "1.7",
"workingSets" : "API,Truffle",
},

"com.oracle.truffle.api.interop.java" : {
"subDir" : "truffle",
"sourceDirs" : ["src"],
Expand Down Expand Up @@ -199,7 +225,10 @@
"com.oracle.truffle.tools" : {
"subDir" : "truffle",
"sourceDirs" : ["src"],
"dependencies" : ["TRUFFLE_API"],
"dependencies" : [
"com.oracle.truffle.api.profiles",
"com.oracle.truffle.api.instrumentation"],
"annotationProcessors" : ["TRUFFLE_DSL_PROCESSOR"],
"checkstyle" : "com.oracle.truffle.api",
"javaCompliance" : "1.7",
"workingSets" : "Truffle,Tools",
Expand All @@ -210,6 +239,7 @@
"sourceDirs" : ["src"],
"dependencies" : [
"com.oracle.truffle.tools",
"com.oracle.truffle.api.instrumentation.test",
"mx:JUNIT"
],
"checkstyle" : "com.oracle.truffle.api",
Expand All @@ -221,8 +251,11 @@
"com.oracle.truffle.tools.debug.shell" : {
"subDir" : "truffle",
"sourceDirs" : ["src"],
"dependencies" : ["com.oracle.truffle.tools",
"JLINE"],
"dependencies" : [
"com.oracle.truffle.tools",
"com.oracle.truffle.api.vm",
"JLINE"
],
"checkstyle" : "com.oracle.truffle.api",
"javaCompliance" : "1.7",
"workingSets" : "Truffle,Tools",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.instrumentation;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.vm.PolyglotEngine;

/**
* Base class for instrumentation tests.
*/
public abstract class AbstractInstrumentationTest {

protected PolyglotEngine engine;

protected final ByteArrayOutputStream out = new ByteArrayOutputStream();
protected final ByteArrayOutputStream err = new ByteArrayOutputStream();

@Before
public void setup() {
engine = PolyglotEngine.newBuilder().setOut(out).setErr(err).build();
}

protected void assertEnabledInstrument(String id) {
Assert.assertTrue(engine.getInstruments().get(id).isEnabled());
}

protected String run(Source source) throws IOException {
this.out.reset();
this.err.reset();
engine.eval(source);
this.out.flush();
this.err.flush();
String outText = getOut();
return outText;
}

protected static boolean containsTag(String[] tags, String tag) {
for (int i = 0; i < tags.length; i++) {
if (tags[i] == tag) {
return true;
}
}
return false;
}

protected String run(String source) throws IOException {
return run(lines(source));
}

protected void assertEvalOut(String source, String output) throws IOException {
String actual = run(lines(source));
if (!actual.equals(output)) {
Assert.assertEquals(output, actual);
}
}

protected final String getOut() {
return new String(out.toByteArray());
}

protected final String getErr() {
return new String(err.toByteArray());
}

protected static Source lines(String... lines) {
StringBuilder b = new StringBuilder();
for (String line : lines) {
b.append(line);
b.append("\n");
}
return Source.fromText(b.toString(), null).withMimeType(InstrumentationTestLanguage.MIME_TYPE);
}

@After
public void teardown() {
if (engine != null) {
engine.dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.instrumentation;

import java.io.IOException;

import org.junit.Test;

import com.oracle.truffle.api.dsl.test.ExpectError;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;

public class InstrumentableTest {

@Instrumentable(factory = TestNode1Wrapper.class)
public abstract static class TestNode1 extends Node {

public abstract void execute1();

public abstract Object execute2();

public abstract int execute3();

public abstract String execute4();

public abstract double execute5();

public abstract long execute6();

public abstract float execute7();

public abstract short execute8();

public abstract byte execute9();

public abstract Object execute10(VirtualFrame frame1);

public abstract Object execute11(int a, VirtualFrame frame1);

public abstract Object execute12(VirtualFrame frame1, int b);

public abstract Object execute13(int a, VirtualFrame frame1, int b);

public abstract byte execute15() throws UnexpectedResultException;

public abstract byte execute16() throws IOException;

public abstract Object execute17(int a, VirtualFrame frame1, int b) throws UnexpectedResultException;

@SuppressWarnings("unused")
public Object execute18(int a, VirtualFrame frame1, int b) throws UnexpectedResultException {
return null;
}
}

// test constructor with source section
@Instrumentable(factory = TestNode2Wrapper.class)
public abstract static class TestNode2 extends Node {

private final SourceSection sourceSection;

public TestNode2(SourceSection sourceSection) {
this.sourceSection = sourceSection;
}

@Override
public SourceSection getSourceSection() {
return sourceSection;
}

public abstract void execute1();

}

// test copy constructor
@Instrumentable(factory = TestNode3Wrapper.class)
public abstract static class TestNode3 extends Node {

public TestNode3(@SuppressWarnings("unused") TestNode3 sourceSection) {
}

public abstract void execute1();

}

@Test
public void testTestNode1() {
}

@ExpectError("Class must not be final to generate a wrapper.")
@Instrumentable(factory = TestErrorFactory.class)
public static final class ErrorNode0 extends Node {
}

@ExpectError("Class must be public to generate a wrapper.")
@Instrumentable(factory = TestErrorFactory.class)
static class ErrorNode2 extends Node {
}

@ExpectError("Inner class must be static to generate a wrapper.")
@Instrumentable(factory = TestErrorFactory.class)
public class ErrorNode3 extends Node {
}

@ExpectError("No methods starting with name execute found to wrap.")
@Instrumentable(factory = TestErrorFactory.class)
public static class ErrorNode4 extends Node {

@SuppressWarnings("unused")
private void execute1() {
}

void execute2() {
}

public final void execute3() {
}
}

@ExpectError("Unable to implement unknown abstract method foobar() in generated wrapper node.")
@Instrumentable(factory = TestErrorFactory.class)
public abstract static class ErrorNode5 extends Node {

public abstract void foobar();
}

@ExpectError("No suiteable constructor found for wrapper factory generation. At least one default or copy constructor must be visible.")
@Instrumentable(factory = TestErrorFactory.class)
@SuppressWarnings("unused")
public abstract static class ErrorNode6 extends Node {

ErrorNode6() {
}

private ErrorNode6(SourceSection notVisible) {
}

private ErrorNode6(ErrorNode6 copyNotVisible) {
}

public ErrorNode6(int a, int b) {
}

public ErrorNode6(String foobar) {
}
}

}
Loading