Code review request: 6973831 NPE when printing stack trace of OOME

David Holmes David.Holmes at oracle.com
Fri Aug 13 00:24:33 UTC 2010


Hi Mandy,

Mandy Chung said the following on 08/13/10 09:22:
> On 08/12/10 12:00, Rémi Forax wrote:
> 
>>> The "detailMessage" is not final because the VM in fact preallocates 
>>> Throwable object (OOME and ArithmeticException) and then sets the 
>>> 'detailMessage' field directly (as the constructor is not invoked). 
>>
>> I am pretty sure the VM can set this field even if it is declared final.
>> I think I don't see the problem.
>>
> 
> I will file a CR to address this and separate from this bug fix.  I 
> believe that the VM has no problem setting this field even if it's 
> declared final.  I may be overly cautious but I think we need the VM 
> team to evaluate this.

The VM doesn't even look at the finality of the field it just does a 
direct store into memory.

The issue with having the VM modify final fields in general is that the 
compiler might reorder/hoist a load of a final field not knowing that it 
might be changed by the VM. However that would only be a problem if the 
object concerned was already accessible at the Java level and that is 
not the case with the preallocated exception objects.

Making the detail message final should be fine - though not essential.

David



More information about the core-libs-dev mailing list