private static void generateGetChannelCountMethod(ClassDefinition classDefinition, int outputChannelCount) { classDefinition.declareMethod( a(PUBLIC), "getChannelCount", type(int.class)) .getBody() .push(outputChannelCount) .retInt(); }
@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(page) .append(thisVariable.getField(inputChannelsField)) .push(i) .invokeInterface(List.class, "get", Object.class, int.class) .checkCast(Integer.class)
.append(wasNull.set(constantFalse())) .pop(arguments.get(0).getType().getJavaType()) // discard left value .push(true)); .comment("if left is true, push true, and goto end") .ifFalseGoto(leftIsFalse) .push(true) .gotoLabel(end) .comment("left was false; push left null flag on the stack (false)") .visitLabel(leftIsFalse) .push(false)); .ifFalseGoto(rightIsTrue) .pop(boolean.class) .push(true) .gotoLabel(end) .comment("right was false; store left null flag (on stack) in wasNull variable, and push false") .visitLabel(rightIsTrue) .putVariable(wasNull) .push(false);
.comment("call rowBlock.isNull(index)") .append(rowBlock) .push(index) .invokeInterface(Block.class, "isNull", boolean.class, int.class);
.append(wasNull.set(constantFalse())) .pop(arguments.get(0).getType().getJavaType()) // discard left value .push(true); .comment("if left is false, push false, and goto end") .ifTrueGoto(leftIsTrue) .push(false) .gotoLabel(end) .comment("left was true; push left null flag on the stack (false)") .visitLabel(leftIsTrue) .push(false); .ifTrueGoto(rightIsTrue) .pop(boolean.class) .push(false) .gotoLabel(end) .comment("right was true; store left null flag (on stack) in wasNull variable, and push true") .visitLabel(rightIsTrue) .putVariable(wasNull) .push(true);
private static void generateHashRowMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes) { Parameter position = arg("position", int.class); Parameter page = arg("blocks", Page.class); MethodDefinition hashRowMethod = classDefinition.declareMethod(a(PUBLIC), "hashRow", type(long.class), position, page); Variable resultVariable = hashRowMethod.getScope().declareVariable(long.class, "result"); hashRowMethod.getBody().push(0L).putVariable(resultVariable); for (int index = 0; index < joinChannelTypes.size(); index++) { BytecodeExpression type = constantType(callSiteBinder, joinChannelTypes.get(index)); BytecodeExpression block = page.invoke("getBlock", Block.class, constantInt(index)); hashRowMethod .getBody() .getVariable(resultVariable) .push(31L) .append(OpCode.LMUL) .append(typeHashCode(type, block, position)) .append(OpCode.LADD) .putVariable(resultVariable); } hashRowMethod .getBody() .getVariable(resultVariable) .retLong(); }
private static FieldDefinition generateInstanceSize(ClassDefinition definition) { // Store instance size in static field FieldDefinition instanceSize = definition.declareField(a(PRIVATE, STATIC, FINAL), "INSTANCE_SIZE", long.class); definition.getClassInitializer() .getBody() .comment("INSTANCE_SIZE = ClassLayout.parseClass(%s.class).instanceSize()", definition.getName()) .push(definition.getType()) .invokeStatic(ClassLayout.class, "parseClass", ClassLayout.class, Class.class) .invokeVirtual(ClassLayout.class, "instanceSize", int.class) .intToLong() .putStaticField(instanceSize); return instanceSize; }
private static FieldDefinition generateInstanceSize(ClassDefinition definition) { // Store instance size in static field FieldDefinition instanceSize = definition.declareField(a(PRIVATE, STATIC, FINAL), "INSTANCE_SIZE", long.class); definition.getClassInitializer() .getBody() .comment("INSTANCE_SIZE = ClassLayout.parseClass(%s.class).instanceSize()", definition.getName()) .push(definition.getType()) .invokeStatic(ClassLayout.class, "parseClass", ClassLayout.class, Class.class) .invokeVirtual(ClassLayout.class, "instanceSize", int.class) .intToLong() .putStaticField(instanceSize); return instanceSize; }
.push(0) .retInt();
.condition(isNull) .ifTrue(new BytecodeBlock() .push(true) .gotoLabel(end))); body.push(true) .gotoLabel(end); ifNullField.condition(value.invoke("isNull", boolean.class, constantInt(i))) .ifTrue(new BytecodeBlock() .push(true) .gotoLabel(end)); .condition(invokeFunction(scope, cachedInstanceBinder, signature.getName(), function, element)) .ifTrue(new BytecodeBlock() .push(true) .gotoLabel(end))); body.push(false);
.append(pageBuilder) .append(outputChannelOffset) .push(pageBuilderOutputChannel++) .append(OpCode.IADD) .invokeVirtual(PageBuilder.class, "getBlockBuilder", BlockBuilder.class, int.class)
.ifFalseGoto(end) .pop(boolean.class) .push(false) .visitLabel(end) .retBoolean();
.push(projectionIndex) .invokeVirtual(PageBuilder.class, "getBlockBuilder", BlockBuilder.class, int.class);
.push(true) .retBoolean();