Prototype prototype(boolean includeThis) { return Prototype.intern(descriptor(includeThis)); }
private void checkPrototype(Prototype proto) { checkDescriptor(proto.getReturnType().getDescriptor()); StdTypeList args = proto.getParameterTypes(); for (int i = 0; i < args.size(); i++) { checkDescriptor(args.get(i).getDescriptor()); } } private void checkDescriptor(String typeDescriptor) {
Type[] params = makeParameterArray(descriptor); int paramCount = 0; int at = 1; result = new Prototype(descriptor, returnType, parameterTypes); return putIntern(result);
/** * Interns an instance, adding to the descriptor as necessary based * on the given definer, name, and flags. For example, an init * method has an uninitialized object of type {@code definer} * as its first argument. * * @param descriptor {@code non-null;} the descriptor string * @param definer {@code non-null;} class the method is defined on * @param isStatic whether this is a static method * @param isInit whether this is an init method * @return {@code non-null;} the interned instance */ public static Prototype intern(String descriptor, Type definer, boolean isStatic, boolean isInit) { Prototype base = intern(descriptor); if (isStatic) { return base; } if (isInit) { definer = definer.asUninitialized(Integer.MAX_VALUE); } return base.withFirstParameter(definer); }
/** * Returns a new interned instance, which is the same as this instance, * except that it has an additional parameter prepended to the original's * argument list. * * @param param {@code non-null;} the new first parameter * @return {@code non-null;} an appropriately-constructed instance */ public Prototype withFirstParameter(Type param) { String newDesc = "(" + param.getDescriptor() + descriptor.substring(1); StdTypeList newParams = parameterTypes.withFirst(param); newParams.setImmutable(); Prototype result = new Prototype(newDesc, returnType, newParams); return putIntern(result); }
/** * Gets the register that begins the method's parameter range (including * the 'this' parameter for non-static methods). The range continues until * {@code regSize} * * @return register as noted above. */ private int getParamBase() { return regSize - desc.getParameterTypes().getWordCount() - (isStatic? 0 : 1); }
/** * {@inheritDoc} * * In this case, this method returns the <i>return type</i> of this method. * * @return {@code non-null;} the method's return type */ @Override public final Type getType() { return prototype.getReturnType(); }
/** {@inheritDoc} */ @Override public String toHuman() { return prototype.getDescriptor(); }
/** * Returns the appropriate {@code invoke-static} rop for the * given type. The result is typically a newly-allocated instance. * * @param meth {@code non-null;} descriptor of the method * @return {@code non-null;} an appropriate instance */ public static Rop opInvokeStatic(Prototype meth) { return new Rop(RegOps.INVOKE_STATIC, meth.getParameterFrameTypes(), StdTypeList.THROWABLE); }
/** {@inheritDoc} */ @Override protected int compareTo0(Constant other) { CstProtoRef otherCstProtoRef = (CstProtoRef) other; return prototype.compareTo(otherCstProtoRef.getPrototype()); }
Type[] params = makeParameterArray(descriptor); int paramCount = 0; int at = 1; return new Prototype(descriptor, returnType, parameterTypes);
/** * Gets the prototype of this method as either a * {@code static} or instance method. In the case of a * {@code static} method, this is the same as the raw * prototype. In the case of an instance method, this has an * appropriately-typed {@code this} argument as the first * one. * * @param isStatic whether the method should be considered static * @return {@code non-null;} the method prototype */ public final Prototype getPrototype(boolean isStatic) { if (isStatic) { return prototype; } else { if (instancePrototype == null) { Type thisType = getDefiningClass().getClassType(); instancePrototype = prototype.withFirstParameter(thisType); } return instancePrototype; } }
/** * Returns the unique instance corresponding to the * given method descriptor. See vmspec-2 sec4.3.3 for details on the * field descriptor syntax. * * @param descriptor {@code non-null;} the descriptor * @return {@code non-null;} the corresponding instance * @throws IllegalArgumentException thrown if the descriptor has * invalid syntax */ public static Prototype intern(String descriptor) { if (descriptor == null) { throw new NullPointerException("descriptor == null"); } Prototype result = internTable.get(descriptor); if (result != null) { return result; } result = fromDescriptor(descriptor); return putIntern(result); }
Type[] params = makeParameterArray(descriptor); int paramCount = 0; int at = 1; result = new Prototype(descriptor, returnType, parameterTypes); return putIntern(result);
/** * Interns an instance, adding to the descriptor as necessary based * on the given definer, name, and flags. For example, an init * method has an uninitialized object of type {@code definer} * as its first argument. * * @param descriptor {@code non-null;} the descriptor string * @param definer {@code non-null;} class the method is defined on * @param isStatic whether this is a static method * @param isInit whether this is an init method * @return {@code non-null;} the interned instance */ public static Prototype intern(String descriptor, Type definer, boolean isStatic, boolean isInit) { Prototype base = intern(descriptor); if (isStatic) { return base; } if (isInit) { definer = definer.asUninitialized(Integer.MAX_VALUE); } return base.withFirstParameter(definer); }
/** * Returns a new interned instance, which is the same as this instance, * except that it has an additional parameter prepended to the original's * argument list. * * @param param {@code non-null;} the new first parameter * @return {@code non-null;} an appropriately-constructed instance */ public Prototype withFirstParameter(Type param) { String newDesc = "(" + param.getDescriptor() + descriptor.substring(1); StdTypeList newParams = parameterTypes.withFirst(param); newParams.setImmutable(); Prototype result = new Prototype(newDesc, returnType, newParams); return putIntern(result); }
/** * Gets the register that begins the method's parameter range (including * the 'this' parameter for non-static methods). The range continues until * {@code regSize} * * @return register as noted above */ private int getParamBase() { return regSize - desc.getParameterTypes().getWordCount() - (isStatic? 0 : 1); }
/** * Gets the return type. * * @return {@code non-null;} the return type */ public Type getReturnType() { return prototype.getReturnType(); }
/** {@inheritDoc} */ @Override public String toHuman() { return prototype.getDescriptor(); }
/** * Returns the appropriate {@code invoke-static} rop for the * given type. The result is typically a newly-allocated instance. * * @param meth {@code non-null;} descriptor of the method * @return {@code non-null;} an appropriate instance */ public static Rop opInvokeStatic(Prototype meth) { return new Rop(RegOps.INVOKE_STATIC, meth.getParameterFrameTypes(), StdTypeList.THROWABLE); }