On 01/17/2014 02:13 PM, Peter Levart wrote:
// Fast path for cleaners
boolean isCleaner = false;
try {
  isCleaner = r instanceof Cleaner;
} catch (OutofMemoryError oome) {

if (isCleaner) {

Hi David, Kalyan,

I've caught-up now. Just thinking: is "instanceof Cleaner" throwing OOME as a result of loading the Cleaner class? Wouldn't the above code then throw some error also in ((Cleaner)r) - the checkcast, since Cleaner class would not be successfully initialized?

Well, no. The above code would just skip Cleaner processing in this situation. And will never be doing it again after the heap is freed... So it might be good to load and initialize Cleaner class as part of ReferenceHandler initialization to ensure correct operation...

Well, yes and no. Let me try once more:

Above code will skip Cleaner processing if the 1st time "instanceof Cleaner" is executed, OOME is thrown as a consequence of full heap while loading and initializing the Cleaner class. The 2nd time the "instanceof Cleaner" is executed after such OOME, the same line would throw NoClassDefFoundError as a consequence of referencing a class that failed initialization. Am I right?

Regards, Peter

Reply via email to