8146961: Fix PermGen memory leaks caused by static final Exceptions
Reviewed-by: joehw, shade, clanger, plevart
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/AbortException.java Thu Aug 18 16:56:31 2016 +0300
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.org.apache.xerces.internal.dom;
+
+public class AbortException extends RuntimeException {
+
+ private static final long serialVersionUID = 2608302175475740417L;
+
+ /**
+ * Constructor AbortException
+ */
+ public AbortException() { super(null, null, false, false); }
+}
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMNormalizer.java Tue Aug 16 17:35:47 2016 -0700
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMNormalizer.java Thu Aug 18 16:56:31 2016 +0300
@@ -26,6 +26,7 @@
import java.io.StringReader;
import java.util.Vector;
+import com.sun.org.apache.xerces.internal.dom.AbortException;
import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.impl.RevalidationHandler;
import com.sun.org.apache.xerces.internal.impl.dtd.DTDGrammar;
@@ -157,11 +158,6 @@
// attribute value normalization
final XMLString fNormalizedValue = new XMLString(new char[16], 0, 0);
- /**
- * If the user stops the process, this exception will be thrown.
- */
- public static final RuntimeException abort = new RuntimeException();
-
//DTD validator
private XMLDTDValidator fDTDValidator;
@@ -242,11 +238,8 @@
XMLGrammarDescription.XML_SCHEMA, fValidationHandler);
fValidationHandler = null;
}
- }
- catch (RuntimeException e) {
- if( e==abort )
- return; // processing aborted by the user
- throw e; // otherwise re-throw.
+ } catch (AbortException e) {
+ return;
}
}
@@ -1371,10 +1364,10 @@
error.fRelatedData = locator.fRelatedNode;
if(!errorHandler.handleError(error))
- throw abort;
+ throw new AbortException();
}
if( severity==DOMError.SEVERITY_FATAL_ERROR )
- throw abort;
+ throw new AbortException();
}
protected final void updateQName (Node node, QName qname){
@@ -2043,5 +2036,4 @@
return null;
}
-
} // DOMNormalizer class
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java Tue Aug 16 17:35:47 2016 -0700
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java Thu Aug 18 16:56:31 2016 +0300
@@ -28,6 +28,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
+import com.sun.org.apache.xerces.internal.dom.AbortException;
import com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl;
import com.sun.org.apache.xerces.internal.dom.DOMErrorImpl;
import com.sun.org.apache.xerces.internal.dom.DOMLocatorImpl;
@@ -501,11 +502,9 @@
} catch (LSException lse) {
// Rethrow LSException.
throw lse;
+ } catch (AbortException e) {
+ return null;
} catch (RuntimeException e) {
- if (e == DOMNormalizer.abort) {
- // stopped at user request
- return null;
- }
throw (LSException) DOMUtil.createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace();
} catch (IOException ioe) {
// REVISIT: A generic IOException doesn't provide enough information
@@ -733,11 +732,9 @@
} catch (LSException lse) {
// Rethrow LSException.
throw lse;
+ } catch (AbortException e) {
+ return false;
} catch (RuntimeException e) {
- if (e == DOMNormalizer.abort) {
- // stopped at user request
- return false;
- }
throw (LSException) DOMUtil.createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace();
} catch (Exception e) {
if (ser.fDOMErrorHandler != null) {
@@ -833,11 +830,9 @@
} catch (LSException lse) {
// Rethrow LSException.
throw lse;
+ } catch (AbortException e) {
+ return false;
} catch (RuntimeException e) {
- if (e == DOMNormalizer.abort) {
- // stopped at user request
- return false;
- }
throw (LSException) DOMUtil.createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace();
} catch (Exception e) {
if (ser.fDOMErrorHandler != null) {