$ 가상본 코맥손드프라우리스 지정하십시오.

I have seen that 오류가 발생하면 다른 프레임워크와도 (에드그 프레임워크와도 EJB 사양명세 또는 일부 제파 구축 업체) 깊은 컨테인먼트하는 클래스뿐만 stacktrace 가 이 같은 '코맥손드프라우리스 $ 가상본'. 더 잘 알고 있지만, 기술 및 자바 프록시 () 는 특정 오토메이티드 더 찾고 있습니다.

  1. 이게 뭐죠?
  2. 이들은 어떻게 생성되는가?
  3. Jvm 은 어떤 관계가 있는가? 그들은 JVM 구현 특정?
해결책
  1. 프록시 클래스가 있다 생성될지 및 로드되는지 런타임용으로 개발하십시오. 이러한 클래스에 대한 소스 코드를 없다. 혹시 내가 아는 당신은 그들을 어떻게 발작이에요 그들한테는요 있으면 일을 할 수 있습니다. 답은 ',' 지정하면 해당 만들 때, 즉 때 린보카션핸들러 를 구현하는 방법을 정의하는 객체에는 호출되었을 프록시 메서드입니다 호출됩니다.

  2. 호츨 사용하여 만들

프로스리자뉴프로스린스턴스 (클라슬로이더, 인터페이스, 린보카션핸들러) 인수가:

  1. '클라슬로이더'. 일단 클래스용 수집됩니다 얻게된다면 로드되었는지 대체하십시오 class loader.
  2. '인터페이스와도'. 할 수 있는 모든 배열입니다 클래스용 객체에는 인터페이스입니다. 그 결과 가상본 이러한 모든 인터페이스를 구현합니다.
  3. '린보카션핸들러'. 이 때 어떻게 해야 할지 방법을 가상본 계시나니 메서드입니다 호출됩니다. 이 프로그램은 객체에는 린보카션핸들러 를 구현하는 ''. 언제 어디서나 메서드입니다 지원 대상 ',' 는 '또는' 또는 '하시코드 인터페이스와도 toString' 는 '이', '는 이 메서드를 호출할 수 있는 방법을 호출하십시오 호출되었을 처리기에서 반군지역' 객체에 대한 방법이 기도하였나니 및 인수만 통과했습니다.

이에 대한 자세한 내용은 '가상본' 클래스에 대한 문서를 참조하십시오.

  1. 이 후 모든 자바 가상 머신 구축현 버전 1.3 지원해야 합니다. 그들은 로드되었는지 꽂으십시오 구체적인 구현 운행에서어떠한 보장할 수 있는 것은 jvm 의 내부 데이터 구조 작업.
해설 (0)

이게 뭐죠?

특별한 게 없다. 그냥 일반적인 Java 클래스 동일하게 인스턴스입니다.

하지만 그 클래스 '는' 합성형 가상본 클래스뿐만 만든 ['#' 자바드랑이어플라치드프라우이 뉴프로스린스턴스] [1]

Jvm 은 어떤 관계가 있는가? 그들은 JVM 구현 특정?

도입된 1.3

http://docs.oracle.com/javase/1.3/docs/relnotes/features.html # 반사

Jave 일부이다. 이 때문에 각 JVM 지원해야 합니다.

이들은 어떻게 만든 (Openjdk7 소스)?

한 마디로. 이들은 JVM 을 사용하여 만든 ASM 기술 (정의중 자바브리트 코드 실행 시)

뭔가 사용하여 동일한 기술:

뉴프로스린스턴스 자바드랑이어플라치드프라우이 호출하십시오 후 '어떻게'

  1. 판독값 getProxyClass0 얻을 수 있는 '콜' 소스 'Class&lt 뉴프로스린스턴스 볼 수 있습니다.? &gt. '
  2. 프로스이제너레이터스의테프로스리클레스 '매직' 이 있는 한 후 많은 캐시에는 또는 스테 페이징됩니다 복귀하십시오 바이트입니다 [] '클래스' 정의 '$1. 매입옵션 클라슬로이더 읽어들입니다 생성할지 가상본' 클래스 (이 classname 확인하셨습니다)
  3. 그냥 인스턴스를 사용할 수 있도록 됩니다

매직 쑨스미스차오프로스이제너레이터 일어나는 일들을 생각해보면

  1. a 클래스 (바이트코드) 모든 방법으로 인터페이스를 하나로 결합한 패돌림!

  2. 구축하십시오 등 각 방법은 같은 바이트코드

  3. 프레젠테이션이든 호출하십시오 메서드입니다 메탐페타민 정보 (저장됩니까 줄이면서)

  4. 전달하십시오 & # 39 에 's' () ',' 호출 처리기에서 호출하십시오 정보

  5. 프레젠테이션이든 '& # 39, s' 에서 '호출 처리기에서 호출하십시오 반환 값 ()' 그냥 다시 1.

클래스 (바이트코드) '형태로 나타내는' 바이트입니다 [] 1.

  • 그리는 방법에 class) *

네, 그냥 이렇게 생각을 jave 코드는 컴파일됨 salesforce. 바이트코드가 런타임 시

