@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) { int field = node.getField(); Type type = node.getType(); Variable wasNullVariable = scope.getVariable("wasNull"); Class<?> javaType = type.getJavaType(); if (!javaType.isPrimitive() && javaType != Slice.class) { javaType = Object.class; } IfStatement ifStatement = new IfStatement(); ifStatement.condition() .setDescription(format("cursor.get%s(%d)", type, field)) .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "isNull", boolean.class, int.class); ifStatement.ifTrue() .putVariable(wasNullVariable, true) .pushJavaDefault(javaType); ifStatement.ifFalse() .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "get" + Primitives.wrap(javaType).getSimpleName(), javaType, int.class); return ifStatement; }
.append(getBlockBytecode) .append(position) .invokeInterface(Type.class, "getLong", long.class, Block.class, int.class); .append(getBlockBytecode) .append(position) .invokeInterface(Type.class, "getDouble", double.class, Block.class, int.class); .append(getBlockBytecode) .append(position) .invokeInterface(Type.class, "getBoolean", boolean.class, Block.class, int.class); .append(getBlockBytecode) .append(position) .invokeInterface(Type.class, "getSlice", Slice.class, Block.class, int.class); .append(getBlockBytecode) .append(position) .invokeInterface(Type.class, "getObject", Object.class, Block.class, int.class);
.pop(valueJavaType) .getVariable(outputBlockVariable) .invokeInterface(BlockBuilder.class, "appendNull", BlockBuilder.class) .pop()) .ifFalse(new BytecodeBlock() .getVariable(outputBlockVariable) .getVariable(tempValue) .invokeInterface(Type.class, methodName, void.class, BlockBuilder.class, valueJavaType)));
body.comment(format("scratchState_%s = stateFactory[%s].createSingleState();", i, i)) .append(thisVariable.getField(stateFactoryField)) .invokeInterface(AccumulatorStateFactory.class, "createSingleState", Object.class) .checkCast(scratchStates.get(i).getType()) .putVariable(scratchStates.get(i));
.append(OpCode.IADD) .invokeVirtual(PageBuilder.class, "getBlockBuilder", BlockBuilder.class, int.class) .invokeInterface(Type.class, "appendTo", void.class, Block.class, int.class, BlockBuilder.class);
.append(thisVariable.getField(inputChannelsField)) .push(i) .invokeInterface(List.class, "get", Object.class, int.class) .checkCast(Integer.class) .invokeVirtual(Integer.class, "intValue", int.class)
.getVariable(variableDefinition) .getVariable(positionVariable) .invokeInterface(Block.class, "isNull", boolean.class, int.class)) .ifFalse(loopBody);
@Inject public EmbedVersion(ServerConfig serverConfig) { ClassDefinition classDefinition = new ClassDefinition( a(PUBLIC, FINAL), makeClassName(baseClassName(serverConfig)), type(Object.class), type(Runnable.class)); FieldDefinition field = classDefinition.declareField(a(PRIVATE), "runnable", Runnable.class); Parameter parameter = arg("runnable", type(Runnable.class)); MethodDefinition constructor = classDefinition.declareConstructor(a(PUBLIC), parameter); constructor.getBody() .comment("super(runnable);") .append(constructor.getThis()) .invokeConstructor(Object.class) .append(constructor.getThis()) .append(parameter) .putField(field) .ret(); MethodDefinition run = classDefinition.declareMethod(a(PUBLIC), "run", type(void.class)); run.getBody() .comment("runnable.run();") .append(run.getThis()) .getField(field) .invokeInterface(Runnable.class, "run", void.class) .ret(); Class<? extends Runnable> generatedClass = defineClass(classDefinition, Runnable.class, ImmutableMap.of(), getClass().getClassLoader()); this.runnableConstructor = constructorMethodHandle(generatedClass, Runnable.class); }
private static BytecodeBlock generateBlockNonNullPositionForLoop(Scope scope, Variable positionVariable, BytecodeBlock loopBody) { Variable rowsVariable = scope.declareVariable(int.class, "rows"); Variable blockVariable = scope.getVariable("block"); BytecodeBlock block = new BytecodeBlock() .append(blockVariable) .invokeInterface(Block.class, "getPositionCount", int.class) .putVariable(rowsVariable); IfStatement ifStatement = new IfStatement("if(!block.isNull(position))") .condition(new BytecodeBlock() .append(blockVariable) .append(positionVariable) .invokeInterface(Block.class, "isNull", boolean.class, int.class)) .ifFalse(loopBody); block.append(new ForLoop() .initialize(positionVariable.set(constantInt(0))) .condition(new BytecodeBlock() .append(positionVariable) .append(rowsVariable) .invokeStatic(CompilerOperations.class, "lessThan", boolean.class, int.class, int.class)) .update(new BytecodeBlock().incrementVariable(positionVariable, (byte) 1)) .body(ifStatement)); return block; }
.append(rowBlock) .push(index) .invokeInterface(Block.class, "isNull", boolean.class, int.class);
@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) { int field = node.getField(); Type type = node.getType(); Variable wasNullVariable = scope.getVariable("wasNull"); Class<?> javaType = type.getJavaType(); if (!javaType.isPrimitive() && javaType != Slice.class) { javaType = Object.class; } IfStatement ifStatement = new IfStatement(); ifStatement.condition() .setDescription(format("cursor.get%s(%d)", type, field)) .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "isNull", boolean.class, int.class); ifStatement.ifTrue() .putVariable(wasNullVariable, true) .pushJavaDefault(javaType); ifStatement.ifFalse() .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "get" + Primitives.wrap(javaType).getSimpleName(), javaType, int.class); return ifStatement; }
@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) { int field = node.getField(); Type type = node.getType(); Variable wasNullVariable = scope.getVariable("wasNull"); Class<?> javaType = type.getJavaType(); if (!javaType.isPrimitive() && javaType != Slice.class) { javaType = Object.class; } IfStatement ifStatement = new IfStatement(); ifStatement.condition() .setDescription(format("cursor.get%s(%d)", type, field)) .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "isNull", boolean.class, int.class); ifStatement.ifTrue() .putVariable(wasNullVariable, true) .pushJavaDefault(javaType); ifStatement.ifFalse() .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "get" + Primitives.wrap(javaType).getSimpleName(), javaType, int.class); return ifStatement; }
@Override public BytecodeNode getBytecode(MethodGenerationContext generationContext) { BytecodeBlock block = new BytecodeBlock(); if (instance != null) { block.append(instance); } for (BytecodeExpression parameter : parameters) { block.append(parameter); } if (instance == null) { return block.invokeStatic(methodTargetType, methodName, returnType, parameterTypes); } else if (instance.getType().isInterface()) { return block.invokeInterface(methodTargetType, methodName, returnType, parameterTypes); } else { return block.invokeVirtual(methodTargetType, methodName, returnType, parameterTypes); } }
.comment("output.appendNull();") .pop(valueJavaType) .invokeInterface(BlockBuilder.class, "appendNull", BlockBuilder.class) .pop()) .ifFalse(new BytecodeBlock() .getVariable(tempOutput) .getVariable(tempValue) .invokeInterface(Type.class, methodName, void.class, BlockBuilder.class, valueJavaType)));
.comment("output.appendNull();") .pop(valueJavaType) .invokeInterface(BlockBuilder.class, "appendNull", BlockBuilder.class) .pop()) .ifFalse(new BytecodeBlock() .getVariable(tempOutput) .getVariable(tempValue) .invokeInterface(Type.class, methodName, void.class, BlockBuilder.class, valueJavaType)));
.append(OpCode.IADD) .invokeVirtual(PageBuilder.class, "getBlockBuilder", BlockBuilder.class, int.class) .invokeInterface(Type.class, "appendTo", void.class, Block.class, int.class, BlockBuilder.class);
@Inject public EmbedVersion(ServerConfig serverConfig) { ClassDefinition classDefinition = new ClassDefinition( a(PUBLIC, FINAL), makeClassName(baseClassName(serverConfig)), type(Object.class), type(Runnable.class)); FieldDefinition field = classDefinition.declareField(a(PRIVATE), "runnable", Runnable.class); Parameter parameter = arg("runnable", type(Runnable.class)); MethodDefinition constructor = classDefinition.declareConstructor(a(PUBLIC), parameter); constructor.getBody() .comment("super(runnable);") .append(constructor.getThis()) .invokeConstructor(Object.class) .append(constructor.getThis()) .append(parameter) .putField(field) .ret(); MethodDefinition run = classDefinition.declareMethod(a(PUBLIC), "run", type(void.class)); run.getBody() .comment("runnable.run();") .append(run.getThis()) .getField(field) .invokeInterface(Runnable.class, "run", void.class) .ret(); Class<? extends Runnable> generatedClass = defineClass(classDefinition, Runnable.class, ImmutableMap.of(), getClass().getClassLoader()); this.runnableConstructor = constructorMethodHandle(generatedClass, Runnable.class); }
private static BytecodeBlock generateBlockNonNullPositionForLoop(Scope scope, Variable positionVariable, BytecodeBlock loopBody) { Variable rowsVariable = scope.declareVariable(int.class, "rows"); Variable blockVariable = scope.getVariable("block"); BytecodeBlock block = new BytecodeBlock() .append(blockVariable) .invokeInterface(Block.class, "getPositionCount", int.class) .putVariable(rowsVariable); IfStatement ifStatement = new IfStatement("if(!block.isNull(position))") .condition(new BytecodeBlock() .append(blockVariable) .append(positionVariable) .invokeInterface(Block.class, "isNull", boolean.class, int.class)) .ifFalse(loopBody); block.append(new ForLoop() .initialize(positionVariable.set(constantInt(0))) .condition(new BytecodeBlock() .append(positionVariable) .append(rowsVariable) .invokeStatic(CompilerOperations.class, "lessThan", boolean.class, int.class, int.class)) .update(new BytecodeBlock().incrementVariable(positionVariable, (byte) 1)) .body(ifStatement)); return block; }
@Inject public EmbedVersion(ServerConfig serverConfig) { ClassDefinition classDefinition = new ClassDefinition( a(PUBLIC, FINAL), makeClassName(baseClassName(serverConfig)), type(Object.class), type(Runnable.class)); FieldDefinition field = classDefinition.declareField(a(PRIVATE), "runnable", Runnable.class); Parameter parameter = arg("runnable", type(Runnable.class)); MethodDefinition constructor = classDefinition.declareConstructor(a(PUBLIC), parameter); constructor.getBody() .comment("super(runnable);") .append(constructor.getThis()) .invokeConstructor(Object.class) .append(constructor.getThis()) .append(parameter) .putField(field) .ret(); MethodDefinition run = classDefinition.declareMethod(a(PUBLIC), "run", type(void.class)); run.getBody() .comment("runnable.run();") .append(run.getThis()) .getField(field) .invokeInterface(Runnable.class, "run", void.class) .ret(); Class<? extends Runnable> generatedClass = defineClass(classDefinition, Runnable.class, ImmutableMap.of(), getClass().getClassLoader()); this.runnableConstructor = constructorMethodHandle(generatedClass, Runnable.class); }
private static BytecodeBlock generateBlockNonNullPositionForLoop(Scope scope, Variable positionVariable, BytecodeBlock loopBody) { Variable rowsVariable = scope.declareVariable(int.class, "rows"); Variable blockVariable = scope.getVariable("block"); BytecodeBlock block = new BytecodeBlock() .append(blockVariable) .invokeInterface(Block.class, "getPositionCount", int.class) .putVariable(rowsVariable); IfStatement ifStatement = new IfStatement("if(!block.isNull(position))") .condition(new BytecodeBlock() .append(blockVariable) .append(positionVariable) .invokeInterface(Block.class, "isNull", boolean.class, int.class)) .ifFalse(loopBody); block.append(new ForLoop() .initialize(positionVariable.set(constantInt(0))) .condition(new BytecodeBlock() .append(positionVariable) .append(rowsVariable) .invokeStatic(CompilerOperations.class, "lessThan", boolean.class, int.class, int.class)) .update(new BytecodeBlock().incrementVariable(positionVariable, (byte) 1)) .body(ifStatement)); return block; }