Reformat files in experimental

This commit is contained in:
Tommy Lillehagen 2017-10-06 14:56:44 +01:00
parent 551dc43265
commit b1fb321230
23 changed files with 134 additions and 130 deletions

View File

@ -271,6 +271,7 @@ data class PackageTree(val branches: Map<String, PackageTree>) {
val exclude: PackageTree, val exclude: PackageTree,
val globSoFar: List<String> val globSoFar: List<String>
) )
val toExpandList = LinkedList(listOf(State(this, excludeTree, emptyList()))) val toExpandList = LinkedList(listOf(State(this, excludeTree, emptyList())))
val globs = ArrayList<Glob>() val globs = ArrayList<Glob>()
while (true) { while (true) {

View File

@ -43,7 +43,6 @@ public class CandidacyStatus {
} }
/** /**
*
* @param signature * @param signature
* @return true if the input was absent from the underlying map * @return true if the input was absent from the underlying map
*/ */
@ -52,7 +51,6 @@ public class CandidacyStatus {
} }
/** /**
*
* @param methodSignature * @param methodSignature
* @return true if the input was absent from the underlying map * @return true if the input was absent from the underlying map
*/ */

View File

@ -6,15 +6,14 @@ import java.util.Set;
/** /**
* A candidate method that is under evaluation. Candidate methods have one of the following states: * A candidate method that is under evaluation. Candidate methods have one of the following states:
* * <p>
* <ul> * <ul>
* <li>{@link CandidateMethod.State#DETERMINISTIC} - It's deterministic and therefore is allowed to be loaded.</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#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#SCANNED} - We're not sure if it's deterministic or not.</li>
* </ul> * </ul>
* * <p>
* CandidateMethods themselves reference other CandidateMethods which are be checked for their deterministic state * CandidateMethods themselves reference other CandidateMethods which are be checked for their deterministic state
*
*/ */
public final class CandidateMethod { public final class CandidateMethod {
@ -94,6 +93,7 @@ public final class CandidateMethod {
/** /**
* This factory constructor is only called for methods that are known to be deterministic in advance * This factory constructor is only called for methods that are known to be deterministic in advance
*
* @param methodSignature * @param methodSignature
* @return * @return
*/ */

View File

@ -1,11 +1,11 @@
package net.corda.sandbox; package net.corda.sandbox;
import static net.corda.sandbox.Utils.*; import static net.corda.sandbox.Utils.*;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
/** /**
*
* @author ben * @author ben
*/ */
public final class SandboxAwareClassWriter extends ClassWriter { public final class SandboxAwareClassWriter extends ClassWriter {
@ -26,10 +26,8 @@ public final class SandboxAwareClassWriter extends ClassWriter {
* that is currently being generated by this ClassWriter, which can of * that is currently being generated by this ClassWriter, which can of
* course not be loaded since it is under construction. * course not be loaded since it is under construction.
* *
* @param type1 * @param type1 the internal name of a class.
* the internal name of a class. * @param type2 the internal name of another class.
* @param type2
* the internal name of another class.
* @return the internal name of the common super class of the two given * @return the internal name of the common super class of the two given
* classes. * classes.
*/ */

View File

@ -3,7 +3,6 @@ package net.corda.sandbox;
import org.objectweb.asm.commons.Remapper; import org.objectweb.asm.commons.Remapper;
/** /**
*
* @author ben * @author ben
*/ */
public final class SandboxRemapper extends Remapper { public final class SandboxRemapper extends Remapper {

View File

@ -4,7 +4,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
*
* @author ben * @author ben
*/ */
public final class Utils { 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 * 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 * 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. * appears to exist, hence this code. If one exists, rip this out.
*
* @param classInternalName * @param classInternalName
* @return * @return
*/ */
@ -55,7 +55,6 @@ public final class Utils {
* This method takes in an internal method name but needs to return a qualified * This method takes in an internal method name but needs to return a qualified
* classname (suitable for loading) * classname (suitable for loading)
* *
*
* @param internalMethodName * @param internalMethodName
* @return * @return
*/ */
@ -72,6 +71,7 @@ public final class Utils {
* Helper method that converts from a fully-qualified class name to the internal class * 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 * 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. * appears to exist, hence this code. If one exists, rip this out.
*
* @param qualifiedClassName * @param qualifiedClassName
* @return * @return
*/ */
@ -102,7 +102,6 @@ public final class Utils {
} }
/** /**
*
* @param qualifiedTypeName * @param qualifiedTypeName
* @return * @return
*/ */
@ -131,7 +130,6 @@ public final class Utils {
} }
/** /**
*
* @param desc - internal * @param desc - internal
* @return the rewritten desc string * @return the rewritten desc string
*/ */

View File

@ -2,6 +2,7 @@ package net.corda.sandbox;
import net.corda.sandbox.visitors.CostInstrumentingMethodVisitor; import net.corda.sandbox.visitors.CostInstrumentingMethodVisitor;
import net.corda.sandbox.visitors.WhitelistCheckingClassVisitor; import net.corda.sandbox.visitors.WhitelistCheckingClassVisitor;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
@ -9,13 +10,13 @@ import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.file.*; import java.nio.file.*;
import java.util.*; import java.util.*;
import org.objectweb.asm.*; import org.objectweb.asm.*;
import org.objectweb.asm.commons.ClassRemapper; import org.objectweb.asm.commons.ClassRemapper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* @author ben * @author ben
*/ */
public final class WhitelistClassLoader extends ClassLoader { public final class WhitelistClassLoader extends ClassLoader {
@ -136,7 +137,6 @@ public final class WhitelistClassLoader extends ClassLoader {
} }
/** /**
*
* @param qualifiedClassName * @param qualifiedClassName
* @return a class object that has been whitelist checked and is known to be * @return a class object that has been whitelist checked and is known to be
* deterministic * deterministic
@ -328,6 +328,7 @@ public final class WhitelistClassLoader extends ClassLoader {
/** /**
* Getter method for the reason for failure * Getter method for the reason for failure
*
* @return * @return
*/ */
public WhitelistClassloadingException reason() { public WhitelistClassloadingException reason() {
@ -336,6 +337,7 @@ public final class WhitelistClassLoader extends ClassLoader {
/** /**
* Getter method for the method candidacy status * Getter method for the method candidacy status
*
* @return * @return
*/ */
public CandidacyStatus getCandidacyStatus() { public CandidacyStatus getCandidacyStatus() {

View File

@ -4,7 +4,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* @author ben * @author ben
*/ */
public class RuntimeCostAccounter { public class RuntimeCostAccounter {

View File

@ -2,6 +2,7 @@ package net.corda.sandbox.tools;
import net.corda.sandbox.WhitelistClassLoader; import net.corda.sandbox.WhitelistClassLoader;
import net.corda.sandbox.visitors.SandboxPathVisitor; import net.corda.sandbox.visitors.SandboxPathVisitor;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; 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 * 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 * classes (note: not methods) that have at least one whitelisted method to create a
* sandboxed version of the class. * sandboxed version of the class.
*
*/ */
// java8.scan.java.lang_and_util java8.interfaces_for_compat java8 sandbox // java8.scan.java.lang_and_util java8.interfaces_for_compat java8 sandbox
public final class SandboxCreator { public final class SandboxCreator {
@ -107,7 +107,6 @@ public final class SandboxCreator {
} }
/** /**
*
* @param basePath * @param basePath
* @param packageName * @param packageName
* @throws IOException * @throws IOException

View File

@ -9,7 +9,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* @author ben * @author ben
*/ */
public final class CostInstrumentingMethodVisitor extends GeneratorAdapter { 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 * This method replaces MONITORENTER / MONITOREXIT opcodes with POP - basically
* stripping the synchronization out of any sandboxed code. * stripping the synchronization out of any sandboxed code.
*
* @param opcode * @param opcode
*/ */
@Override @Override
@ -103,7 +103,7 @@ public final class CostInstrumentingMethodVisitor extends GeneratorAdapter {
/** /**
* This method is called when visiting an opcode with a single operand, that * This method is called when visiting an opcode with a single operand, that
* is a type (represented here as a String). * is a type (represented here as a String).
* * <p>
* For our purposes this is either a NEW opcode or a ANEWARRAY * For our purposes this is either a NEW opcode or a ANEWARRAY
* *
* @param opcode * @param opcode

View File

@ -2,8 +2,10 @@ package net.corda.sandbox.visitors;
import net.corda.sandbox.Utils; import net.corda.sandbox.Utils;
import net.corda.sandbox.WhitelistClassLoader; import net.corda.sandbox.WhitelistClassLoader;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -2,10 +2,12 @@ package net.corda.sandbox.visitors;
import net.corda.sandbox.WhitelistClassLoader; import net.corda.sandbox.WhitelistClassLoader;
import net.corda.sandbox.CandidacyStatus; import net.corda.sandbox.CandidacyStatus;
import java.util.Arrays; import java.util.Arrays;
import net.corda.sandbox.CandidateMethod; import net.corda.sandbox.CandidateMethod;
import net.corda.sandbox.Utils; import net.corda.sandbox.Utils;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -14,6 +16,7 @@ import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static org.objectweb.asm.Opcodes.*; 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 * We initially take the method passed in and store an internal representation of
* the method signature in the our CandidacyStatus working set. * 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 * 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. * custom method visitor which perform additional checks.
* *

View File

@ -13,7 +13,6 @@ import org.objectweb.asm.Label;
/** /**
* A MethodVisitor which checks method instructions in order to determine if this * A MethodVisitor which checks method instructions in order to determine if this
* method is deterministic or not * method is deterministic or not
*
*/ */
final class WhitelistCheckingMethodVisitor extends MethodVisitor { final class WhitelistCheckingMethodVisitor extends MethodVisitor {
@ -85,14 +84,14 @@ final class WhitelistCheckingMethodVisitor extends MethodVisitor {
/** /**
* Currently a no-op. * Currently a no-op.
* * <p>
* The JVMspec seems to permit the possibility of using a backwards branch in a * 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 * tableswitch to try to create an infinite loop. However, it seems to be
* impossible in practice - the specification of StackMapFrame seems to prevent * impossible in practice - the specification of StackMapFrame seems to prevent
* it in modern classfile formats, and even by explicitly generating a version * 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 * 49 (Java 5) classfile, the verifier seems to be specifically resistant to a
* backwards branch from a tableswitch. * backwards branch from a tableswitch.
* * <p>
* We could still add a belt-and-braces static instrumentation to protect * 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 * 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 * should count against the branch limit, or an explicit disallow of a backwards

View File

@ -1,10 +1,13 @@
package net.corda.sandbox; package net.corda.sandbox;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.*; import org.junit.*;
public class WhitelistClassLoaderTest { public class WhitelistClassLoaderTest {

View File

@ -11,7 +11,6 @@ import java.util.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
*
* @author ben * @author ben
*/ */
public class DeterministicClassInstrumenterTest { public class DeterministicClassInstrumenterTest {

View File

@ -1,19 +1,24 @@
package net.corda.sandbox.costing; package net.corda.sandbox.costing;
import net.corda.sandbox.TestUtils; import net.corda.sandbox.TestUtils;
import static net.corda.sandbox.TestUtils.*; import static net.corda.sandbox.TestUtils.*;
import net.corda.sandbox.Utils; import net.corda.sandbox.Utils;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
/** /**
*
* @author ben * @author ben
*/ */
public class SandboxedRewritingTest { public class SandboxedRewritingTest {

View File

@ -1,7 +1,6 @@
package sandbox.greymalkin; package sandbox.greymalkin;
/** /**
*
* @author ben * @author ben
*/ */
// Simple hack for now, generalise to lambdas later... // Simple hack for now, generalise to lambdas later...