Hi Peter,

On 2015-11-11 17:13, Peter Levart wrote:
Hi Claes,

Would constructing NamedFunction(s) using MemberName(s) directly, bypassing reflection, make any sense (for example in DMH):

    private static NamedFunction makeConstantFunction(int idx) {
        try {
            switch (idx) {
                case NF_internalMemberName:
return makeConstantFunction(Object.class, "internalMemberName", Object.class);
                case NF_internalMemberNameEnsureInit:
return makeConstantFunction(Object.class, "internalMemberNameEnsureInit", Object.class);
                case NF_ensureInitialized:
return makeConstantFunction(void.class, "ensureInitialized", Object.class);
                case NF_fieldOffset:
return makeConstantFunction(long.class, "fieldOffset", Object.class);
                case NF_checkBase:
return makeConstantFunction(Object.class, "checkBase", Object.class);
                case NF_staticBase:
return makeConstantFunction(Object.class, "staticBase", Object.class);
                case NF_staticOffset:
return makeConstantFunction(long.class, "staticOffset", Object.class);
                case NF_checkCast:
return makeConstantFunction(Object.class, "checkCast", Object.class, Object.class);
                case NF_allocateInstance:
return makeConstantFunction(Object.class, "allocateInstance", Object.class);
                case NF_constructorMethod:
return makeConstantFunction(Object.class, "constructorMethod", Object.class);
            }
        } catch (ReflectiveOperationException ex) {
            throw newInternalError(ex);
        }
        throw newInternalError("Unknown function index: " + idx);
    }

    private static NamedFunction makeConstantFunction(
Class<?> rtype, String name, Class<?> ... ptypes) throws NoSuchMethodException {
        return new NamedFunction(
            new MemberName(
DirectMethodHandle.class, name, MethodType.methodType(rtype, ptypes), REF_invokeStatic));
    }


...if reflection is not used, there might be some space savings. Or not?

I might be wrong, but I think MemberName will have to do the same reflection to resolve the actual function before use. We might defer the reflection for a bit, but not get rid of it by this approach.

Either way it seems like something to consider separately.

/Claes


Regards, Peter


Reply via email to