Dynamic type in method substitution

Halimi, Jean-Philippe jean-philippe.halimi at intel.com
Fri Jan 18 00:05:37 UTC 2019


Dear all,

Happy new year! :)

I am spending time implementing DigestBase::shaImplCompressMultiBlock stub for Graal as it provides hashing performance improvement. The method is implemented in DigestBase base class, but the stub depends on which derived class the actual instance is of.

Quick diagram:

   DigestBase
     - Implements shaImplCompressMB
   |        \          \
SHA1  SHA2   SHA5
state state   state

Each SHA class has its own state object, but DigestBase implements the shaImplCompressMultiBlock intrinsified method. This stub needs to figure out which SHA class it is an instance of.

I have the following code:

    @MethodSubstitution(isStatic = false)
    static int shaImplCompressMB(Object receiver, byte[] buf, int ofs, int limit) {
        ResolvedJavaType type = INJECTED_INTRINSIC_CONTEXT.getIntrinsicMethod().getDeclaringClass();
        ResolvedJavaType sha1 = HotSpotReplacementsUtil.getType(INJECTED_INTRINSIC_CONTEXT, "sun/security/provider/SHA");
        ResolvedJavaType sha256 = HotSpotReplacementsUtil.getType(INJECTED_INTRINSIC_CONTEXT, "sun/security/provider/SHA2");
        ResolvedJavaType sha512 = HotSpotReplacementsUtil.getType(INJECTED_INTRINSIC_CONTEXT, "sun/security/provider/SHA5");

        if (type == sha1) {
            Object realReceiver = getRealReceiver(receiver);
            Object state = getState(realReceiver, "sun/security/provider/SHA");
            return HotSpotBackend.shaImplCompressMBStub(getBufAddr(buf, ofs), getStateAddr(state), ofs, limit);
        } else if (type == sha256) {
            Object realReceiver = getRealReceiver(receiver);
            Object state = getState(realReceiver, "sun/security/provider/SHA2");
            return HotSpotBackend.sha2ImplCompressMBStub(getBufAddr(buf, ofs), getStateAddr(state), ofs, limit);
        } else if (type == sha512) {
            Object realReceiver = getRealReceiver(receiver);
            Object state = getState(realReceiver, "sun/security/provider/SHA5");
            return HotSpotBackend.sha5ImplCompressMBStub(getBufAddr(buf, ofs), getStateAddr(state), ofs, limit);
        } else {
            return -1;
        }
    }

I would like to know if this is the correct way to proceed, especially lines 3 4 5 6, to respectively get the type of the object instance and the types of each derived class.

Thank you for your help.
-Jp


More information about the graal-dev mailing list