Throwable types handled specially in the VM?

Mandy Chung mandy.chung at oracle.com
Fri Aug 20 15:52:11 PDT 2010


Joe Darcy wrote:
> Hi David.
>
> David Holmes wrote:
>> Hi Joe,
>>
>> Joe Darcy said the following on 08/20/10 12:03:
>>> As part of Project Coin, try-with-resources/ARM blocks have recently 
>>> been integrated into JDK 7.  Part of this feature is changes to 
>>> java.lang.Throwable to support recording of suppressed exception 
>>> information (6911258 "Project Coin: Add essential API support for 
>>> Automatic Resource Management (ARM) blocks").  Subsequently, some 
>>> more changes in Throwable were necessary to fix a regression in the 
>>> ability to print the stack traces of specially handled 
>>> OutOfMemoryErrors (6973831 "NPE when printing stack trace of OOME").
>>>
>>> Are there any other Throwable types which receive special handling 
>>> or creation by the VM?  If there are any, I'd like to examine them 
>>> to find and correct and additional issues.
>>
>> All the preallocation of exceptions occurs in universe_post_init in 
>> universe.cpp. These are as follows
>>
>>     // Setup preallocated OutOfMemoryError errors
>>     Universe::_out_of_memory_error_java_heap = 
>> k_h->allocate_permanent_instance(CHECK_false);
>>     Universe::_out_of_memory_error_perm_gen = 
>> k_h->allocate_permanent_instance(CHECK_false);
>>     Universe::_out_of_memory_error_array_size = 
>> k_h->allocate_permanent_instance(CHECK_false);
>>     Universe::_out_of_memory_error_gc_overhead_limit =
>>       k_h->allocate_permanent_instance(CHECK_false);
>>
>>     // Setup preallocated NullPointerException
>>     // (this is currently used for a cheap & dirty solution in 
>> compiler exception handling)
>>     Universe::_null_ptr_exception_instance = 
>> instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false);
>>     // Setup preallocated ArithmeticException
>>     // (this is currently used for a cheap & dirty solution in 
>> compiler exception handling)
>>     Universe::_arithmetic_exception_instance = 
>> instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false);
>>     // Virtual Machine Error for when we get into a situation we 
>> can't resolve
>>     Universe::_virtual_machine_error_instance =
>>       instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false);
>>
>> As you're aware from 6973831 these are raw allocations that invoke no 
>> constructor, so all fields are implicitly set to their default (null, 
>> 0) values.
>
> Right.
>
>>
>> I can't think of any other specialized exception handling.
>>
> From the name "allocate_permanent_instance," I assume that these 
> exception objects are saved and reused for the lifetime of the JVM, 
> correct?  For better or worse, Throwable and its subclasses are 
> mutable; the suppressed warning information is a new possible 
> mutation, setting the stack trace is an existing mutability avenue.
>
> If so, as Remi has recently pointed out, perhaps these fields should 
> be cleared when the exceptions are resued?
>

FYI - this is tracked by 6978918.

Mandy
> From an API perspective, perhaps the suppression feature should be 
> modified so that self-suppression is interpreted as not allowing a 
> particular exception instance to record addition suppressed exceptions...
>
> -Joe



More information about the hotspot-dev mailing list