Fast Throw - Cached Exceptions

Chandan PR chandanpr at gmail.com
Wed Sep 25 21:22:56 PDT 2013


Hi ,

I was trying to understand returning cached instance of Exception during
fast throw.

After a bit of debugging in the hotspot VM code, was able to understand
most of it.

But lost a bit for NullPointerException case.

in hotspot/src/share/vm/opto/graphKit.cpp.null_check_common

in the case of T_OBJECT: we have the below code

// See if mixing in the NULL pointer changes type.

        // If so, then the NULL pointer was not allowed in the original

        // type.  In other words, "value" was not-null.

        if (t->meet(TypePtr::NULL_PTR) != t) {

          // same as: if (!TypePtr::NULL_PTR->higher_equal(t)) ...

          explicit_null_checks_elided++;

          return value;           // Elided null check quickly!

        }

For some reference types like String, StringBuffer mixing results in NUL
pointer for some others like Object or Interface reference types, the
mixing changes the NULL pointer type.


Was trying to understand the concept/logic and relation to pointer types
regarding this. But lost a bit.


My Sample program is below:

public class FastThrowDemo {

public static void main(String[] args) {

// StringBuffer obj = null;

// String obj = null;

// Object obj = null;

Serializable obj = null;

for (int i = 0; i < 10_000_00; i++) {

try {

obj.toString();

} catch (Exception e) {

}

}

try {

obj.toString();

} catch (Exception e) {

int length = e.getStackTrace().length;

if (length == 0) {

System.err.println("No Stack Trace");

} else {

System.out.println("Stack Trace length is " + length);

}

}

}

}

Any further information or pointers for further reading would be helpful.

-- 
Thanks and Regards,
Chandan.P.R
9945501674


More information about the hotspot-dev mailing list