이 코드는 의논하십시오 값싼 보여줄 수 있다.

핵심 방법으로 sun/misc/ProxyGenerator.java

의테클레스피리

/**
 * Generate a class file for the proxy class.  This method drives the
 * class file generation process.
 */
private byte[] generateClassFile() {

    /* ============================================================
     * Step 1: Assemble ProxyMethod objects for all methods to
     * generate proxy dispatching code for.
     */

    /*
     * Record that proxy methods are needed for the hashCode, equals,
     * and toString methods of java.lang.Object.  This is done before
     * the methods from the proxy interfaces so that the methods from
     * java.lang.Object take precedence over duplicate methods in the
     * proxy interfaces.
     */
    addProxyMethod(hashCodeMethod, Object.class);
    addProxyMethod(equalsMethod, Object.class);
    addProxyMethod(toStringMethod, Object.class);

    /*
     * Now record all of the methods from the proxy interfaces, giving
     * earlier interfaces precedence over later ones with duplicate
     * methods.
     */
    for (int i = 0; i < interfaces.length; i++) {
        Method[] methods = interfaces[i].getMethods();
        for (int j = 0; j < methods.length; j++) {
            addProxyMethod(methods[j], interfaces[i]);
        }
    }

    /*
     * For each set of proxy methods with the same signature,
     * verify that the methods' return types are compatible.
     */
    for (List sigmethods : proxyMethods.values()) {
        checkReturnTypes(sigmethods);
    }

    /* ============================================================
     * Step 2: Assemble FieldInfo and MethodInfo structs for all of
     * fields and methods in the class we are generating.
     */
    try {
        methods.add(generateConstructor());

        for (List sigmethods : proxyMethods.values()) {
            for (ProxyMethod pm : sigmethods) {

                // add static field for method's Method object
                fields.add(new FieldInfo(pm.methodFieldName,
                    "Ljava/lang/reflect/Method;",
                     ACC_PRIVATE | ACC_STATIC));

                // generate code for proxy method and add it
                methods.add(pm.generateMethod());
            }
        }

        methods.add(generateStaticInitializer());

    } catch (IOException e) {
        throw new InternalError("unexpected I/O Exception");
    }

    if (methods.size() > 65535) {
        throw new IllegalArgumentException("method limit exceeded");
    }
    if (fields.size() > 65535) {
        throw new IllegalArgumentException("field limit exceeded");
    }

    /* ============================================================
     * Step 3: Write the final class file.
     */

    /*
     * Make sure that constant pool indexes are reserved for the
     * following items before starting to write the final class file.
     */
    cp.getClass(dotToSlash(className));
    cp.getClass(superclassName);
    for (int i = 0; i < interfaces.length; i++) {
        cp.getClass(dotToSlash(interfaces[i].getName()));
    }

    /*
     * Disallow new constant pool additions beyond this point, since
     * we are about to write the final constant pool table.
     */
    cp.setReadOnly();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    DataOutputStream dout = new DataOutputStream(bout);

    try {
        /*
         * Write all the items of the "ClassFile" structure.
         * See JVMS section 4.1.
         */
                                    // u4 magic;
        dout.writeInt(0xCAFEBABE);
                                    // u2 minor_version;
        dout.writeShort(CLASSFILE_MINOR_VERSION);
                                    // u2 major_version;
        dout.writeShort(CLASSFILE_MAJOR_VERSION);

        cp.write(dout);             // (write constant pool)

                                    // u2 access_flags;
        dout.writeShort(ACC_PUBLIC | ACC_FINAL | ACC_SUPER);
                                    // u2 this_class;
        dout.writeShort(cp.getClass(dotToSlash(className)));
                                    // u2 super_class;
        dout.writeShort(cp.getClass(superclassName));

                                    // u2 interfaces_count;
        dout.writeShort(interfaces.length);
                                    // u2 interfaces[interfaces_count];
        for (int i = 0; i < interfaces.length; i++) {
            dout.writeShort(cp.getClass(
                dotToSlash(interfaces[i].getName())));
        }

                                    // u2 fields_count;
        dout.writeShort(fields.size());
                                    // field_info fields[fields_count];
        for (FieldInfo f : fields) {
            f.write(dout);
        }

                                    // u2 methods_count;
        dout.writeShort(methods.size());
                                    // method_info methods[methods_count];
        for (MethodInfo m : methods) {
            m.write(dout);
        }

                                     // u2 attributes_count;
        dout.writeShort(0); // (no ClassFile attributes for proxy classes)

    } catch (IOException e) {
        throw new InternalError("unexpected I/O Exception");
    }

    return bout.toByteArray();
}

아드프라우이메트로트

/**
 * Add another method to be proxied, either by creating a new
 * ProxyMethod object or augmenting an old one for a duplicate
 * method.
 *
 * "fromClass" indicates the proxy interface that the method was
 * found through, which may be different from (a subinterface of)
 * the method's "declaring class".  Note that the first Method
 * object passed for a given name and descriptor identifies the
 * Method object (and thus the declaring class) that will be
 * passed to the invocation handler's "invoke" method for a given
 * set of duplicate methods.
 */
