public static <T> Class<? extends T> defineClass(ClassDefinition classDefinition, Class<T> superType, Map<Long, MethodHandle> callSiteBindings, ClassLoader parentClassLoader) { return defineClass(classDefinition, superType, new DynamicClassLoader(parentClassLoader, callSiteBindings)); }
public static <T> Class<? extends T> isolateClass( DynamicClassLoader dynamicClassLoader, Class<T> publicBaseClass, Class<? extends T> implementationClass, Class<?>... additionalClasses) { ImmutableMap.Builder<String, byte[]> builder = ImmutableMap.builder(); builder.put(implementationClass.getName(), getBytecode(implementationClass)); for (Class<?> additionalClass : additionalClasses) { builder.put(additionalClass.getName(), getBytecode(additionalClass)); } // load classes into a private class loader Map<String, Class<?>> isolatedClasses = dynamicClassLoader.defineClasses(builder.build()); Class<?> isolatedClass = isolatedClasses.get(implementationClass.getName()); // verify the isolated class checkArgument(isolatedClass != null, "Could load class %s", implementationClass.getName()); checkArgument(publicBaseClass.isAssignableFrom(isolatedClass), "Error isolating class %s, newly loaded class is not a sub type of %s", implementationClass.getName(), publicBaseClass.getName()); checkState(isolatedClass != implementationClass, "Isolation failed"); return isolatedClass.asSubclass(publicBaseClass); }
public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, long bindingId) { ClassLoader classLoader = callerLookup.lookupClass().getClassLoader(); checkArgument(classLoader instanceof DynamicClassLoader, "Expected %s's classloader to be of type %s", callerLookup.lookupClass().getName(), DynamicClassLoader.class.getName()); DynamicClassLoader dynamicClassLoader = (DynamicClassLoader) classLoader; MethodHandle target = dynamicClassLoader.getCallSiteBindings().get(bindingId); checkArgument(target != null, "Binding %s for function %s%s not found", bindingId, name, type.parameterList()); return new ConstantCallSite(target); } }
@Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { // grab the magic lock synchronized (getClassLoadingLock(name)) { // Check if class is in the loaded classes cache Class<?> cachedClass = findLoadedClass(name); if (cachedClass != null) { return resolveClass(cachedClass, resolve); } try { Class<?> clazz = findClass(name); return resolveClass(clazz, resolve); } catch (ClassNotFoundException ignored) { // not a local class } if (overrideClassLoader.isPresent()) { try { return resolveClass(overrideClassLoader.get().loadClass(name), resolve); } catch (ClassNotFoundException e) { // not in override loader } } Class<?> clazz = getParent().loadClass(name); return resolveClass(clazz, resolve); } }
public Class<?> defineClass(String className, byte[] bytecode) { return defineClass(className, bytecode, 0, bytecode.length); }
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] bytecode = pendingClasses.get(name); if (bytecode == null) { throw new ClassNotFoundException(name); } return defineClass(name, bytecode); }
public static <T> AccumulatorStateFactory<T> generateStateFactory(Class<T> clazz) { return generateStateFactory(clazz, new DynamicClassLoader(clazz.getClassLoader())); }
public static <T> Class<? extends T> isolateClass( DynamicClassLoader dynamicClassLoader, Class<T> publicBaseClass, Class<? extends T> implementationClass, Class<?>... additionalClasses) { ImmutableMap.Builder<String, byte[]> builder = ImmutableMap.builder(); builder.put(implementationClass.getName(), getBytecode(implementationClass)); for (Class<?> additionalClass : additionalClasses) { builder.put(additionalClass.getName(), getBytecode(additionalClass)); } // load classes into a private class loader Map<String, Class<?>> isolatedClasses = dynamicClassLoader.defineClasses(builder.build()); Class<?> isolatedClass = isolatedClasses.get(implementationClass.getName()); // verify the isolated class checkArgument(isolatedClass != null, "Could load class %s", implementationClass.getName()); checkArgument(publicBaseClass.isAssignableFrom(isolatedClass), "Error isolating class %s, newly loaded class is not a sub type of %s", implementationClass.getName(), publicBaseClass.getName()); checkState(isolatedClass != implementationClass, "Isolation failed"); return isolatedClass.asSubclass(publicBaseClass); }
public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, long bindingId) { ClassLoader classLoader = callerLookup.lookupClass().getClassLoader(); checkArgument(classLoader instanceof DynamicClassLoader, "Expected %s's classloader to be of type %s", callerLookup.lookupClass().getName(), DynamicClassLoader.class.getName()); DynamicClassLoader dynamicClassLoader = (DynamicClassLoader) classLoader; MethodHandle target = dynamicClassLoader.getCallSiteBindings().get(bindingId); checkArgument(target != null, "Binding %s for function %s%s not found", bindingId, name, type.parameterList()); return new ConstantCallSite(target); } }
public static <T> AccumulatorStateSerializer<T> generateStateSerializer(Class<T> clazz) { return generateStateSerializer(clazz, new DynamicClassLoader(clazz.getClassLoader())); }
public static <T> Class<? extends T> isolateClass( DynamicClassLoader dynamicClassLoader, Class<T> publicBaseClass, Class<? extends T> implementationClass, Class<?>... additionalClasses) { ImmutableMap.Builder<String, byte[]> builder = ImmutableMap.builder(); builder.put(implementationClass.getName(), getBytecode(implementationClass)); for (Class<?> additionalClass : additionalClasses) { builder.put(additionalClass.getName(), getBytecode(additionalClass)); } // load classes into a private class loader Map<String, Class<?>> isolatedClasses = dynamicClassLoader.defineClasses(builder.build()); Class<?> isolatedClass = isolatedClasses.get(implementationClass.getName()); // verify the isolated class checkArgument(isolatedClass != null, "Could load class %s", implementationClass.getName()); checkArgument(publicBaseClass.isAssignableFrom(isolatedClass), "Error isolating class %s, newly loaded class is not a sub type of %s", implementationClass.getName(), publicBaseClass.getName()); checkState(isolatedClass != implementationClass, "Isolation failed"); return isolatedClass.asSubclass(publicBaseClass); }
public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, long bindingId) { ClassLoader classLoader = callerLookup.lookupClass().getClassLoader(); checkArgument(classLoader instanceof DynamicClassLoader, "Expected %s's classloader to be of type %s", callerLookup.lookupClass().getName(), DynamicClassLoader.class.getName()); DynamicClassLoader dynamicClassLoader = (DynamicClassLoader) classLoader; MethodHandle target = dynamicClassLoader.getCallSiteBindings().get(bindingId); checkArgument(target != null, "Binding %s for function %s%s not found", bindingId, name, type.parameterList()); return new ConstantCallSite(target); } }
public IsolatedJoinFilterFunctionFactory(Class<? extends InternalJoinFilterFunction> internalJoinFilterFunction) { try { internalJoinFilterFunctionConstructor = internalJoinFilterFunction .getConstructor(ConnectorSession.class); Class<? extends JoinFilterFunction> isolatedJoinFilterFunction = IsolatedClass.isolateClass( new DynamicClassLoader(getClass().getClassLoader()), JoinFilterFunction.class, StandardJoinFilterFunction.class); isolatedJoinFilterFunctionConstructor = isolatedJoinFilterFunction.getConstructor(InternalJoinFilterFunction.class, LongArrayList.class, List.class); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } }
Map<String, Class<?>> classes = classLoader.defineClasses(bytecodes);
private LookupSourceSupplierFactory internalCompileLookupSourceFactory(List<Type> types, List<Integer> outputChannels, List<Integer> joinChannels, Optional<Integer> sortChannel) { Class<? extends PagesHashStrategy> pagesHashStrategyClass = internalCompileHashStrategy(types, outputChannels, joinChannels, sortChannel); Class<? extends LookupSourceSupplier> joinHashSupplierClass = IsolatedClass.isolateClass( new DynamicClassLoader(getClass().getClassLoader()), LookupSourceSupplier.class, JoinHashSupplier.class, JoinHash.class, PagesHash.class); return new LookupSourceSupplierFactory(joinHashSupplierClass, new PagesHashStrategyFactory(pagesHashStrategyClass)); }
private static InternalAggregationFunction generateAggregation(Type type) { DynamicClassLoader classLoader = new DynamicClassLoader(ChecksumAggregationFunction.class.getClassLoader()); List<Type> inputTypes = ImmutableList.of(type); AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(type), INPUT_FUNCTION.bindTo(type), COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor( NullableLongState.class, StateCompiler.generateStateSerializer(NullableLongState.class, classLoader), StateCompiler.generateStateFactory(NullableLongState.class, classLoader))), VARBINARY); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(BIGINT), VARBINARY, true, false, factory); }
private static InternalAggregationFunction generateAggregation(Type type) { DynamicClassLoader classLoader = new DynamicClassLoader(CountColumn.class.getClassLoader()); AccumulatorStateSerializer<LongState> stateSerializer = StateCompiler.generateStateSerializer(LongState.class, classLoader); AccumulatorStateFactory<LongState> stateFactory = StateCompiler.generateStateFactory(LongState.class, classLoader); Type intermediateType = stateSerializer.getSerializedType(); List<Type> inputTypes = ImmutableList.of(type); AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, BIGINT.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(type), INPUT_FUNCTION, COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor( LongState.class, stateSerializer, stateFactory)), BIGINT); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), BIGINT, true, false, factory); }
private InternalAggregationFunction generateAggregation(Type keyType, Type valueType, Type outputType) { DynamicClassLoader classLoader = new DynamicClassLoader(MultimapAggregationFunction.class.getClassLoader()); List<Type> inputTypes = ImmutableList.of(keyType, valueType); MultimapAggregationStateSerializer stateSerializer = new MultimapAggregationStateSerializer(keyType, valueType); Type intermediateType = stateSerializer.getSerializedType(); AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(keyType, valueType), INPUT_FUNCTION, COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(keyType).bindTo(valueType), ImmutableList.of(new AccumulatorStateDescriptor( MultimapAggregationState.class, stateSerializer, new MultimapAggregationStateFactory(keyType, valueType, groupMode))), outputType); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, true, factory); }
private static InternalAggregationFunction generateAggregation(Type keyType, Type valueType, MapType outputType) { DynamicClassLoader classLoader = new DynamicClassLoader(MapUnionAggregation.class.getClassLoader()); List<Type> inputTypes = ImmutableList.of(outputType); KeyValuePairStateSerializer stateSerializer = new KeyValuePairStateSerializer(outputType); Type intermediateType = stateSerializer.getSerializedType(); AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(outputType), INPUT_FUNCTION.bindTo(keyType).bindTo(valueType), COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor( KeyValuePairsState.class, stateSerializer, new KeyValuePairsStateFactory(keyType, valueType))), outputType); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, false, factory); }
private static InternalAggregationFunction generateAggregation(Type keyType, Type valueType, MapType outputType) { DynamicClassLoader classLoader = new DynamicClassLoader(MapAggregationFunction.class.getClassLoader()); List<Type> inputTypes = ImmutableList.of(keyType, valueType); KeyValuePairStateSerializer stateSerializer = new KeyValuePairStateSerializer(outputType); Type intermediateType = stateSerializer.getSerializedType(); AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(keyType, valueType), INPUT_FUNCTION.bindTo(keyType).bindTo(valueType), COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor( KeyValuePairsState.class, stateSerializer, new KeyValuePairsStateFactory(keyType, valueType))), outputType); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, true, factory); }