MethodInfo ctor = cf.addConstructor(Modifiers.PUBLIC, paramTypes); ctor.markSynthetic(); CodeBuilder builder = new CodeBuilder(ctor); builder.loadThis(); builder.invokeSuperConstructor(null); builder.loadThis(); builder.loadLocal(builder.getParameter(0)); builder.storeField("mCollators", comparatorArrayType); builder.loadThis(); builder.loadLocal(builder.getParameter(1)); builder.storeField("mUsingComparators", comparatorArrayType); builder.returnVoid(); builder = new CodeBuilder(mi); Label endLabel = builder.createLabel(); LocalVariable obj1 = builder.getParameter(0); LocalVariable obj2 = builder.getParameter(1); builder.loadLocal(obj1); builder.loadLocal(obj2); builder.ifEqualBranch(endLabel, true); Label label = builder.createLabel(); builder.loadLocal(obj1); builder.ifNullBranch(label, false); builder.loadConstant(nullHigh ? 1 : -1); builder.returnValue(TypeDesc.INT);
private void generateWildcard(PatternNode node, int depth, int posIndex) { Label loopStart = mBuilder.createLabel().setLocation(); Label loopEnd = mBuilder.createLabel(); Label loopContinue = mBuilder.createLabel(); mBuilder.loadLocal(mPositionsLocal); mBuilder.loadConstant(posIndex - 1); mBuilder.loadLocal(mIndexLocal); if (depth > 0) { mBuilder.loadConstant(depth); mBuilder.math(Opcode.IADD); mBuilder.storeToArray(TypeDesc.INT); mBuilder.loadLocal(mLookupLocal); mBuilder.loadLocal(mIndexLocal); if (depth > 0) { mBuilder.loadConstant(depth); mBuilder.math(Opcode.IADD); mBuilder.loadFromArray(TypeDesc.CHAR); mBuilder.loadConstant('\uffff'); mBuilder.ifComparisonBranch(loopEnd, "=="); } else { LocalVariable tempChar; if (mTempLocals.isEmpty()) { tempChar = mBuilder.createLocalVariable("temp", mIntType);
CodeBuilder b = new CodeBuilder(mi); beanVar = b.getParameter(0); propertyVar = b.getParameter(1); valueVar = null; break; case WRITE_METHOD: case TRY_WRITE_METHOD: beanVar = b.getParameter(0); propertyVar = b.getParameter(1); valueVar = b.getParameter(2); break; case HAS_READ_METHOD: case HAS_WRITE_METHOD: beanVar = null; propertyVar = b.getParameter(0); valueVar = null; break; b.loadLocal(beanVar); b.checkCast(TypeDesc.forClass(beanType)); b.storeLocal(beanVar); Label noMatch = b.createLabel(); List[] caseMethods = caseMethods(caseCount, properties); switchLabels[i] = noMatch; } else { switchLabels[i] = b.createLabel(); b.loadLocal(propertyVar);
private void emit_docVar() { b.loadLocal(docVarParam); // push the docVar parameter b.swap(); // swap the top two words on the stack, so the var id is on top params = new TypeDesc[] {TypeDesc.INT}; // the type of the id parameter (int) b.invokeInterface(docVarType, "getBoost", TypeDesc.FLOAT, params); b.convert(TypeDesc.FLOAT, TypeDesc.DOUBLE); }
private void nullConvert(Label end) { LocalVariable temp = createLocalVariable("temp", TypeDesc.OBJECT); storeLocal(temp); loadLocal(temp); Label notNull = createLabel(); ifNullBranch(notNull, false); loadNull(); branch(end); notNull.setLocation(); loadLocal(temp); }
b.loadThis(); b.loadLocal(b.getParameter(0)); Label notEqual = b.createLabel(); b.ifEqualBranch(notEqual, false); b.loadConstant(true); b.returnValue(TypeDesc.BOOLEAN); b.loadLocal(b.getParameter(0)); b.instanceOf(cf.getType()); Label isInstance = b.createLabel(); b.ifZeroComparisonBranch(isInstance, "!="); b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); b.loadThis(); b.loadField(REF_FIELD_NAME, atomicRefType); b.invokeVirtual(atomicRefType, "get", TypeDesc.OBJECT, null); b.checkCast(TypeDesc.forClass(mType)); for (int i=0; i<b.getParameterCount(); i++) { b.loadLocal(b.getParameter(i)); b.checkCast(cf.getType()); b.loadField(REF_FIELD_NAME, atomicRefType); b.invokeVirtual(atomicRefType, "get", TypeDesc.OBJECT, null); b.checkCast(TypeDesc.forClass(mType)); b.invoke(m);
CodeBuilder b = new CodeBuilder(cf.addMethod(method)); b.newObject(TypeDesc.forClass(objectType)); b.dup(); int count = b.getParameterCount(); for (int i=0; i<count; i++) { b.loadLocal(b.getParameter(i)); b.invoke(ctor); b.returnValue(TypeDesc.OBJECT);
CodeBuilder b = new CodeBuilder(mi); LocalVariable beanVar = b.getParameter(0); b.loadLocal(beanVar); b.checkCast(TypeDesc.forClass(beanType)); b.storeLocal(beanVar); LocalVariable valueVar = b.getParameter(1); b.loadLocal(valueVar); Label searchNotNull = b.createLabel(); b.ifNullBranch(searchNotNull, false); b.loadLocal(beanVar); b.invoke(bp.getReadMethod()); Label noMatch = b.createLabel(); b.ifNullBranch(noMatch, false); b.loadConstant(true); b.returnValue(TypeDesc.BOOLEAN); b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); b.loadLocal(valueVar); b.loadLocal(beanVar); b.invoke(bp.getReadMethod()); b.convert(TypeDesc.forClass(bp.getType()), TypeDesc.OBJECT); b.invokeVirtual(Object.class.getName(), "equals", TypeDesc.BOOLEAN, params);
charWasNull = b.createLabel(); LocalVariable temp = b.createLocalVariable(null, resultSetType); b.storeLocal(temp); b.loadLocal(temp); b.ifNullBranch(charWasNull, true); b.loadLocal(temp); b.loadConstant(0); b.invokeVirtual(String.class.getName(), "charAt", TypeDesc.CHAR, new TypeDesc[] {TypeDesc.INT}); b.convert(TypeDesc.CHAR, toType); Label skipNull = b.createLabel(); b.branch(skipNull); b.loadNull(); b.convert(resultSetType, toType);
TypeDesc[] params = {objectArrayType}; MethodInfo mi = cf.addConstructor(Modifiers.PUBLIC, params); mBuilder = new CodeBuilder(mi); mBuilder.loadThis(); mBuilder.loadLocal(mBuilder.getParameter(0)); mBuilder.invokeSuperConstructor(params); mBuilder.returnVoid(); params = new TypeDesc[]{charArrayType, mIntType, mListType}; mi = cf.addMethod(Modifiers.PUBLIC, "fillMatchResults", null, params); mBuilder = new CodeBuilder(mi); mLookupLocal = mBuilder.getParameter(0); mLimitLocal = mBuilder.getParameter(1); mResultsLocal = mBuilder.getParameter(2); mPositionsLocal = mBuilder.createLocalVariable("positions", mIntArrayType); mIndexLocal = mBuilder.createLocalVariable("index", mIntType); mBuilder.mapLineNumber(++mReferenceLine); mBuilder.loadConstant(mMaxWildPerKey * 2); mBuilder.newObject(mIntArrayType); mBuilder.storeLocal(mPositionsLocal); mBuilder.loadConstant(0); mBuilder.storeLocal(mIndexLocal); mTempLocals = new Stack(); mReturnLabel = mBuilder.createLabel();
private void checkIfPartitionKeyPresent(CodeBuilder b) { b.loadThis(); b.invokeVirtual(StorableGenerator.IS_PARTITION_KEY_INITIALIZED_METHOD_NAME, TypeDesc.BOOLEAN, null); Label ptnkInitialized = b.createLabel(); b.ifZeroComparisonBranch(ptnkInitialized, "!="); TypeDesc exType = TypeDesc.forClass(IllegalStateException.class); b.newObject(exType); b.dup(); b.loadConstant("Partition key not fully specified"); b.invokeConstructor(exType, new TypeDesc[] {TypeDesc.STRING}); b.throwObject(); ptnkInitialized.setLocation(); }
/** * Generates code that loads a Storage instance on the stack, throwing a * FetchException if Storage request fails. * * @param type type of Storage to request */ private void loadStorageForFetch(CodeBuilder b, TypeDesc type) { b.loadThis(); b.loadField(SUPPORT_FIELD_NAME, mSupportType); TypeDesc storageType = TypeDesc.forClass(Storage.class); TypeDesc repositoryType = TypeDesc.forClass(Repository.class); b.invokeInterface (mSupportType, "getRootRepository", repositoryType, null); b.loadConstant(type); // This may throw a RepositoryException. Label tryStart = b.createLabel().setLocation(); b.invokeInterface(repositoryType, STORAGE_FOR_METHOD_NAME, storageType, new TypeDesc[]{TypeDesc.forClass(Class.class)}); Label tryEnd = b.createLabel().setLocation(); Label noException = b.createLabel(); b.branch(noException); b.exceptionHandler(tryStart, tryEnd, RepositoryException.class.getName()); b.invokeVirtual (RepositoryException.class.getName(), "toFetchException", TypeDesc.forClass(FetchException.class), null); b.throwObject(); noException.setLocation(); }
/** * Generates code which emulates this: * * ... * } finally { * statement.close(); * } * * @param statementVar Statement variable * @param tryAfterStatement label right after Statement acquisition */ private void closeStatement (CodeBuilder b, LocalVariable statementVar, Label tryAfterStatement) { Label contLabel = b.createLabel(); Label endFinallyLabel = b.createLabel().setLocation(); b.loadLocal(statementVar); b.invokeInterface(TypeDesc.forClass(Statement.class), "close", null, null); b.branch(contLabel); b.exceptionHandler(tryAfterStatement, endFinallyLabel, null); b.loadLocal(statementVar); b.invokeInterface(TypeDesc.forClass(Statement.class), "close", null, null); b.throwObject(); contLabel.setLocation(); }
CodeBuilder b = new CodeBuilder(cf.addConstructor(Modifiers.PUBLIC, paramDescs)); b.loadThis(); for (int i=0; i<paramTypes.length; i++) { b.loadLocal(b.getParameter(i)); b.invokeSuperConstructor(paramDescs); b.loadThis(); b.loadLocal(b.getParameter(0)); b.storeField("delegate", delegateDesc); b.returnVoid(); CodeBuilder b = new CodeBuilder(cf.addMethod(abstractMethod)); b.loadThis(); b.loadField("delegate", delegateDesc); int count = b.getParameterCount(); for (int i=0; i<count; i++) { b.loadLocal(b.getParameter(i)); b.invoke(delegateMethod); b.returnValue(TypeDesc.forClass(abstractMethod.getReturnType()));
mBuilder.mapLineNumber(++mReferenceLine); mBuilder.createLocalVariable("temp", mIntType); } else { savedIndex = (LocalVariable)mTempLocals.pop(); mBuilder.loadLocal(mIndexLocal); mBuilder.storeLocal(savedIndex); mBuilder.loadLocal(mPositionsLocal); mBuilder.loadConstant(posIndex); mBuilder.loadLocal(mIndexLocal); if (depth > 0) { mBuilder.loadConstant(depth); mBuilder.math(Opcode.IADD); mBuilder.storeToArray(TypeDesc.INT); generateWildcard((PatternNode)subNodes.get(i), depth, posIndex + 2); mBuilder.loadLocal(savedIndex); mBuilder.storeLocal(mIndexLocal); Label noMatch = mBuilder.createLabel(); mBuilder.loadLocal(tempChar); mTempLocals.push(tempChar); } else { mBuilder.loadLocal(mLookupLocal);
CodeBuilder b = new CodeBuilder(cf.addConstructor(Modifiers.PUBLIC, new TypeDesc[] {atomicRefType})); b.loadThis(); b.invokeSuperConstructor(null); b.loadThis(); b.loadLocal(b.getParameter(0)); b.storeField(REF_FIELD_NAME, atomicRefType); b.returnVoid(); addWrappedCall(cf, new CodeBuilder(cf.addMethod(m)), m); int modifiers = m.getModifiers(); if (!Modifier.isFinal(modifiers) && Modifier.isPublic(modifiers)) { b = new CodeBuilder (cf.addMethod(Modifiers.PUBLIC, m.getName(), MethodDesc.forMethod(m))); addWrappedCall(cf, b, m);
private static void throwIllegalArgException(CodeBuilder b, String message, LocalVariable concatStr) { TypeDesc exceptionType = TypeDesc.forClass(IllegalArgumentException.class); TypeDesc[] params = {TypeDesc.STRING}; b.newObject(exceptionType); b.dup(); b.loadConstant(message); b.loadLocal(concatStr); b.invokeVirtual(TypeDesc.STRING, "concat", TypeDesc.STRING, params); b.invokeConstructor(exceptionType, params); b.throwObject(); }
private String addFilterField(PropertyFilter filter, TypeDesc type) { final int propertyOrdinal = mPropertyOrdinalMap.get(filter); final String fieldName = FIELD_PREFIX + propertyOrdinal; if (mGeneratedPropertyFilters.containsKey(filter)) { return fieldName; } final TypeDesc fieldType = actualFieldType(type); mClassFile.addField(Modifiers.PRIVATE.toFinal(true), fieldName, fieldType); // Add code to constructor to store value into field. { CodeBuilder b = mCtorBuilder; b.loadThis(); b.loadLocal(b.getParameter(1)); b.loadConstant(propertyOrdinal); b.loadFromArray(OBJECT); if (type != OBJECT) { b.checkCast(type.toObjectType()); convertProperty(b, type.toObjectType(), fieldType); } b.storeField(fieldName, fieldType); } mGeneratedPropertyFilters.put(filter, filter); return fieldName; }
builder.loadLocal(a); builder.loadLocal(b); builder.invoke(compareToMethod); if (goodLabel != null) { builder.branch(goodLabel); goodLabel = builder.createLabel(); locateGoodLabel = true; Label tryStart = builder.createLabel().setLocation(); builder.loadLocal(a); builder.checkCast(comparableType); builder.loadLocal(b); builder.checkCast(comparableType); Label tryEnd = builder.createLabel().setLocation(); builder.invoke(compareToMethod); builder.branch(goodLabel); builder.exceptionHandler(tryStart, tryEnd, ClassCastException.class.getName()); builder.pop(); if (nextLabel == null) { builder.loadConstant(0); } else { builder.branch(nextLabel);