private void addProxyMethod(Method m, Class fromClass) {
    String name = m.getName();
    Class[] parameterTypes = m.getParameterTypes();
    Class returnType = m.getReturnType();
    Class[] exceptionTypes = m.getExceptionTypes();

    String sig = name + getParameterDescriptors(parameterTypes);
    List sigmethods = proxyMethods.get(sig);
    if (sigmethods != null) {
        for (ProxyMethod pm : sigmethods) {
            if (returnType == pm.returnType) {
                /*
                 * Found a match: reduce exception types to the
                 * greatest set of exceptions that can thrown
                 * compatibly with the throws clauses of both
                 * overridden methods.
                 */
                List> legalExceptions = new ArrayList>();
                collectCompatibleTypes(
                    exceptionTypes, pm.exceptionTypes, legalExceptions);
                collectCompatibleTypes(
                    pm.exceptionTypes, exceptionTypes, legalExceptions);
                pm.exceptionTypes = new Class[legalExceptions.size()];
                pm.exceptionTypes =
                    legalExceptions.toArray(pm.exceptionTypes);
                return;
            }
        }
    } else {
        sigmethods = new ArrayList(3);
        proxyMethods.put(sig, sigmethods);
    }
    sigmethods.add(new ProxyMethod(name, parameterTypes, returnType,
                                   exceptionTypes, fromClass));
}

전체 코드를 실행할 수 있는 프록시 메서드입니다 대한

    private MethodInfo generateMethod() throws IOException {
        String desc = getMethodDescriptor(parameterTypes, returnType);
        MethodInfo minfo = new MethodInfo(methodName, desc,
            ACC_PUBLIC | ACC_FINAL);

        int[] parameterSlot = new int[parameterTypes.length];
        int nextSlot = 1;
        for (int i = 0; i < parameterSlot.length; i++) {
            parameterSlot[i] = nextSlot;
            nextSlot += getWordsPerType(parameterTypes[i]);
        }
        int localSlot0 = nextSlot;
        short pc, tryBegin = 0, tryEnd;

        DataOutputStream out = new DataOutputStream(minfo.code);

        code_aload(0, out);

        out.writeByte(opc_getfield);
        out.writeShort(cp.getFieldRef(
            superclassName,
            handlerFieldName, "Ljava/lang/reflect/InvocationHandler;"));

        code_aload(0, out);

        out.writeByte(opc_getstatic);
        out.writeShort(cp.getFieldRef(
            dotToSlash(className),
            methodFieldName, "Ljava/lang/reflect/Method;"));

        if (parameterTypes.length > 0) {

            code_ipush(parameterTypes.length, out);

            out.writeByte(opc_anewarray);
            out.writeShort(cp.getClass("java/lang/Object"));

            for (int i = 0; i < parameterTypes.length; i++) {

                out.writeByte(opc_dup);

                code_ipush(i, out);

                codeWrapArgument(parameterTypes[i], parameterSlot[i], out);

                out.writeByte(opc_aastore);
            }
        } else {

            out.writeByte(opc_aconst_null);
        }

        out.writeByte(opc_invokeinterface);
        out.writeShort(cp.getInterfaceMethodRef(
            "java/lang/reflect/InvocationHandler",
            "invoke",
            "(Ljava/lang/Object;Ljava/lang/reflect/Method;" +
                "[Ljava/lang/Object;)Ljava/lang/Object;"));
        out.writeByte(4);
        out.writeByte(0);

        if (returnType == void.class) {

            out.writeByte(opc_pop);

            out.writeByte(opc_return);

        } else {

            codeUnwrapReturnValue(returnType, out);
        }

        tryEnd = pc = (short) minfo.code.size();

        List> catchList = computeUniqueCatchList(exceptionTypes);
        if (catchList.size() > 0) {

            for (Class<?> ex : catchList) {
                minfo.exceptionTable.add(new ExceptionTableEntry(
                    tryBegin, tryEnd, pc,
                    cp.getClass(dotToSlash(ex.getName()))));
            }

            out.writeByte(opc_athrow);

            pc = (short) minfo.code.size();

            minfo.exceptionTable.add(new ExceptionTableEntry(
                tryBegin, tryEnd, pc, cp.getClass("java/lang/Throwable")));

            code_astore(localSlot0, out);

            out.writeByte(opc_new);
            out.writeShort(cp.getClass(
                "java/lang/reflect/UndeclaredThrowableException"));

            out.writeByte(opc_dup);

            code_aload(localSlot0, out);

            out.writeByte(opc_invokespecial);

            out.writeShort(cp.getMethodRef(
                "java/lang/reflect/UndeclaredThrowableException",
                "", "(Ljava/lang/Throwable;)V"));

            out.writeByte(opc_athrow);
        }

[1]: http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Proxy.html # 뉴프로스린스턴스 ([], %20java.lang.reflect.invocationhandler 20java.lang.class 자바드란g. 클라슬로이더, %)

해설 (0)