--- old/src/share/classes/java/lang/ref/Reference.java 2013-05-16 12:42:01.784652558 +0200 +++ new/src/share/classes/java/lang/ref/Reference.java 2013-05-16 12:42:01.496652567 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -138,8 +138,17 @@ pending = r.discovered; r.discovered = null; } else { + // we explicitly cascade the two exceptions here to avoid + // double throw of OOME in case InterruptedException needs + // to be loaded during OOME caused by waiting for the + // lock to be signaled. + // The class loading may further trigger other secondary + // exceptions due to low memory that may cause the thread + // to terminate too. try { - lock.wait(); + try { + lock.wait(); + } catch (OutOfMemoryError x) { } } catch (InterruptedException x) { } continue; }