Search in sources :

Example 1 with MemberDefinition

use of sun.tools.java.MemberDefinition in project jdk8u_jdk by JetBrains.

the class RemoteClass method computeInterfaceHash.

/**
     * Compute the "interface hash" of the stub/skeleton pair for this
     * remote implementation class.  This is the 64-bit value used to
     * enforce compatibility between a stub and a skeleton using the
     * JDK 1.1 version of the stub/skeleton protocol.
     *
     * It is calculated using the first 64 bits of a SHA digest.  The
     * digest is from a stream consisting of the following data:
     *     (int) stub version number, always 1
     *     for each remote method, in order of operation number:
     *         (UTF) method name
     *         (UTF) method type signature
     *         for each declared exception, in alphabetical name order:
     *             (UTF) name of exception class
     *
     */
private long computeInterfaceHash() {
    long hash = 0;
    ByteArrayOutputStream sink = new ByteArrayOutputStream(512);
    try {
        MessageDigest md = MessageDigest.getInstance("SHA");
        DataOutputStream out = new DataOutputStream(new DigestOutputStream(sink, md));
        out.writeInt(INTERFACE_HASH_STUB_VERSION);
        for (int i = 0; i < remoteMethods.length; i++) {
            MemberDefinition m = remoteMethods[i].getMemberDefinition();
            Identifier name = m.getName();
            Type type = m.getType();
            out.writeUTF(name.toString());
            // type signatures already use mangled class names
            out.writeUTF(type.getTypeSignature());
            ClassDeclaration[] exceptions = m.getExceptions(env);
            sortClassDeclarations(exceptions);
            for (int j = 0; j < exceptions.length; j++) {
                out.writeUTF(Names.mangleClass(exceptions[j].getName()).toString());
            }
        }
        out.flush();
        // use only the first 64 bits of the digest for the hash
        byte[] hashArray = md.digest();
        for (int i = 0; i < Math.min(8, hashArray.length); i++) {
            hash += ((long) (hashArray[i] & 0xFF)) << (i * 8);
        }
    } catch (IOException e) {
        throw new Error("unexpected exception computing intetrface hash: " + e);
    } catch (NoSuchAlgorithmException e) {
        throw new Error("unexpected exception computing intetrface hash: " + e);
    }
    return hash;
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Type(sun.tools.java.Type) Identifier(sun.tools.java.Identifier) ClassDeclaration(sun.tools.java.ClassDeclaration) DigestOutputStream(java.security.DigestOutputStream) MessageDigest(java.security.MessageDigest) MemberDefinition(sun.tools.java.MemberDefinition)

Example 2 with MemberDefinition

use of sun.tools.java.MemberDefinition in project jdk8u_jdk by JetBrains.

the class RMIGenerator method writeMethodFieldInitializers.

/**
     * Write code to initialize the static fields for each method
     * using the Java Reflection API.
     */
private void writeMethodFieldInitializers(IndentingWriter p) throws IOException {
    for (int i = 0; i < methodFieldNames.length; i++) {
        p.p(methodFieldNames[i] + " = ");
        /*
             * Here we look up the Method object in the arbitrary interface
             * that we find in the RemoteClass.Method object.
             * REMIND: Is this arbitrary choice OK?
             * REMIND: Should this access be part of RemoteClass.Method's
             * abstraction?
             */
        RemoteClass.Method method = remoteMethods[i];
        MemberDefinition def = method.getMemberDefinition();
        Identifier methodName = method.getName();
        Type methodType = method.getType();
        Type[] paramTypes = methodType.getArgumentTypes();
        p.p(def.getClassDefinition().getName() + ".class.getMethod(\"" + methodName + "\", new java.lang.Class[] {");
        for (int j = 0; j < paramTypes.length; j++) {
            if (j > 0)
                p.p(", ");
            p.p(paramTypes[j] + ".class");
        }
        p.pln("});");
    }
}
Also used : Type(sun.tools.java.Type) Identifier(sun.tools.java.Identifier) MemberDefinition(sun.tools.java.MemberDefinition)

Aggregations

Identifier (sun.tools.java.Identifier)2 MemberDefinition (sun.tools.java.MemberDefinition)2 Type (sun.tools.java.Type)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 DigestOutputStream (java.security.DigestOutputStream)1 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ClassDeclaration (sun.tools.java.ClassDeclaration)1