From aa75157273dc12d7f5183873780bacd35360eb5f Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Fri, 24 May 2019 15:09:20 +0100 Subject: [PATCH] CORDA-2961: Migrate the DJVM into its own repository. (#5166) * Migrate the DJVM into its own repository. * Update the documentation for DJVM. --- djvm/.gitignore | 13 - djvm/build.gradle | 122 --- djvm/djvm/build.gradle | 90 --- djvm/djvm/cli/build.gradle | 64 -- .../net/corda/djvm/tools/cli/BuildCommand.kt | 39 - .../net/corda/djvm/tools/cli/CheckCommand.kt | 34 - .../net/corda/djvm/tools/cli/ClassCommand.kt | 204 ----- .../net/corda/djvm/tools/cli/CommandBase.kt | 279 ------- .../net/corda/djvm/tools/cli/Commands.kt | 29 - .../corda/djvm/tools/cli/InspectionCommand.kt | 88 -- .../net/corda/djvm/tools/cli/NewCommand.kt | 72 -- .../net/corda/djvm/tools/cli/Program.kt | 12 - .../net/corda/djvm/tools/cli/RunCommand.kt | 36 - .../net/corda/djvm/tools/cli/ShowCommand.kt | 56 -- .../net/corda/djvm/tools/cli/TreeCommand.kt | 33 - .../net/corda/djvm/tools/cli/Utilities.kt | 102 --- .../corda/djvm/tools/cli/VersionProvider.kt | 14 - djvm/djvm/cli/src/main/resources/log4j2.xml | 39 - djvm/djvm/cli/src/shell/djvm | 16 - djvm/djvm/cli/src/shell/djvm.bat | 15 - djvm/djvm/cli/src/shell/install | 7 - djvm/djvm/shell/.gitignore | 1 - djvm/djvm/shell/djvm | 19 - djvm/djvm/shell/install | 24 - .../java/sandbox/java/lang/Appendable.java | 19 - .../main/java/sandbox/java/lang/Boolean.java | 100 --- .../src/main/java/sandbox/java/lang/Byte.java | 129 --- .../java/sandbox/java/lang/CharSequence.java | 21 - .../java/sandbox/java/lang/Character.java | 481 ----------- .../java/sandbox/java/lang/Comparable.java | 8 - .../java/lang/DJVMThrowableWrapper.java | 37 - .../main/java/sandbox/java/lang/Double.java | 163 ---- .../src/main/java/sandbox/java/lang/Enum.java | 35 - .../main/java/sandbox/java/lang/Float.java | 163 ---- .../main/java/sandbox/java/lang/Integer.java | 241 ------ .../main/java/sandbox/java/lang/Iterable.java | 15 - .../src/main/java/sandbox/java/lang/Long.java | 239 ------ .../main/java/sandbox/java/lang/Number.java | 21 - .../main/java/sandbox/java/lang/Object.java | 70 -- .../main/java/sandbox/java/lang/Runtime.java | 27 - .../main/java/sandbox/java/lang/Short.java | 128 --- .../sandbox/java/lang/StackTraceElement.java | 46 -- .../main/java/sandbox/java/lang/String.java | 424 ---------- .../java/sandbox/java/lang/StringBuffer.java | 20 - .../java/sandbox/java/lang/StringBuilder.java | 20 - .../main/java/sandbox/java/lang/System.java | 23 - .../java/sandbox/java/lang/ThreadLocal.java | 59 -- .../java/sandbox/java/lang/Throwable.java | 137 ---- .../sandbox/java/nio/charset/Charset.java | 18 - .../java/sandbox/java/util/Comparator.java | 9 - .../java/sandbox/java/util/LinkedHashMap.java | 13 - .../main/java/sandbox/java/util/Locale.java | 9 - .../src/main/java/sandbox/java/util/Map.java | 7 - .../sandbox/java/util/function/Function.java | 10 - .../sandbox/java/util/function/Supplier.java | 10 - .../java/sandbox/sun/misc/JavaLangAccess.java | 10 - .../java/sandbox/sun/misc/SharedSecrets.java | 20 - .../net/corda/djvm/SandboxConfiguration.kt | 68 -- .../net/corda/djvm/SandboxRuntimeContext.kt | 67 -- .../djvm/analysis/AnalysisConfiguration.kt | 350 -------- .../corda/djvm/analysis/AnalysisContext.kt | 53 -- .../djvm/analysis/AnalysisRuntimeContext.kt | 22 - .../djvm/analysis/ClassAndMemberVisitor.kt | 598 -------------- .../net/corda/djvm/analysis/ClassResolver.kt | 156 ---- .../corda/djvm/analysis/ExceptionResolver.kt | 41 - .../net/corda/djvm/analysis/SourceLocation.kt | 89 -- .../net/corda/djvm/analysis/Whitelist.kt | 192 ----- .../djvm/code/ClassDefinitionProvider.kt | 22 - .../net/corda/djvm/code/ClassMutator.kt | 148 ---- .../net/corda/djvm/code/DefinitionProvider.kt | 7 - .../kotlin/net/corda/djvm/code/Emitter.kt | 27 - .../net/corda/djvm/code/EmitterContext.kt | 76 -- .../net/corda/djvm/code/EmitterModule.kt | 228 ------ .../kotlin/net/corda/djvm/code/Instruction.kt | 23 - .../djvm/code/MemberDefinitionProvider.kt | 22 - .../main/kotlin/net/corda/djvm/code/Types.kt | 28 - .../code/instructions/BranchInstruction.kt | 15 - .../corda/djvm/code/instructions/CodeLabel.kt | 12 - .../code/instructions/ConstantInstruction.kt | 6 - .../DynamicInvocationInstruction.kt | 20 - .../code/instructions/IntegerInstruction.kt | 13 - .../instructions/MemberAccessInstruction.kt | 35 - .../djvm/code/instructions/MethodEntry.kt | 9 - .../instructions/NoOperationInstruction.kt | 9 - .../instructions/TableSwitchInstruction.kt | 22 - .../corda/djvm/code/instructions/TryBlock.kt | 8 - .../djvm/code/instructions/TryCatchBlock.kt | 14 - .../djvm/code/instructions/TryFinallyBlock.kt | 12 - .../djvm/code/instructions/TypeInstruction.kt | 13 - .../net/corda/djvm/costing/RuntimeCost.kt | 30 - .../corda/djvm/costing/RuntimeCostSummary.kt | 57 -- .../corda/djvm/costing/TypedRuntimeCost.kt | 73 -- .../net/corda/djvm/execution/CostSummary.kt | 37 - .../execution/DeterministicSandboxExecutor.kt | 27 - .../corda/djvm/execution/ExecutionProfile.kt | 45 -- .../corda/djvm/execution/ExecutionSummary.kt | 12 - .../execution/ExecutionSummaryWithResult.kt | 12 - .../net/corda/djvm/execution/IsolatedTask.kt | 98 --- .../corda/djvm/execution/QueueProcessor.kt | 57 -- .../corda/djvm/execution/SandboxException.kt | 34 - .../corda/djvm/execution/SandboxExecutor.kt | 222 ----- .../corda/djvm/formatting/MemberFormatter.kt | 75 -- .../kotlin/net/corda/djvm/messages/Message.kt | 53 -- .../corda/djvm/messages/MessageCollection.kt | 186 ----- .../net/corda/djvm/messages/Severity.kt | 36 - .../corda/djvm/references/AnnotationModule.kt | 36 - .../corda/djvm/references/ClassHierarchy.kt | 119 --- .../net/corda/djvm/references/ClassModule.kt | 209 ----- .../corda/djvm/references/ClassReference.kt | 10 - .../djvm/references/ClassRepresentation.kt | 26 - .../corda/djvm/references/EntityReference.kt | 8 - .../djvm/references/EntityWithAccessFlag.kt | 10 - .../net/corda/djvm/references/Member.kt | 34 - .../djvm/references/MemberInformation.kt | 17 - .../net/corda/djvm/references/MemberModule.kt | 133 --- .../corda/djvm/references/MemberReference.kt | 14 - .../net/corda/djvm/references/ReferenceMap.kt | 80 -- .../djvm/references/ReferenceWithLocation.kt | 17 - .../net/corda/djvm/rewiring/ByteCode.kt | 12 - .../net/corda/djvm/rewiring/ClassRewriter.kt | 116 --- .../net/corda/djvm/rewiring/LoadedClass.kt | 27 - .../corda/djvm/rewiring/SandboxClassLoader.kt | 314 -------- .../rewiring/SandboxClassLoadingException.kt | 35 - .../djvm/rewiring/SandboxClassRemapper.kt | 46 -- .../corda/djvm/rewiring/SandboxClassWriter.kt | 71 -- .../corda/djvm/rewiring/SandboxRemapper.kt | 71 -- .../djvm/rewiring/ThrowableWrapperFactory.kt | 152 ---- .../kotlin/net/corda/djvm/rules/ClassRule.kt | 28 - .../net/corda/djvm/rules/InstructionRule.kt | 28 - .../kotlin/net/corda/djvm/rules/MemberRule.kt | 28 - .../main/kotlin/net/corda/djvm/rules/Rule.kt | 23 - .../AlwaysInheritFromSandboxedObject.kt | 65 -- .../implementation/AlwaysUseExactMath.kt | 42 - .../AlwaysUseNonSynchronizedMethods.kt | 30 - .../AlwaysUseStrictFloatingPointArithmetic.kt | 32 - .../rules/implementation/ArgumentUnwrapper.kt | 35 - .../DisallowCatchingBlacklistedExceptions.kt | 62 -- .../DisallowDynamicInvocation.kt | 18 - .../DisallowNonDeterministicMethods.kt | 50 -- .../DisallowOverriddenSandboxPackage.kt | 17 - .../DisallowUnsupportedApiVersions.kt | 31 - .../HandleExceptionUnwrapper.kt | 46 -- .../rules/implementation/IgnoreBreakpoints.kt | 19 - .../IgnoreSynchronizedBlocks.kt | 25 - .../rules/implementation/ReturnTypeWrapper.kt | 27 - .../implementation/RewriteClassMethods.kt | 56 -- .../implementation/RewriteObjectMethods.kt | 29 - .../implementation/StaticConstantRemover.kt | 30 - .../implementation/StringConstantWrapper.kt | 22 - .../implementation/StubOutFinalizerMethods.kt | 35 - .../implementation/StubOutNativeMethods.kt | 36 - .../StubOutReflectionMethods.kt | 35 - .../implementation/ThrowExceptionWrapper.kt | 20 - .../instrumentation/TraceAllocations.kt | 47 -- .../instrumentation/TraceInvocations.kt | 24 - .../instrumentation/TraceJumps.kt | 24 - .../instrumentation/TraceThrows.kt | 24 - .../net/corda/djvm/source/ClassSource.kt | 48 -- .../djvm/source/JarInputStreamIterator.kt | 62 -- .../net/corda/djvm/source/PathClassSource.kt | 35 - .../corda/djvm/source/SourceClassLoader.kt | 172 ---- .../net/corda/djvm/utilities/Discovery.kt | 31 - .../net/corda/djvm/utilities/Logging.kt | 10 - .../net/corda/djvm/utilities/Processor.kt | 30 - .../djvm/validation/ConstraintProvider.kt | 68 -- .../validation/ReferenceValidationSummary.kt | 18 - .../net/corda/djvm/validation/RuleContext.kt | 70 -- .../corda/djvm/validation/RuleValidator.kt | 81 -- djvm/djvm/src/main/kotlin/sandbox/Task.kt | 27 - .../src/main/kotlin/sandbox/java/lang/DJVM.kt | 329 -------- .../kotlin/sandbox/java/lang/DJVMException.kt | 12 - .../djvm/costing/RuntimeCostAccounter.kt | 110 --- .../djvm/costing/ThresholdViolationError.kt | 9 - .../corda/djvm/rules/RuleViolationError.kt | 10 - .../test/java/net/corda/djvm/WithJava.java | 28 - .../djvm/execution/SandboxEnumJavaTest.java | 105 --- .../execution/SandboxExecutorJavaTest.java | 64 -- .../SandboxObjectHashCodeJavaTest.java | 91 --- .../execution/SandboxThrowableJavaTest.java | 78 -- .../djvm/src/test/kotlin/foo/bar/sandbox/A.kt | 9 - .../djvm/src/test/kotlin/foo/bar/sandbox/B.kt | 10 - .../djvm/src/test/kotlin/foo/bar/sandbox/C.kt | 11 - .../test/kotlin/foo/bar/sandbox/Callable.kt | 13 - .../src/test/kotlin/foo/bar/sandbox/Empty.kt | 5 - .../kotlin/foo/bar/sandbox/KotlinClass.kt | 9 - .../test/kotlin/foo/bar/sandbox/MyObject.kt | 3 - .../kotlin/foo/bar/sandbox/StrictFloat.kt | 10 - .../net/corda/djvm/DJVMExceptionTest.kt | 170 ---- .../test/kotlin/net/corda/djvm/DJVMTest.kt | 150 ---- .../test/kotlin/net/corda/djvm/TestBase.kt | 354 -------- .../test/kotlin/net/corda/djvm/Utilities.kt | 14 - .../analysis/ClassAndMemberVisitorTest.kt | 235 ------ .../corda/djvm/analysis/ClassResolverTest.kt | 50 -- .../corda/djvm/analysis/SourceLocationTest.kt | 40 - .../net/corda/djvm/analysis/WhitelistTest.kt | 44 - .../djvm/annotations/NonDeterministic.kt | 17 - .../djvm/assertions/AssertionExtensions.kt | 72 -- .../assertions/AssertiveClassHierarchy.kt | 24 - .../AssertiveClassHierarchyWithClass.kt | 47 -- ...sertiveClassHierarchyWithClassAndMember.kt | 28 - .../assertions/AssertiveClassWithByteCode.kt | 41 - .../djvm/assertions/AssertiveDJVMObject.kt | 26 - .../djvm/assertions/AssertiveMessages.kt | 68 -- .../djvm/assertions/AssertiveReferenceMap.kt | 46 -- .../AssertiveReferenceMapWithEntity.kt | 21 - .../assertions/AssertiveRuntimeCostSummary.kt | 58 -- .../net/corda/djvm/code/ClassMutatorTest.kt | 76 -- .../net/corda/djvm/code/EmitterModuleTest.kt | 48 -- .../net/corda/djvm/costing/RuntimeCostTest.kt | 29 - .../corda/djvm/execution/SandboxEnumTest.kt | 86 -- .../djvm/execution/SandboxExecutorTest.kt | 762 ------------------ .../djvm/execution/SandboxThrowableTest.kt | 95 --- .../djvm/formatter/MemberFormatterTest.kt | 93 --- .../djvm/references/ClassHierarchyTest.kt | 196 ----- .../corda/djvm/references/ClassModuleTest.kt | 68 -- .../corda/djvm/references/MemberModuleTest.kt | 144 ---- .../corda/djvm/rewiring/ClassRewriterTest.kt | 169 ---- .../djvm/rules/ReferenceExtractorTest.kt | 35 - .../net/corda/djvm/rules/RuleValidatorTest.kt | 67 -- .../djvm/source/SourceClassLoaderTest.kt | 112 --- .../net/corda/djvm/utilities/DiscoveryTest.kt | 33 - .../sandbox/greymalkin/StringReturner.kt | 8 - .../test/resources/jar-with-single-class.jar | Bin 805 -> 0 bytes .../test/resources/jar-with-two-classes.jar | Bin 1208 -> 0 bytes djvm/djvm/src/test/resources/log4j2-test.xml | 17 - djvm/gradle.properties | 14 - djvm/gradle/wrapper/gradle-wrapper.jar | Bin 55190 -> 0 bytes djvm/gradle/wrapper/gradle-wrapper.properties | 5 - djvm/gradlew | 172 ---- djvm/gradlew.bat | 84 -- djvm/settings.gradle | 4 - docs/source/key-concepts-djvm.rst | 11 +- 232 files changed, 10 insertions(+), 15525 deletions(-) delete mode 100644 djvm/.gitignore delete mode 100644 djvm/build.gradle delete mode 100644 djvm/djvm/build.gradle delete mode 100644 djvm/djvm/cli/build.gradle delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/BuildCommand.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CheckCommand.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/ClassCommand.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CommandBase.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Commands.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/InspectionCommand.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/NewCommand.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Program.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/RunCommand.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/ShowCommand.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/TreeCommand.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Utilities.kt delete mode 100644 djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/VersionProvider.kt delete mode 100644 djvm/djvm/cli/src/main/resources/log4j2.xml delete mode 100755 djvm/djvm/cli/src/shell/djvm delete mode 100644 djvm/djvm/cli/src/shell/djvm.bat delete mode 100755 djvm/djvm/cli/src/shell/install delete mode 100644 djvm/djvm/shell/.gitignore delete mode 100755 djvm/djvm/shell/djvm delete mode 100755 djvm/djvm/shell/install delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Appendable.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Boolean.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Byte.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/CharSequence.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Character.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Comparable.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/DJVMThrowableWrapper.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Double.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Enum.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Float.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Integer.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Iterable.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Long.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Number.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Object.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Runtime.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Short.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/StackTraceElement.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/String.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/StringBuffer.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/StringBuilder.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/System.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/ThreadLocal.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/lang/Throwable.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/nio/charset/Charset.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/util/Comparator.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/util/LinkedHashMap.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/util/Locale.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/util/Map.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/util/function/Function.java delete mode 100644 djvm/djvm/src/main/java/sandbox/java/util/function/Supplier.java delete mode 100644 djvm/djvm/src/main/java/sandbox/sun/misc/JavaLangAccess.java delete mode 100644 djvm/djvm/src/main/java/sandbox/sun/misc/SharedSecrets.java delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/SandboxConfiguration.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/SandboxRuntimeContext.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisConfiguration.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisContext.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisRuntimeContext.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ClassAndMemberVisitor.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ClassResolver.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ExceptionResolver.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/SourceLocation.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/Whitelist.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/ClassDefinitionProvider.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/ClassMutator.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/DefinitionProvider.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/Emitter.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/EmitterContext.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/EmitterModule.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/Instruction.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/MemberDefinitionProvider.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/Types.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/BranchInstruction.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/CodeLabel.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/ConstantInstruction.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/DynamicInvocationInstruction.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/IntegerInstruction.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/MemberAccessInstruction.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/MethodEntry.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/NoOperationInstruction.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/TableSwitchInstruction.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/TryBlock.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/TryCatchBlock.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/TryFinallyBlock.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/TypeInstruction.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/costing/RuntimeCost.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/costing/RuntimeCostSummary.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/costing/TypedRuntimeCost.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/execution/CostSummary.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/execution/DeterministicSandboxExecutor.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/execution/ExecutionProfile.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/execution/ExecutionSummary.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/execution/ExecutionSummaryWithResult.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/execution/IsolatedTask.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/execution/QueueProcessor.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/execution/SandboxException.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/execution/SandboxExecutor.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/formatting/MemberFormatter.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/messages/Message.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/messages/MessageCollection.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/messages/Severity.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/AnnotationModule.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/ClassHierarchy.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/ClassModule.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/ClassReference.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/ClassRepresentation.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/EntityReference.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/EntityWithAccessFlag.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/Member.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/MemberInformation.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/MemberModule.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/MemberReference.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/ReferenceMap.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/references/ReferenceWithLocation.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rewiring/ByteCode.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rewiring/ClassRewriter.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rewiring/LoadedClass.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rewiring/SandboxClassLoader.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rewiring/SandboxClassLoadingException.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rewiring/SandboxClassRemapper.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rewiring/SandboxClassWriter.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rewiring/SandboxRemapper.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rewiring/ThrowableWrapperFactory.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/ClassRule.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/InstructionRule.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/MemberRule.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/Rule.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/AlwaysInheritFromSandboxedObject.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/AlwaysUseExactMath.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/AlwaysUseNonSynchronizedMethods.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/AlwaysUseStrictFloatingPointArithmetic.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/ArgumentUnwrapper.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/DisallowCatchingBlacklistedExceptions.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/DisallowDynamicInvocation.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/DisallowNonDeterministicMethods.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/DisallowOverriddenSandboxPackage.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/DisallowUnsupportedApiVersions.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/HandleExceptionUnwrapper.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/IgnoreBreakpoints.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/IgnoreSynchronizedBlocks.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/ReturnTypeWrapper.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/RewriteClassMethods.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/RewriteObjectMethods.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/StaticConstantRemover.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/StringConstantWrapper.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/StubOutFinalizerMethods.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/StubOutNativeMethods.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/StubOutReflectionMethods.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/ThrowExceptionWrapper.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/instrumentation/TraceAllocations.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/instrumentation/TraceInvocations.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/instrumentation/TraceJumps.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/rules/implementation/instrumentation/TraceThrows.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/source/ClassSource.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/source/JarInputStreamIterator.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/source/PathClassSource.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/source/SourceClassLoader.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/utilities/Discovery.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/utilities/Logging.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/utilities/Processor.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/validation/ConstraintProvider.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/validation/ReferenceValidationSummary.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/validation/RuleContext.kt delete mode 100644 djvm/djvm/src/main/kotlin/net/corda/djvm/validation/RuleValidator.kt delete mode 100644 djvm/djvm/src/main/kotlin/sandbox/Task.kt delete mode 100644 djvm/djvm/src/main/kotlin/sandbox/java/lang/DJVM.kt delete mode 100644 djvm/djvm/src/main/kotlin/sandbox/java/lang/DJVMException.kt delete mode 100644 djvm/djvm/src/main/kotlin/sandbox/net/corda/djvm/costing/RuntimeCostAccounter.kt delete mode 100644 djvm/djvm/src/main/kotlin/sandbox/net/corda/djvm/costing/ThresholdViolationError.kt delete mode 100644 djvm/djvm/src/main/kotlin/sandbox/net/corda/djvm/rules/RuleViolationError.kt delete mode 100644 djvm/djvm/src/test/java/net/corda/djvm/WithJava.java delete mode 100644 djvm/djvm/src/test/java/net/corda/djvm/execution/SandboxEnumJavaTest.java delete mode 100644 djvm/djvm/src/test/java/net/corda/djvm/execution/SandboxExecutorJavaTest.java delete mode 100644 djvm/djvm/src/test/java/net/corda/djvm/execution/SandboxObjectHashCodeJavaTest.java delete mode 100644 djvm/djvm/src/test/java/net/corda/djvm/execution/SandboxThrowableJavaTest.java delete mode 100644 djvm/djvm/src/test/kotlin/foo/bar/sandbox/A.kt delete mode 100644 djvm/djvm/src/test/kotlin/foo/bar/sandbox/B.kt delete mode 100644 djvm/djvm/src/test/kotlin/foo/bar/sandbox/C.kt delete mode 100644 djvm/djvm/src/test/kotlin/foo/bar/sandbox/Callable.kt delete mode 100644 djvm/djvm/src/test/kotlin/foo/bar/sandbox/Empty.kt delete mode 100644 djvm/djvm/src/test/kotlin/foo/bar/sandbox/KotlinClass.kt delete mode 100644 djvm/djvm/src/test/kotlin/foo/bar/sandbox/MyObject.kt delete mode 100644 djvm/djvm/src/test/kotlin/foo/bar/sandbox/StrictFloat.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/DJVMExceptionTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/DJVMTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/TestBase.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/Utilities.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/analysis/ClassAndMemberVisitorTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/analysis/ClassResolverTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/analysis/SourceLocationTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/analysis/WhitelistTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/annotations/NonDeterministic.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertionExtensions.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertiveClassHierarchy.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertiveClassHierarchyWithClass.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertiveClassHierarchyWithClassAndMember.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertiveClassWithByteCode.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertiveDJVMObject.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertiveMessages.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertiveReferenceMap.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertiveReferenceMapWithEntity.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/assertions/AssertiveRuntimeCostSummary.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/code/ClassMutatorTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/code/EmitterModuleTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/costing/RuntimeCostTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/execution/SandboxEnumTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/execution/SandboxExecutorTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/execution/SandboxThrowableTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/formatter/MemberFormatterTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/references/ClassHierarchyTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/references/ClassModuleTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/references/MemberModuleTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/rewiring/ClassRewriterTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/rules/ReferenceExtractorTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/rules/RuleValidatorTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/source/SourceClassLoaderTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/net/corda/djvm/utilities/DiscoveryTest.kt delete mode 100644 djvm/djvm/src/test/kotlin/sandbox/greymalkin/StringReturner.kt delete mode 100644 djvm/djvm/src/test/resources/jar-with-single-class.jar delete mode 100644 djvm/djvm/src/test/resources/jar-with-two-classes.jar delete mode 100644 djvm/djvm/src/test/resources/log4j2-test.xml delete mode 100644 djvm/gradle.properties delete mode 100644 djvm/gradle/wrapper/gradle-wrapper.jar delete mode 100644 djvm/gradle/wrapper/gradle-wrapper.properties delete mode 100755 djvm/gradlew delete mode 100644 djvm/gradlew.bat delete mode 100644 djvm/settings.gradle diff --git a/djvm/.gitignore b/djvm/.gitignore deleted file mode 100644 index 9c2a46a770..0000000000 --- a/djvm/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# DJVM-specific files -**/tmp/ -*.log -*.log.gz - -# IntelliJ -*.iml -*.ipr -*.iws -.idea/ - -**/out/ - diff --git a/djvm/build.gradle b/djvm/build.gradle deleted file mode 100644 index d03281f8c3..0000000000 --- a/djvm/build.gradle +++ /dev/null @@ -1,122 +0,0 @@ -buildscript { - ext { - corda_djvm_version = '5.0-SNAPSHOT' - artifactory_contextUrl = 'https://software.r3.com/artifactory' - } - - repositories { - mavenCentral() - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -plugins { - id 'net.corda.plugins.publish-utils' version '4.0.44' apply false - id 'com.github.johnrengelman.shadow' version '5.0.0' apply false - id 'com.jfrog.artifactory' version '4.7.3' apply false - id 'com.jfrog.bintray' version '1.4' apply false - id 'com.gradle.build-scan' version '2.2.1' -} - -import static org.gradle.api.JavaVersion.* -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -subprojects { - group 'net.corda' - version corda_djvm_version - - repositories { - mavenCentral() - jcenter() - } - - tasks.withType(JavaCompile) { - sourceCompatibility = VERSION_1_8 - targetCompatibility = VERSION_1_8 - options.encoding = 'UTF-8' - } - - tasks.withType(KotlinCompile) { - kotlinOptions { - languageVersion = '1.2' - apiVersion = '1.2' - jvmTarget = VERSION_1_8 - javaParameters = true // Useful for reflection. - freeCompilerArgs = ['-Xjvm-default=enable'] - } - } - - tasks.withType(Jar) { task -> - manifest { - attributes('Corda-Vendor': 'Corda Open Source') - attributes('Automatic-Module-Name': "net.corda.${task.project.name.replaceAll('-', '.')}") - } - } - - tasks.withType(Test) { - useJUnitPlatform() - - // Prevent the project from creating temporary files outside of the build directory. - systemProperty 'java.io.tmpdir', buildDir.absolutePath - } -} - -apply plugin: 'net.corda.plugins.publish-utils' -apply plugin: 'com.jfrog.artifactory' - -bintrayConfig { - user = System.getenv('CORDA_BINTRAY_USER') - key = System.getenv('CORDA_BINTRAY_KEY') - repo = 'corda' - org = 'r3' - licenses = ['Apache-2.0'] - vcsUrl = 'https://github.com/corda/corda' - projectUrl = 'https://github.com/corda/corda' - gpgSign = true - gpgPassphrase = System.getenv('CORDA_BINTRAY_GPG_PASSPHRASE') - publications = [ - 'corda-djvm', - 'corda-djvm-cli' - ] - license { - name = 'Apache-2.0' - url = 'https://www.apache.org/licenses/LICENSE-2.0' - distribution = 'repo' - } - developer { - id = 'R3' - name = 'R3' - email = 'dev@corda.net' - } -} - -artifactory { - publish { - contextUrl = artifactory_contextUrl - repository { - repoKey = 'corda-dev' - username = System.getenv('CORDA_ARTIFACTORY_USERNAME') - password = System.getenv('CORDA_ARTIFACTORY_PASSWORD') - } - - defaults { - // The root project has applied 'publish-utils' but has nothing to publish. - if (project != rootProject) { - publications(project.extensions.publish.name()) - } - } - } -} - -wrapper { - gradleVersion = "5.4.1" - distributionType = Wrapper.DistributionType.ALL -} - -buildScan { - termsOfServiceUrl = 'https://gradle.com/terms-of-service' - termsOfServiceAgree = 'yes' -} diff --git a/djvm/djvm/build.gradle b/djvm/djvm/build.gradle deleted file mode 100644 index b0d4baaed7..0000000000 --- a/djvm/djvm/build.gradle +++ /dev/null @@ -1,90 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.jvm' - id 'com.github.johnrengelman.shadow' - id 'net.corda.plugins.publish-utils' - id 'com.jfrog.artifactory' - id 'idea' -} - -description 'Corda deterministic JVM sandbox' - -repositories { - maven { - url "$artifactory_contextUrl/corda-dev" - } -} - -configurations { - testImplementation.extendsFrom shadow - jdkRt.resolutionStrategy { - // Always check the repository for a newer SNAPSHOT. - cacheChangingModulesFor 0, 'seconds' - } -} - -dependencies { - shadow "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - shadow "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - shadow "org.slf4j:slf4j-api:$slf4j_version" - - // ASM: byte code manipulation library - implementation "org.ow2.asm:asm:$asm_version" - implementation "org.ow2.asm:asm-commons:$asm_version" - - // ClassGraph: classpath scanning - shadow "io.github.classgraph:classgraph:$class_graph_version" - - testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version" - testRuntimeOnly "org.junit.platform:junit-platform-launcher:$junit_platform_version" - - // Test utilities - testImplementation "org.assertj:assertj-core:$assertj_version" - testImplementation "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version" - jdkRt "net.corda:deterministic-rt:latest.integration" -} - -jar.enabled = false - -shadowJar { - baseName 'corda-djvm' - classifier '' - relocate 'org.objectweb.asm', 'djvm.org.objectweb.asm' - - // These particular classes are only needed to "bootstrap" - // the compilation of the other sandbox classes. At runtime, - // we will generate better versions from deterministic-rt.jar. - exclude 'sandbox/java/lang/Appendable.class' - exclude 'sandbox/java/lang/CharSequence.class' - exclude 'sandbox/java/lang/Character\$Subset.class' - exclude 'sandbox/java/lang/Character\$Unicode*.class' - exclude 'sandbox/java/lang/Comparable.class' - exclude 'sandbox/java/lang/Enum.class' - exclude 'sandbox/java/lang/Iterable.class' - exclude 'sandbox/java/lang/StackTraceElement.class' - exclude 'sandbox/java/lang/StringBuffer.class' - exclude 'sandbox/java/lang/StringBuilder.class' - exclude 'sandbox/java/nio/**' - exclude 'sandbox/java/util/**' -} -assemble.dependsOn shadowJar - -tasks.withType(Test) { - systemProperty 'deterministic-rt.path', configurations.jdkRt.asPath -} - -artifacts { - publish shadowJar -} - -publish { - dependenciesFrom configurations.shadow - name shadowJar.baseName -} - -idea { - module { - downloadJavadoc = true - downloadSources = true - } -} diff --git a/djvm/djvm/cli/build.gradle b/djvm/djvm/cli/build.gradle deleted file mode 100644 index 3c3562bbd0..0000000000 --- a/djvm/djvm/cli/build.gradle +++ /dev/null @@ -1,64 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.jvm' - id 'com.github.johnrengelman.shadow' - id 'net.corda.plugins.publish-utils' - id 'com.jfrog.artifactory' -} - -description 'Corda deterministic JVM sandbox command-line tool' - -ext { - djvmName = 'corda-djvm-cli' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation "org.jetbrains.kotlin:kotlin-reflect" - implementation "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version" - implementation "org.apache.logging.log4j:log4j-core:$log4j_version" - implementation "com.jcabi:jcabi-manifests:$jcabi_manifests_version" - - implementation "info.picocli:picocli:$picocli_version" - implementation project(path: ':djvm', configuration: 'shadow') -} - -jar.enabled = false - -shadowJar { - baseName djvmName - classifier '' - manifest { - attributes( - 'Automatic-Module-Name': 'net.corda.djvm.cli', - 'Main-Class': 'net.corda.djvm.tools.cli.Program', - 'Build-Date': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'Class-Path': 'tmp/' - ) - } -} - -task shadowZip(type: Zip) { - archiveBaseName = djvmName - archiveClassifier = '' - - from(shadowJar) { - rename "$djvmName-(.*).jar", "${djvmName}.jar" - } - from('src/shell/') { - fileMode = 0755 - } - zip64 true -} - -assemble.dependsOn shadowZip - -artifacts { - publish shadowZip -} - -publish { - dependenciesFrom configurations.shadow - publishSources = false - publishJavadoc = false - name shadowZip.baseName -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/BuildCommand.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/BuildCommand.kt deleted file mode 100644 index 7fafd5d743..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/BuildCommand.kt +++ /dev/null @@ -1,39 +0,0 @@ -package net.corda.djvm.tools.cli - -import picocli.CommandLine.Command -import picocli.CommandLine.Parameters -import java.nio.file.Path - -@Command( - name = "build", - description = ["Build one or more Java source files, each implementing the sandbox runnable interface " + - "required for execution in the deterministic sandbox."] -) -@Suppress("KDocMissingDocumentation") -class BuildCommand : CommandBase() { - - @Parameters - var files: Array = emptyArray() - - override fun validateArguments() = files.isNotEmpty() - - override fun handleCommand(): Boolean { - val codePath = createCodePath() - val files = files.getFileNames { codePath.resolve(it) } - printVerbose("Compiling ${files.joinToString(", ")}...") - ProcessBuilder("javac", "-cp", "tmp:$jarPath", *files).apply { - inheritIO() - environment().putAll(System.getenv()) - start().apply { - waitFor() - return (exitValue() == 0).apply { - if (this) { - printInfo("Build succeeded") - } - } - } - } - return true - } - -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CheckCommand.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CheckCommand.kt deleted file mode 100644 index 6c6e27ea08..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CheckCommand.kt +++ /dev/null @@ -1,34 +0,0 @@ -package net.corda.djvm.tools.cli - -import net.corda.djvm.source.ClassSource -import picocli.CommandLine.Command -import picocli.CommandLine.Parameters - -@Command( - name = "check", - description = ["Statically validate that a class or set of classes (and their dependencies) do not violate any " + - "constraints posed by the deterministic sandbox environment."] -) -@Suppress("KDocMissingDocumentation") -class CheckCommand : ClassCommand() { - - override val filters: Array - get() = classes - - @Parameters(description = ["The partial or fully qualified names of the Java classes to analyse and validate."]) - var classes: Array = emptyArray() - - override fun printSuccess(classes: List>) { - for (clazz in classes.sortedBy { it.name }) { - printVerbose("Class ${clazz.name} validated") - } - printVerbose() - } - - override fun processClasses(classes: List>) { - val sources = classes.map { ClassSource.fromClassName(it.name) } - val summary = executor.validate(*sources.toTypedArray()) - printMessages(summary.messages, summary.classOrigins) - } - -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/ClassCommand.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/ClassCommand.kt deleted file mode 100644 index db6460a2a8..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/ClassCommand.kt +++ /dev/null @@ -1,204 +0,0 @@ -package net.corda.djvm.tools.cli - -import net.corda.djvm.SandboxConfiguration -import net.corda.djvm.analysis.AnalysisConfiguration -import net.corda.djvm.analysis.Whitelist -import net.corda.djvm.execution.* -import net.corda.djvm.references.ClassModule -import net.corda.djvm.source.ClassSource -import net.corda.djvm.source.SourceClassLoader -import net.corda.djvm.utilities.Discovery -import djvm.org.objectweb.asm.ClassReader -import picocli.CommandLine.Option -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -@Suppress("KDocMissingDocumentation", "MemberVisibilityCanBePrivate") -abstract class ClassCommand : CommandBase() { - - @Option( - names = ["-p", "--profile"], - description = ["The execution profile to use (DEFAULT, UNLIMITED, DISABLE_BRANCHING or DISABLE_THROWS)."] - ) - var profile: ExecutionProfile = ExecutionProfile.DEFAULT - - @Option(names = ["--ignore-rules"], description = ["Disable all rules pertaining to the sandbox."]) - var ignoreRules: Boolean = false - - @Option(names = ["--ignore-emitters"], description = ["Disable all emitters defined for the sandbox."]) - var ignoreEmitters: Boolean = false - - @Option(names = ["--ignore-definition-providers"], description = ["Disable all definition providers."]) - var ignoreDefinitionProviders: Boolean = false - - @Option(names = ["-c", "--classpath"], description = ["Additions to the default class path."], split = ":") - var classPath: Array = emptyArray() - - @Option(names = ["--disable-tracing"], description = ["Disable tracing in the sandbox."]) - var disableTracing: Boolean = false - - @Option(names = ["--analyze-annotations"], description = ["Analyze all annotations even if they are not " + - "explicitly referenced."]) - var analyzeAnnotations: Boolean = false - - @Option( - names = ["--prefix-filters"], - description = ["Only record messages matching one of the provided prefixes."], - split = ":" - ) - var prefixFilters: Array = emptyArray() - - abstract val filters: Array - - private val classModule = ClassModule() - - private lateinit var classLoader: ClassLoader - - protected var executor = SandboxExecutor(SandboxConfiguration.DEFAULT) - - abstract fun processClasses(classes: List>) - - open fun printSuccess(classes: List>) {} - - override fun validateArguments() = filters.isNotEmpty() - - override fun handleCommand(): Boolean { - val configuration = getConfiguration(Whitelist.MINIMAL) - classLoader = SourceClassLoader(getClasspath(), configuration.analysisConfiguration.classResolver) - createExecutor(configuration) - - val classes = discoverClasses(filters).onEmpty { - throw Exception("Could not find any classes matching ${filters.joinToString(" ")} on the " + - "system class path") - } - - return try { - processClasses(classes) - printSuccess(classes) - true - } catch (exception: Throwable) { - printException(exception) - if (exception is SandboxException) { - printCosts(exception.executionSummary.costs) - } - false - } - } - - protected fun printCosts(costs: CostSummary) { - if (disableTracing) { - return - } - printInfo("Runtime Cost Summary:") - printInfo(" - allocations = @|yellow ${costs.allocations}|@") - printInfo(" - invocations = @|yellow ${costs.invocations}|@") - printInfo(" - jumps = @|yellow ${costs.jumps}|@") - printInfo(" - throws = @|yellow ${costs.throws}|@") - printInfo() - } - - private fun discoverClasses(filters: Array): List> { - return findDiscoverableRunnables(filters) + findReferencedClasses(filters) + findClassesInJars(filters) - } - - private fun findDiscoverableRunnables(filters: Array): List> { - val classes = find>() - val applicableFilters = filters - .filter { !isJarFile(it) && !isFullClassName(it) } - val filteredClasses = applicableFilters - .flatMap { filter -> - classes.filter { clazz -> - clazz.name.contains(filter, true) - } - } - - if (applicableFilters.isNotEmpty() && filteredClasses.isEmpty()) { - throw Exception("Could not find any classes implementing ${java.util.function.Function::class.java.simpleName} " + - "whose name matches '${applicableFilters.joinToString(" ")}'") - } - - if (applicableFilters.isNotEmpty()) { - printVerbose("Class path: $userClassPath") - printVerbose("Discovered runnables on the class path:") - for (clazz in classes) { - printVerbose(" - ${clazz.name}") - } - printVerbose() - } - return filteredClasses - } - - private fun findReferencedClasses(filters: Array): List> { - return filters.filter { !isJarFile(it) && isFullClassName(it) }.map { - val className = classModule.getFormattedClassName(it) - printVerbose("Looking up class $className...") - lookUpClass(className) - } - } - - private fun findClassesInJars(filters: Array): List> { - return filters.filter { isJarFile(it) }.flatMap { jarFile -> - mutableListOf>().apply { - ClassSource.fromPath(Paths.get(jarFile)).getStreamIterator().forEach { - val reader = ClassReader(it) - val className = classModule.getFormattedClassName(reader.className) - printVerbose("Looking up class $className in $jarFile...") - this.add(lookUpClass(className)) - } - } - } - } - - private fun lookUpClass(className: String): Class<*> { - return try { - classLoader.loadClass(className) - } catch (exception: NoClassDefFoundError) { - val reference = exception.message?.let { - "referenced class ${classModule.getFormattedClassName(it)} in " - } ?: "" - throw Exception("Unable to load ${reference}type $className (is it present on the class path?)") - } catch (exception: TypeNotPresentException) { - val reference = exception.typeName() ?: "" - throw Exception("Type $reference not present in class $className") - } catch (exception: Throwable) { - throw Exception("Unable to load type $className (is it present on the class path?)") - } - } - - private fun isJarFile(filter: String) = Files.exists(Paths.get(filter)) && filter.endsWith(".jar", true) - - private fun isFullClassName(filter: String) = filter.count { it == '.' } > 0 - - private fun getClasspath() = - classPath.toList() + filters.filter { it.endsWith(".jar", true) }.map { Paths.get(it) } - - private fun getConfiguration(whitelist: Whitelist): SandboxConfiguration { - return SandboxConfiguration.of( - profile = profile, - rules = if (ignoreRules) { emptyList() } else { Discovery.find() }, - emitters = ignoreEmitters.emptyListIfTrueOtherwiseNull(), - definitionProviders = if (ignoreDefinitionProviders) { emptyList() } else { Discovery.find() }, - enableTracing = !disableTracing, - analysisConfiguration = AnalysisConfiguration.createRoot( - whitelist = whitelist, - minimumSeverityLevel = level, - analyzeAnnotations = analyzeAnnotations, - prefixFilters = prefixFilters.toList(), - sourceClassLoaderFactory = { classResolver, bootstrapClassLoader -> - SourceClassLoader(getClasspath(), classResolver, bootstrapClassLoader) - } - ) - ) - } - - private fun createExecutor(configuration: SandboxConfiguration) { - executor = SandboxExecutor(configuration) - } - - private fun Boolean.emptyListIfTrueOtherwiseNull(): List? = when (this) { - true -> emptyList() - false -> null - } - -} \ No newline at end of file diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CommandBase.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CommandBase.kt deleted file mode 100644 index 603c480af4..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CommandBase.kt +++ /dev/null @@ -1,279 +0,0 @@ -package net.corda.djvm.tools.cli - -import net.corda.djvm.analysis.Whitelist -import net.corda.djvm.execution.SandboxException -import net.corda.djvm.messages.MessageCollection -import net.corda.djvm.messages.Severity -import net.corda.djvm.references.ClassReference -import net.corda.djvm.references.EntityReference -import net.corda.djvm.references.MemberReference -import net.corda.djvm.rewiring.SandboxClassLoadingException -import org.apache.logging.log4j.Level -import org.apache.logging.log4j.core.config.Configurator -import picocli.CommandLine -import picocli.CommandLine.Help.Ansi -import picocli.CommandLine.Option -import java.nio.file.Path -import java.util.concurrent.Callable - -@Suppress("KDocMissingDocumentation") -abstract class CommandBase : Callable { - - @Option( - names = ["-l", "--level"], - description = ["The minimum severity level to log (TRACE, DEBUG, INFO, WARNING or ERROR."], - converter = [SeverityConverter::class] - ) - protected var level: Severity = Severity.WARNING - - @Option( - names = ["-q", "--quiet"], - description = ["Only print important messages to standard output."] - ) - private var quiet: Boolean = false - - @Option( - names = ["-v", "--verbose"], - description = ["Enable verbose logging."] - ) - private var verbose: Boolean = false - - @Option( - names = ["--debug"], - description = ["Print full stack traces upon error."] - ) - private var debug: Boolean = false - - @Option( - names = ["--colors"], - description = ["Use colors when printing to terminal."] - ) - private var useColors: Boolean = false - - @Option( - names = ["--no-colors"], - description = ["Do not use colors when printing to terminal."] - ) - private var useNoColors: Boolean = false - - @Option( - names = ["--compact"], - description = ["Print compact errors and warnings."] - ) - private var compact: Boolean = false - - @Option( - names = ["--print-origins"], - description = ["Print origins for errors and warnings."] - ) - private var printOrigins: Boolean = false - - private val ansi: Ansi - get() = when { - useNoColors -> Ansi.OFF - useColors -> Ansi.ON - else -> Ansi.AUTO - } - - - class SeverityConverter : CommandLine.ITypeConverter { - override fun convert(value: String): Severity { - return try { - when (value.toUpperCase()) { - "INFO" -> Severity.INFORMATIONAL - else -> Severity.valueOf(value.toUpperCase()) - } - } catch (exception: Exception) { - val candidates = Severity.values().filter { it.name.startsWith(value, true) } - if (candidates.size == 1) { - candidates.first() - } else { - println("ERROR: Must be one of ${Severity.values().joinToString(", ") { it.name }}") - Severity.INFORMATIONAL - } - } - } - } - - override fun call(): Boolean { - if (!validateArguments()) { - CommandLine.usage(this, System.err) - return false - } - if (verbose && quiet) { - printError("Error: Cannot set verbose and quiet modes at the same time") - return false - } - configureLogging() - return try { - handleCommand() - } catch (exception: Throwable) { - printException(exception) - false - } - } - - private fun configureLogging() { - val logLevel = when(level) { - Severity.ERROR -> Level.ERROR - Severity.WARNING -> Level.WARN - Severity.INFORMATIONAL -> Level.INFO - Severity.DEBUG -> Level.DEBUG - Severity.TRACE -> Level.TRACE - } - Configurator.setRootLevel(logLevel) - } - - protected fun printException(exception: Throwable) = when (exception) { - is SandboxClassLoadingException -> { - printMessages(exception.messages, exception.classOrigins) - printError() - } - is SandboxException -> { - val cause = exception.cause - when (cause) { - is SandboxClassLoadingException -> { - printMessages(cause.messages, cause.classOrigins) - printError() - } - else -> { - if (debug) { - exception.exception.printStackTrace(System.err) - } else { - printError("Error: ${errorMessage(exception.exception)}") - } - printError() - } - } - } - else -> { - if (debug) { - exception.printStackTrace(System.err) - } else { - printError("Error: ${errorMessage(exception)}") - printError() - } - } - } - - private fun errorMessage(exception: Throwable): String { - return when (exception) { - is StackOverflowError -> "Stack overflow" - is OutOfMemoryError -> "Out of memory" - is ThreadDeath -> "Thread death" - else -> { - val message = exception.message - when { - message.isNullOrBlank() -> exception.javaClass.simpleName - else -> message!! - } - } - } - } - - protected fun printMessages(messages: MessageCollection, origins: Map> = emptyMap()) { - val sortedMessages = messages.sorted() - val errorCount = messages.errorCount.countOf("error") - val warningCount = messages.warningCount.countOf("warning") - printInfo("Found $errorCount and $warningCount") - if (!compact) { - printInfo() - } - - var first = true - for (message in sortedMessages) { - val severityColor = message.severity.color ?: "blue" - val location = message.location.format().let { - when { - it.isNotBlank() -> "in $it: " - else -> it - } - } - if (compact) { - printError(" - @|$severityColor ${message.severity}|@ $location${message.message}.") - } else { - if (!first) { - printError() - } - printError(" - @|$severityColor ${message.severity}|@ $location\n ${message.message}.") - } - if (printOrigins) { - val classOrigins = origins[message.location.className.replace("/", ".")] ?: emptySet() - for (classOrigin in classOrigins.groupBy({ it.className }, { it })) { - val count = classOrigin.value.count() - val reference = when (count) { - 1 -> classOrigin.value.first() - else -> ClassReference(classOrigin.value.first().className) - } - when (reference) { - is ClassReference -> - printError(" - Reference from ${reference.className}") - is MemberReference -> - printError(" - Reference from ${reference.className}.${reference.memberName}()") - } - } - printError() - } - first = false - } - } - - protected open fun handleCommand(): Boolean { - return false - } - - protected open fun validateArguments(): Boolean { - return false - } - - protected fun printInfo(message: String = "") { - if (!quiet) { - println(ansi.Text(message).toString()) - } - } - - protected fun printVerbose(message: String = "") { - if (verbose) { - println(ansi.Text(message).toString()) - } - } - - protected fun printError(message: String = "") { - System.err.println(ansi.Text(message).toString()) - } - - protected fun printResult(result: Any?) { - printInfo("Execution successful") - printInfo(" - result = $result") - printInfo() - } - - protected fun whitelistFromPath(whitelist: Path?): Whitelist { - return whitelist?.let { - if ("$it" == "NONE") { - Whitelist.EMPTY - } else if ("$it" == "ALL") { - Whitelist.EVERYTHING - } else if ("$it" == "LANG") { - Whitelist.MINIMAL - } else { - try { - Whitelist.fromFile(file = it) - } catch (exception: Throwable) { - throw Exception("Failed to load whitelist '$it'", exception) - } - } - } ?: Whitelist.MINIMAL - } - - private fun Int.countOf(suffix: String): String { - return this.let { - when (it) { - 0 -> "no ${suffix}s" - 1 -> "@|yellow 1|@ $suffix" - else -> "@|yellow $it|@ ${suffix}s" - } - } - } - -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Commands.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Commands.kt deleted file mode 100644 index b76fc3b6db..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Commands.kt +++ /dev/null @@ -1,29 +0,0 @@ -package net.corda.djvm.tools.cli - -import picocli.CommandLine -import picocli.CommandLine.Command - -@Command( - name = "djvm", - versionProvider = VersionProvider::class, - description = ["JVM for running programs in a deterministic sandbox."], - mixinStandardHelpOptions = true, - subcommands = [ - BuildCommand::class, - CheckCommand::class, - InspectionCommand::class, - NewCommand::class, - RunCommand::class, - ShowCommand::class, - TreeCommand::class - ] -) -@Suppress("KDocMissingDocumentation") -class Commands : CommandBase() { - - fun run(args: Array) = when (CommandLine.call(this, System.err, *args)) { - true -> 0 - else -> 1 - } - -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/InspectionCommand.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/InspectionCommand.kt deleted file mode 100644 index 32ce08ec6e..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/InspectionCommand.kt +++ /dev/null @@ -1,88 +0,0 @@ -package net.corda.djvm.tools.cli - -import net.corda.djvm.source.ClassSource -import picocli.CommandLine.Command -import picocli.CommandLine.Parameters -import java.nio.file.Files - -@Command( - name = "inspect", - description = ["Inspect the transformations that are being applied to classes before they get loaded into " + - "the sandbox."] -) -@Suppress("KDocMissingDocumentation") -class InspectionCommand : ClassCommand() { - - override val filters: Array - get() = classes - - @Parameters(description = ["The partial or fully qualified names of the Java classes to inspect."]) - var classes: Array = emptyArray() - - override fun processClasses(classes: List>) { - val sources = classes.map { ClassSource.fromClassName(it.name) } - val (_, messages) = executor.validate(*sources.toTypedArray()) - - if (messages.isNotEmpty()) { - for (message in messages.sorted()) { - printInfo(" - $message") - } - printInfo() - } - - for (classSource in sources) { - val loadedClass = executor.load(classSource) - val sourceClass = createCodePath().resolve("${loadedClass.type.simpleName}.class") - val originalClass = Files.createTempFile("sandbox-", ".java") - val transformedClass = Files.createTempFile("sandbox-", ".java") - - printInfo("Class: ${loadedClass.name}") - printVerbose(" - Size of the original byte code: ${Files.size(sourceClass)}") - printVerbose(" - Size of the transformed byte code: ${loadedClass.byteCode.bytes.size}") - printVerbose(" - Original class: $originalClass") - printVerbose(" - Transformed class: $transformedClass") - printInfo() - - // Generate byte code dump of the original class - ProcessBuilder("javap", "-c", sourceClass.toString()).apply { - redirectOutput(originalClass.toFile()) - environment().putAll(System.getenv()) - start().apply { - waitFor() - exitValue() - } - } - - // Generate byte code dump of the transformed class - Files.createTempFile("sandbox-", ".class").apply { - Files.write(this, loadedClass.byteCode.bytes) - ProcessBuilder("javap", "-c", this.toString()).apply { - redirectOutput(transformedClass.toFile()) - environment().putAll(System.getenv()) - start().apply { - waitFor() - exitValue() - } - } - Files.delete(this) - } - - // Generate and display the difference between the original and the transformed class - ProcessBuilder( - "git", "diff", originalClass.toString(), transformedClass.toString() - ).apply { - inheritIO() - environment().putAll(System.getenv()) - start().apply { - waitFor() - exitValue() - } - } - printInfo() - - Files.deleteIfExists(originalClass) - Files.deleteIfExists(transformedClass) - } - } - -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/NewCommand.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/NewCommand.kt deleted file mode 100644 index 22c6e96aee..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/NewCommand.kt +++ /dev/null @@ -1,72 +0,0 @@ -package net.corda.djvm.tools.cli - -import picocli.CommandLine.* -import java.nio.file.Files -import java.nio.file.Path - -@Command( - name = "new", - description = ["Create one or more new Java classes implementing the sandbox runnable interface that is " + - "required for execution in the deterministic sandbox. Each Java file is created using a template, " + - "with class name derived from the provided file name." - ], - showDefaultValues = true -) -@Suppress("KDocMissingDocumentation") -class NewCommand : CommandBase() { - - @Parameters(description = ["The names of the Java source files that will be created."]) - var files: Array = emptyArray() - - @Option(names = ["-f", "--force"], description = ["Forcefully overwrite files if they already exist."]) - var force: Boolean = false - - @Option(names = ["--from"], description = ["The input type to use for the constructed runnable."]) - var fromType: String = "Object" - - @Option(names = ["--to"], description = ["The output type to use for the constructed runnable."]) - var toType: String = "Object" - - @Option(names = ["--return"], description = ["The default return value for the constructed runnable."]) - var returnValue: String = "null" - - override fun validateArguments() = files.isNotEmpty() - - override fun handleCommand(): Boolean { - val codePath = createCodePath() - val files = files.getFiles { codePath.resolve(it) } - for (file in files) { - try { - printVerbose("Creating file '$file'...") - Files.newBufferedWriter(file, *openOptions(force)).use { - it.append(TEMPLATE - .replace("[NAME]", file.baseName) - .replace("[FROM]", fromType) - .replace("[TO]", toType) - .replace("[RETURN]", returnValue)) - } - } catch (exception: Throwable) { - throw Exception("Failed to create file '$file'", exception) - } - } - return true - } - - companion object { - - val TEMPLATE = """ - |package net.corda.sandbox; - | - |import java.util.function.Function; - | - |public class [NAME] implements Function<[FROM], [TO]> { - | @Override - | public [TO] apply([FROM] input) { - | return [RETURN]; - | } - |} - """.trimMargin() - - } - -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Program.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Program.kt deleted file mode 100644 index 3c4524b0f3..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Program.kt +++ /dev/null @@ -1,12 +0,0 @@ -@file:JvmName("Program") - -package net.corda.djvm.tools.cli - -import kotlin.system.exitProcess - -/** - * The entry point of the deterministic sandbox tool. - */ -fun main(args: Array) { - exitProcess(Commands().run(args)) -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/RunCommand.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/RunCommand.kt deleted file mode 100644 index 62fab057ba..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/RunCommand.kt +++ /dev/null @@ -1,36 +0,0 @@ -package net.corda.djvm.tools.cli - -import net.corda.djvm.source.ClassSource -import picocli.CommandLine.Command -import picocli.CommandLine.Parameters - -@Command( - name = "run", - description = ["Execute runnable in sandbox."], - showDefaultValues = true -) -@Suppress("KDocMissingDocumentation") -class RunCommand : ClassCommand() { - - override val filters: Array - get() = classes - - @Parameters(description = ["The partial or fully qualified names of the Java classes to run."]) - var classes: Array = emptyArray() - - override fun processClasses(classes: List>) { - val interfaceName = java.util.function.Function::class.java.simpleName - for (clazz in classes) { - if (!clazz.interfaces.any { it.simpleName == interfaceName }) { - printError("Class is not an instance of $interfaceName; ${clazz.name}") - return - } - printInfo("Running class ${clazz.name}...") - executor.run(ClassSource.fromClassName(clazz.name), Any()).apply { - printResult(result) - printCosts(costs) - } - } - } - -} \ No newline at end of file diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/ShowCommand.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/ShowCommand.kt deleted file mode 100644 index 67a6deac68..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/ShowCommand.kt +++ /dev/null @@ -1,56 +0,0 @@ -package net.corda.djvm.tools.cli - -import net.corda.djvm.source.ClassSource -import picocli.CommandLine.Command -import picocli.CommandLine.Parameters -import java.nio.file.Files - -@Command( - name = "show", - description = ["Show the transformed version of a class as it is prepared for execution in the deterministic " + - "sandbox."] -) -@Suppress("KDocMissingDocumentation") -class ShowCommand : ClassCommand() { - - override val filters: Array - get() = classes - - @Parameters(description = ["The partial or fully qualified names of the Java classes to inspect."]) - var classes: Array = emptyArray() - - override fun processClasses(classes: List>) { - val sources = classes.map { ClassSource.fromClassName(it.name) } - val (_, messages) = executor.validate(*sources.toTypedArray()) - - if (messages.isNotEmpty()) { - for (message in messages.sorted()) { - printInfo(" - $message") - } - printInfo() - } - - for (classSource in sources) { - val loadedClass = executor.load(classSource) - printInfo("Class: ${loadedClass.name}") - printVerbose(" - Byte code size: ${loadedClass.byteCode.bytes.size}") - printVerbose(" - Has been modified: ${loadedClass.byteCode.isModified}") - printInfo() - - Files.createTempFile("sandbox-", ".class").apply { - Files.write(this, loadedClass.byteCode.bytes) - ProcessBuilder("javap", "-c", this.toString()).apply { - inheritIO() - environment().putAll(System.getenv()) - start().apply { - waitFor() - exitValue() - } - } - Files.delete(this) - } - printInfo() - } - } - -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/TreeCommand.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/TreeCommand.kt deleted file mode 100644 index 26b5dbc7d8..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/TreeCommand.kt +++ /dev/null @@ -1,33 +0,0 @@ -package net.corda.djvm.tools.cli - -import picocli.CommandLine.Command -import java.nio.file.Files - -@Command( - name = "tree", - description = ["Show the hierarchy of the classes that have been created with the 'new' command."] -) -@Suppress("KDocMissingDocumentation") -class TreeCommand : CommandBase() { - - override fun validateArguments() = true - - override fun handleCommand(): Boolean { - val path = workingDirectory.resolve("tmp") - if (!Files.exists(path)) { - printError("No classes have been created so far. Run `djvm new` to get started.") - return false - } - ProcessBuilder("find", ".", "-type", "f").apply { - inheritIO() - environment().putAll(System.getenv()) - directory(path.toFile()) - start().apply { - waitFor() - exitValue() - } - } - return true - } - -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Utilities.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Utilities.kt deleted file mode 100644 index d488aa7253..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/Utilities.kt +++ /dev/null @@ -1,102 +0,0 @@ -@file:JvmName("Utilities") -package net.corda.djvm.tools.cli - -import io.github.classgraph.ClassGraph -import java.lang.reflect.Modifier.isAbstract -import java.lang.reflect.Modifier.isStatic -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths -import java.nio.file.StandardOpenOption - -/** - * Get the expanded file name of each path in the provided array. - */ -fun Array?.getFiles(map: (Path) -> Path = { it }) = (this ?: emptyArray()).map { - val pathString = it.toString() - val path = map(it) - when { - '/' in pathString || '\\' in pathString -> - throw Exception("Please provide a pathless file name") - pathString.endsWith(".java", true) -> path - else -> Paths.get("$path.java") - } -} - -/** - * Get the string representation of each expanded file name in the provided array. - */ -fun Array?.getFileNames(map: (Path) -> Path = { it }) = this.getFiles(map).map { - it.toString() -}.toTypedArray() - -/** - * Execute inlined action if the collection is empty. - */ -inline fun List.onEmpty(action: () -> Unit): List { - if (!this.any()) { - action() - } - return this -} - -/** - * Execute inlined action if the array is empty. - */ -inline fun Array?.onEmpty(action: () -> Unit): Array { - return (this ?: emptyArray()).toList().onEmpty(action).toTypedArray() -} - -/** - * Derive the set of [StandardOpenOption]'s to use for a file operation. - */ -fun openOptions(force: Boolean) = if (force) { - arrayOf(StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING) -} else { - arrayOf(StandardOpenOption.CREATE_NEW) -} - -/** - * Get the path of where any generated code will be placed. Create the directory if it does not exist. - */ -fun createCodePath(): Path { - return Paths.get("tmp", "net", "corda", "sandbox").let { - Files.createDirectories(it) - } -} - -/** - * Return the base name of a file (i.e., its name without extension) - */ -val Path.baseName: String - get() = this.fileName.toString() - .replaceAfterLast('.', "") - .removeSuffix(".") - -/** - * The path of the executing JAR. - */ -val jarPath: String = object {}.javaClass.protectionDomain.codeSource.location.toURI().path - - -/** - * The path of the current working directory. - */ -val workingDirectory: Path = Paths.get(System.getProperty("user.dir")) - -/** - * The class path for the current execution context. - */ -val userClassPath: String = System.getProperty("java.class.path") - -/** - * Get a reference of each concrete class that implements interface or class [T]. - */ -inline fun find(scanSpec: String = "net/corda/sandbox"): List> { - return ClassGraph() - .whitelistPaths(scanSpec) - .enableAllInfo() - .scan() - .use { it.getClassesImplementing(T::class.java.name).loadClasses(T::class.java) } - .filter { !isAbstract(it.modifiers) && !isStatic(it.modifiers) } -} diff --git a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/VersionProvider.kt b/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/VersionProvider.kt deleted file mode 100644 index 24c26e2094..0000000000 --- a/djvm/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/VersionProvider.kt +++ /dev/null @@ -1,14 +0,0 @@ -package net.corda.djvm.tools.cli - -import com.jcabi.manifests.Manifests -import picocli.CommandLine.IVersionProvider - -/** - * Get the version number to use for the tool. - */ -@Suppress("KDocMissingDocumentation") -class VersionProvider : IVersionProvider { - override fun getVersion(): Array = arrayOf( - Manifests.read("Corda-Release-Version") - ) -} diff --git a/djvm/djvm/cli/src/main/resources/log4j2.xml b/djvm/djvm/cli/src/main/resources/log4j2.xml deleted file mode 100644 index 648a657dc3..0000000000 --- a/djvm/djvm/cli/src/main/resources/log4j2.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/djvm/djvm/cli/src/shell/djvm b/djvm/djvm/cli/src/shell/djvm deleted file mode 100755 index 368b50beb7..0000000000 --- a/djvm/djvm/cli/src/shell/djvm +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR=$(dirname $(readlink -f ${BASH_SOURCE[0]})) - -CLASSPATH="${CLASSPATH:-}" - -DEBUG=`echo "${DEBUG:-0}" | sed 's/^[Nn][Oo]*$/0/g'` -DEBUG_PORT=5005 -DEBUG_AGENT="" - -if [ "$DEBUG" != 0 ]; then - echo "Opening remote debugging session on port $DEBUG_PORT" - DEBUG_AGENT="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=$DEBUG_PORT" -fi - -exec java $DEBUG_AGENT -cp "$CLASSPATH:.:tmp:$SCRIPT_DIR/corda-djvm-cli.jar" net.corda.djvm.tools.cli.Program "$@" diff --git a/djvm/djvm/cli/src/shell/djvm.bat b/djvm/djvm/cli/src/shell/djvm.bat deleted file mode 100644 index 74fc1386d0..0000000000 --- a/djvm/djvm/cli/src/shell/djvm.bat +++ /dev/null @@ -1,15 +0,0 @@ -@ECHO off - -SETLOCAL ENABLEEXTENSIONS - -IF NOT DEFINED CLASSPATH (SET CLASSPATH=) - -IF DEFINED DEBUG ( - SET DEBUG_PORT=5005 - SET DEBUG_AGENT=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=%DEBUG_PORT% - ECHO Opening remote debugging session on port %DEBUG_PORT% -) ELSE ( - SET DEBUG_AGENT= -) - -CALL java %DEBUG_AGENT% -cp "%CLASSPATH%;.;tmp;%~dp0\corda-djvm-cli.jar" net.corda.djvm.tools.cli.Program %* diff --git a/djvm/djvm/cli/src/shell/install b/djvm/djvm/cli/src/shell/install deleted file mode 100755 index 69058ef4f1..0000000000 --- a/djvm/djvm/cli/src/shell/install +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR=$(dirname $(readlink -f ${BASH_SOURCE[0]})) - -# Generate auto-completion file for Bash and ZSH -java -cp ${SCRIPT_DIR}/corda-djvm-cli.jar \ - picocli.AutoComplete -n djvm net.corda.djvm.tools.cli.Commands -f diff --git a/djvm/djvm/shell/.gitignore b/djvm/djvm/shell/.gitignore deleted file mode 100644 index 4bc7c1cffa..0000000000 --- a/djvm/djvm/shell/.gitignore +++ /dev/null @@ -1 +0,0 @@ -djvm_completion diff --git a/djvm/djvm/shell/djvm b/djvm/djvm/shell/djvm deleted file mode 100755 index 2b7ff4fe8a..0000000000 --- a/djvm/djvm/shell/djvm +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -file="${BASH_SOURCE[0]}" -linked_file="$(test -L "$file" && readlink "$file" || echo "$file")" -base_dir="$(cd "$(dirname "$linked_file")/../" && pwd)" -djvm_cli_jar=$(ls -1 $base_dir/cli/build/libs/corda-djvm-cli-*.jar) - -CLASSPATH="${CLASSPATH:-}" - -DEBUG=`echo "${DEBUG:-0}" | sed 's/^[Nn][Oo]*$/0/g'` -DEBUG_PORT=5005 -DEBUG_AGENT="" - -if [ "$DEBUG" != 0 ]; then - echo "Opening remote debugging session on port $DEBUG_PORT" - DEBUG_AGENT="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=$DEBUG_PORT" -fi - -java $DEBUG_AGENT -cp "$CLASSPATH:.:tmp:$djvm_cli_jar" net.corda.djvm.tools.cli.Program "$@" diff --git a/djvm/djvm/shell/install b/djvm/djvm/shell/install deleted file mode 100755 index 1870d34884..0000000000 --- a/djvm/djvm/shell/install +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -file="${BASH_SOURCE[0]}" -base_dir="$(cd "$(dirname "$file")/" && pwd)" - -# Build DJVM module and CLI -cd "$base_dir/.." -if !(../gradlew shadowJar); then - echo "Failed to build DJVM" - exit 1 -fi - -djvm_cli_jar=$(ls -1 $base_dir/../cli/build/libs/corda-djvm-cli-*.jar) - -# Generate auto-completion file for Bash and ZSH -cd "$base_dir" -if !(java -cp $djvm_cli_jar \ - picocli.AutoComplete -n djvm net.corda.djvm.tools.cli.Commands -f); then - echo "Failed to generate auto-completion file" - exit 1 -fi - -# Create a symbolic link to the `djvm` utility -sudo ln -sf "$base_dir/djvm" /usr/local/bin/djvm diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Appendable.java b/djvm/djvm/src/main/java/sandbox/java/lang/Appendable.java deleted file mode 100644 index c95eaf6e53..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Appendable.java +++ /dev/null @@ -1,19 +0,0 @@ -package sandbox.java.lang; - -import java.io.IOException; - -/** - * This is a dummy class that implements just enough of {@link java.lang.Appendable} - * to keep {@link sandbox.java.lang.StringBuilder}, {@link sandbox.java.lang.StringBuffer} - * and {@link sandbox.java.lang.String} honest. - * Note that it does not extend {@link java.lang.Appendable}. - */ -public interface Appendable { - - Appendable append(CharSequence csq, int start, int end) throws IOException; - - Appendable append(CharSequence csq) throws IOException; - - Appendable append(char c) throws IOException; - -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Boolean.java b/djvm/djvm/src/main/java/sandbox/java/lang/Boolean.java deleted file mode 100644 index 6d347fdd3e..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Boolean.java +++ /dev/null @@ -1,100 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -import java.io.Serializable; - -@SuppressWarnings({"unused", "WeakerAccess"}) -public final class Boolean extends Object implements Comparable, Serializable { - - public static final Boolean TRUE = new Boolean(true); - public static final Boolean FALSE = new Boolean(false); - - @SuppressWarnings("unchecked") - public static final Class TYPE = (Class) java.lang.Boolean.TYPE; - - private final boolean value; - - public Boolean(boolean value) { - this.value = value; - } - - public Boolean(String s) { - this(parseBoolean(s)); - } - - @Override - public boolean equals(java.lang.Object other) { - return (other instanceof Boolean) && ((Boolean) other).value == value; - } - - @Override - public int hashCode() { - return hashCode(value); - } - - public static int hashCode(boolean value) { - return java.lang.Boolean.hashCode(value); - } - - public boolean booleanValue() { - return value; - } - - @Override - @NotNull - public java.lang.String toString() { - return java.lang.Boolean.toString(value); - } - - @Override - @NotNull - public String toDJVMString() { - return toString(value); - } - - public static String toString(boolean b) { - return String.valueOf(b); - } - - @Override - @NotNull - java.lang.Boolean fromDJVM() { - return value; - } - - @Override - public int compareTo(@NotNull Boolean other) { - return compare(value, other.value); - } - - public static int compare(boolean x, boolean y) { - return java.lang.Boolean.compare(x, y); - } - - public static boolean parseBoolean(String s) { - return java.lang.Boolean.parseBoolean(String.fromDJVM(s)); - } - - public static Boolean valueOf(boolean b) { - return b ? TRUE : FALSE; - } - - public static Boolean valueOf(String s) { - return valueOf(parseBoolean(s)); - } - - public static boolean logicalAnd(boolean a, boolean b) { - return java.lang.Boolean.logicalAnd(a, b); - } - - public static boolean logicalOr(boolean a, boolean b) { - return java.lang.Boolean.logicalOr(a, b); - } - - public static boolean logicalXor(boolean a, boolean b) { - return java.lang.Boolean.logicalXor(a, b); - } - - public static Boolean toDJVM(java.lang.Boolean b) { return (b == null) ? null : new Boolean(b); } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Byte.java b/djvm/djvm/src/main/java/sandbox/java/lang/Byte.java deleted file mode 100644 index 95b329f25d..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Byte.java +++ /dev/null @@ -1,129 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings({"unused", "WeakerAccess"}) -public final class Byte extends Number implements Comparable { - public static final byte MIN_VALUE = java.lang.Byte.MIN_VALUE; - public static final byte MAX_VALUE = java.lang.Byte.MAX_VALUE; - public static final int BYTES = java.lang.Byte.BYTES; - public static final int SIZE = java.lang.Byte.SIZE; - - @SuppressWarnings("unchecked") - public static final Class TYPE = (Class) java.lang.Byte.TYPE; - - private final byte value; - - public Byte(byte value) { - this.value = value; - } - - public Byte(String s) throws NumberFormatException { - this.value = parseByte(s); - } - - @Override - public byte byteValue() { - return value; - } - - @Override - public short shortValue() { - return (short) value; - } - - @Override - public int intValue() { - return (int) value; - } - - @Override - public long longValue() { - return (long) value; - } - - @Override - public float floatValue() { - return (float) value; - } - - @Override - public double doubleValue() { - return (double) value; - } - - @Override - public int hashCode() { - return hashCode(value); - } - - public static int hashCode(byte b) { - return java.lang.Byte.hashCode(b); - } - - @Override - public boolean equals(java.lang.Object other) { - return (other instanceof Byte) && ((Byte) other).value == value; - } - - @Override - @NotNull - public java.lang.String toString() { - return java.lang.Byte.toString(value); - } - - @Override - @NotNull - java.lang.Byte fromDJVM() { - return value; - } - - @Override - public int compareTo(@NotNull Byte other) { - return compare(this.value, other.value); - } - - public static int compare(byte x, byte y) { - return java.lang.Byte.compare(x, y); - } - - public static String toString(byte b) { - return Integer.toString(b); - } - - public static Byte valueOf(byte b) { - return new Byte(b); - } - - public static byte parseByte(String s, int radix) throws NumberFormatException { - return java.lang.Byte.parseByte(String.fromDJVM(s), radix); - } - - public static byte parseByte(String s) throws NumberFormatException { - return java.lang.Byte.parseByte(String.fromDJVM(s)); - } - - public static Byte valueOf(String s, int radix) throws NumberFormatException { - return toDJVM(java.lang.Byte.valueOf(String.fromDJVM(s), radix)); - } - - public static Byte valueOf(String s) throws NumberFormatException { - return toDJVM(java.lang.Byte.valueOf(String.fromDJVM(s))); - } - - public static Byte decode(String s) throws NumberFormatException { - return toDJVM(java.lang.Byte.decode(String.fromDJVM(s))); - } - - public static int toUnsignedInt(byte b) { - return java.lang.Byte.toUnsignedInt(b); - } - - public static long toUnsignedLong(byte b) { - return java.lang.Byte.toUnsignedLong(b); - } - - public static Byte toDJVM(java.lang.Byte b) { - return (b == null) ? null : valueOf(b); - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/CharSequence.java b/djvm/djvm/src/main/java/sandbox/java/lang/CharSequence.java deleted file mode 100644 index 10b024d027..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/CharSequence.java +++ /dev/null @@ -1,21 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -/** - * This is a dummy class that implements just enough of {@link java.lang.CharSequence} - * to allow us to compile {@link sandbox.java.lang.String}. - */ -public interface CharSequence extends java.lang.CharSequence { - - @Override - CharSequence subSequence(int start, int end); - - @NotNull - String toDJVMString(); - - @Override - @NotNull - java.lang.String toString(); - -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Character.java b/djvm/djvm/src/main/java/sandbox/java/lang/Character.java deleted file mode 100644 index 2db6054272..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Character.java +++ /dev/null @@ -1,481 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -import java.io.Serializable; - -@SuppressWarnings({"unused", "WeakerAccess"}) -public final class Character extends Object implements Comparable, Serializable { - public static final int MIN_RADIX = java.lang.Character.MIN_RADIX; - public static final int MAX_RADIX = java.lang.Character.MAX_RADIX; - public static final char MIN_VALUE = java.lang.Character.MIN_VALUE; - public static final char MAX_VALUE = java.lang.Character.MAX_VALUE; - - @SuppressWarnings("unchecked") - public static final Class TYPE = (Class) java.lang.Character.TYPE; - - public static final byte UNASSIGNED = java.lang.Character.UNASSIGNED; - public static final byte UPPERCASE_LETTER = java.lang.Character.UPPERCASE_LETTER; - public static final byte LOWERCASE_LETTER = java.lang.Character.LOWERCASE_LETTER; - public static final byte TITLECASE_LETTER = java.lang.Character.TITLECASE_LETTER; - public static final byte MODIFIER_LETTER = java.lang.Character.MODIFIER_LETTER; - public static final byte OTHER_LETTER = java.lang.Character.OTHER_LETTER; - public static final byte NON_SPACING_MARK = java.lang.Character.NON_SPACING_MARK; - public static final byte ENCLOSING_MARK = java.lang.Character.ENCLOSING_MARK; - public static final byte COMBINING_SPACING_MARK = java.lang.Character.COMBINING_SPACING_MARK; - public static final byte DECIMAL_DIGIT_NUMBER = java.lang.Character.DECIMAL_DIGIT_NUMBER; - public static final byte LETTER_NUMBER = java.lang.Character.LETTER_NUMBER; - public static final byte OTHER_NUMBER = java.lang.Character.OTHER_NUMBER; - public static final byte SPACE_SEPARATOR = java.lang.Character.SPACE_SEPARATOR; - public static final byte LINE_SEPARATOR = java.lang.Character.LINE_SEPARATOR; - public static final byte PARAGRAPH_SEPARATOR = java.lang.Character.PARAGRAPH_SEPARATOR; - public static final byte CONTROL = java.lang.Character.CONTROL; - public static final byte FORMAT = java.lang.Character.FORMAT; - public static final byte PRIVATE_USE = java.lang.Character.PRIVATE_USE; - public static final byte SURROGATE = java.lang.Character.SURROGATE; - public static final byte DASH_PUNCTUATION = java.lang.Character.DASH_PUNCTUATION; - public static final byte START_PUNCTUATION = java.lang.Character.START_PUNCTUATION; - public static final byte END_PUNCTUATION = java.lang.Character.END_PUNCTUATION; - public static final byte CONNECTOR_PUNCTUATION = java.lang.Character.CONNECTOR_PUNCTUATION; - public static final byte OTHER_PUNCTUATION = java.lang.Character.OTHER_PUNCTUATION; - public static final byte MATH_SYMBOL = java.lang.Character.MATH_SYMBOL; - public static final byte CURRENCY_SYMBOL = java.lang.Character.CURRENCY_SYMBOL; - public static final byte MODIFIER_SYMBOL = java.lang.Character.MODIFIER_SYMBOL; - public static final byte OTHER_SYMBOL = java.lang.Character.OTHER_SYMBOL; - public static final byte INITIAL_QUOTE_PUNCTUATION = java.lang.Character.INITIAL_QUOTE_PUNCTUATION; - public static final byte FINAL_QUOTE_PUNCTUATION = java.lang.Character.FINAL_QUOTE_PUNCTUATION; - public static final byte DIRECTIONALITY_UNDEFINED = java.lang.Character.DIRECTIONALITY_UNDEFINED; - public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = java.lang.Character.DIRECTIONALITY_LEFT_TO_RIGHT; - public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = java.lang.Character.DIRECTIONALITY_RIGHT_TO_LEFT; - public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = java.lang.Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC; - public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = java.lang.Character.DIRECTIONALITY_EUROPEAN_NUMBER; - public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = java.lang.Character.DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR; - public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = java.lang.Character.DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR; - public static final byte DIRECTIONALITY_ARABIC_NUMBER = java.lang.Character.DIRECTIONALITY_ARABIC_NUMBER; - public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = java.lang.Character.DIRECTIONALITY_COMMON_NUMBER_SEPARATOR; - public static final byte DIRECTIONALITY_NONSPACING_MARK = java.lang.Character.DIRECTIONALITY_NONSPACING_MARK; - public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = java.lang.Character.DIRECTIONALITY_BOUNDARY_NEUTRAL; - public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = java.lang.Character.DIRECTIONALITY_PARAGRAPH_SEPARATOR; - public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = java.lang.Character.DIRECTIONALITY_SEGMENT_SEPARATOR; - public static final byte DIRECTIONALITY_WHITESPACE = java.lang.Character.DIRECTIONALITY_WHITESPACE; - public static final byte DIRECTIONALITY_OTHER_NEUTRALS = java.lang.Character.DIRECTIONALITY_OTHER_NEUTRALS; - public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = java.lang.Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING; - public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = java.lang.Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE; - public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = java.lang.Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING; - public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = java.lang.Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE; - public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = java.lang.Character.DIRECTIONALITY_POP_DIRECTIONAL_FORMAT; - public static final char MIN_HIGH_SURROGATE = java.lang.Character.MIN_HIGH_SURROGATE; - public static final char MAX_HIGH_SURROGATE = java.lang.Character.MAX_HIGH_SURROGATE; - public static final char MIN_LOW_SURROGATE = java.lang.Character.MIN_LOW_SURROGATE; - public static final char MAX_LOW_SURROGATE = java.lang.Character.MAX_LOW_SURROGATE; - public static final char MIN_SURROGATE = java.lang.Character.MIN_SURROGATE; - public static final char MAX_SURROGATE = java.lang.Character.MAX_SURROGATE; - public static final int MIN_SUPPLEMENTARY_CODE_POINT = java.lang.Character.MIN_SUPPLEMENTARY_CODE_POINT; - public static final int MIN_CODE_POINT = java.lang.Character.MIN_CODE_POINT; - public static final int MAX_CODE_POINT = java.lang.Character.MAX_CODE_POINT; - public static final int BYTES = java.lang.Character.BYTES; - public static final int SIZE = java.lang.Character.SIZE; - - private final char value; - - public Character(char c) { - this.value = c; - } - - public char charValue() { - return this.value; - } - - @Override - public int hashCode() { - return hashCode(this.value); - } - - public static int hashCode(char value) { - return java.lang.Character.hashCode(value); - } - - @Override - public boolean equals(java.lang.Object other) { - return (other instanceof Character) && ((Character) other).value == value; - } - - @Override - @NotNull - public java.lang.String toString() { - return java.lang.Character.toString(value); - } - - @Override - @NotNull - public String toDJVMString() { - return toString(value); - } - - @Override - @NotNull - java.lang.Character fromDJVM() { - return value; - } - - @Override - public int compareTo(@NotNull Character var1) { - return compare(this.value, var1.value); - } - - public static int compare(char x, char y) { - return java.lang.Character.compare(x, y); - } - - public static String toString(char c) { - return String.toDJVM(java.lang.Character.toString(c)); - } - - public static Character valueOf(char c) { - return (c <= 127) ? Cache.cache[(int)c] : new Character(c); - } - - public static boolean isValidCodePoint(int codePoint) { - return java.lang.Character.isValidCodePoint(codePoint); - } - - public static boolean isBmpCodePoint(int codePoint) { - return java.lang.Character.isBmpCodePoint(codePoint); - } - - public static boolean isSupplementaryCodePoint(int codePoint) { - return java.lang.Character.isSupplementaryCodePoint(codePoint); - } - - public static boolean isHighSurrogate(char ch) { - return java.lang.Character.isHighSurrogate(ch); - } - - public static boolean isLowSurrogate(char ch) { - return java.lang.Character.isLowSurrogate(ch); - } - - public static boolean isSurrogate(char ch) { - return java.lang.Character.isSurrogate(ch); - } - - public static boolean isSurrogatePair(char high, char low) { - return java.lang.Character.isSurrogatePair(high, low); - } - - public static int charCount(int codePoint) { - return java.lang.Character.charCount(codePoint); - } - - public static int toCodePoint(char high, char low) { - return java.lang.Character.toCodePoint(high, low); - } - - public static int codePointAt(CharSequence seq, int index) { - return java.lang.Character.codePointAt(seq, index); - } - - public static int codePointAt(char[] a, int index) { - return java.lang.Character.codePointAt(a, index); - } - - public static int codePointAt(char[] a, int index, int limit) { - return java.lang.Character.codePointAt(a, index, limit); - } - - public static int codePointBefore(CharSequence seq, int index) { - return java.lang.Character.codePointBefore(seq, index); - } - - public static int codePointBefore(char[] a, int index) { - return java.lang.Character.codePointBefore(a, index); - } - - public static int codePointBefore(char[] a, int index, int limit) { - return java.lang.Character.codePointBefore(a, index, limit); - } - - public static char highSurrogate(int codePoint) { - return java.lang.Character.highSurrogate(codePoint); - } - - public static char lowSurrogate(int codePoint) { - return java.lang.Character.lowSurrogate(codePoint); - } - - public static int toChars(int codePoint, char[] dst, int dstIndex) { - return java.lang.Character.toChars(codePoint, dst, dstIndex); - } - - public static char[] toChars(int codePoint) { - return java.lang.Character.toChars(codePoint); - } - - public static int codePointCount(CharSequence seq, int beginIndex, int endIndex) { - return java.lang.Character.codePointCount(seq, beginIndex, endIndex); - } - - public static int codePointCount(char[] a, int offset, int count) { - return java.lang.Character.codePointCount(a, offset, count); - } - - public static int offsetByCodePoints(CharSequence seq, int index, int codePointOffset) { - return java.lang.Character.offsetByCodePoints(seq, index, codePointOffset); - } - - public static int offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset) { - return java.lang.Character.offsetByCodePoints(a, start, count, index, codePointOffset); - } - - public static boolean isLowerCase(char ch) { - return java.lang.Character.isLowerCase(ch); - } - - public static boolean isLowerCase(int codePoint) { - return java.lang.Character.isLowerCase(codePoint); - } - - public static boolean isUpperCase(char ch) { - return java.lang.Character.isUpperCase(ch); - } - - public static boolean isUpperCase(int codePoint) { - return java.lang.Character.isUpperCase(codePoint); - } - - public static boolean isTitleCase(char ch) { - return java.lang.Character.isTitleCase(ch); - } - - public static boolean isTitleCase(int codePoint) { - return java.lang.Character.isTitleCase(codePoint); - } - - public static boolean isDigit(char ch) { - return java.lang.Character.isDigit(ch); - } - - public static boolean isDigit(int codePoint) { - return java.lang.Character.isDigit(codePoint); - } - - public static boolean isDefined(char ch) { - return java.lang.Character.isDefined(ch); - } - - public static boolean isDefined(int codePoint) { - return java.lang.Character.isDefined(codePoint); - } - - public static boolean isLetter(char ch) { - return java.lang.Character.isLetter(ch); - } - - public static boolean isLetter(int codePoint) { - return java.lang.Character.isLetter(codePoint); - } - - public static boolean isLetterOrDigit(char ch) { - return java.lang.Character.isLetterOrDigit(ch); - } - - public static boolean isLetterOrDigit(int codePoint) { - return java.lang.Character.isLetterOrDigit(codePoint); - } - - @Deprecated - public static boolean isJavaLetter(char ch) { - return java.lang.Character.isJavaLetter(ch); - } - - @Deprecated - public static boolean isJavaLetterOrDigit(char ch) { - return java.lang.Character.isJavaLetterOrDigit(ch); - } - - public static boolean isAlphabetic(int codePoint) { - return java.lang.Character.isAlphabetic(codePoint); - } - - public static boolean isIdeographic(int codePoint) { - return java.lang.Character.isIdeographic(codePoint); - } - - public static boolean isJavaIdentifierStart(char ch) { - return java.lang.Character.isJavaIdentifierStart(ch); - } - - public static boolean isJavaIdentifierStart(int codePoint) { - return java.lang.Character.isJavaIdentifierStart(codePoint); - } - - public static boolean isJavaIdentifierPart(char ch) { - return java.lang.Character.isJavaIdentifierPart(ch); - } - - public static boolean isJavaIdentifierPart(int codePoint) { - return java.lang.Character.isJavaIdentifierPart(codePoint); - } - - public static boolean isUnicodeIdentifierStart(char ch) { - return java.lang.Character.isUnicodeIdentifierStart(ch); - } - - public static boolean isUnicodeIdentifierStart(int codePoint) { - return java.lang.Character.isUnicodeIdentifierStart(codePoint); - } - - public static boolean isUnicodeIdentifierPart(char ch) { - return java.lang.Character.isUnicodeIdentifierPart(ch); - } - - public static boolean isUnicodeIdentifierPart(int codePoint) { - return java.lang.Character.isUnicodeIdentifierPart(codePoint); - } - - public static boolean isIdentifierIgnorable(char ch) { - return java.lang.Character.isIdentifierIgnorable(ch); - } - - public static boolean isIdentifierIgnorable(int codePoint) { - return java.lang.Character.isIdentifierIgnorable(codePoint); - } - - public static char toLowerCase(char ch) { - return java.lang.Character.toLowerCase(ch); - } - - public static int toLowerCase(int codePoint) { - return java.lang.Character.toLowerCase(codePoint); - } - - public static char toUpperCase(char ch) { - return java.lang.Character.toUpperCase(ch); - } - - public static int toUpperCase(int codePoint) { - return java.lang.Character.toUpperCase(codePoint); - } - - public static char toTitleCase(char ch) { - return java.lang.Character.toTitleCase(ch); - } - - public static int toTitleCase(int codePoint) { - return java.lang.Character.toTitleCase(codePoint); - } - - public static int digit(char ch, int radix) { - return java.lang.Character.digit(ch, radix); - } - - public static int digit(int codePoint, int radix) { - return java.lang.Character.digit(codePoint, radix); - } - - public static int getNumericValue(char ch) { - return java.lang.Character.getNumericValue(ch); - } - - public static int getNumericValue(int codePoint) { - return java.lang.Character.getNumericValue(codePoint); - } - - @Deprecated - public static boolean isSpace(char ch) { - return java.lang.Character.isSpace(ch); - } - - public static boolean isSpaceChar(char ch) { - return java.lang.Character.isSpaceChar(ch); - } - - public static boolean isSpaceChar(int codePoint) { - return java.lang.Character.isSpaceChar(codePoint); - } - - public static boolean isWhitespace(char ch) { - return java.lang.Character.isWhitespace(ch); - } - - public static boolean isWhitespace(int codePoint) { - return java.lang.Character.isWhitespace(codePoint); - } - - public static boolean isISOControl(char ch) { - return java.lang.Character.isISOControl(ch); - } - - public static boolean isISOControl(int codePoint) { - return java.lang.Character.isISOControl(codePoint); - } - - public static int getType(char ch) { - return java.lang.Character.getType(ch); - } - - public static int getType(int codePoint) { - return java.lang.Character.getType(codePoint); - } - - public static char forDigit(int digit, int radix) { - return java.lang.Character.forDigit(digit, radix); - } - - public static byte getDirectionality(char ch) { - return java.lang.Character.getDirectionality(ch); - } - - public static byte getDirectionality(int codePoint) { - return java.lang.Character.getDirectionality(codePoint); - } - - public static boolean isMirrored(char ch) { - return java.lang.Character.isMirrored(ch); - } - - public static boolean isMirrored(int codePoint) { - return java.lang.Character.isMirrored(codePoint); - } - - public static String getName(int codePoint) { - return String.toDJVM(java.lang.Character.getName(codePoint)); - } - - public static Character toDJVM(java.lang.Character c) { - return (c == null) ? null : valueOf(c); - } - - // These three nested classes are placeholders to ensure that - // the Character class bytecode is generated correctly. The - // real classes will be loaded from the from the bootstrap jar - // and then mapped into the sandbox.* namespace. - public static final class UnicodeScript extends Enum { - private UnicodeScript(String name, int index) { - super(name, index); - } - - @Override - public int compareTo(@NotNull UnicodeScript other) { - throw new UnsupportedOperationException("Bootstrap implementation"); - } - } - public static final class UnicodeBlock extends Subset {} - public static class Subset extends Object {} - - /** - * Keep pre-allocated instances of the first 128 characters - * on the basis that these will be used most frequently. - */ - private static class Cache { - private static final Character[] cache = new Character[128]; - - static { - for (int c = 0; c < cache.length; ++c) { - cache[c] = new Character((char) c); - } - } - - private Cache() {} - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Comparable.java b/djvm/djvm/src/main/java/sandbox/java/lang/Comparable.java deleted file mode 100644 index 59b3278a1b..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Comparable.java +++ /dev/null @@ -1,8 +0,0 @@ -package sandbox.java.lang; - -/** - * This is a dummy class that implements just enough of {@link java.lang.Comparable} - * to allow us to compile {@link sandbox.java.lang.String}. - */ -public interface Comparable extends java.lang.Comparable { -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/DJVMThrowableWrapper.java b/djvm/djvm/src/main/java/sandbox/java/lang/DJVMThrowableWrapper.java deleted file mode 100644 index 60de2e117d..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/DJVMThrowableWrapper.java +++ /dev/null @@ -1,37 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -/** - * Pinned exceptions inherit from {@link java.lang.Throwable}, but we - * still need to be able to pass them through the sandbox's - * exception handlers. In which case we will wrap them inside - * one of these. - * - * Exceptions wrapped inside one of these cannot be caught. - * - * Also used for passing exceptions through finally blocks without - * any expensive unwrapping to {@link sandbox.java.lang.Throwable} - * based types. - */ -final class DJVMThrowableWrapper extends Throwable { - private final java.lang.Throwable throwable; - - DJVMThrowableWrapper(java.lang.Throwable t) { - throwable = t; - } - - /** - * Prevent this wrapper from creating its own stack trace. - */ - @Override - public final Throwable fillInStackTrace() { - return this; - } - - @Override - @NotNull - final java.lang.Throwable fromDJVM() { - return throwable; - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Double.java b/djvm/djvm/src/main/java/sandbox/java/lang/Double.java deleted file mode 100644 index d3488edde2..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Double.java +++ /dev/null @@ -1,163 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings({"unused", "WeakerAccess"}) -public final class Double extends Number implements Comparable { - public static final double POSITIVE_INFINITY = java.lang.Double.POSITIVE_INFINITY; - public static final double NEGATIVE_INFINITY = java.lang.Double.NEGATIVE_INFINITY; - public static final double NaN = java.lang.Double.NaN; - public static final double MAX_VALUE = java.lang.Double.MAX_VALUE; - public static final double MIN_NORMAL = java.lang.Double.MIN_NORMAL; - public static final double MIN_VALUE = java.lang.Double.MIN_VALUE; - public static final int MAX_EXPONENT = java.lang.Double.MAX_EXPONENT; - public static final int MIN_EXPONENT = java.lang.Double.MIN_EXPONENT; - public static final int BYTES = java.lang.Double.BYTES; - public static final int SIZE = java.lang.Double.SIZE; - - @SuppressWarnings("unchecked") - public static final Class TYPE = (Class) java.lang.Double.TYPE; - - private final double value; - - public Double(double value) { - this.value = value; - } - - public Double(String s) throws NumberFormatException { - this.value = parseDouble(s); - } - - @Override - public double doubleValue() { - return value; - } - - @Override - public float floatValue() { - return (float)value; - } - - @Override - public long longValue() { - return (long)value; - } - - @Override - public int intValue() { - return (int)value; - } - - @Override - public short shortValue() { - return (short)value; - } - - @Override - public byte byteValue() { - return (byte)value; - } - - public boolean isNaN() { - return java.lang.Double.isNaN(value); - } - - public boolean isInfinite() { - return isInfinite(this.value); - } - - @Override - public boolean equals(java.lang.Object other) { - return (other instanceof Double) && doubleToLongBits(((Double)other).value) == doubleToLongBits(value); - } - - @Override - public int hashCode() { - return hashCode(value); - } - - public static int hashCode(double d) { - return java.lang.Double.hashCode(d); - } - - @Override - @NotNull - public java.lang.String toString() { - return java.lang.Double.toString(value); - } - - @Override - @NotNull - java.lang.Double fromDJVM() { - return value; - } - - @Override - public int compareTo(@NotNull Double other) { - return compare(this.value, other.value); - } - - public static String toString(double d) { - return String.toDJVM(java.lang.Double.toString(d)); - } - - public static String toHexString(double d) { - return String.toDJVM(java.lang.Double.toHexString(d)); - } - - public static Double valueOf(String s) throws NumberFormatException { - return toDJVM(java.lang.Double.valueOf(String.fromDJVM(s))); - } - - public static Double valueOf(double d) { - return new Double(d); - } - - public static double parseDouble(String s) throws NumberFormatException { - return java.lang.Double.parseDouble(String.fromDJVM(s)); - } - - public static boolean isNaN(double d) { - return java.lang.Double.isNaN(d); - } - - public static boolean isInfinite(double d) { - return java.lang.Double.isInfinite(d); - } - - public static boolean isFinite(double d) { - return java.lang.Double.isFinite(d); - } - - public static long doubleToLongBits(double d) { - return java.lang.Double.doubleToLongBits(d); - } - - public static long doubleToRawLongBits(double d) { - return java.lang.Double.doubleToRawLongBits(d); - } - - public static double longBitsToDouble(long bits) { - return java.lang.Double.longBitsToDouble(bits); - } - - public static int compare(double d1, double d2) { - return java.lang.Double.compare(d1, d2); - } - - public static double sum(double a, double b) { - return java.lang.Double.sum(a, b); - } - - public static double max(double a, double b) { - return java.lang.Double.max(a, b); - } - - public static double min(double a, double b) { - return java.lang.Double.min(a, b); - } - - public static Double toDJVM(java.lang.Double d) { - return (d == null) ? null : valueOf(d); - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Enum.java b/djvm/djvm/src/main/java/sandbox/java/lang/Enum.java deleted file mode 100644 index d3a4bf352e..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Enum.java +++ /dev/null @@ -1,35 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -import java.io.Serializable; - -/** - * This is a dummy class. We will load the actual Enum class at run-time. - */ -@SuppressWarnings({"unused", "WeakerAccess"}) -public abstract class Enum> extends Object implements Comparable, Serializable { - - private final String name; - private final int ordinal; - - protected Enum(String name, int ordinal) { - this.name = name; - this.ordinal = ordinal; - } - - public String name() { - return name; - } - - public int ordinal() { - return ordinal; - } - - @Override - @NotNull - final java.lang.Enum fromDJVM() { - throw new UnsupportedOperationException("Dummy implementation"); - } - -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Float.java b/djvm/djvm/src/main/java/sandbox/java/lang/Float.java deleted file mode 100644 index bebc75f916..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Float.java +++ /dev/null @@ -1,163 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings({"unused", "WeakerAccess"}) -public final class Float extends Number implements Comparable { - public static final float POSITIVE_INFINITY = java.lang.Float.POSITIVE_INFINITY; - public static final float NEGATIVE_INFINITY = java.lang.Float.NEGATIVE_INFINITY; - public static final float NaN = java.lang.Float.NaN; - public static final float MAX_VALUE = java.lang.Float.MAX_VALUE; - public static final float MIN_NORMAL = java.lang.Float.MIN_NORMAL; - public static final float MIN_VALUE = java.lang.Float.MIN_VALUE; - public static final int MAX_EXPONENT = java.lang.Float.MAX_EXPONENT; - public static final int MIN_EXPONENT = java.lang.Float.MIN_EXPONENT; - public static final int BYTES = java.lang.Float.BYTES; - public static final int SIZE = java.lang.Float.SIZE; - - @SuppressWarnings("unchecked") - public static final Class TYPE = (Class) java.lang.Float.TYPE; - - private final float value; - - public Float(float value) { - this.value = value; - } - - public Float(String s) throws NumberFormatException { - this.value = parseFloat(s); - } - - @Override - public int hashCode() { - return hashCode(value); - } - - public static int hashCode(float f) { - return java.lang.Float.hashCode(f); - } - - @Override - public boolean equals(java.lang.Object other) { - return other instanceof Float && floatToIntBits(((Float)other).value) == floatToIntBits(this.value); - } - - @Override - @NotNull - public java.lang.String toString() { - return java.lang.Float.toString(value); - } - - @Override - @NotNull - java.lang.Float fromDJVM() { - return value; - } - - @Override - public double doubleValue() { - return (double)value; - } - - @Override - public float floatValue() { - return value; - } - - @Override - public long longValue() { - return (long)value; - } - - @Override - public int intValue() { - return (int)value; - } - - @Override - public short shortValue() { - return (short)value; - } - - @Override - public byte byteValue() { - return (byte)value; - } - - @Override - public int compareTo(@NotNull Float other) { - return compare(this.value, other.value); - } - - public boolean isNaN() { - return isNaN(value); - } - - public boolean isInfinite() { - return isInfinite(value); - } - - public static String toString(float f) { - return String.valueOf(f); - } - - public static String toHexString(float f) { - return String.toDJVM(java.lang.Float.toHexString(f)); - } - - public static Float valueOf(String s) throws NumberFormatException { - return toDJVM(java.lang.Float.valueOf(String.fromDJVM(s))); - } - - public static Float valueOf(float f) { - return new Float(f); - } - - public static float parseFloat(String s) throws NumberFormatException { - return java.lang.Float.parseFloat(String.fromDJVM(s)); - } - - public static boolean isNaN(float f) { - return java.lang.Float.isNaN(f); - } - - public static boolean isInfinite(float f) { - return java.lang.Float.isInfinite(f); - } - - public static boolean isFinite(float f) { - return java.lang.Float.isFinite(f); - } - - public static int floatToIntBits(float f) { - return java.lang.Float.floatToIntBits(f); - } - - public static int floatToRawIntBits(float f) { - return java.lang.Float.floatToIntBits(f); - } - - public static float intBitsToFloat(int bits) { - return java.lang.Float.intBitsToFloat(bits); - } - - public static int compare(float f1, float f2) { - return java.lang.Float.compare(f1, f2); - } - - public static float sum(float a, float b) { - return java.lang.Float.sum(a, b); - } - - public static float max(float a, float b) { - return java.lang.Float.max(a, b); - } - - public static float min(float a, float b) { - return java.lang.Float.min(a, b); - } - - public static Float toDJVM(java.lang.Float f) { - return (f == null) ? null : valueOf(f); - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Integer.java b/djvm/djvm/src/main/java/sandbox/java/lang/Integer.java deleted file mode 100644 index ae05ea0f91..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Integer.java +++ /dev/null @@ -1,241 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings({"unused", "WeakerAccess"}) -public final class Integer extends Number implements Comparable { - - public static final int MIN_VALUE = java.lang.Integer.MIN_VALUE; - public static final int MAX_VALUE = java.lang.Integer.MAX_VALUE; - public static final int BYTES = java.lang.Integer.BYTES; - public static final int SIZE = java.lang.Integer.SIZE; - - static final int[] SIZE_TABLE = new int[] { 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, MAX_VALUE }; - - @SuppressWarnings("unchecked") - public static final Class TYPE = (Class) java.lang.Integer.TYPE; - - private final int value; - - public Integer(int value) { - this.value = value; - } - - public Integer(String s) throws NumberFormatException { - this.value = parseInt(s, 10); - } - - @Override - public int hashCode() { - return Integer.hashCode(value); - } - - public static int hashCode(int i) { - return java.lang.Integer.hashCode(i); - } - - @Override - public boolean equals(java.lang.Object other) { - return (other instanceof Integer) && (value == ((Integer) other).value); - } - - @Override - public int intValue() { - return value; - } - - @Override - public long longValue() { - return value; - } - - @Override - public short shortValue() { - return (short) value; - } - - @Override - public byte byteValue() { - return (byte) value; - } - - @Override - public float floatValue() { - return (float) value; - } - - @Override - public double doubleValue() { - return (double) value; - } - - @Override - public int compareTo(@NotNull Integer other) { - return compare(this.value, other.value); - } - - @Override - @NotNull - public java.lang.String toString() { - return java.lang.Integer.toString(value); - } - - @Override - @NotNull - java.lang.Integer fromDJVM() { - return value; - } - - public static String toString(int i, int radix) { - return String.toDJVM(java.lang.Integer.toString(i, radix)); - } - - public static String toUnsignedString(int i, int radix) { - return String.toDJVM(java.lang.Integer.toUnsignedString(i, radix)); - } - - public static String toHexString(int i) { - return String.toDJVM(java.lang.Integer.toHexString(i)); - } - - public static String toOctalString(int i) { - return String.toDJVM(java.lang.Integer.toOctalString(i)); - } - - public static String toBinaryString(int i) { - return String.toDJVM(java.lang.Integer.toBinaryString(i)); - } - - public static String toString(int i) { - return String.toDJVM(java.lang.Integer.toString(i)); - } - - public static String toUnsignedString(int i) { - return String.toDJVM(java.lang.Integer.toUnsignedString(i)); - } - - public static int parseInt(String s, int radix) throws NumberFormatException { - return java.lang.Integer.parseInt(String.fromDJVM(s), radix); - } - - public static int parseInt(String s) throws NumberFormatException { - return java.lang.Integer.parseInt(String.fromDJVM(s)); - } - - public static int parseUnsignedInt(String s, int radix) throws NumberFormatException { - return java.lang.Integer.parseUnsignedInt(String.fromDJVM(s), radix); - } - - public static int parseUnsignedInt(String s) throws NumberFormatException { - return java.lang.Integer.parseUnsignedInt(String.fromDJVM(s)); - } - - public static Integer valueOf(String s, int radix) throws NumberFormatException { - return toDJVM(java.lang.Integer.valueOf(String.fromDJVM(s), radix)); - } - - public static Integer valueOf(String s) throws NumberFormatException { - return toDJVM(java.lang.Integer.valueOf(String.fromDJVM(s))); - } - - public static Integer valueOf(int i) { - return new Integer(i); - } - - public static Integer decode(String nm) throws NumberFormatException { - return new Integer(java.lang.Integer.decode(String.fromDJVM(nm))); - } - - public static int compare(int x, int y) { - return java.lang.Integer.compare(x, y); - } - - public static int compareUnsigned(int x, int y) { - return java.lang.Integer.compareUnsigned(x, y); - } - - public static long toUnsignedLong(int x) { - return java.lang.Integer.toUnsignedLong(x); - } - - public static int divideUnsigned(int dividend, int divisor) { - return java.lang.Integer.divideUnsigned(dividend, divisor); - } - - public static int remainderUnsigned(int dividend, int divisor) { - return java.lang.Integer.remainderUnsigned(dividend, divisor); - } - - public static int highestOneBit(int i) { - return java.lang.Integer.highestOneBit(i); - } - - public static int lowestOneBit(int i) { - return java.lang.Integer.lowestOneBit(i); - } - - public static int numberOfLeadingZeros(int i) { - return java.lang.Integer.numberOfLeadingZeros(i); - } - - public static int numberOfTrailingZeros(int i) { - return java.lang.Integer.numberOfTrailingZeros(i); - } - - public static int bitCount(int i) { - return java.lang.Integer.bitCount(i); - } - - public static int rotateLeft(int i, int distance) { - return java.lang.Integer.rotateLeft(i, distance); - } - - public static int rotateRight(int i, int distance) { - return java.lang.Integer.rotateRight(i, distance); - } - - public static int reverse(int i) { - return java.lang.Integer.reverse(i); - } - - public static int signum(int i) { - return java.lang.Integer.signum(i); - } - - public static int reverseBytes(int i) { - return java.lang.Integer.reverseBytes(i); - } - - public static int sum(int a, int b) { - return java.lang.Integer.sum(a, b); - } - - public static int max(int a, int b) { - return java.lang.Integer.max(a, b); - } - - public static int min(int a, int b) { - return java.lang.Integer.min(a, b); - } - - public static Integer toDJVM(java.lang.Integer i) { - return (i == null) ? null : valueOf(i); - } - - static int stringSize(final int number) { - int i = 0; - while (number > SIZE_TABLE[i]) { - ++i; - } - return i + 1; - } - - static void getChars(final int number, int index, char[] buffer) { - java.lang.String s = java.lang.Integer.toString(number); - int length = s.length(); - - while (length > 0) { - buffer[--index] = s.charAt(--length); - } - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Iterable.java b/djvm/djvm/src/main/java/sandbox/java/lang/Iterable.java deleted file mode 100644 index 01f8108ac0..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Iterable.java +++ /dev/null @@ -1,15 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -import java.util.Iterator; - -/** - * This is a dummy class that implements just enough of {@link java.lang.Iterable} - * to allow us to compile {@link sandbox.java.lang.String}. - */ -public interface Iterable extends java.lang.Iterable { - @Override - @NotNull - Iterator iterator(); -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Long.java b/djvm/djvm/src/main/java/sandbox/java/lang/Long.java deleted file mode 100644 index 0f07158af1..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Long.java +++ /dev/null @@ -1,239 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings({"unused", "WeakerAccess"}) -public final class Long extends Number implements Comparable { - - public static final long MIN_VALUE = java.lang.Long.MIN_VALUE; - public static final long MAX_VALUE = java.lang.Long.MAX_VALUE; - public static final int BYTES = java.lang.Long.BYTES; - public static final int SIZE = java.lang.Long.SIZE; - - @SuppressWarnings("unchecked") - public static final Class TYPE = (Class) java.lang.Long.TYPE; - - private final long value; - - public Long(long value) { - this.value = value; - } - - public Long(String s) throws NumberFormatException { - this.value = parseLong(s, 10); - } - - @Override - public int hashCode() { - return hashCode(value); - } - - @Override - public boolean equals(java.lang.Object other) { - return (other instanceof Long) && ((Long) other).longValue() == value; - } - - public static int hashCode(long l) { - return java.lang.Long.hashCode(l); - } - - @Override - public int intValue() { - return (int) value; - } - - @Override - public long longValue() { - return value; - } - - @Override - public short shortValue() { - return (short) value; - } - - @Override - public byte byteValue() { - return (byte) value; - } - - @Override - public float floatValue() { - return (float) value; - } - - @Override - public double doubleValue() { - return (double) value; - } - - @Override - public int compareTo(@NotNull Long other) { - return compare(value, other.value); - } - - public static int compare(long x, long y) { - return java.lang.Long.compare(x, y); - } - - @Override - @NotNull - java.lang.Long fromDJVM() { - return value; - } - - @Override - @NotNull - public java.lang.String toString() { - return java.lang.Long.toString(value); - } - - public static String toString(long l) { - return String.toDJVM(java.lang.Long.toString(l)); - } - - public static String toString(long l, int radix) { - return String.toDJVM(java.lang.Long.toString(l, radix)); - } - - public static String toUnsignedString(long l, int radix) { - return String.toDJVM(java.lang.Long.toUnsignedString(l, radix)); - } - - public static String toUnsignedString(long l) { - return String.toDJVM(java.lang.Long.toUnsignedString(l)); - } - - public static String toHexString(long l) { - return String.toDJVM(java.lang.Long.toHexString(l)); - } - - public static String toOctalString(long l) { - return String.toDJVM(java.lang.Long.toOctalString(l)); - } - - public static String toBinaryString(long l) { - return String.toDJVM(java.lang.Long.toBinaryString(l)); - } - - public static long parseLong(String s, int radix) throws NumberFormatException { - return java.lang.Long.parseLong(String.fromDJVM(s), radix); - } - - public static long parseLong(String s) throws NumberFormatException { - return java.lang.Long.parseLong(String.fromDJVM(s)); - } - - public static long parseUnsignedLong(String s, int radix) throws NumberFormatException { - return java.lang.Long.parseUnsignedLong(String.fromDJVM(s), radix); - } - - public static long parseUnsignedLong(String s) throws NumberFormatException { - return java.lang.Long.parseUnsignedLong(String.fromDJVM(s)); - } - - public static Long valueOf(String s, int radix) throws NumberFormatException { - return toDJVM(java.lang.Long.valueOf(String.fromDJVM(s), radix)); - } - - public static Long valueOf(String s) throws NumberFormatException { - return toDJVM(java.lang.Long.valueOf(String.fromDJVM(s))); - } - - public static Long valueOf(long l) { - return new Long(l); - } - - public static Long decode(String s) throws NumberFormatException { - return toDJVM(java.lang.Long.decode(String.fromDJVM(s))); - } - - public static int compareUnsigned(long x, long y) { - return java.lang.Long.compareUnsigned(x, y); - } - - public static long divideUnsigned(long dividend, long divisor) { - return java.lang.Long.divideUnsigned(dividend, divisor); - } - - public static long remainderUnsigned(long dividend, long divisor) { - return java.lang.Long.remainderUnsigned(dividend, divisor); - } - - public static long highestOneBit(long l) { - return java.lang.Long.highestOneBit(l); - } - - public static long lowestOneBit(long l) { - return java.lang.Long.lowestOneBit(l); - } - - public static int numberOfLeadingZeros(long l) { - return java.lang.Long.numberOfLeadingZeros(l); - } - - public static int numberOfTrailingZeros(long l) { - return java.lang.Long.numberOfTrailingZeros(l); - } - - public static int bitCount(long l) { - return java.lang.Long.bitCount(l); - } - - public static long rotateLeft(long i, int distance) { - return java.lang.Long.rotateLeft(i, distance); - } - - public static long rotateRight(long i, int distance) { - return java.lang.Long.rotateRight(i, distance); - } - - public static long reverse(long l) { - return java.lang.Long.reverse(l); - } - - public static int signum(long l) { - return java.lang.Long.signum(l); - } - - public static long reverseBytes(long l) { - return java.lang.Long.reverseBytes(l); - } - - public static long sum(long a, long b) { - return java.lang.Long.sum(a, b); - } - - public static long max(long a, long b) { - return java.lang.Long.max(a, b); - } - - public static long min(long a, long b) { - return java.lang.Long.min(a, b); - } - - public static Long toDJVM(java.lang.Long l) { - return (l == null) ? null : valueOf(l); - } - - static int stringSize(final long number) { - long l = 10; - int i = 1; - - while ((i < 19) && (number >= l)) { - l *= 10; - ++i; - } - - return i; - } - - static void getChars(final long number, int index, char[] buffer) { - java.lang.String s = java.lang.Long.toString(number); - int length = s.length(); - - while (length > 0) { - buffer[--index] = s.charAt(--length); - } - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Number.java b/djvm/djvm/src/main/java/sandbox/java/lang/Number.java deleted file mode 100644 index 89d0a7fd8e..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Number.java +++ /dev/null @@ -1,21 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; -import java.io.Serializable; - -@SuppressWarnings("unused") -public abstract class Number extends Object implements Serializable { - - public abstract double doubleValue(); - public abstract float floatValue(); - public abstract long longValue(); - public abstract int intValue(); - public abstract short shortValue(); - public abstract byte byteValue(); - - @Override - @NotNull - public String toDJVMString() { - return String.toDJVM(toString()); - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Object.java b/djvm/djvm/src/main/java/sandbox/java/lang/Object.java deleted file mode 100644 index bcceaecbf2..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Object.java +++ /dev/null @@ -1,70 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; -import sandbox.net.corda.djvm.rules.RuleViolationError; - -public class Object { - - @Override - public int hashCode() { - return sandbox.java.lang.System.identityHashCode(this); - } - - @Override - @NotNull - public java.lang.String toString() { - return toDJVMString().toString(); - } - - @NotNull - public String toDJVMString() { - return String.toDJVM("sandbox.java.lang.Object@" + java.lang.Integer.toString(hashCode(), 16)); - } - - @NotNull - java.lang.Object fromDJVM() { - return this; - } - - public static java.lang.Object[] fromDJVM(java.lang.Object[] args) { - if (args == null) { - return null; - } - - java.lang.Object[] unwrapped = (java.lang.Object[]) java.lang.reflect.Array.newInstance( - fromDJVM(args.getClass().getComponentType()), args.length - ); - int i = 0; - for (java.lang.Object arg : args) { - unwrapped[i] = unwrap(arg); - ++i; - } - return unwrapped; - } - - private static java.lang.Object unwrap(java.lang.Object arg) { - if (arg instanceof Object) { - return ((Object) arg).fromDJVM(); - } else if (java.lang.Object[].class.isAssignableFrom(arg.getClass())) { - return fromDJVM((java.lang.Object[]) arg); - } else { - return arg; - } - } - - private static Class fromDJVM(Class type) { - try { - return DJVM.fromDJVMType(type); - } catch (ClassNotFoundException e) { - throw new RuleViolationError(e.getMessage()); - } - } - - static java.util.Locale fromDJVM(sandbox.java.util.Locale locale) { - return java.util.Locale.forLanguageTag(locale.toLanguageTag().fromDJVM()); - } - - static java.nio.charset.Charset fromDJVM(sandbox.java.nio.charset.Charset charset) { - return java.nio.charset.Charset.forName(charset.name().fromDJVM()); - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Runtime.java b/djvm/djvm/src/main/java/sandbox/java/lang/Runtime.java deleted file mode 100644 index 830233072b..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Runtime.java +++ /dev/null @@ -1,27 +0,0 @@ -package sandbox.java.lang; - -@SuppressWarnings("unused") -public final class Runtime extends Object { - private static final Runtime RUNTIME = new Runtime(); - - private Runtime() {} - - public static Runtime getRuntime() { - return RUNTIME; - } - - /** - * Everything inside the sandbox is single-threaded. - * @return 1 - */ - public int availableProcessors() { - return 1; - } - - public void loadLibrary(String libraryName) {} - - public void load(String fileName) {} - - public void runFinalization() {} - public void gc() {} -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Short.java b/djvm/djvm/src/main/java/sandbox/java/lang/Short.java deleted file mode 100644 index a0e1cbfd39..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Short.java +++ /dev/null @@ -1,128 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings({"unused", "WeakerAccess"}) -public final class Short extends Number implements Comparable { - public static final short MIN_VALUE = java.lang.Short.MIN_VALUE; - public static final short MAX_VALUE = java.lang.Short.MAX_VALUE; - public static final int BYTES = java.lang.Short.BYTES; - public static final int SIZE = java.lang.Short.SIZE; - - @SuppressWarnings("unchecked") - public static final Class TYPE = (Class) java.lang.Short.TYPE; - - private final short value; - - public Short(short value) { - this.value = value; - } - - public Short(String s) throws NumberFormatException { - this.value = parseShort(s); - } - - @Override - public byte byteValue() { - return (byte)value; - } - - @Override - public short shortValue() { - return value; - } - - @Override - public int intValue() { - return value; - } - - @Override - public long longValue() { - return (long)value; - } - - @Override - public float floatValue() { - return (float)value; - } - - @Override - public double doubleValue() { - return (double)value; - } - - @Override - @NotNull - public java.lang.String toString() { - return java.lang.Integer.toString(value); - } - - @Override - @NotNull - java.lang.Short fromDJVM() { - return value; - } - - @Override - public int hashCode() { - return hashCode(value); - } - - public static int hashCode(short value) { - return java.lang.Short.hashCode(value); - } - - @Override - public boolean equals(java.lang.Object other) { - return (other instanceof Short) && ((Short) other).value == value; - } - - public int compareTo(@NotNull Short other) { - return compare(this.value, other.value); - } - - public static int compare(short x, short y) { - return java.lang.Short.compare(x, y); - } - - public static short reverseBytes(short value) { - return java.lang.Short.reverseBytes(value); - } - - public static int toUnsignedInt(short x) { - return java.lang.Short.toUnsignedInt(x); - } - - public static long toUnsignedLong(short x) { - return java.lang.Short.toUnsignedLong(x); - } - - public static short parseShort(String s, int radix) throws NumberFormatException { - return java.lang.Short.parseShort(String.fromDJVM(s), radix); - } - - public static short parseShort(String s) throws NumberFormatException { - return java.lang.Short.parseShort(String.fromDJVM(s)); - } - - public static Short valueOf(String s, int radix) throws NumberFormatException { - return toDJVM(java.lang.Short.valueOf(String.fromDJVM(s), radix)); - } - - public static Short valueOf(String s) throws NumberFormatException { - return toDJVM(java.lang.Short.valueOf(String.fromDJVM(s))); - } - - public static Short valueOf(short s) { - return new Short(s); - } - - public static Short decode(String nm) throws NumberFormatException { - return toDJVM(java.lang.Short.decode(String.fromDJVM(nm))); - } - - public static Short toDJVM(java.lang.Short i) { - return (i == null) ? null : valueOf(i); - } -} \ No newline at end of file diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/StackTraceElement.java b/djvm/djvm/src/main/java/sandbox/java/lang/StackTraceElement.java deleted file mode 100644 index 7b8173134a..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/StackTraceElement.java +++ /dev/null @@ -1,46 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; - -/** - * This is a dummy class. We will load the genuine class at runtime. - */ -public final class StackTraceElement extends Object implements java.io.Serializable { - - private final String className; - private final String methodName; - private final String fileName; - private final int lineNumber; - - public StackTraceElement(String className, String methodName, String fileName, int lineNumber) { - this.className = className; - this.methodName = methodName; - this.fileName = fileName; - this.lineNumber = lineNumber; - } - - public String getClassName() { - return className; - } - - public String getMethodName() { - return methodName; - } - - public String getFileName() { - return fileName; - } - - public int getLineNumber() { - return lineNumber; - } - - @Override - @NotNull - public String toDJVMString() { - return String.toDJVM( - className.toString() + ':' + methodName.toString() - + (fileName != null ? '(' + fileName.toString() + ':' + lineNumber + ')' : "") - ); - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/String.java b/djvm/djvm/src/main/java/sandbox/java/lang/String.java deleted file mode 100644 index 7d9165f3b8..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/String.java +++ /dev/null @@ -1,424 +0,0 @@ -package sandbox.java.lang; - -import net.corda.djvm.SandboxRuntimeContext; -import org.jetbrains.annotations.NotNull; -import sandbox.java.nio.charset.Charset; -import sandbox.java.util.Comparator; -import sandbox.java.util.Locale; - -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Constructor; - -@SuppressWarnings("unused") -public final class String extends Object implements Comparable, CharSequence, Serializable { - public static final Comparator CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator(); - - private static class CaseInsensitiveComparator extends Object implements Comparator, Serializable { - @Override - public int compare(String s1, String s2) { - return java.lang.String.CASE_INSENSITIVE_ORDER.compare(String.fromDJVM(s1), String.fromDJVM(s2)); - } - } - - private static final String TRUE = new String("true"); - private static final String FALSE = new String("false"); - - private static final Constructor SHARED; - - static { - try { - SHARED = java.lang.String.class.getDeclaredConstructor(char[].class, java.lang.Boolean.TYPE); - SHARED.setAccessible(true); - } catch (NoSuchMethodException e) { - throw new NoSuchMethodError(e.getMessage()); - } - } - - private final java.lang.String value; - - public String() { - this.value = ""; - } - - public String(java.lang.String value) { - this.value = value; - } - - public String(char value[]) { - this.value = new java.lang.String(value); - } - - public String(char value[], int offset, int count) { - this.value = new java.lang.String(value, offset, count); - } - - public String(int[] codePoints, int offset, int count) { - this.value = new java.lang.String(codePoints, offset, count); - } - - @Deprecated - public String(byte ascii[], int hibyte, int offset, int count) { - this.value = new java.lang.String(ascii, hibyte, offset, count); - } - - @Deprecated - public String(byte ascii[], int hibyte) { - this.value = new java.lang.String(ascii, hibyte); - } - - public String(byte bytes[], int offset, int length, String charsetName) - throws UnsupportedEncodingException { - this.value = new java.lang.String(bytes, offset, length, fromDJVM(charsetName)); - } - - public String(byte bytes[], int offset, int length, Charset charset) { - this.value = new java.lang.String(bytes, offset, length, fromDJVM(charset)); - } - - public String(byte bytes[], String charsetName) - throws UnsupportedEncodingException { - this.value = new java.lang.String(bytes, fromDJVM(charsetName)); - } - - public String(byte bytes[], Charset charset) { - this.value = new java.lang.String(bytes, fromDJVM(charset)); - } - - public String(byte bytes[], int offset, int length) { - this.value = new java.lang.String(bytes, offset, length); - } - - public String(byte bytes[]) { - this.value = new java.lang.String(bytes); - } - - public String(StringBuffer buffer) { - this.value = buffer.toString(); - } - - public String(StringBuilder builder) { - this.value = builder.toString(); - } - - String(char[] value, boolean share) { - java.lang.String newValue; - try { - // This is (presumably) an optimisation for memory usage. - newValue = (java.lang.String) SHARED.newInstance(value, share); - } catch (Exception e) { - newValue = new java.lang.String(value); - } - this.value = newValue; - } - - @Override - public char charAt(int index) { - return value.charAt(index); - } - - @Override - public int length() { - return value.length(); - } - - public boolean isEmpty() { - return value.isEmpty(); - } - - public int codePointAt(int index) { - return value.codePointAt(index); - } - - public int codePointBefore(int index) { - return value.codePointBefore(index); - } - - public int codePointCount(int beginIndex, int endIndex) { - return value.codePointCount(beginIndex, endIndex); - } - - public int offsetByCodePoints(int index, int codePointOffset) { - return value.offsetByCodePoints(index, codePointOffset); - } - - public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) { - value.getChars(srcBegin, srcEnd, dst, dstBegin); - } - - @Deprecated - public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) { - value.getBytes(srcBegin, srcEnd, dst, dstBegin); - } - - public byte[] getBytes(String charsetName) throws UnsupportedEncodingException { - return value.getBytes(fromDJVM(charsetName)); - } - - public byte[] getBytes(Charset charset) { - return value.getBytes(fromDJVM(charset)); - } - - public byte[] getBytes() { - return value.getBytes(); - } - - @Override - public boolean equals(java.lang.Object other) { - return (other instanceof String) && ((String) other).value.equals(value); - } - - @Override - public int hashCode() { - return value.hashCode(); - } - - @Override - @NotNull - public java.lang.String toString() { - return value; - } - - @Override - @NotNull - public String toDJVMString() { - return this; - } - - @Override - @NotNull - java.lang.String fromDJVM() { - return value; - } - - public boolean contentEquals(StringBuffer sb) { - return value.contentEquals((CharSequence) sb); - } - - public boolean contentEquals(CharSequence cs) { - return value.contentEquals(cs); - } - - public boolean equalsIgnoreCase(String anotherString) { - return value.equalsIgnoreCase(fromDJVM(anotherString)); - } - - @Override - public CharSequence subSequence(int start, int end) { - return toDJVM((java.lang.String) value.subSequence(start, end)); - } - - @Override - public int compareTo(@NotNull String other) { - return value.compareTo(other.toString()); - } - - public int compareToIgnoreCase(String str) { - return value.compareToIgnoreCase(fromDJVM(str)); - } - - public boolean regionMatches(int toffset, String other, int ooffset, int len) { - return value.regionMatches(toffset, fromDJVM(other), ooffset, len); - } - - public boolean regionMatches(boolean ignoreCase, int toffset, - String other, int ooffset, int len) { - return value.regionMatches(ignoreCase, toffset, fromDJVM(other), ooffset, len); - } - - public boolean startsWith(String prefix, int toffset) { - return value.startsWith(fromDJVM(prefix), toffset); - } - - public boolean startsWith(String prefix) { - return value.startsWith(fromDJVM(prefix)); - } - - public boolean endsWith(String suffix) { - return value.endsWith(fromDJVM(suffix)); - } - - public int indexOf(int ch) { - return value.indexOf(ch); - } - - public int indexOf(int ch, int fromIndex) { - return value.indexOf(ch, fromIndex); - } - - public int lastIndexOf(int ch) { - return value.lastIndexOf(ch); - } - - public int lastIndexOf(int ch, int fromIndex) { - return value.lastIndexOf(ch, fromIndex); - } - - public int indexOf(String str) { - return value.indexOf(fromDJVM(str)); - } - - public int indexOf(String str, int fromIndex) { - return value.indexOf(fromDJVM(str), fromIndex); - } - - public int lastIndexOf(String str) { - return value.lastIndexOf(fromDJVM(str)); - } - - public int lastIndexOf(String str, int fromIndex) { - return value.lastIndexOf(fromDJVM(str), fromIndex); - } - - public String substring(int beginIndex) { - return toDJVM(value.substring(beginIndex)); - } - - public String substring(int beginIndex, int endIndex) { - return toDJVM(value.substring(beginIndex, endIndex)); - } - - public String concat(String str) { - return toDJVM(value.concat(fromDJVM(str))); - } - - public String replace(char oldChar, char newChar) { - return toDJVM(value.replace(oldChar, newChar)); - } - - public boolean matches(String regex) { - return value.matches(fromDJVM(regex)); - } - - public boolean contains(CharSequence s) { - return value.contains(s); - } - - public String replaceFirst(String regex, String replacement) { - return toDJVM(value.replaceFirst(fromDJVM(regex), fromDJVM(replacement))); - } - - public String replaceAll(String regex, String replacement) { - return toDJVM(value.replaceAll(fromDJVM(regex), fromDJVM(replacement))); - } - - public String replace(CharSequence target, CharSequence replacement) { - return toDJVM(value.replace(target, replacement)); - } - - public String[] split(String regex, int limit) { - return toDJVM(value.split(fromDJVM(regex), limit)); - } - - public String[] split(String regex) { - return toDJVM(value.split(fromDJVM(regex))); - } - - public String toLowerCase(Locale locale) { - return toDJVM(value.toLowerCase(fromDJVM(locale))); - } - - public String toLowerCase() { - return toDJVM(value.toLowerCase()); - } - - public String toUpperCase(Locale locale) { - return toDJVM(value.toUpperCase(fromDJVM(locale))); - } - - public String toUpperCase() { - return toDJVM(value.toUpperCase()); - } - - public String trim() { - return toDJVM(value.trim()); - } - - public String intern() { return (String) SandboxRuntimeContext.getInstance().intern(value, this); } - - public char[] toCharArray() { - return value.toCharArray(); - } - - public static String format(String format, java.lang.Object... args) { - return toDJVM(java.lang.String.format(fromDJVM(format), fromDJVM(args))); - } - - public static String format(Locale locale, String format, java.lang.Object... args) { - return toDJVM(java.lang.String.format(fromDJVM(locale), fromDJVM(format), fromDJVM(args))); - } - - public static String join(CharSequence delimiter, CharSequence... elements) { - return toDJVM(java.lang.String.join(delimiter, elements)); - } - - public static String join(CharSequence delimiter, - Iterable elements) { - return toDJVM(java.lang.String.join(delimiter, elements)); - } - - public static String valueOf(java.lang.Object obj) { - return (obj instanceof Object) ? ((Object) obj).toDJVMString() : toDJVM(java.lang.String.valueOf(obj)); - } - - public static String valueOf(char data[]) { - return toDJVM(java.lang.String.valueOf(data)); - } - - public static String valueOf(char data[], int offset, int count) { - return toDJVM(java.lang.String.valueOf(data, offset, count)); - } - - public static String copyValueOf(char data[], int offset, int count) { - return toDJVM(java.lang.String.copyValueOf(data, offset, count)); - } - - public static String copyValueOf(char data[]) { - return toDJVM(java.lang.String.copyValueOf(data)); - } - - public static String valueOf(boolean b) { - return b ? TRUE : FALSE; - } - - public static String valueOf(char c) { - return toDJVM(java.lang.String.valueOf(c)); - } - - public static String valueOf(int i) { - return toDJVM(java.lang.String.valueOf(i)); - } - - public static String valueOf(long l) { - return toDJVM(java.lang.String.valueOf(l)); - } - - public static String valueOf(float f) { - return toDJVM(java.lang.String.valueOf(f)); - } - - public static String valueOf(double d) { - return toDJVM(java.lang.String.valueOf(d)); - } - - static String[] toDJVM(java.lang.String[] value) { - if (value == null) { - return null; - } - String[] result = new String[value.length]; - int i = 0; - for (java.lang.String v : value) { - result[i] = toDJVM(v); - ++i; - } - return result; - } - - public static String toDJVM(java.lang.String value) { - return (value == null) ? null : new String(value); - } - - public static java.lang.String fromDJVM(String value) { - return (value == null) ? null : value.fromDJVM(); - } -} \ No newline at end of file diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/StringBuffer.java b/djvm/djvm/src/main/java/sandbox/java/lang/StringBuffer.java deleted file mode 100644 index 4d8fea7e1d..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/StringBuffer.java +++ /dev/null @@ -1,20 +0,0 @@ -package sandbox.java.lang; - -import java.io.Serializable; - -/** - * This is a dummy class that implements just enough of {@link java.lang.StringBuffer} - * to allow us to compile {@link sandbox.java.lang.String}. - */ -public abstract class StringBuffer extends Object implements CharSequence, Appendable, Serializable { - - @Override - public abstract StringBuffer append(CharSequence seq); - - @Override - public abstract StringBuffer append(CharSequence seq, int start, int end); - - @Override - public abstract StringBuffer append(char c); - -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/StringBuilder.java b/djvm/djvm/src/main/java/sandbox/java/lang/StringBuilder.java deleted file mode 100644 index a90fef7dde..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/StringBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package sandbox.java.lang; - -import java.io.Serializable; - -/** - * This is a dummy class that implements just enough of {@link java.lang.StringBuilder} - * to allow us to compile {@link sandbox.java.lang.String}. - */ -public abstract class StringBuilder extends Object implements Appendable, CharSequence, Serializable { - - @Override - public abstract StringBuilder append(CharSequence seq); - - @Override - public abstract StringBuilder append(CharSequence seq, int start, int end); - - @Override - public abstract StringBuilder append(char c); - -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/System.java b/djvm/djvm/src/main/java/sandbox/java/lang/System.java deleted file mode 100644 index b68a36d83c..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/System.java +++ /dev/null @@ -1,23 +0,0 @@ -package sandbox.java.lang; - -import net.corda.djvm.SandboxRuntimeContext; - -@SuppressWarnings({"WeakerAccess", "unused"}) -public final class System extends Object { - - private System() {} - - public static int identityHashCode(java.lang.Object obj) { - int nativeHashCode = java.lang.System.identityHashCode(obj); - return SandboxRuntimeContext.getInstance().getHashCodeFor(nativeHashCode); - } - - public static final String lineSeparator = String.toDJVM("\n"); - - public static void arraycopy(java.lang.Object src, int srcPos, java.lang.Object dest, int destPos, int length) { - java.lang.System.arraycopy(src, srcPos, dest, destPos, length); - } - - public static void runFinalization() {} - public static void gc() {} -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/ThreadLocal.java b/djvm/djvm/src/main/java/sandbox/java/lang/ThreadLocal.java deleted file mode 100644 index 8a2853bf82..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/ThreadLocal.java +++ /dev/null @@ -1,59 +0,0 @@ -package sandbox.java.lang; - -import sandbox.java.util.function.Supplier; - -/** - * Everything inside the sandbox is single-threaded, so this - * implementation of ThreadLocal is sufficient. - * @param Underlying type of this thread-local variable. - */ -@SuppressWarnings({"unused", "WeakerAccess"}) -public class ThreadLocal extends Object { - - private T value; - private boolean isSet; - - public ThreadLocal() { - } - - protected T initialValue() { - return null; - } - - public T get() { - if (!isSet) { - set(initialValue()); - } - return value; - } - - public void set(T value) { - this.value = value; - this.isSet = true; - } - - public void remove() { - value = null; - isSet = false; - } - - public static ThreadLocal withInitial(Supplier supplier) { - return new SuppliedThreadLocal<>(supplier); - } - - // Stub class for compiling ThreadLocal. The sandbox will import the - // actual SuppliedThreadLocal class at run-time. Having said that, we - // still need a working implementation here for the sake of our tests. - static final class SuppliedThreadLocal extends ThreadLocal { - private final Supplier supplier; - - SuppliedThreadLocal(Supplier supplier) { - this.supplier = supplier; - } - - @Override - protected T initialValue() { - return supplier.get(); - } - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/lang/Throwable.java b/djvm/djvm/src/main/java/sandbox/java/lang/Throwable.java deleted file mode 100644 index df19e2fc6e..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/lang/Throwable.java +++ /dev/null @@ -1,137 +0,0 @@ -package sandbox.java.lang; - -import org.jetbrains.annotations.NotNull; -import sandbox.TaskTypes; - -import java.io.Serializable; - -@SuppressWarnings({"unused", "WeakerAccess"}) -public class Throwable extends Object implements Serializable { - private static final StackTraceElement[] NO_STACK_TRACE = new StackTraceElement[0]; - - private String message; - private Throwable cause; - private StackTraceElement[] stackTrace; - - public Throwable() { - this.cause = this; - fillInStackTrace(); - } - - public Throwable(String message) { - this(); - this.message = message; - } - - public Throwable(Throwable cause) { - this.cause = cause; - this.message = (cause == null) ? null : cause.toDJVMString(); - fillInStackTrace(); - } - - public Throwable(String message, Throwable cause) { - this.message = message; - this.cause = cause; - fillInStackTrace(); - } - - protected Throwable(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - if (writableStackTrace) { - fillInStackTrace(); - } else { - stackTrace = NO_STACK_TRACE; - } - this.message = message; - this.cause = cause; - } - - public String getMessage() { - return message; - } - - public String getLocalizedMessage() { - return getMessage(); - } - - public Throwable getCause() { - return (cause == this) ? null : cause; - } - - public Throwable initCause(Throwable cause) { - if (this.cause != this) { - throw new java.lang.IllegalStateException( - "Can't overwrite cause with " + java.util.Objects.toString(cause, "a null"), fromDJVM()); - } - if (cause == this) { - throw new java.lang.IllegalArgumentException("Self-causation not permitted", fromDJVM()); - } - this.cause = cause; - return this; - } - - @Override - @NotNull - public String toDJVMString() { - java.lang.String s = getClass().getName(); - String localized = getLocalizedMessage(); - return String.valueOf((localized != null) ? (s + ": " + localized.toString()) : s); - } - - public StackTraceElement[] getStackTrace() { - return (stackTrace == NO_STACK_TRACE) ? stackTrace : stackTrace.clone(); - } - - public void setStackTrace(StackTraceElement[] stackTrace) { - StackTraceElement[] traceCopy = stackTrace.clone(); - - for (int i = 0; i < traceCopy.length; ++i) { - if (traceCopy[i] == null) { - throw new java.lang.NullPointerException("stackTrace[" + i + ']'); - } - } - - this.stackTrace = traceCopy; - } - - @SuppressWarnings({"ThrowableNotThrown", "UnusedReturnValue"}) - public Throwable fillInStackTrace() { - if (stackTrace == null) { - /* - * We have been invoked from within this exception's constructor. - * Work our way up the stack trace until we find this constructor, - * and then find out who actually invoked it. This is where our - * sandboxed stack trace will start from. - * - * Our stack trace will end at the point where we entered the sandbox. - */ - final java.lang.StackTraceElement[] elements = new java.lang.Throwable().getStackTrace(); - final java.lang.String exceptionName = getClass().getName(); - int startIdx = 1; - while (startIdx < elements.length && !isConstructorFor(elements[startIdx], exceptionName)) { - ++startIdx; - } - while (startIdx < elements.length && isConstructorFor(elements[startIdx], exceptionName)) { - ++startIdx; - } - - int endIdx = startIdx; - while (endIdx < elements.length && !TaskTypes.isEntryPoint(elements[endIdx])) { - ++endIdx; - } - stackTrace = (startIdx == elements.length) ? NO_STACK_TRACE : DJVM.copyToDJVM(elements, startIdx, endIdx); - } - return this; - } - - private static boolean isConstructorFor(java.lang.StackTraceElement elt, java.lang.String className) { - return elt.getClassName().equals(className) && elt.getMethodName().equals(""); - } - - public void printStackTrace() {} - - @Override - @NotNull - java.lang.Throwable fromDJVM() { - return DJVM.fromDJVM(this); - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/nio/charset/Charset.java b/djvm/djvm/src/main/java/sandbox/java/nio/charset/Charset.java deleted file mode 100644 index 453006bb7f..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/nio/charset/Charset.java +++ /dev/null @@ -1,18 +0,0 @@ -package sandbox.java.nio.charset; - -/** - * This is a dummy class that implements just enough of {@link java.nio.charset.Charset} - * to allow us to compile {@link sandbox.java.lang.String}. - */ -@SuppressWarnings("unused") -public abstract class Charset extends sandbox.java.lang.Object { - private final sandbox.java.lang.String canonicalName; - - protected Charset(sandbox.java.lang.String canonicalName, sandbox.java.lang.String[] aliases) { - this.canonicalName = canonicalName; - } - - public final sandbox.java.lang.String name() { - return canonicalName; - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/util/Comparator.java b/djvm/djvm/src/main/java/sandbox/java/util/Comparator.java deleted file mode 100644 index f6363d9c34..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/util/Comparator.java +++ /dev/null @@ -1,9 +0,0 @@ -package sandbox.java.util; - -/** - * This is a dummy class that implements just enough of {@link java.util.Comparator} - * to allow us to compile {@link sandbox.java.lang.String}. - */ -@FunctionalInterface -public interface Comparator extends java.util.Comparator { -} diff --git a/djvm/djvm/src/main/java/sandbox/java/util/LinkedHashMap.java b/djvm/djvm/src/main/java/sandbox/java/util/LinkedHashMap.java deleted file mode 100644 index 37d8c56210..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/util/LinkedHashMap.java +++ /dev/null @@ -1,13 +0,0 @@ -package sandbox.java.util; - -/** - * This is a dummy class to bootstrap us into the sandbox. - */ -public class LinkedHashMap extends java.util.LinkedHashMap implements Map { - public LinkedHashMap(int initialSize) { - super(initialSize); - } - - public LinkedHashMap() { - } -} diff --git a/djvm/djvm/src/main/java/sandbox/java/util/Locale.java b/djvm/djvm/src/main/java/sandbox/java/util/Locale.java deleted file mode 100644 index ed06b79058..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/util/Locale.java +++ /dev/null @@ -1,9 +0,0 @@ -package sandbox.java.util; - -/** - * This is a dummy class that implements just enough of {@link java.util.Locale} - * to allow us to compile {@link sandbox.java.lang.String}. - */ -public abstract class Locale extends sandbox.java.lang.Object { - public abstract sandbox.java.lang.String toLanguageTag(); -} diff --git a/djvm/djvm/src/main/java/sandbox/java/util/Map.java b/djvm/djvm/src/main/java/sandbox/java/util/Map.java deleted file mode 100644 index 576e462583..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/util/Map.java +++ /dev/null @@ -1,7 +0,0 @@ -package sandbox.java.util; - -/** - * This is a dummy class to bootstrap us into the sandbox. - */ -public interface Map extends java.util.Map { -} diff --git a/djvm/djvm/src/main/java/sandbox/java/util/function/Function.java b/djvm/djvm/src/main/java/sandbox/java/util/function/Function.java deleted file mode 100644 index ce26393f67..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/util/function/Function.java +++ /dev/null @@ -1,10 +0,0 @@ -package sandbox.java.util.function; - -/** - * This is a dummy class that implements just enough of {@link java.util.function.Function} - * to allow us to compile {@link sandbox.Task}. - */ -@FunctionalInterface -public interface Function { - R apply(T item); -} diff --git a/djvm/djvm/src/main/java/sandbox/java/util/function/Supplier.java b/djvm/djvm/src/main/java/sandbox/java/util/function/Supplier.java deleted file mode 100644 index 0ff9f56dfb..0000000000 --- a/djvm/djvm/src/main/java/sandbox/java/util/function/Supplier.java +++ /dev/null @@ -1,10 +0,0 @@ -package sandbox.java.util.function; - -/** - * This is a dummy class that implements just enough of @{link java.util.function.Supplier} - * to allow us to compile {@link sandbox.java.lang.ThreadLocal}. - */ -@FunctionalInterface -public interface Supplier { - T get(); -} diff --git a/djvm/djvm/src/main/java/sandbox/sun/misc/JavaLangAccess.java b/djvm/djvm/src/main/java/sandbox/sun/misc/JavaLangAccess.java deleted file mode 100644 index 189a7f9711..0000000000 --- a/djvm/djvm/src/main/java/sandbox/sun/misc/JavaLangAccess.java +++ /dev/null @@ -1,10 +0,0 @@ -package sandbox.sun.misc; - -import sandbox.java.lang.Enum; - -@SuppressWarnings("unused") -public interface JavaLangAccess { - - > E[] getEnumConstantsShared(Class enumClass); - -} diff --git a/djvm/djvm/src/main/java/sandbox/sun/misc/SharedSecrets.java b/djvm/djvm/src/main/java/sandbox/sun/misc/SharedSecrets.java deleted file mode 100644 index a03f7689c1..0000000000 --- a/djvm/djvm/src/main/java/sandbox/sun/misc/SharedSecrets.java +++ /dev/null @@ -1,20 +0,0 @@ -package sandbox.sun.misc; - -import sandbox.java.lang.Enum; - -@SuppressWarnings("unused") -public class SharedSecrets extends sandbox.java.lang.Object { - private static final JavaLangAccess javaLangAccess = new JavaLangAccessImpl(); - - private static class JavaLangAccessImpl implements JavaLangAccess { - @SuppressWarnings("unchecked") - @Override - public > E[] getEnumConstantsShared(Class enumClass) { - return (E[]) sandbox.java.lang.DJVM.getEnumConstantsShared(enumClass); - } - } - - public static JavaLangAccess getJavaLangAccess() { - return javaLangAccess; - } -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/SandboxConfiguration.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/SandboxConfiguration.kt deleted file mode 100644 index bacc8670b0..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/SandboxConfiguration.kt +++ /dev/null @@ -1,68 +0,0 @@ -package net.corda.djvm - -import net.corda.djvm.analysis.AnalysisConfiguration -import net.corda.djvm.code.DefinitionProvider -import net.corda.djvm.code.EMIT_TRACING -import net.corda.djvm.code.Emitter -import net.corda.djvm.execution.ExecutionProfile -import net.corda.djvm.rewiring.SandboxClassLoader -import net.corda.djvm.rules.Rule -import net.corda.djvm.utilities.Discovery - -/** - * Configuration to use for the deterministic sandbox. - * - * @property rules The rules to apply during the analysis phase. - * @property emitters The code emitters / re-writers to apply to all loaded classes. - * @property definitionProviders The meta-data providers to apply to class and member definitions. - * @property executionProfile The execution profile to use in the sandbox. - * @property analysisConfiguration The configuration used in the analysis of classes. - * @property parentClassLoader The [SandboxClassLoader] that this sandbox will use as a parent. - */ -class SandboxConfiguration private constructor( - val rules: List, - val emitters: List, - val definitionProviders: List, - val executionProfile: ExecutionProfile, - val analysisConfiguration: AnalysisConfiguration, - val parentClassLoader: SandboxClassLoader? -) { - @Suppress("unused") - companion object { - /** - * Default configuration for the deterministic sandbox. - */ - @JvmField - val DEFAULT = SandboxConfiguration.of() - - /** - * Configuration with no emitters, rules, meta-data providers or runtime thresholds. - */ - @JvmField - val EMPTY = SandboxConfiguration.of( - ExecutionProfile.UNLIMITED, emptyList(), emptyList(), emptyList() - ) - - /** - * Create a sandbox configuration where one or more properties deviates from the default. - */ - fun of( - profile: ExecutionProfile = ExecutionProfile.DEFAULT, - rules: List = Discovery.find(), - emitters: List? = null, - definitionProviders: List = Discovery.find(), - enableTracing: Boolean = true, - analysisConfiguration: AnalysisConfiguration = AnalysisConfiguration.createRoot(), - parentClassLoader: SandboxClassLoader? = null - ) = SandboxConfiguration( - executionProfile = profile, - rules = rules, - emitters = (emitters ?: Discovery.find()).filter { - enableTracing || it.priority > EMIT_TRACING - }, - definitionProviders = definitionProviders, - analysisConfiguration = analysisConfiguration, - parentClassLoader = parentClassLoader - ) - } -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/SandboxRuntimeContext.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/SandboxRuntimeContext.kt deleted file mode 100644 index 9bfe692244..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/SandboxRuntimeContext.kt +++ /dev/null @@ -1,67 +0,0 @@ -package net.corda.djvm - -import net.corda.djvm.costing.RuntimeCostSummary -import net.corda.djvm.rewiring.SandboxClassLoader - -/** - * The context in which a sandboxed operation is run. - * - * @property configuration The configuration of the sandbox. - */ -class SandboxRuntimeContext(val configuration: SandboxConfiguration) { - - /** - * The class loader to use inside the sandbox. - */ - val classLoader: SandboxClassLoader = SandboxClassLoader.createFor(configuration) - - /** - * A summary of the currently accumulated runtime costs (for, e.g., memory allocations, invocations, etc.). - */ - val runtimeCosts = RuntimeCostSummary(configuration.executionProfile) - - private val hashCodes: MutableMap = mutableMapOf() - private var objectCounter: Int = 0 - - // TODO Instead of using a magic offset below, one could take in a per-context seed - fun getHashCodeFor(nativeHashCode: Int): Int { - return hashCodes.computeIfAbsent(nativeHashCode) { ++objectCounter + MAGIC_HASH_OFFSET } - } - - private val internStrings: MutableMap = mutableMapOf() - - fun intern(key: String, value: Any): Any { - return internStrings.computeIfAbsent(key) { value } - } - - /** - * Run a set of actions within the provided sandbox context. - */ - fun use(action: SandboxRuntimeContext.() -> Unit) { - SandboxRuntimeContext.instance = this - try { - action(this) - } finally { - threadLocalContext.remove() - } - } - - companion object { - - private val threadLocalContext = ThreadLocal() - private const val MAGIC_HASH_OFFSET = 0xfed_c0de - - /** - * When called from within a sandbox, this returns the context for the current sandbox thread. - */ - @JvmStatic - var instance: SandboxRuntimeContext - get() = threadLocalContext.get() - ?: throw IllegalStateException("SandboxContext has not been initialized before use") - private set(value) { - threadLocalContext.set(value) - } - - } - -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisConfiguration.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisConfiguration.kt deleted file mode 100644 index 7b3988d0ad..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisConfiguration.kt +++ /dev/null @@ -1,350 +0,0 @@ -package net.corda.djvm.analysis - -import net.corda.djvm.code.EmitterModule -import net.corda.djvm.code.ruleViolationError -import net.corda.djvm.code.thresholdViolationError -import net.corda.djvm.messages.Severity -import net.corda.djvm.references.ClassModule -import net.corda.djvm.references.Member -import net.corda.djvm.references.MemberModule -import net.corda.djvm.references.MethodBody -import net.corda.djvm.source.BootstrapClassLoader -import net.corda.djvm.source.SourceClassLoader -import org.objectweb.asm.Opcodes.* -import org.objectweb.asm.Type -import sandbox.net.corda.djvm.costing.RuntimeCostAccounter -import java.io.Closeable -import java.io.IOException -import java.nio.file.Path - -/** - * The configuration to use for an analysis. - * - * @property whitelist The whitelist of class names. - * @property pinnedClasses Classes that have already been declared in the sandbox namespace and that should be - * made available inside the sandboxed environment. These classes belong to the application - * classloader and so are shared across all sandboxes. - * @property classResolver Functionality used to resolve the qualified name and relevant information about a class. - * @property exceptionResolver Resolves the internal names of synthetic exception classes. - * @property minimumSeverityLevel The minimum severity level to log and report. - * @property analyzeAnnotations Analyze annotations despite not being explicitly referenced. - * @property prefixFilters Only record messages where the originating class name matches one of the provided prefixes. - * If none are provided, all messages will be reported. - * @property classModule Module for handling evolution of a class hierarchy during analysis. - * @property memberModule Module for handling the specification and inspection of class members. - * @property bootstrapClassLoader Optional provider for the Java API classes. - * @property supportingClassLoader ClassLoader providing the classes to run inside the sandbox. - * @property isRootConfiguration Effectively, whether we are allowed to close [bootstrapClassLoader]. - */ -class AnalysisConfiguration private constructor( - val whitelist: Whitelist, - val pinnedClasses: Set, - val classResolver: ClassResolver, - val exceptionResolver: ExceptionResolver, - val minimumSeverityLevel: Severity, - val analyzeAnnotations: Boolean, - val prefixFilters: List, - val classModule: ClassModule, - val memberModule: MemberModule, - private val bootstrapClassLoader: BootstrapClassLoader?, - val supportingClassLoader: SourceClassLoader, - private val isRootConfiguration: Boolean -) : Closeable { - - /** - * These interfaces are modified as they are mapped into the sandbox by - * having their unsandboxed version "stitched in" as a super-interface. - * And in some cases, we need to add some synthetic bridge methods as well. - */ - val stitchedInterfaces: Map> get() = STITCHED_INTERFACES - - /** - * These classes have extra methods added as they are mapped into the sandbox. - */ - val stitchedClasses: Map> get() = STITCHED_CLASSES - - @Throws(IOException::class) - override fun close() { - supportingClassLoader.use { - if (isRootConfiguration) { - bootstrapClassLoader?.close() - } - } - } - - /** - * Creates a child [AnalysisConfiguration] with this instance as its parent. - * The child inherits the same [whitelist], [pinnedClasses] and [bootstrapClassLoader]. - */ - fun createChild( - classPaths: List = emptyList(), - newMinimumSeverityLevel: Severity? - ): AnalysisConfiguration { - return AnalysisConfiguration( - whitelist = whitelist, - pinnedClasses = pinnedClasses, - classResolver = classResolver, - exceptionResolver = exceptionResolver, - minimumSeverityLevel = newMinimumSeverityLevel ?: minimumSeverityLevel, - analyzeAnnotations = analyzeAnnotations, - prefixFilters = prefixFilters, - classModule = classModule, - memberModule = memberModule, - bootstrapClassLoader = bootstrapClassLoader, - supportingClassLoader = SourceClassLoader(classPaths, classResolver, bootstrapClassLoader), - isRootConfiguration = false - ) - } - - fun isTemplateClass(className: String): Boolean = className in TEMPLATE_CLASSES - fun isPinnedClass(className: String): Boolean = className in pinnedClasses - - fun isJvmException(className: String): Boolean = className in JVM_EXCEPTIONS - fun isSandboxClass(className: String): Boolean = className.startsWith(SANDBOX_PREFIX) && !isPinnedClass(className) - - companion object { - /** - * The package name prefix to use for classes loaded into a sandbox. - */ - const val SANDBOX_PREFIX: String = "sandbox/" - - /** - * These class must belong to the application class loader. - * They should already exist within the sandbox namespace. - */ - private val MANDATORY_PINNED_CLASSES: Set = setOf( - RuntimeCostAccounter.TYPE_NAME, - ruleViolationError, - thresholdViolationError - ) - - /** - * These classes will be duplicated into every sandbox's - * parent classloader. - */ - private val TEMPLATE_CLASSES: Set = setOf( - java.lang.Boolean::class.java, - java.lang.Byte::class.java, - java.lang.Character::class.java, - java.lang.Double::class.java, - java.lang.Float::class.java, - java.lang.Integer::class.java, - java.lang.Long::class.java, - java.lang.Number::class.java, - java.lang.Runtime::class.java, - java.lang.Short::class.java, - java.lang.String::class.java, - java.lang.String.CASE_INSENSITIVE_ORDER::class.java, - java.lang.System::class.java, - java.lang.ThreadLocal::class.java, - java.lang.Throwable::class.java, - kotlin.Any::class.java, - sun.misc.JavaLangAccess::class.java, - sun.misc.SharedSecrets::class.java - ).sandboxed() + setOf( - "sandbox/Task", - "sandbox/TaskTypes", - "sandbox/java/lang/Character\$Cache", - "sandbox/java/lang/DJVM", - "sandbox/java/lang/DJVMException", - "sandbox/java/lang/DJVMThrowableWrapper", - "sandbox/sun/misc/SharedSecrets\$1", - "sandbox/sun/misc/SharedSecrets\$JavaLangAccessImpl" - ) - - /** - * These exceptions are thrown by the JVM itself, and - * so we need to handle them without wrapping them. - * - * Note that this set is closed, i.e. every one - * of these exceptions' [Throwable] super classes - * is also within this set. - * - * The full list of exceptions is determined by: - * hotspot/src/share/vm/classfile/vmSymbols.hpp - */ - val JVM_EXCEPTIONS: Set = setOf( - java.io.IOException::class.java, - java.lang.AbstractMethodError::class.java, - java.lang.ArithmeticException::class.java, - java.lang.ArrayIndexOutOfBoundsException::class.java, - java.lang.ArrayStoreException::class.java, - java.lang.ClassCastException::class.java, - java.lang.ClassCircularityError::class.java, - java.lang.ClassFormatError::class.java, - java.lang.ClassNotFoundException::class.java, - java.lang.CloneNotSupportedException::class.java, - java.lang.Error::class.java, - java.lang.Exception::class.java, - java.lang.ExceptionInInitializerError::class.java, - java.lang.IllegalAccessError::class.java, - java.lang.IllegalAccessException::class.java, - java.lang.IllegalArgumentException::class.java, - java.lang.IllegalStateException::class.java, - java.lang.IncompatibleClassChangeError::class.java, - java.lang.IndexOutOfBoundsException::class.java, - java.lang.InstantiationError::class.java, - java.lang.InstantiationException::class.java, - java.lang.InternalError::class.java, - java.lang.LinkageError::class.java, - java.lang.NegativeArraySizeException::class.java, - java.lang.NoClassDefFoundError::class.java, - java.lang.NoSuchFieldError::class.java, - java.lang.NoSuchFieldException::class.java, - java.lang.NoSuchMethodError::class.java, - java.lang.NoSuchMethodException::class.java, - java.lang.NullPointerException::class.java, - java.lang.OutOfMemoryError::class.java, - java.lang.ReflectiveOperationException::class.java, - java.lang.RuntimeException::class.java, - java.lang.StackOverflowError::class.java, - java.lang.StringIndexOutOfBoundsException::class.java, - java.lang.ThreadDeath::class.java, - java.lang.Throwable::class.java, - java.lang.UnknownError::class.java, - java.lang.UnsatisfiedLinkError::class.java, - java.lang.UnsupportedClassVersionError::class.java, - java.lang.UnsupportedOperationException::class.java, - java.lang.VerifyError::class.java, - java.lang.VirtualMachineError::class.java - ).sandboxed() + setOf( - // Mentioned here to prevent the DJVM from generating a synthetic wrapper. - "sandbox/java/lang/DJVMThrowableWrapper" - ) - - /** - * These interfaces will be modified as follows when - * added to the sandbox: - * - * interface sandbox.A extends A - */ - private val STITCHED_INTERFACES: Map> = listOf( - object : MethodBuilder( - access = ACC_PUBLIC or ACC_SYNTHETIC or ACC_BRIDGE, - className = sandboxed(CharSequence::class.java), - memberName = "subSequence", - descriptor = "(II)Ljava/lang/CharSequence;" - ) { - override fun writeBody(emitter: EmitterModule) = with(emitter) { - pushObject(0) - pushInteger(1) - pushInteger(2) - invokeInterface(className, memberName, "(II)L$className;") - returnObject() - } - }.withBody() - .build(), - - MethodBuilder( - access = ACC_PUBLIC or ACC_ABSTRACT, - className = sandboxed(CharSequence::class.java), - memberName = "toString", - descriptor = "()Ljava/lang/String;" - ).build() - ).mapByClassName() + mapOf( - sandboxed(Comparable::class.java) to emptyList(), - sandboxed(Comparator::class.java) to emptyList(), - sandboxed(Iterable::class.java) to emptyList() - ) - - /** - * These classes have extra methods added when mapped into the sandbox. - */ - private val STITCHED_CLASSES: Map> = listOf( - object : MethodBuilder( - access = ACC_FINAL, - className = sandboxed(Enum::class.java), - memberName = "fromDJVM", - descriptor = "()Ljava/lang/Enum;", - signature = "()Ljava/lang/Enum<*>;" - ) { - override fun writeBody(emitter: EmitterModule) = with(emitter) { - pushObject(0) - invokeStatic("sandbox/java/lang/DJVM", "fromDJVMEnum", "(Lsandbox/java/lang/Enum;)Ljava/lang/Enum;") - returnObject() - } - }.withBody() - .build(), - - object : MethodBuilder( - access = ACC_BRIDGE or ACC_SYNTHETIC, - className = sandboxed(Enum::class.java), - memberName = "fromDJVM", - descriptor = "()Ljava/lang/Object;" - ) { - override fun writeBody(emitter: EmitterModule) = with(emitter) { - pushObject(0) - invokeVirtual(className, memberName, "()Ljava/lang/Enum;") - returnObject() - } - }.withBody() - .build() - ).mapByClassName() - - private fun sandboxed(clazz: Class<*>): String = (SANDBOX_PREFIX + Type.getInternalName(clazz)).intern() - private fun Set>.sandboxed(): Set = map(Companion::sandboxed).toSet() - private fun Iterable.mapByClassName(): Map> - = groupBy(Member::className).mapValues(Map.Entry>::value) - - /** - * @see [AnalysisConfiguration] - */ - fun createRoot( - whitelist: Whitelist = Whitelist.MINIMAL, - additionalPinnedClasses: Set = emptySet(), - minimumSeverityLevel: Severity = Severity.WARNING, - analyzeAnnotations: Boolean = false, - prefixFilters: List = emptyList(), - classModule: ClassModule = ClassModule(), - memberModule: MemberModule = MemberModule(), - bootstrapClassLoader: BootstrapClassLoader? = null, - sourceClassLoaderFactory: (ClassResolver, BootstrapClassLoader?) -> SourceClassLoader = { classResolver, bootstrapCL -> - SourceClassLoader(emptyList(), classResolver, bootstrapCL) - } - ): AnalysisConfiguration { - val pinnedClasses = MANDATORY_PINNED_CLASSES + additionalPinnedClasses - val classResolver = ClassResolver(pinnedClasses, TEMPLATE_CLASSES, whitelist, SANDBOX_PREFIX) - - return AnalysisConfiguration( - whitelist = whitelist, - pinnedClasses = pinnedClasses, - classResolver = classResolver, - exceptionResolver = ExceptionResolver(JVM_EXCEPTIONS, pinnedClasses, SANDBOX_PREFIX), - minimumSeverityLevel = minimumSeverityLevel, - analyzeAnnotations = analyzeAnnotations, - prefixFilters = prefixFilters, - classModule = classModule, - memberModule = memberModule, - bootstrapClassLoader = bootstrapClassLoader, - supportingClassLoader = sourceClassLoaderFactory(classResolver, bootstrapClassLoader), - isRootConfiguration = true - ) - } - } - - private open class MethodBuilder( - protected val access: Int, - protected val className: String, - protected val memberName: String, - protected val descriptor: String, - protected val signature: String = "" - ) { - private val bodies = mutableListOf() - - protected open fun writeBody(emitter: EmitterModule) {} - - fun withBody(): MethodBuilder { - bodies.add(::writeBody) - return this - } - - fun build() = Member( - access = access, - className = className, - memberName = memberName, - signature = descriptor, - genericsDetails = signature, - body = bodies - ) - } -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisContext.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisContext.kt deleted file mode 100644 index 3ea9b55b1b..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisContext.kt +++ /dev/null @@ -1,53 +0,0 @@ -package net.corda.djvm.analysis - -import net.corda.djvm.code.asPackagePath -import net.corda.djvm.messages.MessageCollection -import net.corda.djvm.references.ClassHierarchy -import net.corda.djvm.references.EntityReference -import net.corda.djvm.references.ReferenceMap - -/** - * The context in which one or more classes are analysed. - * - * @property messages Collection of messages gathered as part of the analysis. - * @property classes List of class definitions that have been analyzed. - * @property references A collection of all referenced members found during analysis together with the locations from - * where each member has been accessed or invoked. - */ -class AnalysisContext private constructor( - val messages: MessageCollection, - val classes: ClassHierarchy, - val references: ReferenceMap -) { - - private val origins = mutableMapOf>() - - /** - * Record a class origin in the current analysis context. - */ - fun recordClassOrigin(name: String, origin: EntityReference) { - origins.getOrPut(name.asPackagePath) { mutableSetOf() }.add(origin) - } - - /** - * Map of class origins. The resulting set represents the types referencing the class in question. - */ - val classOrigins: Map> - get() = origins - - companion object { - - /** - * Create a new analysis context from provided configuration. - */ - fun fromConfiguration(configuration: AnalysisConfiguration): AnalysisContext { - return AnalysisContext( - MessageCollection(configuration.minimumSeverityLevel, configuration.prefixFilters), - ClassHierarchy(configuration.classModule, configuration.memberModule), - ReferenceMap(configuration.classModule) - ) - } - - } - -} \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisRuntimeContext.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisRuntimeContext.kt deleted file mode 100644 index 5853748272..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/AnalysisRuntimeContext.kt +++ /dev/null @@ -1,22 +0,0 @@ -package net.corda.djvm.analysis - -import net.corda.djvm.messages.MessageCollection -import net.corda.djvm.references.ClassRepresentation -import net.corda.djvm.references.Member - -/** - * The context of a class analysis. - * - * @property clazz The class currently being analyzed. - * @property member The member currently being analyzed. - * @property location The current source location. - * @property messages Collection of messages gathered as part of the analysis. - * @property configuration The configuration used in the analysis. - */ -data class AnalysisRuntimeContext( - val clazz: ClassRepresentation, - val member: Member?, - val location: SourceLocation, - val messages: MessageCollection, - val configuration: AnalysisConfiguration -) diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ClassAndMemberVisitor.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ClassAndMemberVisitor.kt deleted file mode 100644 index 3ab04895e4..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ClassAndMemberVisitor.kt +++ /dev/null @@ -1,598 +0,0 @@ -package net.corda.djvm.analysis - -import net.corda.djvm.code.EmitterModule -import net.corda.djvm.code.Instruction -import net.corda.djvm.code.emptyAsNull -import net.corda.djvm.code.instructions.* -import net.corda.djvm.messages.Message -import net.corda.djvm.references.* -import org.objectweb.asm.* -import java.io.InputStream - -/** - * Functionality for traversing a class and its members. - * - * @property configuration The configuration to use for the analysis - * @property classVisitor Class visitor to use when traversing the structure of classes. - */ -open class ClassAndMemberVisitor( - private val configuration: AnalysisConfiguration, - private val classVisitor: ClassVisitor? -) { - - /** - * Holds a reference to the currently used analysis context. - */ - protected var analysisContext: AnalysisContext = AnalysisContext.fromConfiguration(configuration) - - /** - * Holds a link to the class currently being traversed. - */ - private var currentClass: ClassRepresentation? = null - - /** - * Holds a link to the member currently being traversed. - */ - private var currentMember: Member? = null - - /** - * The current source location. - */ - private var sourceLocation = SourceLocation() - - /** - * Analyze class by using the provided qualified name of the class. - */ - inline fun analyze(context: AnalysisContext) = analyze(T::class.java.name, context) - - /** - * Analyze class by using the provided qualified name of the class. - * - * @param className The full, qualified name of the class. - * @param context The context in which the analysis is conducted. - * @param origin The originating class for the analysis. - */ - fun analyze(className: String, context: AnalysisContext, origin: String? = null) { - configuration.supportingClassLoader.classReader(className, context, origin).apply { - analyze(this, context) - } - } - - /** - * Analyze class by using the provided stream of its byte code. - * - * @param classStream A stream of the class' byte code. - * @param context The context in which the analysis is conducted. - */ - fun analyze(classStream: InputStream, context: AnalysisContext) = - analyze(ClassReader(classStream), context) - - /** - * Analyze class by using the provided class reader. - * - * @param classReader An instance of the class reader to use to access the byte code. - * @param context The context in which to analyse the provided class. - * @param options Options for how to parse and process the class. - */ - fun analyze(classReader: ClassReader, context: AnalysisContext, options: Int = 0) { - analysisContext = context - classReader.accept(ClassVisitorImpl(classVisitor), options) - } - - /** - * Extract information about the traversed class. - */ - open fun visitClass(clazz: ClassRepresentation): ClassRepresentation = clazz - - /** - * Process class after it has been fully traversed and analyzed. - * The [classVisitor] has finished visiting all of the class's - * existing elements (i.e. methods, fields, inner classes etc) - * and is about to complete. However, it can still add new - * elements to the class, if required. - */ - open fun visitClassEnd(classVisitor: ClassVisitor, clazz: ClassRepresentation) {} - - /** - * Extract the meta-data indicating the source file of the traversed class (i.e., where it is compiled from). - */ - open fun visitSource(clazz: ClassRepresentation, source: String) {} - - /** - * Extract information about the traversed class annotation. - */ - open fun visitClassAnnotation(clazz: ClassRepresentation, descriptor: String) {} - - /** - * Extract information about the traversed member annotation. - */ - open fun visitMemberAnnotation(clazz: ClassRepresentation, member: Member, descriptor: String) {} - - /** - * Extract information about the traversed method. - */ - open fun visitMethod(clazz: ClassRepresentation, method: Member): Member = method - - /** - * Extract information about the traversed field. - */ - open fun visitField(clazz: ClassRepresentation, field: Member): Member = field - - /** - * Extract information about the traversed instruction. - */ - open fun visitInstruction(method: Member, emitter: EmitterModule, instruction: Instruction) {} - - /** - * Get the analysis context to pass on to method and field visitors. - */ - protected fun currentAnalysisContext(): AnalysisRuntimeContext { - return AnalysisRuntimeContext( - currentClass!!, - currentMember, - sourceLocation, - analysisContext.messages, - configuration - ) - } - - /** - * Check if a class should be processed or not. - */ - protected fun shouldBeProcessed(className: String): Boolean { - return !configuration.whitelist.inNamespace(className) && - !configuration.isPinnedClass(className) - } - - /** - * Extract information about the traversed member annotation. - */ - private fun visitMemberAnnotation( - descriptor: String, - referencedClass: ClassRepresentation? = null, - referencedMember: Member? = null - ) { - val clazz = (referencedClass ?: currentClass) ?: return - val member = (referencedMember ?: currentMember) ?: return - member.annotations.add(descriptor) - captureExceptions { - visitMemberAnnotation(clazz, member, descriptor) - } - } - - /** - * Run action with a guard that populates [AnalysisRuntimeContext.messages] - * based on the output. - */ - private inline fun captureExceptions(action: () -> Unit): Boolean { - return try { - action() - true - } catch (exception: Throwable) { - recordMessage(exception, currentAnalysisContext()) - false - } - } - - /** - * Record a message derived from a [Throwable]. - */ - private fun recordMessage(exception: Throwable, context: AnalysisRuntimeContext) { - context.messages.add(Message.fromThrowable(exception, context.location)) - } - - /** - * Record a reference to a class. - */ - private fun recordTypeReference(type: String) { - val typeName = configuration.classModule - .normalizeClassName(type) - .replace("[]", "") - if (shouldBeProcessed(currentClass!!.name)) { - val classReference = ClassReference(typeName) - analysisContext.references.add(classReference, sourceLocation) - } - } - - /** - * Record a reference to a class member. - */ - private fun recordMemberReference(owner: String, name: String, desc: String) { - if (shouldBeProcessed(currentClass!!.name)) { - recordTypeReference(owner) - val memberReference = MemberReference(owner, name, desc) - analysisContext.references.add(memberReference, sourceLocation) - } - } - - /** - * Visitor used to traverse and analyze a class. - */ - private inner class ClassVisitorImpl( - targetVisitor: ClassVisitor? - ) : ClassVisitor(API_VERSION, targetVisitor) { - - /** - * Extract information about the traversed class. - */ - override fun visit( - version: Int, access: Int, name: String, signature: String?, superName: String?, - interfaces: Array? - ) { - val superClassName = superName ?: "" - val interfaceNames = interfaces?.toMutableList() ?: mutableListOf() - ClassRepresentation(version, access, name, superClassName, interfaceNames, genericsDetails = signature ?: "").also { - currentClass = it - currentMember = null - sourceLocation = SourceLocation(className = name) - } - captureExceptions { - currentClass = visitClass(currentClass!!) - } - val visitedClass = currentClass!! - analysisContext.classes.add(visitedClass) - super.visit( - version, access, visitedClass.name, signature, - visitedClass.superClass.emptyAsNull, - visitedClass.interfaces.toTypedArray() - ) - } - - /** - * Post-processing of the traversed class. - */ - override fun visitEnd() { - configuration.classModule - .getClassReferencesFromClass(currentClass!!, configuration.analyzeAnnotations) - .forEach(::recordTypeReference) - captureExceptions { - visitClassEnd(this, currentClass!!) - } - super.visitEnd() - } - - /** - * Extract the meta-data indicating the source file of the traversed class (i.e., where it is compiled from). - */ - override fun visitSource(source: String?, debug: String?) { - currentClass!!.apply { - sourceFile = configuration.classModule.getFullSourceLocation(this, source) - sourceLocation = sourceLocation.copy(sourceFile = sourceFile) - captureExceptions { - visitSource(this, sourceFile) - } - } - super.visitSource(source, debug) - } - - /** - * Extract information about provided annotations. - */ - override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? { - currentClass!!.apply { - annotations.add(desc) - captureExceptions { - visitClassAnnotation(this, desc) - } - } - return super.visitAnnotation(desc, visible) - } - - /** - * Extract information about the traversed method. - */ - override fun visitMethod( - access: Int, name: String, desc: String, signature: String?, exceptions: Array? - ): MethodVisitor? { - var visitedMember: Member? = null - val clazz = currentClass!! - val member = Member( - access = access, - className = clazz.name, - memberName = name, - signature = desc, - genericsDetails = signature ?: "", - exceptions = exceptions?.toMutableSet() ?: mutableSetOf() - ) - currentMember = member - sourceLocation = sourceLocation.copy( - memberName = name, - signature = desc, - lineNumber = 0 - ) - val processMember = captureExceptions { - visitedMember = visitMethod(clazz, member) - } - configuration.memberModule.addToClass(clazz, visitedMember ?: member) - return if (processMember) { - val derivedMember = visitedMember ?: member - super.visitMethod( - derivedMember.access, - derivedMember.memberName, - derivedMember.signature, - signature, - derivedMember.exceptions.toTypedArray() - )?.let { targetVisitor -> - MethodVisitorImpl(targetVisitor, derivedMember) - } - } else { - null - } - } - - /** - * Extract information about the traversed field. - */ - override fun visitField( - access: Int, name: String, desc: String, signature: String?, value: Any? - ): FieldVisitor? { - var visitedMember: Member? = null - val clazz = currentClass!! - val member = Member( - access = access, - className = clazz.name, - memberName = name, - signature = desc, - genericsDetails = "", - value = value - ) - currentMember = member - sourceLocation = sourceLocation.copy( - memberName = name, - signature = desc, - lineNumber = 0 - ) - val processMember = captureExceptions { - visitedMember = visitField(clazz, member) - } - configuration.memberModule.addToClass(clazz, visitedMember ?: member) - return if (processMember) { - val derivedMember = visitedMember ?: member - super.visitField( - derivedMember.access, - derivedMember.memberName, - derivedMember.signature, - signature, - derivedMember.value - )?.let { targetVisitor -> - FieldVisitorImpl(targetVisitor) - } - } else { - null - } - } - - } - - /** - * Visitor used to traverse and analyze a method. - */ - private inner class MethodVisitorImpl( - targetVisitor: MethodVisitor, - private val method: Member - ) : MethodVisitor(API_VERSION, targetVisitor) { - - /** - * Record line number of current instruction. - */ - override fun visitLineNumber(line: Int, start: Label?) { - sourceLocation = sourceLocation.copy(lineNumber = line) - super.visitLineNumber(line, start) - } - - /** - * Extract information about provided label. - */ - override fun visitLabel(label: Label) { - visit(CodeLabel(label), defaultFirst = true) { - super.visitLabel(label) - } - } - - /** - * Extract information about provided annotations. - */ - override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? { - visitMemberAnnotation(desc) - return super.visitAnnotation(desc, visible) - } - - /** - * Write any new method body code, assuming the definition providers - * have provided any. This handler will not be visited if this method - * has no existing code. - */ - override fun visitCode() { - tryReplaceMethodBody() - visit(MethodEntry(method)) { - super.visitCode() - } - } - - /** - * Extract information about provided field access instruction. - */ - override fun visitFieldInsn(opcode: Int, owner: String, name: String, desc: String) { - recordMemberReference(owner, name, desc) - visit(MemberAccessInstruction(opcode, owner, name, desc, isMethod = false)) { - super.visitFieldInsn(opcode, owner, name, desc) - } - } - - /** - * Extract information about provided method invocation instruction. - */ - override fun visitMethodInsn(opcode: Int, owner: String, name: String, desc: String, itf: Boolean) { - recordMemberReference(owner, name, desc) - visit(MemberAccessInstruction(opcode, owner, name, desc, itf, isMethod = true)) { - super.visitMethodInsn(opcode, owner, name, desc, itf) - } - } - - /** - * Extract information about provided dynamic invocation instruction. - */ - override fun visitInvokeDynamicInsn(name: String, desc: String, bsm: Handle?, vararg bsmArgs: Any?) { - val module = configuration.memberModule - visit(DynamicInvocationInstruction( - name, desc, module.numberOfArguments(desc), module.returnsValueOrReference(desc) - )) { - super.visitInvokeDynamicInsn(name, desc, bsm, *bsmArgs) - } - } - - /** - * Extract information about provided jump instruction. - */ - override fun visitJumpInsn(opcode: Int, label: Label) { - visit(BranchInstruction(opcode, label)) { - super.visitJumpInsn(opcode, label) - } - } - - /** - * Extract information about provided instruction (general instruction with no operands). - */ - override fun visitInsn(opcode: Int) { - visit(Instruction(opcode)) { - super.visitInsn(opcode) - } - } - - /** - * Extract information about provided instruction (general instruction with one operand). - */ - override fun visitIntInsn(opcode: Int, operand: Int) { - visit(IntegerInstruction(opcode, operand)) { - super.visitIntInsn(opcode, operand) - } - } - - /** - * Extract information about provided type instruction (e.g., [Opcodes.NEW], [Opcodes.ANEWARRAY], - * [Opcodes.INSTANCEOF] and [Opcodes.CHECKCAST]). - */ - override fun visitTypeInsn(opcode: Int, type: String) { - recordTypeReference(type) - visit(TypeInstruction(opcode, type)) { - try { - super.visitTypeInsn(opcode, type) - } catch (exception: IllegalArgumentException) { - throw IllegalArgumentException("Invalid name used in type instruction; $type", exception) - } - } - } - - /** - * Extract information about provided try-catch/finally block. - */ - override fun visitTryCatchBlock(start: Label, end: Label, handler: Label, type: String?) { - val block = if (type != null) { - TryCatchBlock(type, handler) - } else { - TryFinallyBlock(handler) - } - visit(block) { - super.visitTryCatchBlock(start, end, handler, type) - } - } - - /** - * Extract information about provided table switch instruction. - */ - override fun visitTableSwitchInsn(min: Int, max: Int, dflt: Label, vararg labels: Label) { - visit(TableSwitchInstruction(min, max, dflt, labels.toList())) { - super.visitTableSwitchInsn(min, max, dflt, *labels) - } - } - - /** - * Extract information about provided increment instruction. - */ - override fun visitIincInsn(`var`: Int, increment: Int) { - visit(IntegerInstruction(Opcodes.IINC, increment)) { - super.visitIincInsn(`var`, increment) - } - } - - /** - * Transform values loaded from the constants pool. - */ - override fun visitLdcInsn(value: Any) { - visit(ConstantInstruction(value), defaultFirst = true) { - super.visitLdcInsn(value) - } - } - - /** - * Finish visiting this method, writing any new method body byte-code - * if we haven't written it already. This would (presumably) only happen - * for methods that previously had no body, e.g. native methods. - */ - override fun visitEnd() { - tryReplaceMethodBody() - super.visitEnd() - } - - private fun tryReplaceMethodBody() { - if (method.body.isNotEmpty() && (mv != null)) { - EmitterModule(mv).apply { - for (body in method.body) { - body(this) - } - } - mv.visitMaxs(-1, -1) - mv.visitEnd() - mv = null - } - } - - /** - * Helper function used to streamline the access to an instruction and to catch any related processing errors. - */ - private inline fun visit(instruction: Instruction, defaultFirst: Boolean = false, defaultAction: () -> Unit) { - val emitterModule = EmitterModule(mv ?: StubMethodVisitor()) - if (defaultFirst) { - defaultAction() - } - val success = captureExceptions { - visitInstruction(currentMember!!, emitterModule, instruction) - } - if (!defaultFirst) { - if (success && emitterModule.emitDefaultInstruction) { - defaultAction() - } - } - } - - } - - /** - * Visitor used to traverse and analyze a field. - */ - private inner class FieldVisitorImpl( - targetVisitor: FieldVisitor - ) : FieldVisitor(API_VERSION, targetVisitor) { - - /** - * Extract information about provided annotations. - */ - override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? { - visitMemberAnnotation(desc) - return super.visitAnnotation(desc, visible) - } - - } - - private inner class StubMethodVisitor : MethodVisitor(API_VERSION, null) - - companion object { - - /** - * The API version of ASM. - */ - const val API_VERSION: Int = Opcodes.ASM6 - - } - -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ClassResolver.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ClassResolver.kt deleted file mode 100644 index 8c42acb039..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ClassResolver.kt +++ /dev/null @@ -1,156 +0,0 @@ -package net.corda.djvm.analysis - -import net.corda.djvm.code.asPackagePath -import net.corda.djvm.code.asResourcePath - -/** - * Functionality for resolving the class name of a sandboxable class. - * - * The resolution of a class name entails determining whether the class can be instrumented or not. This means that the - * following criteria need to be satisfied: - * - The class do not reside in the "java/lang" package. - * - The class has not been explicitly pinned. - * - The class does not already reside in the top-level package named [sandboxPrefix]. - * - * If these criteria have been satisfied, the fully-qualified class name will be derived by prepending [sandboxPrefix] - * to it. Note that [ClassLoader] will not allow defining a class in a package whose fully-qualified class name starts - * with "java/". That will result in the class loader throwing [SecurityException]. Also, some values map onto types - * defined in "java/lang/", e.g., [Integer] and [String]. These cannot be trivially moved into a different package due - * to the internal mechanisms of the JVM. - * - * @property pinnedClasses Classes that have already been declared in the sandbox namespace and that should be made - * available inside the sandboxed environment. - * @property whitelist The set of classes in the Java runtime libraries that have been whitelisted and that should be - * left alone. - * @property sandboxPrefix The package name prefix to use for classes loaded into a sandbox. - */ -class ClassResolver( - private val pinnedClasses: Set, - private val templateClasses: Set, - private val whitelist: Whitelist, - private val sandboxPrefix: String -) { - - /** - * Resolve the class name from a fully qualified name. - */ - fun resolve(name: String): String { - return when { - name.startsWith('[') && name.endsWith(';') -> { - complexArrayTypeRegex.replace(name) { - "${it.groupValues[1]}L${resolveName(it.groupValues[2])};" - } - } - name.startsWith('[') && !name.endsWith(';') -> name - else -> resolveName(name) - } - } - - /** - * Resolve the class name from a fully qualified normalized name. - */ - fun resolveNormalized(name: String): String { - return resolve(name.asResourcePath).asPackagePath - } - - /** - * Derive descriptor by resolving all referenced class names. - */ - fun resolveDescriptor(descriptor: String): String { - val outputDescriptor = StringBuilder() - var longName = StringBuilder() - var isProcessingLongName = false - loop@ for (char in descriptor) { - when { - char != ';' && isProcessingLongName -> { - longName.append(char) - continue@loop - } - char == 'L' -> { - isProcessingLongName = true - longName = StringBuilder() - } - char == ';' -> { - outputDescriptor.append(resolve(longName.toString())) - isProcessingLongName = false - } - } - outputDescriptor.append(char) - } - return outputDescriptor.toString() - } - - /** - * Reverse the resolution of a class name. - */ - fun reverse(resolvedClassName: String): String { - return if (resolvedClassName in pinnedClasses || resolvedClassName in templateClasses) { - resolvedClassName - } else { - removeSandboxPrefix(resolvedClassName) - } - } - - /** - * Reverse the resolution of a class name from a fully qualified normalized name. - */ - fun reverseNormalized(className: String): String { - return reverse(className.asResourcePath).asPackagePath - } - - /** - * Generates the equivalent class name outside the sandbox from a fully qualified normalized name. - */ - fun toSourceNormalized(className: String): String { - return toSource(className.asResourcePath).asPackagePath - } - - /** - * Resolve sandboxed class name from a fully qualified name. - */ - private fun resolveName(name: String): String { - return if (isPinnedOrWhitelistedClass(name) || name in templateClasses) { - name - } else { - "$sandboxPrefix$name" - } - } - - /** - * Maps a class name to its equivalent class outside the sandbox. - * Needed by [net.corda.djvm.source.SourceClassLoader]. - */ - private fun toSource(className: String): String { - return if (className in pinnedClasses) { - className - } else { - removeSandboxPrefix(className) - } - } - - private fun removeSandboxPrefix(className: String): String { - if (className.startsWith(sandboxPrefix)) { - val nameWithoutPrefix = className.drop(sandboxPrefix.length) - if (resolve(nameWithoutPrefix) == className) { - return nameWithoutPrefix - } - } - return className - } - - /** - * Check if class is whitelisted or pinned. - */ - private fun isPinnedOrWhitelistedClass(name: String): Boolean { - return whitelist.matches(name) || - name in pinnedClasses || - sandboxRegex.matches(name) - } - - private val sandboxRegex = "^$sandboxPrefix.*\$".toRegex() - - companion object { - private val complexArrayTypeRegex = "^(\\[+)L(.*);\$".toRegex() - } - -} \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ExceptionResolver.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ExceptionResolver.kt deleted file mode 100644 index 0bfeb103e2..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/ExceptionResolver.kt +++ /dev/null @@ -1,41 +0,0 @@ -package net.corda.djvm.analysis - -import org.objectweb.asm.Type - -class ExceptionResolver( - private val jvmExceptionClasses: Set, - private val pinnedClasses: Set, - private val sandboxPrefix: String -) { - companion object { - private const val DJVM_EXCEPTION_NAME = "\$1DJVM" - - fun isDJVMException(className: String): Boolean = className.endsWith(DJVM_EXCEPTION_NAME) - fun getDJVMException(className: String): String = className + DJVM_EXCEPTION_NAME - fun getDJVMExceptionOwner(className: String): String = className.dropLast(DJVM_EXCEPTION_NAME.length) - } - - fun getThrowableName(clazz: Class<*>): String { - return getDJVMException(Type.getInternalName(clazz)) - } - - fun getThrowableSuperName(clazz: Class<*>): String { - return getThrowableOwnerName(Type.getInternalName(clazz.superclass)) - } - - fun getThrowableOwnerName(className: String): String { - return if (className in jvmExceptionClasses) { - className.unsandboxed - } else if (className in pinnedClasses) { - className - } else { - getDJVMException(className) - } - } - - private val String.unsandboxed: String get() = if (startsWith(sandboxPrefix)) { - drop(sandboxPrefix.length) - } else { - this - } -} \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/SourceLocation.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/SourceLocation.kt deleted file mode 100644 index 78ea440123..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/SourceLocation.kt +++ /dev/null @@ -1,89 +0,0 @@ -package net.corda.djvm.analysis - -import net.corda.djvm.formatting.MemberFormatter -import net.corda.djvm.references.MemberInformation - -/** - * Representation of the source location of a class, member or instruction. - * - * @property className The name of the class. - * @property sourceFile The file containing the source of the compiled class. - * @property memberName The name of the field or method. - * @property signature The signature of the field or method. - * @property lineNumber The index of the line from which the instruction was compiled. - */ -data class SourceLocation( - override val className: String = "", - val sourceFile: String = "", - override val memberName: String = "", - override val signature: String = "", - val lineNumber: Int = 0 -) : MemberInformation { - - /** - * Check whether or not information about the source file is available. - */ - val hasSourceFile: Boolean - get() = sourceFile.isNotBlank() - - /** - * Check whether or not information about the line number is available. - */ - val hasLineNumber: Boolean - get() = lineNumber != 0 - - /** - * Get a string representation of the source location. - */ - override fun toString(): String { - return StringBuilder().apply { - append(className.removePrefix("sandbox/")) - if (memberName.isNotBlank()) { - append(".$memberName") - if (memberFormatter.isMethod(signature)) { - append("(${memberFormatter.format(signature)})") - } - } - }.toString() - } - - /** - * Get a formatted string representation of the source location. - */ - fun format(): String { - if (className.isBlank()) { - return "" - } - return StringBuilder().apply { - append("@|blue ") - append(if (hasSourceFile) { - sourceFile - } else { - className - }.removePrefix("sandbox/")) - append("|@") - if (hasLineNumber) { - append(" on @|yellow line $lineNumber|@") - } - if (memberName.isNotBlank()) { - append(" in @|green ") - if (hasSourceFile) { - append("${memberFormatter.getShortClassName(className)}.$memberName") - } else { - append(memberName) - } - if (memberFormatter.isMethod(signature)) { - append("(${memberFormatter.format(signature)})") - } - append("|@") - } - }.toString() - } - - private companion object { - - private val memberFormatter = MemberFormatter() - - } - -} \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/Whitelist.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/Whitelist.kt deleted file mode 100644 index ed3fb32e88..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/analysis/Whitelist.kt +++ /dev/null @@ -1,192 +0,0 @@ -package net.corda.djvm.analysis - -import java.io.FileNotFoundException -import java.io.InputStream -import java.io.PushbackInputStream -import java.nio.file.Files -import java.nio.file.Path -import java.util.zip.GZIPInputStream - -/** - * Representation of a whitelist deciding what classes, interfaces and members are permissible and consequently can be - * referenced from sandboxed code. - * - * @property namespace If provided, this parameter bounds the namespace of the whitelist. - * @property entries A set of regular expressions used to determine whether a name is covered by the whitelist or not. - * @property textEntries A set of textual entries used to determine whether a name is covered by the whitelist or not. - */ -open class Whitelist private constructor( - private val namespace: Whitelist? = null, - private val entries: Set, - private val textEntries: Set -) { - - /** - * Set of seen names that matched with the whitelist. - */ - private val seenNames = mutableSetOf() - - /** - * Check if name falls within the namespace of the whitelist. - */ - fun inNamespace(name: String): Boolean { - return namespace != null && namespace.matches(name) - } - - /** - * Check if a name is covered by the whitelist. - */ - fun matches(name: String): Boolean { - if (name in seenNames) { - return true - } - return when { - name in textEntries -> { - seenNames.add(name) - true - } - entries.any { it.matches(name) } -> { - seenNames.add(name) - true - } - else -> false - } - } - - /** - * Combine two whitelists into one. - */ - operator fun plus(whitelist: Whitelist): Whitelist { - val entries = entries + whitelist.entries - val textEntries = textEntries + whitelist.textEntries - return when { - namespace != null && whitelist.namespace != null -> - Whitelist(namespace + whitelist.namespace, entries, textEntries) - namespace != null -> - Whitelist(namespace, entries, textEntries) - whitelist.namespace != null -> - Whitelist(whitelist.namespace, entries, textEntries) - else -> - Whitelist(null, entries, textEntries) - } - } - - /** - * Get a derived whitelist by adding a set of additional entries. - */ - operator fun plus(additionalEntries: Set): Whitelist { - return plus(Whitelist(null, additionalEntries, emptySet())) - } - - /** - * Get a derived whitelist by adding an additional entry. - */ - operator fun plus(additionalEntry: Regex): Whitelist { - return plus(setOf(additionalEntry)) - } - - /** - * Enumerate all the entries of the whitelist. - */ - val items: Set - get() = textEntries + entries.map(Regex::pattern) - - companion object { - private val everythingRegex = setOf(".*".toRegex()) - - private val minimumSet = setOf( - "^java/lang/Class(\\..*)?\$".toRegex(), - "^java/lang/ClassLoader(\\..*)?\$".toRegex(), - "^java/lang/Cloneable(\\..*)?\$".toRegex(), - "^java/lang/Object(\\..*)?\$".toRegex(), - "^java/lang/Override(\\..*)?\$".toRegex(), - "^java/lang/Void\$".toRegex(), - "^java/lang/invoke/LambdaMetafactory\$".toRegex(), - "^java/lang/invoke/MethodHandles(\\\$.*)?\$".toRegex(), - "^java/lang/reflect/Array(\\..*)?\$".toRegex(), - "^java/io/Serializable\$".toRegex() - ) - - /** - * Empty whitelist. - */ - val EMPTY: Whitelist = Whitelist(null, emptySet(), emptySet()) - - /** - * The minimum set of classes that needs to be pinned from standard Java libraries. - */ - val MINIMAL: Whitelist = Whitelist(Whitelist(null, minimumSet, emptySet()), minimumSet, emptySet()) - - /** - * Whitelist everything. - */ - val EVERYTHING: Whitelist = Whitelist( - Whitelist(null, everythingRegex, emptySet()), - everythingRegex, - emptySet() - ) - - /** - * Load a whitelist from a resource stream. - */ - fun fromResource(resourceName: String): Whitelist { - val inputStream = Whitelist::class.java.getResourceAsStream("/$resourceName") - ?: throw FileNotFoundException("Cannot find resource \"$resourceName\"") - return fromStream(inputStream) - } - - /** - * Load a whitelist from a file. - */ - fun fromFile(file: Path): Whitelist { - return Files.newInputStream(file).use(this::fromStream) - } - - /** - * Load a whitelist from a GZIP'ed or raw input stream. - */ - fun fromStream(inputStream: InputStream): Whitelist { - val namespaceEntries = mutableSetOf() - val entries = mutableSetOf() - decompressStream(inputStream).bufferedReader().use { - var isCollectingFilterEntries = false - for (line in it.lines().filter(String::isNotBlank)) { - when { - line.trim() == SECTION_SEPARATOR -> { - isCollectingFilterEntries = true - } - isCollectingFilterEntries -> entries.add(line) - else -> namespaceEntries.add(Regex(line)) - } - } - } - val namespace = if (namespaceEntries.isNotEmpty()) { - Whitelist(null, namespaceEntries, emptySet()) - } else { - null - } - return Whitelist(namespace = namespace, entries = emptySet(), textEntries = entries) - } - - /** - * Decompress stream if GZIP'ed, otherwise, use the raw stream. - */ - private fun decompressStream(inputStream: InputStream): InputStream { - val rawStream = PushbackInputStream(inputStream, 2) - val signature = ByteArray(2) - val length = rawStream.read(signature) - rawStream.unread(signature, 0, length) - return if (signature[0] == GZIP_MAGIC_FIRST_BYTE && signature[1] == GZIP_MAGIC_SECOND_BYTE) { - GZIPInputStream(rawStream) - } else { - rawStream - } - } - - private const val SECTION_SEPARATOR = "---" - private const val GZIP_MAGIC_FIRST_BYTE = GZIPInputStream.GZIP_MAGIC.toByte() - private const val GZIP_MAGIC_SECOND_BYTE = (GZIPInputStream.GZIP_MAGIC shr 8).toByte() - } - -} - diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/ClassDefinitionProvider.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/ClassDefinitionProvider.kt deleted file mode 100644 index cd99d1b3b1..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/ClassDefinitionProvider.kt +++ /dev/null @@ -1,22 +0,0 @@ -package net.corda.djvm.code - -import net.corda.djvm.analysis.AnalysisRuntimeContext -import net.corda.djvm.references.ClassRepresentation - -/** - * A class definition provider is a hook for [ClassMutator], from where one can modify the name and meta-data of - * processed classes. - */ -interface ClassDefinitionProvider : DefinitionProvider { - - /** - * Hook for providing modifications to a class definition. - * - * @param context The context in which the hook is called. - * @param clazz The original class definition. - * - * @return The updated class definition, or [clazz] if no changes are desired. - */ - fun define(context: AnalysisRuntimeContext, clazz: ClassRepresentation): ClassRepresentation - -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/ClassMutator.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/ClassMutator.kt deleted file mode 100644 index 4d8f2b6307..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/ClassMutator.kt +++ /dev/null @@ -1,148 +0,0 @@ -package net.corda.djvm.code - -import net.corda.djvm.analysis.AnalysisConfiguration -import net.corda.djvm.analysis.ClassAndMemberVisitor -import net.corda.djvm.code.instructions.MethodEntry -import net.corda.djvm.references.ClassRepresentation -import net.corda.djvm.references.Member -import net.corda.djvm.references.MethodBody -import net.corda.djvm.utilities.Processor -import net.corda.djvm.utilities.loggerFor -import org.objectweb.asm.ClassVisitor -import org.objectweb.asm.Opcodes.* - -/** - * Helper class for applying a set of definition providers and emitters to a class or set of classes. - * - * @param classVisitor Class visitor to use when traversing the structure of classes. - * @property configuration The configuration to use for class analysis. - * @property definitionProviders A set of providers used to update the name or meta-data of classes and members. - * @param emitters A set of code emitters used to modify and instrument method bodies. - */ -class ClassMutator( - classVisitor: ClassVisitor, - private val configuration: AnalysisConfiguration, - private val definitionProviders: List = emptyList(), - emitters: List = emptyList() -) : ClassAndMemberVisitor(configuration, classVisitor) { - - /** - * Internal [Emitter] to add static field initializers to - * any class constructor method. - */ - private inner class PrependClassInitializer : Emitter { - override fun emit(context: EmitterContext, instruction: Instruction) = context.emit { - if (instruction is MethodEntry - && instruction.method.memberName == "" && instruction.method.signature == "()V" - && initializers.isNotEmpty()) { - writeByteCode(initializers) - initializers.clear() - } - } - } - - /* - * Some emitters must be executed before others. E.g. we need to apply - * the tracing emitters before the non-tracing ones. - */ - private val emitters: List = (emitters + PrependClassInitializer()).sortedBy(Emitter::priority) - private val initializers = mutableListOf() - - /** - * Tracks whether any modifications have been applied to any of the processed class(es) and pertinent members. - */ - var hasBeenModified: Boolean = false - private set - - /** - * Apply definition providers to a class. This can be used to update the name or definition (pertinent meta-data) - * of the class itself. - */ - override fun visitClass(clazz: ClassRepresentation): ClassRepresentation { - var resultingClass = clazz - Processor.processEntriesOfType(definitionProviders, analysisContext.messages) { - resultingClass = it.define(currentAnalysisContext(), resultingClass) - } - if (clazz != resultingClass) { - logger.trace("Type has been mutated {}", clazz) - hasBeenModified = true - } - return super.visitClass(resultingClass) - } - - /** - * If we have some static fields to initialise, and haven't already added them - * to an existing class initialiser block then we need to create one. - */ - override fun visitClassEnd(classVisitor: ClassVisitor, clazz: ClassRepresentation) { - tryWriteClassInitializer(classVisitor) - super.visitClassEnd(classVisitor, clazz) - } - - private fun tryWriteClassInitializer(classVisitor: ClassVisitor) { - if (initializers.isNotEmpty()) { - classVisitor.visitMethod(ACC_STATIC, "", "()V", null, null)?.also { mv -> - mv.visitCode() - EmitterModule(mv).writeByteCode(initializers) - mv.visitInsn(RETURN) - mv.visitMaxs(-1, -1) - mv.visitEnd() - } - initializers.clear() - hasBeenModified = true - } - } - - /** - * Apply definition providers to a method. This can be used to update the name or definition (pertinent meta-data) - * of a class member. - */ - override fun visitMethod(clazz: ClassRepresentation, method: Member): Member { - var resultingMethod = method - Processor.processEntriesOfType(definitionProviders, analysisContext.messages) { - resultingMethod = it.define(currentAnalysisContext(), resultingMethod) - } - if (method != resultingMethod) { - logger.trace("Method has been mutated {}", method) - hasBeenModified = true - } - return super.visitMethod(clazz, resultingMethod) - } - - /** - * Apply definition providers to a field. This can be used to update the name or definition (pertinent meta-data) - * of a class member. - */ - override fun visitField(clazz: ClassRepresentation, field: Member): Member { - var resultingField = field - Processor.processEntriesOfType(definitionProviders, analysisContext.messages) { - resultingField = it.define(currentAnalysisContext(), resultingField) - } - if (field != resultingField) { - logger.trace("Field has been mutated {}", field) - initializers += resultingField.body - hasBeenModified = true - } - return super.visitField(clazz, resultingField) - } - - /** - * Apply emitters to an instruction. This can be used to instrument a part of the code block, change behaviour of - * an existing instruction, or strip it out completely. - */ - override fun visitInstruction(method: Member, emitter: EmitterModule, instruction: Instruction) { - val context = EmitterContext(currentAnalysisContext(), configuration, emitter) - Processor.processEntriesOfType(emitters, analysisContext.messages) { - it.emit(context, instruction) - } - if (!emitter.emitDefaultInstruction || emitter.hasEmittedCustomCode) { - hasBeenModified = true - } - super.visitInstruction(method, emitter, instruction) - } - - private companion object { - private val logger = loggerFor() - } - -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/DefinitionProvider.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/DefinitionProvider.kt deleted file mode 100644 index d284fddef5..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/DefinitionProvider.kt +++ /dev/null @@ -1,7 +0,0 @@ -package net.corda.djvm.code - -/** - * A definition provider is a hook for [ClassMutator], from where one can modify the name and meta-data of processed - * classes and class members. - */ -interface DefinitionProvider \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/Emitter.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/Emitter.kt deleted file mode 100644 index 2eb5e0de5d..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/Emitter.kt +++ /dev/null @@ -1,27 +0,0 @@ -package net.corda.djvm.code - -/** - * An emitter is a hook for [ClassMutator], from where one can modify the byte code of a class method. - */ -interface Emitter { - - /** - * Hook for providing modifications to an instruction in a method body. One can also prepend and append instructions - * by using the [EmitterContext], and skip the default instruction altogether by invoking - * [EmitterModule.preventDefault] from within [EmitterContext.emit]. - * - * @param context The context from which the emitter is invoked. By calling [EmitterContext.emit], one gets access - * to an instance of [EmitterModule] from within the supplied closure. From there, one can emit new instructions and - * intercept the original instruction (for instance, modify or delete the instruction). - * @param instruction The instruction currently being processed. - */ - fun emit(context: EmitterContext, instruction: Instruction) - - /** - * Determines the order in which emitters are executed within the sandbox. - */ - @JvmDefault - val priority: Int - get() = EMIT_DEFAULT - -} \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/EmitterContext.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/EmitterContext.kt deleted file mode 100644 index 31ce3d7f8a..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/EmitterContext.kt +++ /dev/null @@ -1,76 +0,0 @@ -package net.corda.djvm.code - -import net.corda.djvm.analysis.AnalysisConfiguration -import net.corda.djvm.analysis.AnalysisRuntimeContext -import net.corda.djvm.analysis.SourceLocation -import net.corda.djvm.analysis.Whitelist -import net.corda.djvm.references.ClassRepresentation -import net.corda.djvm.references.ClassModule -import net.corda.djvm.references.Member -import net.corda.djvm.references.MemberModule - -/** - * The context in which an emitter is invoked. - * - * @property analysisContext The context in which a class and its members are processed. - * @property configuration The configuration to used for the analysis. - * @property emitterModule A module providing code generation functionality that can be used from within an emitter. - */ -@Suppress("unused") -open class EmitterContext( - private val analysisContext: AnalysisRuntimeContext, - private val configuration: AnalysisConfiguration, - val emitterModule: EmitterModule -) { - - /** - * The class currently being analysed. - */ - val clazz: ClassRepresentation - get() = analysisContext.clazz - - /** - * The member currently being analysed, if any. - */ - val member: Member? - get() = analysisContext.member - - /** - * The current source location. - */ - val location: SourceLocation - get() = analysisContext.location - - /** - * The configured whitelist. - */ - val whitelist: Whitelist - get() = analysisContext.configuration.whitelist - - /** - * Utilities for dealing with classes. - */ - val classModule: ClassModule - get() = analysisContext.configuration.classModule - - /** - * Utilities for dealing with members. - */ - val memberModule: MemberModule - get() = analysisContext.configuration.memberModule - - /** - * Resolve the sandboxed name of a class or interface. - */ - fun resolve(typeName: String): String { - return configuration.classResolver.resolve(typeName) - } - - /** - * Set up and execute an emitter block for a particular member. - */ - inline fun emit(action: EmitterModule.() -> Unit) { - action(emitterModule) - } - -} \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/EmitterModule.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/EmitterModule.kt deleted file mode 100644 index e51647830b..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/EmitterModule.kt +++ /dev/null @@ -1,228 +0,0 @@ -package net.corda.djvm.code - -import net.corda.djvm.references.MethodBody -import org.objectweb.asm.Label -import org.objectweb.asm.MethodVisitor -import org.objectweb.asm.Opcodes.* -import org.objectweb.asm.Type -import sandbox.net.corda.djvm.costing.RuntimeCostAccounter - -/** - * Helper functions for emitting code to a method body. - * - * @property methodVisitor The underlying visitor which controls all the byte code for the current method. - */ -@Suppress("unused") -class EmitterModule( - private val methodVisitor: MethodVisitor -) { - - /** - * Indicates whether the default instruction in the currently processed block is to be emitted or not. - */ - var emitDefaultInstruction: Boolean = true - private set - - /** - * Indicates whether any custom code has been emitted in the applicable context. - */ - var hasEmittedCustomCode: Boolean = false - private set - - /** - * Emit instruction for creating a new object of type [typeName]. - */ - fun new(typeName: String, opcode: Int = NEW) { - hasEmittedCustomCode = true - methodVisitor.visitTypeInsn(opcode, typeName) - } - - /** - * Emit instruction for creating a new object of type [T]. - */ - inline fun new() { - new(Type.getInternalName(T::class.java)) - } - - /** - * Emit instruction for loading a constant onto the stack. - */ - fun loadConstant(constant: Any) { - hasEmittedCustomCode = true - methodVisitor.visitLdcInsn(constant) - } - - /** - * Emit instruction for invoking a static method. - */ - fun invokeStatic(owner: String, name: String, descriptor: String, isInterface: Boolean = false) { - hasEmittedCustomCode = true - methodVisitor.visitMethodInsn(INVOKESTATIC, owner, name, descriptor, isInterface) - } - - /** - * Emit instruction for invoking a virtual method. - */ - fun invokeVirtual(owner: String, name: String, descriptor: String, isInterface: Boolean = false) { - hasEmittedCustomCode = true - methodVisitor.visitMethodInsn(INVOKEVIRTUAL, owner, name, descriptor, isInterface) - } - - /** - * Emit instruction for invoking a special method, e.g. a constructor or a method on a super-type. - */ - fun invokeSpecial(owner: String, name: String, descriptor: String, isInterface: Boolean = false) { - hasEmittedCustomCode = true - methodVisitor.visitMethodInsn(INVOKESPECIAL, owner, name, descriptor, isInterface) - } - - /** - * Emit instruction for invoking a special method on class [T], e.g. a constructor or a method on a super-type. - */ - inline fun invokeSpecial(name: String, descriptor: String, isInterface: Boolean = false) { - invokeSpecial(Type.getInternalName(T::class.java), name, descriptor, isInterface) - } - - fun invokeInterface(owner: String, name: String, descriptor: String) { - methodVisitor.visitMethodInsn(INVOKEINTERFACE, owner, name, descriptor, true) - hasEmittedCustomCode = true - } - - /** - * Emit instruction for storing a value into a static field. - */ - fun putStatic(owner: String, name: String, descriptor: String) { - methodVisitor.visitFieldInsn(PUTSTATIC, owner, name, descriptor) - hasEmittedCustomCode = true - } - - /** - * Emit instruction for popping one element off the stack. - */ - fun pop() { - hasEmittedCustomCode = true - methodVisitor.visitInsn(POP) - } - - /** - * Emit instruction for duplicating the top of the stack. - */ - fun duplicate() { - hasEmittedCustomCode = true - methodVisitor.visitInsn(DUP) - } - - /** - * Emit instruction for pushing an object reference - * from a register onto the stack. - */ - fun pushObject(regNum: Int) { - methodVisitor.visitVarInsn(ALOAD, regNum) - hasEmittedCustomCode = true - } - - /** - * Emit instruction for pushing an integer value - * from a register onto the stack. - */ - fun pushInteger(regNum: Int) { - methodVisitor.visitVarInsn(ILOAD, regNum) - hasEmittedCustomCode = true - } - - /** - * Emit instructions to rearrange the stack as follows: - * [W1] [W3] - * [W2] -> [W1] - * [w3] [W2] - */ - fun raiseThirdWordToTop() { - methodVisitor.visitInsn(DUP2_X1) - methodVisitor.visitInsn(POP2) - hasEmittedCustomCode = true - } - - /** - * Emit instructions to rearrange the stack as follows: - * [W1] [W2] - * [W2] -> [W3] - * [W3] [W1] - */ - fun sinkTopToThirdWord() { - methodVisitor.visitInsn(DUP_X2) - methodVisitor.visitInsn(POP) - hasEmittedCustomCode = true - } - - /** - * Emit a sequence of instructions for instantiating and throwing an exception based on the provided message. - */ - fun throwException(exceptionType: Class, message: String) { - val exceptionName = Type.getInternalName(exceptionType) - new(exceptionName) - methodVisitor.visitInsn(DUP) - methodVisitor.visitLdcInsn(message) - invokeSpecial(exceptionName, "", "(Ljava/lang/String;)V") - methodVisitor.visitInsn(ATHROW) - } - - inline fun throwException(message: String) = throwException(T::class.java, message) - - /** - * Attempt to cast the object on the top of the stack to the given class. - */ - fun castObjectTo(className: String) { - methodVisitor.visitTypeInsn(CHECKCAST, className) - hasEmittedCustomCode = true - } - - /** - * Emit instruction for returning from "void" method. - */ - fun returnVoid() { - methodVisitor.visitInsn(RETURN) - hasEmittedCustomCode = true - } - - /** - * Emit instruction for a function that returns an object reference. - */ - fun returnObject() { - methodVisitor.visitInsn(ARETURN) - hasEmittedCustomCode = true - } - - /** - * Emit instructions for a new line number. - */ - fun lineNumber(line: Int) { - val label = Label() - methodVisitor.visitLabel(label) - methodVisitor.visitLineNumber(line, label) - hasEmittedCustomCode = true - } - - /** - * Write the bytecode from these [MethodBody] objects as provided. - */ - fun writeByteCode(bodies: Iterable) { - for (body in bodies) { - body(this) - } - } - - /** - * Tell the code writer not to emit the default instruction. - */ - fun preventDefault() { - emitDefaultInstruction = false - } - - /** - * Emit instruction for invoking a method on the static runtime cost accounting and instrumentation object. - */ - fun invokeInstrumenter(methodName: String, methodSignature: String) { - invokeStatic(RuntimeCostAccounter.TYPE_NAME, methodName, methodSignature) - } - -} \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/Instruction.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/Instruction.kt deleted file mode 100644 index 90cee5daad..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/Instruction.kt +++ /dev/null @@ -1,23 +0,0 @@ -package net.corda.djvm.code - -import org.objectweb.asm.Opcodes - -/** - * Byte code instruction. - * - * @property operation The operation code, enumerated in [Opcodes]. - */ -open class Instruction( - val operation: Int -) { - - companion object { - - /** - * Byte code for the breakpoint operation. - */ - const val OP_BREAKPOINT: Int = 202 - - } - -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/MemberDefinitionProvider.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/MemberDefinitionProvider.kt deleted file mode 100644 index b6a2433db8..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/MemberDefinitionProvider.kt +++ /dev/null @@ -1,22 +0,0 @@ -package net.corda.djvm.code - -import net.corda.djvm.analysis.AnalysisRuntimeContext -import net.corda.djvm.references.Member - -/** - * A member definition provider is a hook for [ClassMutator], from where one can modify the name and meta-data of - * processed class members. - */ -interface MemberDefinitionProvider : DefinitionProvider { - - /** - * Hook for providing modifications to a member definition. - * - * @param context The context in which the hook is called. - * @param member The original member definition. - * - * @return The updated member definition, or [member] if no changes are desired. - */ - fun define(context: AnalysisRuntimeContext, member: Member): Member - -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/Types.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/Types.kt deleted file mode 100644 index 3d3b86d2af..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/Types.kt +++ /dev/null @@ -1,28 +0,0 @@ -@file:JvmName("Types") -package net.corda.djvm.code - -import org.objectweb.asm.Type -import sandbox.java.lang.DJVMException -import sandbox.net.corda.djvm.costing.ThresholdViolationError -import sandbox.net.corda.djvm.rules.RuleViolationError - -/** - * These are the priorities for executing [Emitter] instances. - * Tracing emitters are executed first. - */ -const val EMIT_TRACING: Int = 0 -const val EMIT_TRAPPING_EXCEPTIONS: Int = EMIT_TRACING + 1 -const val EMIT_HANDLING_EXCEPTIONS: Int = EMIT_TRAPPING_EXCEPTIONS + 1 -const val EMIT_DEFAULT: Int = 10 - -val ruleViolationError: String = Type.getInternalName(RuleViolationError::class.java) -val thresholdViolationError: String = Type.getInternalName(ThresholdViolationError::class.java) -val djvmException: String = Type.getInternalName(DJVMException::class.java) - -/** - * Local extension method for normalizing a class name. - */ -val String.asPackagePath: String get() = this.replace('/', '.') -val String.asResourcePath: String get() = this.replace('.', '/') - -val String.emptyAsNull: String? get() = if (isEmpty()) null else this \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/BranchInstruction.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/BranchInstruction.kt deleted file mode 100644 index 92e060b923..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/BranchInstruction.kt +++ /dev/null @@ -1,15 +0,0 @@ -package net.corda.djvm.code.instructions - -import net.corda.djvm.code.Instruction -import org.objectweb.asm.Label - -/** - * Branch instruction. - * - * @property label The label of the target. - */ -@Suppress("MemberVisibilityCanBePrivate") -class BranchInstruction( - operation: Int, - val label: Label -) : Instruction(operation) \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/CodeLabel.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/CodeLabel.kt deleted file mode 100644 index 73243e9721..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/CodeLabel.kt +++ /dev/null @@ -1,12 +0,0 @@ -package net.corda.djvm.code.instructions - -import org.objectweb.asm.Label - -/** - * Label of a code block. - * - * @property label The label for the given code block. - */ -class CodeLabel( - val label: Label -) : NoOperationInstruction() diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/ConstantInstruction.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/ConstantInstruction.kt deleted file mode 100644 index ebd90d6f02..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/ConstantInstruction.kt +++ /dev/null @@ -1,6 +0,0 @@ -package net.corda.djvm.code.instructions - -import net.corda.djvm.code.Instruction -import org.objectweb.asm.Opcodes - -class ConstantInstruction(val value: Any) : Instruction(Opcodes.LDC) \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/DynamicInvocationInstruction.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/DynamicInvocationInstruction.kt deleted file mode 100644 index 2dbbff45c4..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/DynamicInvocationInstruction.kt +++ /dev/null @@ -1,20 +0,0 @@ -package net.corda.djvm.code.instructions - -import net.corda.djvm.code.Instruction -import org.objectweb.asm.Opcodes - -/** - * Dynamic invocation instruction. - * - * @property memberName The name of the method to invoke. - * @property signature The function signature of the method being invoked. - * @property numberOfArguments The number of arguments to pass to the target. - * @property returnsValueOrReference False if the target returns `void`, or true if it returns a value or a reference. - */ -@Suppress("MemberVisibilityCanBePrivate") -class DynamicInvocationInstruction( - val memberName: String, - val signature: String, - val numberOfArguments: Int, - val returnsValueOrReference: Boolean -) : Instruction(Opcodes.INVOKEDYNAMIC) diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/IntegerInstruction.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/IntegerInstruction.kt deleted file mode 100644 index ac7581acbe..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/IntegerInstruction.kt +++ /dev/null @@ -1,13 +0,0 @@ -package net.corda.djvm.code.instructions - -import net.corda.djvm.code.Instruction - -/** - * Instruction with a single, constant integer operand. - * - * @property operand The integer operand. - */ -class IntegerInstruction( - operation: Int, - val operand: Int -) : Instruction(operation) \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/MemberAccessInstruction.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/MemberAccessInstruction.kt deleted file mode 100644 index da0d761f18..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/MemberAccessInstruction.kt +++ /dev/null @@ -1,35 +0,0 @@ -package net.corda.djvm.code.instructions - -import net.corda.djvm.code.Instruction -import net.corda.djvm.references.MemberReference - -/** - * Field access and method invocation instruction. - * - * @property owner The class owning the field or method. - * @property memberName The name of the field or the method being accessed. - * @property signature The return type of a field or function signature for a method. - * @property ownerIsInterface If the member is a method, this is true if the owner is an interface. - * @property isMethod Indicates whether the member is a method or a field. - */ -class MemberAccessInstruction( - operation: Int, - val owner: String, - val memberName: String, - val signature: String, - val ownerIsInterface: Boolean = false, - val isMethod: Boolean = false -) : Instruction(operation) { - - /** - * The absolute name of the referenced member. - */ - val reference = "$owner.$memberName:$signature" - - /** - * Get a member reference representation of the target of the instruction. - */ - val member: MemberReference - get() = MemberReference(owner, memberName, signature) - -} diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/MethodEntry.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/MethodEntry.kt deleted file mode 100644 index cde092c056..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/MethodEntry.kt +++ /dev/null @@ -1,9 +0,0 @@ -package net.corda.djvm.code.instructions - -import net.corda.djvm.references.Member - -/** - * Pseudo-instruction marking the beginning of a method. - * @property method [Member] describing this method. - */ -class MethodEntry(val method: Member): NoOperationInstruction() \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/NoOperationInstruction.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/NoOperationInstruction.kt deleted file mode 100644 index e27c951e29..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/NoOperationInstruction.kt +++ /dev/null @@ -1,9 +0,0 @@ -package net.corda.djvm.code.instructions - -import net.corda.djvm.code.Instruction -import org.objectweb.asm.Opcodes - -/** - * Instruction that, surprise surprise (!), does nothing! - */ -open class NoOperationInstruction : Instruction(Opcodes.NOP) \ No newline at end of file diff --git a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/TableSwitchInstruction.kt b/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/TableSwitchInstruction.kt deleted file mode 100644 index b3fec2bd4e..0000000000 --- a/djvm/djvm/src/main/kotlin/net/corda/djvm/code/instructions/TableSwitchInstruction.kt +++ /dev/null @@ -1,22 +0,0 @@ -package net.corda.djvm.code.instructions - -import net.corda.djvm.code.Instruction -import org.objectweb.asm.Label -import org.objectweb.asm.Opcodes - -/** - * Table switch instruction. - * - * @property min The minimum key value. - * @property max The maximum key value. - * @property defaultHandler The label of the default handler block. - * @property handlers The labels of each of the handler blocks, where the label of the handler block for key - * `min + i` is at index `i` in `handlers`. - */ -@Suppress("MemberVisibilityCanBePrivate") -class TableSwitchInstruction( - val min: Int, - val max: Int, - val defaultHandler: Label, - val handlers: List