mirror of
https://github.com/corda/corda.git
synced 2025-05-29 21:54:26 +00:00
Reformat files in experimental
This commit is contained in:
parent
551dc43265
commit
b1fb321230
@ -32,7 +32,7 @@ fun recordUsedInstrumentedCallStack() {
|
||||
val throwable = Throwable()
|
||||
var index = 0
|
||||
while (true) {
|
||||
require (index < throwable.stackTrace.size) { "Can't find getStack call" }
|
||||
require(index < throwable.stackTrace.size) { "Can't find getStack call" }
|
||||
val stackElement = throwable.stackTrace[index]
|
||||
if (stackElement.className == "co.paralleluniverse.fibers.Stack" && stackElement.methodName == "getStack") {
|
||||
break
|
||||
@ -129,7 +129,7 @@ class QuasarInstrumentationHookAgent {
|
||||
// The separator append is a hack, it causes a package with an empty name to be added to the exclude tree,
|
||||
// which practically causes that level of the tree to be always expanded in the output globs.
|
||||
val expand = arguments.expand?.let { PackageTree.fromStrings(it.map { "$it${arguments.separator}" }, arguments.separator) }
|
||||
val truncatedTree = truncate?.let { scannedTree.truncate(it)} ?: scannedTree
|
||||
val truncatedTree = truncate?.let { scannedTree.truncate(it) } ?: scannedTree
|
||||
val expandedTree = expand?.let { alwaysExcludedTree.merge(it) } ?: alwaysExcludedTree
|
||||
val globs = truncatedTree.toGlobs(expandedTree)
|
||||
globs.forEach {
|
||||
@ -152,7 +152,7 @@ object QuasarInstrumentationHook : ClassFileTransformer {
|
||||
val instrumentMap = mapOf<String, (CtClass) -> Unit>(
|
||||
"co/paralleluniverse/fibers/Stack" to { clazz ->
|
||||
// This is called on each suspend, we hook into it to get the stack trace of actually used Suspendables
|
||||
val getStackMethod = clazz.methods.single { it.name == "getStack" }
|
||||
val getStackMethod = clazz.methods.single { it.name == "getStack" }
|
||||
getStackMethod.insertBefore(
|
||||
"$hookClassName.${::recordUsedInstrumentedCallStack.name}();"
|
||||
)
|
||||
@ -194,7 +194,7 @@ object QuasarInstrumentationHook : ClassFileTransformer {
|
||||
throwable.printStackTrace(System.out)
|
||||
classfileBuffer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class Glob(val parts: List<String>, val isFull: Boolean) {
|
||||
@ -271,6 +271,7 @@ data class PackageTree(val branches: Map<String, PackageTree>) {
|
||||
val exclude: PackageTree,
|
||||
val globSoFar: List<String>
|
||||
)
|
||||
|
||||
val toExpandList = LinkedList(listOf(State(this, excludeTree, emptyList())))
|
||||
val globs = ArrayList<Glob>()
|
||||
while (true) {
|
||||
|
@ -43,7 +43,6 @@ public class CandidacyStatus {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param signature
|
||||
* @return true if the input was absent from the underlying map
|
||||
*/
|
||||
@ -52,7 +51,6 @@ public class CandidacyStatus {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param methodSignature
|
||||
* @return true if the input was absent from the underlying map
|
||||
*/
|
||||
|
@ -6,15 +6,14 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* A candidate method that is under evaluation. Candidate methods have one of the following states:
|
||||
*
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>{@link CandidateMethod.State#DETERMINISTIC} - It's deterministic and therefore is allowed to be loaded.</li>
|
||||
* <li>{@link CandidateMethod.State#DISALLOWED} - It's not deterministic and won't be allowed to be loaded.</li>
|
||||
* <li>{@link CandidateMethod.State#SCANNED} - We're not sure if it's deterministic or not.</li>
|
||||
* <li>{@link CandidateMethod.State#DETERMINISTIC} - It's deterministic and therefore is allowed to be loaded.</li>
|
||||
* <li>{@link CandidateMethod.State#DISALLOWED} - It's not deterministic and won't be allowed to be loaded.</li>
|
||||
* <li>{@link CandidateMethod.State#SCANNED} - We're not sure if it's deterministic or not.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* CandidateMethods themselves reference other CandidateMethods which are be checked for their deterministic state
|
||||
*
|
||||
*/
|
||||
public final class CandidateMethod {
|
||||
|
||||
@ -59,7 +58,7 @@ public final class CandidateMethod {
|
||||
|
||||
public void deterministic() {
|
||||
if (currentState == State.DISALLOWED) {
|
||||
throw new IllegalArgumentException("Method "+ internalMethodName +" attempted to transition from DISALLOWED to DETERMINISTIC");
|
||||
throw new IllegalArgumentException("Method " + internalMethodName + " attempted to transition from DISALLOWED to DETERMINISTIC");
|
||||
}
|
||||
currentState = State.DETERMINISTIC;
|
||||
}
|
||||
@ -94,6 +93,7 @@ public final class CandidateMethod {
|
||||
|
||||
/**
|
||||
* This factory constructor is only called for methods that are known to be deterministic in advance
|
||||
*
|
||||
* @param methodSignature
|
||||
* @return
|
||||
*/
|
||||
|
@ -1,11 +1,11 @@
|
||||
package net.corda.sandbox;
|
||||
|
||||
import static net.corda.sandbox.Utils.*;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ben
|
||||
*/
|
||||
public final class SandboxAwareClassWriter extends ClassWriter {
|
||||
@ -26,12 +26,10 @@ public final class SandboxAwareClassWriter extends ClassWriter {
|
||||
* that is currently being generated by this ClassWriter, which can of
|
||||
* course not be loaded since it is under construction.
|
||||
*
|
||||
* @param type1
|
||||
* the internal name of a class.
|
||||
* @param type2
|
||||
* the internal name of another class.
|
||||
* @param type1 the internal name of a class.
|
||||
* @param type2 the internal name of another class.
|
||||
* @return the internal name of the common super class of the two given
|
||||
* classes.
|
||||
* classes.
|
||||
*/
|
||||
@Override
|
||||
public String getCommonSuperClass(final String type1, final String type2) {
|
||||
|
@ -3,7 +3,6 @@ package net.corda.sandbox;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ben
|
||||
*/
|
||||
public final class SandboxRemapper extends Remapper {
|
||||
|
@ -4,7 +4,6 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ben
|
||||
*/
|
||||
public final class Utils {
|
||||
@ -43,6 +42,7 @@ public final class Utils {
|
||||
* Helper method that converts from the internal class name format (as used in the
|
||||
* Constant Pool) to a fully-qualified class name. No obvious library method to do this
|
||||
* appears to exist, hence this code. If one exists, rip this out.
|
||||
*
|
||||
* @param classInternalName
|
||||
* @return
|
||||
*/
|
||||
@ -55,7 +55,6 @@ public final class Utils {
|
||||
* This method takes in an internal method name but needs to return a qualified
|
||||
* classname (suitable for loading)
|
||||
*
|
||||
*
|
||||
* @param internalMethodName
|
||||
* @return
|
||||
*/
|
||||
@ -72,6 +71,7 @@ public final class Utils {
|
||||
* Helper method that converts from a fully-qualified class name to the internal class
|
||||
* name format (as used in the Constant Pool). No obvious library method to do this
|
||||
* appears to exist, hence this code. If one exists, rip this out.
|
||||
*
|
||||
* @param qualifiedClassName
|
||||
* @return
|
||||
*/
|
||||
@ -102,7 +102,6 @@ public final class Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param qualifiedTypeName
|
||||
* @return
|
||||
*/
|
||||
@ -131,7 +130,6 @@ public final class Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param desc - internal
|
||||
* @return the rewritten desc string
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@ package net.corda.sandbox;
|
||||
|
||||
import net.corda.sandbox.visitors.CostInstrumentingMethodVisitor;
|
||||
import net.corda.sandbox.visitors.WhitelistCheckingClassVisitor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
@ -9,13 +10,13 @@ import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.objectweb.asm.*;
|
||||
import org.objectweb.asm.commons.ClassRemapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ben
|
||||
*/
|
||||
public final class WhitelistClassLoader extends ClassLoader {
|
||||
@ -99,7 +100,7 @@ public final class WhitelistClassLoader extends ClassLoader {
|
||||
*
|
||||
* @param other
|
||||
* @return a suitably constructed whitelisting classloader based on the state
|
||||
* of the passed classloader
|
||||
* of the passed classloader
|
||||
*/
|
||||
public static WhitelistClassLoader of(final WhitelistClassLoader other) {
|
||||
final WhitelistClassLoader out = new WhitelistClassLoader(other);
|
||||
@ -136,10 +137,9 @@ public final class WhitelistClassLoader extends ClassLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param qualifiedClassName
|
||||
* @return a class object that has been whitelist checked and is known to be
|
||||
* deterministic
|
||||
* deterministic
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
@Override
|
||||
@ -328,6 +328,7 @@ public final class WhitelistClassLoader extends ClassLoader {
|
||||
|
||||
/**
|
||||
* Getter method for the reason for failure
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WhitelistClassloadingException reason() {
|
||||
@ -336,6 +337,7 @@ public final class WhitelistClassLoader extends ClassLoader {
|
||||
|
||||
/**
|
||||
* Getter method for the method candidacy status
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public CandidacyStatus getCandidacyStatus() {
|
||||
|
@ -22,8 +22,8 @@ public class WhitelistClassloadingException extends Exception {
|
||||
}
|
||||
|
||||
protected WhitelistClassloadingException(String message, Throwable cause,
|
||||
boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ben
|
||||
*/
|
||||
public class RuntimeCostAccounter {
|
||||
|
@ -2,6 +2,7 @@ package net.corda.sandbox.tools;
|
||||
|
||||
import net.corda.sandbox.WhitelistClassLoader;
|
||||
import net.corda.sandbox.visitors.SandboxPathVisitor;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
@ -18,7 +19,6 @@ import joptsimple.OptionSet;
|
||||
* This class takes in an exploded set of JRE classes, and a whitelist, and rewrites all
|
||||
* classes (note: not methods) that have at least one whitelisted method to create a
|
||||
* sandboxed version of the class.
|
||||
*
|
||||
*/
|
||||
// java8.scan.java.lang_and_util java8.interfaces_for_compat java8 sandbox
|
||||
public final class SandboxCreator {
|
||||
@ -107,7 +107,6 @@ public final class SandboxCreator {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param basePath
|
||||
* @param packageName
|
||||
* @throws IOException
|
||||
|
@ -9,7 +9,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ben
|
||||
*/
|
||||
public final class CostInstrumentingMethodVisitor extends GeneratorAdapter {
|
||||
@ -36,6 +35,7 @@ public final class CostInstrumentingMethodVisitor extends GeneratorAdapter {
|
||||
/**
|
||||
* This method replaces MONITORENTER / MONITOREXIT opcodes with POP - basically
|
||||
* stripping the synchronization out of any sandboxed code.
|
||||
*
|
||||
* @param opcode
|
||||
*/
|
||||
@Override
|
||||
@ -103,7 +103,7 @@ public final class CostInstrumentingMethodVisitor extends GeneratorAdapter {
|
||||
/**
|
||||
* This method is called when visiting an opcode with a single operand, that
|
||||
* is a type (represented here as a String).
|
||||
*
|
||||
* <p>
|
||||
* For our purposes this is either a NEW opcode or a ANEWARRAY
|
||||
*
|
||||
* @param opcode
|
||||
|
@ -2,8 +2,10 @@ package net.corda.sandbox.visitors;
|
||||
|
||||
import net.corda.sandbox.Utils;
|
||||
import net.corda.sandbox.WhitelistClassLoader;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -30,7 +32,7 @@ public final class SandboxPathVisitor extends SimpleFileVisitor<Path> {
|
||||
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attr) {
|
||||
// Check that this is a class file
|
||||
if (!path.toString().matches(Utils.CLASSFILE_NAME_SUFFIX)) {
|
||||
System.out.println("Skipping: "+ path);
|
||||
System.out.println("Skipping: " + path);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,12 @@ package net.corda.sandbox.visitors;
|
||||
|
||||
import net.corda.sandbox.WhitelistClassLoader;
|
||||
import net.corda.sandbox.CandidacyStatus;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.corda.sandbox.CandidateMethod;
|
||||
import net.corda.sandbox.Utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -14,6 +16,7 @@ import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
/**
|
||||
@ -57,7 +60,7 @@ public final class WhitelistCheckingClassVisitor extends ClassVisitor {
|
||||
/**
|
||||
* We initially take the method passed in and store an internal representation of
|
||||
* the method signature in the our CandidacyStatus working set.
|
||||
*
|
||||
* <p>
|
||||
* We then get an ASM MethodVisitor (which can read the byte code of the method) and pass that to our
|
||||
* custom method visitor which perform additional checks.
|
||||
*
|
||||
|
@ -13,7 +13,6 @@ import org.objectweb.asm.Label;
|
||||
/**
|
||||
* A MethodVisitor which checks method instructions in order to determine if this
|
||||
* method is deterministic or not
|
||||
*
|
||||
*/
|
||||
final class WhitelistCheckingMethodVisitor extends MethodVisitor {
|
||||
|
||||
@ -85,14 +84,14 @@ final class WhitelistCheckingMethodVisitor extends MethodVisitor {
|
||||
|
||||
/**
|
||||
* Currently a no-op.
|
||||
*
|
||||
* <p>
|
||||
* The JVMspec seems to permit the possibility of using a backwards branch in a
|
||||
* tableswitch to try to create an infinite loop. However, it seems to be
|
||||
* impossible in practice - the specification of StackMapFrame seems to prevent
|
||||
* it in modern classfile formats, and even by explicitly generating a version
|
||||
* 49 (Java 5) classfile, the verifier seems to be specifically resistant to a
|
||||
* backwards branch from a tableswitch.
|
||||
*
|
||||
* <p>
|
||||
* We could still add a belt-and-braces static instrumentation to protect
|
||||
* against this but it currently seems unnecessary - at worse it is a branch that
|
||||
* should count against the branch limit, or an explicit disallow of a backwards
|
||||
|
@ -22,7 +22,7 @@ public class TestUtils {
|
||||
// Copy resource jar to tmp dir
|
||||
tmpdir = Files.createTempDirectory("wlcl-tmp-test");
|
||||
Path copiedJar = tmpdir.resolve("tmp-resource.jar");
|
||||
try(final InputStream in = TestUtils.class.getResourceAsStream(resourcePathToJar)) {
|
||||
try (final InputStream in = TestUtils.class.getResourceAsStream(resourcePathToJar)) {
|
||||
Files.copy(in, copiedJar, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
final FileSystem fs = FileSystems.newFileSystem(copiedJar, null);
|
||||
@ -33,7 +33,7 @@ public class TestUtils {
|
||||
public static Path copySandboxJarToTmpDir(final String resourcePathToJar) throws IOException {
|
||||
|
||||
Path sandboxJar = tmpdir.resolve("tmp-sandbox.jar");
|
||||
try(final InputStream in = TestUtils.class.getResourceAsStream(resourcePathToJar)) {
|
||||
try (final InputStream in = TestUtils.class.getResourceAsStream(resourcePathToJar)) {
|
||||
Files.copy(in, sandboxJar, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
final FileSystem sandboxFs = FileSystems.newFileSystem(sandboxJar, null);
|
||||
@ -46,7 +46,7 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
public static void cleanupTmpJar() throws IOException {
|
||||
for (FileSystem fs: tmpFileSystems) {
|
||||
for (FileSystem fs : tmpFileSystems) {
|
||||
fs.close();
|
||||
}
|
||||
tmpFileSystems.clear();
|
||||
@ -92,15 +92,15 @@ public class TestUtils {
|
||||
// Helper for finding the correct offsets if they change
|
||||
public static void printBytes(byte[] data) {
|
||||
byte[] datum = new byte[1];
|
||||
for (int i=0; i < data.length; i++) {
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
datum[0] = data[i];
|
||||
System.out.println(i +" : "+ DatatypeConverter.printHexBinary(datum));
|
||||
System.out.println(i + " : " + DatatypeConverter.printHexBinary(datum));
|
||||
}
|
||||
}
|
||||
|
||||
public static int findOffset(byte[] classBytes, byte[] originalSeq) {
|
||||
int offset = 0;
|
||||
for (int i=415; i < classBytes.length; i++) {
|
||||
for (int i = 415; i < classBytes.length; i++) {
|
||||
if (classBytes[i] != originalSeq[offset]) {
|
||||
offset = 0;
|
||||
continue;
|
||||
|
@ -1,10 +1,13 @@
|
||||
package net.corda.sandbox;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
public class WhitelistClassLoaderTest {
|
||||
|
@ -11,7 +11,6 @@ import java.util.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ben
|
||||
*/
|
||||
public class DeterministicClassInstrumenterTest {
|
||||
|
@ -1,19 +1,24 @@
|
||||
package net.corda.sandbox.costing;
|
||||
|
||||
import net.corda.sandbox.TestUtils;
|
||||
|
||||
import static net.corda.sandbox.TestUtils.*;
|
||||
|
||||
import net.corda.sandbox.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ben
|
||||
*/
|
||||
public class SandboxedRewritingTest {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package sandbox.greymalkin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ben
|
||||
*/
|
||||
// Simple hack for now, generalise to lambdas later...
|
||||
|
Loading…
x
Reference in New Issue
Block a user