private static void generateGetSizeInBytesMethod(ClassDefinition classDefinition, FieldDefinition sizeField) { MethodDefinition getSizeInBytesMethod = classDefinition.declareMethod(a(PUBLIC), "getSizeInBytes", type(long.class)); Variable thisVariable = getSizeInBytesMethod.getThis(); getSizeInBytesMethod.getBody() .append(thisVariable.getField(sizeField)) .retLong(); }
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 <T> Class<? extends T> generateSingleStateClass(Class<T> clazz, Map<String, Type> fieldTypes, DynamicClassLoader classLoader) { ClassDefinition definition = new ClassDefinition( a(PUBLIC, FINAL), makeClassName("Single" + clazz.getSimpleName()), type(Object.class), type(clazz)); FieldDefinition instanceSize = generateInstanceSize(definition); // Add getter for class size definition.declareMethod(a(PUBLIC), "getEstimatedSize", type(long.class)) .getBody() .getStaticField(instanceSize) .retLong(); // Generate constructor MethodDefinition constructor = definition.declareConstructor(a(PUBLIC)); constructor.getBody() .append(constructor.getThis()) .invokeConstructor(Object.class); // Generate fields List<StateField> fields = enumerateFields(clazz, fieldTypes); for (StateField field : fields) { generateField(definition, constructor, field); } constructor.getBody() .ret(); return defineClass(definition, clazz, classLoader); }
.getBody() .getVariable(resultVariable) .retLong();
public BytecodeBlock ret(Class<?> type) { if (type == long.class) { retLong(); } else if (type == boolean.class) { retBoolean(); } else if (type == int.class || type == byte.class || type == char.class || type == short.class) { retInt(); } else if (type == float.class) { retFloat(); } else if (type == double.class) { retDouble(); } else if (type == void.class) { ret(); } else if (!type.isPrimitive()) { retObject(); } else { throw new IllegalArgumentException("Unsupported type: " + type.getName()); } return this; }
private static void generateGetSizeInBytesMethod(ClassDefinition classDefinition, FieldDefinition sizeField) { MethodDefinition getSizeInBytesMethod = classDefinition.declareMethod(a(PUBLIC), "getSizeInBytes", type(long.class)); Variable thisVariable = getSizeInBytesMethod.getThis(); getSizeInBytesMethod.getBody() .append(thisVariable.getField(sizeField)) .retLong(); }
private static void generateGetSizeInBytesMethod(ClassDefinition classDefinition, FieldDefinition sizeField) { MethodDefinition getSizeInBytesMethod = classDefinition.declareMethod(a(PUBLIC), "getSizeInBytes", type(long.class)); Variable thisVariable = getSizeInBytesMethod.getThis(); getSizeInBytesMethod.getBody() .append(thisVariable.getField(sizeField)) .retLong(); }
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 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 <T> Class<? extends T> generateSingleStateClass(Class<T> clazz, Map<String, Type> fieldTypes, DynamicClassLoader classLoader) { ClassDefinition definition = new ClassDefinition( a(PUBLIC, FINAL), makeClassName("Single" + clazz.getSimpleName()), type(Object.class), type(clazz)); FieldDefinition instanceSize = generateInstanceSize(definition); // Add getter for class size definition.declareMethod(a(PUBLIC), "getEstimatedSize", type(long.class)) .getBody() .getStaticField(instanceSize) .retLong(); // Generate constructor MethodDefinition constructor = definition.declareConstructor(a(PUBLIC)); constructor.getBody() .append(constructor.getThis()) .invokeConstructor(Object.class); // Generate fields List<StateField> fields = enumerateFields(clazz, fieldTypes); for (StateField field : fields) { generateField(definition, constructor, field); } constructor.getBody() .ret(); return defineClass(definition, clazz, classLoader); }
private static <T> Class<? extends T> generateSingleStateClass(Class<T> clazz, Map<String, Type> fieldTypes, DynamicClassLoader classLoader) { ClassDefinition definition = new ClassDefinition( a(PUBLIC, FINAL), makeClassName("Single" + clazz.getSimpleName()), type(Object.class), type(clazz)); FieldDefinition instanceSize = generateInstanceSize(definition); // Add getter for class size definition.declareMethod(a(PUBLIC), "getEstimatedSize", type(long.class)) .getBody() .getStaticField(instanceSize) .retLong(); // Generate constructor MethodDefinition constructor = definition.declareConstructor(a(PUBLIC)); constructor.getBody() .append(constructor.getThis()) .invokeConstructor(Object.class); // Generate fields List<StateField> fields = enumerateFields(clazz, fieldTypes); for (StateField field : fields) { generateField(definition, constructor, field); } constructor.getBody() .ret(); return defineClass(definition, clazz, classLoader); }
.getBody() .getVariable(resultVariable) .retLong();
.getBody() .getVariable(resultVariable) .retLong();