idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
33,100 | @ OperationsPerInvocation ( 20 ) public void benchmarkJdkProxy ( Blackhole blackHole ) { blackHole . consume ( jdkProxyInstance . method ( booleanValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( byteValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( shortValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( intValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( charValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( intValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( longValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( floatValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( doubleValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( stringValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( booleanValue , booleanValue , booleanValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( byteValue , byteValue , byteValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( shortValue , shortValue , shortValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( charValue , charValue , charValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( longValue , longValue , longValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( floatValue , floatValue , floatValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( doubleValue , doubleValue , doubleValue ) ) ; blackHole . consume ( jdkProxyInstance . method ( stringValue , stringValue , stringValue ) ) ; } | Performs a benchmark for a trivial class creation using the Java Class Library s utilities . |
33,101 | public static UsingLookup of ( Object lookup ) { if ( ! DISPATCHER . isAlive ( ) ) { throw new IllegalStateException ( "The current VM does not support class definition via method handle lookups" ) ; } else if ( ! JavaType . METHOD_HANDLES_LOOKUP . isInstance ( lookup ) ) { throw new IllegalArgumentException ( "Not a method handle lookup: " + lookup ) ; } else if ( ( DISPATCHER . lookupModes ( lookup ) & PACKAGE_LOOKUP ) == 0 ) { throw new IllegalArgumentException ( "Lookup does not imply package-access: " + lookup ) ; } return new UsingLookup ( DISPATCHER . dropLookupMode ( lookup , Opcodes . ACC_PRIVATE ) ) ; } | Creates class injector that defines a class using a method handle lookup . |
33,102 | public static ClassInjector of ( File folder , Target target , Instrumentation instrumentation ) { return new UsingInstrumentation ( folder , target , instrumentation , new RandomString ( ) ) ; } | Creates an instrumentation - based class injector . |
33,103 | public static ClassReader of ( byte [ ] binaryRepresentation ) { if ( EXPERIMENTAL ) { byte [ ] actualVersion = new byte [ ] { binaryRepresentation [ 4 ] , binaryRepresentation [ 5 ] , binaryRepresentation [ 6 ] , binaryRepresentation [ 7 ] } ; binaryRepresentation [ 4 ] = ( byte ) ( Opcodes . V12 >>> 24 ) ; binaryRepresentation [ 5 ] = ( byte ) ( Opcodes . V12 >>> 16 ) ; binaryRepresentation [ 6 ] = ( byte ) ( Opcodes . V12 >>> 8 ) ; binaryRepresentation [ 7 ] = ( byte ) Opcodes . V12 ; ClassReader classReader = new ClassReader ( binaryRepresentation ) ; System . arraycopy ( actualVersion , 0 , binaryRepresentation , 4 , actualVersion . length ) ; return classReader ; } else { return new ClassReader ( binaryRepresentation ) ; } } | Creates a class reader for the given binary representation of a class file . |
33,104 | private List < StackManipulation > argumentValuesOf ( MethodDescription instrumentedMethod ) { TypeList . Generic parameterTypes = instrumentedMethod . getParameters ( ) . asTypeList ( ) ; List < StackManipulation > instruction = new ArrayList < StackManipulation > ( parameterTypes . size ( ) ) ; int currentIndex = 1 ; for ( TypeDescription . Generic parameterType : parameterTypes ) { instruction . add ( new StackManipulation . Compound ( MethodVariableAccess . of ( parameterType ) . loadFrom ( currentIndex ) , assigner . assign ( parameterType , TypeDescription . Generic . OBJECT , Assigner . Typing . STATIC ) ) ) ; currentIndex += parameterType . getStackSize ( ) . getSize ( ) ; } return instruction ; } | Returns a list of stack manipulations that loads all arguments of an instrumented method . |
33,105 | protected ByteCodeAppender . Size apply ( MethodVisitor methodVisitor , Context implementationContext , MethodDescription instrumentedMethod , StackManipulation preparingManipulation , FieldDescription fieldDescription ) { if ( instrumentedMethod . isStatic ( ) ) { throw new IllegalStateException ( "It is not possible to apply an invocation handler onto the static method " + instrumentedMethod ) ; } MethodConstant . CanCache methodConstant = privileged ? MethodConstant . ofPrivileged ( instrumentedMethod . asDefined ( ) ) : MethodConstant . of ( instrumentedMethod . asDefined ( ) ) ; StackManipulation . Size stackSize = new StackManipulation . Compound ( preparingManipulation , FieldAccess . forField ( fieldDescription ) . read ( ) , MethodVariableAccess . loadThis ( ) , cached ? methodConstant . cached ( ) : methodConstant , ArrayFactory . forType ( TypeDescription . Generic . OBJECT ) . withValues ( argumentValuesOf ( instrumentedMethod ) ) , MethodInvocation . invoke ( INVOCATION_HANDLER_TYPE . getDeclaredMethods ( ) . getOnly ( ) ) , assigner . assign ( TypeDescription . Generic . OBJECT , instrumentedMethod . getReturnType ( ) , Assigner . Typing . DYNAMIC ) , MethodReturn . of ( instrumentedMethod . getReturnType ( ) ) ) . apply ( methodVisitor , implementationContext ) ; return new ByteCodeAppender . Size ( stackSize . getMaximalSize ( ) , instrumentedMethod . getStackSize ( ) ) ; } | Applies an implementation that delegates to a invocation handler . |
33,106 | public TypeReferenceAdjustment filter ( ElementMatcher < ? super TypeDescription > filter ) { return new TypeReferenceAdjustment ( strict , this . filter . < TypeDescription > or ( filter ) ) ; } | Excludes all matched types from being added as an attribute . |
33,107 | public static StackManipulation of ( TypeDescription typeDescription ) { if ( typeDescription . isPrimitive ( ) ) { throw new IllegalArgumentException ( "Cannot check an instance against a primitive type: " + typeDescription ) ; } return new InstanceCheck ( typeDescription ) ; } | Creates a new instance check . |
33,108 | protected boolean onCacheMiss ( T target ) { boolean cached = matcher . matches ( target ) ; map . put ( target , cached ) ; return cached ; } | Invoked if the cache is not hit . |
33,109 | public static String hashOf ( int value ) { char [ ] buffer = new char [ ( Integer . SIZE / KEY_BITS ) + ( ( Integer . SIZE % KEY_BITS ) == 0 ? 0 : 1 ) ] ; for ( int index = 0 ; index < buffer . length ; index ++ ) { buffer [ index ] = SYMBOL [ ( value >>> index * KEY_BITS ) & ( - 1 >>> ( Integer . SIZE - KEY_BITS ) ) ] ; } return new String ( buffer ) ; } | Represents an integer value as a string hash . This string is not technically random but generates a fixed character sequence based on the hash provided . |
33,110 | public static CanCache of ( MethodDescription . InDefinedShape methodDescription ) { if ( methodDescription . isTypeInitializer ( ) ) { return CanCacheIllegal . INSTANCE ; } else if ( methodDescription . isConstructor ( ) ) { return new ForConstructor ( methodDescription ) ; } else { return new ForMethod ( methodDescription ) ; } } | Creates a stack manipulation that loads a method constant onto the operand stack . |
33,111 | protected static List < StackManipulation > typeConstantsFor ( List < TypeDescription > parameterTypes ) { List < StackManipulation > typeConstants = new ArrayList < StackManipulation > ( parameterTypes . size ( ) ) ; for ( TypeDescription parameterType : parameterTypes ) { typeConstants . add ( ClassConstant . of ( parameterType ) ) ; } return typeConstants ; } | Returns a list of type constant load operations for the given list of parameters . |
33,112 | @ SuppressFBWarnings ( value = "GC_UNRELATED_TYPES" , justification = "Cross-comparison is intended" ) public Class < ? > insert ( ClassLoader classLoader , T key , Class < ? > type ) { ConcurrentMap < T , Reference < Class < ? > > > storage = cache . get ( new LookupKey ( classLoader ) ) ; if ( storage == null ) { storage = new ConcurrentHashMap < T , Reference < Class < ? > > > ( ) ; ConcurrentMap < T , Reference < Class < ? > > > previous = cache . putIfAbsent ( new StorageKey ( classLoader , this ) , storage ) ; if ( previous != null ) { storage = previous ; } } Reference < Class < ? > > reference = sort . wrap ( type ) , previous = storage . putIfAbsent ( key , reference ) ; while ( previous != null ) { Class < ? > previousType = previous . get ( ) ; if ( previousType != null ) { return previousType ; } else if ( storage . remove ( key , previous ) ) { previous = storage . putIfAbsent ( key , reference ) ; } else { previous = storage . get ( key ) ; if ( previous == null ) { previous = storage . putIfAbsent ( key , reference ) ; } } } return type ; } | Inserts a new type into the cache . If a type with the same class loader and key was inserted previously the cache is not updated . |
33,113 | @ OperationsPerInvocation ( 20 ) public void benchmarkByteBuddyWithProxy ( Blackhole blackHole ) { blackHole . consume ( byteBuddyWithProxyInstance . method ( booleanValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( byteValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( shortValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( intValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( charValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( intValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( longValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( floatValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( doubleValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( stringValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( booleanValue , booleanValue , booleanValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( byteValue , byteValue , byteValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( shortValue , shortValue , shortValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( charValue , charValue , charValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( longValue , longValue , longValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( floatValue , floatValue , floatValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( doubleValue , doubleValue , doubleValue ) ) ; blackHole . consume ( byteBuddyWithProxyInstance . method ( stringValue , stringValue , stringValue ) ) ; } | Performs a benchmark of a super method invocation using Byte Buddy . This benchmark uses an annotation - based approach which is more difficult to optimize by the JIT compiler . |
33,114 | @ OperationsPerInvocation ( 20 ) public void benchmarkByteBuddyWithAccessor ( Blackhole blackHole ) { blackHole . consume ( byteBuddyWithAccessorInstance . method ( booleanValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( byteValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( shortValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( intValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( charValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( intValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( longValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( floatValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( doubleValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( stringValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( booleanValue , booleanValue , booleanValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( byteValue , byteValue , byteValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( shortValue , shortValue , shortValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( charValue , charValue , charValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( longValue , longValue , longValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( floatValue , floatValue , floatValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( doubleValue , doubleValue , doubleValue ) ) ; blackHole . consume ( byteBuddyWithAccessorInstance . method ( stringValue , stringValue , stringValue ) ) ; } | Performs a benchmark of a super method invocation using Byte Buddy . This benchmark also uses the annotation - based approach but creates delegation methods which do not require the creation of additional classes . |
33,115 | @ OperationsPerInvocation ( 20 ) public void benchmarkByteBuddyWithPrefix ( Blackhole blackHole ) { blackHole . consume ( byteBuddyWithPrefixInstance . method ( booleanValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( byteValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( shortValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( intValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( charValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( intValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( longValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( floatValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( doubleValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( stringValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( booleanValue , booleanValue , booleanValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( byteValue , byteValue , byteValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( shortValue , shortValue , shortValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( charValue , charValue , charValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( longValue , longValue , longValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( floatValue , floatValue , floatValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( doubleValue , doubleValue , doubleValue ) ) ; blackHole . consume ( byteBuddyWithPrefixInstance . method ( stringValue , stringValue , stringValue ) ) ; } | Performs a benchmark of a super method invocation using Byte Buddy . This benchmark also uses the annotation - based approach but hard - codes the super method call subsequently to the method . |
33,116 | @ OperationsPerInvocation ( 20 ) public void benchmarkByteBuddySpecialized ( Blackhole blackHole ) { blackHole . consume ( byteBuddySpecializedInstance . method ( booleanValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( byteValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( shortValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( intValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( charValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( intValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( longValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( floatValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( doubleValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( stringValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( booleanValue , booleanValue , booleanValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( byteValue , byteValue , byteValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( shortValue , shortValue , shortValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( charValue , charValue , charValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( intValue , intValue , intValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( longValue , longValue , longValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( floatValue , floatValue , floatValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( doubleValue , doubleValue , doubleValue ) ) ; blackHole . consume ( byteBuddySpecializedInstance . method ( stringValue , stringValue , stringValue ) ) ; } | Performs a benchmark of a super method invocation using Byte Buddy . This benchmark uses a specialized interception strategy which is easier to inline by the compiler . |
33,117 | public MemberSubstitution replaceWithField ( ElementMatcher < ? super FieldDescription > matcher ) { return replaceWith ( new Substitution . ForFieldAccess . OfMatchedField ( matcher ) ) ; } | Replaces any interaction with a matched byte code element with a non - static field access on the first parameter of the matched element . When matching a non - static field access or method invocation the substituted field is located on the same receiver type as the original access . For static access the first argument is used as a receiver . |
33,118 | public MemberSubstitution replaceWithMethod ( ElementMatcher < ? super MethodDescription > matcher , MethodGraph . Compiler methodGraphCompiler ) { return replaceWith ( new Substitution . ForMethodInvocation . OfMatchedMethod ( matcher , methodGraphCompiler ) ) ; } | Replaces any interaction with a matched byte code element with a non - static method access on the first parameter of the matched element . When matching a non - static field access or method invocation the substituted method is located on the same receiver type as the original access . For static access the first argument is used as a receiver . |
33,119 | public Plugin . Factory . UsingReflection . ArgumentResolver toArgumentResolver ( ) { return new Plugin . Factory . UsingReflection . ArgumentResolver . ForIndex . WithDynamicType ( index , value ) ; } | Resolves this plugin argument to an argument resolver . |
33,120 | public static < S > List < S > of ( S left , List < ? extends S > right ) { if ( right . isEmpty ( ) ) { return Collections . singletonList ( left ) ; } else { List < S > list = new ArrayList < S > ( 1 + right . size ( ) ) ; list . add ( left ) ; list . addAll ( right ) ; return list ; } } | Creates a list of a single element and another list . |
33,121 | public static < S > List < S > of ( List < ? extends S > left , List < ? extends S > right ) { List < S > list = new ArrayList < S > ( left . size ( ) + right . size ( ) ) ; list . addAll ( left ) ; list . addAll ( right ) ; return list ; } | Creates a list of a left and right list . |
33,122 | private void onOwnableType ( Generic ownableType ) { Generic ownerType = ownableType . getOwnerType ( ) ; if ( ownerType != null && ownerType . getSort ( ) . isParameterized ( ) ) { onOwnableType ( ownerType ) ; signatureVisitor . visitInnerClassType ( ownableType . asErasure ( ) . getSimpleName ( ) ) ; } else { signatureVisitor . visitClassType ( ownableType . asErasure ( ) . getInternalName ( ) ) ; } for ( Generic typeArgument : ownableType . getTypeArguments ( ) ) { typeArgument . accept ( new OfTypeArgument ( signatureVisitor ) ) ; } } | Visits a type which might define an owner type . |
33,123 | public static StackManipulation of ( Serializable value ) { if ( value == null ) { return NullConstant . INSTANCE ; } try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; ObjectOutputStream objectOutputStream = new ObjectOutputStream ( byteArrayOutputStream ) ; try { objectOutputStream . writeObject ( value ) ; } finally { objectOutputStream . close ( ) ; } return new SerializedConstant ( byteArrayOutputStream . toString ( CHARSET ) ) ; } catch ( IOException exception ) { throw new IllegalStateException ( "Cannot serialize " + value , exception ) ; } } | Creates a new stack manipulation to load the supplied value onto the stack . |
33,124 | public void addReads ( Instrumentation instrumentation , JavaModule module ) { DISPATCHER . addReads ( instrumentation , this . module , module . unwrap ( ) ) ; } | Adds a read - edge to this module to the supplied module using the instrumentation API . |
33,125 | public EntryPoint getEntryPoint ( ClassLoaderResolver classLoaderResolver , File root , Iterable < ? extends File > classPath ) { if ( entryPoint == null || entryPoint . length ( ) == 0 ) { throw new GradleException ( "Entry point name is not defined" ) ; } for ( EntryPoint . Default entryPoint : EntryPoint . Default . values ( ) ) { if ( this . entryPoint . equals ( entryPoint . name ( ) ) ) { return entryPoint ; } } try { return ( EntryPoint ) Class . forName ( entryPoint , false , classLoaderResolver . resolve ( getClassPath ( root , classPath ) ) ) . getDeclaredConstructor ( ) . newInstance ( ) ; } catch ( Exception exception ) { throw new GradleException ( "Cannot create entry point: " + entryPoint , exception ) ; } } | Resolves this initialization to an entry point instance . |
33,126 | public void transformation ( Closure < ? > closure ) { transformations . add ( ( Transformation ) project . configure ( new Transformation ( project ) , closure ) ) ; } | Adds a transformation to apply . |
33,127 | public void initialization ( Closure < ? > closure ) { if ( initialization != null ) { throw new GradleException ( "Initialization is already set" ) ; } initialization = ( Initialization ) project . configure ( new Initialization ( ) , closure ) ; } | Adds an initialization to apply . |
33,128 | public MethodNameTransformer getMethodNameTransformer ( ) { return suffix == null || suffix . length ( ) == 0 ? MethodNameTransformer . Suffixing . withRandomSuffix ( ) : new MethodNameTransformer . Suffixing ( suffix ) ; } | Returns the method name transformer to use . |
33,129 | public void setup ( ) { baseClassDescription = TypePool . Default . ofSystemLoader ( ) . describe ( baseClass . getName ( ) ) . resolve ( ) ; } | Sets up this benchmark . |
33,130 | public ExampleInterface baseline ( ) { return new ExampleInterface ( ) { public boolean method ( boolean arg ) { return false ; } public byte method ( byte arg ) { return 0 ; } public short method ( short arg ) { return 0 ; } public int method ( int arg ) { return 0 ; } public char method ( char arg ) { return 0 ; } public long method ( long arg ) { return 0 ; } public float method ( float arg ) { return 0 ; } public double method ( double arg ) { return 0 ; } public Object method ( Object arg ) { return null ; } public boolean [ ] method ( boolean arg1 , boolean arg2 , boolean arg3 ) { return null ; } public byte [ ] method ( byte arg1 , byte arg2 , byte arg3 ) { return null ; } public short [ ] method ( short arg1 , short arg2 , short arg3 ) { return null ; } public int [ ] method ( int arg1 , int arg2 , int arg3 ) { return null ; } public char [ ] method ( char arg1 , char arg2 , char arg3 ) { return null ; } public long [ ] method ( long arg1 , long arg2 , long arg3 ) { return null ; } public float [ ] method ( float arg1 , float arg2 , float arg3 ) { return null ; } public double [ ] method ( double arg1 , double arg2 , double arg3 ) { return null ; } public Object [ ] method ( Object arg1 , Object arg2 , Object arg3 ) { return null ; } } ; } | Creates a baseline for the benchmark . |
33,131 | public ExampleInterface benchmarkByteBuddy ( ) throws Exception { return new ByteBuddy ( ) . with ( TypeValidation . DISABLED ) . ignore ( none ( ) ) . subclass ( baseClass ) . method ( isDeclaredBy ( baseClass ) ) . intercept ( StubMethod . INSTANCE ) . make ( ) . load ( newClassLoader ( ) , ClassLoadingStrategy . Default . INJECTION ) . getLoaded ( ) . getDeclaredConstructor ( ) . newInstance ( ) ; } | Performs a benchmark of an interface implementation using Byte Buddy . |
33,132 | public ExampleInterface benchmarkCglib ( ) { Enhancer enhancer = new Enhancer ( ) ; enhancer . setUseCache ( false ) ; enhancer . setClassLoader ( newClassLoader ( ) ) ; enhancer . setSuperclass ( baseClass ) ; CallbackHelper callbackHelper = new CallbackHelper ( Object . class , new Class [ ] { baseClass } ) { protected Object getCallback ( Method method ) { if ( method . getDeclaringClass ( ) == baseClass ) { return new FixedValue ( ) { public Object loadObject ( ) { return null ; } } ; } else { return NoOp . INSTANCE ; } } } ; enhancer . setCallbackFilter ( callbackHelper ) ; enhancer . setCallbacks ( callbackHelper . getCallbacks ( ) ) ; return ( ExampleInterface ) enhancer . create ( ) ; } | Performs a benchmark of an interface implementation using cglib . |
33,133 | public ExampleInterface benchmarkJavassist ( ) throws Exception { ProxyFactory proxyFactory = new ProxyFactory ( ) { protected ClassLoader getClassLoader ( ) { return newClassLoader ( ) ; } } ; proxyFactory . setUseCache ( false ) ; proxyFactory . setUseWriteReplace ( false ) ; proxyFactory . setSuperclass ( Object . class ) ; proxyFactory . setInterfaces ( new Class < ? > [ ] { baseClass } ) ; proxyFactory . setFilter ( new MethodFilter ( ) { public boolean isHandled ( Method method ) { return true ; } } ) ; @ SuppressWarnings ( "unchecked" ) Object instance = proxyFactory . createClass ( ) . getDeclaredConstructor ( ) . newInstance ( ) ; ( ( javassist . util . proxy . Proxy ) instance ) . setHandler ( new MethodHandler ( ) { public Object invoke ( Object self , Method thisMethod , Method proceed , Object [ ] args ) throws Throwable { Class < ? > returnType = thisMethod . getReturnType ( ) ; if ( returnType . isPrimitive ( ) ) { if ( returnType == boolean . class ) { return defaultBooleanValue ; } else if ( returnType == byte . class ) { return defaultByteValue ; } else if ( returnType == short . class ) { return defaultShortValue ; } else if ( returnType == char . class ) { return defaultCharValue ; } else if ( returnType == int . class ) { return defaultIntValue ; } else if ( returnType == long . class ) { return defaultLongValue ; } else if ( returnType == float . class ) { return defaultFloatValue ; } else { return defaultDoubleValue ; } } else { return defaultReferenceValue ; } } } ) ; return ( ExampleInterface ) instance ; } | Performs a benchmark of an interface implementation using javassist proxies . |
33,134 | public ExampleInterface benchmarkJdkProxy ( ) throws Exception { return ( ExampleInterface ) Proxy . newProxyInstance ( newClassLoader ( ) , new Class < ? > [ ] { baseClass } , new InvocationHandler ( ) { public Object invoke ( Object proxy , Method method , Object [ ] args ) { Class < ? > returnType = method . getReturnType ( ) ; if ( returnType . isPrimitive ( ) ) { if ( returnType == boolean . class ) { return defaultBooleanValue ; } else if ( returnType == byte . class ) { return defaultByteValue ; } else if ( returnType == short . class ) { return defaultShortValue ; } else if ( returnType == char . class ) { return defaultCharValue ; } else if ( returnType == int . class ) { return defaultIntValue ; } else if ( returnType == long . class ) { return defaultLongValue ; } else if ( returnType == float . class ) { return defaultFloatValue ; } else { return defaultDoubleValue ; } } else { return defaultReferenceValue ; } } } ) ; } | Performs a benchmark of an interface implementation using the Java Class Library s utilities . |
33,135 | private InstrumentedType applyConstructorStrategy ( InstrumentedType instrumentedType ) { if ( ! instrumentedType . isInterface ( ) ) { for ( MethodDescription . Token token : constructorStrategy . extractConstructors ( instrumentedType ) ) { instrumentedType = instrumentedType . withMethod ( token ) ; } } return instrumentedType ; } | Applies this builder s constructor strategy to the given instrumented type . |
33,136 | private void adjustStack ( int delta , int offset ) { if ( delta > 2 ) { throw new IllegalStateException ( "Cannot push multiple values onto the operand stack: " + delta ) ; } else if ( delta > 0 ) { int position = current . size ( ) ; while ( offset > 0 && position > 0 ) { offset -= current . get ( -- position ) . getSize ( ) ; } if ( offset < 0 ) { throw new IllegalStateException ( "Unexpected offset underflow: " + offset ) ; } current . add ( position , StackSize . of ( delta ) ) ; } else if ( offset != 0 ) { throw new IllegalStateException ( "Cannot specify non-zero offset " + offset + " for non-incrementing value: " + delta ) ; } else { while ( delta < 0 ) { if ( current . isEmpty ( ) ) { return ; } delta += current . remove ( current . size ( ) - 1 ) . getSize ( ) ; } if ( delta == 1 ) { current . add ( StackSize . SINGLE ) ; } else if ( delta != 0 ) { throw new IllegalStateException ( "Unexpected remainder on the operand stack: " + delta ) ; } } } | Adjusts the current state of the operand stack . |
33,137 | public int drainStack ( int store , int load , StackSize size ) { int difference = current . get ( current . size ( ) - 1 ) . getSize ( ) - size . getSize ( ) ; if ( current . size ( ) == 1 && difference == 0 ) { return 0 ; } else { super . visitVarInsn ( store , freeIndex ) ; if ( difference == 1 ) { super . visitInsn ( Opcodes . POP ) ; } else if ( difference != 0 ) { throw new IllegalStateException ( "Unexpected remainder on the operand stack: " + difference ) ; } doDrain ( current . subList ( 0 , current . size ( ) - 1 ) ) ; super . visitVarInsn ( load , freeIndex ) ; return freeIndex + size . getSize ( ) ; } } | Drains the stack to only contain the top value . For this the value on top of the stack is temporarily stored in the local variable array until all values on the stack are popped off . Subsequently the top value is pushed back onto the operand stack . |
33,138 | private void doDrain ( List < StackSize > stackSizes ) { ListIterator < StackSize > iterator = stackSizes . listIterator ( stackSizes . size ( ) ) ; while ( iterator . hasPrevious ( ) ) { StackSize current = iterator . previous ( ) ; switch ( current ) { case SINGLE : super . visitInsn ( Opcodes . POP ) ; break ; case DOUBLE : super . visitInsn ( Opcodes . POP2 ) ; break ; default : throw new IllegalStateException ( "Unexpected stack size: " + current ) ; } } } | Drains all supplied elements of the operand stack . |
33,139 | public void register ( Label label , List < StackSize > stackSizes ) { sizes . put ( label , stackSizes ) ; } | Explicitly registers a label to define a given stack state . |
33,140 | public static AssignerConfigurable value ( TypeDescription fixedValue ) { return new ForPoolValue ( ClassConstant . of ( fixedValue ) , TypeDescription . CLASS ) ; } | Returns the given type in form of a loaded type . The value is loaded from the written class s constant pool . |
33,141 | protected ByteCodeAppender . Size apply ( MethodVisitor methodVisitor , Context implementationContext , MethodDescription instrumentedMethod , TypeDescription . Generic fixedValueType , StackManipulation valueLoadingInstruction ) { StackManipulation assignment = assigner . assign ( fixedValueType , instrumentedMethod . getReturnType ( ) , typing ) ; if ( ! assignment . isValid ( ) ) { throw new IllegalArgumentException ( "Cannot return value of type " + fixedValueType + " for " + instrumentedMethod ) ; } StackManipulation . Size stackSize = new StackManipulation . Compound ( valueLoadingInstruction , assignment , MethodReturn . of ( instrumentedMethod . getReturnType ( ) ) ) . apply ( methodVisitor , implementationContext ) ; return new ByteCodeAppender . Size ( stackSize . getMaximalSize ( ) , instrumentedMethod . getStackSize ( ) ) ; } | Blueprint method that for applying the actual implementation . |
33,142 | @ SuppressFBWarnings ( value = "REC_CATCH_EXCEPTION" , justification = "Applies Maven exception wrapper" ) public EntryPoint getEntryPoint ( ClassLoaderResolver classLoaderResolver , String groupId , String artifactId , String version , String packaging ) throws MojoExecutionException { if ( entryPoint == null || entryPoint . length ( ) == 0 ) { throw new MojoExecutionException ( "Entry point name is not defined" ) ; } for ( EntryPoint . Default entryPoint : EntryPoint . Default . values ( ) ) { if ( this . entryPoint . equals ( entryPoint . name ( ) ) ) { return entryPoint ; } } try { return ( EntryPoint ) Class . forName ( entryPoint , false , classLoaderResolver . resolve ( asCoordinate ( groupId , artifactId , version , packaging ) ) ) . getDeclaredConstructor ( ) . newInstance ( ) ; } catch ( Exception exception ) { throw new MojoExecutionException ( "Cannot create entry point: " + entryPoint , exception ) ; } } | Resolves the described entry point . |
33,143 | public Class < ? > defineClass ( String name , byte [ ] binaryRepresentation ) throws ClassNotFoundException { return defineClasses ( Collections . singletonMap ( name , binaryRepresentation ) ) . get ( name ) ; } | Defines a new type to be loaded by this class loader . |
33,144 | public void setup ( ) { proxyInterceptor = MethodDelegation . to ( ByteBuddyProxyInterceptor . class ) ; accessInterceptor = MethodDelegation . to ( ByteBuddyAccessInterceptor . class ) ; prefixInterceptor = MethodDelegation . to ( ByteBuddyPrefixInterceptor . class ) ; baseClassDescription = TypePool . Default . ofSystemLoader ( ) . describe ( baseClass . getName ( ) ) . resolve ( ) ; proxyClassDescription = TypePool . Default . ofSystemLoader ( ) . describe ( ByteBuddyProxyInterceptor . class . getName ( ) ) . resolve ( ) ; accessClassDescription = TypePool . Default . ofSystemLoader ( ) . describe ( ByteBuddyAccessInterceptor . class . getName ( ) ) . resolve ( ) ; prefixClassDescription = TypePool . Default . ofSystemLoader ( ) . describe ( ByteBuddyPrefixInterceptor . class . getName ( ) ) . resolve ( ) ; proxyInterceptorDescription = MethodDelegation . to ( proxyClassDescription ) ; accessInterceptorDescription = MethodDelegation . to ( accessClassDescription ) ; prefixInterceptorDescription = MethodDelegation . to ( prefixClassDescription ) ; } | A setup method to create precomputed delegator . |
33,145 | public ExampleClass benchmarkByteBuddyWithProxyAndReusedDelegator ( ) throws Exception { return new ByteBuddy ( ) . with ( TypeValidation . DISABLED ) . ignore ( none ( ) ) . subclass ( baseClass ) . method ( isDeclaredBy ( baseClass ) ) . intercept ( proxyInterceptor ) . make ( ) . load ( newClassLoader ( ) , ClassLoadingStrategy . Default . INJECTION ) . getLoaded ( ) . getDeclaredConstructor ( ) . newInstance ( ) ; } | Performs a benchmark of a class extension using Byte Buddy . This benchmark also uses the annotation - based approach but creates delegation methods which do not require the creation of additional classes . This benchmark reuses a precomputed delegator . |
33,146 | public ExampleClass benchmarkByteBuddyWithAccessorWithTypePool ( ) throws Exception { return ( ExampleClass ) new ByteBuddy ( ) . with ( TypeValidation . DISABLED ) . ignore ( none ( ) ) . subclass ( baseClassDescription ) . method ( isDeclaredBy ( baseClassDescription ) ) . intercept ( MethodDelegation . to ( accessClassDescription ) ) . make ( ) . load ( newClassLoader ( ) , ClassLoadingStrategy . Default . INJECTION ) . getLoaded ( ) . getDeclaredConstructor ( ) . newInstance ( ) ; } | Performs a benchmark of a class extension using Byte Buddy . This benchmark also uses the annotation - based approach but creates delegation methods which do not require the creation of additional classes . This benchmark uses a type pool to compare against usage of the reflection API . |
33,147 | public ExampleClass benchmarkByteBuddyWithAccessorAndReusedDelegatorWithTypePool ( ) throws Exception { return ( ExampleClass ) new ByteBuddy ( ) . with ( TypeValidation . DISABLED ) . ignore ( none ( ) ) . subclass ( baseClassDescription ) . method ( isDeclaredBy ( baseClassDescription ) ) . intercept ( accessInterceptorDescription ) . make ( ) . load ( newClassLoader ( ) , ClassLoadingStrategy . Default . INJECTION ) . getLoaded ( ) . getDeclaredConstructor ( ) . newInstance ( ) ; } | Performs a benchmark of a class extension using Byte Buddy . This benchmark also uses the annotation - based approach but creates delegation methods which do not require the creation of additional classes . This benchmark reuses a precomputed delegator . This benchmark uses a type pool to compare against usage of the reflection API . |
33,148 | public ExampleClass benchmarkCglib ( ) { Enhancer enhancer = new Enhancer ( ) ; enhancer . setUseCache ( false ) ; enhancer . setUseFactory ( false ) ; enhancer . setInterceptDuringConstruction ( true ) ; enhancer . setClassLoader ( newClassLoader ( ) ) ; enhancer . setSuperclass ( baseClass ) ; CallbackHelper callbackHelper = new CallbackHelper ( baseClass , new Class [ 0 ] ) { protected Object getCallback ( Method method ) { if ( method . getDeclaringClass ( ) == baseClass ) { return new MethodInterceptor ( ) { public Object intercept ( Object object , Method method , Object [ ] arguments , MethodProxy methodProxy ) throws Throwable { return methodProxy . invokeSuper ( object , arguments ) ; } } ; } else { return NoOp . INSTANCE ; } } } ; enhancer . setCallbackFilter ( callbackHelper ) ; enhancer . setCallbacks ( callbackHelper . getCallbacks ( ) ) ; return ( ExampleClass ) enhancer . create ( ) ; } | Performs a benchmark of a class extension using cglib . |
33,149 | public ExampleClass benchmarkJavassist ( ) throws Exception { ProxyFactory proxyFactory = new ProxyFactory ( ) { protected ClassLoader getClassLoader ( ) { return newClassLoader ( ) ; } } ; proxyFactory . setUseCache ( false ) ; proxyFactory . setUseWriteReplace ( false ) ; proxyFactory . setSuperclass ( baseClass ) ; proxyFactory . setFilter ( new MethodFilter ( ) { public boolean isHandled ( Method method ) { return method . getDeclaringClass ( ) == baseClass ; } } ) ; @ SuppressWarnings ( "unchecked" ) Object instance = proxyFactory . createClass ( ) . getDeclaredConstructor ( ) . newInstance ( ) ; ( ( javassist . util . proxy . Proxy ) instance ) . setHandler ( new MethodHandler ( ) { public Object invoke ( Object self , Method thisMethod , Method proceed , Object [ ] args ) throws Throwable { return proceed . invoke ( self , args ) ; } } ) ; return ( ExampleClass ) instance ; } | Performs a benchmark of a class extension using javassist proxies . |
33,150 | public < T > DynamicType . Builder < T > rebase ( TypeDescription type , ClassFileLocator classFileLocator , MethodNameTransformer methodNameTransformer ) { if ( type . isArray ( ) || type . isPrimitive ( ) ) { throw new IllegalArgumentException ( "Cannot rebase array or primitive type: " + type ) ; } return new RebaseDynamicTypeBuilder < T > ( instrumentedTypeFactory . represent ( type ) , classFileVersion , auxiliaryTypeNamingStrategy , annotationValueFilterFactory , annotationRetention , implementationContextFactory , methodGraphCompiler , typeValidation , visibilityBridgeStrategy , classWriterStrategy , ignoredMethods , type , classFileLocator , methodNameTransformer ) ; } | Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the rebased type s class such that the class s original can be invoked from the new method implementations . Rebasing a type can be seen similarly to creating a subclass where the subclass is later merged with the original class file . |
33,151 | protected static Implementation . Target of ( TypeDescription instrumentedType , MethodGraph . Linked methodGraph , ClassFileVersion classFileVersion , MethodRebaseResolver methodRebaseResolver ) { return new RebaseImplementationTarget ( instrumentedType , methodGraph , DefaultMethodInvocation . of ( classFileVersion ) , methodRebaseResolver . asTokenMap ( ) ) ; } | Creates a new rebase implementation target . |
33,152 | private Implementation . SpecialMethodInvocation invokeSuper ( MethodGraph . Node node ) { return node . getSort ( ) . isResolved ( ) ? Implementation . SpecialMethodInvocation . Simple . of ( node . getRepresentative ( ) , instrumentedType . getSuperClass ( ) . asErasure ( ) ) : Implementation . SpecialMethodInvocation . Illegal . INSTANCE ; } | Creates a special method invocation for the given node . |
33,153 | private Implementation . SpecialMethodInvocation invokeSuper ( MethodRebaseResolver . Resolution resolution ) { return resolution . isRebased ( ) ? RebasedMethodInvocation . of ( resolution . getResolvedMethod ( ) , instrumentedType , resolution . getAdditionalArguments ( ) ) : Implementation . SpecialMethodInvocation . Simple . of ( resolution . getResolvedMethod ( ) , instrumentedType ) ; } | Creates a special method invocation for the given rebase resolution . |
33,154 | @ SuppressWarnings ( "all" ) public static boolean register ( ClassFileTransformer classFileTransformer , Object classFileFactory ) { try { TypeDescription typeDescription = TypeDescription . ForLoadedType . of ( LambdaFactory . class ) ; Class < ? > lambdaFactory = ClassInjector . UsingReflection . ofSystemClassLoader ( ) . inject ( Collections . singletonMap ( typeDescription , ClassFileLocator . ForClassLoader . read ( LambdaFactory . class ) ) ) . get ( typeDescription ) ; @ SuppressWarnings ( "unchecked" ) Map < ClassFileTransformer , Object > classFileTransformers = ( Map < ClassFileTransformer , Object > ) lambdaFactory . getField ( FIELD_NAME ) . get ( null ) ; synchronized ( classFileTransformers ) { try { return classFileTransformers . isEmpty ( ) ; } finally { classFileTransformers . put ( classFileTransformer , lambdaFactory . getConstructor ( Object . class , Method . class ) . newInstance ( classFileFactory , classFileFactory . getClass ( ) . getMethod ( "make" , Object . class , String . class , Object . class , Object . class , Object . class , Object . class , boolean . class , List . class , List . class , Collection . class ) ) ) ; } } } catch ( RuntimeException exception ) { throw exception ; } catch ( Exception exception ) { throw new IllegalStateException ( "Could not register class file transformer" , exception ) ; } } | Registers a class file transformer together with a factory for creating a lambda expression . It is possible to call this method independently of the class loader s context as the supplied injector makes sure that the manipulated collection is the one that is held by the system class loader . |
33,155 | @ SuppressWarnings ( "all" ) public static boolean release ( ClassFileTransformer classFileTransformer ) { try { @ SuppressWarnings ( "unchecked" ) Map < ClassFileTransformer , ? > classFileTransformers = ( Map < ClassFileTransformer , ? > ) ClassLoader . getSystemClassLoader ( ) . loadClass ( LambdaFactory . class . getName ( ) ) . getField ( FIELD_NAME ) . get ( null ) ; synchronized ( classFileTransformers ) { return classFileTransformers . remove ( classFileTransformer ) != null && classFileTransformers . isEmpty ( ) ; } } catch ( RuntimeException exception ) { throw exception ; } catch ( Exception exception ) { throw new IllegalStateException ( "Could not release class file transformer" , exception ) ; } } | Releases a class file transformer . |
33,156 | private byte [ ] invoke ( Object caller , String invokedName , Object invokedType , Object samMethodType , Object implMethod , Object instantiatedMethodType , boolean serializable , List < Class < ? > > markerInterfaces , List < ? > additionalBridges , Collection < ClassFileTransformer > classFileTransformers ) { try { return ( byte [ ] ) dispatcher . invoke ( target , caller , invokedName , invokedType , samMethodType , implMethod , instantiatedMethodType , serializable , markerInterfaces , additionalBridges , classFileTransformers ) ; } catch ( RuntimeException exception ) { throw exception ; } catch ( Exception exception ) { throw new IllegalStateException ( "Cannot create class for lambda expression" , exception ) ; } } | Applies this lambda meta factory . |
33,157 | public static byte [ ] make ( Object caller , String invokedName , Object invokedType , Object samMethodType , Object implMethod , Object instantiatedMethodType , boolean serializable , List < Class < ? > > markerInterfaces , List < ? > additionalBridges ) { return CLASS_FILE_TRANSFORMERS . values ( ) . iterator ( ) . next ( ) . invoke ( caller , invokedName , invokedType , samMethodType , implMethod , instantiatedMethodType , serializable , markerInterfaces , additionalBridges , CLASS_FILE_TRANSFORMERS . keySet ( ) ) ; } | Dispatches the creation of a new class representing a class file . |
33,158 | public ModifierAdjustment withMethodModifiers ( ElementMatcher < ? super MethodDescription > matcher , List < ? extends ModifierContributor . ForMethod > modifierContributors ) { return withInvokableModifiers ( isMethod ( ) . and ( matcher ) , modifierContributors ) ; } | Adjusts a method s modifiers if it fulfills the supplied matcher . |
33,159 | public ModifierAdjustment withInvokableModifiers ( ElementMatcher < ? super MethodDescription > matcher , List < ? extends ModifierContributor . ForMethod > modifierContributors ) { return new ModifierAdjustment ( typeAdjustments , fieldAdjustments , CompoundList . of ( new Adjustment < MethodDescription > ( matcher , ModifierContributor . Resolver . of ( modifierContributors ) ) , methodAdjustments ) ) ; } | Adjusts a method s or constructor s modifiers if it fulfills the supplied matcher . |
33,160 | public ClassLoader resolve ( MavenCoordinate mavenCoordinate ) throws MojoFailureException , MojoExecutionException { ClassLoader classLoader = classLoaders . get ( mavenCoordinate ) ; if ( classLoader == null ) { classLoader = doResolve ( mavenCoordinate ) ; classLoaders . put ( mavenCoordinate , classLoader ) ; } return classLoader ; } | Resolves a Maven coordinate to a class loader that can load all of the coordinates classes . If a Maven coordinate was resolved previously the previously created class loader is returned . |
33,161 | private ClassLoader doResolve ( MavenCoordinate mavenCoordinate ) throws MojoExecutionException , MojoFailureException { List < URL > urls = new ArrayList < URL > ( ) ; log . info ( "Resolving transformer dependency: " + mavenCoordinate ) ; try { DependencyNode root = repositorySystem . collectDependencies ( repositorySystemSession , new CollectRequest ( new Dependency ( mavenCoordinate . asArtifact ( ) , "runtime" ) , remoteRepositories ) ) . getRoot ( ) ; repositorySystem . resolveDependencies ( repositorySystemSession , new DependencyRequest ( ) . setRoot ( root ) ) ; PreorderNodeListGenerator preorderNodeListGenerator = new PreorderNodeListGenerator ( ) ; root . accept ( preorderNodeListGenerator ) ; for ( Artifact artifact : preorderNodeListGenerator . getArtifacts ( false ) ) { urls . add ( artifact . getFile ( ) . toURI ( ) . toURL ( ) ) ; } } catch ( DependencyCollectionException exception ) { throw new MojoExecutionException ( "Could not collect dependencies for " + mavenCoordinate , exception ) ; } catch ( DependencyResolutionException exception ) { throw new MojoExecutionException ( "Could not resolve dependencies for " + mavenCoordinate , exception ) ; } catch ( MalformedURLException exception ) { throw new MojoFailureException ( "Could not resolve file as URL for " + mavenCoordinate , exception ) ; } return new URLClassLoader ( urls . toArray ( new URL [ 0 ] ) , ByteBuddy . class . getClassLoader ( ) ) ; } | Resolves a Maven coordinate to a class loader that can load all of the coordinates classes . |
33,162 | public static Map < TypeDescription , Class < ? > > load ( ClassLoader classLoader , Map < TypeDescription , byte [ ] > types ) { return load ( classLoader , types , ClassLoadingStrategy . NO_PROTECTION_DOMAIN , PersistenceHandler . LATENT , PackageDefinitionStrategy . Trivial . INSTANCE , false , true ) ; } | Loads a given set of class descriptions and their binary representations . |
33,163 | @ SuppressFBWarnings ( value = "DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED" , justification = "Privilege is explicit user responsibility" ) public static Map < TypeDescription , Class < ? > > load ( ClassLoader classLoader , Map < TypeDescription , byte [ ] > types , ProtectionDomain protectionDomain , PersistenceHandler persistenceHandler , PackageDefinitionStrategy packageDefinitionStrategy , boolean forbidExisting , boolean sealed ) { Map < String , byte [ ] > typesByName = new HashMap < String , byte [ ] > ( ) ; for ( Map . Entry < TypeDescription , byte [ ] > entry : types . entrySet ( ) ) { typesByName . put ( entry . getKey ( ) . getName ( ) , entry . getValue ( ) ) ; } classLoader = new ChildFirst ( classLoader , sealed , typesByName , protectionDomain , persistenceHandler , packageDefinitionStrategy , NoOpClassFileTransformer . INSTANCE ) ; Map < TypeDescription , Class < ? > > result = new LinkedHashMap < TypeDescription , Class < ? > > ( ) ; for ( TypeDescription typeDescription : types . keySet ( ) ) { try { Class < ? > type = Class . forName ( typeDescription . getName ( ) , false , classLoader ) ; if ( forbidExisting && type . getClassLoader ( ) != classLoader ) { throw new IllegalStateException ( "Class already loaded: " + type ) ; } result . put ( typeDescription , type ) ; } catch ( ClassNotFoundException exception ) { throw new IllegalStateException ( "Cannot load class " + typeDescription , exception ) ; } } return result ; } | Loads a given set of class descriptions and their binary representations using a child - first class loader . |
33,164 | private boolean isShadowed ( String resourceName ) { if ( persistenceHandler . isManifest ( ) || ! resourceName . endsWith ( CLASS_FILE_SUFFIX ) ) { return false ; } synchronized ( this ) { String typeName = resourceName . replace ( '/' , '.' ) . substring ( 0 , resourceName . length ( ) - CLASS_FILE_SUFFIX . length ( ) ) ; if ( typeDefinitions . containsKey ( typeName ) ) { return true ; } Class < ? > loadedClass = findLoadedClass ( typeName ) ; return loadedClass != null && loadedClass . getClassLoader ( ) == this ; } } | Checks if a resource name represents a class file of a class that was loaded by this class loader . |
33,165 | public static MethodDelegation toMethodReturnOf ( String name , MethodGraph . Compiler methodGraphCompiler ) { return withDefaultConfiguration ( ) . toMethodReturnOf ( name , methodGraphCompiler ) ; } | Delegates any intercepted method to invoke a method on an instance that is returned by a parameterless method of the given name . To be considered a valid delegation target a method must be visible and accessible to the instrumented type . This is the case if the method s declaring type is either public or in the same package as the instrumented type and if the method is either public or non - private and in the same package as the instrumented type . Private methods can only be used as a delegation target if the delegation is targeting the instrumented type . |
33,166 | public Implementation . Composable withAssigner ( Assigner assigner ) { return new MethodDelegation ( implementationDelegate , parameterBinders , ambiguityResolver , terminationHandler , bindingResolver , assigner ) ; } | Applies an assigner to the method delegation that is used for assigning method return and parameter types . |
33,167 | public static void main ( String [ ] args ) throws RunnerException { new Runner ( new OptionsBuilder ( ) . include ( WILDCARD + SuperClassInvocationBenchmark . class . getSimpleName ( ) + WILDCARD ) . include ( WILDCARD + StubInvocationBenchmark . class . getSimpleName ( ) + WILDCARD ) . include ( WILDCARD + ClassByImplementationBenchmark . class . getSimpleName ( ) + WILDCARD ) . include ( WILDCARD + ClassByExtensionBenchmark . class . getSimpleName ( ) + WILDCARD ) . include ( WILDCARD + TrivialClassCreationBenchmark . class . getSimpleName ( ) + WILDCARD ) . forks ( 0 ) . build ( ) ) . run ( ) ; } | Executes the benchmark . |
33,168 | public static Action < AbstractCompile > of ( Project project ) { return new PostCompilationAction ( project , project . getExtensions ( ) . create ( "byteBuddy" , ByteBuddyExtension . class , project ) ) ; } | Creates a post compilation action . |
33,169 | private ClassLoader doResolve ( Set < ? extends File > classPath ) { List < URL > urls = new ArrayList < URL > ( classPath . size ( ) ) ; for ( File file : classPath ) { try { urls . add ( file . toURI ( ) . toURL ( ) ) ; } catch ( MalformedURLException exception ) { throw new GradleException ( "Cannot resolve " + file + " as URL" , exception ) ; } } return new URLClassLoader ( urls . toArray ( new URL [ 0 ] ) , ByteBuddy . class . getClassLoader ( ) ) ; } | Resolves a class path to a class loader . |
33,170 | public static Weighted < Arborescence < Node > > getMaxArborescence ( WeightedGraph graph , Node root ) { return getMaxArborescence ( graph . filterEdges ( not ( DirectedEdge . hasDestination ( root ) ) ) ) ; } | Find an optimal arborescence of the given graph graph rooted in the given node root . |
33,171 | public static Weighted < Arborescence < Node > > getMaxArborescence ( WeightedGraph graph ) { final PartialSolution partialSolution = PartialSolution . initialize ( graph . filterEdges ( not ( DirectedEdge . isAutoCycle ( ) ) ) ) ; final Deque < Node > componentsWithNoInEdges = new ArrayDeque < > ( partialSolution . getNodes ( ) ) ; while ( ! componentsWithNoInEdges . isEmpty ( ) ) { final Node component = componentsWithNoInEdges . poll ( ) ; final Optional < ExclusiveEdge > oMaxInEdge = partialSolution . popBestEdge ( component ) ; if ( ! oMaxInEdge . isPresent ( ) ) continue ; final ExclusiveEdge maxInEdge = oMaxInEdge . get ( ) ; final Optional < Node > newComponent = partialSolution . addEdge ( maxInEdge ) ; if ( newComponent . isPresent ( ) ) { componentsWithNoInEdges . add ( newComponent . get ( ) ) ; } } return partialSolution . recoverBestArborescence ( ) ; } | Find an optimal arborescence of the given graph . |
33,172 | public static < DESERIALISED > Serialiser < DESERIALISED , ? > of ( AttributeType . DataType < DESERIALISED > dataType ) { Serialiser < ? , ? > serialiser = serialisers . get ( dataType ) ; if ( serialiser == null ) { throw new UnsupportedOperationException ( "Unsupported DataType: " + dataType . toString ( ) ) ; } return ( Serialiser < DESERIALISED , ? > ) serialiser ; } | accessed via the constant properties defined above . |
33,173 | private AttributeAtom rewriteWithRelationVariable ( Atom parentAtom ) { if ( parentAtom . isResource ( ) && ( ( AttributeAtom ) parentAtom ) . getRelationVariable ( ) . isReturned ( ) ) return rewriteWithRelationVariable ( ) ; return this ; } | rewrites the atom to one with relation variable |
33,174 | Set < List < Fragment > > allFragmentOrders ( ) { Collection < List < EquivalentFragmentSet > > fragmentSetPermutations = Collections2 . permutations ( equivalentFragmentSets ) ; return fragmentSetPermutations . stream ( ) . flatMap ( ConjunctionQuery :: cartesianProduct ) . collect ( toSet ( ) ) ; } | Get all possible orderings of fragments |
33,175 | private static double branchWeight ( Node node , Arborescence < Node > arborescence , Map < Node , Set < Node > > edgesParentToChild , Map < Node , Map < Node , Fragment > > edgeFragmentChildToParent ) { Double nodeWeight = node . getNodeWeight ( ) ; if ( nodeWeight == null ) { nodeWeight = getEdgeFragmentCost ( node , arborescence , edgeFragmentChildToParent ) + nodeFragmentWeight ( node ) ; node . setNodeWeight ( nodeWeight ) ; } Double branchWeight = node . getBranchWeight ( ) ; if ( branchWeight == null ) { final double [ ] weight = { nodeWeight } ; if ( edgesParentToChild . containsKey ( node ) ) { edgesParentToChild . get ( node ) . forEach ( child -> weight [ 0 ] += branchWeight ( child , arborescence , edgesParentToChild , edgeFragmentChildToParent ) ) ; } branchWeight = weight [ 0 ] ; node . setBranchWeight ( branchWeight ) ; } return branchWeight ; } | recursively compute the weight of a branch |
33,176 | private static double nodeFragmentWeight ( Node node ) { double costFragmentsWithoutDependency = node . getFragmentsWithoutDependency ( ) . stream ( ) . mapToDouble ( Fragment :: fragmentCost ) . sum ( ) ; double costFragmentsWithDependencyVisited = node . getFragmentsWithDependencyVisited ( ) . stream ( ) . mapToDouble ( Fragment :: fragmentCost ) . sum ( ) ; double costFragmentsWithDependency = node . getFragmentsWithDependency ( ) . stream ( ) . mapToDouble ( Fragment :: fragmentCost ) . sum ( ) ; return costFragmentsWithoutDependency + node . getFixedFragmentCost ( ) + ( costFragmentsWithDependencyVisited + costFragmentsWithDependency ) / 2D ; } | compute the total cost of a node |
33,177 | private static double getEdgeFragmentCost ( Node node , Arborescence < Node > arborescence , Map < Node , Map < Node , Fragment > > edgeToFragment ) { Fragment fragment = getEdgeFragment ( node , arborescence , edgeToFragment ) ; if ( fragment != null ) return fragment . fragmentCost ( ) ; return 0D ; } | get edge fragment cost in order to map branch cost |
33,178 | public boolean add ( ConceptMap answer , ConceptMap answerIndex ) { Index ind = Index . of ( answerIndex . vars ( ) ) ; if ( ind . equals ( index ) ) { return indexedAnswers . put ( answerIndex , answer ) ; } throw new IllegalStateException ( "Illegal index: " + answerIndex + " indices: " + index ) ; } | add answer with specific index |
33,179 | public Map < Variable , ConceptId > idTransform ( ReasonerQueryImpl query , Unifier unifier ) { Map < Variable , ConceptId > transform = new HashMap < > ( ) ; this . getAtoms ( IdPredicate . class ) . forEach ( thisP -> { Collection < Variable > vars = unifier . get ( thisP . getVarName ( ) ) ; Variable var = ! vars . isEmpty ( ) ? Iterators . getOnlyElement ( vars . iterator ( ) ) : thisP . getVarName ( ) ; IdPredicate p2 = query . getIdPredicate ( var ) ; if ( p2 != null ) transform . put ( thisP . getVarName ( ) , p2 . getPredicate ( ) ) ; } ) ; return transform ; } | returns id transform that would convert this query to a query alpha - equivalent to the query provided they are structurally equivalent |
33,180 | public ConceptMap getSubstitution ( ) { if ( substitution == null ) { Set < Variable > varNames = getVarNames ( ) ; Set < IdPredicate > predicates = getAtoms ( IsaAtomBase . class ) . map ( IsaAtomBase :: getTypePredicate ) . filter ( Objects :: nonNull ) . filter ( p -> varNames . contains ( p . getVarName ( ) ) ) . collect ( Collectors . toSet ( ) ) ; getAtoms ( IdPredicate . class ) . forEach ( predicates :: add ) ; HashMap < Variable , Concept > answerMap = new HashMap < > ( ) ; predicates . forEach ( p -> { Concept concept = tx ( ) . getConcept ( p . getPredicate ( ) ) ; if ( concept == null ) throw GraqlCheckedException . idNotFound ( p . getPredicate ( ) ) ; answerMap . put ( p . getVarName ( ) , concept ) ; } ) ; substitution = new ConceptMap ( answerMap ) ; } return substitution ; } | Does id predicates - > answer conversion |
33,181 | public Stream < Casting > castingsRelation ( Role ... roles ) { Set < Role > roleSet = new HashSet < > ( Arrays . asList ( roles ) ) ; if ( roleSet . isEmpty ( ) ) { return vertex ( ) . getEdgesOfType ( Direction . OUT , Schema . EdgeLabel . ROLE_PLAYER ) . map ( edge -> Casting . withRelation ( edge , owner ) ) ; } Set < Integer > roleTypesIds = roleSet . stream ( ) . map ( r -> r . labelId ( ) . getValue ( ) ) . collect ( Collectors . toSet ( ) ) ; return vertex ( ) . tx ( ) . getTinkerTraversal ( ) . V ( ) . hasId ( elementId ( ) ) . outE ( Schema . EdgeLabel . ROLE_PLAYER . getLabel ( ) ) . has ( Schema . EdgeProperty . RELATION_TYPE_LABEL_ID . name ( ) , type ( ) . labelId ( ) . getValue ( ) ) . has ( Schema . EdgeProperty . ROLE_LABEL_ID . name ( ) , P . within ( roleTypesIds ) ) . toStream ( ) . map ( edge -> vertex ( ) . tx ( ) . factory ( ) . buildEdgeElement ( edge ) ) . map ( edge -> Casting . withRelation ( edge , owner ) ) ; } | Castings are retrieved from the perspective of the Relation |
33,182 | public Explanation childOf ( ConceptMap ans ) { return new Explanation ( getPattern ( ) , ans . explanation ( ) . getAnswers ( ) ) ; } | produce a new explanation with a provided parent answer |
33,183 | private void validate ( Concept concept ) { validateParam ( concept , TYPE , Thing . class , Thing :: type ) ; validateParam ( concept , SUPER_CONCEPT , SchemaConcept . class , SchemaConcept :: sup ) ; validateParam ( concept , LABEL , SchemaConcept . class , SchemaConcept :: label ) ; validateParam ( concept , ID , Concept . class , Concept :: id ) ; validateParam ( concept , VALUE , Attribute . class , Attribute :: value ) ; validateParam ( concept , DATA_TYPE , AttributeType . class , AttributeType :: dataType ) ; validateParam ( concept , WHEN , Rule . class , Rule :: when ) ; validateParam ( concept , THEN , Rule . class , Rule :: then ) ; } | Check if this pre - existing concept conforms to all specified parameters |
33,184 | private < S extends Concept , T > void validateParam ( Concept concept , BuilderParam < T > param , Class < S > conceptType , Function < S , T > getter ) { if ( has ( param ) ) { T value = use ( param ) ; boolean isInstance = conceptType . isInstance ( concept ) ; if ( ! isInstance || ! Objects . equals ( getter . apply ( conceptType . cast ( concept ) ) , value ) ) { throw GraqlQueryException . insertPropertyOnExistingConcept ( param . name ( ) , value , concept ) ; } } } | Check if the concept is of the given type and has a property that matches the given parameter . |
33,185 | public static void setSuper ( SchemaConcept subConcept , SchemaConcept superConcept ) { if ( superConcept . isEntityType ( ) ) { subConcept . asEntityType ( ) . sup ( superConcept . asEntityType ( ) ) ; } else if ( superConcept . isRelationType ( ) ) { subConcept . asRelationType ( ) . sup ( superConcept . asRelationType ( ) ) ; } else if ( superConcept . isRole ( ) ) { subConcept . asRole ( ) . sup ( superConcept . asRole ( ) ) ; } else if ( superConcept . isAttributeType ( ) ) { subConcept . asAttributeType ( ) . sup ( superConcept . asAttributeType ( ) ) ; } else if ( superConcept . isRule ( ) ) { subConcept . asRule ( ) . sup ( superConcept . asRule ( ) ) ; } else { throw InvalidKBException . insertMetaType ( subConcept . label ( ) , superConcept ) ; } } | Make the second argument the super of the first argument |
33,186 | public void markForDeduplication ( KeyspaceImpl keyspace , String index , ConceptId conceptId ) { Attribute attribute = Attribute . create ( keyspace , index , conceptId ) ; LOG . trace ( "insert({})" , attribute ) ; queue . insert ( attribute ) ; } | Marks an attribute for deduplication . The attribute will be inserted to an internal queue to be processed by the de - duplicator daemon in real - time . The attribute must have been inserted to the database prior to calling this method . |
33,187 | public static < T > Partition < T > singletons ( Collection < T > nodes ) { final Map < T , T > parents = Maps . newHashMap ( ) ; final Map < T , Integer > ranks = Maps . newHashMap ( ) ; for ( T node : nodes ) { parents . put ( node , node ) ; ranks . put ( node , 0 ) ; } return new Partition < T > ( parents , ranks ) ; } | Constructs a new partition of singletons |
33,188 | public V componentOf ( V i ) { final V parent = parents . getOrDefault ( i , i ) ; if ( parent . equals ( i ) ) { return i ; } else { parents . put ( i , componentOf ( parent ) ) ; } return parents . get ( i ) ; } | Find the representative for the given item |
33,189 | public V merge ( V a , V b ) { final V aHead = componentOf ( a ) ; final V bHead = componentOf ( b ) ; if ( aHead . equals ( bHead ) ) return aHead ; final int aRank = ranks . getOrDefault ( aHead , 0 ) ; final int bRank = ranks . getOrDefault ( bHead , 0 ) ; if ( aRank > bRank ) { parents . put ( bHead , aHead ) ; return aHead ; } else if ( bRank > aRank ) { parents . put ( aHead , bHead ) ; return bHead ; } else { parents . put ( bHead , aHead ) ; ranks . put ( aHead , aRank + 1 ) ; return aHead ; } } | Merges the given components and returns the representative of the new component |
33,190 | public boolean sameComponent ( V a , V b ) { return componentOf ( a ) . equals ( componentOf ( b ) ) ; } | Determines whether the two items are in the same component or not |
33,191 | private void validateRelationType ( RelationType relationType ) { ValidateGlobalRules . validateHasMinimumRoles ( relationType ) . ifPresent ( errorsFound :: add ) ; errorsFound . addAll ( ValidateGlobalRules . validateRelationTypesToRolesSchema ( relationType ) ) ; } | Validation rules exclusive to relation types |
33,192 | public void link ( ConceptImpl concept ) { concept . vertex ( ) . addEdge ( vertex ( ) , Schema . EdgeLabel . ISA ) ; } | Links a new concept to this shard . |
33,193 | static boolean isAlive ( Vertex vertex ) { if ( vertex == null ) return false ; try { return Sets . newHashSet ( Schema . BaseType . values ( ) ) . contains ( Schema . BaseType . valueOf ( vertex . label ( ) ) ) ; } catch ( IllegalStateException e ) { return false ; } } | The state of the vertex in the database . This may detect ghost nodes and allow them to be excluded from computations . If the vertex is alive it is likely to be a valid Grakn concept . |
33,194 | static < T > Set < T > reduceSet ( Iterator < Set < T > > values ) { Set < T > set = new HashSet < > ( ) ; while ( values . hasNext ( ) ) { set . addAll ( values . next ( ) ) ; } return set ; } | A helper method for set MapReduce . It simply combines sets into one set . |
33,195 | static < K , V > Map < K , V > keyValuesToMap ( Iterator < KeyValue < K , V > > keyValues ) { Map < K , V > map = new HashMap < > ( ) ; keyValues . forEachRemaining ( pair -> map . put ( pair . getKey ( ) , pair . getValue ( ) ) ) ; return map ; } | Transforms an iterator of key - value pairs into a map |
33,196 | private static boolean mayHaveResourceEdge ( TransactionOLTP graknGraph , ConceptId conceptId1 , ConceptId conceptId2 ) { Concept concept1 = graknGraph . getConcept ( conceptId1 ) ; Concept concept2 = graknGraph . getConcept ( conceptId2 ) ; return concept1 != null && concept2 != null && ( concept1 . isAttribute ( ) || concept2 . isAttribute ( ) ) ; } | Check whether it is possible that there is a resource edge between the two given concepts . |
33,197 | public static ConceptId getResourceEdgeId ( TransactionOLTP graph , ConceptId conceptId1 , ConceptId conceptId2 ) { if ( mayHaveResourceEdge ( graph , conceptId1 , conceptId2 ) ) { Optional < Concept > firstConcept = graph . stream ( Graql . match ( var ( "x" ) . id ( conceptId1 . getValue ( ) ) , var ( "y" ) . id ( conceptId2 . getValue ( ) ) , var ( "z" ) . rel ( var ( "x" ) ) . rel ( var ( "y" ) ) ) . get ( "z" ) ) . map ( answer -> answer . get ( "z" ) ) . findFirst ( ) ; if ( firstConcept . isPresent ( ) ) { return firstConcept . get ( ) . id ( ) ; } } return null ; } | Get the resource edge id if there is one . Return null if not . |
33,198 | public static Server createServer ( boolean benchmark ) { ServerID serverID = ServerID . me ( ) ; Config config = Config . create ( ) ; JanusGraphFactory janusGraphFactory = new JanusGraphFactory ( config ) ; LockManager lockManager = new ServerLockManager ( ) ; KeyspaceManager keyspaceStore = new KeyspaceManager ( janusGraphFactory , config ) ; SessionFactory sessionFactory = new SessionFactory ( lockManager , janusGraphFactory , keyspaceStore , config ) ; AttributeDeduplicatorDaemon attributeDeduplicatorDaemon = new AttributeDeduplicatorDaemon ( sessionFactory ) ; if ( benchmark ) { ServerTracing . initInstrumentation ( "server-instrumentation" ) ; } io . grpc . Server serverRPC = createServerRPC ( config , sessionFactory , attributeDeduplicatorDaemon , keyspaceStore , janusGraphFactory ) ; return createServer ( serverID , serverRPC , lockManager , attributeDeduplicatorDaemon , keyspaceStore ) ; } | Create a Server configured for Grakn Core . |
33,199 | public static Server createServer ( ServerID serverID , io . grpc . Server rpcServer , LockManager lockManager , AttributeDeduplicatorDaemon attributeDeduplicatorDaemon , KeyspaceManager keyspaceStore ) { Server server = new Server ( serverID , lockManager , rpcServer , attributeDeduplicatorDaemon , keyspaceStore ) ; Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( server :: close , "grakn-server-shutdown" ) ) ; return server ; } | Allows the creation of a Server instance with various configurations |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.