From 74ad666e62d03c3c52ef35d75cbc1f35759fee5b Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Wed, 18 Jun 2014 10:44:24 +0100 Subject: [PATCH 001/362] 8044187: Enhancements to InnocuousThread Reviewed-by: alanb --- .../classes/sun/misc/InnocuousThread.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java b/jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java index db431029484..37b9e62eca0 100644 --- a/jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java +++ b/jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java @@ -26,7 +26,10 @@ package sun.misc; import java.security.AccessControlContext; +import java.security.AccessController; import java.security.ProtectionDomain; +import java.security.PrivilegedAction; +import java.util.concurrent.atomic.AtomicInteger; /** * A thread that has no permissions, is not a member of any user-defined @@ -36,22 +39,35 @@ import java.security.ProtectionDomain; */ public final class InnocuousThread extends Thread { private static final Unsafe UNSAFE; - private static final ThreadGroup THREADGROUP; + private static final ThreadGroup INNOCUOUSTHREADGROUP; private static final AccessControlContext ACC; private static final long THREADLOCALS; private static final long INHERITABLETHREADLOCALS; private static final long INHERITEDACCESSCONTROLCONTEXT; + private static final AtomicInteger threadNumber = new AtomicInteger(1); + public InnocuousThread(Runnable target) { - super(THREADGROUP, target, "anInnocuousThread"); + this(INNOCUOUSTHREADGROUP, target, + "InnocuousThread-" + threadNumber.getAndIncrement()); + } + + public InnocuousThread(Runnable target, String name) { + this(INNOCUOUSTHREADGROUP, target, name); + } + + private InnocuousThread(ThreadGroup group, Runnable target, String name) { + super(group, target, name); UNSAFE.putOrderedObject(this, INHERITEDACCESSCONTROLCONTEXT, ACC); eraseThreadLocals(); } + // always report system class loader, or null + private ClassLoader contextClassLoader = ClassLoader.getSystemClassLoader(); + @Override public ClassLoader getContextClassLoader() { - // always report system class loader - return ClassLoader.getSystemClassLoader(); + return contextClassLoader; } @Override @@ -61,7 +77,10 @@ public final class InnocuousThread extends Thread { @Override public void setContextClassLoader(ClassLoader cl) { - throw new SecurityException("setContextClassLoader"); + if (cl == null) + contextClassLoader = null; + else + throw new SecurityException("setContextClassLoader"); } // ensure run method is run only once @@ -113,7 +132,10 @@ public final class InnocuousThread extends Thread { break; group = parent; } - THREADGROUP = new ThreadGroup(group, "InnocuousThreadGroup"); + final ThreadGroup root = group; + INNOCUOUSTHREADGROUP = AccessController.doPrivileged( + (PrivilegedAction) () -> + { return new ThreadGroup(root, "InnocuousThreadGroup"); }); } catch (Exception e) { throw new Error(e); } From 4b6b14f69e642e94eb5561dd04e321ecd850f258 Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Thu, 26 Jun 2014 14:49:23 +0100 Subject: [PATCH 002/362] 8048210: More Enhancements to InnocuousThread and friends Reviewed-by: alanb, pchelko, jbachorik --- .../classes/sun/misc/InnocuousThread.java | 36 ++------- .../classes/sun/misc/ManagedLocalsThread.java | 73 +++++++++++++++++++ 2 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java diff --git a/jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java b/jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java index 37b9e62eca0..78a0a185f0a 100644 --- a/jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java +++ b/jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java @@ -34,16 +34,13 @@ import java.util.concurrent.atomic.AtomicInteger; /** * A thread that has no permissions, is not a member of any user-defined * ThreadGroup and supports the ability to erase ThreadLocals. - * - * @implNote Based on the implementation of InnocuousForkJoinWorkerThread. */ -public final class InnocuousThread extends Thread { +public final class InnocuousThread extends ManagedLocalsThread { private static final Unsafe UNSAFE; private static final ThreadGroup INNOCUOUSTHREADGROUP; private static final AccessControlContext ACC; - private static final long THREADLOCALS; - private static final long INHERITABLETHREADLOCALS; private static final long INHERITEDACCESSCONTROLCONTEXT; + private static final long CONTEXTCLASSLOADER; private static final AtomicInteger threadNumber = new AtomicInteger(1); @@ -56,18 +53,10 @@ public final class InnocuousThread extends Thread { this(INNOCUOUSTHREADGROUP, target, name); } - private InnocuousThread(ThreadGroup group, Runnable target, String name) { + public InnocuousThread(ThreadGroup group, Runnable target, String name) { super(group, target, name); UNSAFE.putOrderedObject(this, INHERITEDACCESSCONTROLCONTEXT, ACC); - eraseThreadLocals(); - } - - // always report system class loader, or null - private ClassLoader contextClassLoader = ClassLoader.getSystemClassLoader(); - - @Override - public ClassLoader getContextClassLoader() { - return contextClassLoader; + UNSAFE.putOrderedObject(this, CONTEXTCLASSLOADER, ClassLoader.getSystemClassLoader()); } @Override @@ -77,8 +66,9 @@ public final class InnocuousThread extends Thread { @Override public void setContextClassLoader(ClassLoader cl) { + // Allow clearing of the TCCL to remove the reference to the system classloader. if (cl == null) - contextClassLoader = null; + super.setContextClassLoader(null); else throw new SecurityException("setContextClassLoader"); } @@ -94,14 +84,6 @@ public final class InnocuousThread extends Thread { } } - /** - * Drops all thread locals (and inherited thread locals). - */ - public void eraseThreadLocals() { - UNSAFE.putObject(this, THREADLOCALS, null); - UNSAFE.putObject(this, INHERITABLETHREADLOCALS, null); - } - // Use Unsafe to access Thread group and ThreadGroup parent fields static { try { @@ -114,12 +96,10 @@ public final class InnocuousThread extends Thread { Class tk = Thread.class; Class gk = ThreadGroup.class; - THREADLOCALS = UNSAFE.objectFieldOffset - (tk.getDeclaredField("threadLocals")); - INHERITABLETHREADLOCALS = UNSAFE.objectFieldOffset - (tk.getDeclaredField("inheritableThreadLocals")); INHERITEDACCESSCONTROLCONTEXT = UNSAFE.objectFieldOffset (tk.getDeclaredField("inheritedAccessControlContext")); + CONTEXTCLASSLOADER = UNSAFE.objectFieldOffset + (tk.getDeclaredField("contextClassLoader")); long tg = UNSAFE.objectFieldOffset(tk.getDeclaredField("group")); long gp = UNSAFE.objectFieldOffset(gk.getDeclaredField("parent")); diff --git a/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java b/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java new file mode 100644 index 00000000000..49298dca610 --- /dev/null +++ b/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2014, 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 sun.misc; + +/** + * A thread that has it's thread locals, and inheritable thread + * locals erased on construction. + */ +public class ManagedLocalsThread extends Thread { + private static final Unsafe UNSAFE; + private static final long THREAD_LOCALS; + private static final long INHERITABLE_THREAD_LOCALS; + + public ManagedLocalsThread(Runnable target) { + super(target); + eraseThreadLocals(); + } + + public ManagedLocalsThread(Runnable target, String name) { + super(target, name); + eraseThreadLocals(); + } + + public ManagedLocalsThread(ThreadGroup group, Runnable target, String name) { + super(group, target, name); + eraseThreadLocals(); + } + + /** + * Drops all thread locals (and inherited thread locals). + */ + public final void eraseThreadLocals() { + UNSAFE.putObject(this, THREAD_LOCALS, null); + UNSAFE.putObject(this, INHERITABLE_THREAD_LOCALS, null); + } + + static { + UNSAFE = Unsafe.getUnsafe(); + Class t = Thread.class; + try { + THREAD_LOCALS = UNSAFE.objectFieldOffset + (t.getDeclaredField("threadLocals")); + INHERITABLE_THREAD_LOCALS = UNSAFE.objectFieldOffset + (t.getDeclaredField("inheritableThreadLocals")); + } catch (Exception e) { + throw new Error(e); + } + } +} + From b8ae69575c3d80971e443f4ca6e473771df8fe7d Mon Sep 17 00:00:00 2001 From: Alexander Zvegintsev Date: Tue, 11 Nov 2014 17:36:43 +0300 Subject: [PATCH 003/362] 8060461: Fix for JDK-8042609 uncovers additional issue Reviewed-by: ahgross, prr, serb --- .../unix/native/libsplashscreen/splashscreen_sys.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jdk/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c b/jdk/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c index 85a93042f1d..ed3bfaa1108 100644 --- a/jdk/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c +++ b/jdk/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2014, 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 @@ -281,9 +281,7 @@ SplashCreateWindow(Splash * splash) { /* for changing the visible shape of a window to an nonrectangular form */ void SplashUpdateShape(Splash * splash) { - if (!shapeSupported) - return; - if (!splash->maskRequired) { + if (splash->currentFrame < 0 || !shapeSupported || !splash->maskRequired) { return; } XShapeCombineRectangles(splash->display, splash->window, ShapeClip, 0, 0, @@ -324,6 +322,10 @@ ByteOrderToX(int byteOrder) { void SplashRedrawWindow(Splash * splash) { + if (splash->currentFrame < 0) { + return; + } + XImage *ximage; // making this method redraw a part of the image does not make From 81c5390912a85432db7dc9cbcceb09a7f84607e9 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Thu, 18 Dec 2014 10:43:02 -0800 Subject: [PATCH 004/362] 8065286: Fewer subtable substitutions Reviewed-by: bae, srl, mschoene --- .../native/libfontmanager/layout/MultipleSubstSubtables.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jdk/src/java.desktop/share/native/libfontmanager/layout/MultipleSubstSubtables.cpp b/jdk/src/java.desktop/share/native/libfontmanager/layout/MultipleSubstSubtables.cpp index 5ed9a3a532c..e6e7d533eb6 100644 --- a/jdk/src/java.desktop/share/native/libfontmanager/layout/MultipleSubstSubtables.cpp +++ b/jdk/src/java.desktop/share/native/libfontmanager/layout/MultipleSubstSubtables.cpp @@ -71,6 +71,9 @@ le_uint32 MultipleSubstitutionSubtable::process(const LETableReference &base, Gl if (coverageIndex >= 0 && coverageIndex < seqCount) { Offset sequenceTableOffset = SWAPW(sequenceTableOffsetArray[coverageIndex]); LEReferenceTo sequenceTable(base, success, sequenceTableOffset); + if (LE_FAILURE(success)) { + return 0; + } le_uint16 glyphCount = SWAPW(sequenceTable->glyphCount); if (glyphCount == 0) { From 5299b605ee6b8f0673349ca8825ce2c57c97e32f Mon Sep 17 00:00:00 2001 From: Phil Race Date: Thu, 18 Dec 2014 10:45:02 -0800 Subject: [PATCH 005/362] 8065291: Improved font lookups Reviewed-by: bae, srl, mschoene --- .../share/native/libfontmanager/layout/LookupProcessor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jdk/src/java.desktop/share/native/libfontmanager/layout/LookupProcessor.cpp b/jdk/src/java.desktop/share/native/libfontmanager/layout/LookupProcessor.cpp index b5d750d9a98..0629e9d6da1 100644 --- a/jdk/src/java.desktop/share/native/libfontmanager/layout/LookupProcessor.cpp +++ b/jdk/src/java.desktop/share/native/libfontmanager/layout/LookupProcessor.cpp @@ -255,6 +255,7 @@ LookupProcessor::LookupProcessor(const LETableReference &baseAddress, if (requiredFeatureIndex != 0xFFFF) { requiredFeatureTable = featureListTable->getFeatureTable(featureListTable, requiredFeatureIndex, &requiredFeatureTag, success); + if (LE_FAILURE(success)) return; featureReferences += SWAPW(requiredFeatureTable->lookupCount); } @@ -292,7 +293,7 @@ LookupProcessor::LookupProcessor(const LETableReference &baseAddress, } featureTable = featureListTable->getFeatureTable(featureListTable, featureIndex, &featureTag, success); - + if (LE_FAILURE(success)) continue; if (featureTag == fm.tag) { count += selectLookups(featureTable, fm.mask, order + count, success); } @@ -319,7 +320,7 @@ LookupProcessor::LookupProcessor(const LETableReference &baseAddress, #endif featureTable = featureListTable->getFeatureTable(featureListTable, featureIndex, &featureTag, success); - + if (LE_FAILURE(success)) continue; if (featureTag == fm.tag) { order += selectLookups(featureTable, fm.mask, order, success); } From c60792dc47946cccabc6c77ce6cb98cbc1f0c134 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Thu, 18 Dec 2014 10:45:45 -0800 Subject: [PATCH 006/362] 8067050: Better font consistency checking Reviewed-by: bae, srl, mschoene --- .../share/native/libfontmanager/layout/LETableReference.h | 4 ++-- .../native/libfontmanager/layout/LigatureSubstSubtables.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jdk/src/java.desktop/share/native/libfontmanager/layout/LETableReference.h b/jdk/src/java.desktop/share/native/libfontmanager/layout/LETableReference.h index 6afd3c1c13b..459d4e08806 100644 --- a/jdk/src/java.desktop/share/native/libfontmanager/layout/LETableReference.h +++ b/jdk/src/java.desktop/share/native/libfontmanager/layout/LETableReference.h @@ -150,8 +150,8 @@ public: if(isEmpty()) { //err = LE_MISSING_FONT_TABLE_ERROR; clear(); // it's just empty. Not an error. - } else if(offset >= fParent->fLength) { - LE_DEBUG_TR3("offset out of range: (%p) +%d", NULL, offset); + } else if(offset >= fParent->fLength || (offset & 0x01)) { + LE_DEBUG_TR3("offset out of range or odd alignment: (%p) +%d", NULL, offset); err = LE_INDEX_OUT_OF_BOUNDS_ERROR; clear(); } else { diff --git a/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstSubtables.cpp b/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstSubtables.cpp index 8e0e7cdd2b8..55209409578 100644 --- a/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstSubtables.cpp +++ b/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstSubtables.cpp @@ -58,7 +58,7 @@ le_uint32 LigatureSubstitutionSubtable::process(const LETableReference &base, Gl if( LE_FAILURE(success) ) { return 0; } le_uint16 ligCount = SWAPW(ligSetTable->ligatureCount); - LEReferenceTo ligatureTableOffsetArray(base, success, ligSetTable->ligatureTableOffsetArray, ligCount); + LEReferenceToArrayOf ligatureTableOffsetArray(base, success, ligSetTable->ligatureTableOffsetArray, ligCount); for (le_uint16 lig = 0; LE_SUCCESS(success) && lig < ligCount; lig += 1) { Offset ligTableOffset = SWAPW(ligSetTable->ligatureTableOffsetArray[lig]); LEReferenceTo ligTable(ligSetTable, success, ligTableOffset); From dca06c50cb5a99f50923011cfe68e072a38564cf Mon Sep 17 00:00:00 2001 From: Jason Uh Date: Fri, 19 Dec 2014 14:48:56 -0800 Subject: [PATCH 007/362] 8066479: Better certificate chain validation Reviewed-by: mullan --- .../sun/security/pkcs12/PKCS12KeyStore.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/jdk/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java b/jdk/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java index 354a644e37e..1f52015392c 100644 --- a/jdk/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java +++ b/jdk/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java @@ -716,6 +716,11 @@ public final class PKCS12KeyStore extends KeyStoreSpi { entry.protectedPrivKey = key.clone(); if (chain != null) { + // validate cert-chain + if ((chain.length > 1) && (!validateChain(chain))) { + throw new KeyStoreException("Certificate chain is " + + "not valid"); + } entry.chain = chain.clone(); certificateCount += chain.length; @@ -1490,7 +1495,12 @@ public final class PKCS12KeyStore extends KeyStoreSpi { if (!(issuerDN.equals(subjectDN))) return false; } - return true; + + // Check for loops in the chain. If there are repeated certs, + // the Set of certs in the chain will contain fewer certs than + // the chain + Set set = new HashSet<>(Arrays.asList(certChain)); + return set.size() == certChain.length; } @@ -2070,7 +2080,24 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ArrayList chain = new ArrayList(); X509Certificate cert = findMatchedCertificate(entry); + + mainloop: while (cert != null) { + // Check for loops in the certificate chain + if (!chain.isEmpty()) { + for (X509Certificate chainCert : chain) { + if (cert.equals(chainCert)) { + if (debug != null) { + debug.println("Loop detected in " + + "certificate chain. Skip adding " + + "repeated cert to chain. Subject: " + + cert.getSubjectX500Principal() + .toString()); + } + break mainloop; + } + } + } chain.add(cert); X500Principal issuerDN = cert.getIssuerX500Principal(); if (issuerDN.equals(cert.getSubjectX500Principal())) { From e840a34dc22ddd4d6a1341d14545aedcd6d11133 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Wed, 7 Jan 2015 13:10:00 -0800 Subject: [PATCH 008/362] 8067684: Better font substitutions Reviewed-by: bae, srl, mschoene --- .../native/libfontmanager/layout/MultipleSubstSubtables.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jdk/src/java.desktop/share/native/libfontmanager/layout/MultipleSubstSubtables.cpp b/jdk/src/java.desktop/share/native/libfontmanager/layout/MultipleSubstSubtables.cpp index e6e7d533eb6..f0da2f0f812 100644 --- a/jdk/src/java.desktop/share/native/libfontmanager/layout/MultipleSubstSubtables.cpp +++ b/jdk/src/java.desktop/share/native/libfontmanager/layout/MultipleSubstSubtables.cpp @@ -75,6 +75,8 @@ le_uint32 MultipleSubstitutionSubtable::process(const LETableReference &base, Gl return 0; } le_uint16 glyphCount = SWAPW(sequenceTable->glyphCount); + LEReferenceToArrayOf + substituteArrayRef(base, success, sequenceTable->substituteArray, glyphCount); if (glyphCount == 0) { glyphIterator->setCurrGlyphID(0xFFFF); From ecdd3ad65a1f6e6304547672e920538434db2579 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Thu, 15 Jan 2015 09:47:06 -0800 Subject: [PATCH 009/362] 8067699: Better glyph storage Reviewed-by: srl, bae, mschoene --- .../share/native/libfontmanager/layout/LigatureSubstProc.cpp | 2 +- .../share/native/libfontmanager/layout/LigatureSubstProc2.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstProc.cpp b/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstProc.cpp index 0014b95a515..99e9e37dd68 100644 --- a/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstProc.cpp +++ b/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstProc.cpp @@ -115,7 +115,7 @@ ByteOffset LigatureSubstitutionProcessor::processStateEntry(LEGlyphStorage &glyp LE_DEBUG_BAD_FONT("off end of ligature substitution header"); return newState; // get out! bad font } - if(componentGlyph > glyphStorage.getGlyphCount()) { + if(componentGlyph >= glyphStorage.getGlyphCount()) { LE_DEBUG_BAD_FONT("preposterous componentGlyph"); currGlyph++; return newState; // get out! bad font diff --git a/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstProc2.cpp b/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstProc2.cpp index 8e5b1cfa93d..558cf8b1ae0 100644 --- a/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstProc2.cpp +++ b/jdk/src/java.desktop/share/native/libfontmanager/layout/LigatureSubstProc2.cpp @@ -119,7 +119,7 @@ le_uint16 LigatureSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyp offset = action & lafComponentOffsetMask; if (offset != 0) { - if(componentGlyph > glyphStorage.getGlyphCount()) { + if(componentGlyph >= glyphStorage.getGlyphCount()) { LE_DEBUG_BAD_FONT("preposterous componentGlyph"); currGlyph+= dir; return nextStateIndex; // get out! bad font From e307e3921e733486f037f87fdcbf747b87c8b413 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Sun, 18 Jan 2015 23:28:36 +0300 Subject: [PATCH 010/362] 8068320: Limit applet requests Reviewed-by: prr, skoivu, art --- .../data/swingbeaninfo/SwingBeanInfo.template | 33 ++++++++---- .../share/classes/java/beans/Beans.java | 36 ++++--------- .../classes/java/beans/SimpleBeanInfo.java | 45 ++++++---------- .../LoadingStandardIcons.java | 53 +++++++++++++++++++ .../LoadingStandardIcons/java.policy | 1 + 5 files changed, 103 insertions(+), 65 deletions(-) create mode 100644 jdk/test/java/beans/SimpleBeanInfo/LoadingStandardIcons/LoadingStandardIcons.java create mode 100644 jdk/test/java/beans/SimpleBeanInfo/LoadingStandardIcons/java.policy diff --git a/jdk/make/data/swingbeaninfo/SwingBeanInfo.template b/jdk/make/data/swingbeaninfo/SwingBeanInfo.template index 9c1a133f67f..e0c83c0e2cf 100644 --- a/jdk/make/data/swingbeaninfo/SwingBeanInfo.template +++ b/jdk/make/data/swingbeaninfo/SwingBeanInfo.template @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -92,25 +92,38 @@ public class @(BeanClassName)BeanInfo extends javax.swing.SwingBeanInfoBase { /** * @return an icon of the specified kind for @(BeanClassName) */ - public Image getIcon(int kind) { + public Image getIcon(final int kind) { Image i; switch (kind){ case ICON_COLOR_32x32: - i = loadImage("beaninfo/images/@(BeanClassName)Color32.gif"); - return ((i == null) ? loadImage("beaninfo/images/JComponentColor32.gif") : i); + i = loadStandardImage("beaninfo/images/@(BeanClassName)Color32.gif"); + return ((i == null) ? loadStandardImage("beaninfo/images/JComponentColor32.gif") : i); case ICON_COLOR_16x16: - i = loadImage("beaninfo/images/@(BeanClassName)Color16.gif"); - return ((i == null) ? loadImage("beaninfo/images/JComponentColor16.gif") : i); + i = loadStandardImage("beaninfo/images/@(BeanClassName)Color16.gif"); + return ((i == null) ? loadStandardImage("beaninfo/images/JComponentColor16.gif") : i); case ICON_MONO_32x32: - i = loadImage("beaninfo/images/@(BeanClassName)Mono32.gif"); - return ((i == null) ? loadImage("beaninfo/images/JComponentMono32.gif") : i); + i = loadStandardImage("beaninfo/images/@(BeanClassName)Mono32.gif"); + return ((i == null) ? loadStandardImage("beaninfo/images/JComponentMono32.gif") : i); case ICON_MONO_16x16: - i = loadImage("beaninfo/images/@(BeanClassName)Mono16.gif"); - return ((i == null) ? loadImage("beaninfo/images/JComponentMono16.gif") : i); + i = loadStandardImage("beaninfo/images/@(BeanClassName)Mono16.gif"); + return ((i == null) ? loadStandardImage("beaninfo/images/JComponentMono16.gif") : i); default: return super.getIcon(kind); } } + + /** + * This is a utility method to help in loading standard icon images. + * + * @param resourceName A pathname relative to the directory holding the + * class file of the current class + * @return an image object. May be null if the load failed. + * @see java.beans.SimpleBeanInfo#loadImage(String) + */ + private Image loadStandardImage(final String resourceName) { + return java.security.AccessController.doPrivileged( + (java.security.PrivilegedAction) () -> loadImage(resourceName)); + } } diff --git a/jdk/src/java.desktop/share/classes/java/beans/Beans.java b/jdk/src/java.desktop/share/classes/java/beans/Beans.java index cd864899ea6..81fe09a71dd 100644 --- a/jdk/src/java.desktop/share/classes/java/beans/Beans.java +++ b/jdk/src/java.desktop/share/classes/java/beans/Beans.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2015, 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 @@ -46,9 +46,6 @@ import java.lang.reflect.Modifier; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; - import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; @@ -183,16 +180,10 @@ public class Beans { // Try to find a serialized object with this name final String serName = beanName.replace('.','/').concat(".ser"); - final ClassLoader loader = cls; - ins = AccessController.doPrivileged - (new PrivilegedAction() { - public InputStream run() { - if (loader == null) - return ClassLoader.getSystemResourceAsStream(serName); - else - return loader.getResourceAsStream(serName); - } - }); + if (cls == null) + ins = ClassLoader.getSystemResourceAsStream(serName); + else + ins = cls.getResourceAsStream(serName); if (ins != null) { try { if (cls == null) { @@ -283,19 +274,10 @@ public class Beans { URL docBase = null; // Now get the URL correponding to the resource name. - - final ClassLoader cloader = cls; - objectUrl = - AccessController.doPrivileged - (new PrivilegedAction() { - public URL run() { - if (cloader == null) - return ClassLoader.getSystemResource - (resourceName); - else - return cloader.getResource(resourceName); - } - }); + if (cls == null) { + objectUrl = ClassLoader.getSystemResource(resourceName); + } else + objectUrl = cls.getResource(resourceName); // If we found a URL, we try to locate the docbase by taking // of the final path name component, and the code base by taking diff --git a/jdk/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java b/jdk/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java index 7b97e414ebb..45d5b44ba58 100644 --- a/jdk/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java +++ b/jdk/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2015, 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 @@ -25,6 +25,11 @@ package java.beans; +import java.awt.Image; +import java.awt.Toolkit; +import java.awt.image.ImageProducer; +import java.net.URL; + /** * This is a support class to make it easier for people to provide * BeanInfo classes. @@ -101,7 +106,7 @@ public class SimpleBeanInfo implements BeanInfo { * Claim there are no icons available. You can override * this if you want to provide icons for your bean. */ - public java.awt.Image getIcon(int iconKind) { + public Image getIcon(int iconKind) { return null; } @@ -116,33 +121,17 @@ public class SimpleBeanInfo implements BeanInfo { * "wombat.gif". * @return an image object. May be null if the load failed. */ - public java.awt.Image loadImage(final String resourceName) { + public Image loadImage(final String resourceName) { try { - final Class c = getClass(); - java.awt.image.ImageProducer ip = (java.awt.image.ImageProducer) - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - java.net.URL url; - if ((url = c.getResource(resourceName)) == null) { - return null; - } else { - try { - return url.getContent(); - } catch (java.io.IOException ioe) { - return null; - } - } - } - }); - - if (ip == null) - return null; - java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit(); - return tk.createImage(ip); - } catch (Exception ex) { - return null; + final URL url = getClass().getResource(resourceName); + if (url != null) { + final ImageProducer ip = (ImageProducer) url.getContent(); + if (ip != null) { + return Toolkit.getDefaultToolkit().createImage(ip); + } + } + } catch (final Exception ignored) { } + return null; } - } diff --git a/jdk/test/java/beans/SimpleBeanInfo/LoadingStandardIcons/LoadingStandardIcons.java b/jdk/test/java/beans/SimpleBeanInfo/LoadingStandardIcons/LoadingStandardIcons.java new file mode 100644 index 00000000000..9b96bd2f668 --- /dev/null +++ b/jdk/test/java/beans/SimpleBeanInfo/LoadingStandardIcons/LoadingStandardIcons.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +import java.awt.Image; +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; + +import javax.swing.JButton; + +/** + * @test + * @bug 4141523 + * @run main/othervm/policy=java.policy -Djava.security.manager LoadingStandardIcons + */ +public final class LoadingStandardIcons { + + public static void main(final String[] args) { + final Object bi; + try { + bi = Introspector.getBeanInfo(JButton.class); + } catch (IntrospectionException e) { + throw new RuntimeException(e); + } + final Image m16 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_MONO_16x16); + final Image m32 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_MONO_32x32); + final Image c16 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_COLOR_16x16); + final Image c32 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_COLOR_32x32); + if (m16 == null || m32 == null || c16 == null || c32 == null) { + throw new RuntimeException("Image should not be null"); + } + } +} diff --git a/jdk/test/java/beans/SimpleBeanInfo/LoadingStandardIcons/java.policy b/jdk/test/java/beans/SimpleBeanInfo/LoadingStandardIcons/java.policy new file mode 100644 index 00000000000..1c8a0e79762 --- /dev/null +++ b/jdk/test/java/beans/SimpleBeanInfo/LoadingStandardIcons/java.policy @@ -0,0 +1 @@ +; \ No newline at end of file From 31896469fd9005f38987877242fbd7c6e1574e4e Mon Sep 17 00:00:00 2001 From: Alexander Zvegintsev Date: Mon, 19 Jan 2015 20:02:31 +0300 Subject: [PATCH 011/362] 8069198: Upgrade image library Reviewed-by: ahgross, bae, mschoene, serb --- .../native/libsplashscreen/libpng/CHANGES | 1656 ++++++- .../native/libsplashscreen/libpng/LICENSE | 6 +- .../native/libsplashscreen/libpng/README | 63 +- .../share/native/libsplashscreen/libpng/png.c | 3069 ++++++++++-- .../share/native/libsplashscreen/libpng/png.h | 1920 +++++--- .../native/libsplashscreen/libpng/pngconf.h | 523 +- .../native/libsplashscreen/libpng/pngdebug.h | 21 +- .../native/libsplashscreen/libpng/pngerror.c | 509 +- .../native/libsplashscreen/libpng/pngget.c | 513 +- .../native/libsplashscreen/libpng/pnginfo.h | 75 +- .../libsplashscreen/libpng/pnglibconf.h | 195 +- .../native/libsplashscreen/libpng/pngmem.c | 744 +-- .../native/libsplashscreen/libpng/pngpread.c | 1126 +---- .../native/libsplashscreen/libpng/pngpriv.h | 1762 ++++--- .../native/libsplashscreen/libpng/pngread.c | 4059 +++++++++++++--- .../native/libsplashscreen/libpng/pngrio.c | 72 +- .../native/libsplashscreen/libpng/pngrtran.c | 2090 ++++---- .../native/libsplashscreen/libpng/pngrutil.c | 4222 ++++++++++------- .../native/libsplashscreen/libpng/pngset.c | 1098 +++-- .../native/libsplashscreen/libpng/pngstruct.h | 266 +- .../native/libsplashscreen/libpng/pngtest.c | 1050 ++-- .../native/libsplashscreen/libpng/pngtrans.c | 275 +- .../native/libsplashscreen/libpng/pngwio.c | 114 +- .../native/libsplashscreen/libpng/pngwrite.c | 1808 +++++-- .../native/libsplashscreen/libpng/pngwtran.c | 255 +- .../native/libsplashscreen/libpng/pngwutil.c | 2086 ++++---- 26 files changed, 19454 insertions(+), 10123 deletions(-) diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/CHANGES b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/CHANGES index 44ce7dd46ac..443187481ba 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/CHANGES +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/CHANGES @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -23,8 +23,6 @@ * questions. */ -#if 0 -libpng_changes(){ /* CHANGES - changes for libpng Version 0.2 @@ -205,7 +203,7 @@ Version 0.96 [May, 1997] Fixed serious bug with < 8bpp images introduced in 0.95 Fixed 256-color transparency bug (Greg Roelofs) Fixed up documentation (Greg Roelofs, Laszlo Nyul) - Fixed "error" in pngconf.h for Linux setjmp() behaviour + Fixed "error" in pngconf.h for Linux setjmp() behavior Fixed DOS medium model support (Tim Wegner) Fixed png_check_keyword() for case with error in static string text Added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul) @@ -222,18 +220,20 @@ Version 0.97 [January, 1998] Added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P) Minor corrections in libpng.txt Added simple sRGB support (Glenn R-P) - Easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED; + Easier conditional compiling, e.g., + define PNG_READ/WRITE_NOT_FULLY_SUPPORTED; all configurable options can be selected from command-line instead of having to edit pngconf.h (Glenn R-P) Fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P) Added more conditions for png_do_background, to avoid changing black pixels to background when a background is supplied and no pixels are transparent - Repaired PNG_NO_STDIO behaviour - Tested NODIV support and made it default behaviour (Greg Roelofs) + Repaired PNG_NO_STDIO behavior + Tested NODIV support and made it default behavior (Greg Roelofs) Added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler) Regularized version numbering scheme and bumped shared-library major - version number to 2 to avoid problems with libpng 0.89 apps (Greg Roelofs) + version number to 2 to avoid problems with libpng 0.89 apps + (Greg Roelofs) Version 0.98 [January, 1998] Cleaned up some typos in libpng.txt and in code documentation @@ -1803,7 +1803,7 @@ Version 1.2.13beta1 [October 2, 2006] Removed AC_FUNC_MALLOC from configure.ac Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h Change "logical" to "bitwise" throughout documentation. - Detect and fix attempt to write wrong iCCP profile length. + Detect and fix attempt to write wrong iCCP profile length (CVE-2006-7244) Version 1.0.21, 1.2.13 [November 14, 2006] Fix potential buffer overflow in sPLT chunk handler. @@ -2126,7 +2126,7 @@ Version 1.4.0beta24 [July 25, 2008] png_decompress_chunk(), and remove "chunkdata" from parameter list. Put a call to png_check_chunk_name() in png_read_chunk_header(). Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte. - Removed two calls to png_check_chunk_name() occurring later in the process. + Removed two calls to png_check_chunk_name() occuring later in the process. Define PNG_NO_ERROR_NUMBERS by default in pngconf.h Version 1.4.0beta25 [July 30, 2008] @@ -2386,7 +2386,7 @@ Version 1.4.0beta72 [August 1, 2009] Version 1.4.0beta73 [August 1, 2009] Reject attempt to write iCCP chunk with negative embedded profile length - (JD Chen) + (JD Chen) (CVE-2009-5063). Version 1.4.0beta74 [August 8, 2009] Changed png_ptr and info_ptr member "trans" to "trans_alpha". @@ -3174,8 +3174,8 @@ version 1.5.1beta01 [January 8, 2011] in version 1.5.0beta36 but is not noted in the CHANGES. Similarly, it was changed from png_charpp to png_const_bytepp in png_set_iCCP(). Ensure that png_rgb_to_gray ignores palette mapped images, if libpng - internally happens to call it with one. - Fixed a failure to handle palette mapped images correctly. + internally happens to call it with one, and fixed a failure to handle + palette mapped images correctly. This fixes CVE-2690. Version 1.5.1beta02 [January 14, 2011] Fixed a bug in handling of interlaced images (bero at arklinux.org). @@ -3314,8 +3314,8 @@ Version 1.5.2 [March 31, 2011] Version 1.5.3beta01 [April 1, 2011] Re-initialize the zlib compressor before compressing non-IDAT chunks. - Added API functions to set parameters for zlib compression of non-IDAT - chunks. + Added API functions (png_set_text_compression_level() and four others) to + set parameters for zlib compression of non-IDAT chunks. Version 1.5.3beta02 [April 3, 2011] Updated scripts/symbols.def with new API functions. @@ -3372,7 +3372,7 @@ Version 1.5.3beta05 [May 6, 2011] dependency of the tIME-supporting RFC1132 code on stdio is removed and PNG_NO_WARNINGS does actually work now. Pass "" instead of '\0' to png_default_error() in png_err(). This mistake - was introduced in libpng-1.2.20beta01. + was introduced in libpng-1.2.20beta01. This fixes CVE-2011-2691. Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte optimization configureable. IDAT compression failed if preceded by a compressed text chunk (bug @@ -3403,7 +3403,8 @@ Version 1.5.3beta08 [May 16, 2011] Documented png_set_alpha_mode(), other changes in libpng.3/libpng-manual.txt The cHRM chunk now sets the defaults for png_set_rgb_to_gray() (when negative parameters are supplied by the caller), while in the absence of cHRM - sRGB/Rec 709 values are still used. + sRGB/Rec 709 values are still used. This introduced a divide-by-zero + bug in png_handle_cHRM(). The bKGD chunk no longer overwrites the background value set by png_set_background(), allowing the latter to be used before the file header is read. It never performed any useful function to override @@ -3443,7 +3444,8 @@ Version 1.5.3rc02 [June 8, 2011] Frank Busse, CVE-2011-2501, related to CVE-2004-0421). Version 1.5.3beta11 [June 11, 2011] - Fixed png_handle_sCAL which is broken in 1.5; added sCAL to pngtest.png + Fixed png_handle_sCAL which is broken in 1.5. This fixes CVE 2011-2692. + Added sCAL to pngtest.png Revised documentation about png_set_user_limits() to say that it also affects png writing. Revised handling of png_set_user_limits() so that it can increase the @@ -3468,7 +3470,7 @@ Version 1.5.3beta11 [June 11, 2011] Removed string/memory macros that are no longer used and are not necessarily fully supportable, particularly png_strncpy and png_snprintf. Added log option to pngvalid.c and attempted to improve gamma messages. - + Version 1.5.3 [omitted] People found the presence of a beta release following an rc release to be confusing; therefore we bump the version to libpng-1.5.4beta01 @@ -3532,6 +3534,1620 @@ Version 1.5.4rc01 [June 30, 2011] Define PNG_ALLOCATED to "restrict" only if MSC_VER >= 1400. Version 1.5.4 [July 7, 2011] + No changes. + +Version 1.5.5beta01 [July 13, 2011] + Fixed some typos and made other minor changes in the manual. + Updated contrib/pngminus/makefile.std (Samuli Souminen) + +Version 1.5.5beta02 [July 14, 2011] + Revised Makefile.am and Makefile.in to look in the right directory for + pnglibconf.h.prebuilt + +Version 1.5.5beta03 [July 27, 2011] + Enabled compilation with g++ compiler. This compiler does not recognize + the file extension, so it always compiles with C++ rules. Made minor + changes to pngrutil.c to cast results where C++ expects it but C does not. + Minor editing of libpng.3 and libpng-manual.txt. + +Version 1.5.5beta04 [July 29, 2011] + Revised CMakeLists.txt (Clifford Yapp) + Updated commentary about the png_rgb_to_gray() default coefficients + in the manual and in pngrtran.c + +Version 1.5.5beta05 [August 17, 2011] + Prevent unexpected API exports from non-libpng DLLs on Windows. The "_DLL" + is removed from the test of whether a DLL is being built (this erroneously + caused the libpng APIs to be marked as DLL exports in static builds under + Microsoft Visual Studio). Almost all of the libpng building configuration + is moved from pngconf.h to pngpriv.h, but PNG_DLL_EXPORT remains in + pngconf.h, though, so that it is colocated with the import definition (it + is no longer used anywhere in the installed headers). The VStudio project + definitions have been cleaned up: "_USRDLL" has been removed from the + static library builds (this was incorrect), and PNG_USE_DLL has been added + to pngvalid to test the functionality (pngtest does not supply it, + deliberately). The spurious "_EXPORTS" has been removed from the + libpng build (all these errors were a result of copy/paste between project + configurations.) + Added new types and internal functions for CIE RGB end point handling to + pngpriv.h (functions yet to be implemented). + +Version 1.5.5beta06 [August 26, 2011] + Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set in CMakeLists.txt + (Clifford Yap) + Fixes to rgb_to_gray and cHRM XYZ APIs (John Bowler): + The rgb_to_gray code had errors when combined with gamma correction. + Some pixels were treated as true grey when they weren't and such pixels + and true grey ones were not gamma corrected (the original value of the + red component was used instead). APIs to get and set cHRM using color + space end points have been added and the rgb_to_gray code that defaults + based on cHRM, and the divide-by-zero bug in png_handle_cHRM (CERT + VU#477046, CVE-2011-3328, introduced in 1.5.4) have been corrected. + A considerable number of tests has been added to pngvalid for the + rgb_to_gray transform. + Arithmetic errors in rgb_to_gray whereby the calculated gray value was + truncated to the bit depth rather than rounded have been fixed except in + the 8-bit non-gamma-corrected case (where consistency seems more important + than correctness.) The code still has considerable inaccuracies in the + 8-bit case because 8-bit linear arithmetic is used. + +Version 1.5.5beta07 [September 7, 2011] + Added "$(ARCH)" option to makefile.darwin + Added SunOS support to configure.ac and Makefile.am + Changed png_chunk_benign_error() to png_warning() in png.c, in + png_XYZ_from_xy_checked(). + +Version 1.5.5beta08 [September 10, 2011] + Fixed 64-bit compilation errors (gcc). The errors fixed relate + to conditions where types that are 32 bits in the GCC 32-bit + world (uLong and png_size_t) become 64 bits in the 64-bit + world. This produces potential truncation errors which the + compiler correctly flags. + Relocated new HAVE_SOLARIS_LD definition in configure.ac + Constant changes for 64-bit compatibility (removal of L suffixes). The + 16-bit cases still use "L" as we don't have a 16-bit test system. + +Version 1.5.5rc01 [September 15, 2011] + Removed "L" suffixes in pngpriv.h + +Version 1.5.5 [September 22, 2011] + No changes. + +Version 1.5.6beta01 [September 22, 2011] + Fixed some 64-bit type conversion warnings in pngrtran.c + Moved row_info from png_struct to a local variable. + The various interlace mask arrays have been made into arrays of + bytes and made PNG_CONST and static (previously some arrays were + marked PNG_CONST and some weren't). + Additional checks have been added to the transform code to validate the + pixel depths after the transforms on both read and write. + Removed some redundant code from pngwrite.c, in png_destroy_write_struct(). + Changed chunk reading/writing code to use png_uint_32 instead of png_byte[4]. + This removes the need to allocate temporary strings for chunk names on + the stack in the read/write code. Unknown chunk handling still uses the + string form because this is exposed in the API. + +Version 1.5.6beta02 [September 26, 2011] + Added a note in the manual the png_read_update_info() must be called only + once with a particular info_ptr. + Fixed a typo in the definition of the new PNG_STRING_FROM_CHUNK(s,c) macro. + +Version 1.5.6beta03 [September 28, 2011] + Revised test-pngtest.sh to report FAIL when pngtest fails. + Added "--strict" option to pngtest, to report FAIL when the failure is + only because the resulting valid files are different. + Revised CMakeLists.txt to work with mingw and removed some material from + CMakeLists.txt that is no longer useful in libpng-1.5. + +Version 1.5.6beta04 [October 5, 2011] + Fixed typo in Makefile.in and Makefile.am ("-M Wl" should be "-M -Wl")." + +Version 1.5.6beta05 [October 12, 2011] + Speed up png_combine_row() for interlaced images. This reduces the generality + of the code, allowing it to be optimized for Adam7 interlace. The masks + passed to png_combine_row() are now generated internally, avoiding + some code duplication and localizing the interlace handling somewhat. + Align png_struct::row_buf - previously it was always unaligned, caused by + a bug in the code that attempted to align it; the code needs to subtract + one from the pointer to take account of the filter byte prepended to + each row. + Optimized png_combine_row() when rows are aligned. This gains a small + percentage for 16-bit and 32-bit pixels in the typical case where the + output row buffers are appropriately aligned. The optimization was not + previously possible because the png_struct buffer was always misaligned. + Fixed bug in png_write_chunk_header() debug print, introduced in 1.5.6beta01. + +Version 1.5.6beta06 [October 17, 2011] + Removed two redundant tests for unitialized row. + Fixed a relatively harmless memory overwrite in compressed text writing + with a 1 byte zlib buffer. + Add ability to call png_read_update_info multiple times to pngvalid.c. + Fixes for multiple calls to png_read_update_info. These fixes attend to + most of the errors revealed in pngvalid, however doing the gamma work + twice results in inaccuracies that can't be easily fixed. There is now + a warning in the code if this is going to happen. + Turned on multiple png_read_update_info in pngvalid transform tests. + Prevent libpng from overwriting unused bits at the end of the image when + it is not byte aligned, while reading. Prior to libpng-1.5.6 libpng would + overwrite the partial byte at the end of each row if the row width was not + an exact multiple of 8 bits and the image is not interlaced. + +Version 1.5.6beta07 [October 21, 2011] + Made png_ptr->prev_row an aligned pointer into png_ptr->big_prev_row + (Mans Rullgard). + +Version 1.5.6rc01 [October 26, 2011] + Changed misleading "Missing PLTE before cHRM" warning to "Out of place cHRM" + +Version 1.5.6rc02 [October 27, 2011] + Added LSR() macro to defend against buggy compilers that evaluate non-taken + code branches and complain about out-of-range shifts. + +Version 1.5.6rc03 [October 28, 2011] + Renamed the LSR() macro to PNG_LSR() and added PNG_LSL() macro. + Fixed compiler warnings with Intel and MSYS compilers. The logical shift + fix for Microsoft Visual C is required by other compilers, so this + enables that fix for all compilers when using compile-time constants. + Under MSYS 'byte' is a name declared in a system header file, so we + changed the name of a local variable to avoid the warnings that result. + Added #define PNG_ALIGN_TYPE PNG_ALIGN_NONE to contrib/pngminim/*/pngusr.h + +Version 1.5.6 [November 3, 2011] + No changes. + +Version 1.5.7beta01 [November 4, 2011] + Added support for ARM processor, when decoding all PNG up-filtered rows + and any other-filtered rows with 3 or 4 bytes per pixel (Mans Rullgard). + Fixed bug in pngvalid on early allocation failure; fixed type cast in + pngmem.c; pngvalid would attempt to call png_error() if the allocation + of a png_struct or png_info failed. This would probably have led to a + crash. The pngmem.c implementation of png_malloc() included a cast + to png_size_t which would fail on large allocations on 16-bit systems. + Fix for the preprocessor of the Intel C compiler. The preprocessor + splits adjacent @ signs with a space; this changes the concatentation + token from @-@-@ to PNG_JOIN; that should work with all compiler + preprocessors. + Paeth filter speed improvements from work by Siarhei Siamashka. This + changes the 'Paeth' reconstruction function to improve the GCC code + generation on x86. The changes are only part of the suggested ones; + just the changes that definitely improve speed and remain simple. + The changes also slightly increase the clarity of the code. + +Version 1.5.7beta02 [November 11, 2011] + Check compression_type parameter in png_get_iCCP and remove spurious + casts. The compression_type parameter is always assigned to, so must + be non-NULL. The cast of the profile length potentially truncated the + value unnecessarily on a 16-bit int system, so the cast of the (byte) + compression type to (int) is specified by ANSI-C anyway. + Fixed FP division by zero in pngvalid.c; the 'test_pixel' code left + the sBIT fields in the test pixel as 0, which resulted in a floating + point division by zero which was irrelevant but causes systems where + FP exceptions cause a crash. Added code to pngvalid to turn on FP + exceptions if the appropriate glibc support is there to ensure this is + tested in the future. + Updated scripts/pnglibconf.mak and scripts/makefile.std to handle the + new PNG_JOIN macro. + Added versioning to pnglibconf.h comments. + Simplified read/write API initial version; basic read/write tested on + a variety of images, limited documentation (in the header file.) + Installed more accurate linear to sRGB conversion tables. The slightly + modified tables reduce the number of 16-bit values that + convert to an off-by-one 8-bit value. The "makesRGB.c" code that was used + to generate the tables is now in a contrib/sRGBtables sub-directory. + +Version 1.5.7beta03 [November 17, 2011] + Removed PNG_CONST from the sRGB table declarations in pngpriv.h and png.c + Added run-time detection of NEON support. + Added contrib/libtests; includes simplified API test and timing test and + a color conversion utility for rapid checking of failed 'pngstest' results. + Multiple transform bug fixes plus a work-round for double gamma correction. + libpng does not support more than one transform that requires linear data + at once - if this is tried typically the results is double gamma + correction. Since the simplified APIs can need rgb to gray combined with + a compose operation it is necessary to do one of these outside the main + libpng transform code. This check-in also contains fixes to various bugs + in the simplified APIs themselves and to some bugs in compose and rgb to + gray (on palette) itself. + Fixes for C++ compilation using g++ When libpng source is compiled + using g++. The compiler imposes C++ rules on the C source; thus it + is desireable to make the source work with either C or C++ rules + without throwing away useful error information. This change adds + png_voidcast to allow C semantic (void*) cases or the corresponding + C++ static_cast operation, as appropriate. + Added --noexecstack to assembler file compilation. GCC does not set + this on assembler compilation, even though it does on C compilation. + This creates security issues if assembler code is enabled; the + work-around is to set it by default in the flags for $(CCAS) + Work around compilers that don't support declaration of const data. Some + compilers fault 'extern const' data declarations (because the data is + not initialized); this turns on const-ness only for compilers where + this is known to work. + +Version 1.5.7beta04 [November 17, 2011] + Since the gcc driver does not recognize the --noexecstack flag, we must + use the -Wa prefix to have it passed through to the assembler. + Also removed a duplicate setting of this flag. + Added files that were omitted from the libpng-1.5.7beta03 zip distribution. + +Version 1.5.7beta05 [November 25, 2011] + Removed "zTXt" from warning in generic chunk decompression function. + Validate time settings passed to pngset() and png_convert_to_rfc1123() + (Frank Busse). + Added MINGW support to CMakeLists.txt + Reject invalid compression flag or method when reading the iTXt chunk. + Backed out 'simplified' API changes. The API seems too complex and there + is a lack of consensus or enthusiasm for the proposals. The API also + reveals significant bugs inside libpng (double gamma correction and the + known bug of being unable to retrieve a corrected palette). It seems + better to wait until the bugs, at least, are corrected. + Moved pngvalid.c into contrib/libtests + Rebuilt Makefile.in, configure, etc., with autoconf-2.68 + +Version 1.5.7rc01 [December 1, 2011] + Replaced an "#if" with "#ifdef" in pngrtran.c + Revised #if PNG_DO_BC block in png.c (use #ifdef and add #else) + +Version 1.5.7rc02 [December 5, 2011] + Revised project files and contrib/pngvalid/pngvalid.c to account for + the relocation of pngvalid into contrib/libtests. + Revised pngconf.h to use " __declspec(restrict)" only when MSC_VER >= 1400, + as in libpng-1.5.4. + Put CRLF line endings in the owatcom project files. + +Version 1.5.7rc03 [December 7, 2011] + Updated CMakeLists.txt to account for the relocation of pngvalid.c + +Version 1.5.7 [December 15, 2011] + Minor fixes to pngvalid.c for gcc 4.6.2 compatibility to remove warnings + reported by earlier versions. + Fixed minor memset/sizeof errors in pngvalid.c. + +Version 1.6.0beta01 [December 15, 2011] + Removed machine-generated configure files from the GIT repository (they will + continue to appear in the tarball distributions and in the libpng15 and + earlier GIT branches). + Restored the new 'simplified' API, which was started in libpng-1.5.7beta02 + but later deleted from libpng-1.5.7beta05. + Added example programs for the new 'simplified' API. + Added ANSI-C (C90) headers and require them, and take advantage of the + change. Also fixed some of the projects/* and contrib/* files that needed + updates for libpng16 and the move of pngvalid.c. + With this change the required ANSI-C header files are assumed to exist: the + implementation must provide float.h, limits.h, stdarg.h and stddef.h and + libpng relies on limits.h and stddef.h existing and behaving as defined + (the other two required headers aren't used). Non-ANSI systems that don't + have stddef.h or limits.h will have to provide an appropriate fake + containing the relevant types and #defines. + The use of FAR/far has been eliminated and the definition of png_alloc_size_t + is now controlled by a flag so that 'small size_t' systems can select it + if necessary. Libpng 1.6 may not currently work on such systems -- it + seems likely that it will ask 'malloc' for more than 65535 bytes with any + image that has a sufficiently large row size (rather than simply failing + to read such images). + New tools directory containing tools used to generate libpng code. + Fixed race conditions in parallel make builds. With higher degrees of + parallelism during 'make' the use of the same temporary file names such + as 'dfn*' can result in a race where a temporary file from one arm of the + build is deleted or overwritten in another arm. This changes the + temporary files for suffix rules to always use $* and ensures that the + non-suffix rules use unique file names. + +Version 1.6.0beta02 [December 21, 2011] + Correct configure builds where build and source directories are separate. + The include path of 'config.h' was erroneously made relative in pngvalid.c + in libpng 1.5.7. + +Version 1.6.0beta03 [December 22, 2011] + Start-up code size improvements, error handler flexibility. These changes + alter how the tricky allocation of the initial png_struct and png_info + structures are handled. png_info is now handled in pretty much the same + way as everything else, except that the allocations handle NULL return + silently. png_struct is changed in a similar way on allocation and on + deallocation a 'safety' error handler is put in place (which should never + be required). The error handler itself is changed to permit mismatches + in the application and libpng error buffer size; however, this means a + silent change to the API to return the jmp_buf if the size doesn't match + the size from the libpng compilation; libpng now allocates the memory and + this may fail. Overall these changes result in slight code size + reductions; however, this is a reduction in code that is always executed + so is particularly valuable. Overall on a 64-bit system the libpng DLL + decreases in code size by 1733 bytes. pngerror.o increases in size by + about 465 bytes because of the new functionality. + Added png_convert_to_rfc1123_buffer() and deprecated png_convert_to_rfc1123() + to avoid including a spurious buffer in the png_struct. + +Version 1.6.0beta04 [December 30, 2011] + Regenerated configure scripts with automake-1.11.2 + Eliminated png_info_destroy(). It is now used only in png.c and only calls + one other internal function and memset(). + Enabled png_get_sCAL_fixed() if floating point APIs are enabled. Previously + it was disabled whenever internal fixed point arithmetic was selected, + which meant it didn't exist even on systems where FP was available but not + preferred. + Added pngvalid.c compile time checks for const APIs. + Implemented 'restrict' for png_info and png_struct. Because of the way + libpng works both png_info and png_struct are always accessed via a + single pointer. This means adding C99 'restrict' to the pointer gives + the compiler some opportunity to optimize the code. This change allows + that. + Moved AC_MSG_CHECKING([if libraries can be versioned]) later to the proper + location in configure.ac (Gilles Espinasse). + Changed png_memcpy to C assignment where appropriate. Changed all those + uses of png_memcpy that were doing a simple assignment to assignments + (all those cases where the thing being copied is a non-array C L-value). + Added some error checking to png_set_*() routines. + Removed the reference to the non-exported function png_memcpy() from + example.c. + Fixed the Visual C 64-bit build - it requires jmp_buf to be aligned, but + it had become misaligned. + Revised contrib/pngminus/pnm2png.c to avoid warnings when png_uint_32 + and unsigned long are of different sizes. + +Version 1.6.0beta05 [January 15, 2012] + Updated manual with description of the simplified API (copied from png.h) + Fix bug in pngerror.c: some long warnings were being improperly truncated + (CVE-2011-3464, bug introduced in libpng-1.5.3beta05). + +Version 1.6.0beta06 [January 24, 2012] + Added palette support to the simplified APIs. This commit + changes some of the macro definitions in png.h, app code + may need corresponding changes. + Increased the formatted warning buffer to 192 bytes. + Added color-map support to simplified API. This is an initial version for + review; the documentation has not yet been updated. + Fixed Min/GW uninstall to remove libpng.dll.a + +Version 1.6.0beta07 [January 28, 2012] + Eliminated Intel icc/icl compiler warnings. The Intel (GCC derived) + compiler issues slightly different warnings from those issued by the + current vesions of GCC. This eliminates those warnings by + adding/removing casts and small code rewrites. + Updated configure.ac from autoupdate: added --enable-werror option. + Also some layout regularization and removal of introduced tab characters + (replaced with 3-character indentation). Obsolete macros identified by + autoupdate have been removed; the replacements are all in 2.59 so + the pre-req hasn't been changed. --enable-werror checks for support + for -Werror (or the given argument) in the compiler. This mimics the + gcc configure option by allowing -Werror to be turned on safely; without + the option the tests written in configure itself fail compilation because + they cause compiler warnings. + Rewrote autogen.sh to run autoreconf instead of running tools one-by-one. + Conditionalize the install rules for MINGW and CYGWIN in CMakeLists.txt and + set CMAKE_LIBRARY_OUTPUT_DIRECTORY to "lib" on all platforms (C. Yapp). + Freeze libtool files in the 'scripts' directory. This version of autogen.sh + attempts to dissuade people from running it when it is not, or should not, + be necessary. In fact, autogen.sh does not work when run in a libpng + directory extracted from a tar distribution anymore. You must run it in + a GIT clone instead. + Added two images to contrib/pngsuite (1-bit and 2-bit transparent grayscale), + and renamed three whose names were inconsistent with those in + pngsuite/README.txt. + +Version 1.6.0beta08 [February 1, 2012] + Fixed Image::colormap misalignment in pngstest.c + Check libtool/libtoolize version number (2.4.2) in configure.ac + Divide test-pngstest.sh into separate pngstest runs for basic and + transparent images. + Moved automake options to AM_INIT_AUTOMAKE in configure.ac + Added color-tests, silent-rules (Not yet implemented in Makefile.am) and + version checking to configure.ac + Improved pngstest speed by not doing redundant tests and add const to + the background parameter of png_image_finish_read. The --background + option is now done automagically only when required, so that commandline + option no longer exists. + Cleaned up pngpriv.h to consistently declare all functions and data. + Also eliminated PNG_CONST_DATA, which is apparently not needed but we + can't be sure until it is gone. + Added symbol prefixing that allows all the libpng external symbols + to be prefixed (suggested by Reuben Hawkins). + Updated "ftbb*.png" list in the owatcom and vstudio projects. + Fixed 'prefix' builds on clean systems. The generation of pngprefix.h + should not require itself. + Updated INSTALL to explain that autogen.sh must be run in a GIT clone, + not in a libpng directory extracted from a tar distribution. + +Version 1.6.0beta09 [February 1, 2012] + Reverted the prebuilt configure files to libpng-1.6.0beta05 condition. + +Version 1.6.0beta10 [February 3, 2012] + Added Z_SOLO for zlib-1.2.6+ and correct pngstest tests + Updated list of test images in CMakeLists.txt + Updated the prebuilt configure files to current condition. + Revised INSTALL information about autogen.sh; it works in tar distributions. + +Version 1.6.0beta11 [February 16, 2012] + Fix character count in pngstest command in projects/owatcom/pngstest.tgt + Revised test-pngstest.sh to report PASS/FAIL for each image. + Updated documentation about the simplified API. + Corrected estimate of error in libpng png_set_rgb_to_gray API. The API is + extremely inaccurate for sRGB conversions because it uses an 8-bit + intermediate linear value and it does not use the sRGB transform, so it + suffers from the known instability in gamma transforms for values close + to 0 (see Poynton). The net result is that the calculation has a maximum + error of 14.99/255; 0.5/255^(1/2.2). pngstest now uses 15 for the + permitted 8-bit error. This may still not be enough because of arithmetic + error. + Removed some unused arrays (with #ifdef) from png_read_push_finish_row(). + Fixed a memory overwrite bug in simplified read of RGB PNG with + non-linear gamma Also bugs in the error checking in pngread.c and changed + quite a lot of the checks in pngstest.c to be correct; either correctly + written or not over-optimistic. The pngstest changes are insufficient to + allow all possible RGB transforms to be passed; pngstest cmppixel needs + to be rewritten to make it clearer which errors it allows and then changed + to permit known inaccuracies. + Removed tests for no-longer-used *_EMPTY_PLTE_SUPPORTED from pngstruct.h + Fixed fixed/float API export conditionals. 1) If FIXED_POINT or + FLOATING_POINT options were switched off, png.h ended up with lone ';' + characters. This is not valid ANSI-C outside a function. The ';' + characters have been moved inside the definition of PNG_FP_EXPORT and + PNG_FIXED_EXPORT. 2) If either option was switched off, the declaration + of the corresponding functions were completely omitted, even though some + of them are still used internally. The result is still valid, but + produces warnings from gcc with some warning options (including -Wall). The + fix is to cause png.h to declare the functions with PNG_INTERNAL_FUNCTION + when png.h is included from pngpriv.h. + Check for invalid palette index while reading paletted PNG. When one is + found, issue a warning and increase png_ptr->num_palette accordingly. + Apps are responsible for checking to see if that happened. + +Version 1.6.0beta12 [February 18, 2012] + Do not increase num_palette on invalid_index. + Relocated check for invalid palette index to pngrtran.c, after unpacking + the sub-8-bit pixels. + Fixed CVE-2011-3026 buffer overrun bug. This bug was introduced when + iCCP chunk support was added at libpng-1.0.6. Deal more correctly with the + test on iCCP chunk length. Also removed spurious casts that may hide + problems on 16-bit systems. + +Version 1.6.0beta13 [February 24, 2012] + Eliminated redundant png_push_read_tEXt|zTXt|iTXt|unknown code from + pngpread.c and use the sequential png_handle_tEXt, etc., in pngrutil.c; + now that png_ptr->buffer is inaccessible to applications, the special + handling is no longer useful. + Added PNG_SAFE_LIMITS feature to pnglibconf.dfa, pngpriv.h, and new + pngusr.dfa to reset the user limits to safe ones if PNG_SAFE_LIMITS is + defined. To enable, use "CPPFLAGS=-DPNG_SAFE_LIMITS_SUPPORTED=1" on the + configure command or put #define PNG_SAFE_LIMITS_SUPPORTED in + pnglibconf.h.prebuilt and pnglibconf.h. + +Version 1.6.0beta14 [February 27, 2012] + Added information about the new limits in the manual. + Updated Makefile.in + +Version 1.6.0beta15 [March 2, 2012] + Removed unused "current_text" members of png_struct and the png_free() + of png_ptr->current_text from pngread.c + Rewrote pngstest.c for substantial speed improvement. + Fixed transparent pixel and 16-bit rgb tests in pngstest and removed a + spurious check in pngwrite.c + Added PNG_IMAGE_FLAG_FAST for the benefit of applications that store + intermediate files, or intermediate in-memory data, while processing + image data with the simplified API. The option makes the files larger + but faster to write and read. pngstest now uses this by default; this + can be disabled with the --slow option. + Improved pngstest fine tuning of error numbers, new test file generator. + The generator generates images that test the full range of sample values, + allow the error numbers in pngstest to be tuned and checked. makepng + also allows generation of images with extra chunks, although this is + still work-in-progress. + Added check for invalid palette index while reading. + Fixed some bugs in ICC profile writing. The code should now accept + all potentially valid ICC profiles and reject obviously invalid ones. + It now uses png_error() to do so rather than casually writing a PNG + without the necessary color data. + Removed whitespace from the end of lines in all source files and scripts. + +Version 1.6.0beta16 [March 6, 2012] + Relocated palette-index checking function from pngrutil.c to pngtrans.c + Added palette-index checking while writing. + Changed png_inflate() and calling routines to avoid overflow problems. + This is an intermediate check-in that solves the immediate problems and + introduces one performance improvement (avoiding a copy via png_ptr->zbuf.) + Further changes will be made to make ICC profile handling more secure. + Fixed build warnings (MSVC, GCC, GCC v3). Cygwin GCC with default options + declares 'index' as a global, causing a warning if it is used as a local + variable. GCC 64-bit warns about assigning a (size_t) (unsigned 64-bit) + to an (int) (signed 32-bit). MSVC, however, warns about using the + unary '-' operator on an unsigned value (even though it is well defined + by ANSI-C to be ~x+1). The padding calculation was changed to use a + different method. Removed the tests on png_ptr->pass. + Added contrib/libtests/tarith.c to test internal arithmetic functions from + png.c. This is a libpng maintainer program used to validate changes to the + internal arithmetic functions. + Made read 'inflate' handling like write 'deflate' handling. The read + code now claims and releases png_ptr->zstream, like the write code. + The bug whereby the progressive reader failed to release the zstream + is now fixed, all initialization is delayed, and the code checks for + changed parameters on deflate rather than always calling + deflatedEnd/deflateInit. + Validate the zTXt strings in pngvalid. + Added code to validate the windowBits value passed to deflateInit2(). + If the call to deflateInit2() is wrong a png_warning will be issued + (in fact this is harmless, but the PNG data produced may be sub-optimal). + +Version 1.6.0beta17 [March 10, 2012] + Fixed PNG_LIBPNG_BUILD_BASE_TYPE definition. + Reject all iCCP chunks after the first, even if the first one is invalid. + Deflate/inflate was reworked to move common zlib calls into single + functions [rw]util.c. A new shared keyword check routine was also added + and the 'zbuf' is no longer allocated on progressive read. It is now + possible to call png_inflate() incrementally. A warning is no longer + issued if the language tag or translated keyword in the iTXt chunk + has zero length. + If benign errors are disabled use maximum window on ancilliary inflate. + This works round a bug introduced in 1.5.4 where compressed ancillary + chunks could end up with a too-small windowBits value in the deflate + header. + +Version 1.6.0beta18 [March 16, 2012] + Issue a png_benign_error() instead of png_warning() about bad palette index. + In pngtest, treat benign errors as errors if "-strict" is present. + Fixed an off-by-one error in the palette index checking function. + Fixed a compiler warning under Cygwin (Windows-7, 32-bit system) + Revised example.c to put text strings in a temporary character array + instead of directly assigning string constants to png_textp members. + This avoids compiler warnings when -Wwrite-strings is enabled. + Added output flushing to aid debugging under Visual Studio. Unfortunately + this is necessary because the VS2010 output window otherwise simply loses + the error messages on error (they weren't flushed to the window before + the process exited, apparently!) + Added configuration support for benign errors and changed the read + default. Also changed some warnings in the iCCP and sRGB handling + from to benign errors. Configuration now makes read benign + errors warnings and write benign errors to errors by default (thus + changing the behavior on read). The simplified API always forces + read benign errors to warnings (regardless of the system default, unless + this is disabled in which case the simplified API can't be built.) + +Version 1.6.0beta19 [March 18, 2012] + Work around for duplicate row start calls; added warning messages. + This turns on PNG_FLAG_DETECT_UNINITIALIZED to detect app code that + fails to call one of the 'start' routines (not enabled in libpng-1.5 + because it is technically an API change, since it did normally work + before.) It also makes duplicate calls to png_read_start_row (an + internal function called at the start of the image read) benign, as + they were before changes to use png_inflate_claim. Somehow webkit is + causing this to happen; this is probably a mis-feature in the zlib + changes so this commit is only a work-round. + Removed erroneous setting of DETECT_UNINITIALIZED and added more + checks. The code now does a png_error if an attempt is made to do the + row initialization twice; this is an application error and it has + serious consequences because the transform data in png_struct is + changed by each call. + Added application error reporting and added chunk names to read + benign errors; also added --strict to pngstest - not enabled + yet because a warning is produced. + Avoid the double gamma correction warning in the simplified API. + This allows the --strict option to pass in the pngstest checks + +Version 1.6.0beta20 [March 29, 2012] + Changed chunk handler warnings into benign errors, incrementally load iCCP + Added checksum-icc.c to contrib/tools + Prevent PNG_EXPAND+PNG_SHIFT doing the shift twice. + Recognize known sRGB ICC profiles while reading; prefer writing the + iCCP profile over writing the sRGB chunk, controlled by the + PNG_sRGB_PROFILE_CHECKS option. + Revised png_set_text_2() to avoid potential memory corruption (fixes + CVE-2011-3048, also known as CVE-2012-3425). + +Version 1.6.0beta21 [April 27, 2012] + Revised scripts/makefile.darwin: use system zlib; remove quotes around + architecture list; add missing ppc architecture; add architecture options + to shared library link; don't try to create a shared lib based on missing + RELEASE variable. + Enable png_set_check_for_invalid_index() for both read and write. + Removed #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED in pngpriv.h around + declaration of png_handle_unknown(). + Added -lssp_nonshared in a comment in scripts/makefile.freebsd + and changed deprecated NOOBJ and NOPROFILE to NO_OBJ and NO_PROFILE. + +Version 1.6.0beta22 [May 23, 2012] + Removed need for -Wno-cast-align with clang. clang correctly warns on + alignment increasing pointer casts when -Wcast-align is passed. This + fixes the cases that clang warns about either by eliminating the + casts from png_bytep to png_uint_16p (pngread.c), or, for pngrutil.c + where the cast is previously verified or pngstest.c where it is OK, by + introducing new png_aligncast macros to do the cast in a way that clang + accepts. + +Version 1.6.0beta23 [June 6, 2012] + Revised CMakeLists.txt to not attempt to make a symlink under mingw. + Made fixes for new optimization warnings from gcc 4.7.0. The compiler + performs an optimization which is safe; however it then warns about it. + Changing the type of 'palette_number' in pngvalid.c removes the warning. + Do not depend upon a GCC feature macro being available for use in generating + the linker mapfile symbol prefix. + Improved performance of new do_check_palette_indexes() function (only + update the value when it actually increases, move test for whether + the check is wanted out of the function. + +Version 1.6.0beta24 [June 7, 2012] + Don't check palette indexes if num_palette is 0 (as it can be in MNG files). + +Version 1.6.0beta25 [June 16, 2012] + Revised png_set_keep_unknown_chunks() so num_chunks < 0 means ignore all + unknown chunks and all known chunks except for IHDR, PLTE, tRNS, IDAT, + and IEND. Previously it only meant ignore all unknown chunks, the + same as num_chunks == 0. Revised png_image_skip_unused_chunks() to + provide a list of chunks to be processed instead of a list of chunks to + ignore. Revised contrib/gregbook/readpng2.c accordingly. + +Version 1.6.0beta26 [July 10, 2012] + Removed scripts/makefile.cegcc from the *.zip and *.7z distributions; it + depends on configure, which is not included in those archives. + Moved scripts/chkfmt to contrib/tools. + Changed "a+w" to "u+w" in Makefile.in to fix CVE-2012-3386. + +Version 1.6.0beta27 [August 11, 2012] + Do not compile PNG_DEPRECATED, PNG_ALLOC and PNG_PRIVATE when __GNUC__ < 3. + Do not use __restrict when GNUC is <= 3.1 + Removed references to png_zalloc() and png_zfree() from the manual. + Fixed configurations where floating point is completely disabled. Because + of the changes to support symbol prefixing PNG_INTERNAL_FUNCTION declares + floating point APIs during libpng builds even if they are completely + disabled. This requires the png floating point types (png_double*) to be + declared even though the functions are never actually defined. This + change provides a dummy definition so that the declarations work, yet any + implementation will fail to compile because of an incomplete type. + Re-eliminated the use of strcpy() in pngtest.c. An unncessary use of + strcpy() was accidentally re-introduced in libpng16; this change replaces + it with strncpy(). + Eliminated use of png_sizeof(); use sizeof() instead. + Use a consistent style for (sizeof type) and (sizeof (array)) + Cleanup of png_set_filler(). This function does very different things on + read and write. In libpng 1.6 the two cases can be distinguished and + considerable code cleanup, and extra error checking, is possible. This + makes calls on the write side that have no effect be ignored with a + png_app_error(), which can be disabled in the app using + png_set_benign_errors(), and removes the spurious use of usr_channels + on the read side. + Insist on autotools 1.12.1 for git builds because there are security issues + with 1.12 and insisting on anything less would allow 1.12 to be used. + Removed info_ptr->signature[8] from WRITE-only builds. + Add some conditions for compiling png_fixed(). This is a small function + but it requires "-lm" on some platforms. + Cause pngtest --strict to fail on any warning from libpng (not just errors) + and cause it not to fail at the comparison step if libpng lacks support + for writing chunks that it reads from the input (currently only implemented + for compressed text chunks). + Make all three "make check" test programs work without READ or WRITE support. + Now "make check" will succeed even if libpng is compiled with -DPNG_NO_READ + or -DPNG_NO_WRITE. The tests performed are reduced, but the basic reading + and writing of a PNG file is always tested by one or more of the tests. + Consistently use strlen(), memset(), memcpy(), and memcmp() instead of the + png_strlen(), png_memset(), png_memcpy(), and png_memcmp() macros. + Removed the png_sizeof(), png_strlen(), png_memset(), png_memcpy(), and + png_memcmp() macros. + Work around gcc 3.x and Microsoft Visual Studio 2010 complaints. Both object + to the split initialization of num_chunks. + +Version 1.6.0beta28 [August 29, 2012] + Unknown handling fixes and clean up. This adds more correct option + control of the unknown handling, corrects the pre-existing bug where + the per-chunk 'keep' setting is ignored and makes it possible to skip + IDAT chunks in the sequential reader (broken in earlier 1.6 versions). + There is a new test program, test-unknown.c, which is a work in progress + (not currently part of the test suite). Comments in the header files now + explain how the unknown handling works. + Allow fine grain control of unknown chunk APIs. This change allows + png_set_keep_unknown_chunks() to be turned off if not required and causes + both read and write to behave appropriately (on read this is only possible + if the user callback is used to handle unknown chunks). The change + also removes the support for storing unknown chunks in the info_struct + if the only unknown handling enabled is via the callback, allowing libpng + to be configured with callback reading and none of the unnecessary code. + Corrected fix for unknown handling in pngtest. This reinstates the + libpng handling of unknown chunks other than vpAg and sTER (including + unsafe-to-copy chunks which were dropped before) and eliminates the + repositioning of vpAg and sTER in pngtest.png by changing pngtest.png + (so the chunks are where libpng would put them). + Added "tunknown" test and corrected a logic error in png_handle_unknown() + when SAVE support is absent. Moved the shell test scripts for + contrib/libtests from the libpng top directory to contrib/libtests. + png_handle_unknown() must always read or skip the chunk, if + SAVE_UNKNOWN_CHUNKS is turned off *and* the application does not set + a user callback an unknown chunk will not be read, leading to a read + error, which was revealed by the "tunknown" test. + Cleaned up and corrected ICC profile handling. + contrib/libtests/makepng: corrected 'rgb' and 'gray' cases. profile_error + messages could be truncated; made a correct buffer size calculation and + adjusted pngerror.c appropriately. png_icc_check_* checking improved; + changed the functions to receive the correct color type of the PNG on read + or write and check that it matches the color space of the profile (despite + what the comments said before, there is danger in assuming the app will + cope correctly with an RGB profile on a grayscale image and, since it + violates the PNG spec, allowing it is certain to produce inconsistent + app behavior and might even cause app crashes.) Check that profiles + contain the tags needed to process the PNG (tags all required by the ICC + spec). Removed unused PNG_STATIC from pngpriv.h. + +Version 1.6.0beta29 [September 4, 2012] + Fixed the simplified API example programs to add the *colormap parameter + to several of he API and improved the error message if the version field + is not set. + Added contrib/examples/* to the *.zip and *.7z distributions. + Updated simplified API synopses and description of the png_image structure + in the manual. + Made makepng and pngtest produce identical PNGs, add "--relaxed" option + to pngtest. The "--relaxed" option turns off the benign errors that are + enabled by default in pre-RC builds. makepng can now write ICC profiles + where the length has not been extended to a multiple of 4, and pngtest + now intercepts all libpng errors, allowing the previously-introduced + "--strict test" on no warnings to actually work. + Improved ICC profile handling including cHRM chunk generation and fixed + Cygwin+MSVC build errors. The ICC profile handling now includes more + checking. Several errors that caused rejection of the profile are now + handled with a warning in such a way that the invalid profiles will be + read by default in release (but not pre-RC) builds but will not be + written by default. The easy part of handling the cHRM chunk is written, + where the ICC profile contains the required data. The more difficult + part plus guessing a gAMA value requires code to pass selected RGB values + through the profile. + +Version 1.6.0beta30 [October 24, 2012] + Changed ICC profile matrix/vector types to not depend on array type rules. + By the ANSI-C standard the new types should be identical to the previous + versions, and all known versions of gcc tested with the previous versions + except for GCC-4.2.1 work with this version. The change makes the ANSI-C + rule that const applied to an array of elements applies instead to the + elements in the array moot by explicitly applying const to the base + elements of the png_icc_matrix and png_icc_vector types. The accidental + (harmless) 'const' previously applied to the parameters of two of the + functions have also been removed. + Added a work around for GCC 4.2 optimization bug. + Marked the broken (bad white point) original HP sRGB profiles correctly and + correct comments. + Added -DZ_SOLO to contrib/pngminim/*/makefile to work with zlib-1.2.7 + Use /MDd for vstudio debug builds. Also added pngunkown to the vstudio + builds, fixed build errors and corrected a minor exit code error in + pngvalid if the 'touch' file name is invalid. + Add updated WARNING file to projects/vstudio from libpng 1.5/vstudio + Fixed build when using #define PNG_NO_READ_GAMMA in png_do_compose() in + pngrtran.c (Domani Hannes). + +Version 1.6.0beta31 [November 1, 2012] + Undid the erroneous change to vstudio/pngvalid build in libpng-1.6.0beta30. + Made pngvalid so that it will build outside the libpng source tree. + Made builds -DPNG_NO_READ_GAMMA compile (the unit tests still fail). + Made PNG_NO_READ_GAMMA switch off interfaces that depend on READ_GAMMA. + Prior to 1.6.0 switching off READ_GAMMA did unpredictable things to the + interfaces that use it (specifically, png_do_background in 1.4 would + simply display composite for grayscale images but do composition + with the incorrect arithmetic for color ones). In 1.6 the semantic + of -DPNG_NO_READ_GAMMA is changed to simply disable any interface that + depends on it; this obliges people who set it to consider whether they + really want it off if they happen to use any of the interfaces in + question (typically most users who disable it won't). + Fixed GUIDs in projects/vstudio. Some were duplicated or missing, + resulting in VS2010 having to update the files. + Removed non-working ICC profile support code that was mostly added to + libpng-1.6.0beta29 and beta30. There was too much code for too little + gain; implementing full ICC color correction may be desireable but is left + up to applications. + +Version 1.6.0beta32 [November 25, 2012] + Fixed an intermittent SEGV in pngstest due to an uninitialized array element. + Added the ability for contrib/libtests/makepng.c to make a PNG with just one + color. This is useful for debugging pngstest color inaccuracy reports. + Fixed error checking in the simplified write API (Olaf van der Spek) + Made png_user_version_check() ok to use with libpng version 1.10.x and later. + +Version 1.6.0beta33 [December 15, 2012] + Fixed typo in png.c (PNG_SET_CHUNK_MALLOC_MAX should be PNG_CHUNK_MALLOC_MAX) + that causes the MALLOC_MAX limit not to work (John Bowler) + Change png_warning() to png_app_error() in pngwrite.c and comment the + fall-through condition. + Change png_warning() to png_app_warning() in png_write_tRNS(). + Rearranged the ARM-NEON optimizations: Isolated the machine specific code + to the hardware subdirectory and added comments to pngrutil.c so that + implementors of other optimizations know what to do. + Fixed cases of unquoted DESTDIR in Makefile.am + Rebuilt Makefile.in, etc., with autoconf-2.69 and automake-1.12.5. + +Version 1.6.0beta34 [December 19, 2012] + Cleaned up whitespace in the synopsis portion of the manpage "libpng.3" + Disassembled the version number in scripts/options.awk (necessary for + building on SunOs). + +Version 1.6.0beta35 [December 23, 2012] + Made default Zlib compression settings be configurable. This adds #defines to + pnglibconf.h to control the defaults. + Fixed Windows build issues, enabled ARM compilation. Various warnings issued + by earlier versions of GCC fixed for Cygwin and Min/GW (which both use old + GCCs.) ARM support is enabled by default in zlib.props (unsupported by + Microsoft) and ARM compilation is made possible by deleting the check for + x86. The test programs cannot be run because they are not signed. + +Version 1.6.0beta36 [January 2, 2013] + Discontinued distributing libpng-1.x.x.tar.bz2. + Discontinued distributing libpng-1.7.0-1.6.0-diff.txt and similar. + Rebuilt configure with autoconf-2.69 (inadvertently not done in beta33) + Fixed 'make distcheck' on SUN OS - libpng.so was not being removed + +Version 1.6.0beta37 [January 10, 2013] + Fixed conceivable but difficult to repro overflow. Also added two test + programs to generate and test a PNG which should have the problem. + +Version 1.6.0beta39 [January 19, 2013] + Again corrected attempt at overflow detection in png_set_unknown_chunks() + (CVE-2013-7353). Added overflow detection in png_set_sPLT() and + png_set_text_2() (CVE-2013-7354). + +Version 1.6.0beta40 [January 20, 2013] + Use consistent handling of overflows in text, sPLT and unknown png_set_* APIs + +Version 1.6.0rc01 [January 26, 2013] + No changes. + +Version 1.6.0rc02 [February 4, 2013] + Added png_get_palette_max() function. + +Version 1.6.0rc03 [February 5, 2013] + Fixed the png_get_palette_max API. + +Version 1.6.0rc04 [February 7, 2013] + Turn serial tests back on (recently turned off by autotools upgrade). + +Version 1.6.0rc05 [February 8, 2013] + Update manual about png_get_palette_max(). + +Version 1.6.0rc06 [February 9, 2013] + Fixed missing dependency in --prefix builds The intermediate + internal 'prefix.h' file can only be generated correctly after + pnglibconf.h, however the dependency was not in Makefile.am. The + symptoms are unpredictable depending on the order make chooses to + build pngprefix.h and pnglibconf.h, often the error goes unnoticed + because there is a system pnglibconf.h to use instead. + +Version 1.6.0rc07 [February 10, 2013] + Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED + block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly. + +Version 1.6.0rc08 [February 10, 2013] + Fix typo in png.h #ifdef + +Version 1.6.0 [February 14, 2013] + No changes. + +Version 1.6.1beta01 [February 16, 2013] + Made symbol prefixing work with the ARM neon optimizations. Also allow + pngpriv.h to be included for preprocessor definitions only, so it can + be used in non-C/C++ files. Back ported from libpng 1.7. + Made sRGB check numbers consistent. + Ported libpng 1.5 options.awk/dfn file handling to 1.6, fixed one bug. + Removed cc -E workround, corrected png_get_palette_max API Tested on + SUN OS cc 5.9, which demonstrates the tokenization problem previously + avoided by using /lib/cpp. Since all .dfn output is now protected in + double quotes unless it is to be macro substituted the fix should + work everywhere. + Enabled parallel tests - back ported from libpng-1.7. + scripts/pnglibconf.dfa formatting improvements back ported from libpng17. + Fixed a race condition in the creation of the build 'scripts' directory + while building with a parallel make. + Use approved/supported Android method to check for NEON, use Linux/POSIX + 1003.1 API to check /proc/self/auxv avoiding buffer allocation and other + library calls (ported from libpng15). + +Version 1.6.1beta02 [February 19, 2013] + Use parentheses more consistently in "#if defined(MACRO)" tests. + Folded long lines. + Reenabled code to allow zero length PLTE chunks for MNG. + +Version 1.6.1beta03 [February 22, 2013] + Fixed ALIGNED_MEMORY support. + Allow run-time ARM NEON checking to be disabled. A new configure option: + --enable-arm-neon=always will stop the run-time checks. New checks + within arm/arm_init.c will cause the code not to be compiled unless + __ARM_NEON__ is set. This should make it fail safe (if someone asks + for it on then the build will fail if it can't be done.) + Updated the INSTALL document. + +Version 1.6.1beta04 [February 27, 2013] + Revised INSTALL to recommend using CPPFLAGS instead of INCLUDES. + Revised scripts/makefile.freebsd to respect ZLIBLIB and ZLIBINC. + Revised scripts/dfn.awk to work with the buggy MSYS awk that has trouble + with CRLF line endings. + +Version 1.6.1beta05 [March 1, 2013] + Avoid a possible memory leak in contrib/gregbook/readpng.c + +Version 1.6.1beta06 [March 4, 2013] + Better documentation of unknown handling API interactions. + Corrected Android builds and corrected libpng.vers with symbol + prefixing. This adds an API to set optimization options externally, + providing an alternative and general solution for the non-portable + run-time tests used by the ARM Neon code. It also makes those tests + compile and link on Android. + The order of settings vs options in pnglibconf.h is reversed to allow + settings to depend on options and options can now set (or override) the + defaults for settings. + +Version 1.6.1beta07 [March 7, 2013] + Corrected simplified API default gamma for color-mapped output, added + a flag to change default. In 1.6.0 when the simplified API was used + to produce color-mapped output from an input image with no gamma + information the gamma assumed for the input could be different from + that assumed for non-color-mapped output. In particular 16-bit depth + input files were assumed to be sRGB encoded, whereas in the 'direct' + case they were assumed to have linear data. This was an error. The + fix makes the simplified API treat all input files the same way and + adds a new flag to the png_image::flags member to allow the + application/user to specify that 16-bit files contain sRGB data + rather than the default linear. + Fixed bugs in the pngpixel and makepng test programs. + +Version 1.6.1beta08 [March 7, 2013] + Fixed CMakelists.txt to allow building a single variant of the library + (Claudio Bley): + Introduced a PNG_LIB_TARGETS variable that lists all activated library + targets. It is an error if this variable ends up empty, ie. you have + to build at least one library variant. + Made the *_COPY targets only depend on library targets actually being build. + Use PNG_LIB_TARGETS to unify a code path. + Changed the CREATE_SYMLINK macro to expect the full path to a file as the + first argument. When symlinking the filename component of that path is + determined and used as the link target. + Use copy_if_different in the CREATE_SYMLINK macro. + +Version 1.6.1beta09 [March 13, 2013] + Eliminated two warnings from the Intel C compiler. The warnings are + technically valid, although a reasonable treatment of division would + show it to be incorrect. + +Version 1.6.1rc01 [March 21, 2013] + No changes. + +Version 1.6.1 [March 28, 2013] + No changes. + +Version 1.6.2beta01 [April 14, 2013] + Updated documentation of 1.5.x to 1.6.x changes in iCCP chunk handling. + Fixed incorrect warning of excess deflate data. End condition - the + warning would be produced if the end of the deflate stream wasn't read + in the last row. The warning is harmless. + Corrected the test on user transform changes on read. It was in the + png_set of the transform function, but that doesn't matter unless the + transform function changes the rowbuf size, and that is only valid if + transform_info is called. + Corrected a misplaced closing bracket in contrib/libtests/pngvalid.c + (Flavio Medeiros). + Corrected length written to uncompressed iTXt chunks (Samuli Suominen). + Bug was introduced in libpng-1.6.0. + +Version 1.6.2rc01 [April 18, 2013] + Added contrib/tools/fixitxt.c, to repair the erroneous iTXt chunk length + written by libpng-1.6.0 and 1.6.1. + Disallow storing sRGB information when the sRGB is not supported. + +Version 1.6.2rc02 [April 18, 2013] + Merge pngtest.c with libpng-1.7.0 + +Version 1.6.2rc03 [April 22, 2013] + Trivial spelling cleanup. + +Version 1.6.2rc04 and 1.6.2rc05 [omitted] + +Version 1.6.2rc06 [April 24, 2013] + Reverted to version 1.6.2rc03. Recent changes to arm/neon support + have been ported to libpng-1.7.0beta09 and will reappear in version + 1.6.3beta01. + +Version 1.6.2 [April 25, 2013] + No changes. + +Version 1.6.3beta01 [April 25, 2013] + Revised stack marking in arm/filter_neon.S and configure.ac. + Ensure that NEON filter stuff is completely disabled when switched 'off'. + Previously the ARM NEON specific files were still built if the option + was switched 'off' as opposed to being explicitly disabled. + +Version 1.6.3beta02 [April 26, 2013] + Test for 'arm*' not just 'arm' in the host_cpu configure variable. + Rebuilt the configure scripts. + +Version 1.6.3beta03 [April 30, 2013] + Expanded manual paragraph about writing private chunks, particularly + the need to call png_set_keep_unknown_chunks() when writing them. + Avoid dereferencing NULL pointer possibly returned from + png_create_write_struct() (Andrew Church). + +Version 1.6.3beta05 [May 9, 2013] + Calculate our own zlib windowBits when decoding rather than trusting the + CMF bytes in the PNG datastream. + Added an option to force maximum window size for inflating, which was + the behavior of libpng15 and earlier. + Added png-fix-itxt and png-fix-too-far-back to the built programs and + removed warnings from the source code and timepng that are revealed as + a result. + Detect wrong libpng versions linked to png-fix-too-far-back, which currently + only works with libpng versions that can be made to reliably fail when + the deflate data contains an out-of-window reference. This means only + 1.6 and later. + Fixed gnu issues: g++ needs a static_cast, gcc 4.4.7 has a broken warning + message which it is easier to work round than ignore. + Updated contrib/pngminus/pnm2png.c (Paul Stewart): + Check for EOF + Ignore "#" delimited comments in input file to pnm2png.c. + Fixed whitespace handling + Added a call to png_set_packing() + Initialize dimension values so if sscanf fails at least we have known + invalid values. + Attempt to detect configuration issues with png-fix-too-far-back, which + requires both the correct libpng and the correct zlib to function + correctly. + Check ZLIB_VERNUM for mismatches, enclose #error in quotes + Added information in the documentation about problems with and fixes for + the bad CRC and bad iTXt chunk situations. + +Version 1.6.3beta06 [May 12, 2013] + Allow contrib/pngminus/pnm2png.c to compile without WRITE_INVERT and + WRITE_PACK supported (writes error message that it can't read P1 or + P4 PBM files). + Improved png-fix-too-far-back usage message, added --suffix option. + Revised contrib/pngminim/*/makefile to generate pnglibconf.h with the + right zlib header files. + Separated CPPFLAGS and CFLAGS in contrib/pngminim/*/makefile + +Version 1.6.3beta07 [June 8, 2013] + Removed a redundant test in png_set_IHDR(). + Added set(CMAKE_CONFIGURATION_TYPES ...) to CMakeLists.txt (Andrew Hundt) + Deleted set(CMAKE_BUILD_TYPE) block from CMakeLists.txt + Enclose the prototypes for the simplified write API in + #ifdef PNG_STDIO_SUPPORTED/#endif + Make ARM NEON support work at compile time (not just configure time). + This moves the test on __ARM_NEON__ into pngconf.h to avoid issues when + using a compiler that compiles for multiple architectures at one time. + Removed PNG_FILTER_OPTIMIZATIONS and PNG_ARM_NEON_SUPPORTED from + pnglibconf.h, allowing more of the decisions to be made internally + (pngpriv.h) during the compile. Without this, symbol prefixing is broken + under certain circumstances on ARM platforms. Now only the API parts of + the optimizations ('check' vs 'api') are exposed in the public header files + except that the new setting PNG_ARM_NEON_OPT documents how libpng makes the + decision about whether or not to use the optimizations. + Protect symbol prefixing against CC/CPPFLAGS/CFLAGS useage. + Previous iOS/Xcode fixes for the ARM NEON optimizations moved the test + on __ARM_NEON__ from configure time to compile time. This breaks symbol + prefixing because the definition of the special png_init_filter_functions + call was hidden at configure time if the relevant compiler arguments are + passed in CFLAGS as opposed to CC. This change attempts to avoid all + the confusion that would result by declaring the init function even when + it is not used, so that it will always get prefixed. + +Version 1.6.3beta08 [June 18, 2013] + Revised libpng.3 so that "doclifter" can process it. + +Version 1.6.3beta09 [June 27, 2013] + Revised example.c to illustrate use of PNG_DEFAULT_sRGB and PNG_GAMMA_MAC_18 + as parameters for png_set_gamma(). These have been available since + libpng-1.5.4. + Renamed contrib/tools/png-fix-too-far-back.c to pngfix.c and revised it + to check all compressed chunks known to libpng. + +Version 1.6.3beta10 [July 5, 2013] + Updated documentation to show default behavior of benign errors correctly. + Only compile ARM code when PNG_READ_SUPPORTED is defined. + Fixed undefined behavior in contrib/tools/pngfix.c and added new strip + option. pngfix relied on undefined behavior and even a simple change from + gcc to g++ caused it to fail. The new strip option 'unsafe' has been + implemented and is the default if --max is given. Option names have + been clarified, with --strip=transform now stripping the bKGD chunk, + which was stripped previously with --strip=unused. + Added all documented chunk types to pngpriv.h + Unified pngfix.c source with libpng17. + +Version 1.6.3rc01 [July 11, 2013] + No changes. + +Version 1.6.3 [July 18, 2013] + Revised manual about changes in iTXt chunk handling made in libpng-1.6.0. + Added "/* SAFE */" comments in pngrutil.c and pngrtran.c where warnings + may be erroneously issued by code-checking applications. + +Version 1.6.4beta01 [August 21, 2013] + Added information about png_set_options() to the manual. + Delay calling png_init_filter_functions() until a row with nonzero filter + is found. + +Version 1.6.4beta02 [August 30, 2013] + Fixed inconsistent conditional compilation of png_chunk_unknown_handling() + prototype, definition, and usage. Made it depend on + PNG_HANDLE_AS_UNKNOWN_SUPPORTED everywhere. + +Version 1.6.4rc01 [September 5, 2013] + No changes. + +Version 1.6.4 [September 12, 2013] + No changes. + +Version 1.6.5 [September 14, 2013] + Removed two stray lines of code from arm/arm_init.c. + +Version 1.6.6 [September 16, 2013] + Removed two stray lines of code from arm/arm_init.c, again. + +Version 1.6.7beta01 [September 30, 2013] + Revised unknown chunk code to correct several bugs in the NO_SAVE_/NO_WRITE + combination + Allow HANDLE_AS_UNKNOWN to work when other options are configured off. Also + fixed the pngminim makefiles to work when $(MAKEFLAGS) contains stuff + which terminates the make options (as by default in recent versions of + Gentoo). + Avoid up-cast warnings in pngvalid.c. On ARM the alignment requirements of + png_modifier are greater than that of png_store and as a consequence + compilation of pngvalid.c results in a warning about increased alignment + requirements because of the bare cast to (png_modifier*). The code is safe, + because the pointer is known to point to a stack allocated png_modifier, + but this change avoids the warning. + Fixed default behavior of ARM_NEON_API. If the ARM NEON API option was + compiled without the CHECK option it defaulted to on, not off. + Check user callback behavior in pngunknown.c. Previous versions compiled + if SAVE_UNKNOWN was not available but did nothing since the callback + was never implemented. + Merged pngunknown.c with 1.7 version and back ported 1.7 improvements/fixes + +Version 1.6.7beta02 [October 12, 2013] + Made changes for compatibility with automake 1.14: + 1) Added the 'compile' program to the list of programs that must be cleaned + in autogen.sh + 2) Added 'subdir-objects' which causes .c files in sub-directories to be + compiled such that the corresponding .o files are also in the + sub-directory. This is because automake 1.14 warns that the + current behavior of compiling to the top level directory may be removed + in the future. + 3) Updated dependencies on pnglibconf.h to match the new .o locations and + added all the files in contrib/libtests and contrib/tools that depend + on pnglibconf.h + 4) Added 'BUILD_SOURCES = pnglibconf.h'; this is the automake recommended + way of handling the dependencies of sources that are machine generated; + unfortunately it only works if the user does 'make all' or 'make check', + so the dependencies (3) are still required. + Cleaned up (char*) casts of zlib messages. The latest version of the Intel C + compiler complains about casting a string literal as (char*), so copied the + treatment of z_const from the library code into pngfix.c + Simplified error message code in pngunknown. The simplification has the + useful side effect of avoiding a bogus warning generated by the latest + version of the Intel C compiler (it objects to + condition ? string-literal : string-literal). + Make autogen.sh work with automake 1.13 as well as 1.14. Do this by always + removing the 1.14 'compile' script but never checking for it. + +Version 1.6.7beta03 [October 19, 2013] + Added ARMv8 support (James Yu ). Added file + arm/filter_neon_intrinsics.c; enable with -mfpu=neon. + Revised pngvalid to generate size images with as many filters as it can + manage, limited by the number of rows. + Cleaned up ARM NEON compilation handling. The tests are now in pngpriv.h + and detect the broken GCC compilers. + +Version 1.6.7beta04 [October 26, 2013] + Allow clang derived from older GCC versions to use ARM intrinsics. This + causes all clang builds that use -mfpu=neon to use the intrinsics code, + not the assembler code. This has only been tested on iOS 7. It may be + necessary to exclude some earlier clang versions but this seems unlikely. + Changed NEON implementation selection mechanism. This allows assembler + or intrinsics to be turned on at compile time during the build by defining + PNG_ARM_NEON_IMPLEMENTATION to the correct value (2 or 1). This macro + is undefined by default and the build type is selected in pngpriv.h. + +Version 1.6.7rc01 [November 2, 2013] + No changes. + +Version 1.6.7rc02 [November 7, 2013] + Fixed #include in filter_neon_intrinsics.c and ctype macros. The ctype char + checking macros take an unsigned char argument, not a signed char. + +Version 1.6.7 [November 14, 2013] + No changes. + +Version 1.6.8beta01 [November 24, 2013] + Moved prototype for png_handle_unknown() in pngpriv.h outside of + the #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED/#endif block. + Added "-Wall" to CFLAGS in contrib/pngminim/*/makefile + Conditionally compile some unused functions reported by -Wall in + pngminim. + Fixed 'minimal' builds. Various obviously useful minimal configurations + don't build because of missing contrib/libtests test programs and + overly complex dependencies in scripts/pnglibconf.dfa. This change + adds contrib/conftest/*.dfa files that can be used in automatic build + scripts to ensure that these configurations continue to build. + Enabled WRITE_INVERT and WRITE_PACK in contrib/pngminim/encoder. + Fixed pngvalid 'fail' function declaration on the Intel C Compiler. + This reverts to the previous 'static' implementation and works round + the 'unused static function' warning by using PNG_UNUSED(). + +Version 1.6.8beta02 [November 30, 2013] + Removed or marked PNG_UNUSED some harmless "dead assignments" reported + by clang scan-build. + Changed tabs to 3 spaces in png_debug macros and changed '"%s"m' + to '"%s" m' to improve portability among compilers. + Changed png_free_default() to free() in pngtest.c + +Version 1.6.8rc01 [December 12, 2013] + Tidied up pngfix inits and fixed pngtest no-write builds. + +Version 1.6.8rc02 [December 14, 2013] + Handle zero-length PLTE chunk or NULL palette with png_error() + instead of png_chunk_report(), which by default issues a warning + rather than an error, leading to later reading from a NULL pointer + (png_ptr->palette) in png_do_expand_palette(). This is CVE-2013-6954 + and VU#650142. Libpng-1.6.1 through 1.6.7 are vulnerable. + Libpng-1.6.0 and earlier do not have this bug. + +Version 1.6.8 [December 19, 2013] + No changes. + +Version 1.6.9beta01 [December 26, 2013] + Bookkeeping: Moved functions around (no changes). Moved transform + function definitions before the place where they are called so that + they can be made static. Move the intrapixel functions and the + grayscale palette builder out of the png?tran.c files. The latter + isn't a transform function and is no longer used internally, and the + former MNG specific functions are better placed in pngread/pngwrite.c + Made transform implementation functions static. This makes the internal + functions called by png_do_{read|write}_transformations static. On an + x86-64 DLL build (Gentoo Linux) this reduces the size of the text + segment of the DLL by 1208 bytes, about 0.6%. It also simplifies + maintenance by removing the declarations from pngpriv.h and allowing + easier changes to the internal interfaces. + Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69 + in the tar distributions. + +Version 1.6.9beta02 [January 1, 2014] + Added checks for libpng 1.5 to pngvalid.c. This supports the use of + this version of pngvalid in libpng 1.5 + Merged with pngvalid.c from libpng-1.7 changes to create a single + pngvalid.c + Removed #error macro from contrib/tools/pngfix.c (Thomas Klausner). + Merged pngrio.c, pngtrans.c, pngwio.c, and pngerror.c with libpng-1.7.0 + Merged libpng-1.7.0 changes to make no-interlace configurations work + with test programs. + Revised pngvalid.c to support libpng 1.5, which does not support the + PNG_MAXIMUM_INFLATE_WINDOW option, so #define it out when appropriate in + pngvalid.c + Allow unversioned links created on install to be disabled in configure. + In configure builds 'make install' changes/adds links like png.h + and libpng.a to point to the newly installed, versioned, files (e.g. + libpng17/png.h and libpng17.a). Three new configure options and some + rearrangement of Makefile.am allow creation of these links to be disabled. + +Version 1.6.9beta03 [January 10, 2014] + Removed potentially misleading warning from png_check_IHDR(). + +Version 1.6.9beta04 [January 20, 2014] + Updated scripts/makefile.* to use CPPFLAGS (Cosmin). + Added clang attribute support (Cosmin). + +Version 1.6.9rc01 [January 28, 2014] + No changes. + +Version 1.6.9rc02 [January 30, 2014] + Quiet an uninitialized memory warning from VC2013 in png_get_png(). + +Version 1.6.9 [February 6, 2014] + +Version 1.6.10beta01 [February 9, 2014] + Backported changes from libpng-1.7.0beta30 and beta31: + Fixed a large number of instances where PNGCBAPI was omitted from + function definitions. + Added pngimage test program for png_read_png() and png_write_png() + with two new test scripts. + Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling + png_set_packing() in png_read_png(). + Fixed combination of ~alpha with shift. On read invert alpha, processing + occurred after shift processing, which causes the final values to be + outside the range that should be produced by the shift. Reversing the + order on read makes the two transforms work together correctly and mirrors + the order used on write. + Do not read invalid sBIT chunks. Previously libpng only checked sBIT + values on write, so a malicious PNG writer could therefore cause + the read code to return an invalid sBIT chunk, which might lead to + application errors or crashes. Such chunks are now skipped (with + chunk_benign_error). + Make png_read_png() and png_write_png() prototypes in png.h depend + upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED. + Support builds with unsupported PNG_TRANSFORM_* values. All of the + PNG_TRANSFORM_* values are always defined in png.h and, because they + are used for both read and write in some cases, it is not reliable + to #if out ones that are totally unsupported. This change adds error + detection in png_read_image() and png_write_image() to do a + png_app_error() if the app requests something that cannot be done + and it adds corresponding code to pngimage.c to handle such options + by not attempting to test them. + +Version 1.6.10beta02 [February 23, 2014] + Moved redefines of png_error(), png_warning(), png_chunk_error(), + and png_chunk_warning() from pngpriv.h to png.h to make them visible + to libpng-calling applications. + Moved OS dependent code from arm/arm_init.c, to allow the included + implementation of the ARM NEON discovery function to be set at + build-time and provide sample implementations from the current code in the + contrib/arm-neon subdirectory. The __linux__ code has also been changed to + compile and link on Android by using /proc/cpuinfo, and the old linux code + is in contrib/arm-neon/linux-auxv.c. The new code avoids POSIX and Linux + dependencies apart from opening /proc/cpuinfo and is C90 compliant. + Check for info_ptr == NULL early in png_read_end() so we don't need to + run all the png_handle_*() and depend on them to return if info_ptr == NULL. + This improves the performance of png_read_end(png_ptr, NULL) and makes + it more robust against future programming errors. + Check for __has_extension before using it in pngconf.h, to + support older Clang versions (Jeremy Sequoia). + Treat CRC error handling with png_set_crc_action(), instead of with + png_set_benign_errors(), which has been the case since libpng-1.6.0beta18. + Use a user warning handler in contrib/gregbook/readpng2.c instead of default, + so warnings will be put on stderr even if libpng has CONSOLE_IO disabled. + Added png_ptr->process_mode = PNG_READ_IDAT_MODE in png_push_read_chunk + after recognizing the IDAT chunk, which avoids an infinite loop while + reading a datastream whose first IDAT chunk is of zero-length. + This fixes CERT VU#684412 and CVE-2014-0333. + Don't recognize known sRGB profiles as sRGB if they have been hacked, + but don't reject them and don't issue a copyright violation warning. + +Version 1.6.10beta03 [February 25, 2014] + Moved some documentation from png.h to libpng.3 and libpng-manual.txt + Minor editing of contrib/arm-neon/README and contrib/examples/*.c + +Version 1.6.10rc01 [February 27, 2014] + Fixed typos in the manual and in scripts/pnglibconf.dfa (CFLAGS -> CPPFLAGS + and PNG_USR_CONFIG -> PNG_USER_CONFIG). + +Version 1.6.10rc02 [February 28, 2014] + Removed unreachable return statement after png_chunk_error() + in pngrutil.c + +Version 1.6.10rc03 [March 4, 2014] + Un-deprecated png_data_freer(). + +Version 1.6.10 [March 6, 2014] + No changes. + +Version 1.6.11beta01 [March 17, 2014] + Use "if (value != 0)" instead of "if (value)" consistently. + Changed ZlibSrcDir from 1.2.5 to 1.2.8 in projects/vstudio. + Moved configuration information from the manual to the INSTALL file. + +Version 1.6.11beta02 [April 6, 2014] + Removed #if/#else/#endif from inside two pow() calls in pngvalid.c because + they were handled improperly by Portland Group's PGI-14.1 - PGI-14.3 + when using its "__builtin_pow()" function. + Silence 'unused parameter' build warnings (Cosmin Truta). + $(CP) is now used alongside $(RM_F). Also, use 'copy' instead of 'cp' + where applicable, and applied other minor makefile changes (Cosmin). + Don't warn about invalid dimensions exceeding user limits (Cosmin). + Allow an easy replacement of the default pre-built configuration + header with a custom header, via the make PNGLIBCONF_H_PREBUILT + macro (Cosmin). + +Version 1.6.11beta03 [April 6, 2014] + Fixed a typo in pngrutil.c, introduced in libpng-1.5.6, that interferes + with "blocky" expansion of sub-8-bit interlaced PNG files (Eric Huss). + Optionally use __builtin_bswap16() in png_do_swap(). + +Version 1.6.11beta04 [April 19, 2014] + Made progressive reading of interlaced images consistent with the + behavior of the sequential reader and consistent with the manual, by + moving some code out of the PNG_READ_INTERLACING_SUPPORTED blocks. The + row_callback now receives the proper pass number and unexpanded rows, when + png_combine_row() isn't built or used, and png_set_interlace_handling() + is not called. + Allow PNG_sRGB_PROFILE_CHECKING = (-1) to mean no sRGB profile checking. + +Version 1.6.11beta05 [April 26, 2014] + Do not reject ICC V2 profiles that lack padding (Kai-Uwe Behrmann). + Relocated closing bracket of the sRGB profile test loop to avoid getting + "Not recognizing known sRGB profile that has been edited" warning for + ICC V2 profiles that lack the MD5 signature in the profile header. + +Version 1.6.11beta06 [May 19, 2014] + Added PNG_SKIP_sRGB_CHECK_PROFILE choice for png_set_option(). + +Version 1.6.11rc01 [May 27, 2014] + No changes. + +Version 1.6.11rc02 [June 3, 2014] + Test ZLIB_VERNUM instead of PNG_ZLIB_VERNUM in contrib/tools/pngfix.c + +Version 1.6.11 [June 5, 2014] + No changes. + +Version 1.6.12rc01 [June 6, 2014] + Relocated new code from 1.6.11beta06 in png.c to a point after the + declarations (Max Stepin). + +Version 1.6.12rc02 [June 7, 2014] + Changed file permissions of contrib/tools/intgamma.sh, + test-driver, and compile from 0644 to 0755 (Cosmin). + +Version 1.6.12rc03 [June 8, 2014] + Ensure "__has_attribute()" macro exists before trying to use it with + old clang compilers (MacPorts Ticket #43939). + +Version 1.6.12 [June 12, 2014] + No changes. + +Version 1.6.13beta01 [July 4, 2014] + Quieted -Wsign-compare and -Wclobber compiler warnings in + contrib/pngminus/*.c + Added "(void) png_ptr;" where needed in contrib/gregbook to quiet + compiler complaints about unused pointers. + Split a long output string in contrib/gregbook/rpng2-x.c. + Added "PNG_SET_OPTION" requirement for sRGB chunk support to pnglibconf.dfa, + Needed for write-only support (John Bowler). + Changed "if defined(__ARM_NEON__)" to + "if (defined(__ARM_NEON__) || defined(__ARM_NEON))" (James Wu). + Fixed clang no-warning builds: png_digit was defined but never used. + +Version 1.6.13beta02 [July 21, 2014] + Fixed an incorrect separator ("/" should be "\") in scripts/makefile.vcwin32 + (bug report from Wolfgang S. Kechel). Bug was introduced in libpng-1.6.11. + Also fixed makefile.bc32, makefile.bor, makefile.msc, makefile.intel, and + makefile.tc3 similarly. + +Version 1.6.13beta03 [August 3, 2014] + Removed scripts/makefile.elf. It has not worked since libpng-1.5.0beta14 + due to elimination of the PNG_FUNCTION_EXPORT and PNG_DATA_EXPORT + definitions from pngconf.h. + Ensure that CMakeLists.txt makes the target "lib" directory before making + symbolic link into it (SourceForge bug report #226 by Rolf Timmermans). + +Version 1.6.13beta04 [August 8, 2014] + Added opinion that the ECCN (Export Control Classification Number) for + libpng is EAR99 to the README file. + Eliminated use of "$<" in makefile explicit rules, when copying + $PNGLIBCONF_H_PREBUILT. This does not work on some versions of make; + bug introduced in libpng version 1.6.11. + +Version 1.6.13rc01 [August 14, 2014] + Made "ccopts" agree with "CFLAGS" in scripts/makefile.hp* and makefile.*sunu + +Version 1.6.13 [August 21, 2014] + No changes. + +Version 1.6.14beta01 [September 14, 2014] + Guard usage of png_ptr->options with #ifdef PNG_SET_OPTION_SUPPORTED. + Do not build contrib/tools/pngfix.c when PNG_SETJMP_NOT_SUPPORTED, + to allow "make" to complete without setjmp support (bug report by + Claudio Fontana) + Add "#include " to contrib/tools/pngfix.c (John Bowler) + +Version 1.6.14beta02 [September 18, 2014] + Use nanosleep() instead of usleep() in contrib/gregbook/rpng2-x.c + because usleep() is deprecated. + Define usleep() in contrib/gregbook/rpng2-x.c if not already defined + in unistd.h and nanosleep() is not available; fixes error introduced + in libpng-1.6.13. + Disable floating point exception handling in pngvalid.c when + PNG_FLOATING_ARITHMETIC is not supported (bug report by "zootus + at users.sourceforge.net"). + +Version 1.6.14beta03 [September 19, 2014] + Define FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in pngvalid.c if not + already defined. Revert floating point exception handling in pngvalid.c + to version 1.6.14beta01 behavior. + +Version 1.6.14beta04 [September 27, 2014] + Fixed incorrect handling of the iTXt compression flag in pngrutil.c + (bug report by Shunsaku Hirata). Bug was introduced in libpng-1.6.0. + +Version 1.6.14beta05 [October 1, 2014] + Added "option READ_iCCP enables READ_COMPRESSED_TEXT" to pnglibconf.dfa + +Version 1.6.14beta06 [October 5, 2014] + Removed unused "text_len" parameter from private function png_write_zTXt(). + Conditionally compile some code in png_deflate_claim(), when + PNG_WARNINGS_SUPPORTED and PNG_ERROR_TEXT_SUPPORTED are disabled. + Replaced repeated code in pngpread.c with PNG_PUSH_SAVE_BUFFER_IF_FULL. + Added "chunk iTXt enables TEXT" and "chunk zTXt enables TEXT" + to pnglibconf.dfa. + Removed "option READ_COMPRESSED_TEXT enables READ_TEXT" from pnglibconf.dfa, + to make it possible to configure a libpng that supports iCCP but not TEXT. + +Version 1.6.14beta07 [October 7, 2014] + Removed "option WRITE_COMPRESSED_TEXT enables WRITE_TEXT" from pnglibconf.dfa + Only mark text chunks as written after successfully writing them. + +Version 1.6.14rc01 [October 15, 2014] + Fixed some typos in comments. + +Version 1.6.14rc02 [October 17, 2014] + Changed png_convert_to_rfc_1123() to png_convert_to_rfc_1123_buffer() + in the manual, to reflect the change made in libpng-1.6.0. + Updated README file to explain that direct access to the png_struct + and info_struct members has not been permitted since libpng-1.5.0. + +Version 1.6.14 [October 23, 2014] + No changes. + +Version 1.6.15beta01 [October 29, 2014] + Changed "if (!x)" to "if (x == 0)" and "if (x)" to "if (x != 0)" + Simplified png_free_data(). + Added missing "ptr = NULL" after some instances of png_free(). + +Version 1.6.15beta02 [November 1, 2014] + Changed remaining "if (!x)" to "if (x == 0)" and "if (x)" to "if (x != 0)" + +Version 1.6.15beta03 [November 3, 2014] + Added PNG_USE_ARM_NEON configuration flag (Marcin Juszkiewicz). + +Version 1.6.15beta04 [November 4, 2014] + Removed new PNG_USE_ARM_NEON configuration flag and made a one-line + revision to configure.ac to support ARM on aarch64 instead (John Bowler). + +Version 1.6.15beta05 [November 5, 2014] + Use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING in + example.c, pngtest.c, and applications in the contrib directory. + Avoid out-of-bounds memory access in png_user_version_check(). + Simplified and future-proofed png_user_version_check(). + Fixed GCC unsigned int->float warnings. Various versions of GCC + seem to generate warnings when an unsigned value is implicitly + converted to double. This is probably a GCC bug but this change + avoids the issue by explicitly converting to (int) where safe. + Free all allocated memory in pngimage. The file buffer cache was left + allocated at the end of the program, harmless but it causes memory + leak reports from clang. + Fixed array size calculations to avoid warnings. At various points + in the code the number of elements in an array is calculated using + sizeof. This generates a compile time constant of type (size_t) which + is then typically assigned to an (unsigned int) or (int). Some versions + of GCC on 64-bit systems warn about the apparent narrowing, even though + the same compiler does apparently generate the correct, in-range, + numeric constant. This adds appropriate, safe, casts to make the + warnings go away. + +Version 1.6.15beta06 [November 6, 2014] + Reverted use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING + in the manual, example.c, pngtest.c, and applications in the contrib + directory. It was incorrect advice. + +Version 1.6.15beta07 [November 7, 2014] + Removed #ifdef PNG_16BIT_SUPPORTED/#endif around png_product2(); it is + needed by png_reciprocal2(). + Added #ifdef PNG_16BIT_SUPPORTED/#endif around png_log16bit() and + png_do_swap(). + Changed all "#endif /* PNG_FEATURE_SUPPORTED */" to "#endif /* FEATURE */" + +Version 1.6.15beta08 [November 8, 2014] + More housecleaning in *.h + +Version 1.6.15rc01 [November 13, 2014] + +Version 1.6.15rc02 [November 14, 2014] + The macros passed in the command line to Borland make were ignored if + similarly-named macros were already defined in makefiles. This behavior + is different from POSIX make and other make programs. Surround the + macro definitions with ifndef guards (Cosmin). + +Version 1.6.15rc03 [November 16, 2014] + Added "-D_CRT_SECURE_NO_WARNINGS" to CFLAGS in scripts/makefile.vcwin32. + Removed the obsolete $ARCH variable from scripts/makefile.darwin. + +Version 1.6.15 [November 20, 2014] + No changes. + +Version 1.6.16beta01 [December 14, 2014] + Added ".align 2" to arm/filter_neon.S to support old GAS assemblers that + don't do alignment correctly. + Revised Makefile.am and scripts/symbols.dfn to work with MinGW/MSYS + (Bob Friesenhahn). + +Version 1.6.16beta02 [December 15, 2014] + Revised Makefile.am and scripts/*.dfn again to work with MinGW/MSYS; + renamed scripts/*.dfn to scripts/*.c (John Bowler). + +Version 1.6.16beta03 [December 21, 2014] + Quiet a "comparison always true" warning in pngstest.c (John Bowler). + +Version 1.6.16rc01 [December 21, 2014] + Restored a test on width that was removed from png.c at libpng-1.6.9 + (Bug report by Alex Eubanks). + +Version 1.6.16rc02 [December 21, 2014] + Undid the update to pngrutil.c in 1.6.16rc01. + +Version 1.6.16rc03 [December 21, 2014] + Fixed an overflow in png_combine_row with very wide interlaced images. + +Version 1.6.16 [December 22, 2014] + No changes. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit @@ -3540,5 +5156,3 @@ to subscribe) or to glennrp at users.sourceforge.net Glenn R-P -*/ } -#endif diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/LICENSE b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/LICENSE index 89f5243f164..f912f6a6d9b 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/LICENSE +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/LICENSE @@ -10,8 +10,8 @@ this sentence. This code is released under the libpng license. -libpng versions 1.2.6, August 15, 2004, through 1.5.4, July 7, 2011, are -Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are +libpng versions 1.2.6, August 15, 2004, through 1.6.16, December 22, 2014, are +Copyright (c) 2004, 2006-2014 Glenn Randers-Pehrson, and are distributed according to the same disclaimer and license as libpng-1.2.5 with the following individual added to the list of Contributing Authors @@ -108,4 +108,4 @@ certification mark of the Open Source Initiative. Glenn Randers-Pehrson glennrp at users.sourceforge.net -July 7, 2011 +December 22, 2014 diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/README b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/README index 71396a8d9d0..8c5b0b2f153 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/README +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/README @@ -1,11 +1,11 @@ -README for libpng version 1.5.4 - July 7, 2011 (shared library 15.0) +README for libpng version 1.6.16 - December 22, 2014 (shared library 16.0) See the note about version numbers near the top of png.h See INSTALL for instructions on how to install libpng. -Libpng comes in several distribution formats. Get libpng-*.tar.gz, -libpng-*.tar.xz or libpng-*.tar.bz2 if you want UNIX-style line endings -in the text files, or lpng*.zip if you want DOS-style line endings. +Libpng comes in several distribution formats. Get libpng-*.tar.gz or +libpng-*.tar.xz or if you want UNIX-style line endings in the text files, +or lpng*.7z or lpng*.zip if you want DOS-style line endings. Version 0.89 was the first official release of libpng. Don't let the fact that it's the first release fool you. The libpng library has been in @@ -23,18 +23,25 @@ earlier versions if you are using a shared library. The type of the png_uint_32, which will affect shared-library applications that use this function. -To avoid problems with changes to the internals of png_info_struct, +To avoid problems with changes to the internals of png info_struct, new APIs have been made available in 0.95 to avoid direct application access to info_ptr. These functions are the png_set_ and png_get_ functions. These functions should be used when accessing/storing the info_struct data, rather than manipulating it directly, to avoid such problems in the future. -It is important to note that the APIs do not make current programs +It is important to note that the APIs did not make current programs that access the info struct directly incompatible with the new -library. However, it is strongly suggested that new programs use -the new APIs (as shown in example.c and pngtest.c), and older programs -be converted to the new format, to facilitate upgrades in the future. +library, through libpng-1.2.x. In libpng-1.4.x, which was meant to +be a transitional release, members of the png_struct and the +info_struct can still be accessed, but the compiler will issue a +warning about deprecated usage. Since libpng-1.5.0, direct access +to these structs is not allowed, and the definitions of the structs +reside in private pngstruct.h and pnginfo.h header files that are not +accessible to applications. It is strongly suggested that new +programs use the new APIs (as shown in example.c and pngtest.c), and +older programs be converted to the new format, to facilitate upgrades +in the future. **** Additions since 0.90 include the ability to compile libpng as a @@ -77,17 +84,21 @@ compression library that is useful for more things than just PNG files. You can use zlib as a drop-in replacement for fread() and fwrite() if you are so inclined. -zlib should be available at the same place that libpng is, or at. -ftp://ftp.info-zip.org/pub/infozip/zlib +zlib should be available at the same place that libpng is, or at zlib.net. You may also want a copy of the PNG specification. It is available as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find these at http://www.libpng.org/pub/png/documents/ This code is currently being archived at libpng.sf.net in the -[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT) -at GO GRAPHSUP. If you can't find it in any of those places, -e-mail me, and I'll help you find it. +[DOWNLOAD] area, and at ftp://ftp.simplesystems.org. If you can't find it +in any of those places, e-mail me, and I'll help you find it. + +I am not a lawyer, but I believe that the Export Control Classification +Number (ECCN) for libpng is EAR99, which means not subject to export +controls or International Traffic in Arms Regulations (ITAR) because it +is open source, publicly available software, that does not contain any +encryption software. See the EAR, paragraphs 734.3(b)(3) and 734.7(b). If you have any code changes, requests, problems, etc., please e-mail them to me. Also, I'd appreciate any make files or project files, @@ -105,7 +116,7 @@ based in a large way on Guy's and Andreas' earlier work), and the PNG development group. Send comments/corrections/commendations to png-mng-implement at -lists.sourceforge.net (subscription required; visit +lists.sourceforge.net (subscription required; visit https://lists.sourceforge.net/lists/listinfo/png-mng-implement to subscribe) or to glennrp at users.sourceforge.net @@ -123,7 +134,7 @@ and ...". If in doubt, send questions to me. I'll bounce them to others, if necessary. Please do not send suggestions on how to change PNG. We have -been discussing PNG for sixteen years now, and it is official and +been discussing PNG for nineteen years now, and it is official and finished. If you have suggestions for libpng, however, I'll gladly listen. Even if your suggestion is not used immediately, it may be used later. @@ -167,23 +178,25 @@ Files in this distribution: pngwrite.c => High-level write functions pngwtran.c => Write data transformations pngwutil.c => Write utility functions + arm => Contains optimized code for the ARM platform contrib => Contributions + examples => Example programs gregbook => source code for PNG reading and writing, from Greg Roelofs' "PNG: The Definitive Guide", O'Reilly, 1999 - msvctest => Builds and runs pngtest using a MSVC workspace - pngminus => Simple pnm2png and png2pnm programs - pngsuite => Test images - visupng => Contains a MSVC workspace for VisualPng + libtests => Test programs + pngminim => Minimal decoder, encoder, and progressive decoder + programs demonstrating use of pngusr.dfa + pngminus => Simple pnm2png and png2pnm programs + pngsuite => Test images + tools => Various tools + visupng => Contains a MSVC workspace for VisualPng projects => Contains project files and workspaces for building a DLL - cbuilder5 => Contains a Borland workspace for building - libpng and zlib - visualc6 => Contains a Microsoft Visual C++ (MSVC) - workspace for building libpng and zlib + owatcom => Contains a WATCOM project for building libpng visualc71 => Contains a Microsoft Visual C++ (MSVC) workspace for building libpng and zlib - xcode => Contains an Apple xcode + vstudio => Contains a Microsoft Visual C++ (MSVC) workspace for building libpng and zlib scripts => Directory containing scripts for building libpng: (see scripts/README.txt for the list of scripts) diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/png.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/png.c index 23dd8c54ae2..d7682a1c4fd 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/png.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/png.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.16 [December 22, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -42,7 +42,7 @@ #include "pngpriv.h" /* Generate a compiler error if there is an old png.h in the search path. */ -typedef png_libpng_version_1_5_4 Your_png_h_is_not_version_1_5_4; +typedef png_libpng_version_1_6_16 Your_png_h_is_not_version_1_6_16; /* Tells libpng that we have already handled the first "num_bytes" bytes * of the PNG file signature. If the PNG data is embedded into another @@ -52,7 +52,7 @@ typedef png_libpng_version_1_5_4 Your_png_h_is_not_version_1_5_4; #ifdef PNG_READ_SUPPORTED void PNGAPI -png_set_sig_bytes(png_structp png_ptr, int num_bytes) +png_set_sig_bytes(png_structrp png_ptr, int num_bytes) { png_debug(1, "in png_set_sig_bytes"); @@ -71,7 +71,7 @@ png_set_sig_bytes(png_structp png_ptr, int num_bytes) * can simply check the remaining bytes for extra assurance. Returns * an integer less than, equal to, or greater than zero if sig is found, * respectively, to be less than, to match, or be greater than the correct - * PNG signature (this is the same behaviour as strcmp, memcmp, etc). + * PNG signature (this is the same behavior as strcmp, memcmp, etc). */ int PNGAPI png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check) @@ -90,52 +90,47 @@ png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check) if (start + num_to_check > 8) num_to_check = 8 - start; - return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check))); + return ((int)(memcmp(&sig[start], &png_signature[start], num_to_check))); } -#endif /* PNG_READ_SUPPORTED */ +#endif /* READ */ #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) /* Function to allocate memory for zlib */ PNG_FUNCTION(voidpf /* PRIVATE */, png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED) { - png_voidp ptr; - png_structp p=(png_structp)png_ptr; - png_uint_32 save_flags=p->flags; - png_alloc_size_t num_bytes; + png_alloc_size_t num_bytes = size; if (png_ptr == NULL) - return (NULL); + return NULL; - if (items > PNG_UINT_32_MAX/size) + if (items >= (~(png_alloc_size_t)0)/size) { - png_warning (p, "Potential overflow in png_zalloc()"); - return (NULL); + png_warning (png_voidcast(png_structrp, png_ptr), + "Potential overflow in png_zalloc()"); + return NULL; } - num_bytes = (png_alloc_size_t)items * size; - p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; - ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); - p->flags=save_flags; - - return ((voidpf)ptr); + num_bytes *= items; + return png_malloc_warn(png_voidcast(png_structrp, png_ptr), num_bytes); } /* Function to free memory for zlib */ void /* PRIVATE */ png_zfree(voidpf png_ptr, voidpf ptr) { - png_free((png_structp)png_ptr, (png_voidp)ptr); + png_free(png_voidcast(png_const_structrp,png_ptr), ptr); } /* Reset the CRC variable to 32 bits of 1's. Care must be taken * in case CRC is > 32 bits to leave the top bits 0. */ void /* PRIVATE */ -png_reset_crc(png_structp png_ptr) +png_reset_crc(png_structrp png_ptr) { - png_ptr->crc = crc32(0, Z_NULL, 0); + /* The cast is safe because the crc is a 32 bit value. */ + png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0); } /* Calculate the CRC over a section of data. We can only pass as @@ -144,119 +139,254 @@ png_reset_crc(png_structp png_ptr) * trouble of calculating it. */ void /* PRIVATE */ -png_calculate_crc(png_structp png_ptr, png_const_bytep ptr, png_size_t length) +png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, png_size_t length) { int need_crc = 1; - if (png_ptr->chunk_name[0] & 0x20) /* ancillary */ + if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0) { if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) need_crc = 0; } - else /* critical */ + else /* critical */ { - if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) + if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0) need_crc = 0; } - if (need_crc) - png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length); -} - -/* Check a user supplied version number, called from both read and write - * functions that create a png_struct - */ -int -png_user_version_check(png_structp png_ptr, png_const_charp user_png_ver) -{ - if (user_png_ver) + /* 'uLong' is defined in zlib.h as unsigned long; this means that on some + * systems it is a 64 bit value. crc32, however, returns 32 bits so the + * following cast is safe. 'uInt' may be no more than 16 bits, so it is + * necessary to perform a loop here. + */ + if (need_crc != 0 && length > 0) { - int i = 0; + uLong crc = png_ptr->crc; /* Should never issue a warning */ do { - if (user_png_ver[i] != png_libpng_ver[i]) + uInt safe_length = (uInt)length; + if (safe_length == 0) + safe_length = (uInt)-1; /* evil, but safe */ + + crc = crc32(crc, ptr, safe_length); + + /* The following should never issue compiler warnings; if they do the + * target system has characteristics that will probably violate other + * assumptions within the libpng code. + */ + ptr += safe_length; + length -= safe_length; + } + while (length > 0); + + /* And the following is always safe because the crc is only 32 bits. */ + png_ptr->crc = (png_uint_32)crc; + } +} + +/* Check a user supplied version number, called from both read and write + * functions that create a png_struct. + */ +int +png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver) +{ + /* Libpng versions 1.0.0 and later are binary compatible if the version + * string matches through the second '.'; we must recompile any + * applications that use any older library version. + */ + + if (user_png_ver != NULL) + { + int i = -1; + int found_dots = 0; + + do + { + i++; + if (user_png_ver[i] != PNG_LIBPNG_VER_STRING[i]) png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; - } while (png_libpng_ver[i++]); + if (user_png_ver[i] == '.') + found_dots++; + } while (found_dots < 2 && user_png_ver[i] != 0 && + PNG_LIBPNG_VER_STRING[i] != 0); } else png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; - if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) + if ((png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) != 0) { - /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so - * we must recompile any applications that use any older library version. - * For versions after libpng 1.0, we will be compatible, so we need - * only check the first digit. - */ - if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || - (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || - (user_png_ver[0] == '0' && user_png_ver[2] < '9')) - { #ifdef PNG_WARNINGS_SUPPORTED - size_t pos = 0; - char m[128]; + size_t pos = 0; + char m[128]; - pos = png_safecat(m, sizeof m, pos, "Application built with libpng-"); - pos = png_safecat(m, sizeof m, pos, user_png_ver); - pos = png_safecat(m, sizeof m, pos, " but running with "); - pos = png_safecat(m, sizeof m, pos, png_libpng_ver); + pos = png_safecat(m, (sizeof m), pos, + "Application built with libpng-"); + pos = png_safecat(m, (sizeof m), pos, user_png_ver); + pos = png_safecat(m, (sizeof m), pos, " but running with "); + pos = png_safecat(m, (sizeof m), pos, PNG_LIBPNG_VER_STRING); + PNG_UNUSED(pos) - png_warning(png_ptr, m); + png_warning(png_ptr, m); #endif #ifdef PNG_ERROR_NUMBERS_SUPPORTED - png_ptr->flags = 0; + png_ptr->flags = 0; #endif - return 0; - } + return 0; } /* Success return. */ return 1; } -/* Allocate the memory for an info_struct for the application. We don't - * really need the png_ptr, but it could potentially be useful in the - * future. This should be used in favour of malloc(png_sizeof(png_info)) - * and png_info_init() so that applications that want to use a shared - * libpng don't have to be recompiled if png_info changes size. +/* Generic function to create a png_struct for either read or write - this + * contains the common initialization. */ -PNG_FUNCTION(png_infop,PNGAPI -png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED) +PNG_FUNCTION(png_structp /* PRIVATE */, +png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) { - png_infop info_ptr; + png_struct create_struct; +# ifdef PNG_SETJMP_SUPPORTED + jmp_buf create_jmp_buf; +# endif + + /* This temporary stack-allocated structure is used to provide a place to + * build enough context to allow the user provided memory allocator (if any) + * to be called. + */ + memset(&create_struct, 0, (sizeof create_struct)); + + /* Added at libpng-1.2.6 */ +# ifdef PNG_USER_LIMITS_SUPPORTED + create_struct.user_width_max = PNG_USER_WIDTH_MAX; + create_struct.user_height_max = PNG_USER_HEIGHT_MAX; + +# ifdef PNG_USER_CHUNK_CACHE_MAX + /* Added at libpng-1.2.43 and 1.4.0 */ + create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; +# endif + +# ifdef PNG_USER_CHUNK_MALLOC_MAX + /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists + * in png_struct regardless. + */ + create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; +# endif +# endif + + /* The following two API calls simply set fields in png_struct, so it is safe + * to do them now even though error handling is not yet set up. + */ +# ifdef PNG_USER_MEM_SUPPORTED + png_set_mem_fn(&create_struct, mem_ptr, malloc_fn, free_fn); +# else + PNG_UNUSED(mem_ptr) + PNG_UNUSED(malloc_fn) + PNG_UNUSED(free_fn) +# endif + + /* (*error_fn) can return control to the caller after the error_ptr is set, + * this will result in a memory leak unless the error_fn does something + * extremely sophisticated. The design lacks merit but is implicit in the + * API. + */ + png_set_error_fn(&create_struct, error_ptr, error_fn, warn_fn); + +# ifdef PNG_SETJMP_SUPPORTED + if (!setjmp(create_jmp_buf)) + { + /* Temporarily fake out the longjmp information until we have + * successfully completed this function. This only works if we have + * setjmp() support compiled in, but it is safe - this stuff should + * never happen. + */ + create_struct.jmp_buf_ptr = &create_jmp_buf; + create_struct.jmp_buf_size = 0; /*stack allocation*/ + create_struct.longjmp_fn = longjmp; +# else + { +# endif + /* Call the general version checker (shared with read and write code): + */ + if (png_user_version_check(&create_struct, user_png_ver) != 0) + { + png_structrp png_ptr = png_voidcast(png_structrp, + png_malloc_warn(&create_struct, (sizeof *png_ptr))); + + if (png_ptr != NULL) + { + /* png_ptr->zstream holds a back-pointer to the png_struct, so + * this can only be done now: + */ + create_struct.zstream.zalloc = png_zalloc; + create_struct.zstream.zfree = png_zfree; + create_struct.zstream.opaque = png_ptr; + +# ifdef PNG_SETJMP_SUPPORTED + /* Eliminate the local error handling: */ + create_struct.jmp_buf_ptr = NULL; + create_struct.jmp_buf_size = 0; + create_struct.longjmp_fn = 0; +# endif + + *png_ptr = create_struct; + + /* This is the successful return point */ + return png_ptr; + } + } + } + + /* A longjmp because of a bug in the application storage allocator or a + * simple failure to allocate the png_struct. + */ + return NULL; +} + +/* Allocate the memory for an info_struct for the application. */ +PNG_FUNCTION(png_infop,PNGAPI +png_create_info_struct,(png_const_structrp png_ptr),PNG_ALLOCATED) +{ + png_inforp info_ptr; png_debug(1, "in png_create_info_struct"); if (png_ptr == NULL) - return (NULL); + return NULL; + + /* Use the internal API that does not (or at least should not) error out, so + * that this call always returns ok. The application typically sets up the + * error handling *after* creating the info_struct because this is the way it + * has always been done in 'example.c'. + */ + info_ptr = png_voidcast(png_inforp, png_malloc_base(png_ptr, + (sizeof *info_ptr))); -#ifdef PNG_USER_MEM_SUPPORTED - info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, - png_ptr->malloc_fn, png_ptr->mem_ptr); -#else - info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); -#endif if (info_ptr != NULL) - png_info_init_3(&info_ptr, png_sizeof(png_info)); + memset(info_ptr, 0, (sizeof *info_ptr)); - return (info_ptr); + return info_ptr; } /* This function frees the memory associated with a single info struct. * Normally, one would use either png_destroy_read_struct() or * png_destroy_write_struct() to free an info struct, but this may be - * useful for some applications. + * useful for some applications. From libpng 1.6.0 this function is also used + * internally to implement the png_info release part of the 'struct' destroy + * APIs. This ensures that all possible approaches free the same data (all of + * it). */ void PNGAPI -png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) +png_destroy_info_struct(png_const_structrp png_ptr, png_infopp info_ptr_ptr) { - png_infop info_ptr = NULL; + png_inforp info_ptr = NULL; png_debug(1, "in png_destroy_info_struct"); @@ -268,46 +398,57 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) if (info_ptr != NULL) { - png_info_destroy(png_ptr, info_ptr); - -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn, - png_ptr->mem_ptr); -#else - png_destroy_struct((png_voidp)info_ptr); -#endif + /* Do this first in case of an error below; if the app implements its own + * memory management this can lead to png_free calling png_error, which + * will abort this routine and return control to the app error handler. + * An infinite loop may result if it then tries to free the same info + * ptr. + */ *info_ptr_ptr = NULL; + + png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + memset(info_ptr, 0, (sizeof *info_ptr)); + png_free(png_ptr, info_ptr); } } /* Initialize the info structure. This is now an internal function (0.89) * and applications using it are urged to use png_create_info_struct() - * instead. + * instead. Use deprecated in 1.6.0, internal use removed (used internally it + * is just a memset). + * + * NOTE: it is almost inconceivable that this API is used because it bypasses + * the user-memory mechanism and the user error handling/warning mechanisms in + * those cases where it does anything other than a memset. */ - -void PNGAPI -png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) +PNG_FUNCTION(void,PNGAPI +png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size), + PNG_DEPRECATED) { - png_infop info_ptr = *ptr_ptr; + png_inforp info_ptr = *ptr_ptr; png_debug(1, "in png_info_init_3"); if (info_ptr == NULL) return; - if (png_sizeof(png_info) > png_info_struct_size) + if ((sizeof (png_info)) > png_info_struct_size) { - png_destroy_struct(info_ptr); - info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); + *ptr_ptr = NULL; + /* The following line is why this API should not be used: */ + free(info_ptr); + info_ptr = png_voidcast(png_inforp, png_malloc_base(NULL, + (sizeof *info_ptr))); *ptr_ptr = info_ptr; } /* Set everything to 0 */ - png_memset(info_ptr, 0, png_sizeof(png_info)); + memset(info_ptr, 0, (sizeof *info_ptr)); } +/* The following API is not called internally */ void PNGAPI -png_data_freer(png_structp png_ptr, png_infop info_ptr, +png_data_freer(png_const_structrp png_ptr, png_inforp info_ptr, int freer, png_uint_32 mask) { png_debug(1, "in png_data_freer"); @@ -322,12 +463,11 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr, info_ptr->free_me &= ~mask; else - png_warning(png_ptr, - "Unknown freer parameter in png_data_freer"); + png_error(png_ptr, "Unknown freer parameter in png_data_freer"); } void PNGAPI -png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, +png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask, int num) { png_debug(1, "in png_free_data"); @@ -337,32 +477,32 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_TEXT_SUPPORTED /* Free text item num or (if num == -1) all text items */ - if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) + if (info_ptr->text != 0 && + ((mask & PNG_FREE_TEXT) & info_ptr->free_me) != 0) { if (num != -1) { - if (info_ptr->text && info_ptr->text[num].key) - { - png_free(png_ptr, info_ptr->text[num].key); - info_ptr->text[num].key = NULL; - } + png_free(png_ptr, info_ptr->text[num].key); + info_ptr->text[num].key = NULL; } else { int i; + for (i = 0; i < info_ptr->num_text; i++) - png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i); + png_free(png_ptr, info_ptr->text[i].key); + png_free(png_ptr, info_ptr->text); info_ptr->text = NULL; - info_ptr->num_text=0; + info_ptr->num_text = 0; } } #endif #ifdef PNG_tRNS_SUPPORTED /* Free any tRNS entry */ - if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) + if (((mask & PNG_FREE_TRNS) & info_ptr->free_me) != 0) { png_free(png_ptr, info_ptr->trans_alpha); info_ptr->trans_alpha = NULL; @@ -372,7 +512,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_sCAL_SUPPORTED /* Free any sCAL entry */ - if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) + if (((mask & PNG_FREE_SCAL) & info_ptr->free_me) != 0) { png_free(png_ptr, info_ptr->scal_s_width); png_free(png_ptr, info_ptr->scal_s_height); @@ -384,20 +524,20 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_pCAL_SUPPORTED /* Free any pCAL entry */ - if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) + if (((mask & PNG_FREE_PCAL) & info_ptr->free_me) != 0) { png_free(png_ptr, info_ptr->pcal_purpose); png_free(png_ptr, info_ptr->pcal_units); info_ptr->pcal_purpose = NULL; info_ptr->pcal_units = NULL; + if (info_ptr->pcal_params != NULL) { int i; - for (i = 0; i < (int)info_ptr->pcal_nparams; i++) - { + + for (i = 0; i < info_ptr->pcal_nparams; i++) png_free(png_ptr, info_ptr->pcal_params[i]); - info_ptr->pcal_params[i] = NULL; - } + png_free(png_ptr, info_ptr->pcal_params); info_ptr->pcal_params = NULL; } @@ -406,8 +546,8 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #endif #ifdef PNG_iCCP_SUPPORTED - /* Free any iCCP entry */ - if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) + /* Free any profile entry */ + if (((mask & PNG_FREE_ICCP) & info_ptr->free_me) != 0) { png_free(png_ptr, info_ptr->iccp_name); png_free(png_ptr, info_ptr->iccp_profile); @@ -419,26 +559,28 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_sPLT_SUPPORTED /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ - if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) + if (info_ptr->splt_palettes != 0 && + ((mask & PNG_FREE_SPLT) & info_ptr->free_me) != 0) { if (num != -1) { - if (info_ptr->splt_palettes) - { - png_free(png_ptr, info_ptr->splt_palettes[num].name); - png_free(png_ptr, info_ptr->splt_palettes[num].entries); - info_ptr->splt_palettes[num].name = NULL; - info_ptr->splt_palettes[num].entries = NULL; - } + png_free(png_ptr, info_ptr->splt_palettes[num].name); + png_free(png_ptr, info_ptr->splt_palettes[num].entries); + info_ptr->splt_palettes[num].name = NULL; + info_ptr->splt_palettes[num].entries = NULL; } else { - if (info_ptr->splt_palettes_num) + if (info_ptr->splt_palettes_num != 0) { int i; - for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) - png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i); + + for (i = 0; i < info_ptr->splt_palettes_num; i++) + { + png_free(png_ptr, info_ptr->splt_palettes[i].name); + png_free(png_ptr, info_ptr->splt_palettes[i].entries); + } png_free(png_ptr, info_ptr->splt_palettes); info_ptr->splt_palettes = NULL; @@ -449,32 +591,24 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, } #endif -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED - if (png_ptr->unknown_chunk.data) - { - png_free(png_ptr, png_ptr->unknown_chunk.data); - png_ptr->unknown_chunk.data = NULL; - } - - if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED + if (info_ptr->unknown_chunks != 0 && + ((mask & PNG_FREE_UNKN) & info_ptr->free_me) != 0) { if (num != -1) { - if (info_ptr->unknown_chunks) - { - png_free(png_ptr, info_ptr->unknown_chunks[num].data); - info_ptr->unknown_chunks[num].data = NULL; - } + png_free(png_ptr, info_ptr->unknown_chunks[num].data); + info_ptr->unknown_chunks[num].data = NULL; } else { int i; - if (info_ptr->unknown_chunks_num) + if (info_ptr->unknown_chunks_num != 0) { for (i = 0; i < info_ptr->unknown_chunks_num; i++) - png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); + png_free(png_ptr, info_ptr->unknown_chunks[i].data); png_free(png_ptr, info_ptr->unknown_chunks); info_ptr->unknown_chunks = NULL; @@ -486,7 +620,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_hIST_SUPPORTED /* Free any hIST entry */ - if ((mask & PNG_FREE_HIST) & info_ptr->free_me) + if (((mask & PNG_FREE_HIST) & info_ptr->free_me) != 0) { png_free(png_ptr, info_ptr->hist); info_ptr->hist = NULL; @@ -495,9 +629,9 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #endif /* Free any PLTE entry that was internally allocated */ - if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) + if (((mask & PNG_FREE_PLTE) & info_ptr->free_me) != 0) { - png_zfree(png_ptr, info_ptr->palette); + png_free(png_ptr, info_ptr->palette); info_ptr->palette = NULL; info_ptr->valid &= ~PNG_INFO_PLTE; info_ptr->num_palette = 0; @@ -505,16 +639,14 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, #ifdef PNG_INFO_IMAGE_SUPPORTED /* Free any image bits attached to the info structure */ - if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) + if (((mask & PNG_FREE_ROWS) & info_ptr->free_me) != 0) { - if (info_ptr->row_pointers) + if (info_ptr->row_pointers != 0) { - int row; - for (row = 0; row < (int)info_ptr->height; row++) - { + png_uint_32 row; + for (row = 0; row < info_ptr->height; row++) png_free(png_ptr, info_ptr->row_pointers[row]); - info_ptr->row_pointers[row] = NULL; - } + png_free(png_ptr, info_ptr->row_pointers); info_ptr->row_pointers = NULL; } @@ -527,37 +659,14 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, info_ptr->free_me &= ~mask; } - -/* This is an internal routine to free any memory that the info struct is - * pointing to before re-using it or freeing the struct itself. Recall - * that png_free() checks for NULL pointers for us. - */ -void /* PRIVATE */ -png_info_destroy(png_structp png_ptr, png_infop info_ptr) -{ - png_debug(1, "in png_info_destroy"); - - png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - if (png_ptr->num_chunk_list) - { - png_free(png_ptr, png_ptr->chunk_list); - png_ptr->chunk_list = NULL; - png_ptr->num_chunk_list = 0; - } -#endif - - png_info_init_3(&info_ptr, png_sizeof(png_info)); -} -#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ +#endif /* READ || WRITE */ /* This function returns a pointer to the io_ptr associated with the user * functions. The application should free any memory associated with this * pointer before png_write_destroy() or png_read_destroy() are called. */ png_voidp PNGAPI -png_get_io_ptr(png_structp png_ptr) +png_get_io_ptr(png_const_structrp png_ptr) { if (png_ptr == NULL) return (NULL); @@ -570,11 +679,11 @@ png_get_io_ptr(png_structp png_ptr) /* Initialize the default input/output functions for the PNG file. If you * use your own read or write routines, you can call either png_set_read_fn() * or png_set_write_fn() instead of png_init_io(). If you have defined - * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't - * necessarily available. + * PNG_NO_STDIO or otherwise disabled PNG_STDIO_SUPPORTED, you must use a + * function of your own because "FILE *" isn't necessarily available. */ void PNGAPI -png_init_io(png_structp png_ptr, png_FILE_p fp) +png_init_io(png_structrp png_ptr, png_FILE_p fp) { png_debug(1, "in png_init_io"); @@ -585,44 +694,64 @@ png_init_io(png_structp png_ptr, png_FILE_p fp) } # endif +#ifdef PNG_SAVE_INT_32_SUPPORTED +/* The png_save_int_32 function assumes integers are stored in two's + * complement format. If this isn't the case, then this routine needs to + * be modified to write data in two's complement format. Note that, + * the following works correctly even if png_int_32 has more than 32 bits + * (compare the more complex code required on read for sign extension.) + */ +void PNGAPI +png_save_int_32(png_bytep buf, png_int_32 i) +{ + buf[0] = (png_byte)((i >> 24) & 0xff); + buf[1] = (png_byte)((i >> 16) & 0xff); + buf[2] = (png_byte)((i >> 8) & 0xff); + buf[3] = (png_byte)(i & 0xff); +} +#endif + # ifdef PNG_TIME_RFC1123_SUPPORTED /* Convert the supplied time into an RFC 1123 string suitable for use in * a "Creation Time" or other text-based time string. */ -png_const_charp PNGAPI -png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime) +int PNGAPI +png_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime) { static PNG_CONST char short_months[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - if (png_ptr == NULL) - return (NULL); + if (out == NULL) + return 0; + + if (ptime->year > 9999 /* RFC1123 limitation */ || + ptime->month == 0 || ptime->month > 12 || + ptime->day == 0 || ptime->day > 31 || + ptime->hour > 23 || ptime->minute > 59 || + ptime->second > 60) + return 0; { size_t pos = 0; - char number_buf[5]; /* enough for a four digit year */ + char number_buf[5]; /* enough for a four-digit year */ -# define APPEND_STRING(string)\ - pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\ - pos, (string)) +# define APPEND_STRING(string) pos = png_safecat(out, 29, pos, (string)) # define APPEND_NUMBER(format, value)\ APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value))) -# define APPEND(ch)\ - if (pos < (sizeof png_ptr->time_buffer)-1)\ - png_ptr->time_buffer[pos++] = (ch) +# define APPEND(ch) if (pos < 28) out[pos++] = (ch) - APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day % 32); + APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day); APPEND(' '); - APPEND_STRING(short_months[(ptime->month - 1) % 12]); + APPEND_STRING(short_months[(ptime->month - 1)]); APPEND(' '); APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year); APPEND(' '); - APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour % 24); + APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour); APPEND(':'); - APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute % 60); + APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute); APPEND(':'); - APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second % 61); + APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second); APPEND_STRING(" +0000"); /* This reliably terminates the buffer */ # undef APPEND @@ -630,14 +759,37 @@ png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime) # undef APPEND_STRING } - return png_ptr->time_buffer; + return 1; } -# endif /* PNG_TIME_RFC1123_SUPPORTED */ -#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ +# if PNG_LIBPNG_VER < 10700 +/* To do: remove the following from libpng-1.7 */ +/* Original API that uses a private buffer in png_struct. + * Deprecated because it causes png_struct to carry a spurious temporary + * buffer (png_struct::time_buffer), better to have the caller pass this in. + */ +png_const_charp PNGAPI +png_convert_to_rfc1123(png_structrp png_ptr, png_const_timep ptime) +{ + if (png_ptr != NULL) + { + /* The only failure above if png_ptr != NULL is from an invalid ptime */ + if (png_convert_to_rfc1123_buffer(png_ptr->time_buffer, ptime) == 0) + png_warning(png_ptr, "Ignoring invalid time value"); + + else + return png_ptr->time_buffer; + } + + return NULL; +} +# endif +# endif /* TIME_RFC1123 */ + +#endif /* READ || WRITE */ png_const_charp PNGAPI -png_get_copyright(png_const_structp png_ptr) +png_get_copyright(png_const_structrp png_ptr) { PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ #ifdef PNG_STRING_COPYRIGHT @@ -645,14 +797,14 @@ png_get_copyright(png_const_structp png_ptr) #else # ifdef __STDC__ return PNG_STRING_NEWLINE \ - "libpng version 1.5.4 - July 7, 2011" PNG_STRING_NEWLINE \ - "Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ + "libpng version 1.6.16 - December 22, 2014" PNG_STRING_NEWLINE \ + "Copyright (c) 1998-2014 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE; # else - return "libpng version 1.5.4 - July 7, 2011\ - Copyright (c) 1998-2011 Glenn Randers-Pehrson\ + return "libpng version 1.6.16 - December 22, 2014\ + Copyright (c) 1998-2014 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; # endif @@ -668,14 +820,14 @@ png_get_copyright(png_const_structp png_ptr) * it is guaranteed that png.c uses the correct version of png.h. */ png_const_charp PNGAPI -png_get_libpng_ver(png_const_structp png_ptr) +png_get_libpng_ver(png_const_structrp png_ptr) { /* Version of *.c files used when building libpng */ return png_get_header_ver(png_ptr); } png_const_charp PNGAPI -png_get_header_ver(png_const_structp png_ptr) +png_get_header_ver(png_const_structrp png_ptr) { /* Version of *.h files used when building libpng */ PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ @@ -683,7 +835,7 @@ png_get_header_ver(png_const_structp png_ptr) } png_const_charp PNGAPI -png_get_header_version(png_const_structp png_ptr) +png_get_header_version(png_const_structrp png_ptr) { /* Returns longer string containing both version and date */ PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ @@ -698,37 +850,122 @@ png_get_header_version(png_const_structp png_ptr) #endif } -#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -# ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +/* NOTE: this routine is not used internally! */ +/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth + * large of png_color. This lets grayscale images be treated as + * paletted. Most useful for gamma correction and simplification + * of code. This API is not used internally. + */ +void PNGAPI +png_build_grayscale_palette(int bit_depth, png_colorp palette) +{ + int num_palette; + int color_inc; + int i; + int v; + + png_debug(1, "in png_do_build_grayscale_palette"); + + if (palette == NULL) + return; + + switch (bit_depth) + { + case 1: + num_palette = 2; + color_inc = 0xff; + break; + + case 2: + num_palette = 4; + color_inc = 0x55; + break; + + case 4: + num_palette = 16; + color_inc = 0x11; + break; + + case 8: + num_palette = 256; + color_inc = 1; + break; + + default: + num_palette = 0; + color_inc = 0; + break; + } + + for (i = 0, v = 0; i < num_palette; i++, v += color_inc) + { + palette[i].red = (png_byte)v; + palette[i].green = (png_byte)v; + palette[i].blue = (png_byte)v; + } +} +#endif + +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED int PNGAPI -png_handle_as_unknown(png_structp png_ptr, png_const_bytep chunk_name) +png_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name) { /* Check chunk_name and return "keep" value if it's on the list, else 0 */ - int i; - png_bytep p; - if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0) - return 0; + png_const_bytep p, p_end; - p = png_ptr->chunk_list + png_ptr->num_chunk_list*5 - 5; - for (i = png_ptr->num_chunk_list; i; i--, p -= 5) - if (!png_memcmp(chunk_name, p, 4)) - return ((int)*(p + 4)); - return 0; + if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list == 0) + return PNG_HANDLE_CHUNK_AS_DEFAULT; + + p_end = png_ptr->chunk_list; + p = p_end + png_ptr->num_chunk_list*5; /* beyond end */ + + /* The code is the fifth byte after each four byte string. Historically this + * code was always searched from the end of the list, this is no longer + * necessary because the 'set' routine handles duplicate entries correcty. + */ + do /* num_chunk_list > 0, so at least one */ + { + p -= 5; + + if (memcmp(chunk_name, p, 4) == 0) + return p[4]; + } + while (p > p_end); + + /* This means that known chunks should be processed and unknown chunks should + * be handled according to the value of png_ptr->unknown_default; this can be + * confusing because, as a result, there are two levels of defaulting for + * unknown chunks. + */ + return PNG_HANDLE_CHUNK_AS_DEFAULT; } -# endif -#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\ + defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) +int /* PRIVATE */ +png_chunk_unknown_handling(png_const_structrp png_ptr, png_uint_32 chunk_name) +{ + png_byte chunk_string[5]; + + PNG_CSTRING_FROM_CHUNK(chunk_string, chunk_name); + return png_handle_as_unknown(png_ptr, chunk_string); +} +#endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */ +#endif /* SET_UNKNOWN_CHUNKS */ #ifdef PNG_READ_SUPPORTED /* This function, added to libpng-1.0.6g, is untested. */ int PNGAPI -png_reset_zstream(png_structp png_ptr) +png_reset_zstream(png_structrp png_ptr) { if (png_ptr == NULL) return Z_STREAM_ERROR; + /* WARNING: this resets the window bits to the maximum! */ return (inflateReset(&png_ptr->zstream)); } -#endif /* PNG_READ_SUPPORTED */ +#endif /* READ */ /* This function was added to libpng-1.0.7 */ png_uint_32 PNGAPI @@ -741,93 +978,1530 @@ png_access_version_number(void) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -# ifdef PNG_SIZE_T -/* Added at libpng version 1.2.6 */ - PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); -png_size_t PNGAPI -png_convert_size(size_t size) +/* Ensure that png_ptr->zstream.msg holds some appropriate error message string. + * If it doesn't 'ret' is used to set it to something appropriate, even in cases + * like Z_OK or Z_STREAM_END where the error code is apparently a success code. + */ +void /* PRIVATE */ +png_zstream_error(png_structrp png_ptr, int ret) { - if (size > (png_size_t)-1) - PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */ + /* Translate 'ret' into an appropriate error string, priority is given to the + * one in zstream if set. This always returns a string, even in cases like + * Z_OK or Z_STREAM_END where the error code is a success code. + */ + if (png_ptr->zstream.msg == NULL) switch (ret) + { + default: + case Z_OK: + png_ptr->zstream.msg = PNGZ_MSG_CAST("unexpected zlib return code"); + break; - return ((png_size_t)size); + case Z_STREAM_END: + /* Normal exit */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("unexpected end of LZ stream"); + break; + + case Z_NEED_DICT: + /* This means the deflate stream did not have a dictionary; this + * indicates a bogus PNG. + */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("missing LZ dictionary"); + break; + + case Z_ERRNO: + /* gz APIs only: should not happen */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("zlib IO error"); + break; + + case Z_STREAM_ERROR: + /* internal libpng error */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("bad parameters to zlib"); + break; + + case Z_DATA_ERROR: + png_ptr->zstream.msg = PNGZ_MSG_CAST("damaged LZ stream"); + break; + + case Z_MEM_ERROR: + png_ptr->zstream.msg = PNGZ_MSG_CAST("insufficient memory"); + break; + + case Z_BUF_ERROR: + /* End of input or output; not a problem if the caller is doing + * incremental read or write. + */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("truncated"); + break; + + case Z_VERSION_ERROR: + png_ptr->zstream.msg = PNGZ_MSG_CAST("unsupported zlib version"); + break; + + case PNG_UNEXPECTED_ZLIB_RETURN: + /* Compile errors here mean that zlib now uses the value co-opted in + * pngpriv.h for PNG_UNEXPECTED_ZLIB_RETURN; update the switch above + * and change pngpriv.h. Note that this message is "... return", + * whereas the default/Z_OK one is "... return code". + */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("unexpected zlib return"); + break; + } } -# endif /* PNG_SIZE_T */ + +/* png_convert_size: a PNGAPI but no longer in png.h, so deleted + * at libpng 1.5.5! + */ /* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ -# ifdef PNG_CHECK_cHRM_SUPPORTED - -int /* PRIVATE */ -png_check_cHRM_fixed(png_structp png_ptr, - png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, - png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, - png_fixed_point blue_x, png_fixed_point blue_y) -{ - int ret = 1; - unsigned long xy_hi,xy_lo,yx_hi,yx_lo; - - png_debug(1, "in function png_check_cHRM_fixed"); - - if (png_ptr == NULL) - return 0; - - /* (x,y,z) values are first limited to 0..100000 (PNG_FP_1), the white - * y must also be greater than 0. To test for the upper limit calculate - * (PNG_FP_1-y) - x must be <= to this for z to be >= 0 (and the expression - * cannot overflow.) At this point we know x and y are >= 0 and (x+y) is - * <= PNG_FP_1. The previous test on PNG_MAX_UINT_31 is removed because it - * pointless (and it produces compiler warnings!) +#ifdef PNG_GAMMA_SUPPORTED /* always set if COLORSPACE */ +static int +png_colorspace_check_gamma(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_fixed_point gAMA, int from) + /* This is called to check a new gamma value against an existing one. The + * routine returns false if the new gamma value should not be written. + * + * 'from' says where the new gamma value comes from: + * + * 0: the new gamma value is the libpng estimate for an ICC profile + * 1: the new gamma value comes from a gAMA chunk + * 2: the new gamma value comes from an sRGB chunk */ - if (white_x < 0 || white_y <= 0 || - red_x < 0 || red_y < 0 || - green_x < 0 || green_y < 0 || - blue_x < 0 || blue_y < 0) +{ + png_fixed_point gtest; + + if ((colorspace->flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && + (png_muldiv(>est, colorspace->gamma, PNG_FP_1, gAMA) == 0 || + png_gamma_significant(gtest) != 0)) { - png_warning(png_ptr, - "Ignoring attempt to set negative chromaticity value"); - ret = 0; - } - /* And (x+y) must be <= PNG_FP_1 (so z is >= 0) */ - if (white_x > PNG_FP_1 - white_y) - { - png_warning(png_ptr, "Invalid cHRM white point"); - ret = 0; + /* Either this is an sRGB image, in which case the calculated gamma + * approximation should match, or this is an image with a profile and the + * value libpng calculates for the gamma of the profile does not match the + * value recorded in the file. The former, sRGB, case is an error, the + * latter is just a warning. + */ + if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0 || from == 2) + { + png_chunk_report(png_ptr, "gamma value does not match sRGB", + PNG_CHUNK_ERROR); + /* Do not overwrite an sRGB value */ + return from == 2; + } + + else /* sRGB tag not involved */ + { + png_chunk_report(png_ptr, "gamma value does not match libpng estimate", + PNG_CHUNK_WARNING); + return from == 1; + } } - if (red_x > PNG_FP_1 - red_y) - { - png_warning(png_ptr, "Invalid cHRM red point"); - ret = 0; - } - - if (green_x > PNG_FP_1 - green_y) - { - png_warning(png_ptr, "Invalid cHRM green point"); - ret = 0; - } - - if (blue_x > PNG_FP_1 - blue_y) - { - png_warning(png_ptr, "Invalid cHRM blue point"); - ret = 0; - } - - png_64bit_product(green_x - red_x, blue_y - red_y, &xy_hi, &xy_lo); - png_64bit_product(green_y - red_y, blue_x - red_x, &yx_hi, &yx_lo); - - if (xy_hi == yx_hi && xy_lo == yx_lo) - { - png_warning(png_ptr, - "Ignoring attempt to set cHRM RGB triangle with zero area"); - ret = 0; - } - - return ret; + return 1; } -# endif /* PNG_CHECK_cHRM_SUPPORTED */ void /* PRIVATE */ -png_check_IHDR(png_structp png_ptr, +png_colorspace_set_gamma(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_fixed_point gAMA) +{ + /* Changed in libpng-1.5.4 to limit the values to ensure overflow can't + * occur. Since the fixed point representation is asymetrical it is + * possible for 1/gamma to overflow the limit of 21474 and this means the + * gamma value must be at least 5/100000 and hence at most 20000.0. For + * safety the limits here are a little narrower. The values are 0.00016 to + * 6250.0, which are truly ridiculous gamma values (and will produce + * displays that are all black or all white.) + * + * In 1.6.0 this test replaces the ones in pngrutil.c, in the gAMA chunk + * handling code, which only required the value to be >0. + */ + png_const_charp errmsg; + + if (gAMA < 16 || gAMA > 625000000) + errmsg = "gamma value out of range"; + +# ifdef PNG_READ_gAMA_SUPPORTED + /* Allow the application to set the gamma value more than once */ + else if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && + (colorspace->flags & PNG_COLORSPACE_FROM_gAMA) != 0) + errmsg = "duplicate"; +# endif + + /* Do nothing if the colorspace is already invalid */ + else if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) + return; + + else + { + if (png_colorspace_check_gamma(png_ptr, colorspace, gAMA, + 1/*from gAMA*/) != 0) + { + /* Store this gamma value. */ + colorspace->gamma = gAMA; + colorspace->flags |= + (PNG_COLORSPACE_HAVE_GAMMA | PNG_COLORSPACE_FROM_gAMA); + } + + /* At present if the check_gamma test fails the gamma of the colorspace is + * not updated however the colorspace is not invalidated. This + * corresponds to the case where the existing gamma comes from an sRGB + * chunk or profile. An error message has already been output. + */ + return; + } + + /* Error exit - errmsg has been set. */ + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_chunk_report(png_ptr, errmsg, PNG_CHUNK_WRITE_ERROR); +} + +void /* PRIVATE */ +png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr) +{ + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0) + { + /* Everything is invalid */ + info_ptr->valid &= ~(PNG_INFO_gAMA|PNG_INFO_cHRM|PNG_INFO_sRGB| + PNG_INFO_iCCP); + +# ifdef PNG_COLORSPACE_SUPPORTED + /* Clean up the iCCP profile now if it won't be used. */ + png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, -1/*not used*/); +# else + PNG_UNUSED(png_ptr) +# endif + } + + else + { +# ifdef PNG_COLORSPACE_SUPPORTED + /* Leave the INFO_iCCP flag set if the pngset.c code has already set + * it; this allows a PNG to contain a profile which matches sRGB and + * yet still have that profile retrievable by the application. + */ + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_MATCHES_sRGB) != 0) + info_ptr->valid |= PNG_INFO_sRGB; + + else + info_ptr->valid &= ~PNG_INFO_sRGB; + + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + info_ptr->valid |= PNG_INFO_cHRM; + + else + info_ptr->valid &= ~PNG_INFO_cHRM; +# endif + + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0) + info_ptr->valid |= PNG_INFO_gAMA; + + else + info_ptr->valid &= ~PNG_INFO_gAMA; + } +} + +#ifdef PNG_READ_SUPPORTED +void /* PRIVATE */ +png_colorspace_sync(png_const_structrp png_ptr, png_inforp info_ptr) +{ + if (info_ptr == NULL) /* reduce code size; check here not in the caller */ + return; + + info_ptr->colorspace = png_ptr->colorspace; + png_colorspace_sync_info(png_ptr, info_ptr); +} +#endif +#endif + +#ifdef PNG_COLORSPACE_SUPPORTED +/* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for + * cHRM, as opposed to using chromaticities. These internal APIs return + * non-zero on a parameter error. The X, Y and Z values are required to be + * positive and less than 1.0. + */ +static int +png_xy_from_XYZ(png_xy *xy, const png_XYZ *XYZ) +{ + png_int_32 d, dwhite, whiteX, whiteY; + + d = XYZ->red_X + XYZ->red_Y + XYZ->red_Z; + if (png_muldiv(&xy->redx, XYZ->red_X, PNG_FP_1, d) == 0) + return 1; + if (png_muldiv(&xy->redy, XYZ->red_Y, PNG_FP_1, d) == 0) + return 1; + dwhite = d; + whiteX = XYZ->red_X; + whiteY = XYZ->red_Y; + + d = XYZ->green_X + XYZ->green_Y + XYZ->green_Z; + if (png_muldiv(&xy->greenx, XYZ->green_X, PNG_FP_1, d) == 0) + return 1; + if (png_muldiv(&xy->greeny, XYZ->green_Y, PNG_FP_1, d) == 0) + return 1; + dwhite += d; + whiteX += XYZ->green_X; + whiteY += XYZ->green_Y; + + d = XYZ->blue_X + XYZ->blue_Y + XYZ->blue_Z; + if (png_muldiv(&xy->bluex, XYZ->blue_X, PNG_FP_1, d) == 0) + return 1; + if (png_muldiv(&xy->bluey, XYZ->blue_Y, PNG_FP_1, d) == 0) + return 1; + dwhite += d; + whiteX += XYZ->blue_X; + whiteY += XYZ->blue_Y; + + /* The reference white is simply the sum of the end-point (X,Y,Z) vectors, + * thus: + */ + if (png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite) == 0) + return 1; + if (png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite) == 0) + return 1; + + return 0; +} + +static int +png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy) +{ + png_fixed_point red_inverse, green_inverse, blue_scale; + png_fixed_point left, right, denominator; + + /* Check xy and, implicitly, z. Note that wide gamut color spaces typically + * have end points with 0 tristimulus values (these are impossible end + * points, but they are used to cover the possible colors.) + */ + if (xy->redx < 0 || xy->redx > PNG_FP_1) return 1; + if (xy->redy < 0 || xy->redy > PNG_FP_1-xy->redx) return 1; + if (xy->greenx < 0 || xy->greenx > PNG_FP_1) return 1; + if (xy->greeny < 0 || xy->greeny > PNG_FP_1-xy->greenx) return 1; + if (xy->bluex < 0 || xy->bluex > PNG_FP_1) return 1; + if (xy->bluey < 0 || xy->bluey > PNG_FP_1-xy->bluex) return 1; + if (xy->whitex < 0 || xy->whitex > PNG_FP_1) return 1; + if (xy->whitey < 0 || xy->whitey > PNG_FP_1-xy->whitex) return 1; + + /* The reverse calculation is more difficult because the original tristimulus + * value had 9 independent values (red,green,blue)x(X,Y,Z) however only 8 + * derived values were recorded in the cHRM chunk; + * (red,green,blue,white)x(x,y). This loses one degree of freedom and + * therefore an arbitrary ninth value has to be introduced to undo the + * original transformations. + * + * Think of the original end-points as points in (X,Y,Z) space. The + * chromaticity values (c) have the property: + * + * C + * c = --------- + * X + Y + Z + * + * For each c (x,y,z) from the corresponding original C (X,Y,Z). Thus the + * three chromaticity values (x,y,z) for each end-point obey the + * relationship: + * + * x + y + z = 1 + * + * This describes the plane in (X,Y,Z) space that intersects each axis at the + * value 1.0; call this the chromaticity plane. Thus the chromaticity + * calculation has scaled each end-point so that it is on the x+y+z=1 plane + * and chromaticity is the intersection of the vector from the origin to the + * (X,Y,Z) value with the chromaticity plane. + * + * To fully invert the chromaticity calculation we would need the three + * end-point scale factors, (red-scale, green-scale, blue-scale), but these + * were not recorded. Instead we calculated the reference white (X,Y,Z) and + * recorded the chromaticity of this. The reference white (X,Y,Z) would have + * given all three of the scale factors since: + * + * color-C = color-c * color-scale + * white-C = red-C + green-C + blue-C + * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale + * + * But cHRM records only white-x and white-y, so we have lost the white scale + * factor: + * + * white-C = white-c*white-scale + * + * To handle this the inverse transformation makes an arbitrary assumption + * about white-scale: + * + * Assume: white-Y = 1.0 + * Hence: white-scale = 1/white-y + * Or: red-Y + green-Y + blue-Y = 1.0 + * + * Notice the last statement of the assumption gives an equation in three of + * the nine values we want to calculate. 8 more equations come from the + * above routine as summarised at the top above (the chromaticity + * calculation): + * + * Given: color-x = color-X / (color-X + color-Y + color-Z) + * Hence: (color-x - 1)*color-X + color.x*color-Y + color.x*color-Z = 0 + * + * This is 9 simultaneous equations in the 9 variables "color-C" and can be + * solved by Cramer's rule. Cramer's rule requires calculating 10 9x9 matrix + * determinants, however this is not as bad as it seems because only 28 of + * the total of 90 terms in the various matrices are non-zero. Nevertheless + * Cramer's rule is notoriously numerically unstable because the determinant + * calculation involves the difference of large, but similar, numbers. It is + * difficult to be sure that the calculation is stable for real world values + * and it is certain that it becomes unstable where the end points are close + * together. + * + * So this code uses the perhaps slightly less optimal but more + * understandable and totally obvious approach of calculating color-scale. + * + * This algorithm depends on the precision in white-scale and that is + * (1/white-y), so we can immediately see that as white-y approaches 0 the + * accuracy inherent in the cHRM chunk drops off substantially. + * + * libpng arithmetic: a simple inversion of the above equations + * ------------------------------------------------------------ + * + * white_scale = 1/white-y + * white-X = white-x * white-scale + * white-Y = 1.0 + * white-Z = (1 - white-x - white-y) * white_scale + * + * white-C = red-C + green-C + blue-C + * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale + * + * This gives us three equations in (red-scale,green-scale,blue-scale) where + * all the coefficients are now known: + * + * red-x*red-scale + green-x*green-scale + blue-x*blue-scale + * = white-x/white-y + * red-y*red-scale + green-y*green-scale + blue-y*blue-scale = 1 + * red-z*red-scale + green-z*green-scale + blue-z*blue-scale + * = (1 - white-x - white-y)/white-y + * + * In the last equation color-z is (1 - color-x - color-y) so we can add all + * three equations together to get an alternative third: + * + * red-scale + green-scale + blue-scale = 1/white-y = white-scale + * + * So now we have a Cramer's rule solution where the determinants are just + * 3x3 - far more tractible. Unfortunately 3x3 determinants still involve + * multiplication of three coefficients so we can't guarantee to avoid + * overflow in the libpng fixed point representation. Using Cramer's rule in + * floating point is probably a good choice here, but it's not an option for + * fixed point. Instead proceed to simplify the first two equations by + * eliminating what is likely to be the largest value, blue-scale: + * + * blue-scale = white-scale - red-scale - green-scale + * + * Hence: + * + * (red-x - blue-x)*red-scale + (green-x - blue-x)*green-scale = + * (white-x - blue-x)*white-scale + * + * (red-y - blue-y)*red-scale + (green-y - blue-y)*green-scale = + * 1 - blue-y*white-scale + * + * And now we can trivially solve for (red-scale,green-scale): + * + * green-scale = + * (white-x - blue-x)*white-scale - (red-x - blue-x)*red-scale + * ----------------------------------------------------------- + * green-x - blue-x + * + * red-scale = + * 1 - blue-y*white-scale - (green-y - blue-y) * green-scale + * --------------------------------------------------------- + * red-y - blue-y + * + * Hence: + * + * red-scale = + * ( (green-x - blue-x) * (white-y - blue-y) - + * (green-y - blue-y) * (white-x - blue-x) ) / white-y + * ------------------------------------------------------------------------- + * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x) + * + * green-scale = + * ( (red-y - blue-y) * (white-x - blue-x) - + * (red-x - blue-x) * (white-y - blue-y) ) / white-y + * ------------------------------------------------------------------------- + * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x) + * + * Accuracy: + * The input values have 5 decimal digits of accuracy. The values are all in + * the range 0 < value < 1, so simple products are in the same range but may + * need up to 10 decimal digits to preserve the original precision and avoid + * underflow. Because we are using a 32-bit signed representation we cannot + * match this; the best is a little over 9 decimal digits, less than 10. + * + * The approach used here is to preserve the maximum precision within the + * signed representation. Because the red-scale calculation above uses the + * difference between two products of values that must be in the range -1..+1 + * it is sufficient to divide the product by 7; ceil(100,000/32767*2). The + * factor is irrelevant in the calculation because it is applied to both + * numerator and denominator. + * + * Note that the values of the differences of the products of the + * chromaticities in the above equations tend to be small, for example for + * the sRGB chromaticities they are: + * + * red numerator: -0.04751 + * green numerator: -0.08788 + * denominator: -0.2241 (without white-y multiplication) + * + * The resultant Y coefficients from the chromaticities of some widely used + * color space definitions are (to 15 decimal places): + * + * sRGB + * 0.212639005871510 0.715168678767756 0.072192315360734 + * Kodak ProPhoto + * 0.288071128229293 0.711843217810102 0.000085653960605 + * Adobe RGB + * 0.297344975250536 0.627363566255466 0.075291458493998 + * Adobe Wide Gamut RGB + * 0.258728243040113 0.724682314948566 0.016589442011321 + */ + /* By the argument, above overflow should be impossible here. The return + * value of 2 indicates an internal error to the caller. + */ + if (png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 7) == 0) + return 2; + if (png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 7) == 0) + return 2; + denominator = left - right; + + /* Now find the red numerator. */ + if (png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 7) == 0) + return 2; + if (png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 7) == 0) + return 2; + + /* Overflow is possible here and it indicates an extreme set of PNG cHRM + * chunk values. This calculation actually returns the reciprocal of the + * scale value because this allows us to delay the multiplication of white-y + * into the denominator, which tends to produce a small number. + */ + if (png_muldiv(&red_inverse, xy->whitey, denominator, left-right) == 0 || + red_inverse <= xy->whitey /* r+g+b scales = white scale */) + return 1; + + /* Similarly for green_inverse: */ + if (png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 7) == 0) + return 2; + if (png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 7) == 0) + return 2; + if (png_muldiv(&green_inverse, xy->whitey, denominator, left-right) == 0 || + green_inverse <= xy->whitey) + return 1; + + /* And the blue scale, the checks above guarantee this can't overflow but it + * can still produce 0 for extreme cHRM values. + */ + blue_scale = png_reciprocal(xy->whitey) - png_reciprocal(red_inverse) - + png_reciprocal(green_inverse); + if (blue_scale <= 0) + return 1; + + + /* And fill in the png_XYZ: */ + if (png_muldiv(&XYZ->red_X, xy->redx, PNG_FP_1, red_inverse) == 0) + return 1; + if (png_muldiv(&XYZ->red_Y, xy->redy, PNG_FP_1, red_inverse) == 0) + return 1; + if (png_muldiv(&XYZ->red_Z, PNG_FP_1 - xy->redx - xy->redy, PNG_FP_1, + red_inverse) == 0) + return 1; + + if (png_muldiv(&XYZ->green_X, xy->greenx, PNG_FP_1, green_inverse) == 0) + return 1; + if (png_muldiv(&XYZ->green_Y, xy->greeny, PNG_FP_1, green_inverse) == 0) + return 1; + if (png_muldiv(&XYZ->green_Z, PNG_FP_1 - xy->greenx - xy->greeny, PNG_FP_1, + green_inverse) == 0) + return 1; + + if (png_muldiv(&XYZ->blue_X, xy->bluex, blue_scale, PNG_FP_1) == 0) + return 1; + if (png_muldiv(&XYZ->blue_Y, xy->bluey, blue_scale, PNG_FP_1) == 0) + return 1; + if (png_muldiv(&XYZ->blue_Z, PNG_FP_1 - xy->bluex - xy->bluey, blue_scale, + PNG_FP_1) == 0) + return 1; + + return 0; /*success*/ +} + +static int +png_XYZ_normalize(png_XYZ *XYZ) +{ + png_int_32 Y; + + if (XYZ->red_Y < 0 || XYZ->green_Y < 0 || XYZ->blue_Y < 0 || + XYZ->red_X < 0 || XYZ->green_X < 0 || XYZ->blue_X < 0 || + XYZ->red_Z < 0 || XYZ->green_Z < 0 || XYZ->blue_Z < 0) + return 1; + + /* Normalize by scaling so the sum of the end-point Y values is PNG_FP_1. + * IMPLEMENTATION NOTE: ANSI requires signed overflow not to occur, therefore + * relying on addition of two positive values producing a negative one is not + * safe. + */ + Y = XYZ->red_Y; + if (0x7fffffff - Y < XYZ->green_X) + return 1; + Y += XYZ->green_Y; + if (0x7fffffff - Y < XYZ->blue_X) + return 1; + Y += XYZ->blue_Y; + + if (Y != PNG_FP_1) + { + if (png_muldiv(&XYZ->red_X, XYZ->red_X, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->red_Y, XYZ->red_Y, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->red_Z, XYZ->red_Z, PNG_FP_1, Y) == 0) + return 1; + + if (png_muldiv(&XYZ->green_X, XYZ->green_X, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->green_Y, XYZ->green_Y, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->green_Z, XYZ->green_Z, PNG_FP_1, Y) == 0) + return 1; + + if (png_muldiv(&XYZ->blue_X, XYZ->blue_X, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->blue_Y, XYZ->blue_Y, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->blue_Z, XYZ->blue_Z, PNG_FP_1, Y) == 0) + return 1; + } + + return 0; +} + +static int +png_colorspace_endpoints_match(const png_xy *xy1, const png_xy *xy2, int delta) +{ + /* Allow an error of +/-0.01 (absolute value) on each chromaticity */ + if (PNG_OUT_OF_RANGE(xy1->whitex, xy2->whitex,delta) || + PNG_OUT_OF_RANGE(xy1->whitey, xy2->whitey,delta) || + PNG_OUT_OF_RANGE(xy1->redx, xy2->redx, delta) || + PNG_OUT_OF_RANGE(xy1->redy, xy2->redy, delta) || + PNG_OUT_OF_RANGE(xy1->greenx, xy2->greenx,delta) || + PNG_OUT_OF_RANGE(xy1->greeny, xy2->greeny,delta) || + PNG_OUT_OF_RANGE(xy1->bluex, xy2->bluex, delta) || + PNG_OUT_OF_RANGE(xy1->bluey, xy2->bluey, delta)) + return 0; + return 1; +} + +/* Added in libpng-1.6.0, a different check for the validity of a set of cHRM + * chunk chromaticities. Earlier checks used to simply look for the overflow + * condition (where the determinant of the matrix to solve for XYZ ends up zero + * because the chromaticity values are not all distinct.) Despite this it is + * theoretically possible to produce chromaticities that are apparently valid + * but that rapidly degrade to invalid, potentially crashing, sets because of + * arithmetic inaccuracies when calculations are performed on them. The new + * check is to round-trip xy -> XYZ -> xy and then check that the result is + * within a small percentage of the original. + */ +static int +png_colorspace_check_xy(png_XYZ *XYZ, const png_xy *xy) +{ + int result; + png_xy xy_test; + + /* As a side-effect this routine also returns the XYZ endpoints. */ + result = png_XYZ_from_xy(XYZ, xy); + if (result != 0) + return result; + + result = png_xy_from_XYZ(&xy_test, XYZ); + if (result != 0) + return result; + + if (png_colorspace_endpoints_match(xy, &xy_test, + 5/*actually, the math is pretty accurate*/) != 0) + return 0; + + /* Too much slip */ + return 1; +} + +/* This is the check going the other way. The XYZ is modified to normalize it + * (another side-effect) and the xy chromaticities are returned. + */ +static int +png_colorspace_check_XYZ(png_xy *xy, png_XYZ *XYZ) +{ + int result; + png_XYZ XYZtemp; + + result = png_XYZ_normalize(XYZ); + if (result != 0) + return result; + + result = png_xy_from_XYZ(xy, XYZ); + if (result != 0) + return result; + + XYZtemp = *XYZ; + return png_colorspace_check_xy(&XYZtemp, xy); +} + +/* Used to check for an endpoint match against sRGB */ +static const png_xy sRGB_xy = /* From ITU-R BT.709-3 */ +{ + /* color x y */ + /* red */ 64000, 33000, + /* green */ 30000, 60000, + /* blue */ 15000, 6000, + /* white */ 31270, 32900 +}; + +static int +png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr, + png_colorspacerp colorspace, const png_xy *xy, const png_XYZ *XYZ, + int preferred) +{ + if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) + return 0; + + /* The consistency check is performed on the chromaticities; this factors out + * variations because of the normalization (or not) of the end point Y + * values. + */ + if (preferred < 2 && + (colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + /* The end points must be reasonably close to any we already have. The + * following allows an error of up to +/-.001 + */ + if (png_colorspace_endpoints_match(xy, &colorspace->end_points_xy, + 100) == 0) + { + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_benign_error(png_ptr, "inconsistent chromaticities"); + return 0; /* failed */ + } + + /* Only overwrite with preferred values */ + if (preferred == 0) + return 1; /* ok, but no change */ + } + + colorspace->end_points_xy = *xy; + colorspace->end_points_XYZ = *XYZ; + colorspace->flags |= PNG_COLORSPACE_HAVE_ENDPOINTS; + + /* The end points are normally quoted to two decimal digits, so allow +/-0.01 + * on this test. + */ + if (png_colorspace_endpoints_match(xy, &sRGB_xy, 1000) != 0) + colorspace->flags |= PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB; + + else + colorspace->flags &= PNG_COLORSPACE_CANCEL( + PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB); + + return 2; /* ok and changed */ +} + +int /* PRIVATE */ +png_colorspace_set_chromaticities(png_const_structrp png_ptr, + png_colorspacerp colorspace, const png_xy *xy, int preferred) +{ + /* We must check the end points to ensure they are reasonable - in the past + * color management systems have crashed as a result of getting bogus + * colorant values, while this isn't the fault of libpng it is the + * responsibility of libpng because PNG carries the bomb and libpng is in a + * position to protect against it. + */ + png_XYZ XYZ; + + switch (png_colorspace_check_xy(&XYZ, xy)) + { + case 0: /* success */ + return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, xy, &XYZ, + preferred); + + case 1: + /* We can't invert the chromaticities so we can't produce value XYZ + * values. Likely as not a color management system will fail too. + */ + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_benign_error(png_ptr, "invalid chromaticities"); + break; + + default: + /* libpng is broken; this should be a warning but if it happens we + * want error reports so for the moment it is an error. + */ + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_error(png_ptr, "internal error checking chromaticities"); + break; + } + + return 0; /* failed */ +} + +int /* PRIVATE */ +png_colorspace_set_endpoints(png_const_structrp png_ptr, + png_colorspacerp colorspace, const png_XYZ *XYZ_in, int preferred) +{ + png_XYZ XYZ = *XYZ_in; + png_xy xy; + + switch (png_colorspace_check_XYZ(&xy, &XYZ)) + { + case 0: + return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, &xy, &XYZ, + preferred); + + case 1: + /* End points are invalid. */ + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_benign_error(png_ptr, "invalid end points"); + break; + + default: + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_error(png_ptr, "internal error checking chromaticities"); + break; + } + + return 0; /* failed */ +} + +#if defined(PNG_sRGB_SUPPORTED) || defined(PNG_iCCP_SUPPORTED) +/* Error message generation */ +static char +png_icc_tag_char(png_uint_32 byte) +{ + byte &= 0xff; + if (byte >= 32 && byte <= 126) + return (char)byte; + else + return '?'; +} + +static void +png_icc_tag_name(char *name, png_uint_32 tag) +{ + name[0] = '\''; + name[1] = png_icc_tag_char(tag >> 24); + name[2] = png_icc_tag_char(tag >> 16); + name[3] = png_icc_tag_char(tag >> 8); + name[4] = png_icc_tag_char(tag ); + name[5] = '\''; +} + +static int +is_ICC_signature_char(png_alloc_size_t it) +{ + return it == 32 || (it >= 48 && it <= 57) || (it >= 65 && it <= 90) || + (it >= 97 && it <= 122); +} + +static int +is_ICC_signature(png_alloc_size_t it) +{ + return is_ICC_signature_char(it >> 24) /* checks all the top bits */ && + is_ICC_signature_char((it >> 16) & 0xff) && + is_ICC_signature_char((it >> 8) & 0xff) && + is_ICC_signature_char(it & 0xff); +} + +static int +png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_alloc_size_t value, png_const_charp reason) +{ + size_t pos; + char message[196]; /* see below for calculation */ + + if (colorspace != NULL) + colorspace->flags |= PNG_COLORSPACE_INVALID; + + pos = png_safecat(message, (sizeof message), 0, "profile '"); /* 9 chars */ + pos = png_safecat(message, pos+79, pos, name); /* Truncate to 79 chars */ + pos = png_safecat(message, (sizeof message), pos, "': "); /* +2 = 90 */ + if (is_ICC_signature(value) != 0) + { + /* So 'value' is at most 4 bytes and the following cast is safe */ + png_icc_tag_name(message+pos, (png_uint_32)value); + pos += 6; /* total +8; less than the else clause */ + message[pos++] = ':'; + message[pos++] = ' '; + } +# ifdef PNG_WARNINGS_SUPPORTED + else + { + char number[PNG_NUMBER_BUFFER_SIZE]; /* +24 = 114*/ + + pos = png_safecat(message, (sizeof message), pos, + png_format_number(number, number+(sizeof number), + PNG_NUMBER_FORMAT_x, value)); + pos = png_safecat(message, (sizeof message), pos, "h: "); /*+2 = 116*/ + } +# endif + /* The 'reason' is an arbitrary message, allow +79 maximum 195 */ + pos = png_safecat(message, (sizeof message), pos, reason); + PNG_UNUSED(pos) + + /* This is recoverable, but make it unconditionally an app_error on write to + * avoid writing invalid ICC profiles into PNG files (i.e., we handle them + * on read, with a warning, but on write unless the app turns off + * application errors the PNG won't be written.) + */ + png_chunk_report(png_ptr, message, + (colorspace != NULL) ? PNG_CHUNK_ERROR : PNG_CHUNK_WRITE_ERROR); + + return 0; +} +#endif /* sRGB || iCCP */ + +#ifdef PNG_sRGB_SUPPORTED +int /* PRIVATE */ +png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace, + int intent) +{ + /* sRGB sets known gamma, end points and (from the chunk) intent. */ + /* IMPORTANT: these are not necessarily the values found in an ICC profile + * because ICC profiles store values adapted to a D50 environment; it is + * expected that the ICC profile mediaWhitePointTag will be D50; see the + * checks and code elsewhere to understand this better. + * + * These XYZ values, which are accurate to 5dp, produce rgb to gray + * coefficients of (6968,23435,2366), which are reduced (because they add up + * to 32769 not 32768) to (6968,23434,2366). These are the values that + * libpng has traditionally used (and are the best values given the 15bit + * algorithm used by the rgb to gray code.) + */ + static const png_XYZ sRGB_XYZ = /* D65 XYZ (*not* the D50 adapted values!) */ + { + /* color X Y Z */ + /* red */ 41239, 21264, 1933, + /* green */ 35758, 71517, 11919, + /* blue */ 18048, 7219, 95053 + }; + + /* Do nothing if the colorspace is already invalidated. */ + if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) + return 0; + + /* Check the intent, then check for existing settings. It is valid for the + * PNG file to have cHRM or gAMA chunks along with sRGB, but the values must + * be consistent with the correct values. If, however, this function is + * called below because an iCCP chunk matches sRGB then it is quite + * conceivable that an older app recorded incorrect gAMA and cHRM because of + * an incorrect calculation based on the values in the profile - this does + * *not* invalidate the profile (though it still produces an error, which can + * be ignored.) + */ + if (intent < 0 || intent >= PNG_sRGB_INTENT_LAST) + return png_icc_profile_error(png_ptr, colorspace, "sRGB", + (unsigned)intent, "invalid sRGB rendering intent"); + + if ((colorspace->flags & PNG_COLORSPACE_HAVE_INTENT) != 0 && + colorspace->rendering_intent != intent) + return png_icc_profile_error(png_ptr, colorspace, "sRGB", + (unsigned)intent, "inconsistent rendering intents"); + + if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0) + { + png_benign_error(png_ptr, "duplicate sRGB information ignored"); + return 0; + } + + /* If the standard sRGB cHRM chunk does not match the one from the PNG file + * warn but overwrite the value with the correct one. + */ + if ((colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0 && + !png_colorspace_endpoints_match(&sRGB_xy, &colorspace->end_points_xy, + 100)) + png_chunk_report(png_ptr, "cHRM chunk does not match sRGB", + PNG_CHUNK_ERROR); + + /* This check is just done for the error reporting - the routine always + * returns true when the 'from' argument corresponds to sRGB (2). + */ + (void)png_colorspace_check_gamma(png_ptr, colorspace, PNG_GAMMA_sRGB_INVERSE, + 2/*from sRGB*/); + + /* intent: bugs in GCC force 'int' to be used as the parameter type. */ + colorspace->rendering_intent = (png_uint_16)intent; + colorspace->flags |= PNG_COLORSPACE_HAVE_INTENT; + + /* endpoints */ + colorspace->end_points_xy = sRGB_xy; + colorspace->end_points_XYZ = sRGB_XYZ; + colorspace->flags |= + (PNG_COLORSPACE_HAVE_ENDPOINTS|PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB); + + /* gamma */ + colorspace->gamma = PNG_GAMMA_sRGB_INVERSE; + colorspace->flags |= PNG_COLORSPACE_HAVE_GAMMA; + + /* Finally record that we have an sRGB profile */ + colorspace->flags |= + (PNG_COLORSPACE_MATCHES_sRGB|PNG_COLORSPACE_FROM_sRGB); + + return 1; /* set */ +} +#endif /* sRGB */ + +#ifdef PNG_iCCP_SUPPORTED +/* Encoded value of D50 as an ICC XYZNumber. From the ICC 2010 spec the value + * is XYZ(0.9642,1.0,0.8249), which scales to: + * + * (63189.8112, 65536, 54060.6464) + */ +static const png_byte D50_nCIEXYZ[12] = + { 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d }; + +int /* PRIVATE */ +png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length) +{ + if (profile_length < 132) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "too short"); + + return 1; +} + +int /* PRIVATE */ +png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length, + png_const_bytep profile/* first 132 bytes only */, int color_type) +{ + png_uint_32 temp; + + /* Length check; this cannot be ignored in this code because profile_length + * is used later to check the tag table, so even if the profile seems over + * long profile_length from the caller must be correct. The caller can fix + * this up on read or write by just passing in the profile header length. + */ + temp = png_get_uint_32(profile); + if (temp != profile_length) + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "length does not match profile"); + + temp = (png_uint_32) (*(profile+8)); + if (temp > 3 && (profile_length & 3)) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "invalid length"); + + temp = png_get_uint_32(profile+128); /* tag count: 12 bytes/tag */ + if (temp > 357913930 || /* (2^32-4-132)/12: maximum possible tag count */ + profile_length < 132+12*temp) /* truncated tag table */ + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "tag count too large"); + + /* The 'intent' must be valid or we can't store it, ICC limits the intent to + * 16 bits. + */ + temp = png_get_uint_32(profile+64); + if (temp >= 0xffff) /* The ICC limit */ + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "invalid rendering intent"); + + /* This is just a warning because the profile may be valid in future + * versions. + */ + if (temp >= PNG_sRGB_INTENT_LAST) + (void)png_icc_profile_error(png_ptr, NULL, name, temp, + "intent outside defined range"); + + /* At this point the tag table can't be checked because it hasn't necessarily + * been loaded; however, various header fields can be checked. These checks + * are for values permitted by the PNG spec in an ICC profile; the PNG spec + * restricts the profiles that can be passed in an iCCP chunk (they must be + * appropriate to processing PNG data!) + */ + + /* Data checks (could be skipped). These checks must be independent of the + * version number; however, the version number doesn't accomodate changes in + * the header fields (just the known tags and the interpretation of the + * data.) + */ + temp = png_get_uint_32(profile+36); /* signature 'ascp' */ + if (temp != 0x61637370) + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "invalid signature"); + + /* Currently the PCS illuminant/adopted white point (the computational + * white point) are required to be D50, + * however the profile contains a record of the illuminant so perhaps ICC + * expects to be able to change this in the future (despite the rationale in + * the introduction for using a fixed PCS adopted white.) Consequently the + * following is just a warning. + */ + if (memcmp(profile+68, D50_nCIEXYZ, 12) != 0) + (void)png_icc_profile_error(png_ptr, NULL, name, 0/*no tag value*/, + "PCS illuminant is not D50"); + + /* The PNG spec requires this: + * "If the iCCP chunk is present, the image samples conform to the colour + * space represented by the embedded ICC profile as defined by the + * International Color Consortium [ICC]. The colour space of the ICC profile + * shall be an RGB colour space for colour images (PNG colour types 2, 3, and + * 6), or a greyscale colour space for greyscale images (PNG colour types 0 + * and 4)." + * + * This checking code ensures the embedded profile (on either read or write) + * conforms to the specification requirements. Notice that an ICC 'gray' + * color-space profile contains the information to transform the monochrome + * data to XYZ or L*a*b (according to which PCS the profile uses) and this + * should be used in preference to the standard libpng K channel replication + * into R, G and B channels. + * + * Previously it was suggested that an RGB profile on grayscale data could be + * handled. However it it is clear that using an RGB profile in this context + * must be an error - there is no specification of what it means. Thus it is + * almost certainly more correct to ignore the profile. + */ + temp = png_get_uint_32(profile+16); /* data colour space field */ + switch (temp) + { + case 0x52474220: /* 'RGB ' */ + if ((color_type & PNG_COLOR_MASK_COLOR) == 0) + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "RGB color space not permitted on grayscale PNG"); + break; + + case 0x47524159: /* 'GRAY' */ + if ((color_type & PNG_COLOR_MASK_COLOR) != 0) + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "Gray color space not permitted on RGB PNG"); + break; + + default: + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "invalid ICC profile color space"); + } + + /* It is up to the application to check that the profile class matches the + * application requirements; the spec provides no guidance, but it's pretty + * weird if the profile is not scanner ('scnr'), monitor ('mntr'), printer + * ('prtr') or 'spac' (for generic color spaces). Issue a warning in these + * cases. Issue an error for device link or abstract profiles - these don't + * contain the records necessary to transform the color-space to anything + * other than the target device (and not even that for an abstract profile). + * Profiles of these classes may not be embedded in images. + */ + temp = png_get_uint_32(profile+12); /* profile/device class */ + switch (temp) + { + case 0x73636E72: /* 'scnr' */ + case 0x6D6E7472: /* 'mntr' */ + case 0x70727472: /* 'prtr' */ + case 0x73706163: /* 'spac' */ + /* All supported */ + break; + + case 0x61627374: /* 'abst' */ + /* May not be embedded in an image */ + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "invalid embedded Abstract ICC profile"); + + case 0x6C696E6B: /* 'link' */ + /* DeviceLink profiles cannot be interpreted in a non-device specific + * fashion, if an app uses the AToB0Tag in the profile the results are + * undefined unless the result is sent to the intended device, + * therefore a DeviceLink profile should not be found embedded in a + * PNG. + */ + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "unexpected DeviceLink ICC profile class"); + + case 0x6E6D636C: /* 'nmcl' */ + /* A NamedColor profile is also device specific, however it doesn't + * contain an AToB0 tag that is open to misinterpretation. Almost + * certainly it will fail the tests below. + */ + (void)png_icc_profile_error(png_ptr, NULL, name, temp, + "unexpected NamedColor ICC profile class"); + break; + + default: + /* To allow for future enhancements to the profile accept unrecognized + * profile classes with a warning, these then hit the test below on the + * tag content to ensure they are backward compatible with one of the + * understood profiles. + */ + (void)png_icc_profile_error(png_ptr, NULL, name, temp, + "unrecognized ICC profile class"); + break; + } + + /* For any profile other than a device link one the PCS must be encoded + * either in XYZ or Lab. + */ + temp = png_get_uint_32(profile+20); + switch (temp) + { + case 0x58595A20: /* 'XYZ ' */ + case 0x4C616220: /* 'Lab ' */ + break; + + default: + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "unexpected ICC PCS encoding"); + } + + return 1; +} + +int /* PRIVATE */ +png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length, + png_const_bytep profile /* header plus whole tag table */) +{ + png_uint_32 tag_count = png_get_uint_32(profile+128); + png_uint_32 itag; + png_const_bytep tag = profile+132; /* The first tag */ + + /* First scan all the tags in the table and add bits to the icc_info value + * (temporarily in 'tags'). + */ + for (itag=0; itag < tag_count; ++itag, tag += 12) + { + png_uint_32 tag_id = png_get_uint_32(tag+0); + png_uint_32 tag_start = png_get_uint_32(tag+4); /* must be aligned */ + png_uint_32 tag_length = png_get_uint_32(tag+8);/* not padded */ + + /* The ICC specification does not exclude zero length tags, therefore the + * start might actually be anywhere if there is no data, but this would be + * a clear abuse of the intent of the standard so the start is checked for + * being in range. All defined tag types have an 8 byte header - a 4 byte + * type signature then 0. + */ + if ((tag_start & 3) != 0) + { + /* CNHP730S.icc shipped with Microsoft Windows 64 violates this, it is + * only a warning here because libpng does not care about the + * alignment. + */ + (void)png_icc_profile_error(png_ptr, NULL, name, tag_id, + "ICC profile tag start not a multiple of 4"); + } + + /* This is a hard error; potentially it can cause read outside the + * profile. + */ + if (tag_start > profile_length || tag_length > profile_length - tag_start) + return png_icc_profile_error(png_ptr, colorspace, name, tag_id, + "ICC profile tag outside profile"); + } + + return 1; /* success, maybe with warnings */ +} + +#if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0 +/* Information about the known ICC sRGB profiles */ +static const struct +{ + png_uint_32 adler, crc, length; + png_uint_32 md5[4]; + png_byte have_md5; + png_byte is_broken; + png_uint_16 intent; + +# define PNG_MD5(a,b,c,d) { a, b, c, d }, (a!=0)||(b!=0)||(c!=0)||(d!=0) +# define PNG_ICC_CHECKSUM(adler, crc, md5, intent, broke, date, length, fname)\ + { adler, crc, length, md5, broke, intent }, + +} png_sRGB_checks[] = +{ + /* This data comes from contrib/tools/checksum-icc run on downloads of + * all four ICC sRGB profiles from www.color.org. + */ + /* adler32, crc32, MD5[4], intent, date, length, file-name */ + PNG_ICC_CHECKSUM(0x0a3fd9f6, 0x3b8772b9, + PNG_MD5(0x29f83dde, 0xaff255ae, 0x7842fae4, 0xca83390d), 0, 0, + "2009/03/27 21:36:31", 3048, "sRGB_IEC61966-2-1_black_scaled.icc") + + /* ICC sRGB v2 perceptual no black-compensation: */ + PNG_ICC_CHECKSUM(0x4909e5e1, 0x427ebb21, + PNG_MD5(0xc95bd637, 0xe95d8a3b, 0x0df38f99, 0xc1320389), 1, 0, + "2009/03/27 21:37:45", 3052, "sRGB_IEC61966-2-1_no_black_scaling.icc") + + PNG_ICC_CHECKSUM(0xfd2144a1, 0x306fd8ae, + PNG_MD5(0xfc663378, 0x37e2886b, 0xfd72e983, 0x8228f1b8), 0, 0, + "2009/08/10 17:28:01", 60988, "sRGB_v4_ICC_preference_displayclass.icc") + + /* ICC sRGB v4 perceptual */ + PNG_ICC_CHECKSUM(0x209c35d2, 0xbbef7812, + PNG_MD5(0x34562abf, 0x994ccd06, 0x6d2c5721, 0xd0d68c5d), 0, 0, + "2007/07/25 00:05:37", 60960, "sRGB_v4_ICC_preference.icc") + + /* The following profiles have no known MD5 checksum. If there is a match + * on the (empty) MD5 the other fields are used to attempt a match and + * a warning is produced. The first two of these profiles have a 'cprt' tag + * which suggests that they were also made by Hewlett Packard. + */ + PNG_ICC_CHECKSUM(0xa054d762, 0x5d5129ce, + PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 0, + "2004/07/21 18:57:42", 3024, "sRGB_IEC61966-2-1_noBPC.icc") + + /* This is a 'mntr' (display) profile with a mediaWhitePointTag that does not + * match the D50 PCS illuminant in the header (it is in fact the D65 values, + * so the white point is recorded as the un-adapted value.) The profiles + * below only differ in one byte - the intent - and are basically the same as + * the previous profile except for the mediaWhitePointTag error and a missing + * chromaticAdaptationTag. + */ + PNG_ICC_CHECKSUM(0xf784f3fb, 0x182ea552, + PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 0, 1/*broken*/, + "1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 perceptual") + + PNG_ICC_CHECKSUM(0x0398f3fc, 0xf29e526d, + PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 1/*broken*/, + "1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 media-relative") +}; + +static int +png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr, + png_const_bytep profile, uLong adler) +{ + /* The quick check is to verify just the MD5 signature and trust the + * rest of the data. Because the profile has already been verified for + * correctness this is safe. png_colorspace_set_sRGB will check the 'intent' + * field too, so if the profile has been edited with an intent not defined + * by sRGB (but maybe defined by a later ICC specification) the read of + * the profile will fail at that point. + */ + + png_uint_32 length = 0; + png_uint_32 intent = 0x10000; /* invalid */ +#if PNG_sRGB_PROFILE_CHECKS > 1 + uLong crc = 0; /* the value for 0 length data */ +#endif + unsigned int i; + +#ifdef PNG_SET_OPTION_SUPPORTED + /* First see if PNG_SKIP_sRGB_CHECK_PROFILE has been set to "on" */ + if (((png_ptr->options >> PNG_SKIP_sRGB_CHECK_PROFILE) & 3) == + PNG_OPTION_ON) + return 0; +#endif + + for (i=0; i < (sizeof png_sRGB_checks) / (sizeof png_sRGB_checks[0]); ++i) + { + if (png_get_uint_32(profile+84) == png_sRGB_checks[i].md5[0] && + png_get_uint_32(profile+88) == png_sRGB_checks[i].md5[1] && + png_get_uint_32(profile+92) == png_sRGB_checks[i].md5[2] && + png_get_uint_32(profile+96) == png_sRGB_checks[i].md5[3]) + { + /* This may be one of the old HP profiles without an MD5, in that + * case we can only use the length and Adler32 (note that these + * are not used by default if there is an MD5!) + */ +# if PNG_sRGB_PROFILE_CHECKS == 0 + if (png_sRGB_checks[i].have_md5 != 0) + return 1+png_sRGB_checks[i].is_broken; +# endif + + /* Profile is unsigned or more checks have been configured in. */ + if (length == 0) + { + length = png_get_uint_32(profile); + intent = png_get_uint_32(profile+64); + } + + /* Length *and* intent must match */ + if (length == png_sRGB_checks[i].length && + intent == png_sRGB_checks[i].intent) + { + /* Now calculate the adler32 if not done already. */ + if (adler == 0) + { + adler = adler32(0, NULL, 0); + adler = adler32(adler, profile, length); + } + + if (adler == png_sRGB_checks[i].adler) + { + /* These basic checks suggest that the data has not been + * modified, but if the check level is more than 1 perform + * our own crc32 checksum on the data. + */ +# if PNG_sRGB_PROFILE_CHECKS > 1 + if (crc == 0) + { + crc = crc32(0, NULL, 0); + crc = crc32(crc, profile, length); + } + + /* So this check must pass for the 'return' below to happen. + */ + if (crc == png_sRGB_checks[i].crc) +# endif + { + if (png_sRGB_checks[i].is_broken != 0) + { + /* These profiles are known to have bad data that may cause + * problems if they are used, therefore attempt to + * discourage their use, skip the 'have_md5' warning below, + * which is made irrelevant by this error. + */ + png_chunk_report(png_ptr, "known incorrect sRGB profile", + PNG_CHUNK_ERROR); + } + + /* Warn that this being done; this isn't even an error since + * the profile is perfectly valid, but it would be nice if + * people used the up-to-date ones. + */ + else if (png_sRGB_checks[i].have_md5 == 0) + { + png_chunk_report(png_ptr, "out-of-date sRGB profile with" + " no signature", + PNG_CHUNK_WARNING); + } + + return 1+png_sRGB_checks[i].is_broken; + } + } + +# if PNG_sRGB_PROFILE_CHECKS > 0 + /* The signature matched, but the profile had been changed in some + * way. This probably indicates a data error or uninformed hacking. + * Fall through to "no match". + */ + png_chunk_report(png_ptr, "Not recognizing known sRGB profile that" + " has been edited", + PNG_CHUNK_WARNING); + break; +# endif + } + } + } + + return 0; /* no match */ +} +#endif + +#ifdef PNG_sRGB_SUPPORTED +void /* PRIVATE */ +png_icc_set_sRGB(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_bytep profile, uLong adler) +{ + /* Is this profile one of the known ICC sRGB profiles? If it is, just set + * the sRGB information. + */ +#if PNG_sRGB_PROFILE_CHECKS >= 0 + if (png_compare_ICC_profile_with_sRGB(png_ptr, profile, adler) != 0) +#endif + (void)png_colorspace_set_sRGB(png_ptr, colorspace, + (int)/*already checked*/png_get_uint_32(profile+64)); +} +#endif /* READ_sRGB */ + +int /* PRIVATE */ +png_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length, png_const_bytep profile, + int color_type) +{ + if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) + return 0; + + if (png_icc_check_length(png_ptr, colorspace, name, profile_length) != 0 && + png_icc_check_header(png_ptr, colorspace, name, profile_length, profile, + color_type) != 0 && + png_icc_check_tag_table(png_ptr, colorspace, name, profile_length, + profile) != 0) + { +# ifdef PNG_sRGB_SUPPORTED + /* If no sRGB support, don't try storing sRGB information */ + png_icc_set_sRGB(png_ptr, colorspace, profile, 0); +# endif + return 1; + } + + /* Failure case */ + return 0; +} +#endif /* iCCP */ + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +void /* PRIVATE */ +png_colorspace_set_rgb_coefficients(png_structrp png_ptr) +{ + /* Set the rgb_to_gray coefficients from the colorspace. */ + if (png_ptr->rgb_to_gray_coefficients_set == 0 && + (png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + /* png_set_background has not been called, get the coefficients from the Y + * values of the colorspace colorants. + */ + png_fixed_point r = png_ptr->colorspace.end_points_XYZ.red_Y; + png_fixed_point g = png_ptr->colorspace.end_points_XYZ.green_Y; + png_fixed_point b = png_ptr->colorspace.end_points_XYZ.blue_Y; + png_fixed_point total = r+g+b; + + if (total > 0 && + r >= 0 && png_muldiv(&r, r, 32768, total) && r >= 0 && r <= 32768 && + g >= 0 && png_muldiv(&g, g, 32768, total) && g >= 0 && g <= 32768 && + b >= 0 && png_muldiv(&b, b, 32768, total) && b >= 0 && b <= 32768 && + r+g+b <= 32769) + { + /* We allow 0 coefficients here. r+g+b may be 32769 if two or + * all of the coefficients were rounded up. Handle this by + * reducing the *largest* coefficient by 1; this matches the + * approach used for the default coefficients in pngrtran.c + */ + int add = 0; + + if (r+g+b > 32768) + add = -1; + else if (r+g+b < 32768) + add = 1; + + if (add != 0) + { + if (g >= r && g >= b) + g += add; + else if (r >= g && r >= b) + r += add; + else + b += add; + } + + /* Check for an internal error. */ + if (r+g+b != 32768) + png_error(png_ptr, + "internal error handling cHRM coefficients"); + + else + { + png_ptr->rgb_to_gray_red_coeff = (png_uint_16)r; + png_ptr->rgb_to_gray_green_coeff = (png_uint_16)g; + } + } + + /* This is a png_error at present even though it could be ignored - + * it should never happen, but it is important that if it does, the + * bug is fixed. + */ + else + png_error(png_ptr, "internal error handling cHRM->XYZ"); + } +} +#endif + +#endif /* COLORSPACE */ + +#ifdef __GNUC__ +/* This exists solely to work round a warning from GNU C. */ +static int /* PRIVATE */ +png_gt(size_t a, size_t b) +{ + return a > b; +} +#else +# define png_gt(a,b) ((a) > (b)) +#endif + +void /* PRIVATE */ +png_check_IHDR(png_const_structrp png_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type) @@ -840,53 +2514,68 @@ png_check_IHDR(png_structp png_ptr, png_warning(png_ptr, "Image width is zero in IHDR"); error = 1; } + else if (width > PNG_UINT_31_MAX) + { + png_warning(png_ptr, "Invalid image width in IHDR"); + error = 1; + } + + else if (png_gt(width, + (PNG_SIZE_MAX >> 3) /* 8-byte RGBA pixels */ + - 48 /* big_row_buf hack */ + - 1 /* filter byte */ + - 7*8 /* rounding width to multiple of 8 pix */ + - 8)) /* extra max_pixel_depth pad */ + { + /* The size of the row must be within the limits of this architecture. + * Because the read code can perform arbitrary transformations the + * maximum size is checked here. Because the code in png_read_start_row + * adds extra space "for safety's sake" in several places a conservative + * limit is used here. + * + * NOTE: it would be far better to check the size that is actually used, + * but the effect in the real world is minor and the changes are more + * extensive, therefore much more dangerous and much more difficult to + * write in a way that avoids compiler warnings. + */ + png_warning(png_ptr, "Image width is too large for this architecture"); + error = 1; + } + else + { +# ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (width > png_ptr->user_width_max) +# else + if (width > PNG_USER_WIDTH_MAX) +# endif + { + png_warning(png_ptr, "Image width exceeds user limit in IHDR"); + error = 1; + } + } if (height == 0) { png_warning(png_ptr, "Image height is zero in IHDR"); error = 1; } - -# ifdef PNG_SET_USER_LIMITS_SUPPORTED - if (width > png_ptr->user_width_max) - -# else - if (width > PNG_USER_WIDTH_MAX) -# endif - { - png_warning(png_ptr, "Image width exceeds user limit in IHDR"); - error = 1; - } - -# ifdef PNG_SET_USER_LIMITS_SUPPORTED - if (height > png_ptr->user_height_max) -# else - if (height > PNG_USER_HEIGHT_MAX) -# endif - { - png_warning(png_ptr, "Image height exceeds user limit in IHDR"); - error = 1; - } - - if (width > PNG_UINT_31_MAX) - { - png_warning(png_ptr, "Invalid image width in IHDR"); - error = 1; - } - - if (height > PNG_UINT_31_MAX) + else if (height > PNG_UINT_31_MAX) { png_warning(png_ptr, "Invalid image height in IHDR"); error = 1; } - - if (width > (PNG_UINT_32_MAX - >> 3) /* 8-byte RGBA pixels */ - - 48 /* bigrowbuf hack */ - - 1 /* filter byte */ - - 7*8 /* rounding of width to multiple of 8 pixels */ - - 8) /* extra max_pixel_depth pad */ - png_warning(png_ptr, "Width is too large for libpng to process pixels"); + else + { +# ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (height > png_ptr->user_height_max) +# else + if (height > PNG_USER_HEIGHT_MAX) +# endif + { + png_warning(png_ptr, "Image height exceeds user limit in IHDR"); + error = 1; + } + } /* Check other values */ if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && @@ -934,13 +2623,13 @@ png_check_IHDR(png_structp png_ptr, * 4. The filter_method is 64 and * 5. The color_type is RGB or RGBA */ - if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) && - png_ptr->mng_features_permitted) + if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && + png_ptr->mng_features_permitted != 0) png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); if (filter_type != PNG_FILTER_TYPE_BASE) { - if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && (color_type == PNG_COLOR_TYPE_RGB || @@ -950,7 +2639,7 @@ png_check_IHDR(png_structp png_ptr, error = 1; } - if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) + if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0) { png_warning(png_ptr, "Invalid filter method in IHDR"); error = 1; @@ -1010,7 +2699,7 @@ png_check_fp_number(png_const_charp string, png_size_t size, int *statep, switch ((state & PNG_FP_STATE) + (type & PNG_FP_SAW_ANY)) { case PNG_FP_INTEGER + PNG_FP_SAW_SIGN: - if (state & PNG_FP_SAW_ANY) + if ((state & PNG_FP_SAW_ANY) != 0) goto PNG_FP_End; /* not a part of the number */ png_fp_add(state, type); @@ -1018,10 +2707,10 @@ png_check_fp_number(png_const_charp string, png_size_t size, int *statep, case PNG_FP_INTEGER + PNG_FP_SAW_DOT: /* Ok as trailer, ok as lead of fraction. */ - if (state & PNG_FP_SAW_DOT) /* two dots */ + if ((state & PNG_FP_SAW_DOT) != 0) /* two dots */ goto PNG_FP_End; - else if (state & PNG_FP_SAW_DIGIT) /* trailing dot? */ + else if ((state & PNG_FP_SAW_DIGIT) != 0) /* trailing dot? */ png_fp_add(state, type); else @@ -1030,7 +2719,7 @@ png_check_fp_number(png_const_charp string, png_size_t size, int *statep, break; case PNG_FP_INTEGER + PNG_FP_SAW_DIGIT: - if (state & PNG_FP_SAW_DOT) /* delayed fraction */ + if ((state & PNG_FP_SAW_DOT) != 0) /* delayed fraction */ png_fp_set(state, PNG_FP_FRACTION | PNG_FP_SAW_DOT); png_fp_add(state, type | PNG_FP_WAS_VALID); @@ -1068,7 +2757,7 @@ png_check_fp_number(png_const_charp string, png_size_t size, int *statep, break; case PNG_FP_EXPONENT + PNG_FP_SAW_SIGN: - if (state & PNG_FP_SAW_ANY) + if ((state & PNG_FP_SAW_ANY) != 0) goto PNG_FP_End; /* not a part of the number */ png_fp_add(state, PNG_FP_SAW_SIGN); @@ -1111,15 +2800,15 @@ png_check_fp_string(png_const_charp string, png_size_t size) int state=0; png_size_t char_index=0; - if (png_check_fp_number(string, size, &state, &char_index) && + if (png_check_fp_number(string, size, &state, &char_index) != 0 && (char_index == size || string[char_index] == 0)) return state /* must be non-zero - see above */; return 0; /* i.e. fail */ } -#endif /* pCAL or sCAL */ +#endif /* pCAL || sCAL */ -#ifdef PNG_READ_sCAL_SUPPORTED +#ifdef PNG_sCAL_SUPPORTED # ifdef PNG_FLOATING_POINT_SUPPORTED /* Utility used below - a simple accurate power of ten from an integral * exponent. @@ -1151,7 +2840,7 @@ png_pow10(int power) } while (power > 0); - if (recip) d = 1/d; + if (recip != 0) d = 1/d; } /* else power is 0 and d is 1 */ @@ -1162,7 +2851,7 @@ png_pow10(int power) * precision. */ void /* PRIVATE */ -png_ascii_from_fp(png_structp png_ptr, png_charp ascii, png_size_t size, +png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, double fp, unsigned int precision) { /* We use standard functions from math.h, but not printf because @@ -1365,8 +3054,9 @@ png_ascii_from_fp(png_structp png_ptr, png_charp ascii, png_size_t size, if (exp_b10 != (-1)) { - if (exp_b10 == 0) *ascii++ = 46, --size; /* counted - above */ + if (exp_b10 == 0) + *ascii++ = 46, --size; /* counted above */ + --exp_b10; } *ascii++ = (char)(48 + (int)d), ++cdigits; @@ -1411,18 +3101,30 @@ png_ascii_from_fp(png_structp png_ptr, png_charp ascii, png_size_t size, size -= cdigits; *ascii++ = 69, --size; /* 'E': PLUS 1 TOTAL 2+precision */ - if (exp_b10 < 0) - { - *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */ - exp_b10 = -exp_b10; - } - cdigits = 0; - - while (exp_b10 > 0) + /* The following use of an unsigned temporary avoids ambiguities in + * the signed arithmetic on exp_b10 and permits GCC at least to do + * better optimization. + */ { - exponent[cdigits++] = (char)(48 + exp_b10 % 10); - exp_b10 /= 10; + unsigned int uexp_b10; + + if (exp_b10 < 0) + { + *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */ + uexp_b10 = -exp_b10; + } + + else + uexp_b10 = exp_b10; + + cdigits = 0; + + while (uexp_b10 > 0) + { + exponent[cdigits++] = (char)(48 + uexp_b10 % 10); + uexp_b10 /= 10; + } } /* Need another size check here for the exponent digits, so @@ -1464,8 +3166,8 @@ png_ascii_from_fp(png_structp png_ptr, png_charp ascii, png_size_t size, /* Function to format a fixed point value in ASCII. */ void /* PRIVATE */ -png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size, - png_fixed_point fp) +png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii, + png_size_t size, png_fixed_point fp) { /* Require space for 10 decimal digits, a decimal point, a minus sign and a * trailing \0, 13 characters: @@ -1480,7 +3182,7 @@ png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size, else num = fp; - if (num <= 0x80000000U) /* else overflowed */ + if (num <= 0x80000000) /* else overflowed */ { unsigned int ndigits = 0, first = 16 /* flag value */; char digits[10]; @@ -1535,21 +3237,30 @@ png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size, #endif /* READ_SCAL */ #if defined(PNG_FLOATING_POINT_SUPPORTED) && \ - !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) + !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \ + (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \ + defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \ + (defined(PNG_sCAL_SUPPORTED) && \ + defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)) png_fixed_point -png_fixed(png_structp png_ptr, double fp, png_const_charp text) +png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text) { double r = floor(100000 * fp + .5); if (r > 2147483647. || r < -2147483648.) png_fixed_error(png_ptr, text); +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(text) +# endif + return (png_fixed_point)r; } #endif -#if defined(PNG_READ_GAMMA_SUPPORTED) || \ - defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG__READ_pHYs_SUPPORTED) +#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_COLORSPACE_SUPPORTED) ||\ + defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED) /* muldiv functions */ /* This API takes signed arguments and rounds the result to the nearest * integer (or, for a fixed point number - the standard argument - to @@ -1653,11 +3364,12 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, if (s00 >= (D >> 1)) ++result; - if (negative) + if (negative != 0) result = -result; /* Check for overflow. */ - if ((negative && result <= 0) || (!negative && result >= 0)) + if ((negative != 0 && result <= 0) || + (negative == 0 && result >= 0)) { *res = result; return 1; @@ -1676,12 +3388,12 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, * result. */ png_fixed_point -png_muldiv_warn(png_structp png_ptr, png_fixed_point a, png_int_32 times, +png_muldiv_warn(png_const_structrp png_ptr, png_fixed_point a, png_int_32 times, png_int_32 divisor) { png_fixed_point result; - if (png_muldiv(&result, a, times, divisor)) + if (png_muldiv(&result, a, times, divisor) != 0) return result; png_warning(png_ptr, "fixed point overflow ignored"); @@ -1689,7 +3401,7 @@ png_muldiv_warn(png_structp png_ptr, png_fixed_point a, png_int_32 times, } #endif -#ifdef PNG_READ_GAMMA_SUPPORTED /* more fixed point functions for gammma */ +#ifdef PNG_GAMMA_SUPPORTED /* more fixed point functions for gamma */ /* Calculate a reciprocal, return 0 on div-by-zero or overflow. */ png_fixed_point png_reciprocal(png_fixed_point a) @@ -1702,34 +3414,48 @@ png_reciprocal(png_fixed_point a) #else png_fixed_point res; - if (png_muldiv(&res, 100000, 100000, a)) + if (png_muldiv(&res, 100000, 100000, a) != 0) return res; #endif return 0; /* error/overflow */ } +/* This is the shared test on whether a gamma value is 'significant' - whether + * it is worth doing gamma correction. + */ +int /* PRIVATE */ +png_gamma_significant(png_fixed_point gamma_val) +{ + return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED || + gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED; +} +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +#if defined(PNG_16BIT_SUPPORTED) || !defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) /* A local convenience routine. */ static png_fixed_point png_product2(png_fixed_point a, png_fixed_point b) { /* The required result is 1/a * 1/b; the following preserves accuracy. */ -#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED +# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED double r = a * 1E-5; r *= b; r = floor(r+.5); if (r <= 2147483647. && r >= -2147483648.) return (png_fixed_point)r; -#else +# else png_fixed_point res; - if (png_muldiv(&res, a, b, 100000)) + if (png_muldiv(&res, a, b, 100000) != 0) return res; -#endif +# endif return 0; /* overflow */ } +#endif /* 16BIT || !FLOATING_ARITHMETIC */ /* The inverse of the above. */ png_fixed_point @@ -1759,73 +3485,28 @@ png_reciprocal2(png_fixed_point a, png_fixed_point b) } #endif /* READ_GAMMA */ -#ifdef PNG_CHECK_cHRM_SUPPORTED -/* Added at libpng version 1.2.34 (Dec 8, 2008) and 1.4.0 (Jan 2, - * 2010: moved from pngset.c) */ -/* - * Multiply two 32-bit numbers, V1 and V2, using 32-bit - * arithmetic, to produce a 64-bit result in the HI/LO words. - * - * A B - * x C D - * ------ - * AD || BD - * AC || CB || 0 - * - * where A and B are the high and low 16-bit words of V1, - * C and D are the 16-bit words of V2, AD is the product of - * A and D, and X || Y is (X << 16) + Y. -*/ - -void /* PRIVATE */ -png_64bit_product (long v1, long v2, unsigned long *hi_product, - unsigned long *lo_product) -{ - int a, b, c, d; - long lo, hi, x, y; - - a = (v1 >> 16) & 0xffff; - b = v1 & 0xffff; - c = (v2 >> 16) & 0xffff; - d = v2 & 0xffff; - - lo = b * d; /* BD */ - x = a * d + c * b; /* AD + CB */ - y = ((lo >> 16) & 0xffff) + x; - - lo = (lo & 0xffff) | ((y & 0xffff) << 16); - hi = (y >> 16) & 0xffff; - - hi += a * c; /* AC */ - - *hi_product = (unsigned long)hi; - *lo_product = (unsigned long)lo; -} -#endif /* CHECK_cHRM */ - #ifdef PNG_READ_GAMMA_SUPPORTED /* gamma table code */ #ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED /* Fixed point gamma. + * + * The code to calculate the tables used below can be found in the shell script + * contrib/tools/intgamma.sh * * To calculate gamma this code implements fast log() and exp() calls using only * fixed point arithmetic. This code has sufficient precision for either 8-bit * or 16-bit sample values. * * The tables used here were calculated using simple 'bc' programs, but C double - * precision floating point arithmetic would work fine. The programs are given - * at the head of each table. + * precision floating point arithmetic would work fine. * * 8-bit log table * This is a table of -log(value/255)/log(2) for 'value' in the range 128 to * 255, so it's the base 2 logarithm of a normalized 8-bit floating point * mantissa. The numbers are 32-bit fractions. */ -static png_uint_32 +static const png_uint_32 png_8bit_l2[128] = { -# if PNG_DO_BC - for (i=128;i<256;++i) { .5 - l(i/255)/l(2)*65536*65536; } -# endif 4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U, 3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U, 3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U, @@ -1848,6 +3529,7 @@ png_8bit_l2[128] = 324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U, 172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U, 24347096U, 0U + #if 0 /* The following are the values for 16-bit tables - these work fine for the * 8-bit conversions but produce very slightly larger errors in the 16-bit @@ -1869,18 +3551,18 @@ png_8bit_l2[128] = #endif }; -PNG_STATIC png_int_32 +static png_int_32 png_log8bit(unsigned int x) { unsigned int lg2 = 0; /* Each time 'x' is multiplied by 2, 1 must be subtracted off the final log, * because the log is actually negate that means adding 1. The final * returned value thus has the range 0 (for 255 input) to 7.994 (for 1 - * input), return 7.99998 for the overflow (log 0) case - so the result is + * input), return -1 for the overflow (log 0) case, - so the result is * always at most 19 bits. */ if ((x &= 0xff) == 0) - return 0xffffffff; + return -1; if ((x & 0xf0) == 0) lg2 = 4, x <<= 4; @@ -1925,14 +3607,15 @@ png_log8bit(unsigned int x) * Zero (257): 0 * End (258): 23499 */ -PNG_STATIC png_int_32 +#ifdef PNG_16BIT_SUPPORTED +static png_int_32 png_log16bit(png_uint_32 x) { unsigned int lg2 = 0; /* As above, but now the input has 16 bits. */ if ((x &= 0xffff) == 0) - return 0xffffffff; + return -1; if ((x & 0xff00) == 0) lg2 = 8, x <<= 8; @@ -1975,14 +3658,15 @@ png_log16bit(png_uint_32 x) /* Safe, because the result can't have more than 20 bits: */ return (png_int_32)((lg2 + 2048) >> 12); } +#endif /* 16BIT */ /* The 'exp()' case must invert the above, taking a 20-bit fixed point * logarithmic value and returning a 16 or 8-bit number as appropriate. In * each case only the low 16 bits are relevant - the fraction - since the * integer bits (the top 4) simply determine a shift. * - * The worst case is the 16-bit distinction between 65535 and 65534, this - * requires perhaps spurious accuracty in the decoding of the logarithm to + * The worst case is the 16-bit distinction between 65535 and 65534. This + * requires perhaps spurious accuracy in the decoding of the logarithm to * distinguish log2(65535/65534.5) - 10^-5 or 17 bits. There is little chance * of getting this accuracy in practice. * @@ -1990,12 +3674,9 @@ png_log16bit(png_uint_32 x) * frational part of the logarithm by using an accurate 32-bit value from the * top four fractional bits then multiplying in the remaining bits. */ -static png_uint_32 +static const png_uint_32 png_32bit_exp[16] = { -# if PNG_DO_BC - for (i=0;i<16;++i) { .5 + e(-i/16*l(2))*2^32; } -# endif /* NOTE: the first entry is deliberately set to the maximum 32-bit value. */ 4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U, 3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U, @@ -2003,7 +3684,7 @@ png_32bit_exp[16] = }; /* Adjustment table; provided to explain the numbers in the code below. */ -#if PNG_DO_BC +#if 0 for (i=11;i>=0;--i){ print i, " ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), "\n"} 11 44937.64284865548751208448 10 45180.98734845585101160448 @@ -2019,7 +3700,7 @@ for (i=11;i>=0;--i){ print i, " ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), "\n"} 0 45425.85339951654943850496 #endif -PNG_STATIC png_uint_32 +static png_uint_32 png_exp(png_fixed_point x) { if (x > 0 && x <= 0xfffff) /* Else overflow or zero (underflow) */ @@ -2067,13 +3748,13 @@ png_exp(png_fixed_point x) return 0; } -PNG_STATIC png_byte +static png_byte png_exp8bit(png_fixed_point lg2) { /* Get a 32-bit value: */ png_uint_32 x = png_exp(lg2); - /* Convert the 32-bit value to 0..255 by multiplying by 256-1, note that the + /* Convert the 32-bit value to 0..255 by multiplying by 256-1. Note that the * second, rounding, step can't overflow because of the first, subtraction, * step. */ @@ -2081,7 +3762,8 @@ png_exp8bit(png_fixed_point lg2) return (png_byte)((x + 0x7fffffU) >> 24); } -PNG_STATIC png_uint_16 +#ifdef PNG_16BIT_SUPPORTED +static png_uint_16 png_exp16bit(png_fixed_point lg2) { /* Get a 32-bit value: */ @@ -2091,6 +3773,7 @@ png_exp16bit(png_fixed_point lg2) x -= x >> 16; return (png_uint_16)((x + 32767U) >> 16); } +#endif /* 16BIT */ #endif /* FLOATING_ARITHMETIC */ png_byte @@ -2099,13 +3782,37 @@ png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val) if (value > 0 && value < 255) { # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = floor(255*pow(value/255.,gamma_val*.00001)+.5); + /* 'value' is unsigned, ANSI-C90 requires the compiler to correctly + * convert this to a floating point value. This includes values that + * would overflow if 'value' were to be converted to 'int'. + * + * Apparently GCC, however, does an intermediate conversion to (int) + * on some (ARM) but not all (x86) platforms, possibly because of + * hardware FP limitations. (E.g. if the hardware conversion always + * assumes the integer register contains a signed value.) This results + * in ANSI-C undefined behavior for large values. + * + * Other implementations on the same machine might actually be ANSI-C90 + * conformant and therefore compile spurious extra code for the large + * values. + * + * We can be reasonably sure that an unsigned to float conversion + * won't be faster than an int to float one. Therefore this code + * assumes responsibility for the undefined behavior, which it knows + * can't happen because of the check above. + * + * Note the argument to this routine is an (unsigned int) because, on + * 16-bit platforms, it is assigned a value which might be out of + * range for an (int); that would result in undefined behavior in the + * caller if the *argument* ('value') were to be declared (int). + */ + double r = floor(255*pow((int)/*SAFE*/value/255.,gamma_val*.00001)+.5); return (png_byte)r; # else png_int_32 lg2 = png_log8bit(value); png_fixed_point res; - if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1)) + if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0) return png_exp8bit(res); /* Overflow. */ @@ -2116,19 +3823,26 @@ png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val) return (png_byte)value; } +#ifdef PNG_16BIT_SUPPORTED png_uint_16 png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val) { if (value > 0 && value < 65535) { # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = floor(65535*pow(value/65535.,gamma_val*.00001)+.5); + /* The same (unsigned int)->(double) constraints apply here as above, + * however in this case the (unsigned int) to (int) conversion can + * overflow on an ANSI-C90 compliant system so the cast needs to ensure + * that this is not possible. + */ + double r = floor(65535*pow((png_int_32)value/65535., + gamma_val*.00001)+.5); return (png_uint_16)r; # else png_int_32 lg2 = png_log16bit(value); png_fixed_point res; - if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1)) + if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0) return png_exp16bit(res); /* Overflow. */ @@ -2138,6 +3852,7 @@ png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val) return (png_uint_16)value; } +#endif /* 16BIT */ /* This does the right thing based on the bit_depth field of the * png_struct, interpreting values as 8-bit or 16-bit. While the result @@ -2145,26 +3860,22 @@ png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val) * 8-bit (as are the arguments.) */ png_uint_16 /* PRIVATE */ -png_gamma_correct(png_structp png_ptr, unsigned int value, +png_gamma_correct(png_structrp png_ptr, unsigned int value, png_fixed_point gamma_val) { if (png_ptr->bit_depth == 8) return png_gamma_8bit_correct(value, gamma_val); +#ifdef PNG_16BIT_SUPPORTED else return png_gamma_16bit_correct(value, gamma_val); +#else + /* should not reach this */ + return 0; +#endif /* 16BIT */ } -/* This is the shared test on whether a gamma value is 'significant' - whether - * it is worth doing gamma correction. - */ -int /* PRIVATE */ -png_gamma_significant(png_fixed_point gamma_val) -{ - return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED || - gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED; -} - +#ifdef PNG_16BIT_SUPPORTED /* Internal function to build a single 16-bit table - the table consists of * 'num' 256 entry subtables, where 'num' is determined by 'shift' - the amount * to shift the input values right (or 16-number_of_signifiant_bits). @@ -2174,27 +3885,33 @@ png_gamma_significant(png_fixed_point gamma_val) * should be somewhere that will be cleaned. */ static void -png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable, +png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable, PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val) { /* Various values derived from 'shift': */ PNG_CONST unsigned int num = 1U << (8U - shift); +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + /* CSE the division and work round wacky GCC warnings (see the comments + * in png_gamma_8bit_correct for where these come from.) + */ + PNG_CONST double fmax = 1./(((png_int_32)1 << (16U - shift))-1); +#endif PNG_CONST unsigned int max = (1U << (16U - shift))-1U; PNG_CONST unsigned int max_by_2 = 1U << (15U-shift); unsigned int i; png_uint_16pp table = *ptable = - (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p)); + (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p))); for (i = 0; i < num; i++) { png_uint_16p sub_table = table[i] = - (png_uint_16p)png_malloc(png_ptr, 256 * png_sizeof(png_uint_16)); + (png_uint_16p)png_malloc(png_ptr, 256 * (sizeof (png_uint_16))); /* The 'threshold' test is repeated here because it can arise for one of * the 16-bit tables even if the others don't hit it. */ - if (png_gamma_significant(gamma_val)) + if (png_gamma_significant(gamma_val) != 0) { /* The old code would overflow at the end and this would cause the * 'pow' function to return a result >1, resulting in an @@ -2210,10 +3927,13 @@ png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable, png_uint_32 ig = (j << (8-shift)) + i; # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED /* Inline the 'max' scaling operation: */ - double d = floor(65535*pow(ig/(double)max, gamma_val*.00001)+.5); + /* See png_gamma_8bit_correct for why the cast to (int) is + * required here. + */ + double d = floor(65535.*pow(ig*fmax, gamma_val*.00001)+.5); sub_table[j] = (png_uint_16)d; # else - if (shift) + if (shift != 0) ig = (ig * 65535U + max_by_2)/max; sub_table[j] = png_gamma_16bit_correct(ig, gamma_val); @@ -2229,7 +3949,7 @@ png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable, { png_uint_32 ig = (j << (8-shift)) + i; - if (shift) + if (shift != 0) ig = (ig * 65535U + max_by_2)/max; sub_table[j] = (png_uint_16)ig; @@ -2242,7 +3962,7 @@ png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable, * required. */ static void -png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable, +png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable, PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val) { PNG_CONST unsigned int num = 1U << (8U - shift); @@ -2251,15 +3971,15 @@ png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable, png_uint_32 last; png_uint_16pp table = *ptable = - (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p)); + (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p))); /* 'num' is the number of tables and also the number of low bits of low * bits of the input 16-bit value used to select a table. Each table is - * itself index by the high 8 bits of the value. + * itself indexed by the high 8 bits of the value. */ for (i = 0; i < num; i++) table[i] = (png_uint_16p)png_malloc(png_ptr, - 256 * png_sizeof(png_uint_16)); + 256 * (sizeof (png_uint_16))); /* 'gamma_val' is set to the reciprocal of the value calculated above, so * pow(out,g) is an *input* value. 'last' is the last input value set. @@ -2303,23 +4023,84 @@ png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable, last++; } } +#endif /* 16BIT */ /* Build a single 8-bit table: same as the 16-bit case but much simpler (and * typically much faster). Note that libpng currently does no sBIT processing - * (apparently contrary to the spec) so a 256 entry table is always generated. + * (apparently contrary to the spec) so a 256-entry table is always generated. */ static void -png_build_8bit_table(png_structp png_ptr, png_bytepp ptable, +png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable, PNG_CONST png_fixed_point gamma_val) { unsigned int i; png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256); - if (png_gamma_significant(gamma_val)) for (i=0; i<256; i++) - table[i] = png_gamma_8bit_correct(i, gamma_val); + if (png_gamma_significant(gamma_val) != 0) + for (i=0; i<256; i++) + table[i] = png_gamma_8bit_correct(i, gamma_val); - else for (i=0; i<256; ++i) - table[i] = (png_byte)i; + else + for (i=0; i<256; ++i) + table[i] = (png_byte)i; +} + +/* Used from png_read_destroy and below to release the memory used by the gamma + * tables. + */ +void /* PRIVATE */ +png_destroy_gamma_table(png_structrp png_ptr) +{ + png_free(png_ptr, png_ptr->gamma_table); + png_ptr->gamma_table = NULL; + +#ifdef PNG_16BIT_SUPPORTED + if (png_ptr->gamma_16_table != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_table[i]); + } + png_free(png_ptr, png_ptr->gamma_16_table); + png_ptr->gamma_16_table = NULL; + } +#endif /* 16BIT */ + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + png_free(png_ptr, png_ptr->gamma_from_1); + png_ptr->gamma_from_1 = NULL; + png_free(png_ptr, png_ptr->gamma_to_1); + png_ptr->gamma_to_1 = NULL; + +#ifdef PNG_16BIT_SUPPORTED + if (png_ptr->gamma_16_from_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_from_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_from_1); + png_ptr->gamma_16_from_1 = NULL; + } + if (png_ptr->gamma_16_to_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_to_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_to_1); + png_ptr->gamma_16_to_1 = NULL; + } +#endif /* 16BIT */ +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ } /* We build the 8- or 16-bit gamma tables here. Note that for 16-bit @@ -2328,35 +4109,48 @@ png_build_8bit_table(png_structp png_ptr, png_bytepp ptable, * we don't need to allocate > 64K chunks for a full 16-bit table. */ void /* PRIVATE */ -png_build_gamma_table(png_structp png_ptr, int bit_depth) +png_build_gamma_table(png_structrp png_ptr, int bit_depth) { png_debug(1, "in png_build_gamma_table"); + /* Remove any existing table; this copes with multiple calls to + * png_read_update_info. The warning is because building the gamma tables + * multiple times is a performance hit - it's harmless but the ability to call + * png_read_update_info() multiple times is new in 1.5.6 so it seems sensible + * to warn if the app introduces such a hit. + */ + if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL) + { + png_warning(png_ptr, "gamma table being rebuilt"); + png_destroy_gamma_table(png_ptr); + } + if (bit_depth <= 8) { png_build_8bit_table(png_ptr, &png_ptr->gamma_table, - png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->gamma, + png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma, png_ptr->screen_gamma) : PNG_FP_1); #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) - if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) + if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0) { png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1, - png_reciprocal(png_ptr->gamma)); + png_reciprocal(png_ptr->colorspace.gamma)); png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1, png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : - png_ptr->gamma/* Probably doing rgb_to_gray */); + png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */); } #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ } +#ifdef PNG_16BIT_SUPPORTED else { png_byte shift, sig_bit; - if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) { sig_bit = png_ptr->sig_bit.red; @@ -2376,7 +4170,7 @@ png_build_gamma_table(png_structp png_ptr, int bit_depth) * Where 'iv' is the input color value and 'ov' is the output value - * pow(iv, gamma). * - * Thus the gamma table consists of up to 256 256 entry tables. The table + * Thus the gamma table consists of up to 256 256-entry tables. The table * is selected by the (8-gamma_shift) most significant of the low 8 bits of * the color value then indexed by the upper 8 bits: * @@ -2393,7 +4187,7 @@ png_build_gamma_table(png_structp png_ptr, int bit_depth) else shift = 0; /* keep all 16 bits */ - if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) + if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0) { /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively * the significant bits in the *input* when the output will @@ -2408,32 +4202,28 @@ png_build_gamma_table(png_structp png_ptr, int bit_depth) png_ptr->gamma_shift = shift; -#ifdef PNG_16BIT_SUPPORTED /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now * PNG_COMPOSE). This effectively smashed the background calculation for * 16-bit output because the 8-bit table assumes the result will be reduced * to 8 bits. */ - if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) -#endif + if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0) png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift, - png_ptr->screen_gamma > 0 ? png_product2(png_ptr->gamma, + png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma, png_ptr->screen_gamma) : PNG_FP_1); -#ifdef PNG_16BIT_SUPPORTED else png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift, - png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->gamma, + png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma, png_ptr->screen_gamma) : PNG_FP_1); -#endif #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) - if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) + if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0) { png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift, - png_reciprocal(png_ptr->gamma)); + png_reciprocal(png_ptr->colorspace.gamma)); /* Notice that the '16 from 1' table should be full precision, however * the lookup on this table still uses gamma_shift, so it can't be. @@ -2441,10 +4231,291 @@ png_build_gamma_table(png_structp png_ptr, int bit_depth) */ png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift, png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : - png_ptr->gamma/* Probably doing rgb_to_gray */); + png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */); } #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ } +#endif /* 16BIT */ } #endif /* READ_GAMMA */ -#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +/* HARDWARE OR SOFTWARE OPTION SUPPORT */ +#ifdef PNG_SET_OPTION_SUPPORTED +int PNGAPI +png_set_option(png_structrp png_ptr, int option, int onoff) +{ + if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT && + (option & 1) == 0) + { + int mask = 3 << option; + int setting = (2 + (onoff != 0)) << option; + int current = png_ptr->options; + + png_ptr->options = (png_byte)((current & ~mask) | setting); + + return (current & mask) >> option; + } + + return PNG_OPTION_INVALID; +} +#endif + +/* sRGB support */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +/* sRGB conversion tables; these are machine generated with the code in + * contrib/tools/makesRGB.c. The actual sRGB transfer curve defined in the + * specification (see the article at http://en.wikipedia.org/wiki/SRGB) + * is used, not the gamma=1/2.2 approximation use elsewhere in libpng. + * The sRGB to linear table is exact (to the nearest 16 bit linear fraction). + * The inverse (linear to sRGB) table has accuracies as follows: + * + * For all possible (255*65535+1) input values: + * + * error: -0.515566 - 0.625971, 79441 (0.475369%) of readings inexact + * + * For the input values corresponding to the 65536 16-bit values: + * + * error: -0.513727 - 0.607759, 308 (0.469978%) of readings inexact + * + * In all cases the inexact readings are only off by one. + */ + +#ifdef PNG_SIMPLIFIED_READ_SUPPORTED +/* The convert-to-sRGB table is only currently required for read. */ +const png_uint_16 png_sRGB_table[256] = +{ + 0,20,40,60,80,99,119,139, + 159,179,199,219,241,264,288,313, + 340,367,396,427,458,491,526,562, + 599,637,677,718,761,805,851,898, + 947,997,1048,1101,1156,1212,1270,1330, + 1391,1453,1517,1583,1651,1720,1790,1863, + 1937,2013,2090,2170,2250,2333,2418,2504, + 2592,2681,2773,2866,2961,3058,3157,3258, + 3360,3464,3570,3678,3788,3900,4014,4129, + 4247,4366,4488,4611,4736,4864,4993,5124, + 5257,5392,5530,5669,5810,5953,6099,6246, + 6395,6547,6700,6856,7014,7174,7335,7500, + 7666,7834,8004,8177,8352,8528,8708,8889, + 9072,9258,9445,9635,9828,10022,10219,10417, + 10619,10822,11028,11235,11446,11658,11873,12090, + 12309,12530,12754,12980,13209,13440,13673,13909, + 14146,14387,14629,14874,15122,15371,15623,15878, + 16135,16394,16656,16920,17187,17456,17727,18001, + 18277,18556,18837,19121,19407,19696,19987,20281, + 20577,20876,21177,21481,21787,22096,22407,22721, + 23038,23357,23678,24002,24329,24658,24990,25325, + 25662,26001,26344,26688,27036,27386,27739,28094, + 28452,28813,29176,29542,29911,30282,30656,31033, + 31412,31794,32179,32567,32957,33350,33745,34143, + 34544,34948,35355,35764,36176,36591,37008,37429, + 37852,38278,38706,39138,39572,40009,40449,40891, + 41337,41785,42236,42690,43147,43606,44069,44534, + 45002,45473,45947,46423,46903,47385,47871,48359, + 48850,49344,49841,50341,50844,51349,51858,52369, + 52884,53401,53921,54445,54971,55500,56032,56567, + 57105,57646,58190,58737,59287,59840,60396,60955, + 61517,62082,62650,63221,63795,64372,64952,65535 +}; +#endif /* SIMPLIFIED_READ */ + +/* The base/delta tables are required for both read and write (but currently + * only the simplified versions.) + */ +const png_uint_16 png_sRGB_base[512] = +{ + 128,1782,3383,4644,5675,6564,7357,8074, + 8732,9346,9921,10463,10977,11466,11935,12384, + 12816,13233,13634,14024,14402,14769,15125,15473, + 15812,16142,16466,16781,17090,17393,17690,17981, + 18266,18546,18822,19093,19359,19621,19879,20133, + 20383,20630,20873,21113,21349,21583,21813,22041, + 22265,22487,22707,22923,23138,23350,23559,23767, + 23972,24175,24376,24575,24772,24967,25160,25352, + 25542,25730,25916,26101,26284,26465,26645,26823, + 27000,27176,27350,27523,27695,27865,28034,28201, + 28368,28533,28697,28860,29021,29182,29341,29500, + 29657,29813,29969,30123,30276,30429,30580,30730, + 30880,31028,31176,31323,31469,31614,31758,31902, + 32045,32186,32327,32468,32607,32746,32884,33021, + 33158,33294,33429,33564,33697,33831,33963,34095, + 34226,34357,34486,34616,34744,34873,35000,35127, + 35253,35379,35504,35629,35753,35876,35999,36122, + 36244,36365,36486,36606,36726,36845,36964,37083, + 37201,37318,37435,37551,37668,37783,37898,38013, + 38127,38241,38354,38467,38580,38692,38803,38915, + 39026,39136,39246,39356,39465,39574,39682,39790, + 39898,40005,40112,40219,40325,40431,40537,40642, + 40747,40851,40955,41059,41163,41266,41369,41471, + 41573,41675,41777,41878,41979,42079,42179,42279, + 42379,42478,42577,42676,42775,42873,42971,43068, + 43165,43262,43359,43456,43552,43648,43743,43839, + 43934,44028,44123,44217,44311,44405,44499,44592, + 44685,44778,44870,44962,45054,45146,45238,45329, + 45420,45511,45601,45692,45782,45872,45961,46051, + 46140,46229,46318,46406,46494,46583,46670,46758, + 46846,46933,47020,47107,47193,47280,47366,47452, + 47538,47623,47709,47794,47879,47964,48048,48133, + 48217,48301,48385,48468,48552,48635,48718,48801, + 48884,48966,49048,49131,49213,49294,49376,49458, + 49539,49620,49701,49782,49862,49943,50023,50103, + 50183,50263,50342,50422,50501,50580,50659,50738, + 50816,50895,50973,51051,51129,51207,51285,51362, + 51439,51517,51594,51671,51747,51824,51900,51977, + 52053,52129,52205,52280,52356,52432,52507,52582, + 52657,52732,52807,52881,52956,53030,53104,53178, + 53252,53326,53400,53473,53546,53620,53693,53766, + 53839,53911,53984,54056,54129,54201,54273,54345, + 54417,54489,54560,54632,54703,54774,54845,54916, + 54987,55058,55129,55199,55269,55340,55410,55480, + 55550,55620,55689,55759,55828,55898,55967,56036, + 56105,56174,56243,56311,56380,56448,56517,56585, + 56653,56721,56789,56857,56924,56992,57059,57127, + 57194,57261,57328,57395,57462,57529,57595,57662, + 57728,57795,57861,57927,57993,58059,58125,58191, + 58256,58322,58387,58453,58518,58583,58648,58713, + 58778,58843,58908,58972,59037,59101,59165,59230, + 59294,59358,59422,59486,59549,59613,59677,59740, + 59804,59867,59930,59993,60056,60119,60182,60245, + 60308,60370,60433,60495,60558,60620,60682,60744, + 60806,60868,60930,60992,61054,61115,61177,61238, + 61300,61361,61422,61483,61544,61605,61666,61727, + 61788,61848,61909,61969,62030,62090,62150,62211, + 62271,62331,62391,62450,62510,62570,62630,62689, + 62749,62808,62867,62927,62986,63045,63104,63163, + 63222,63281,63340,63398,63457,63515,63574,63632, + 63691,63749,63807,63865,63923,63981,64039,64097, + 64155,64212,64270,64328,64385,64443,64500,64557, + 64614,64672,64729,64786,64843,64900,64956,65013, + 65070,65126,65183,65239,65296,65352,65409,65465 +}; + +const png_byte png_sRGB_delta[512] = +{ + 207,201,158,129,113,100,90,82,77,72,68,64,61,59,56,54, + 52,50,49,47,46,45,43,42,41,40,39,39,38,37,36,36, + 35,34,34,33,33,32,32,31,31,30,30,30,29,29,28,28, + 28,27,27,27,27,26,26,26,25,25,25,25,24,24,24,24, + 23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21, + 21,20,20,20,20,20,20,20,20,19,19,19,19,19,19,19, + 19,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17, + 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16, + 16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15, + 15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14, + 14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13, + 13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12, + 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11, + 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 +}; +#endif /* SIMPLIFIED READ/WRITE sRGB support */ + +/* SIMPLIFIED READ/WRITE SUPPORT */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +static int +png_image_free_function(png_voidp argument) +{ + png_imagep image = png_voidcast(png_imagep, argument); + png_controlp cp = image->opaque; + png_control c; + + /* Double check that we have a png_ptr - it should be impossible to get here + * without one. + */ + if (cp->png_ptr == NULL) + return 0; + + /* First free any data held in the control structure. */ +# ifdef PNG_STDIO_SUPPORTED + if (cp->owned_file != 0) + { + FILE *fp = png_voidcast(FILE*, cp->png_ptr->io_ptr); + cp->owned_file = 0; + + /* Ignore errors here. */ + if (fp != NULL) + { + cp->png_ptr->io_ptr = NULL; + (void)fclose(fp); + } + } +# endif + + /* Copy the control structure so that the original, allocated, version can be + * safely freed. Notice that a png_error here stops the remainder of the + * cleanup, but this is probably fine because that would indicate bad memory + * problems anyway. + */ + c = *cp; + image->opaque = &c; + png_free(c.png_ptr, cp); + + /* Then the structures, calling the correct API. */ + if (c.for_write != 0) + { +# ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED + png_destroy_write_struct(&c.png_ptr, &c.info_ptr); +# else + png_error(c.png_ptr, "simplified write not supported"); +# endif + } + else + { +# ifdef PNG_SIMPLIFIED_READ_SUPPORTED + png_destroy_read_struct(&c.png_ptr, &c.info_ptr, NULL); +# else + png_error(c.png_ptr, "simplified read not supported"); +# endif + } + + /* Success. */ + return 1; +} + +void PNGAPI +png_image_free(png_imagep image) +{ + /* Safely call the real function, but only if doing so is safe at this point + * (if not inside an error handling context). Otherwise assume + * png_safe_execute will call this API after the return. + */ + if (image != NULL && image->opaque != NULL && + image->opaque->error_buf == NULL) + { + /* Ignore errors here: */ + (void)png_safe_execute(image, png_image_free_function, image); + image->opaque = NULL; + } +} + +int /* PRIVATE */ +png_image_error(png_imagep image, png_const_charp error_message) +{ + /* Utility to log an error. */ + png_safecat(image->message, (sizeof image->message), 0, error_message); + image->warning_or_error |= PNG_IMAGE_ERROR; + png_image_free(image); + return 0; +} + +#endif /* SIMPLIFIED READ/WRITE */ +#endif /* READ || WRITE */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/png.h b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/png.h index 354e35a73f0..de99418e773 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/png.h +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/png.h @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * libpng version 1.5.4 - July 7, 2011 - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * libpng version 1.6.16, December 22, 2014 + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -39,7 +39,7 @@ * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.5.4 - July 7, 2011: Glenn + * libpng versions 0.97, January 1998, through 1.6.16, December 22, 2014: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -185,6 +185,61 @@ * 1.5.4beta01-08 15 10504 15.so.15.4[.0] * 1.5.4rc01 15 10504 15.so.15.4[.0] * 1.5.4 15 10504 15.so.15.4[.0] + * 1.5.5beta01-08 15 10505 15.so.15.5[.0] + * 1.5.5rc01 15 10505 15.so.15.5[.0] + * 1.5.5 15 10505 15.so.15.5[.0] + * 1.5.6beta01-07 15 10506 15.so.15.6[.0] + * 1.5.6rc01-03 15 10506 15.so.15.6[.0] + * 1.5.6 15 10506 15.so.15.6[.0] + * 1.5.7beta01-05 15 10507 15.so.15.7[.0] + * 1.5.7rc01-03 15 10507 15.so.15.7[.0] + * 1.5.7 15 10507 15.so.15.7[.0] + * 1.6.0beta01-40 16 10600 16.so.16.0[.0] + * 1.6.0rc01-08 16 10600 16.so.16.0[.0] + * 1.6.0 16 10600 16.so.16.0[.0] + * 1.6.1beta01-09 16 10601 16.so.16.1[.0] + * 1.6.1rc01 16 10601 16.so.16.1[.0] + * 1.6.1 16 10601 16.so.16.1[.0] + * 1.6.2beta01 16 10602 16.so.16.2[.0] + * 1.6.2rc01-06 16 10602 16.so.16.2[.0] + * 1.6.2 16 10602 16.so.16.2[.0] + * 1.6.3beta01-11 16 10603 16.so.16.3[.0] + * 1.6.3rc01 16 10603 16.so.16.3[.0] + * 1.6.3 16 10603 16.so.16.3[.0] + * 1.6.4beta01-02 16 10604 16.so.16.4[.0] + * 1.6.4rc01 16 10604 16.so.16.4[.0] + * 1.6.4 16 10604 16.so.16.4[.0] + * 1.6.5 16 10605 16.so.16.5[.0] + * 1.6.6 16 10606 16.so.16.6[.0] + * 1.6.7beta01-04 16 10607 16.so.16.7[.0] + * 1.6.7rc01-03 16 10607 16.so.16.7[.0] + * 1.6.7 16 10607 16.so.16.7[.0] + * 1.6.8beta01-02 16 10608 16.so.16.8[.0] + * 1.6.8rc01-02 16 10608 16.so.16.8[.0] + * 1.6.8 16 10608 16.so.16.8[.0] + * 1.6.9beta01-04 16 10609 16.so.16.9[.0] + * 1.6.9rc01-02 16 10609 16.so.16.9[.0] + * 1.6.9 16 10609 16.so.16.9[.0] + * 1.6.10beta01-03 16 10610 16.so.16.10[.0] + * 1.6.10rc01-03 16 10610 16.so.16.10[.0] + * 1.6.10 16 10610 16.so.16.10[.0] + * 1.6.11beta01-06 16 10611 16.so.16.11[.0] + * 1.6.11rc01-02 16 10611 16.so.16.11[.0] + * 1.6.11 16 10611 16.so.16.11[.0] + * 1.6.12rc01-03 16 10612 16.so.16.12[.0] + * 1.6.12 16 10612 16.so.16.12[.0] + * 1.6.13beta01-04 16 10613 16.so.16.13[.0] + * 1.6.13rc01-02 16 10613 16.so.16.13[.0] + * 1.6.13 16 10613 16.so.16.13[.0] + * 1.6.14beta01-07 16 10614 16.so.16.14[.0] + * 1.6.14rc01-02 16 10614 16.so.16.14[.0] + * 1.6.14 16 10614 16.so.16.14[.0] + * 1.6.15beta01-08 16 10615 16.so.16.15[.0] + * 1.6.15rc01-03 16 10615 16.so.16.15[.0] + * 1.6.15 16 10615 16.so.16.15[.0] + * 1.6.16beta01-03 16 10616 16.so.16.16[.0] + * 1.6.16rc01-02 16 10616 16.so.16.16[.0] + * 1.6.16 16 10616 16.so.16.16[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be @@ -194,7 +249,7 @@ * to the source version x.y.z (leading zeros in y and z). Beta versions * were given the previous public release number plus a letter, until * version 1.0.6j; from then on they were given the upcoming public - * release number plus "betaNN" or "rcN". + * release number plus "betaNN" or "rcNN". * * Binary incompatibility exists only when applications make direct access * to the info_ptr or png_ptr members through png.h, and the compiled @@ -216,8 +271,8 @@ * * This code is released under the libpng license. * - * libpng versions 1.2.6, August 15, 2004, through 1.5.4, July 7, 2011, are - * Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are + * libpng versions 1.2.6, August 15, 2004, through 1.6.16, December 22, 2014, are + * Copyright (c) 2004, 2006-2014 Glenn Randers-Pehrson, and are * distributed according to the same disclaimer and license as libpng-1.2.5 * with the following individual added to the list of Contributing Authors: * @@ -328,28 +383,30 @@ * Y2K compliance in libpng: * ========================= * - * July 7, 2011 + * December 22, 2014 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. * * This is your unofficial assurance that libpng from version 0.71 and - * upward through 1.5.4 are Y2K compliant. It is my belief that + * upward through 1.6.16 are Y2K compliant. It is my belief that * earlier versions were also Y2K compliant. * * Libpng only has two year fields. One is a 2-byte unsigned integer - * that will hold years up to 65535. The other holds the date in text - * format, and will hold years up to 9999. + * that will hold years up to 65535. The other, which is deprecated, + * holds the date in text format, and will hold years up to 9999. * * The integer is * "png_uint_16 year" in png_time_struct. * * The string is - * "png_char time_buffer" in png_struct + * "char time_buffer[29]" in png_struct. This is no longer used + * in libpng-1.6.x and will be removed from libpng-1.7.0. * * There are seven time-related functions: - * png.c: png_convert_to_rfc_1123() in png.c - * (formerly png_convert_to_rfc_1152() in error) + * png.c: png_convert_to_rfc_1123_buffer() in png.c + * (formerly png_convert_to_rfc_1123() prior to libpng-1.5.x and + * png_convert_to_rfc_1152() in error prior to libpng-0.98) * png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c * png_convert_from_time_t() in pngwrite.c * png_get_tIME() in pngget.c @@ -360,8 +417,8 @@ * All handle dates properly in a Y2K environment. The * png_convert_from_time_t() function calls gmtime() to convert from system * clock time, which returns (year - 1900), which we properly convert to - * the full 4-digit year. There is a possibility that applications using - * libpng are not passing 4-digit years into the png_convert_to_rfc_1123() + * the full 4-digit year. There is a possibility that libpng applications + * are not passing 4-digit years into the png_convert_to_rfc_1123_buffer() * function, or that they are incorrectly passing only a 2-digit year * instead of "year - 1900" into the png_convert_from_struct_tm() function, * but this is not under our control. The libpng documentation has always @@ -385,21 +442,27 @@ /* This is not the place to learn how to use libpng. The file libpng-manual.txt * describes how to use libpng, and the file example.c summarizes it * with some code on which to build. This file is useful for looking - * at the actual function definitions and structure components. + * at the actual function definitions and structure components. If that + * file has been stripped from your copy of libpng, you can find it at + * + * + * If you just need to read a PNG file and don't want to read the documentation + * skip to the end of this file and read the section entitled 'simplified API'. */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.5.4" +#define PNG_LIBPNG_VER_STRING "1.6.16" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.5.4 - July 7, 2011\n" + " libpng version 1.6.16 - December 22, 2014\n" -#define PNG_LIBPNG_VER_SONUM 15 -#define PNG_LIBPNG_VER_DLLNUM 15 +#define PNG_LIBPNG_VER_SONUM 16 +#define PNG_LIBPNG_VER_DLLNUM 16 /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ #define PNG_LIBPNG_VER_MAJOR 1 -#define PNG_LIBPNG_VER_MINOR 5 -#define PNG_LIBPNG_VER_RELEASE 4 +#define PNG_LIBPNG_VER_MINOR 6 +#define PNG_LIBPNG_VER_RELEASE 16 + /* This should match the numeric part of the final component of * PNG_LIBPNG_VER_STRING, omitting any leading zero: */ @@ -421,7 +484,7 @@ #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with PNG_LIBPNG_BUILD_PRIVATE */ -#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_BETA +#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE /* Careful here. At one time, Guy wanted to use 082, but that would be octal. * We must not include leading zeros. @@ -429,7 +492,7 @@ * version 1.0.0 was mis-numbered 100 instead of 10000). From * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ -#define PNG_LIBPNG_VER 10504 /* 1.5.4 */ +#define PNG_LIBPNG_VER 10616 /* 1.6.16 */ /* Library configuration: these options cannot be changed after * the library has been built. @@ -442,25 +505,7 @@ #endif #ifndef PNG_VERSION_INFO_ONLY -# ifndef PNG_BUILDING_SYMBOL_TABLE - /* - * Standard header files (not needed for the version info or while - * building symbol table -- see scripts/pnglibconf.dfa) - */ -# ifdef PNG_SETJMP_SUPPORTED -# include -# endif - - /* Need the time information for converting tIME chunks, it - * defines struct tm: - */ -# ifdef PNG_CONVERT_tIME_SUPPORTED - /* "time.h" functions are not supported on all operating systems */ -# include -# endif -# endif - -/* Machine specific configuration. */ + /* Machine specific configuration. */ # include "pngconf.h" #endif @@ -509,6 +554,7 @@ extern "C" { * 2. Type definitions (base types are defined in pngconf.h), structure * definitions. * 3. Exported library functions. + * 4. Simplified API. * * The library source code has additional files (principally pngpriv.h) that * allow configuration of the library. @@ -551,7 +597,48 @@ extern "C" { /* This triggers a compiler error in png.c, if png.c and png.h * do not agree upon the version number. */ -typedef char* png_libpng_version_1_5_4; +typedef char* png_libpng_version_1_6_16; + +/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info. + * + * png_struct is the cache of information used while reading or writing a single + * PNG file. One of these is always required, although the simplified API + * (below) hides the creation and destruction of it. + */ +typedef struct png_struct_def png_struct; +typedef const png_struct * png_const_structp; +typedef png_struct * png_structp; +typedef png_struct * * png_structpp; + +/* png_info contains information read from or to be written to a PNG file. One + * or more of these must exist while reading or creating a PNG file. The + * information is not used by libpng during read but is used to control what + * gets written when a PNG file is created. "png_get_" function calls read + * information during read and "png_set_" functions calls write information + * when creating a PNG. + * been moved into a separate header file that is not accessible to + * applications. Read libpng-manual.txt or libpng.3 for more info. + */ +typedef struct png_info_def png_info; +typedef png_info * png_infop; +typedef const png_info * png_const_infop; +typedef png_info * * png_infopp; + +/* Types with names ending 'p' are pointer types. The corresponding types with + * names ending 'rp' are identical pointer types except that the pointer is + * marked 'restrict', which means that it is the only pointer to the object + * passed to the function. Applications should not use the 'restrict' types; + * it is always valid to pass 'p' to a pointer with a function argument of the + * corresponding 'rp' type. Different compilers have different rules with + * regard to type matching in the presence of 'restrict'. For backward + * compatibility libpng callbacks never have 'restrict' in their parameters and, + * consequentially, writing portable application code is extremely difficult if + * an attempt is made to use 'restrict'. + */ +typedef png_struct * PNG_RESTRICT png_structrp; +typedef const png_struct * PNG_RESTRICT png_const_structrp; +typedef png_info * PNG_RESTRICT png_inforp; +typedef const png_info * PNG_RESTRICT png_const_inforp; /* Three color definitions. The order of the red, green, and blue, (and the * exact size) is not important, although the size of the fields need to @@ -563,9 +650,9 @@ typedef struct png_color_struct png_byte green; png_byte blue; } png_color; -typedef png_color FAR * png_colorp; -typedef PNG_CONST png_color FAR * png_const_colorp; -typedef png_color FAR * FAR * png_colorpp; +typedef png_color * png_colorp; +typedef const png_color * png_const_colorp; +typedef png_color * * png_colorpp; typedef struct png_color_16_struct { @@ -575,9 +662,9 @@ typedef struct png_color_16_struct png_uint_16 blue; png_uint_16 gray; /* for use in grayscale files */ } png_color_16; -typedef png_color_16 FAR * png_color_16p; -typedef PNG_CONST png_color_16 FAR * png_const_color_16p; -typedef png_color_16 FAR * FAR * png_color_16pp; +typedef png_color_16 * png_color_16p; +typedef const png_color_16 * png_const_color_16p; +typedef png_color_16 * * png_color_16pp; typedef struct png_color_8_struct { @@ -587,9 +674,9 @@ typedef struct png_color_8_struct png_byte gray; /* for use in grayscale files */ png_byte alpha; /* for alpha channel files */ } png_color_8; -typedef png_color_8 FAR * png_color_8p; -typedef PNG_CONST png_color_8 FAR * png_const_color_8p; -typedef png_color_8 FAR * FAR * png_color_8pp; +typedef png_color_8 * png_color_8p; +typedef const png_color_8 * png_const_color_8p; +typedef png_color_8 * * png_color_8pp; /* * The following two structures are used for the in-core representation @@ -603,9 +690,9 @@ typedef struct png_sPLT_entry_struct png_uint_16 alpha; png_uint_16 frequency; } png_sPLT_entry; -typedef png_sPLT_entry FAR * png_sPLT_entryp; -typedef PNG_CONST png_sPLT_entry FAR * png_const_sPLT_entryp; -typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp; +typedef png_sPLT_entry * png_sPLT_entryp; +typedef const png_sPLT_entry * png_const_sPLT_entryp; +typedef png_sPLT_entry * * png_sPLT_entrypp; /* When the depth of the sPLT palette is 8 bits, the color and alpha samples * occupy the LSB of their respective members, and the MSB of each member @@ -619,18 +706,27 @@ typedef struct png_sPLT_struct png_sPLT_entryp entries; /* palette entries */ png_int_32 nentries; /* number of palette entries */ } png_sPLT_t; -typedef png_sPLT_t FAR * png_sPLT_tp; -typedef PNG_CONST png_sPLT_t FAR * png_const_sPLT_tp; -typedef png_sPLT_t FAR * FAR * png_sPLT_tpp; +typedef png_sPLT_t * png_sPLT_tp; +typedef const png_sPLT_t * png_const_sPLT_tp; +typedef png_sPLT_t * * png_sPLT_tpp; #ifdef PNG_TEXT_SUPPORTED /* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file, * and whether that contents is compressed or not. The "key" field - * points to a regular zero-terminated C string. The "text", "lang", and - * "lang_key" fields can be regular C strings, empty strings, or NULL pointers. + * points to a regular zero-terminated C string. The "text" fields can be a + * regular C string, an empty string, or a NULL pointer. * However, the structure returned by png_get_text() will always contain - * regular zero-terminated C strings (possibly empty), never NULL pointers, - * so they can be safely used in printf() and other string-handling functions. + * the "text" field as a regular zero-terminated C string (possibly + * empty), never a NULL pointer, so it can be safely used in printf() and + * other string-handling functions. Note that the "itxt_length", "lang", and + * "lang_key" members of the structure only exist when the library is built + * with iTXt chunk support. Prior to libpng-1.4.0 the library was built by + * default without iTXt support. Also note that when iTXt *is* supported, + * the "lang" and "lang_key" fields contain NULL pointers when the + * "compression" field contains * PNG_TEXT_COMPRESSION_NONE or + * PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the + * same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag" + * which is always 0 or 1, or its "compression method" which is always 0. */ typedef struct png_text_struct { @@ -649,9 +745,9 @@ typedef struct png_text_struct png_charp lang_key; /* keyword translated UTF-8 string, 0 or more chars or a NULL pointer */ } png_text; -typedef png_text FAR * png_textp; -typedef PNG_CONST png_text FAR * png_const_textp; -typedef png_text FAR * FAR * png_textpp; +typedef png_text * png_textp; +typedef const png_text * png_const_textp; +typedef png_text * * png_textpp; #endif /* Supported compression types for text in PNG files (tEXt, and zTXt). @@ -679,49 +775,45 @@ typedef struct png_time_struct png_byte minute; /* minute of hour, 0 - 59 */ png_byte second; /* second of minute, 0 - 60 (for leap seconds) */ } png_time; -typedef png_time FAR * png_timep; -typedef PNG_CONST png_time FAR * png_const_timep; -typedef png_time FAR * FAR * png_timepp; +typedef png_time * png_timep; +typedef const png_time * png_const_timep; +typedef png_time * * png_timepp; -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \ - defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) +#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) ||\ + defined(PNG_USER_CHUNKS_SUPPORTED) /* png_unknown_chunk is a structure to hold queued chunks for which there is * no specific support. The idea is that we can use this to queue * up private chunks for output even though the library doesn't actually * know about their semantics. + * + * The data in the structure is set by libpng on read and used on write. */ typedef struct png_unknown_chunk_t { - png_byte name[5]; - png_byte *data; + png_byte name[5]; /* Textual chunk name with '\0' terminator */ + png_byte *data; /* Data, should not be modified on read! */ png_size_t size; - /* libpng-using applications should NOT directly modify this byte. */ + /* On write 'location' must be set using the flag values listed below. + * Notice that on read it is set by libpng however the values stored have + * more bits set than are listed below. Always treat the value as a + * bitmask. On write set only one bit - setting multiple bits may cause the + * chunk to be written in multiple places. + */ png_byte location; /* mode of operation at read time */ } - - png_unknown_chunk; -typedef png_unknown_chunk FAR * png_unknown_chunkp; -typedef PNG_CONST png_unknown_chunk FAR * png_const_unknown_chunkp; -typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp; + +typedef png_unknown_chunk * png_unknown_chunkp; +typedef const png_unknown_chunk * png_const_unknown_chunkp; +typedef png_unknown_chunk * * png_unknown_chunkpp; #endif -/* Values for the unknown chunk location byte */ - +/* Flag values for the unknown chunk location byte. */ #define PNG_HAVE_IHDR 0x01 #define PNG_HAVE_PLTE 0x02 #define PNG_AFTER_IDAT 0x08 -/* The complete definition of png_info has, as of libpng-1.5.0, - * been moved into a separate header file that is not accessible to - * applications. Read libpng-manual.txt or libpng.3 for more info. - */ -typedef struct png_info_def png_info; -typedef png_info FAR * png_infop; -typedef PNG_CONST png_info FAR * png_const_infop; -typedef png_info FAR * FAR * png_infopp; - /* Maximum positive integer used in PNG is (2^31)-1 */ #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) #define PNG_UINT_32_MAX ((png_uint_32)(-1)) @@ -821,7 +913,7 @@ typedef png_info FAR * FAR * png_infopp; #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */ #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */ #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */ -#define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */ +#define PNG_INFO_IDAT 0x8000 /* ESR, 1.0.6 */ /* This is used for the transformation routines, as some of them * change these values for the row. It also should enable using @@ -837,16 +929,8 @@ typedef struct png_row_info_struct png_byte pixel_depth; /* bits per pixel (depth * channels) */ } png_row_info; -typedef png_row_info FAR * png_row_infop; -typedef png_row_info FAR * FAR * png_row_infopp; - -/* The complete definition of png_struct has, as of libpng-1.5.0, - * been moved into a separate header file that is not accessible to - * applications. Read libpng-manual.txt or libpng.3 for more info. - */ -typedef struct png_struct_def png_struct; -typedef PNG_CONST png_struct FAR * png_const_structp; -typedef png_struct FAR * png_structp; +typedef png_row_info * png_row_infop; +typedef png_row_info * * png_row_infopp; /* These are the function types for the I/O functions and for the functions * that allow the user to override the default I/O functions with his or her @@ -893,7 +977,8 @@ typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp, png_unknown_chunkp)); #endif #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED -typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); +/* not used anywhere */ +/* typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); */ #endif #ifdef PNG_SETJMP_SUPPORTED @@ -949,8 +1034,6 @@ typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp, png_alloc_size_t)); typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp)); -typedef png_struct FAR * FAR * png_structpp; - /* Section 3: exported functions * Here are the function definitions most commonly used. This is not * the place to find out how to use libpng. See libpng-manual.txt for the @@ -986,7 +1069,7 @@ PNG_EXPORT(1, png_uint_32, png_access_version_number, (void)); /* Tell lib we have already handled the first magic bytes. * Handling more than 8 bytes from the beginning of the file is an error. */ -PNG_EXPORT(2, void, png_set_sig_bytes, (png_structp png_ptr, int num_bytes)); +PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes)); /* Check sig[start] through sig[start + num_to_check - 1] to see if it's a * PNG file. Returns zero if the supplied bytes match the 8-byte PNG @@ -1014,9 +1097,9 @@ PNG_EXPORTA(5, png_structp, png_create_write_struct, PNG_ALLOCATED); PNG_EXPORT(6, png_size_t, png_get_compression_buffer_size, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); -PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structp png_ptr, +PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structrp png_ptr, png_size_t size)); /* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp @@ -1030,10 +1113,10 @@ PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structp png_ptr, * allocated by the library - the call will return NULL on a mismatch * indicating an ABI mismatch. */ -PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structp png_ptr, +PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structrp png_ptr, png_longjmp_ptr longjmp_fn, size_t jmp_buf_size)); # define png_jmpbuf(png_ptr) \ - (*png_set_longjmp_fn((png_ptr), longjmp, sizeof (jmp_buf))) + (*png_set_longjmp_fn((png_ptr), longjmp, (sizeof (jmp_buf)))) #else # define png_jmpbuf(png_ptr) \ (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP) @@ -1043,12 +1126,12 @@ PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structp png_ptr, * will use it; otherwise it will call PNG_ABORT(). This function was * added in libpng-1.5.0. */ -PNG_EXPORTA(9, void, png_longjmp, (png_structp png_ptr, int val), +PNG_EXPORTA(9, void, png_longjmp, (png_const_structrp png_ptr, int val), PNG_NORETURN); #ifdef PNG_READ_SUPPORTED /* Reset the compression stream */ -PNG_EXPORT(10, int, png_reset_zstream, (png_structp png_ptr)); +PNG_EXPORTA(10, int, png_reset_zstream, (png_structrp png_ptr), PNG_DEPRECATED); #endif /* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ @@ -1066,91 +1149,107 @@ PNG_EXPORTA(12, png_structp, png_create_write_struct_2, #endif /* Write the PNG file signature. */ -PNG_EXPORT(13, void, png_write_sig, (png_structp png_ptr)); +PNG_EXPORT(13, void, png_write_sig, (png_structrp png_ptr)); /* Write a PNG chunk - size, type, (optional) data, CRC. */ -PNG_EXPORT(14, void, png_write_chunk, (png_structp png_ptr, png_const_bytep +PNG_EXPORT(14, void, png_write_chunk, (png_structrp png_ptr, png_const_bytep chunk_name, png_const_bytep data, png_size_t length)); /* Write the start of a PNG chunk - length and chunk name. */ -PNG_EXPORT(15, void, png_write_chunk_start, (png_structp png_ptr, +PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr, png_const_bytep chunk_name, png_uint_32 length)); /* Write the data of a PNG chunk started with png_write_chunk_start(). */ -PNG_EXPORT(16, void, png_write_chunk_data, (png_structp png_ptr, +PNG_EXPORT(16, void, png_write_chunk_data, (png_structrp png_ptr, png_const_bytep data, png_size_t length)); /* Finish a chunk started with png_write_chunk_start() (includes CRC). */ -PNG_EXPORT(17, void, png_write_chunk_end, (png_structp png_ptr)); +PNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr)); /* Allocate and initialize the info structure */ -PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_structp png_ptr), +PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structrp png_ptr), PNG_ALLOCATED); -PNG_EXPORT(19, void, png_info_init_3, (png_infopp info_ptr, - png_size_t png_info_struct_size)); +/* DEPRECATED: this function allowed init structures to be created using the + * default allocation method (typically malloc). Use is deprecated in 1.6.0 and + * the API will be removed in the future. + */ +PNG_EXPORTA(19, void, png_info_init_3, (png_infopp info_ptr, + png_size_t png_info_struct_size), PNG_DEPRECATED); /* Writes all the PNG information before the image. */ PNG_EXPORT(20, void, png_write_info_before_PLTE, - (png_structp png_ptr, png_infop info_ptr)); + (png_structrp png_ptr, png_const_inforp info_ptr)); PNG_EXPORT(21, void, png_write_info, - (png_structp png_ptr, png_infop info_ptr)); + (png_structrp png_ptr, png_const_inforp info_ptr)); #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the information before the actual image data. */ PNG_EXPORT(22, void, png_read_info, - (png_structp png_ptr, png_infop info_ptr)); + (png_structrp png_ptr, png_inforp info_ptr)); #endif #ifdef PNG_TIME_RFC1123_SUPPORTED -PNG_EXPORT(23, png_const_charp, png_convert_to_rfc1123, - (png_structp png_ptr, + /* Convert to a US string format: there is no localization support in this + * routine. The original implementation used a 29 character buffer in + * png_struct, this will be removed in future versions. + */ +#if PNG_LIBPNG_VER < 10700 +/* To do: remove this from libpng17 (and from libpng17/png.c and pngstruct.h) */ +PNG_EXPORTA(23, png_const_charp, png_convert_to_rfc1123, (png_structrp png_ptr, + png_const_timep ptime),PNG_DEPRECATED); +#endif +PNG_EXPORT(241, int, png_convert_to_rfc1123_buffer, (char out[29], png_const_timep ptime)); #endif #ifdef PNG_CONVERT_tIME_SUPPORTED /* Convert from a struct tm to png_time */ PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime, - PNG_CONST struct tm FAR * ttime)); + const struct tm * ttime)); /* Convert from time_t to png_time. Uses gmtime() */ -PNG_EXPORT(25, void, png_convert_from_time_t, - (png_timep ptime, time_t ttime)); -#endif /* PNG_CONVERT_tIME_SUPPORTED */ +PNG_EXPORT(25, void, png_convert_from_time_t, (png_timep ptime, time_t ttime)); +#endif /* CONVERT_tIME */ #ifdef PNG_READ_EXPAND_SUPPORTED /* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ -PNG_EXPORT(26, void, png_set_expand, (png_structp png_ptr)); -PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structp png_ptr)); -PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structp png_ptr)); -PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structp png_ptr)); +PNG_EXPORT(26, void, png_set_expand, (png_structrp png_ptr)); +PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structrp png_ptr)); +PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structrp png_ptr)); +PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structrp png_ptr)); #endif #ifdef PNG_READ_EXPAND_16_SUPPORTED /* Expand to 16-bit channels, forces conversion of palette to RGB and expansion * of a tRNS chunk if present. */ -PNG_EXPORT(221, void, png_set_expand_16, (png_structp png_ptr)); +PNG_EXPORT(221, void, png_set_expand_16, (png_structrp png_ptr)); #endif #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) /* Use blue, green, red order for pixels. */ -PNG_EXPORT(30, void, png_set_bgr, (png_structp png_ptr)); +PNG_EXPORT(30, void, png_set_bgr, (png_structrp png_ptr)); #endif #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED /* Expand the grayscale to 24-bit RGB if necessary. */ -PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structp png_ptr)); +PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structrp png_ptr)); #endif #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED /* Reduce RGB to grayscale. */ -PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structp png_ptr, - int error_action, double red, double green)); -PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structp png_ptr, - int error_action, png_fixed_point red, png_fixed_point green)); +#define PNG_ERROR_ACTION_NONE 1 +#define PNG_ERROR_ACTION_WARN 2 +#define PNG_ERROR_ACTION_ERROR 3 +#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/ -PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structp +PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structrp png_ptr, + int error_action, double red, double green)) +PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structrp png_ptr, + int error_action, png_fixed_point red, png_fixed_point green)) + +PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structrp png_ptr)); #endif @@ -1160,9 +1259,9 @@ PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth, #endif #ifdef PNG_READ_ALPHA_MODE_SUPPORTED -/* How the alpha channel is interpreted - this affects how the color channels of - * a PNG file are returned when an alpha channel, or tRNS chunk in a palette - * file, is present. +/* How the alpha channel is interpreted - this affects how the color channels + * of a PNG file are returned to the calling application when an alpha channel, + * or a tRNS chunk in a palette file, is present. * * This has no effect on the way pixels are written into a PNG output * datastream. The color samples in a PNG datastream are never premultiplied @@ -1170,33 +1269,19 @@ PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth, * * The default is to return data according to the PNG specification: the alpha * channel is a linear measure of the contribution of the pixel to the - * corresponding composited pixel. The gamma encoded color channels must be - * scaled according to the contribution and to do this it is necessary to undo + * corresponding composited pixel, and the color channels are unassociated + * (not premultiplied). The gamma encoded color channels must be scaled + * according to the contribution and to do this it is necessary to undo * the encoding, scale the color values, perform the composition and reencode * the values. This is the 'PNG' mode. * * The alternative is to 'associate' the alpha with the color information by - * storing color channel values that have been scaled by the alpha. The - * advantage is that the color channels can be resampled (the image can be - * scaled) in this form. The disadvantage is that normal practice is to store - * linear, not (gamma) encoded, values and this requires 16-bit channels for - * still images rather than the 8-bit channels that are just about sufficient if - * gamma encoding is used. In addition all non-transparent pixel values, - * including completely opaque ones, must be gamma encoded to produce the final - * image. This is the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' mode (the - * latter being the two common names for associated alpha color channels.) + * storing color channel values that have been scaled by the alpha. + * image. These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes + * (the latter being the two common names for associated alpha color channels). * - * Since it is not necessary to perform arithmetic on opaque color values so - * long as they are not to be resampled and are in the final color space it is - * possible to optimize the handling of alpha by storing the opaque pixels in - * the PNG format (adjusted for the output color space) while storing partially - * opaque pixels in the standard, linear, format. The accuracy required for - * standard alpha composition is relatively low, because the pixels are - * isolated, therefore typically the accuracy loss in storing 8-bit linear - * values is acceptable. (This is not true if the alpha channel is used to - * simulate transparency over large areas - use 16 bits or the PNG mode in - * this case!) This is the 'OPTIMIZED' mode. For this mode a pixel is - * treated as opaque only if the alpha value is equal to the maximum value. + * For the 'OPTIMIZED' mode, a pixel is treated as opaque only if the alpha + * value is equal to the maximum value. * * The final choice is to gamma encode the alpha channel as well. This is * broken because, in practice, no implementation that uses this choice @@ -1215,76 +1300,15 @@ PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth, #define PNG_ALPHA_OPTIMIZED 2 /* 'PNG' for opaque pixels, else 'STANDARD' */ #define PNG_ALPHA_BROKEN 3 /* the alpha channel is gamma encoded */ -PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structp png_ptr, int mode, - double output_gamma)); -PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structp png_ptr, - int mode, png_fixed_point output_gamma)); +PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structrp png_ptr, int mode, + double output_gamma)) +PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr, + int mode, png_fixed_point output_gamma)) #endif -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED) +#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED) /* The output_gamma value is a screen gamma in libpng terminology: it expresses - * how to decode the output values, not how they are encoded. The values used - * correspond to the normal numbers used to describe the overall gamma of a - * computer display system; for example 2.2 for an sRGB conformant system. The - * values are scaled by 100000 in the _fixed version of the API (so 220000 for - * sRGB.) - * - * The inverse of the value is always used to provide a default for the PNG file - * encoding if it has no gAMA chunk and if png_set_gamma() has not been called - * to override the PNG gamma information. - * - * When the ALPHA_OPTIMIZED mode is selected the output gamma is used to encode - * opaque pixels however pixels with lower alpha values are not encoded, - * regardless of the output gamma setting. - * - * When the standard Porter Duff handling is requested with mode 1 the output - * encoding is set to be linear and the output_gamma value is only relevant - * as a default for input data that has no gamma information. The linear output - * encoding will be overridden if png_set_gamma() is called - the results may be - * highly unexpected! - * - * The following numbers are derived from the sRGB standard and the research - * behind it. sRGB is defined to be approximated by a PNG gAMA chunk value of - * 0.45455 (1/2.2) for PNG. The value implicitly includes any viewing - * correction required to take account of any differences in the color - * environment of the original scene and the intended display environment; the - * value expresses how to *decode* the image for display, not how the original - * data was *encoded*. - * - * sRGB provides a peg for the PNG standard by defining a viewing environment. - * sRGB itself, and earlier TV standards, actually use a more complex transform - * (a linear portion then a gamma 2.4 power law) than PNG can express. (PNG is - * limited to simple power laws.) By saying that an image for direct display on - * an sRGB conformant system should be stored with a gAMA chunk value of 45455 - * (11.3.3.2 and 11.3.3.5 of the ISO PNG specification) the PNG specification - * makes it possible to derive values for other display systems and - * environments. - * - * The Mac value is deduced from the sRGB based on an assumption that the actual - * extra viewing correction used in early Mac display systems was implemented as - * a power 1.45 lookup table. - * - * Any system where a programmable lookup table is used or where the behavior of - * the final display device characteristics can be changed requires system - * specific code to obtain the current characteristic. However this can be - * difficult and most PNG gamma correction only requires an approximate value. - * - * By default, if png_set_alpha_mode() is not called, libpng assumes that all - * values are unencoded, linear, values and that the output device also has a - * linear characteristic. This is only very rarely correct - it is invariably - * better to call png_set_alpha_mode() with PNG_DEFAULT_sRGB than rely on the - * default if you don't know what the right answer is! - * - * The special value PNG_GAMMA_MAC_18 indicates an older Mac system (pre Mac OS - * 10.6) which used a correction table to implement a somewhat lower gamma on an - * otherwise sRGB system. - * - * Both these values are reserved (not simple gamma values) in order to allow - * more precise correction internally in the future. - * - * NOTE: the following values can be passed to either the fixed or floating - * point APIs, but the floating point API will also accept floating point - * values. + * how to decode the output values, not how they are encoded. */ #define PNG_DEFAULT_sRGB -1 /* sRGB gamma and color space */ #define PNG_GAMMA_MAC_18 -2 /* Old Mac '1.8' gamma and color space */ @@ -1351,7 +1375,7 @@ PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structp png_ptr, * * When the default gamma of PNG files doesn't match the output gamma. * If you have PNG files with no gamma information png_set_alpha_mode allows - * you to provide a default gamma, but it also sets the output gamma to the + * you to provide a default gamma, but it also sets the ouput gamma to the * matching value. If you know your PNG files have a gamma that doesn't * match the output you can take advantage of the fact that * png_set_alpha_mode always sets the output gamma but only sets the PNG @@ -1369,51 +1393,50 @@ PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structp png_ptr, */ #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED -PNG_EXPORT(36, void, png_set_strip_alpha, (png_structp png_ptr)); +PNG_EXPORT(36, void, png_set_strip_alpha, (png_structrp png_ptr)); #endif #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) -PNG_EXPORT(37, void, png_set_swap_alpha, (png_structp png_ptr)); +PNG_EXPORT(37, void, png_set_swap_alpha, (png_structrp png_ptr)); #endif #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) -PNG_EXPORT(38, void, png_set_invert_alpha, (png_structp png_ptr)); +PNG_EXPORT(38, void, png_set_invert_alpha, (png_structrp png_ptr)); #endif #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) /* Add a filler byte to 8-bit Gray or 24-bit RGB images. */ -PNG_EXPORT(39, void, png_set_filler, (png_structp png_ptr, png_uint_32 filler, +PNG_EXPORT(39, void, png_set_filler, (png_structrp png_ptr, png_uint_32 filler, int flags)); /* The values of the PNG_FILLER_ defines should NOT be changed */ # define PNG_FILLER_BEFORE 0 # define PNG_FILLER_AFTER 1 /* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */ -PNG_EXPORT(40, void, png_set_add_alpha, - (png_structp png_ptr, png_uint_32 filler, - int flags)); -#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */ +PNG_EXPORT(40, void, png_set_add_alpha, (png_structrp png_ptr, + png_uint_32 filler, int flags)); +#endif /* READ_FILLER || WRITE_FILLER */ #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) /* Swap bytes in 16-bit depth files. */ -PNG_EXPORT(41, void, png_set_swap, (png_structp png_ptr)); +PNG_EXPORT(41, void, png_set_swap, (png_structrp png_ptr)); #endif #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) /* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */ -PNG_EXPORT(42, void, png_set_packing, (png_structp png_ptr)); +PNG_EXPORT(42, void, png_set_packing, (png_structrp png_ptr)); #endif #if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ defined(PNG_WRITE_PACKSWAP_SUPPORTED) /* Swap packing order of pixels in bytes. */ -PNG_EXPORT(43, void, png_set_packswap, (png_structp png_ptr)); +PNG_EXPORT(43, void, png_set_packswap, (png_structrp png_ptr)); #endif #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) /* Converts files to legal bit depths. */ -PNG_EXPORT(44, void, png_set_shift, (png_structp png_ptr, png_const_color_8p +PNG_EXPORT(44, void, png_set_shift, (png_structrp png_ptr, png_const_color_8p true_bits)); #endif @@ -1425,12 +1448,12 @@ PNG_EXPORT(44, void, png_set_shift, (png_structp png_ptr, png_const_color_8p * necessary to call png_read_row or png_read_rows png_get_image_height * times for each pass. */ -PNG_EXPORT(45, int, png_set_interlace_handling, (png_structp png_ptr)); +PNG_EXPORT(45, int, png_set_interlace_handling, (png_structrp png_ptr)); #endif #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) /* Invert monochrome files */ -PNG_EXPORT(46, void, png_set_invert_mono, (png_structp png_ptr)); +PNG_EXPORT(46, void, png_set_invert_mono, (png_structrp png_ptr)); #endif #ifdef PNG_READ_BACKGROUND_SUPPORTED @@ -1439,12 +1462,12 @@ PNG_EXPORT(46, void, png_set_invert_mono, (png_structp png_ptr)); * read. Doing so will result in unexpected behavior and possible warnings or * errors if the PNG file contains a bKGD chunk. */ -PNG_FP_EXPORT(47, void, png_set_background, (png_structp png_ptr, +PNG_FP_EXPORT(47, void, png_set_background, (png_structrp png_ptr, png_const_color_16p background_color, int background_gamma_code, - int need_expand, double background_gamma)); -PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structp png_ptr, + int need_expand, double background_gamma)) +PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structrp png_ptr, png_const_color_16p background_color, int background_gamma_code, - int need_expand, png_fixed_point background_gamma)); + int need_expand, png_fixed_point background_gamma)) #endif #ifdef PNG_READ_BACKGROUND_SUPPORTED # define PNG_BACKGROUND_GAMMA_UNKNOWN 0 @@ -1455,23 +1478,22 @@ PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structp png_ptr, #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED /* Scale a 16-bit depth file down to 8-bit, accurately. */ -PNG_EXPORT(229, void, png_set_scale_16, (png_structp png_ptr)); +PNG_EXPORT(229, void, png_set_scale_16, (png_structrp png_ptr)); #endif #ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED #define PNG_READ_16_TO_8 SUPPORTED /* Name prior to 1.5.4 */ /* Strip the second byte of information from a 16-bit depth file. */ -PNG_EXPORT(48, void, png_set_strip_16, (png_structp png_ptr)); +PNG_EXPORT(48, void, png_set_strip_16, (png_structrp png_ptr)); #endif #ifdef PNG_READ_QUANTIZE_SUPPORTED /* Turn on quantizing, and reduce the palette to the number of colors * available. */ -PNG_EXPORT(49, void, png_set_quantize, - (png_structp png_ptr, png_colorp palette, - int num_palette, int maximum_colors, png_const_uint_16p histogram, - int full_quantize)); +PNG_EXPORT(49, void, png_set_quantize, (png_structrp png_ptr, + png_colorp palette, int num_palette, int maximum_colors, + png_const_uint_16p histogram, int full_quantize)); #endif #ifdef PNG_READ_GAMMA_SUPPORTED @@ -1491,71 +1513,69 @@ PNG_EXPORT(49, void, png_set_quantize, * API (floating point or fixed.) Notice, however, that the 'file_gamma' value * is the inverse of a 'screen gamma' value. */ -PNG_FP_EXPORT(50, void, png_set_gamma, - (png_structp png_ptr, double screen_gamma, - double override_file_gamma)); -PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structp png_ptr, - png_fixed_point screen_gamma, png_fixed_point override_file_gamma)); +PNG_FP_EXPORT(50, void, png_set_gamma, (png_structrp png_ptr, + double screen_gamma, double override_file_gamma)) +PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structrp png_ptr, + png_fixed_point screen_gamma, png_fixed_point override_file_gamma)) #endif #ifdef PNG_WRITE_FLUSH_SUPPORTED /* Set how many lines between output flushes - 0 for no flushing */ -PNG_EXPORT(51, void, png_set_flush, (png_structp png_ptr, int nrows)); +PNG_EXPORT(51, void, png_set_flush, (png_structrp png_ptr, int nrows)); /* Flush the current PNG output buffer */ -PNG_EXPORT(52, void, png_write_flush, (png_structp png_ptr)); +PNG_EXPORT(52, void, png_write_flush, (png_structrp png_ptr)); #endif /* Optional update palette with requested transformations */ -PNG_EXPORT(53, void, png_start_read_image, (png_structp png_ptr)); +PNG_EXPORT(53, void, png_start_read_image, (png_structrp png_ptr)); /* Optional call to update the users info structure */ -PNG_EXPORT(54, void, png_read_update_info, - (png_structp png_ptr, png_infop info_ptr)); +PNG_EXPORT(54, void, png_read_update_info, (png_structrp png_ptr, + png_inforp info_ptr)); #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read one or more rows of image data. */ -PNG_EXPORT(55, void, png_read_rows, (png_structp png_ptr, png_bytepp row, +PNG_EXPORT(55, void, png_read_rows, (png_structrp png_ptr, png_bytepp row, png_bytepp display_row, png_uint_32 num_rows)); #endif #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read a row of data. */ -PNG_EXPORT(56, void, png_read_row, (png_structp png_ptr, png_bytep row, +PNG_EXPORT(56, void, png_read_row, (png_structrp png_ptr, png_bytep row, png_bytep display_row)); #endif #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the whole image into memory at once. */ -PNG_EXPORT(57, void, png_read_image, (png_structp png_ptr, png_bytepp image)); +PNG_EXPORT(57, void, png_read_image, (png_structrp png_ptr, png_bytepp image)); #endif /* Write a row of image data */ -PNG_EXPORT(58, void, png_write_row, - (png_structp png_ptr, png_const_bytep row)); +PNG_EXPORT(58, void, png_write_row, (png_structrp png_ptr, + png_const_bytep row)); /* Write a few rows of image data: (*row) is not written; however, the type * is declared as writeable to maintain compatibility with previous versions * of libpng and to allow the 'display_row' array from read_rows to be passed * unchanged to write_rows. */ -PNG_EXPORT(59, void, png_write_rows, (png_structp png_ptr, png_bytepp row, +PNG_EXPORT(59, void, png_write_rows, (png_structrp png_ptr, png_bytepp row, png_uint_32 num_rows)); /* Write the image data */ -PNG_EXPORT(60, void, png_write_image, - (png_structp png_ptr, png_bytepp image)); +PNG_EXPORT(60, void, png_write_image, (png_structrp png_ptr, png_bytepp image)); /* Write the end of the PNG file. */ -PNG_EXPORT(61, void, png_write_end, - (png_structp png_ptr, png_infop info_ptr)); +PNG_EXPORT(61, void, png_write_end, (png_structrp png_ptr, + png_inforp info_ptr)); #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the end of the PNG file. */ -PNG_EXPORT(62, void, png_read_end, (png_structp png_ptr, png_infop info_ptr)); +PNG_EXPORT(62, void, png_read_end, (png_structrp png_ptr, png_inforp info_ptr)); #endif /* Free any memory associated with the png_info_struct */ -PNG_EXPORT(63, void, png_destroy_info_struct, (png_structp png_ptr, +PNG_EXPORT(63, void, png_destroy_info_struct, (png_const_structrp png_ptr, png_infopp info_ptr_ptr)); /* Free any memory associated with the png_struct and the png_info_structs */ @@ -1567,8 +1587,8 @@ PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)); /* Set the libpng method of handling chunk CRC errors */ -PNG_EXPORT(66, void, png_set_crc_action, - (png_structp png_ptr, int crit_action, int ancil_action)); +PNG_EXPORT(66, void, png_set_crc_action, (png_structrp png_ptr, int crit_action, + int ancil_action)); /* Values for png_set_crc_action() say how to handle CRC errors in * ancillary and critical chunks, and whether to use the data contained @@ -1597,8 +1617,8 @@ PNG_EXPORT(66, void, png_set_crc_action, /* Set the filtering method(s) used by libpng. Currently, the only valid * value for "method" is 0. */ -PNG_EXPORT(67, void, png_set_filter, - (png_structp png_ptr, int method, int filters)); +PNG_EXPORT(67, void, png_set_filter, (png_structrp png_ptr, int method, + int filters)); /* Flags for png_set_filter() to say which filters to use. The flags * are chosen so that they don't conflict with real filter types @@ -1653,14 +1673,14 @@ PNG_EXPORT(67, void, png_set_filter, * the weights and costs are set to 1.0, this degenerates the WEIGHTED method * to the UNWEIGHTED method, but with added encoding time/computation. */ -PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structp png_ptr, +PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structrp png_ptr, int heuristic_method, int num_weights, png_const_doublep filter_weights, - png_const_doublep filter_costs)); + png_const_doublep filter_costs)) PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed, - (png_structp png_ptr, - int heuristic_method, int num_weights, png_const_fixed_point_p - filter_weights, png_const_fixed_point_p filter_costs)); -#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ + (png_structrp png_ptr, int heuristic_method, int num_weights, + png_const_fixed_point_p filter_weights, + png_const_fixed_point_p filter_costs)) +#endif /* WRITE_WEIGHTED_FILTER */ /* Heuristic used for row filter selection. These defines should NOT be * changed. @@ -1678,45 +1698,45 @@ PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed, * for PNG images, and do considerably fewer caclulations. In the future, * these values may not correspond directly to the zlib compression levels. */ -PNG_EXPORT(69, void, png_set_compression_level, - (png_structp png_ptr, int level)); +PNG_EXPORT(69, void, png_set_compression_level, (png_structrp png_ptr, + int level)); -PNG_EXPORT(70, void, png_set_compression_mem_level, (png_structp png_ptr, +PNG_EXPORT(70, void, png_set_compression_mem_level, (png_structrp png_ptr, int mem_level)); -PNG_EXPORT(71, void, png_set_compression_strategy, (png_structp png_ptr, +PNG_EXPORT(71, void, png_set_compression_strategy, (png_structrp png_ptr, int strategy)); /* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a * smaller value of window_bits if it can do so safely. */ -PNG_EXPORT(72, void, png_set_compression_window_bits, (png_structp png_ptr, +PNG_EXPORT(72, void, png_set_compression_window_bits, (png_structrp png_ptr, int window_bits)); -PNG_EXPORT(73, void, png_set_compression_method, (png_structp png_ptr, +PNG_EXPORT(73, void, png_set_compression_method, (png_structrp png_ptr, int method)); #endif #ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED /* Also set zlib parameters for compressing non-IDAT chunks */ -PNG_EXPORT(222, void, png_set_text_compression_level, - (png_structp png_ptr, int level)); +PNG_EXPORT(222, void, png_set_text_compression_level, (png_structrp png_ptr, + int level)); -PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structp png_ptr, +PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structrp png_ptr, int mem_level)); -PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structp png_ptr, +PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structrp png_ptr, int strategy)); /* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a * smaller value of window_bits if it can do so safely. */ -PNG_EXPORT(225, void, png_set_text_compression_window_bits, (png_structp - png_ptr, int window_bits)); +PNG_EXPORT(225, void, png_set_text_compression_window_bits, + (png_structrp png_ptr, int window_bits)); -PNG_EXPORT(226, void, png_set_text_compression_method, (png_structp png_ptr, +PNG_EXPORT(226, void, png_set_text_compression_method, (png_structrp png_ptr, int method)); -#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ +#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */ /* These next functions are called for input/output, memory, and error * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c, @@ -1729,7 +1749,7 @@ PNG_EXPORT(226, void, png_set_text_compression_method, (png_structp png_ptr, #ifdef PNG_STDIO_SUPPORTED /* Initialize the input/output for the PNG file to the default functions. */ -PNG_EXPORT(74, void, png_init_io, (png_structp png_ptr, png_FILE_p fp)); +PNG_EXPORT(74, void, png_init_io, (png_structrp png_ptr, png_FILE_p fp)); #endif /* Replace the (error and abort), and warning functions with user @@ -1740,12 +1760,11 @@ PNG_EXPORT(74, void, png_init_io, (png_structp png_ptr, png_FILE_p fp)); * default function will be used. */ -PNG_EXPORT(75, void, png_set_error_fn, - (png_structp png_ptr, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warning_fn)); +PNG_EXPORT(75, void, png_set_error_fn, (png_structrp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn)); /* Return the user pointer associated with the error functions */ -PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structp png_ptr)); +PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structrp png_ptr)); /* Replace the default data output functions with a user supplied one(s). * If buffered output is not used, then output_flush_fn can be set to NULL. @@ -1757,47 +1776,47 @@ PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structp png_ptr)); * default flush function, which uses the standard *FILE structure, will * be used. */ -PNG_EXPORT(77, void, png_set_write_fn, (png_structp png_ptr, png_voidp io_ptr, +PNG_EXPORT(77, void, png_set_write_fn, (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)); /* Replace the default data input function with a user supplied one. */ -PNG_EXPORT(78, void, png_set_read_fn, (png_structp png_ptr, png_voidp io_ptr, +PNG_EXPORT(78, void, png_set_read_fn, (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn)); /* Return the user pointer associated with the I/O functions */ -PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_structp png_ptr)); +PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_const_structrp png_ptr)); -PNG_EXPORT(80, void, png_set_read_status_fn, (png_structp png_ptr, +PNG_EXPORT(80, void, png_set_read_status_fn, (png_structrp png_ptr, png_read_status_ptr read_row_fn)); -PNG_EXPORT(81, void, png_set_write_status_fn, (png_structp png_ptr, +PNG_EXPORT(81, void, png_set_write_status_fn, (png_structrp png_ptr, png_write_status_ptr write_row_fn)); #ifdef PNG_USER_MEM_SUPPORTED /* Replace the default memory allocation functions with user supplied one(s). */ -PNG_EXPORT(82, void, png_set_mem_fn, (png_structp png_ptr, png_voidp mem_ptr, +PNG_EXPORT(82, void, png_set_mem_fn, (png_structrp png_ptr, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)); /* Return the user pointer associated with the memory functions */ -PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structp png_ptr)); +PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structrp png_ptr)); #endif #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED -PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structp png_ptr, +PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structrp png_ptr, png_user_transform_ptr read_user_transform_fn)); #endif #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED -PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structp png_ptr, +PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structrp png_ptr, png_user_transform_ptr write_user_transform_fn)); #endif #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED -PNG_EXPORT(86, void, png_set_user_transform_info, (png_structp png_ptr, +PNG_EXPORT(86, void, png_set_user_transform_info, (png_structrp png_ptr, png_voidp user_transform_ptr, int user_transform_depth, int user_transform_channels)); /* Return the user pointer associated with the user transform functions */ PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); #endif #ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED @@ -1812,31 +1831,53 @@ PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr, * find the output pixel (x,y) given an interlaced sub-image pixel * (row,col,pass). (See below for these macros.) */ -PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structp)); -PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structp)); +PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structrp)); +PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp)); +#endif + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED +/* This callback is called only for *unknown* chunks. If + * PNG_HANDLE_AS_UNKNOWN_SUPPORTED is set then it is possible to set known + * chunks to be treated as unknown, however in this case the callback must do + * any processing required by the chunk (e.g. by calling the appropriate + * png_set_ APIs.) + * + * There is no write support - on write, by default, all the chunks in the + * 'unknown' list are written in the specified position. + * + * The integer return from the callback function is interpreted thus: + * + * negative: An error occured, png_chunk_error will be called. + * zero: The chunk was not handled, the chunk will be saved. A critical + * chunk will cause an error at this point unless it is to be saved. + * positive: The chunk was handled, libpng will ignore/discard it. + * + * See "INTERACTION WTIH USER CHUNK CALLBACKS" below for important notes about + * how this behavior will change in libpng 1.7 + */ +PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr, + png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); #endif #ifdef PNG_USER_CHUNKS_SUPPORTED -PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structp png_ptr, - png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); -PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structp png_ptr)); +PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structrp png_ptr)); #endif #ifdef PNG_PROGRESSIVE_READ_SUPPORTED /* Sets the function callbacks for the push reader, and a pointer to a * user-defined structure available to the callback functions. */ -PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structp png_ptr, +PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structrp png_ptr, png_voidp progressive_ptr, png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn)); /* Returns the user pointer associated with the push read functions */ -PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, (png_const_structp png_ptr)); +PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, + (png_const_structrp png_ptr)); /* Function to be called when data becomes available */ -PNG_EXPORT(92, void, png_process_data, - (png_structp png_ptr, png_infop info_ptr, - png_bytep buffer, png_size_t buffer_size)); +PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr, + png_inforp info_ptr, png_bytep buffer, png_size_t buffer_size)); /* A function which may be called *only* within png_process_data to stop the * processing of any more data. The function returns the number of bytes @@ -1845,7 +1886,7 @@ PNG_EXPORT(92, void, png_process_data, * 'save' is set to true the routine will first save all the pending data and * will always return 0. */ -PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structp, int save)); +PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structrp, int save)); /* A function which may be called *only* outside (after) a call to * png_process_data. It returns the number of bytes of data to skip in the @@ -1853,40 +1894,43 @@ PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structp, int save)); * application must skip than number of bytes of input data and pass the * following data to the next call to png_process_data. */ -PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structp)); +PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structrp)); /* Function that combines rows. 'new_row' is a flag that should come from * the callback and be non-NULL if anything needs to be done; the library * stores its own version of the new data internally and ignores the passed * in value. */ -PNG_EXPORT(93, void, png_progressive_combine_row, (png_structp png_ptr, +PNG_EXPORT(93, void, png_progressive_combine_row, (png_const_structrp png_ptr, png_bytep old_row, png_const_bytep new_row)); -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ +#endif /* PROGRESSIVE_READ */ -PNG_EXPORTA(94, png_voidp, png_malloc, - (png_structp png_ptr, png_alloc_size_t size), - PNG_ALLOCATED); +PNG_EXPORTA(94, png_voidp, png_malloc, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); /* Added at libpng version 1.4.0 */ -PNG_EXPORTA(95, png_voidp, png_calloc, - (png_structp png_ptr, png_alloc_size_t size), - PNG_ALLOCATED); +PNG_EXPORTA(95, png_voidp, png_calloc, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); /* Added at libpng version 1.2.4 */ -PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_structp png_ptr, +PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_const_structrp png_ptr, png_alloc_size_t size), PNG_ALLOCATED); /* Frees a pointer allocated by png_malloc() */ -PNG_EXPORT(97, void, png_free, (png_structp png_ptr, png_voidp ptr)); +PNG_EXPORT(97, void, png_free, (png_const_structrp png_ptr, png_voidp ptr)); /* Free data that was allocated internally */ -PNG_EXPORT(98, void, png_free_data, - (png_structp png_ptr, png_infop info_ptr, png_uint_32 free_me, int num)); +PNG_EXPORT(98, void, png_free_data, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 free_me, int num)); /* Reassign responsibility for freeing existing data, whether allocated - * by libpng or by the application */ -PNG_EXPORT(99, void, png_data_freer, - (png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask)); + * by libpng or by the application; this works on the png_info structure passed + * in, it does not change the state for other png_info structures. + * + * It is unlikely that this function works correctly as of 1.6.0 and using it + * may result either in memory leaks or double free of allocated data. + */ +PNG_EXPORT(99, void, png_data_freer, (png_const_structrp png_ptr, + png_inforp info_ptr, int freer, png_uint_32 mask)); /* Assignments for png_data_freer */ #define PNG_DESTROY_WILL_FREE_DATA 1 @@ -1899,8 +1943,10 @@ PNG_EXPORT(99, void, png_data_freer, #define PNG_FREE_ROWS 0x0040 #define PNG_FREE_PCAL 0x0080 #define PNG_FREE_SCAL 0x0100 -#define PNG_FREE_UNKN 0x0200 -#define PNG_FREE_LIST 0x0400 +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +# define PNG_FREE_UNKN 0x0200 +#endif +/* PNG_FREE_LIST 0x0400 removed in 1.6.0 because it is ignored */ #define PNG_FREE_PLTE 0x1000 #define PNG_FREE_TRNS 0x2000 #define PNG_FREE_TEXT 0x4000 @@ -1908,50 +1954,55 @@ PNG_EXPORT(99, void, png_data_freer, #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ #ifdef PNG_USER_MEM_SUPPORTED -PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_structp png_ptr, - png_alloc_size_t size), PNG_ALLOCATED); -PNG_EXPORT(101, void, png_free_default, (png_structp png_ptr, png_voidp ptr)); +PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED PNG_DEPRECATED); +PNG_EXPORTA(101, void, png_free_default, (png_const_structrp png_ptr, + png_voidp ptr), PNG_DEPRECATED); #endif #ifdef PNG_ERROR_TEXT_SUPPORTED /* Fatal error in PNG image of libpng - can't continue */ -PNG_EXPORTA(102, void, png_error, - (png_structp png_ptr, png_const_charp error_message), - PNG_NORETURN); +PNG_EXPORTA(102, void, png_error, (png_const_structrp png_ptr, + png_const_charp error_message), PNG_NORETURN); /* The same, but the chunk name is prepended to the error string. */ -PNG_EXPORTA(103, void, png_chunk_error, (png_structp png_ptr, +PNG_EXPORTA(103, void, png_chunk_error, (png_const_structrp png_ptr, png_const_charp error_message), PNG_NORETURN); #else /* Fatal error in PNG image of libpng - can't continue */ -PNG_EXPORTA(104, void, png_err, (png_structp png_ptr), PNG_NORETURN); +PNG_EXPORTA(104, void, png_err, (png_const_structrp png_ptr), PNG_NORETURN); +# define png_error(s1,s2) png_err(s1) +# define png_chunk_error(s1,s2) png_err(s1) #endif #ifdef PNG_WARNINGS_SUPPORTED /* Non-fatal error in libpng. Can continue, but may have a problem. */ -PNG_EXPORT(105, void, png_warning, (png_structp png_ptr, +PNG_EXPORT(105, void, png_warning, (png_const_structrp png_ptr, png_const_charp warning_message)); /* Non-fatal error in libpng, chunk name is prepended to message. */ -PNG_EXPORT(106, void, png_chunk_warning, (png_structp png_ptr, +PNG_EXPORT(106, void, png_chunk_warning, (png_const_structrp png_ptr, png_const_charp warning_message)); +#else +# define png_warning(s1,s2) ((void)(s1)) +# define png_chunk_warning(s1,s2) ((void)(s1)) #endif #ifdef PNG_BENIGN_ERRORS_SUPPORTED /* Benign error in libpng. Can continue, but may have a problem. * User can choose whether to handle as a fatal error or as a warning. */ -# undef png_benign_error -PNG_EXPORT(107, void, png_benign_error, (png_structp png_ptr, +PNG_EXPORT(107, void, png_benign_error, (png_const_structrp png_ptr, png_const_charp warning_message)); -/* Same, chunk name is prepended to message. */ -# undef png_chunk_benign_error -PNG_EXPORT(108, void, png_chunk_benign_error, (png_structp png_ptr, +#ifdef PNG_READ_SUPPORTED +/* Same, chunk name is prepended to message (only during read) */ +PNG_EXPORT(108, void, png_chunk_benign_error, (png_const_structrp png_ptr, png_const_charp warning_message)); +#endif PNG_EXPORT(109, void, png_set_benign_errors, - (png_structp png_ptr, int allowed)); + (png_structrp png_ptr, int allowed)); #else # ifdef PNG_ALLOW_BENIGN_ERRORS # define png_benign_error png_warning @@ -1975,268 +2026,274 @@ PNG_EXPORT(109, void, png_set_benign_errors, * png_info_struct. */ /* Returns "flag" if chunk data is valid in info_ptr. */ -PNG_EXPORT(110, png_uint_32, png_get_valid, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_32 flag)); +PNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 flag)); /* Returns number of bytes needed to hold a transformed row. */ -PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structp png_ptr, - png_const_infop info_ptr)); +PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); #ifdef PNG_INFO_IMAGE_SUPPORTED /* Returns row_pointers, which is an array of pointers to scanlines that was * returned from png_read_png(). */ -PNG_EXPORT(112, png_bytepp, png_get_rows, - (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(112, png_bytepp, png_get_rows, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + /* Set row_pointers, which is an array of pointers to scanlines for use * by png_write_png(). */ -PNG_EXPORT(113, void, png_set_rows, (png_structp png_ptr, - png_infop info_ptr, png_bytepp row_pointers)); +PNG_EXPORT(113, void, png_set_rows, (png_const_structrp png_ptr, + png_inforp info_ptr, png_bytepp row_pointers)); #endif /* Returns number of color channels in image. */ -PNG_EXPORT(114, png_byte, png_get_channels, - (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(114, png_byte, png_get_channels, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); #ifdef PNG_EASY_ACCESS_SUPPORTED /* Returns image width in pixels. */ -PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structp png_ptr, - png_const_infop info_ptr)); +PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); /* Returns image height in pixels. */ -PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structp png_ptr, - png_const_infop info_ptr)); +PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); /* Returns image bit_depth. */ -PNG_EXPORT(117, png_byte, png_get_bit_depth, - (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(117, png_byte, png_get_bit_depth, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); /* Returns image color_type. */ -PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structp png_ptr, - png_const_infop info_ptr)); +PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); /* Returns image filter_type. */ -PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structp png_ptr, - png_const_infop info_ptr)); +PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); /* Returns image interlace_type. */ -PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structp png_ptr, - png_const_infop info_ptr)); +PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); /* Returns image compression_type. */ -PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structp png_ptr, - png_const_infop info_ptr)); +PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); /* Returns image resolution in pixels per meter, from pHYs chunk data. */ PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); /* Returns pixel aspect ratio, computed from pHYs chunk data. */ PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)) PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)) /* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); PNG_EXPORT(128, png_int_32, png_get_x_offset_microns, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); PNG_EXPORT(129, png_int_32, png_get_y_offset_microns, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); -#endif /* PNG_EASY_ACCESS_SUPPORTED */ +#endif /* EASY_ACCESS */ +#ifdef PNG_READ_SUPPORTED /* Returns pointer to signature string read from PNG header */ -PNG_EXPORT(130, png_const_bytep, png_get_signature, - (png_const_structp png_ptr, png_infop info_ptr)); - -#ifdef PNG_bKGD_SUPPORTED -PNG_EXPORT(131, png_uint_32, png_get_bKGD, - (png_const_structp png_ptr, png_infop info_ptr, - png_color_16p *background)); +PNG_EXPORT(130, png_const_bytep, png_get_signature, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); #endif #ifdef PNG_bKGD_SUPPORTED -PNG_EXPORT(132, void, png_set_bKGD, (png_structp png_ptr, png_infop info_ptr, - png_const_color_16p background)); +PNG_EXPORT(131, png_uint_32, png_get_bKGD, (png_const_structrp png_ptr, + png_inforp info_ptr, png_color_16p *background)); +#endif + +#ifdef PNG_bKGD_SUPPORTED +PNG_EXPORT(132, void, png_set_bKGD, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_color_16p background)); #endif #ifdef PNG_cHRM_SUPPORTED -PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structp png_ptr, - png_const_infop info_ptr, double *white_x, double *white_y, double *red_x, +PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structrp png_ptr, + png_const_inforp info_ptr, double *white_x, double *white_y, double *red_x, double *red_y, double *green_x, double *green_y, double *blue_x, - double *blue_y)); -#ifdef PNG_FIXED_POINT_SUPPORTED /* Otherwise not implemented */ + double *blue_y)) +PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_const_structrp png_ptr, + png_const_inforp info_ptr, double *red_X, double *red_Y, double *red_Z, + double *green_X, double *green_Y, double *green_Z, double *blue_X, + double *blue_Y, double *blue_Z)) PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed, - (png_const_structp png_ptr, - png_const_infop info_ptr, png_fixed_point *int_white_x, - png_fixed_point *int_white_y, png_fixed_point *int_red_x, - png_fixed_point *int_red_y, png_fixed_point *int_green_x, - png_fixed_point *int_green_y, png_fixed_point *int_blue_x, - png_fixed_point *int_blue_y)); -#endif + (png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_white_x, png_fixed_point *int_white_y, + png_fixed_point *int_red_x, png_fixed_point *int_red_y, + png_fixed_point *int_green_x, png_fixed_point *int_green_y, + png_fixed_point *int_blue_x, png_fixed_point *int_blue_y)) +PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_red_X, png_fixed_point *int_red_Y, + png_fixed_point *int_red_Z, png_fixed_point *int_green_X, + png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, + png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, + png_fixed_point *int_blue_Z)) #endif #ifdef PNG_cHRM_SUPPORTED -PNG_FP_EXPORT(135, void, png_set_cHRM, - (png_structp png_ptr, png_infop info_ptr, +PNG_FP_EXPORT(135, void, png_set_cHRM, (png_const_structrp png_ptr, + png_inforp info_ptr, double white_x, double white_y, double red_x, double red_y, double green_x, - double green_y, double blue_x, double blue_y)); -PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_structp png_ptr, - png_infop info_ptr, png_fixed_point int_white_x, + double green_y, double blue_x, double blue_y)) +PNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_const_structrp png_ptr, + png_inforp info_ptr, double red_X, double red_Y, double red_Z, + double green_X, double green_Y, double green_Z, double blue_X, + double blue_Y, double blue_Z)) +PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y, png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, - png_fixed_point int_blue_y)); + png_fixed_point int_blue_y)) +PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y, + png_fixed_point int_red_Z, png_fixed_point int_green_X, + png_fixed_point int_green_Y, png_fixed_point int_green_Z, + png_fixed_point int_blue_X, png_fixed_point int_blue_Y, + png_fixed_point int_blue_Z)) #endif #ifdef PNG_gAMA_SUPPORTED -PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, - (png_const_structp png_ptr, png_const_infop info_ptr, - double *file_gamma)); +PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structrp png_ptr, + png_const_inforp info_ptr, double *file_gamma)) PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_fixed_point *int_file_gamma)); + (png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_file_gamma)) #endif #ifdef PNG_gAMA_SUPPORTED -PNG_FP_EXPORT(139, void, png_set_gAMA, (png_structp png_ptr, - png_infop info_ptr, double file_gamma)); -PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_structp png_ptr, - png_infop info_ptr, png_fixed_point int_file_gamma)); +PNG_FP_EXPORT(139, void, png_set_gAMA, (png_const_structrp png_ptr, + png_inforp info_ptr, double file_gamma)) +PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, png_fixed_point int_file_gamma)) #endif #ifdef PNG_hIST_SUPPORTED -PNG_EXPORT(141, png_uint_32, png_get_hIST, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_16p *hist)); +PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_16p *hist)); #endif #ifdef PNG_hIST_SUPPORTED -PNG_EXPORT(142, void, png_set_hIST, (png_structp png_ptr, - png_infop info_ptr, png_const_uint_16p hist)); +PNG_EXPORT(142, void, png_set_hIST, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_uint_16p hist)); #endif -PNG_EXPORT(143, png_uint_32, png_get_IHDR, - (png_structp png_ptr, png_infop info_ptr, - png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, - int *interlace_method, int *compression_method, int *filter_method)); +PNG_EXPORT(143, png_uint_32, png_get_IHDR, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *width, png_uint_32 *height, + int *bit_depth, int *color_type, int *interlace_method, + int *compression_method, int *filter_method)); -PNG_EXPORT(144, void, png_set_IHDR, - (png_structp png_ptr, png_infop info_ptr, - png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, - int interlace_method, int compression_method, int filter_method)); +PNG_EXPORT(144, void, png_set_IHDR, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_method, int compression_method, + int filter_method)); #ifdef PNG_oFFs_SUPPORTED -PNG_EXPORT(145, png_uint_32, png_get_oFFs, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)); +PNG_EXPORT(145, png_uint_32, png_get_oFFs, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, + int *unit_type)); #endif #ifdef PNG_oFFs_SUPPORTED -PNG_EXPORT(146, void, png_set_oFFs, - (png_structp png_ptr, png_infop info_ptr, - png_int_32 offset_x, png_int_32 offset_y, int unit_type)); +PNG_EXPORT(146, void, png_set_oFFs, (png_const_structrp png_ptr, + png_inforp info_ptr, png_int_32 offset_x, png_int_32 offset_y, + int unit_type)); #endif #ifdef PNG_pCAL_SUPPORTED -PNG_EXPORT(147, png_uint_32, png_get_pCAL, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, - int *nparams, - png_charp *units, png_charpp *params)); +PNG_EXPORT(147, png_uint_32, png_get_pCAL, (png_const_structrp png_ptr, + png_inforp info_ptr, png_charp *purpose, png_int_32 *X0, + png_int_32 *X1, int *type, int *nparams, png_charp *units, + png_charpp *params)); #endif #ifdef PNG_pCAL_SUPPORTED -PNG_EXPORT(148, void, png_set_pCAL, (png_structp png_ptr, - png_infop info_ptr, - png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, - int nparams, png_const_charp units, png_charpp params)); +PNG_EXPORT(148, void, png_set_pCAL, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1, + int type, int nparams, png_const_charp units, png_charpp params)); #endif #ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(149, png_uint_32, png_get_pHYs, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +PNG_EXPORT(149, png_uint_32, png_get_pHYs, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, + int *unit_type)); #endif #ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(150, void, png_set_pHYs, - (png_structp png_ptr, png_infop info_ptr, - png_uint_32 res_x, png_uint_32 res_y, int unit_type)); +PNG_EXPORT(150, void, png_set_pHYs, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)); #endif -PNG_EXPORT(151, png_uint_32, png_get_PLTE, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_colorp *palette, int *num_palette)); +PNG_EXPORT(151, png_uint_32, png_get_PLTE, (png_const_structrp png_ptr, + png_inforp info_ptr, png_colorp *palette, int *num_palette)); -PNG_EXPORT(152, void, png_set_PLTE, - (png_structp png_ptr, png_infop info_ptr, - png_const_colorp palette, int num_palette)); +PNG_EXPORT(152, void, png_set_PLTE, (png_structrp png_ptr, + png_inforp info_ptr, png_const_colorp palette, int num_palette)); #ifdef PNG_sBIT_SUPPORTED -PNG_EXPORT(153, png_uint_32, png_get_sBIT, - (png_const_structp png_ptr, png_infop info_ptr, - png_color_8p *sig_bit)); +PNG_EXPORT(153, png_uint_32, png_get_sBIT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_color_8p *sig_bit)); #endif #ifdef PNG_sBIT_SUPPORTED -PNG_EXPORT(154, void, png_set_sBIT, - (png_structp png_ptr, png_infop info_ptr, png_const_color_8p sig_bit)); +PNG_EXPORT(154, void, png_set_sBIT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_color_8p sig_bit)); #endif #ifdef PNG_sRGB_SUPPORTED -PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structp png_ptr, - png_const_infop info_ptr, int *file_srgb_intent)); +PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structrp png_ptr, + png_const_inforp info_ptr, int *file_srgb_intent)); #endif #ifdef PNG_sRGB_SUPPORTED -PNG_EXPORT(156, void, png_set_sRGB, - (png_structp png_ptr, png_infop info_ptr, int srgb_intent)); -PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_structp png_ptr, - png_infop info_ptr, int srgb_intent)); +PNG_EXPORT(156, void, png_set_sRGB, (png_const_structrp png_ptr, + png_inforp info_ptr, int srgb_intent)); +PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_const_structrp png_ptr, + png_inforp info_ptr, int srgb_intent)); #endif #ifdef PNG_iCCP_SUPPORTED -PNG_EXPORT(158, png_uint_32, png_get_iCCP, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_charpp name, int *compression_type, png_bytepp profile, - png_uint_32 *proflen)); +PNG_EXPORT(158, png_uint_32, png_get_iCCP, (png_const_structrp png_ptr, + png_inforp info_ptr, png_charpp name, int *compression_type, + png_bytepp profile, png_uint_32 *proflen)); #endif #ifdef PNG_iCCP_SUPPORTED -PNG_EXPORT(159, void, png_set_iCCP, - (png_structp png_ptr, png_infop info_ptr, - png_const_charp name, int compression_type, png_const_bytep profile, - png_uint_32 proflen)); +PNG_EXPORT(159, void, png_set_iCCP, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_charp name, int compression_type, + png_const_bytep profile, png_uint_32 proflen)); #endif #ifdef PNG_sPLT_SUPPORTED -PNG_EXPORT(160, png_uint_32, png_get_sPLT, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_sPLT_tpp entries)); +PNG_EXPORT(160, int, png_get_sPLT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_sPLT_tpp entries)); #endif #ifdef PNG_sPLT_SUPPORTED -PNG_EXPORT(161, void, png_set_sPLT, - (png_structp png_ptr, png_infop info_ptr, - png_const_sPLT_tp entries, int nentries)); +PNG_EXPORT(161, void, png_set_sPLT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_sPLT_tp entries, int nentries)); #endif #ifdef PNG_TEXT_SUPPORTED /* png_get_text also returns the number of text chunks in *num_text */ -PNG_EXPORT(162, png_uint_32, png_get_text, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_textp *text_ptr, int *num_text)); +PNG_EXPORT(162, int, png_get_text, (png_const_structrp png_ptr, + png_inforp info_ptr, png_textp *text_ptr, int *num_text)); #endif /* Note while png_set_text() will accept a structure whose text, @@ -2247,116 +2304,220 @@ PNG_EXPORT(162, png_uint_32, png_get_text, */ #ifdef PNG_TEXT_SUPPORTED -PNG_EXPORT(163, void, png_set_text, - (png_structp png_ptr, png_infop info_ptr, - png_const_textp text_ptr, int num_text)); +PNG_EXPORT(163, void, png_set_text, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_textp text_ptr, int num_text)); #endif #ifdef PNG_tIME_SUPPORTED -PNG_EXPORT(164, png_uint_32, png_get_tIME, - (png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)); +PNG_EXPORT(164, png_uint_32, png_get_tIME, (png_const_structrp png_ptr, + png_inforp info_ptr, png_timep *mod_time)); #endif #ifdef PNG_tIME_SUPPORTED -PNG_EXPORT(165, void, png_set_tIME, - (png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time)); +PNG_EXPORT(165, void, png_set_tIME, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_timep mod_time)); #endif #ifdef PNG_tRNS_SUPPORTED -PNG_EXPORT(166, png_uint_32, png_get_tRNS, - (png_const_structp png_ptr, png_infop info_ptr, - png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)); +PNG_EXPORT(166, png_uint_32, png_get_tRNS, (png_const_structrp png_ptr, + png_inforp info_ptr, png_bytep *trans_alpha, int *num_trans, + png_color_16p *trans_color)); #endif #ifdef PNG_tRNS_SUPPORTED -PNG_EXPORT(167, void, png_set_tRNS, - (png_structp png_ptr, png_infop info_ptr, - png_const_bytep trans_alpha, int num_trans, +PNG_EXPORT(167, void, png_set_tRNS, (png_structrp png_ptr, + png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)); #endif #ifdef PNG_sCAL_SUPPORTED -PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, - (png_const_structp png_ptr, png_const_infop info_ptr, - int *unit, double *width, double *height)); -#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED +PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr, + png_const_inforp info_ptr, int *unit, double *width, double *height)) +#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ + defined(PNG_FLOATING_POINT_SUPPORTED) /* NOTE: this API is currently implemented using floating point arithmetic, * consequently it can only be used on systems with floating point support. * In any case the range of values supported by png_fixed_point is small and it * is highly recommended that png_get_sCAL_s be used instead. */ PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed, - (png_structp png_ptr, png_const_infop info_ptr, int *unit, - png_fixed_point *width, - png_fixed_point *height)); + (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, + png_fixed_point *width, png_fixed_point *height)) #endif PNG_EXPORT(169, png_uint_32, png_get_sCAL_s, - (png_const_structp png_ptr, png_const_infop info_ptr, - int *unit, png_charpp swidth, png_charpp sheight)); + (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, + png_charpp swidth, png_charpp sheight)); -PNG_FP_EXPORT(170, void, png_set_sCAL, - (png_structp png_ptr, png_infop info_ptr, - int unit, double width, double height)); -PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_structp png_ptr, - png_infop info_ptr, int unit, png_fixed_point width, - png_fixed_point height)); -PNG_EXPORT(171, void, png_set_sCAL_s, - (png_structp png_ptr, png_infop info_ptr, - int unit, png_const_charp swidth, png_const_charp sheight)); -#endif /* PNG_sCAL_SUPPORTED */ +PNG_FP_EXPORT(170, void, png_set_sCAL, (png_const_structrp png_ptr, + png_inforp info_ptr, int unit, double width, double height)) +PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, int unit, png_fixed_point width, + png_fixed_point height)) +PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr, + png_inforp info_ptr, int unit, + png_const_charp swidth, png_const_charp sheight)); +#endif /* sCAL */ -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED -/* Provide a list of chunks and how they are to be handled, if the built-in - handling or default unknown chunk handling is not desired. Any chunks not - listed will be handled in the default manner. The IHDR and IEND chunks - must not be listed. - keep = 0: follow default behaviour - = 1: do not keep - = 2: keep only if safe-to-copy - = 3: keep even if unsafe-to-copy -*/ -PNG_EXPORT(172, void, png_set_keep_unknown_chunks, - (png_structp png_ptr, int keep, - png_const_bytep chunk_list, int num_chunks)); -PNG_EXPORT(173, int, png_handle_as_unknown, (png_structp png_ptr, +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED +/* Provide the default handling for all unknown chunks or, optionally, for + * specific unknown chunks. + * + * NOTE: prior to 1.6.0 the handling specified for particular chunks on read was + * ignored and the default was used, the per-chunk setting only had an effect on + * write. If you wish to have chunk-specific handling on read in code that must + * work on earlier versions you must use a user chunk callback to specify the + * desired handling (keep or discard.) + * + * The 'keep' parameter is a PNG_HANDLE_CHUNK_ value as listed below. The + * parameter is interpreted as follows: + * + * READ: + * PNG_HANDLE_CHUNK_AS_DEFAULT: + * Known chunks: do normal libpng processing, do not keep the chunk (but + * see the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED) + * Unknown chunks: for a specific chunk use the global default, when used + * as the default discard the chunk data. + * PNG_HANDLE_CHUNK_NEVER: + * Discard the chunk data. + * PNG_HANDLE_CHUNK_IF_SAFE: + * Keep the chunk data if the chunk is not critical else raise a chunk + * error. + * PNG_HANDLE_CHUNK_ALWAYS: + * Keep the chunk data. + * + * If the chunk data is saved it can be retrieved using png_get_unknown_chunks, + * below. Notice that specifying "AS_DEFAULT" as a global default is equivalent + * to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks + * it simply resets the behavior to the libpng default. + * + * INTERACTION WTIH USER CHUNK CALLBACKS: + * The per-chunk handling is always used when there is a png_user_chunk_ptr + * callback and the callback returns 0; the chunk is then always stored *unless* + * it is critical and the per-chunk setting is other than ALWAYS. Notice that + * the global default is *not* used in this case. (In effect the per-chunk + * value is incremented to at least IF_SAFE.) + * + * IMPORTANT NOTE: this behavior will change in libpng 1.7 - the global and + * per-chunk defaults will be honored. If you want to preserve the current + * behavior when your callback returns 0 you must set PNG_HANDLE_CHUNK_IF_SAFE + * as the default - if you don't do this libpng 1.6 will issue a warning. + * + * If you want unhandled unknown chunks to be discarded in libpng 1.6 and + * earlier simply return '1' (handled). + * + * PNG_HANDLE_AS_UNKNOWN_SUPPORTED: + * If this is *not* set known chunks will always be handled by libpng and + * will never be stored in the unknown chunk list. Known chunks listed to + * png_set_keep_unknown_chunks will have no effect. If it is set then known + * chunks listed with a keep other than AS_DEFAULT will *never* be processed + * by libpng, in addition critical chunks must either be processed by the + * callback or saved. + * + * The IHDR and IEND chunks must not be listed. Because this turns off the + * default handling for chunks that would otherwise be recognized the + * behavior of libpng transformations may well become incorrect! + * + * WRITE: + * When writing chunks the options only apply to the chunks specified by + * png_set_unknown_chunks (below), libpng will *always* write known chunks + * required by png_set_ calls and will always write the core critical chunks + * (as required for PLTE). + * + * Each chunk in the png_set_unknown_chunks list is looked up in the + * png_set_keep_unknown_chunks list to find the keep setting, this is then + * interpreted as follows: + * + * PNG_HANDLE_CHUNK_AS_DEFAULT: + * Write safe-to-copy chunks and write other chunks if the global + * default is set to _ALWAYS, otherwise don't write this chunk. + * PNG_HANDLE_CHUNK_NEVER: + * Do not write the chunk. + * PNG_HANDLE_CHUNK_IF_SAFE: + * Write the chunk if it is safe-to-copy, otherwise do not write it. + * PNG_HANDLE_CHUNK_ALWAYS: + * Write the chunk. + * + * Note that the default behavior is effectively the opposite of the read case - + * in read unknown chunks are not stored by default, in write they are written + * by default. Also the behavior of PNG_HANDLE_CHUNK_IF_SAFE is very different + * - on write the safe-to-copy bit is checked, on read the critical bit is + * checked and on read if the chunk is critical an error will be raised. + * + * num_chunks: + * =========== + * If num_chunks is positive, then the "keep" parameter specifies the manner + * for handling only those chunks appearing in the chunk_list array, + * otherwise the chunk list array is ignored. + * + * If num_chunks is 0 the "keep" parameter specifies the default behavior for + * unknown chunks, as described above. + * + * If num_chunks is negative, then the "keep" parameter specifies the manner + * for handling all unknown chunks plus all chunks recognized by libpng + * except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to + * be processed by libpng. + */ +PNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structrp png_ptr, + int keep, png_const_bytep chunk_list, int num_chunks)); + +/* The "keep" PNG_HANDLE_CHUNK_ parameter for the specified chunk is returned; + * the result is therefore true (non-zero) if special handling is required, + * false for the default handling. + */ +PNG_EXPORT(173, int, png_handle_as_unknown, (png_const_structrp png_ptr, png_const_bytep chunk_name)); #endif -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED -PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structp png_ptr, - png_infop info_ptr, png_const_unknown_chunkp unknowns, + +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +PNG_EXPORT(174, void, png_set_unknown_chunks, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)); + /* NOTE: prior to 1.6.0 this routine set the 'location' field of the added + * unknowns to the location currently stored in the png_struct. This is + * invariably the wrong value on write. To fix this call the following API + * for each chunk in the list with the correct location. If you know your + * code won't be compiled on earlier versions you can rely on + * png_set_unknown_chunks(write-ptr, png_get_unknown_chunks(read-ptr)) doing + * the correct thing. + */ + PNG_EXPORT(175, void, png_set_unknown_chunk_location, - (png_structp png_ptr, png_infop info_ptr, int chunk, int location)); -PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structp png_ptr, - png_const_infop info_ptr, png_unknown_chunkpp entries)); + (png_const_structrp png_ptr, png_inforp info_ptr, int chunk, int location)); + +PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structrp png_ptr, + png_inforp info_ptr, png_unknown_chunkpp entries)); #endif /* Png_free_data() will turn off the "valid" flag for anything it frees. * If you need to turn it off for a chunk that your application has freed, * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); */ -PNG_EXPORT(177, void, png_set_invalid, - (png_structp png_ptr, png_infop info_ptr, int mask)); +PNG_EXPORT(177, void, png_set_invalid, (png_const_structrp png_ptr, + png_inforp info_ptr, int mask)); #ifdef PNG_INFO_IMAGE_SUPPORTED /* The "params" pointer is currently not used and is for future expansion. */ -PNG_EXPORT(178, void, png_read_png, (png_structp png_ptr, png_infop info_ptr, +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +PNG_EXPORT(178, void, png_read_png, (png_structrp png_ptr, png_inforp info_ptr, int transforms, png_voidp params)); -PNG_EXPORT(179, void, png_write_png, (png_structp png_ptr, png_infop info_ptr, +#endif +#ifdef PNG_WRITE_SUPPORTED +PNG_EXPORT(179, void, png_write_png, (png_structrp png_ptr, png_inforp info_ptr, int transforms, png_voidp params)); #endif +#endif PNG_EXPORT(180, png_const_charp, png_get_copyright, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); PNG_EXPORT(181, png_const_charp, png_get_header_ver, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); PNG_EXPORT(182, png_const_charp, png_get_header_version, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); PNG_EXPORT(183, png_const_charp, png_get_libpng_ver, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); #ifdef PNG_MNG_FEATURES_SUPPORTED -PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structp png_ptr, +PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structrp png_ptr, png_uint_32 mng_features_permitted)); #endif @@ -2365,75 +2526,77 @@ PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structp png_ptr, #define PNG_HANDLE_CHUNK_NEVER 1 #define PNG_HANDLE_CHUNK_IF_SAFE 2 #define PNG_HANDLE_CHUNK_ALWAYS 3 +#define PNG_HANDLE_CHUNK_LAST 4 /* Strip the prepended error numbers ("#nnn ") from error and warning * messages before passing them to the error or warning handler. */ #ifdef PNG_ERROR_NUMBERS_SUPPORTED -PNG_EXPORT(185, void, png_set_strip_error_numbers, - (png_structp png_ptr, +PNG_EXPORT(185, void, png_set_strip_error_numbers, (png_structrp png_ptr, png_uint_32 strip_mode)); #endif /* Added in libpng-1.2.6 */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED -PNG_EXPORT(186, void, png_set_user_limits, (png_structp png_ptr, +PNG_EXPORT(186, void, png_set_user_limits, (png_structrp png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max)); PNG_EXPORT(187, png_uint_32, png_get_user_width_max, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); PNG_EXPORT(188, png_uint_32, png_get_user_height_max, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); /* Added in libpng-1.4.0 */ -PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structp png_ptr, +PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structrp png_ptr, png_uint_32 user_chunk_cache_max)); PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); /* Added in libpng-1.4.1 */ -PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structp png_ptr, +PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structrp png_ptr, png_alloc_size_t user_chunk_cache_max)); PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); #endif #if defined(PNG_INCH_CONVERSIONS_SUPPORTED) PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)); PNG_FP_EXPORT(196, float, png_get_x_offset_inches, - (png_const_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)) #ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed, - (png_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)) #endif -PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structp png_ptr, - png_const_infop info_ptr)); +PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structrp png_ptr, + png_const_inforp info_ptr)) #ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed, - (png_structp png_ptr, png_const_infop info_ptr)); + (png_const_structrp png_ptr, png_const_inforp info_ptr)) #endif # ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structp png_ptr, - png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, +PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); -# endif /* PNG_pHYs_SUPPORTED */ -#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */ +# endif /* pHYs */ +#endif /* INCH_CONVERSIONS */ /* Added in libpng-1.4.0 */ #ifdef PNG_IO_STATE_SUPPORTED -PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_structp png_ptr)); +PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_const_structrp png_ptr)); + +/* Removed from libpng 1.6; use png_get_io_chunk_type. */ +PNG_REMOVED(200, png_const_bytep, png_get_io_chunk_name, (png_structrp png_ptr), + PNG_DEPRECATED) -PNG_EXPORTA(200, png_const_bytep, png_get_io_chunk_name, - (png_structp png_ptr), PNG_DEPRECATED); PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, - (png_const_structp png_ptr)); + (png_const_structrp png_ptr)); /* The flags returned by png_get_io_state() are the following: */ # define PNG_IO_NONE 0x0000 /* no I/O at this moment */ @@ -2445,7 +2608,7 @@ PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, # define PNG_IO_CHUNK_CRC 0x0080 /* currently at the chunk crc */ # define PNG_IO_MASK_OP 0x000f /* current operation: reading/writing */ # define PNG_IO_MASK_LOC 0x00f0 /* current location: sig/hdr/data/crc */ -#endif /* ?PNG_IO_STATE_SUPPORTED */ +#endif /* IO_STATE */ /* Interlace support. The following macros are always defined so that if * libpng interlace handling is turned off the macros may be used to handle @@ -2457,8 +2620,16 @@ PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, * full, image which appears in a given pass. 'pass' is in the range 0 * to 6 and the result is in the range 0 to 7. */ -#define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7) -#define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7) +#define PNG_PASS_START_ROW(pass) (((1&~(pass))<<(3-((pass)>>1)))&7) +#define PNG_PASS_START_COL(pass) (((1& (pass))<<(3-(((pass)+1)>>1)))&7) + +/* A macro to return the offset between pixels in the output row for a pair of + * pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that + * follows. Note that ROW_OFFSET is the offset from one row to the next whereas + * COL_OFFSET is from one column to the next, within a row. + */ +#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8) +#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1)) /* Two macros to help evaluate the number of rows or columns in each * pass. This is expressed as a shift - effectively log2 of the number or @@ -2481,10 +2652,10 @@ PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, * necessary to find the row in the output image given a row in an interlaced * image, so two more macros: */ -#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \ - (((yIn)<>(((7-(off))-(pass))<<2)) & 0xFU) | \ - ((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U)) + ((0x110145AF>>(((7-(off))-(pass))<<2)) & 0xF) | \ + ((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0)) #define PNG_ROW_IN_INTERLACE_PASS(y, pass) \ ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1) @@ -2520,14 +2691,14 @@ PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \ * (png_uint_16)(alpha) \ + (png_uint_16)(bg)*(png_uint_16)(255 \ - - (png_uint_16)(alpha)) + (png_uint_16)128); \ + - (png_uint_16)(alpha)) + 128); \ (composite) = (png_byte)((temp + (temp >> 8)) >> 8); } # define png_composite_16(composite, fg, alpha, bg) \ { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \ * (png_uint_32)(alpha) \ - + (png_uint_32)(bg)*(png_uint_32)(65535L \ - - (png_uint_32)(alpha)) + (png_uint_32)32768L); \ + + (png_uint_32)(bg)*(65535 \ + - (png_uint_32)(alpha)) + 32768); \ (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); } #else /* Standard method using integer division */ @@ -2535,13 +2706,13 @@ PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, # define png_composite(composite, fg, alpha, bg) \ (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \ (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ - (png_uint_16)127) / 255) + 127) / 255) # define png_composite_16(composite, fg, alpha, bg) \ (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \ - (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \ - (png_uint_32)32767) / (png_uint_32)65535L) -#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ + (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \ + 32767) / 65535) +#endif /* READ_COMPOSITE_NODIV */ #ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf)); @@ -2549,7 +2720,7 @@ PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf)); PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf)); #endif -PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_structp png_ptr, +PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_const_structrp png_ptr, png_const_bytep buf)); /* No png_get_int_16 -- may be added if there's a real need for it. */ @@ -2575,7 +2746,7 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); * The png_get_int_32() routine assumes we are using two's complement * format for negative values, which is almost certainly true. */ -# define png_get_uint_32(buf) \ +# define PNG_get_uint_32(buf) \ (((png_uint_32)(*(buf)) << 24) + \ ((png_uint_32)(*((buf) + 1)) << 16) + \ ((png_uint_32)(*((buf) + 2)) << 8) + \ @@ -2584,27 +2755,550 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the * function) incorrectly returned a value of type png_uint_32. */ -# define png_get_uint_16(buf) \ +# define PNG_get_uint_16(buf) \ ((png_uint_16) \ (((unsigned int)(*(buf)) << 8) + \ ((unsigned int)(*((buf) + 1))))) -# define png_get_int_32(buf) \ +# define PNG_get_int_32(buf) \ ((png_int_32)((*(buf) & 0x80) \ ? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \ : (png_int_32)png_get_uint_32(buf))) + + /* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h, + * but defining a macro name prefixed with PNG_PREFIX. + */ +# ifndef PNG_PREFIX +# define png_get_uint_32(buf) PNG_get_uint_32(buf) +# define png_get_uint_16(buf) PNG_get_uint_16(buf) +# define png_get_int_32(buf) PNG_get_int_32(buf) +# endif +#else +# ifdef PNG_PREFIX + /* No macros; revert to the (redefined) function */ +# define PNG_get_uint_32 (png_get_uint_32) +# define PNG_get_uint_16 (png_get_uint_16) +# define PNG_get_int_32 (png_get_int_32) +# endif #endif -/* Maintainer: Put new public prototypes here ^, in libpng.3, and project - * defs +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) || \ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +/******************************************************************************* + * SIMPLIFIED API + ******************************************************************************* + * + * Please read the documentation in libpng-manual.txt (TODO: write said + * documentation) if you don't understand what follows. + * + * The simplified API hides the details of both libpng and the PNG file format + * itself. It allows PNG files to be read into a very limited number of + * in-memory bitmap formats or to be written from the same formats. If these + * formats do not accomodate your needs then you can, and should, use the more + * sophisticated APIs above - these support a wide variety of in-memory formats + * and a wide variety of sophisticated transformations to those formats as well + * as a wide variety of APIs to manipulate ancillary information. + * + * To read a PNG file using the simplified API: + * + * 1) Declare a 'png_image' structure (see below) on the stack and set the + * version field to PNG_IMAGE_VERSION. + * 2) Call the appropriate png_image_begin_read... function. + * 3) Set the png_image 'format' member to the required sample format. + * 4) Allocate a buffer for the image and, if required, the color-map. + * 5) Call png_image_finish_read to read the image and, if required, the + * color-map into your buffers. + * + * There are no restrictions on the format of the PNG input itself; all valid + * color types, bit depths, and interlace methods are acceptable, and the + * input image is transformed as necessary to the requested in-memory format + * during the png_image_finish_read() step. The only caveat is that if you + * request a color-mapped image from a PNG that is full-color or makes + * complex use of an alpha channel the transformation is extremely lossy and the + * result may look terrible. + * + * To write a PNG file using the simplified API: + * + * 1) Declare a 'png_image' structure on the stack and memset() it to all zero. + * 2) Initialize the members of the structure that describe the image, setting + * the 'format' member to the format of the image samples. + * 3) Call the appropriate png_image_write... function with a pointer to the + * image and, if necessary, the color-map to write the PNG data. + * + * png_image is a structure that describes the in-memory format of an image + * when it is being read or defines the in-memory format of an image that you + * need to write: + */ +#define PNG_IMAGE_VERSION 1 + +typedef struct png_control *png_controlp; +typedef struct +{ + png_controlp opaque; /* Initialize to NULL, free with png_image_free */ + png_uint_32 version; /* Set to PNG_IMAGE_VERSION */ + png_uint_32 width; /* Image width in pixels (columns) */ + png_uint_32 height; /* Image height in pixels (rows) */ + png_uint_32 format; /* Image format as defined below */ + png_uint_32 flags; /* A bit mask containing informational flags */ + png_uint_32 colormap_entries; + /* Number of entries in the color-map */ + + /* In the event of an error or warning the following field will be set to a + * non-zero value and the 'message' field will contain a '\0' terminated + * string with the libpng error or warning message. If both warnings and + * an error were encountered, only the error is recorded. If there + * are multiple warnings, only the first one is recorded. + * + * The upper 30 bits of this value are reserved, the low two bits contain + * a value as follows: + */ +# define PNG_IMAGE_WARNING 1 +# define PNG_IMAGE_ERROR 2 + /* + * The result is a two-bit code such that a value more than 1 indicates + * a failure in the API just called: + * + * 0 - no warning or error + * 1 - warning + * 2 - error + * 3 - error preceded by warning + */ +# define PNG_IMAGE_FAILED(png_cntrl) ((((png_cntrl).warning_or_error)&0x03)>1) + + png_uint_32 warning_or_error; + + char message[64]; +} png_image, *png_imagep; + +/* The samples of the image have one to four channels whose components have + * original values in the range 0 to 1.0: + * + * 1: A single gray or luminance channel (G). + * 2: A gray/luminance channel and an alpha channel (GA). + * 3: Three red, green, blue color channels (RGB). + * 4: Three color channels and an alpha channel (RGBA). + * + * The components are encoded in one of two ways: + * + * a) As a small integer, value 0..255, contained in a single byte. For the + * alpha channel the original value is simply value/255. For the color or + * luminance channels the value is encoded according to the sRGB specification + * and matches the 8-bit format expected by typical display devices. + * + * The color/gray channels are not scaled (pre-multiplied) by the alpha + * channel and are suitable for passing to color management software. + * + * b) As a value in the range 0..65535, contained in a 2-byte integer. All + * channels can be converted to the original value by dividing by 65535; all + * channels are linear. Color channels use the RGB encoding (RGB end-points) of + * the sRGB specification. This encoding is identified by the + * PNG_FORMAT_FLAG_LINEAR flag below. + * + * When the simplified API needs to convert between sRGB and linear colorspaces, + * the actual sRGB transfer curve defined in the sRGB specification (see the + * article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2 + * approximation used elsewhere in libpng. + * + * When an alpha channel is present it is expected to denote pixel coverage + * of the color or luminance channels and is returned as an associated alpha + * channel: the color/gray channels are scaled (pre-multiplied) by the alpha + * value. + * + * The samples are either contained directly in the image data, between 1 and 8 + * bytes per pixel according to the encoding, or are held in a color-map indexed + * by bytes in the image data. In the case of a color-map the color-map entries + * are individual samples, encoded as above, and the image data has one byte per + * pixel to select the relevant sample from the color-map. + */ + +/* PNG_FORMAT_* + * + * #defines to be used in png_image::format. Each #define identifies a + * particular layout of sample data and, if present, alpha values. There are + * separate defines for each of the two component encodings. + * + * A format is built up using single bit flag values. All combinations are + * valid. Formats can be built up from the flag values or you can use one of + * the predefined values below. When testing formats always use the FORMAT_FLAG + * macros to test for individual features - future versions of the library may + * add new flags. + * + * When reading or writing color-mapped images the format should be set to the + * format of the entries in the color-map then png_image_{read,write}_colormap + * called to read or write the color-map and set the format correctly for the + * image data. Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly! + * + * NOTE: libpng can be built with particular features disabled, if you see + * compiler errors because the definition of one of the following flags has been + * compiled out it is because libpng does not have the required support. It is + * possible, however, for the libpng configuration to enable the format on just + * read or just write; in that case you may see an error at run time. You can + * guard against this by checking for the definition of the appropriate + * "_SUPPORTED" macro, one of: + * + * PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED + */ +#define PNG_FORMAT_FLAG_ALPHA 0x01U /* format with an alpha channel */ +#define PNG_FORMAT_FLAG_COLOR 0x02U /* color format: otherwise grayscale */ +#define PNG_FORMAT_FLAG_LINEAR 0x04U /* 2 byte channels else 1 byte */ +#define PNG_FORMAT_FLAG_COLORMAP 0x08U /* image data is color-mapped */ + +#ifdef PNG_FORMAT_BGR_SUPPORTED +# define PNG_FORMAT_FLAG_BGR 0x10U /* BGR colors, else order is RGB */ +#endif + +#ifdef PNG_FORMAT_AFIRST_SUPPORTED +# define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */ +#endif + +/* Commonly used formats have predefined macros. + * + * First the single byte (sRGB) formats: + */ +#define PNG_FORMAT_GRAY 0 +#define PNG_FORMAT_GA PNG_FORMAT_FLAG_ALPHA +#define PNG_FORMAT_AG (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST) +#define PNG_FORMAT_RGB PNG_FORMAT_FLAG_COLOR +#define PNG_FORMAT_BGR (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR) +#define PNG_FORMAT_RGBA (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA) +#define PNG_FORMAT_ARGB (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST) +#define PNG_FORMAT_BGRA (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA) +#define PNG_FORMAT_ABGR (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST) + +/* Then the linear 2-byte formats. When naming these "Y" is used to + * indicate a luminance (gray) channel. + */ +#define PNG_FORMAT_LINEAR_Y PNG_FORMAT_FLAG_LINEAR +#define PNG_FORMAT_LINEAR_Y_ALPHA (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA) +#define PNG_FORMAT_LINEAR_RGB (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR) +#define PNG_FORMAT_LINEAR_RGB_ALPHA \ + (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA) + +/* With color-mapped formats the image data is one byte for each pixel, the byte + * is an index into the color-map which is formatted as above. To obtain a + * color-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP + * to one of the above definitions, or you can use one of the definitions below. + */ +#define PNG_FORMAT_RGB_COLORMAP (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_BGR_COLORMAP (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_RGBA_COLORMAP (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_ARGB_COLORMAP (PNG_FORMAT_ARGB|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_BGRA_COLORMAP (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_ABGR_COLORMAP (PNG_FORMAT_ABGR|PNG_FORMAT_FLAG_COLORMAP) + +/* PNG_IMAGE macros + * + * These are convenience macros to derive information from a png_image + * structure. The PNG_IMAGE_SAMPLE_ macros return values appropriate to the + * actual image sample values - either the entries in the color-map or the + * pixels in the image. The PNG_IMAGE_PIXEL_ macros return corresponding values + * for the pixels and will always return 1 for color-mapped formats. The + * remaining macros return information about the rows in the image and the + * complete image. + * + * NOTE: All the macros that take a png_image::format parameter are compile time + * constants if the format parameter is, itself, a constant. Therefore these + * macros can be used in array declarations and case labels where required. + * Similarly the macros are also pre-processor constants (sizeof is not used) so + * they can be used in #if tests. + * + * First the information about the samples. + */ +#define PNG_IMAGE_SAMPLE_CHANNELS(fmt)\ + (((fmt)&(PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA))+1) + /* Return the total number of channels in a given format: 1..4 */ + +#define PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\ + ((((fmt) & PNG_FORMAT_FLAG_LINEAR) >> 2)+1) + /* Return the size in bytes of a single component of a pixel or color-map + * entry (as appropriate) in the image: 1 or 2. + */ + +#define PNG_IMAGE_SAMPLE_SIZE(fmt)\ + (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)) + /* This is the size of the sample data for one sample. If the image is + * color-mapped it is the size of one color-map entry (and image pixels are + * one byte in size), otherwise it is the size of one image pixel. + */ + +#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\ + (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256) + /* The maximum size of the color-map required by the format expressed in a + * count of components. This can be used to compile-time allocate a + * color-map: + * + * png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)]; + * + * png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)]; + * + * Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the + * information from one of the png_image_begin_read_ APIs and dynamically + * allocate the required memory. + */ + +/* Corresponding information about the pixels */ +#define PNG_IMAGE_PIXEL_(test,fmt)\ + (((fmt)&PNG_FORMAT_FLAG_COLORMAP)?1:test(fmt)) + +#define PNG_IMAGE_PIXEL_CHANNELS(fmt)\ + PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_CHANNELS,fmt) + /* The number of separate channels (components) in a pixel; 1 for a + * color-mapped image. + */ + +#define PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\ + PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_COMPONENT_SIZE,fmt) + /* The size, in bytes, of each component in a pixel; 1 for a color-mapped + * image. + */ + +#define PNG_IMAGE_PIXEL_SIZE(fmt) PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_SIZE,fmt) + /* The size, in bytes, of a complete pixel; 1 for a color-mapped image. */ + +/* Information about the whole row, or whole image */ +#define PNG_IMAGE_ROW_STRIDE(image)\ + (PNG_IMAGE_PIXEL_CHANNELS((image).format) * (image).width) + /* Return the total number of components in a single row of the image; this + * is the minimum 'row stride', the minimum count of components between each + * row. For a color-mapped image this is the minimum number of bytes in a + * row. + */ + +#define PNG_IMAGE_BUFFER_SIZE(image, row_stride)\ + (PNG_IMAGE_PIXEL_COMPONENT_SIZE((image).format)*(image).height*(row_stride)) + /* Return the size, in bytes, of an image buffer given a png_image and a row + * stride - the number of components to leave space for in each row. + */ + +#define PNG_IMAGE_SIZE(image)\ + PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image)) + /* Return the size, in bytes, of the image in memory given just a png_image; + * the row stride is the minimum stride required for the image. + */ + +#define PNG_IMAGE_COLORMAP_SIZE(image)\ + (PNG_IMAGE_SAMPLE_SIZE((image).format) * (image).colormap_entries) + /* Return the size, in bytes, of the color-map of this image. If the image + * format is not a color-map format this will return a size sufficient for + * 256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if + * you don't want to allocate a color-map in this case. + */ + +/* PNG_IMAGE_FLAG_* + * + * Flags containing additional information about the image are held in the + * 'flags' field of png_image. + */ +#define PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB 0x01 + /* This indicates the the RGB values of the in-memory bitmap do not + * correspond to the red, green and blue end-points defined by sRGB. + */ + +#define PNG_IMAGE_FLAG_FAST 0x02 + /* On write emphasise speed over compression; the resultant PNG file will be + * larger but will be produced significantly faster, particular for large + * images. Do not use this option for images which will be distributed, only + * used it when producing intermediate files that will be read back in + * repeatedly. For a typical 24-bit image the option will double the read + * speed at the cost of increasing the image size by 25%, however for many + * more compressible images the PNG file can be 10 times larger with only a + * slight speed gain. + */ + +#define PNG_IMAGE_FLAG_16BIT_sRGB 0x04 + /* On read if the image is a 16-bit per component image and there is no gAMA + * or sRGB chunk assume that the components are sRGB encoded. Notice that + * images output by the simplified API always have gamma information; setting + * this flag only affects the interpretation of 16-bit images from an + * external source. It is recommended that the application expose this flag + * to the user; the user can normally easily recognize the difference between + * linear and sRGB encoding. This flag has no effect on write - the data + * passed to the write APIs must have the correct encoding (as defined + * above.) + * + * If the flag is not set (the default) input 16-bit per component data is + * assumed to be linear. + * + * NOTE: the flag can only be set after the png_image_begin_read_ call, + * because that call initializes the 'flags' field. + */ + +#ifdef PNG_SIMPLIFIED_READ_SUPPORTED +/* READ APIs + * --------- + * + * The png_image passed to the read APIs must have been initialized by setting + * the png_controlp field 'opaque' to NULL (or, safer, memset the whole thing.) + */ +#ifdef PNG_STDIO_SUPPORTED +PNG_EXPORT(234, int, png_image_begin_read_from_file, (png_imagep image, + const char *file_name)); + /* The named file is opened for read and the image header is filled in + * from the PNG header in the file. + */ + +PNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image, + FILE* file)); + /* The PNG header is read from the stdio FILE object. */ +#endif /* STDIO */ + +PNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image, + png_const_voidp memory, png_size_t size)); + /* The PNG header is read from the given memory buffer. */ + +PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image, + png_const_colorp background, void *buffer, png_int_32 row_stride, + void *colormap)); + /* Finish reading the image into the supplied buffer and clean up the + * png_image structure. + * + * row_stride is the step, in byte or 2-byte units as appropriate, + * between adjacent rows. A positive stride indicates that the top-most row + * is first in the buffer - the normal top-down arrangement. A negative + * stride indicates that the bottom-most row is first in the buffer. + * + * background need only be supplied if an alpha channel must be removed from + * a png_byte format and the removal is to be done by compositing on a solid + * color; otherwise it may be NULL and any composition will be done directly + * onto the buffer. The value is an sRGB color to use for the background, + * for grayscale output the green channel is used. + * + * background must be supplied when an alpha channel must be removed from a + * single byte color-mapped output format, in other words if: + * + * 1) The original format from png_image_begin_read_from_* had + * PNG_FORMAT_FLAG_ALPHA set. + * 2) The format set by the application does not. + * 3) The format set by the application has PNG_FORMAT_FLAG_COLORMAP set and + * PNG_FORMAT_FLAG_LINEAR *not* set. + * + * For linear output removing the alpha channel is always done by compositing + * on black and background is ignored. + * + * colormap must be supplied when PNG_FORMAT_FLAG_COLORMAP is set. It must + * be at least the size (in bytes) returned by PNG_IMAGE_COLORMAP_SIZE. + * image->colormap_entries will be updated to the actual number of entries + * written to the colormap; this may be less than the original value. + */ + +PNG_EXPORT(238, void, png_image_free, (png_imagep image)); + /* Free any data allocated by libpng in image->opaque, setting the pointer to + * NULL. May be called at any time after the structure is initialized. + */ +#endif /* SIMPLIFIED_READ */ + +#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED +#ifdef PNG_STDIO_SUPPORTED +/* WRITE APIS + * ---------- + * For write you must initialize a png_image structure to describe the image to + * be written. To do this use memset to set the whole structure to 0 then + * initialize fields describing your image. + * + * version: must be set to PNG_IMAGE_VERSION + * opaque: must be initialized to NULL + * width: image width in pixels + * height: image height in rows + * format: the format of the data (image and color-map) you wish to write + * flags: set to 0 unless one of the defined flags applies; set + * PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images where the RGB + * values do not correspond to the colors in sRGB. + * colormap_entries: set to the number of entries in the color-map (0 to 256) + */ +PNG_EXPORT(239, int, png_image_write_to_file, (png_imagep image, + const char *file, int convert_to_8bit, const void *buffer, + png_int_32 row_stride, const void *colormap)); + /* Write the image to the named file. */ + +PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file, + int convert_to_8_bit, const void *buffer, png_int_32 row_stride, + const void *colormap)); + /* Write the image to the given (FILE*). */ + +/* With both write APIs if image is in one of the linear formats with 16-bit + * data then setting convert_to_8_bit will cause the output to be an 8-bit PNG + * gamma encoded according to the sRGB specification, otherwise a 16-bit linear + * encoded PNG file is written. + * + * With color-mapped data formats the colormap parameter point to a color-map + * with at least image->colormap_entries encoded in the specified format. If + * the format is linear the written PNG color-map will be converted to sRGB + * regardless of the convert_to_8_bit flag. + * + * With all APIs row_stride is handled as in the read APIs - it is the spacing + * from one row to the next in component sized units (1 or 2 bytes) and if + * negative indicates a bottom-up row layout in the buffer. + * + * Note that the write API does not support interlacing or sub-8-bit pixels. + */ +#endif /* STDIO */ +#endif /* SIMPLIFIED_WRITE */ +/******************************************************************************* + * END OF SIMPLIFIED API + ******************************************************************************/ +#endif /* SIMPLIFIED_{READ|WRITE} */ + +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +PNG_EXPORT(242, void, png_set_check_for_invalid_index, + (png_structrp png_ptr, int allowed)); +# ifdef PNG_GET_PALETTE_MAX_SUPPORTED +PNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr, + png_const_infop info_ptr)); +# endif +#endif /* CHECK_FOR_INVALID_INDEX */ + +/******************************************************************************* + * IMPLEMENTATION OPTIONS + ******************************************************************************* + * + * Support for arbitrary implementation-specific optimizations. The API allows + * particular options to be turned on or off. 'Option' is the number of the + * option and 'onoff' is 0 (off) or non-0 (on). The value returned is given + * by the PNG_OPTION_ defines below. + * + * HARDWARE: normally hardware capabilites, such as the Intel SSE instructions, + * are detected at run time, however sometimes it may be impossible + * to do this in user mode, in which case it is necessary to discover + * the capabilities in an OS specific way. Such capabilities are + * listed here when libpng has support for them and must be turned + * ON by the application if present. + * + * SOFTWARE: sometimes software optimizations actually result in performance + * decrease on some architectures or systems, or with some sets of + * PNG images. 'Software' options allow such optimizations to be + * selected at run time. + */ +#ifdef PNG_SET_OPTION_SUPPORTED +#ifdef PNG_ARM_NEON_API_SUPPORTED +# define PNG_ARM_NEON 0 /* HARDWARE: ARM Neon SIMD instructions supported */ +#endif +#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */ +#define PNG_SKIP_sRGB_CHECK_PROFILE 4 /* SOFTWARE: Check ICC profile for sRGB */ +#define PNG_OPTION_NEXT 6 /* Next option - numbers must be even */ + +/* Return values: NOTE: there are four values and 'off' is *not* zero */ +#define PNG_OPTION_UNSET 0 /* Unset - defaults to off */ +#define PNG_OPTION_INVALID 1 /* Option number out of range */ +#define PNG_OPTION_OFF 2 +#define PNG_OPTION_ON 3 + +PNG_EXPORT(244, int, png_set_option, (png_structrp png_ptr, int option, + int onoff)); +#endif /* SET_OPTION */ + +/******************************************************************************* + * END OF HARDWARE AND SOFTWARE OPTIONS + ******************************************************************************/ + +/* Maintainer: Put new public prototypes here ^, in libpng.3, in project + * defs, and in scripts/symbols.def. */ /* The last ordinal number (this is the *last* one already used; the next - * one to use is one more than this.) Maintainer, remember to add an entry to - * scripts/symbols.def as well. + * one to use is one more than this.) */ #ifdef PNG_EXPORT_LAST_ORDINAL - PNG_EXPORT_LAST_ORDINAL(229); + PNG_EXPORT_LAST_ORDINAL(244); #endif #ifdef __cplusplus diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngconf.h b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngconf.h index 3072bb94704..2059235d374 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngconf.h +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngconf.h @@ -29,9 +29,9 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * libpng version 1.5.4 - July 7, 2011 + * libpng version 1.6.16,December 22, 2014 * - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -50,37 +50,73 @@ #ifndef PNGCONF_H #define PNGCONF_H -#ifndef PNG_BUILDING_SYMBOL_TABLE -/* PNG_NO_LIMITS_H may be used to turn off the use of the standard C - * definition file for machine specific limits, this may impact the - * correctness of the definitons below (see uses of INT_MAX). - */ -# ifndef PNG_NO_LIMITS_H -# include +/* To do: Do all of this in scripts/pnglibconf.dfa */ +#ifdef PNG_SAFE_LIMITS_SUPPORTED +# ifdef PNG_USER_WIDTH_MAX +# undef PNG_USER_WIDTH_MAX +# define PNG_USER_WIDTH_MAX 1000000L # endif - -/* For the memory copy APIs (i.e. the standard definitions of these), - * because this file defines png_memcpy and so on the base APIs must - * be defined here. - */ -# ifdef BSD -# include -# else -# include +# ifdef PNG_USER_HEIGHT_MAX +# undef PNG_USER_HEIGHT_MAX +# define PNG_USER_HEIGHT_MAX 1000000L # endif - -/* For png_FILE_p - this provides the standard definition of a - * FILE - */ -# ifdef PNG_STDIO_SUPPORTED -# include +# ifdef PNG_USER_CHUNK_MALLOC_MAX +# undef PNG_USER_CHUNK_MALLOC_MAX +# define PNG_USER_CHUNK_MALLOC_MAX 4000000L +# endif +# ifdef PNG_USER_CHUNK_CACHE_MAX +# undef PNG_USER_CHUNK_CACHE_MAX +# define PNG_USER_CHUNK_CACHE_MAX 128 # endif #endif +#ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */ + +/* From libpng 1.6.0 libpng requires an ANSI X3.159-1989 ("ISOC90") compliant C + * compiler for correct compilation. The following header files are required by + * the standard. If your compiler doesn't provide these header files, or they + * do not match the standard, you will need to provide/improve them. + */ +#include +#include + +/* Library header files. These header files are all defined by ISOC90; libpng + * expects conformant implementations, however, an ISOC90 conformant system need + * not provide these header files if the functionality cannot be implemented. + * In this case it will be necessary to disable the relevant parts of libpng in + * the build of pnglibconf.h. + * + * Prior to 1.6.0 string.h was included here; the API changes in 1.6.0 to not + * include this unnecessary header file. + */ + +#ifdef PNG_STDIO_SUPPORTED + /* Required for the definition of FILE: */ +# include +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* Required for the definition of jmp_buf and the declaration of longjmp: */ +# include +#endif + +#ifdef PNG_CONVERT_tIME_SUPPORTED + /* Required for struct tm: */ +# include +#endif + +#endif /* PNG_BUILDING_SYMBOL_TABLE */ + +/* Prior to 1.6.0 it was possible to turn off 'const' in declarations using + * PNG_NO_CONST; this is no longer supported except for data declarations which + * apparently still cause problems in 2011 on some compilers. + */ +#define PNG_CONST const /* backward compatibility only */ + /* This controls optimization of the reading of 16 and 32 bit values * from PNG files. It can be set on a per-app-file basis - it - * just changes whether a macro is used to the function is called. - * The library builder sets the default, if read functions are not + * just changes whether a macro is used when the function is called. + * The library builder sets the default; if read functions are not * built into the library the macro implementation is forced on. */ #ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED @@ -100,28 +136,13 @@ * may be changed on a per-file basis when compiling against libpng. */ -/* The PNGARG macro protects us against machines that don't have function - * prototypes (ie K&R style headers). If your compiler does not handle - * function prototypes, define this macro and use the included ansi2knr. - * I've always been able to use _NO_PROTO as the indicator, but you may - * need to drag the empty declaration out in front of here, or change the - * ifdef to suit your own needs. +/* The PNGARG macro was used in versions of libpng prior to 1.6.0 to protect + * against legacy (pre ISOC90) compilers that did not understand function + * prototypes. It is not required for modern C compilers. */ #ifndef PNGARG - -# ifdef OF /* zlib prototype munger */ -# define PNGARG(arglist) OF(arglist) -# else - -# ifdef _NO_PROTO -# define PNGARG(arglist) () -# else -# define PNGARG(arglist) arglist -# endif /* _NO_PROTO */ - -# endif /* OF */ - -#endif /* PNGARG */ +# define PNGARG(arglist) arglist +#endif /* Function calling conventions. * ============================= @@ -192,7 +213,9 @@ * 'type', compiler specific. * * PNG_DLL_EXPORT Set to the magic to use during a libpng build to - * make a symbol exported from the DLL. + * make a symbol exported from the DLL. Not used in the + * public header files; see pngpriv.h for how it is used + * in the libpng build. * * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come * from a DLL - used to define PNG_IMPEXP when @@ -203,18 +226,16 @@ * ========================== * This code is used at build time to find PNG_IMPEXP, the API settings * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL - * import processing is possible. On Windows/x86 systems it also sets + * import processing is possible. On Windows systems it also sets * compiler-specific macros to the values required to change the calling * conventions of the various functions. */ -#if ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\ - defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) ) &&\ - ( defined(_X86_) || defined(_X64_) || defined(_M_IX86) ||\ - defined(_M_X64) || defined(_M_IA64) ) - /* Windows system (DOS doesn't support DLLs) running on x86/x64. Includes - * builds under Cygwin or MinGW. Also includes Watcom builds but these need - * special treatment because they are not compatible with GCC or Visual C - * because of different calling conventions. +#if defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\ + defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) + /* Windows system (DOS doesn't support DLLs). Includes builds under Cygwin or + * MinGW on any architecture currently supported by Windows. Also includes + * Watcom builds but these need special treatment because they are not + * compatible with GCC or Visual C because of different calling conventions. */ # if PNG_API_RULE == 2 /* If this line results in an error, either because __watcall is not @@ -225,9 +246,12 @@ # define PNGCAPI __watcall # endif -# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800)) +# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800)) # define PNGCAPI __cdecl # if PNG_API_RULE == 1 + /* If this line results in an error __stdcall is not understood and + * PNG_API_RULE should not have been set to '1'. + */ # define PNGAPI __stdcall # endif # else @@ -242,10 +266,11 @@ # define PNGAPI _stdcall # endif # endif /* compiler/api */ + /* NOTE: PNGCBAPI always defaults to PNGCAPI. */ # if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD) - ERROR: PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed +# error "PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed" # endif # if (defined(_MSC_VER) && _MSC_VER < 800) ||\ @@ -265,7 +290,7 @@ # endif # endif /* compiler */ -#else /* !Windows/x86 */ +#else /* !Windows */ # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) # define PNGAPI _System # else /* !Windows/x86 && !OS/2 */ @@ -286,25 +311,14 @@ # define PNGAPI PNGCAPI #endif -/* The default for PNG_IMPEXP depends on whether the library is - * being built or used. +/* PNG_IMPEXP may be set on the compilation system command line or (if not set) + * then in an internal header file when building the library, otherwise (when + * using the library) it is set here. */ #ifndef PNG_IMPEXP -# ifdef PNGLIB_BUILD - /* Building the library */ -# if (defined(DLL_EXPORT)/*from libtool*/ ||\ - defined(_WINDLL) || defined(_DLL) || defined(__DLL__) ||\ - defined(_USRDLL) ||\ - defined(PNG_BUILD_DLL)) && defined(PNG_DLL_EXPORT) - /* Building a DLL. */ -# define PNG_IMPEXP PNG_DLL_EXPORT -# endif /* DLL */ -# else - /* Using the library */ -# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT) - /* This forces use of a DLL, disallowing static linking */ -# define PNG_IMPEXP PNG_DLL_IMPORT -# endif +# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT) + /* This forces use of a DLL, disallowing static linking */ +# define PNG_IMPEXP PNG_DLL_IMPORT # endif # ifndef PNG_IMPEXP @@ -370,26 +384,48 @@ #ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED /* Support for compiler specific function attributes. These are used - * so that where compiler support is available incorrect use of API + * so that where compiler support is available, incorrect use of API * functions in png.h will generate compiler warnings. Added at libpng - * version 1.2.41. + * version 1.2.41. Disabling these removes the warnings but may also produce + * less efficient code. */ -# if defined(__GNUC__) +# if defined(__clang__) && defined(__has_attribute) + /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */ +# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__) +# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) +# endif +# if !defined(PNG_NORETURN) && __has_attribute(__noreturn__) +# define PNG_NORETURN __attribute__((__noreturn__)) +# endif +# if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__) +# define PNG_ALLOCATED __attribute__((__malloc__)) +# endif +# if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__) +# define PNG_DEPRECATED __attribute__((__deprecated__)) +# endif +# if !defined(PNG_PRIVATE) +# ifdef __has_extension +# if __has_extension(attribute_unavailable_with_message) +# define PNG_PRIVATE __attribute__((__unavailable__(\ + "This function is not exported by libpng."))) +# endif +# endif +# endif +# ifndef PNG_RESTRICT +# define PNG_RESTRICT __restrict +# endif + +# elif defined(__GNUC__) # ifndef PNG_USE_RESULT # define PNG_USE_RESULT __attribute__((__warn_unused_result__)) # endif # ifndef PNG_NORETURN # define PNG_NORETURN __attribute__((__noreturn__)) # endif -# ifndef PNG_ALLOCATED -# define PNG_ALLOCATED __attribute__((__malloc__)) -# endif - - /* This specifically protects structure members that should only be - * accessed from within the library, therefore should be empty during - * a library build. - */ -# ifndef PNGLIB_BUILD +# if __GNUC__ >= 3 +# ifndef PNG_ALLOCATED +# define PNG_ALLOCATED __attribute__((__malloc__)) +# endif # ifndef PNG_DEPRECATED # define PNG_DEPRECATED __attribute__((__deprecated__)) # endif @@ -402,10 +438,14 @@ __attribute__((__deprecated__)) # endif # endif -# endif /* PNGLIB_BUILD */ -# endif /* __GNUC__ */ +# if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1)) +# ifndef PNG_RESTRICT +# define PNG_RESTRICT __restrict +# endif +# endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */ +# endif /* __GNUC__ >= 3 */ -# if defined(_MSC_VER) && (_MSC_VER >= 1300) +# elif defined(_MSC_VER) && (_MSC_VER >= 1300) # ifndef PNG_USE_RESULT # define PNG_USE_RESULT /* not supported */ # endif @@ -417,20 +457,23 @@ # define PNG_ALLOCATED __declspec(restrict) # endif # endif +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __declspec(deprecated) +# endif +# ifndef PNG_PRIVATE +# define PNG_PRIVATE __declspec(deprecated) +# endif +# ifndef PNG_RESTRICT +# if (_MSC_VER >= 1400) +# define PNG_RESTRICT __restrict +# endif +# endif - /* This specifically protects structure members that should only be - * accessed from within the library, therefore should be empty during - * a library build. - */ -# ifndef PNGLIB_BUILD -# ifndef PNG_DEPRECATED -# define PNG_DEPRECATED __declspec(deprecated) -# endif -# ifndef PNG_PRIVATE -# define PNG_PRIVATE __declspec(deprecated) -# endif -# endif /* PNGLIB_BUILD */ -# endif /* _MSC_VER */ +# elif defined(__WATCOMC__) +# ifndef PNG_RESTRICT +# define PNG_RESTRICT __restrict +# endif +# endif #endif /* PNG_PEDANTIC_WARNINGS */ #ifndef PNG_DEPRECATED @@ -448,10 +491,14 @@ #ifndef PNG_PRIVATE # define PNG_PRIVATE /* This is a private libpng function */ #endif +#ifndef PNG_RESTRICT +# define PNG_RESTRICT /* The C99 "restrict" feature */ +#endif + #ifndef PNG_FP_EXPORT /* A floating point API. */ # ifdef PNG_FLOATING_POINT_SUPPORTED # define PNG_FP_EXPORT(ordinal, type, name, args)\ - PNG_EXPORT(ordinal, type, name, args) + PNG_EXPORT(ordinal, type, name, args); # else /* No floating point APIs */ # define PNG_FP_EXPORT(ordinal, type, name, args) # endif @@ -459,189 +506,167 @@ #ifndef PNG_FIXED_EXPORT /* A fixed point API. */ # ifdef PNG_FIXED_POINT_SUPPORTED # define PNG_FIXED_EXPORT(ordinal, type, name, args)\ - PNG_EXPORT(ordinal, type, name, args) + PNG_EXPORT(ordinal, type, name, args); # else /* No fixed point APIs */ # define PNG_FIXED_EXPORT(ordinal, type, name, args) # endif #endif -/* The following uses const char * instead of char * for error - * and warning message functions, so some compilers won't complain. - * If you do not want to use const, define PNG_NO_CONST here. +#ifndef PNG_BUILDING_SYMBOL_TABLE +/* Some typedefs to get us started. These should be safe on most of the common + * platforms. * - * This should not change how the APIs are called, so it can be done - * on a per-file basis in the application. + * png_uint_32 and png_int_32 may, currently, be larger than required to hold a + * 32-bit value however this is not normally advisable. + * + * png_uint_16 and png_int_16 should always be two bytes in size - this is + * verified at library build time. + * + * png_byte must always be one byte in size. + * + * The checks below use constants from limits.h, as defined by the ISOC90 + * standard. */ -#ifndef PNG_CONST -# ifndef PNG_NO_CONST -# define PNG_CONST const -# else -# define PNG_CONST -# endif +#if CHAR_BIT == 8 && UCHAR_MAX == 255 + typedef unsigned char png_byte; +#else +# error "libpng requires 8 bit bytes" #endif -/* Some typedefs to get us started. These should be safe on most of the - * common platforms. The typedefs should be at least as large as the - * numbers suggest (a png_uint_32 must be at least 32 bits long), but they - * don't have to be exactly that size. Some compilers dislike passing - * unsigned shorts as function parameters, so you may be better off using - * unsigned int for png_uint_16. - */ - -#if defined(INT_MAX) && (INT_MAX > 0x7ffffffeL) -typedef unsigned int png_uint_32; -typedef int png_int_32; +#if INT_MIN == -32768 && INT_MAX == 32767 + typedef int png_int_16; +#elif SHRT_MIN == -32768 && SHRT_MAX == 32767 + typedef short png_int_16; #else -typedef unsigned long png_uint_32; -typedef long png_int_32; +# error "libpng requires a signed 16 bit type" #endif -typedef unsigned short png_uint_16; -typedef short png_int_16; -typedef unsigned char png_byte; -#ifdef PNG_NO_SIZE_T -typedef unsigned int png_size_t; +#if UINT_MAX == 65535 + typedef unsigned int png_uint_16; +#elif USHRT_MAX == 65535 + typedef unsigned short png_uint_16; #else +# error "libpng requires an unsigned 16 bit type" +#endif + +#if INT_MIN < -2147483646 && INT_MAX > 2147483646 + typedef int png_int_32; +#elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646 + typedef long int png_int_32; +#else +# error "libpng requires a signed 32 bit (or more) type" +#endif + +#if UINT_MAX > 4294967294 + typedef unsigned int png_uint_32; +#elif ULONG_MAX > 4294967294 + typedef unsigned long int png_uint_32; +#else +# error "libpng requires an unsigned 32 bit (or more) type" +#endif + +/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however, + * requires an ISOC90 compiler and relies on consistent behavior of sizeof. + */ typedef size_t png_size_t; -#endif -#define png_sizeof(x) (sizeof (x)) +typedef ptrdiff_t png_ptrdiff_t; -/* The following is needed for medium model support. It cannot be in the - * pngpriv.h header. Needs modification for other compilers besides - * MSC. Model independent support declares all arrays and pointers to be - * large using the far keyword. The zlib version used must also support - * model independent data. As of version zlib 1.0.4, the necessary changes - * have been made in zlib. The USE_FAR_KEYWORD define triggers other - * changes that are needed. (Tim Wegner) +/* libpng needs to know the maximum value of 'size_t' and this controls the + * definition of png_alloc_size_t, below. This maximum value of size_t limits + * but does not control the maximum allocations the library makes - there is + * direct application control of this through png_set_user_limits(). */ - -/* Separate compiler dependencies (problem here is that zlib.h always - * defines FAR. (SJT) - */ -#ifdef __BORLANDC__ -# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) -# define LDATA 1 -# else -# define LDATA 0 -# endif - /* GRR: why is Cygwin in here? Cygwin is not Borland C... */ -# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) -# define PNG_MAX_MALLOC_64K /* only used in build */ -# if (LDATA != 1) -# ifndef FAR -# define FAR __far -# endif -# define USE_FAR_KEYWORD -# endif /* LDATA != 1 */ - /* Possibly useful for moving data out of default segment. - * Uncomment it if you want. Could also define FARDATA as - * const if your compiler supports it. (SJT) -# define FARDATA FAR - */ -# endif /* __WIN32__, __FLAT__, __CYGWIN__ */ -#endif /* __BORLANDC__ */ - - -/* Suggest testing for specific compiler first before testing for - * FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM, - * making reliance oncertain keywords suspect. (SJT) - */ - -/* MSC Medium model */ -#ifdef FAR -# ifdef M_I86MM -# define USE_FAR_KEYWORD -# define FARDATA FAR -# include +#ifndef PNG_SMALL_SIZE_T + /* Compiler specific tests for systems where size_t is known to be less than + * 32 bits (some of these systems may no longer work because of the lack of + * 'far' support; see above.) + */ +# if (defined(__TURBOC__) && !defined(__FLAT__)) ||\ + (defined(_MSC_VER) && defined(MAXSEG_64K)) +# define PNG_SMALL_SIZE_T # endif #endif -/* SJT: default case */ -#ifndef FAR -# define FAR +/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, and no + * smaller than png_uint_32. Casts from png_size_t or png_uint_32 to + * png_alloc_size_t are not necessary; in fact, it is recommended not to use + * them at all so that the compiler can complain when something turns out to be + * problematic. + * + * Casts in the other direction (from png_alloc_size_t to png_size_t or + * png_uint_32) should be explicitly applied; however, we do not expect to + * encounter practical situations that require such conversions. + * + * PNG_SMALL_SIZE_T must be defined if the maximum value of size_t is less than + * 4294967295 - i.e. less than the maximum value of png_uint_32. + */ +#ifdef PNG_SMALL_SIZE_T + typedef png_uint_32 png_alloc_size_t; +#else + typedef png_size_t png_alloc_size_t; #endif -/* At this point FAR is always defined */ -#ifndef FARDATA -# define FARDATA -#endif +/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler + * implementations of Intel CPU specific support of user-mode segmented address + * spaces, where 16-bit pointers address more than 65536 bytes of memory using + * separate 'segment' registers. The implementation requires two different + * types of pointer (only one of which includes the segment value.) + * + * If required this support is available in version 1.2 of libpng and may be + * available in versions through 1.5, although the correctness of the code has + * not been verified recently. + */ -/* Typedef for floating-point numbers that are converted - * to fixed-point with a multiple of 100,000, e.g., gamma +/* Typedef for floating-point numbers that are converted to fixed-point with a + * multiple of 100,000, e.g., gamma */ typedef png_int_32 png_fixed_point; /* Add typedefs for pointers */ -typedef void FAR * png_voidp; -typedef PNG_CONST void FAR * png_const_voidp; -typedef png_byte FAR * png_bytep; -typedef PNG_CONST png_byte FAR * png_const_bytep; -typedef png_uint_32 FAR * png_uint_32p; -typedef PNG_CONST png_uint_32 FAR * png_const_uint_32p; -typedef png_int_32 FAR * png_int_32p; -typedef PNG_CONST png_int_32 FAR * png_const_int_32p; -typedef png_uint_16 FAR * png_uint_16p; -typedef PNG_CONST png_uint_16 FAR * png_const_uint_16p; -typedef png_int_16 FAR * png_int_16p; -typedef PNG_CONST png_int_16 FAR * png_const_int_16p; -typedef char FAR * png_charp; -typedef PNG_CONST char FAR * png_const_charp; -typedef png_fixed_point FAR * png_fixed_point_p; -typedef PNG_CONST png_fixed_point FAR * png_const_fixed_point_p; -typedef png_size_t FAR * png_size_tp; -typedef PNG_CONST png_size_t FAR * png_const_size_tp; +typedef void * png_voidp; +typedef const void * png_const_voidp; +typedef png_byte * png_bytep; +typedef const png_byte * png_const_bytep; +typedef png_uint_32 * png_uint_32p; +typedef const png_uint_32 * png_const_uint_32p; +typedef png_int_32 * png_int_32p; +typedef const png_int_32 * png_const_int_32p; +typedef png_uint_16 * png_uint_16p; +typedef const png_uint_16 * png_const_uint_16p; +typedef png_int_16 * png_int_16p; +typedef const png_int_16 * png_const_int_16p; +typedef char * png_charp; +typedef const char * png_const_charp; +typedef png_fixed_point * png_fixed_point_p; +typedef const png_fixed_point * png_const_fixed_point_p; +typedef png_size_t * png_size_tp; +typedef const png_size_t * png_const_size_tp; #ifdef PNG_STDIO_SUPPORTED typedef FILE * png_FILE_p; #endif #ifdef PNG_FLOATING_POINT_SUPPORTED -typedef double FAR * png_doublep; -typedef PNG_CONST double FAR * png_const_doublep; +typedef double * png_doublep; +typedef const double * png_const_doublep; #endif /* Pointers to pointers; i.e. arrays */ -typedef png_byte FAR * FAR * png_bytepp; -typedef png_uint_32 FAR * FAR * png_uint_32pp; -typedef png_int_32 FAR * FAR * png_int_32pp; -typedef png_uint_16 FAR * FAR * png_uint_16pp; -typedef png_int_16 FAR * FAR * png_int_16pp; -typedef PNG_CONST char FAR * FAR * png_const_charpp; -typedef char FAR * FAR * png_charpp; -typedef png_fixed_point FAR * FAR * png_fixed_point_pp; +typedef png_byte * * png_bytepp; +typedef png_uint_32 * * png_uint_32pp; +typedef png_int_32 * * png_int_32pp; +typedef png_uint_16 * * png_uint_16pp; +typedef png_int_16 * * png_int_16pp; +typedef const char * * png_const_charpp; +typedef char * * png_charpp; +typedef png_fixed_point * * png_fixed_point_pp; #ifdef PNG_FLOATING_POINT_SUPPORTED -typedef double FAR * FAR * png_doublepp; +typedef double * * png_doublepp; #endif /* Pointers to pointers to pointers; i.e., pointer to array */ -typedef char FAR * FAR * FAR * png_charppp; +typedef char * * * png_charppp; -/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, - * and no smaller than png_uint_32. Casts from png_size_t or png_uint_32 - * to png_alloc_size_t are not necessary; in fact, it is recommended - * not to use them at all so that the compiler can complain when something - * turns out to be problematic. - * Casts in the other direction (from png_alloc_size_t to png_size_t or - * png_uint_32) should be explicitly applied; however, we do not expect - * to encounter practical situations that require such conversions. - */ -#if defined(__TURBOC__) && !defined(__FLAT__) - typedef unsigned long png_alloc_size_t; -#else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - typedef unsigned long png_alloc_size_t; -# else - /* This is an attempt to detect an old Windows system where (int) is - * actually 16 bits, in that case png_malloc must have an argument with a - * bigger size to accommodate the requirements of the library. - */ -# if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) && \ - (!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL) - typedef DWORD png_alloc_size_t; -# else - typedef png_size_t png_alloc_size_t; -# endif -# endif -#endif +#endif /* PNG_BUILDING_SYMBOL_TABLE */ #endif /* PNGCONF_H */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngdebug.h b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngdebug.h index 33e6fca2864..d4af91dcd5c 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngdebug.h +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngdebug.h @@ -29,11 +29,11 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Copyright (c) 1998-2013 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.6.8 [December 19, 2013] * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer @@ -53,7 +53,7 @@ * (actually ((void)0)). * * level: level of detail of message, starting at 0. A level 'n' - * message is preceded by 'n' tab characters (not implemented + * message is preceded by 'n' 3-space indentations (not implemented * on Microsoft compilers unless PNG_DEBUG_FILE is also * defined, to allow debug DLL compilation with no standard IO). * message: a printf(3) style text string. A trailing '\n' is added @@ -105,32 +105,29 @@ # endif /* PNG_DEBUG_FILE */ # if (PNG_DEBUG > 1) -/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on - * non-ISO compilers - */ # ifdef __STDC__ # ifndef png_debug # define png_debug(l,m) \ do { \ int num_tabs=l; \ - fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \ + fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ + (num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \ } while (0) # endif # ifndef png_debug1 # define png_debug1(l,m,p1) \ do { \ int num_tabs=l; \ - fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \ + fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ + (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \ } while (0) # endif # ifndef png_debug2 # define png_debug2(l,m,p1,p2) \ do { \ int num_tabs=l; \ - fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \ + fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ + (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\ } while (0) # endif # else /* __STDC __ */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngerror.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngerror.c index 2fbcb6e74b2..7ab1cfeeb7e 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngerror.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngerror.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -48,14 +48,14 @@ #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -static PNG_FUNCTION(void, png_default_error,PNGARG((png_structp png_ptr, +static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr, png_const_charp error_message)),PNG_NORETURN); #ifdef PNG_WARNINGS_SUPPORTED static void /* PRIVATE */ -png_default_warning PNGARG((png_structp png_ptr, +png_default_warning PNGARG((png_const_structrp png_ptr, png_const_charp warning_message)); -#endif /* PNG_WARNINGS_SUPPORTED */ +#endif /* WARNINGS */ /* This function is called whenever there is a fatal error. This function * should not be changed. If there is a need to handle errors differently, @@ -64,14 +64,15 @@ png_default_warning PNGARG((png_structp png_ptr, */ #ifdef PNG_ERROR_TEXT_SUPPORTED PNG_FUNCTION(void,PNGAPI -png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) +png_error,(png_const_structrp png_ptr, png_const_charp error_message), + PNG_NORETURN) { #ifdef PNG_ERROR_NUMBERS_SUPPORTED char msg[16]; if (png_ptr != NULL) { - if (png_ptr->flags& - (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) + if ((png_ptr->flags & + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0 { if (*error_message == PNG_LITERAL_SHARP) { @@ -81,7 +82,7 @@ png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) if (error_message[offset] == ' ') break; - if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) + if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0) { int i; for (i = 0; i < offset - 1; i++) @@ -96,7 +97,7 @@ png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) else { - if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) + if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0) { msg[0] = '0'; msg[1] = '\0'; @@ -107,7 +108,8 @@ png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) } #endif if (png_ptr != NULL && png_ptr->error_fn != NULL) - (*(png_ptr->error_fn))(png_ptr, error_message); + (*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr), + error_message); /* If the custom handler doesn't exist, or if it returns, use the default handler, which will not return. */ @@ -115,7 +117,7 @@ png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) } #else PNG_FUNCTION(void,PNGAPI -png_err,(png_structp png_ptr),PNG_NORETURN) +png_err,(png_const_structrp png_ptr),PNG_NORETURN) { /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed * erroneously as '\0', instead of the empty string "". This was @@ -123,13 +125,13 @@ png_err,(png_structp png_ptr),PNG_NORETURN) * will crash in this case. */ if (png_ptr != NULL && png_ptr->error_fn != NULL) - (*(png_ptr->error_fn))(png_ptr, ""); + (*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr), ""); /* If the custom handler doesn't exist, or if it returns, use the default handler, which will not return. */ png_default_error(png_ptr, ""); } -#endif /* PNG_ERROR_TEXT_SUPPORTED */ +#endif /* ERROR_TEXT */ /* Utility to safely appends strings to a buffer. This never errors out so * error checking is not required in the caller. @@ -178,7 +180,7 @@ png_format_number(png_const_charp start, png_charp end, int format, case PNG_NUMBER_FORMAT_fixed: /* Needs five digits (the fraction) */ mincount = 5; - if (output || number % 10 != 0) + if (output != 0 || number % 10 != 0) { *--end = digits[number % 10]; output = 1; @@ -189,7 +191,7 @@ png_format_number(png_const_charp start, png_charp end, int format, case PNG_NUMBER_FORMAT_02u: /* Expects at least 2 digits. */ mincount = 2; - /* fall through */ + /* FALL THROUGH */ case PNG_NUMBER_FORMAT_u: *--end = digits[number % 10]; @@ -199,7 +201,7 @@ png_format_number(png_const_charp start, png_charp end, int format, case PNG_NUMBER_FORMAT_02x: /* This format expects at least two digits */ mincount = 2; - /* fall through */ + /* FALL THROUGH */ case PNG_NUMBER_FORMAT_x: *--end = digits[number & 0xf]; @@ -215,13 +217,13 @@ png_format_number(png_const_charp start, png_charp end, int format, ++count; /* Float a fixed number here: */ - if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start) + if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start)) { /* End of the fraction, but maybe nothing was output? In that case * drop the decimal point. If the number is a true zero handle that * here. */ - if (output) + if (output != 0) *--end = '.'; else if (number == 0) /* and !output */ *--end = '0'; @@ -239,14 +241,14 @@ png_format_number(png_const_charp start, png_charp end, int format, * png_set_error_fn() to replace the warning function at run-time. */ void PNGAPI -png_warning(png_structp png_ptr, png_const_charp warning_message) +png_warning(png_const_structrp png_ptr, png_const_charp warning_message) { int offset = 0; if (png_ptr != NULL) { #ifdef PNG_ERROR_NUMBERS_SUPPORTED - if (png_ptr->flags& - (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) + if ((png_ptr->flags & + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0) #endif { if (*warning_message == PNG_LITERAL_SHARP) @@ -258,7 +260,8 @@ png_warning(png_structp png_ptr, png_const_charp warning_message) } } if (png_ptr != NULL && png_ptr->warning_fn != NULL) - (*(png_ptr->warning_fn))(png_ptr, warning_message + offset); + (*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr), + warning_message + offset); else png_default_warning(png_ptr, warning_message + offset); } @@ -306,38 +309,43 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format, } void -png_formatted_warning(png_structp png_ptr, png_warning_parameters p, +png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p, png_const_charp message) { - /* The internal buffer is just 128 bytes - enough for all our messages, - * overflow doesn't happen because this code checks! + /* The internal buffer is just 192 bytes - enough for all our messages, + * overflow doesn't happen because this code checks! If someone figures + * out how to send us a message longer than 192 bytes, all that will + * happen is that the message will be truncated appropriately. */ - size_t i; - char msg[128]; + size_t i = 0; /* Index in the msg[] buffer: */ + char msg[192]; - for (i=0; i<(sizeof msg)-1 && *message != '\0'; ++i) + /* Each iteration through the following loop writes at most one character + * to msg[i++] then returns here to validate that there is still space for + * the trailing '\0'. It may (in the case of a parameter) read more than + * one character from message[]; it must check for '\0' and continue to the + * test if it finds the end of string. + */ + while (i<(sizeof msg)-1 && *message != '\0') { - if (*message == '@') + /* '@' at end of string is now just printed (previously it was skipped); + * it is an error in the calling code to terminate the string with @. + */ + if (p != NULL && *message == '@' && message[1] != '\0') { - int parameter = -1; - switch (*++message) - { - case '1': - parameter = 0; - break; + int parameter_char = *++message; /* Consume the '@' */ + static const char valid_parameters[] = "123456789"; + int parameter = 0; - case '2': - parameter = 1; - break; + /* Search for the parameter digit, the index in the string is the + * parameter to use. + */ + while (valid_parameters[parameter] != parameter_char && + valid_parameters[parameter] != '\0') + ++parameter; - case '\0': - continue; /* To break out of the for loop above. */ - - default: - break; - } - - if (parameter >= 0 && parameter < PNG_WARNING_PARAMETER_COUNT) + /* If the parameter digit is out of range it will just get printed. */ + if (parameter < PNG_WARNING_PARAMETER_COUNT) { /* Append this parameter */ png_const_charp parm = p[parameter]; @@ -347,47 +355,101 @@ png_formatted_warning(png_structp png_ptr, png_warning_parameters p, * that parm[] has been initialized, so there is no guarantee of a * trailing '\0': */ - for (; i<(sizeof msg)-1 && parm != '\0' && parm < pend; ++i) - msg[i] = *parm++; + while (i<(sizeof msg)-1 && *parm != '\0' && parm < pend) + msg[i++] = *parm++; + /* Consume the parameter digit too: */ ++message; continue; } /* else not a parameter and there is a character after the @ sign; just - * copy that. + * copy that. This is known not to be '\0' because of the test above. */ } /* At this point *message can't be '\0', even in the bad parameter case * above where there is a lone '@' at the end of the message string. */ - msg[i] = *message++; + msg[i++] = *message++; } /* i is always less than (sizeof msg), so: */ msg[i] = '\0'; - /* And this is the formatted message: */ + /* And this is the formatted message. It may be larger than + * PNG_MAX_ERROR_TEXT, but that is only used for 'chunk' errors and these + * are not (currently) formatted. + */ png_warning(png_ptr, msg); } -#endif /* PNG_WARNINGS_SUPPORTED */ +#endif /* WARNINGS */ #ifdef PNG_BENIGN_ERRORS_SUPPORTED void PNGAPI -png_benign_error(png_structp png_ptr, png_const_charp error_message) +png_benign_error(png_const_structrp png_ptr, png_const_charp error_message) { - if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) + if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0) + { +# ifdef PNG_READ_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && + png_ptr->chunk_name != 0) + png_chunk_warning(png_ptr, error_message); + else +# endif + png_warning(png_ptr, error_message); + } + + else + { +# ifdef PNG_READ_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && + png_ptr->chunk_name != 0) + png_chunk_error(png_ptr, error_message); + else +# endif + png_error(png_ptr, error_message); + } + +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(error_message) +# endif +} + +void /* PRIVATE */ +png_app_warning(png_const_structrp png_ptr, png_const_charp error_message) +{ + if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0) png_warning(png_ptr, error_message); else png_error(png_ptr, error_message); -} -#endif +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(error_message) +# endif +} + +void /* PRIVATE */ +png_app_error(png_const_structrp png_ptr, png_const_charp error_message) +{ + if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0) + png_warning(png_ptr, error_message); + else + png_error(png_ptr, error_message); + +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(error_message) +# endif +} +#endif /* BENIGN_ERRORS */ + +#define PNG_MAX_ERROR_TEXT 196 /* Currently limited by profile_error in png.c */ +#if defined(PNG_WARNINGS_SUPPORTED) || \ + (defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)) /* These utilities are used internally to build an error message that relates * to the current chunk. The chunk name comes from png_ptr->chunk_name, - * this is used to prefix the message. The message is limited in length - * to 63 bytes, the name characters are output as hex digits wrapped in [] + * which is used to prefix the message. The message is limited in length + * to 63 bytes. The name characters are output as hex digits wrapped in [] * if the character is invalid. */ #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) @@ -396,18 +458,19 @@ static PNG_CONST char png_digit[16] = { 'A', 'B', 'C', 'D', 'E', 'F' }; -#define PNG_MAX_ERROR_TEXT 64 -#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED) static void /* PRIVATE */ -png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp +png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp error_message) { - int iout = 0, iin = 0; + png_uint_32 chunk_name = png_ptr->chunk_name; + int iout = 0, ishift = 24; - while (iin < 4) + while (ishift >= 0) { - int c = png_ptr->chunk_name[iin++]; - if (isnonalpha(c)) + int c = (int)(chunk_name >> ishift) & 0xff; + + ishift -= 8; + if (isnonalpha(c) != 0) { buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET; buffer[iout++] = png_digit[(c & 0xf0) >> 4]; @@ -417,7 +480,7 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp else { - buffer[iout++] = (png_byte)c; + buffer[iout++] = (char)c; } } @@ -426,10 +489,11 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp else { + int iin = 0; + buffer[iout++] = ':'; buffer[iout++] = ' '; - iin = 0; while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0') buffer[iout++] = error_message[iin++]; @@ -437,11 +501,11 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp buffer[iout] = '\0'; } } -#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */ +#endif /* WARNINGS || ERROR_TEXT */ #if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) PNG_FUNCTION(void,PNGAPI -png_chunk_error,(png_structp png_ptr, png_const_charp error_message), +png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message), PNG_NORETURN) { char msg[18+PNG_MAX_ERROR_TEXT]; @@ -454,11 +518,11 @@ png_chunk_error,(png_structp png_ptr, png_const_charp error_message), png_error(png_ptr, msg); } } -#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */ +#endif /* READ && ERROR_TEXT */ #ifdef PNG_WARNINGS_SUPPORTED void PNGAPI -png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) +png_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message) { char msg[18+PNG_MAX_ERROR_TEXT]; if (png_ptr == NULL) @@ -470,38 +534,83 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) png_warning(png_ptr, msg); } } -#endif /* PNG_WARNINGS_SUPPORTED */ +#endif /* WARNINGS */ #ifdef PNG_READ_SUPPORTED #ifdef PNG_BENIGN_ERRORS_SUPPORTED void PNGAPI -png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message) +png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp + error_message) { - if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) + if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0) png_chunk_warning(png_ptr, error_message); else png_chunk_error(png_ptr, error_message); + +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(error_message) +# endif } #endif -#endif /* PNG_READ_SUPPORTED */ +#endif /* READ */ + +void /* PRIVATE */ +png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error) +{ +# ifndef PNG_WARNINGS_SUPPORTED + PNG_UNUSED(message) +# endif + + /* This is always supported, but for just read or just write it + * unconditionally does the right thing. + */ +# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED) + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) +# endif + +# ifdef PNG_READ_SUPPORTED + { + if (error < PNG_CHUNK_ERROR) + png_chunk_warning(png_ptr, message); + + else + png_chunk_benign_error(png_ptr, message); + } +# endif + +# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED) + else if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) +# endif + +# ifdef PNG_WRITE_SUPPORTED + { + if (error < PNG_CHUNK_WRITE_ERROR) + png_app_warning(png_ptr, message); + + else + png_app_error(png_ptr, message); + } +# endif +} #ifdef PNG_ERROR_TEXT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED PNG_FUNCTION(void, -png_fixed_error,(png_structp png_ptr, png_const_charp name),PNG_NORETURN) +png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN) { # define fixed_message "fixed point overflow in " # define fixed_message_ln ((sizeof fixed_message)-1) int iin; char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT]; - png_memcpy(msg, fixed_message, fixed_message_ln); + memcpy(msg, fixed_message, fixed_message_ln); iin = 0; - if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0) - { - msg[fixed_message_ln + iin] = name[iin]; - ++iin; - } + if (name != NULL) + while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0) + { + msg[fixed_message_ln + iin] = name[iin]; + ++iin; + } msg[fixed_message_ln + iin] = 0; png_error(png_ptr, msg); } @@ -513,14 +622,111 @@ png_fixed_error,(png_structp png_ptr, png_const_charp name),PNG_NORETURN) * otherwise it is necessary for png_default_error to be overridden. */ jmp_buf* PNGAPI -png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn, +png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn, size_t jmp_buf_size) { - if (png_ptr == NULL || jmp_buf_size != png_sizeof(jmp_buf)) + /* From libpng 1.6.0 the app gets one chance to set a 'jmpbuf_size' value + * and it must not change after that. Libpng doesn't care how big the + * buffer is, just that it doesn't change. + * + * If the buffer size is no *larger* than the size of jmp_buf when libpng is + * compiled a built in jmp_buf is returned; this preserves the pre-1.6.0 + * semantics that this call will not fail. If the size is larger, however, + * the buffer is allocated and this may fail, causing the function to return + * NULL. + */ + if (png_ptr == NULL) return NULL; + if (png_ptr->jmp_buf_ptr == NULL) + { + png_ptr->jmp_buf_size = 0; /* not allocated */ + + if (jmp_buf_size <= (sizeof png_ptr->jmp_buf_local)) + png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local; + + else + { + png_ptr->jmp_buf_ptr = png_voidcast(jmp_buf *, + png_malloc_warn(png_ptr, jmp_buf_size)); + + if (png_ptr->jmp_buf_ptr == NULL) + return NULL; /* new NULL return on OOM */ + + png_ptr->jmp_buf_size = jmp_buf_size; + } + } + + else /* Already allocated: check the size */ + { + size_t size = png_ptr->jmp_buf_size; + + if (size == 0) + { + size = (sizeof png_ptr->jmp_buf_local); + if (png_ptr->jmp_buf_ptr != &png_ptr->jmp_buf_local) + { + /* This is an internal error in libpng: somehow we have been left + * with a stack allocated jmp_buf when the application regained + * control. It's always possible to fix this up, but for the moment + * this is a png_error because that makes it easy to detect. + */ + png_error(png_ptr, "Libpng jmp_buf still allocated"); + /* png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local; */ + } + } + + if (size != jmp_buf_size) + { + png_warning(png_ptr, "Application jmp_buf size changed"); + return NULL; /* caller will probably crash: no choice here */ + } + } + + /* Finally fill in the function, now we have a satisfactory buffer. It is + * valid to change the function on every call. + */ png_ptr->longjmp_fn = longjmp_fn; - return &png_ptr->longjmp_buffer; + return png_ptr->jmp_buf_ptr; +} + +void /* PRIVATE */ +png_free_jmpbuf(png_structrp png_ptr) +{ + if (png_ptr != NULL) + { + jmp_buf *jb = png_ptr->jmp_buf_ptr; + + /* A size of 0 is used to indicate a local, stack, allocation of the + * pointer; used here and in png.c + */ + if (jb != NULL && png_ptr->jmp_buf_size > 0) + { + + /* This stuff is so that a failure to free the error control structure + * does not leave libpng in a state with no valid error handling: the + * free always succeeds, if there is an error it gets ignored. + */ + if (jb != &png_ptr->jmp_buf_local) + { + /* Make an internal, libpng, jmp_buf to return here */ + jmp_buf free_jmp_buf; + + if (!setjmp(free_jmp_buf)) + { + png_ptr->jmp_buf_ptr = &free_jmp_buf; /* come back here */ + png_ptr->jmp_buf_size = 0; /* stack allocation */ + png_ptr->longjmp_fn = longjmp; + png_free(png_ptr, jb); /* Return to setjmp on error */ + } + } + } + + /* *Always* cancel everything out: */ + png_ptr->jmp_buf_size = 0; + png_ptr->jmp_buf_ptr = NULL; + png_ptr->longjmp_fn = 0; + } } #endif @@ -530,7 +736,7 @@ png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn, * error function pointer in png_set_error_fn(). */ static PNG_FUNCTION(void /* PRIVATE */, -png_default_error,(png_structp png_ptr, png_const_charp error_message), +png_default_error,(png_const_structrp png_ptr, png_const_charp error_message), PNG_NORETURN) { #ifdef PNG_CONSOLE_IO_SUPPORTED @@ -577,24 +783,23 @@ png_default_error,(png_structp png_ptr, png_const_charp error_message), } PNG_FUNCTION(void,PNGAPI -png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN) +png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN) { #ifdef PNG_SETJMP_SUPPORTED - if (png_ptr && png_ptr->longjmp_fn) - { -# ifdef USE_FAR_KEYWORD - { - jmp_buf tmp_jmpbuf; - png_memcpy(tmp_jmpbuf, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); - png_ptr->longjmp_fn(tmp_jmpbuf, val); - } - -# else - png_ptr->longjmp_fn(png_ptr->longjmp_buffer, val); -# endif - } + if (png_ptr != NULL && png_ptr->longjmp_fn != NULL && + png_ptr->jmp_buf_ptr != NULL) + png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val); +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(val) #endif - /* Here if not setjmp support or if png_ptr is null. */ + + /* If control reaches this point, png_longjmp() must not return. The only + * choice is to terminate the whole process (or maybe the thread); to do + * this the ANSI-C abort() function is used unless a different method is + * implemented by overriding the default configuration setting for + * PNG_ABORT(). + */ PNG_ABORT(); } @@ -605,7 +810,7 @@ png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN) * not used, but it is passed in case it may be useful. */ static void /* PRIVATE */ -png_default_warning(png_structp png_ptr, png_const_charp warning_message) +png_default_warning(png_const_structrp png_ptr, png_const_charp warning_message) { #ifdef PNG_CONSOLE_IO_SUPPORTED # ifdef PNG_ERROR_NUMBERS_SUPPORTED @@ -647,15 +852,15 @@ png_default_warning(png_structp png_ptr, png_const_charp warning_message) #endif PNG_UNUSED(png_ptr) /* Make compiler happy */ } -#endif /* PNG_WARNINGS_SUPPORTED */ +#endif /* WARNINGS */ /* This function is called when the application wants to use another method * of handling errors and warnings. Note that the error function MUST NOT * return to the calling routine or serious problems will occur. The return - * method used in the default routine calls longjmp(png_ptr->longjmp_buffer, 1) + * method used in the default routine calls longjmp(png_ptr->jmp_buf_ptr, 1) */ void PNGAPI -png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, +png_set_error_fn(png_structrp png_ptr, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn) { if (png_ptr == NULL) @@ -676,7 +881,7 @@ png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, * pointer before png_write_destroy and png_read_destroy are called. */ png_voidp PNGAPI -png_get_error_ptr(png_const_structp png_ptr) +png_get_error_ptr(png_const_structrp png_ptr) { if (png_ptr == NULL) return NULL; @@ -687,7 +892,7 @@ png_get_error_ptr(png_const_structp png_ptr) #ifdef PNG_ERROR_NUMBERS_SUPPORTED void PNGAPI -png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) +png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode) { if (png_ptr != NULL) { @@ -697,4 +902,90 @@ png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) } } #endif -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ + +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) + /* Currently the above both depend on SETJMP_SUPPORTED, however it would be + * possible to implement without setjmp support just so long as there is some + * way to handle the error return here: + */ +PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI +png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message), + PNG_NORETURN) +{ + const png_const_structrp png_ptr = png_nonconst_ptr; + png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr); + + /* An error is always logged here, overwriting anything (typically a warning) + * that is already there: + */ + if (image != NULL) + { + png_safecat(image->message, (sizeof image->message), 0, error_message); + image->warning_or_error |= PNG_IMAGE_ERROR; + + /* Retrieve the jmp_buf from within the png_control, making this work for + * C++ compilation too is pretty tricky: C++ wants a pointer to the first + * element of a jmp_buf, but C doesn't tell us the type of that. + */ + if (image->opaque != NULL && image->opaque->error_buf != NULL) + longjmp(png_control_jmp_buf(image->opaque), 1); + + /* Missing longjmp buffer, the following is to help debugging: */ + { + size_t pos = png_safecat(image->message, (sizeof image->message), 0, + "bad longjmp: "); + png_safecat(image->message, (sizeof image->message), pos, + error_message); + } + } + + /* Here on an internal programming error. */ + abort(); +} + +#ifdef PNG_WARNINGS_SUPPORTED +void /* PRIVATE */ PNGCBAPI +png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message) +{ + const png_const_structrp png_ptr = png_nonconst_ptr; + png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr); + + /* A warning is only logged if there is no prior warning or error. */ + if (image->warning_or_error == 0) + { + png_safecat(image->message, (sizeof image->message), 0, warning_message); + image->warning_or_error |= PNG_IMAGE_WARNING; + } +} +#endif + +int /* PRIVATE */ +png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg) +{ + volatile png_imagep image = image_in; + volatile int result; + volatile png_voidp saved_error_buf; + jmp_buf safe_jmpbuf; + + /* Safely execute function(arg) with png_error returning to this function. */ + saved_error_buf = image->opaque->error_buf; + result = setjmp(safe_jmpbuf) == 0; + + if (result != 0) + { + + image->opaque->error_buf = safe_jmpbuf; + result = function(arg); + } + + image->opaque->error_buf = saved_error_buf; + + /* And do the cleanup prior to any failure return. */ + if (result == 0) + png_image_free(image); + + return result; +} +#endif /* SIMPLIFIED READ || SIMPLIFIED_WRITE */ +#endif /* READ || WRITE */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngget.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngget.c index ea27004d0fc..c87fc907797 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngget.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngget.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.1 [February 3, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -45,7 +45,7 @@ #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) png_uint_32 PNGAPI -png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 flag) { if (png_ptr != NULL && info_ptr != NULL) @@ -55,7 +55,7 @@ png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr, } png_size_t PNGAPI -png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->rowbytes); @@ -65,7 +65,7 @@ png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr) #ifdef PNG_INFO_IMAGE_SUPPORTED png_bytepp PNGAPI -png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->row_pointers); @@ -77,7 +77,7 @@ png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr) #ifdef PNG_EASY_ACCESS_SUPPORTED /* Easy access to info, added in libpng-0.99 */ png_uint_32 PNGAPI -png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->width; @@ -86,7 +86,7 @@ png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr) } png_uint_32 PNGAPI -png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->height; @@ -95,7 +95,7 @@ png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr) } png_byte PNGAPI -png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->bit_depth; @@ -104,7 +104,7 @@ png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr) } png_byte PNGAPI -png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->color_type; @@ -113,7 +113,7 @@ png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr) } png_byte PNGAPI -png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->filter_type; @@ -122,7 +122,7 @@ png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr) } png_byte PNGAPI -png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->interlace_type; @@ -131,7 +131,7 @@ png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr) } png_byte PNGAPI -png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->compression_type; @@ -140,10 +140,12 @@ png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr) } png_uint_32 PNGAPI -png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp + info_ptr) { #ifdef PNG_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) { png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter"); @@ -151,16 +153,21 @@ png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) return (info_ptr->x_pixels_per_unit); } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) #endif return (0); } png_uint_32 PNGAPI -png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp + info_ptr) { #ifdef PNG_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) { png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter"); @@ -168,16 +175,20 @@ png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) return (info_ptr->y_pixels_per_unit); } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) #endif return (0); } png_uint_32 PNGAPI -png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr) { #ifdef PNG_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) { png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); @@ -185,6 +196,9 @@ png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit) return (info_ptr->x_pixels_per_unit); } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) #endif return (0); @@ -192,10 +206,12 @@ png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) #ifdef PNG_FLOATING_POINT_SUPPORTED float PNGAPI -png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp + info_ptr) { #ifdef PNG_READ_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) { png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); @@ -203,6 +219,9 @@ png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr) return ((float)((float)info_ptr->y_pixels_per_unit /(float)info_ptr->x_pixels_per_unit)); } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) #endif return ((float)0.0); @@ -211,14 +230,15 @@ png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr) #ifdef PNG_FIXED_POINT_SUPPORTED png_fixed_point PNGAPI -png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr, - png_const_infop info_ptr) +png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr, + png_const_inforp info_ptr) { #ifdef PNG_READ_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) - && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 - && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX - && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0 && + info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 && + info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX && + info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX) { png_fixed_point res; @@ -228,9 +248,12 @@ png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr, * range of 0..2^31-1; otherwise the cast might overflow. */ if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1, - (png_int_32)info_ptr->x_pixels_per_unit)) + (png_int_32)info_ptr->x_pixels_per_unit) != 0) return res; } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) #endif return 0; @@ -238,64 +261,80 @@ png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr, #endif png_int_32 PNGAPI -png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr) { #ifdef PNG_oFFs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0) { png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) return (info_ptr->x_offset); } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) #endif return (0); } png_int_32 PNGAPI -png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr) { #ifdef PNG_oFFs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0) { png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) return (info_ptr->y_offset); } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) #endif return (0); } png_int_32 PNGAPI -png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) { #ifdef PNG_oFFs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0) { png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels"); if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) return (info_ptr->x_offset); } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) #endif return (0); } png_int_32 PNGAPI -png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) { #ifdef PNG_oFFs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0) { png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels"); if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) return (info_ptr->y_offset); } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) #endif return (0); @@ -326,7 +365,7 @@ ppi_from_ppm(png_uint_32 ppm) */ png_fixed_point result; if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127, - 5000)) + 5000) != 0) return result; /* Overflow. */ @@ -335,26 +374,26 @@ ppi_from_ppm(png_uint_32 ppm) } png_uint_32 PNGAPI -png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) { return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr)); } png_uint_32 PNGAPI -png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) { return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr)); } png_uint_32 PNGAPI -png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) { return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr)); } #ifdef PNG_FIXED_POINT_SUPPORTED static png_fixed_point -png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns) +png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns) { /* Convert from metres * 1,000,000 to inches * 100,000, meters to * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127. @@ -365,8 +404,8 @@ png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns) } png_fixed_point PNGAPI -png_get_x_offset_inches_fixed(png_structp png_ptr, - png_const_infop info_ptr) +png_get_x_offset_inches_fixed(png_const_structrp png_ptr, + png_const_inforp info_ptr) { return png_fixed_inches_from_microns(png_ptr, png_get_x_offset_microns(png_ptr, info_ptr)); @@ -375,8 +414,8 @@ png_get_x_offset_inches_fixed(png_structp png_ptr, #ifdef PNG_FIXED_POINT_SUPPORTED png_fixed_point PNGAPI -png_get_y_offset_inches_fixed(png_structp png_ptr, - png_const_infop info_ptr) +png_get_y_offset_inches_fixed(png_const_structrp png_ptr, + png_const_inforp info_ptr) { return png_fixed_inches_from_microns(png_ptr, png_get_y_offset_microns(png_ptr, info_ptr)); @@ -385,7 +424,7 @@ png_get_y_offset_inches_fixed(png_structp png_ptr, #ifdef PNG_FLOATING_POINT_SUPPORTED float PNGAPI -png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) { /* To avoid the overflow do the conversion directly in floating * point. @@ -396,7 +435,7 @@ png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) #ifdef PNG_FLOATING_POINT_SUPPORTED float PNGAPI -png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) { /* To avoid the overflow do the conversion directly in floating * point. @@ -407,12 +446,13 @@ png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) #ifdef PNG_pHYs_SUPPORTED png_uint_32 PNGAPI -png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) { png_uint_32 retval = 0; - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) { png_debug1(1, "in %s retrieval function", "pHYs"); @@ -443,15 +483,16 @@ png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr, return (retval); } -#endif /* PNG_pHYs_SUPPORTED */ -#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */ +#endif /* pHYs */ +#endif /* INCH_CONVERSIONS */ /* png_get_channels really belongs in here, too, but it's been around longer */ -#endif /* PNG_EASY_ACCESS_SUPPORTED */ +#endif /* EASY_ACCESS */ + png_byte PNGAPI -png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr) +png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->channels); @@ -459,22 +500,25 @@ png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr) return (0); } +#ifdef PNG_READ_SUPPORTED png_const_bytep PNGAPI -png_get_signature(png_const_structp png_ptr, png_infop info_ptr) +png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->signature); return (NULL); } +#endif #ifdef PNG_bKGD_SUPPORTED png_uint_32 PNGAPI -png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr, +png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr, png_color_16p *background) { - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) - && background != NULL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_bKGD) != 0 && + background != NULL) { png_debug1(1, "in %s retrieval function", "bKGD"); @@ -487,32 +531,95 @@ png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr, #endif #ifdef PNG_cHRM_SUPPORTED +/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the + * same time to correct the rgb grayscale coefficient defaults obtained from the + * cHRM chunk in 1.5.4 + */ # ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr, double *white_x, double *white_y, double *red_x, double *red_y, double *green_x, double *green_y, double *blue_x, double *blue_y) { - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + /* Quiet API change: this code used to only return the end points if a cHRM + * chunk was present, but the end points can also come from iCCP or sRGB + * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and + * the png_set_ APIs merely check that set end points are mutually + * consistent. + */ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) { png_debug1(1, "in %s retrieval function", "cHRM"); if (white_x != NULL) - *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X"); + *white_x = png_float(png_ptr, + info_ptr->colorspace.end_points_xy.whitex, "cHRM white X"); if (white_y != NULL) - *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y"); + *white_y = png_float(png_ptr, + info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y"); if (red_x != NULL) - *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X"); + *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx, + "cHRM red X"); if (red_y != NULL) - *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y"); + *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy, + "cHRM red Y"); if (green_x != NULL) - *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X"); + *green_x = png_float(png_ptr, + info_ptr->colorspace.end_points_xy.greenx, "cHRM green X"); if (green_y != NULL) - *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y"); + *green_y = png_float(png_ptr, + info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y"); if (blue_x != NULL) - *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X"); + *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex, + "cHRM blue X"); if (blue_y != NULL) - *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y"); + *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey, + "cHRM blue Y"); + return (PNG_INFO_cHRM); + } + + return (0); +} + +png_uint_32 PNGAPI +png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr, + double *red_X, double *red_Y, double *red_Z, double *green_X, + double *green_Y, double *green_Z, double *blue_X, double *blue_Y, + double *blue_Z) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)"); + + if (red_X != NULL) + *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X, + "cHRM red X"); + if (red_Y != NULL) + *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y, + "cHRM red Y"); + if (red_Z != NULL) + *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z, + "cHRM red Z"); + if (green_X != NULL) + *green_X = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X"); + if (green_Y != NULL) + *green_Y = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y"); + if (green_Z != NULL) + *green_Z = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z"); + if (blue_X != NULL) + *blue_X = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X"); + if (blue_Y != NULL) + *blue_Y = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y"); + if (blue_Z != NULL) + *blue_Z = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z"); return (PNG_INFO_cHRM); } @@ -522,31 +629,69 @@ png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr, # ifdef PNG_FIXED_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_red_X, png_fixed_point *int_red_Y, + png_fixed_point *int_red_Z, png_fixed_point *int_green_X, + png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, + png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, + png_fixed_point *int_blue_Z) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + png_debug1(1, "in %s retrieval function", "cHRM_XYZ"); + + if (int_red_X != NULL) + *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X; + if (int_red_Y != NULL) + *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y; + if (int_red_Z != NULL) + *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z; + if (int_green_X != NULL) + *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X; + if (int_green_Y != NULL) + *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y; + if (int_green_Z != NULL) + *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z; + if (int_blue_X != NULL) + *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X; + if (int_blue_Y != NULL) + *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y; + if (int_blue_Z != NULL) + *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z; + return (PNG_INFO_cHRM); + } + + return (0); +} + +png_uint_32 PNGAPI +png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, png_fixed_point *blue_x, png_fixed_point *blue_y) { png_debug1(1, "in %s retrieval function", "cHRM"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) { if (white_x != NULL) - *white_x = info_ptr->x_white; + *white_x = info_ptr->colorspace.end_points_xy.whitex; if (white_y != NULL) - *white_y = info_ptr->y_white; + *white_y = info_ptr->colorspace.end_points_xy.whitey; if (red_x != NULL) - *red_x = info_ptr->x_red; + *red_x = info_ptr->colorspace.end_points_xy.redx; if (red_y != NULL) - *red_y = info_ptr->y_red; + *red_y = info_ptr->colorspace.end_points_xy.redy; if (green_x != NULL) - *green_x = info_ptr->x_green; + *green_x = info_ptr->colorspace.end_points_xy.greenx; if (green_y != NULL) - *green_y = info_ptr->y_green; + *green_y = info_ptr->colorspace.end_points_xy.greeny; if (blue_x != NULL) - *blue_x = info_ptr->x_blue; + *blue_x = info_ptr->colorspace.end_points_xy.bluex; if (blue_y != NULL) - *blue_y = info_ptr->y_blue; + *blue_y = info_ptr->colorspace.end_points_xy.bluey; return (PNG_INFO_cHRM); } @@ -556,49 +701,57 @@ png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr, #endif #ifdef PNG_gAMA_SUPPORTED -png_uint_32 PNGFAPI -png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr, +# ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, png_fixed_point *file_gamma) { png_debug1(1, "in %s retrieval function", "gAMA"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) - && file_gamma != NULL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && + file_gamma != NULL) { - *file_gamma = info_ptr->gamma; + *file_gamma = info_ptr->colorspace.gamma; return (PNG_INFO_gAMA); } return (0); } +# endif + # ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr, double *file_gamma) { - png_fixed_point igamma; - png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma); + png_debug1(1, "in %s retrieval function", "gAMA(float)"); - if (ok) - *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA"); + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && + file_gamma != NULL) + { + *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma, + "png_get_gAMA"); + return (PNG_INFO_gAMA); + } - return ok; + return (0); } - # endif #endif #ifdef PNG_sRGB_SUPPORTED png_uint_32 PNGAPI -png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr, int *file_srgb_intent) { png_debug1(1, "in %s retrieval function", "sRGB"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) - && file_srgb_intent != NULL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL) { - *file_srgb_intent = (int)info_ptr->srgb_intent; + *file_srgb_intent = info_ptr->colorspace.rendering_intent; return (PNG_INFO_sRGB); } @@ -608,22 +761,24 @@ png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr, #ifdef PNG_iCCP_SUPPORTED png_uint_32 PNGAPI -png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, png_charpp name, int *compression_type, png_bytepp profile, png_uint_32 *proflen) { png_debug1(1, "in %s retrieval function", "iCCP"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) - && name != NULL && profile != NULL && proflen != NULL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_iCCP) != 0 && + name != NULL && compression_type != NULL && profile != NULL && + proflen != NULL) { *name = info_ptr->iccp_name; *profile = info_ptr->iccp_profile; - /* Compression_type is a dummy so the API won't have to change - * if we introduce multiple compression types later. + *proflen = png_get_uint_32(info_ptr->iccp_profile); + /* This is somewhat irrelevant since the profile data returned has + * actually been uncompressed. */ - *proflen = (int)info_ptr->iccp_proflen; - *compression_type = (int)info_ptr->iccp_compression; + *compression_type = PNG_COMPRESSION_TYPE_BASE; return (PNG_INFO_iCCP); } @@ -632,14 +787,14 @@ png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr, #endif #ifdef PNG_sPLT_SUPPORTED -png_uint_32 PNGAPI -png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr, +int PNGAPI +png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr, png_sPLT_tpp spalettes) { if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) { *spalettes = info_ptr->splt_palettes; - return ((png_uint_32)info_ptr->splt_palettes_num); + return info_ptr->splt_palettes_num; } return (0); @@ -648,13 +803,13 @@ png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr, #ifdef PNG_hIST_SUPPORTED png_uint_32 PNGAPI -png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_16p *hist) { png_debug1(1, "in %s retrieval function", "hIST"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) - && hist != NULL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL) { *hist = info_ptr->hist; return (PNG_INFO_hIST); @@ -665,11 +820,10 @@ png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr, #endif png_uint_32 PNGAPI -png_get_IHDR(png_structp png_ptr, png_infop info_ptr, +png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_type, int *compression_type, int *filter_type) - { png_debug1(1, "in %s retrieval function", "IHDR"); @@ -696,7 +850,7 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr, * application has ignored our advice not to mess with the members * of info_ptr directly. */ - png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, + png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height, info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, info_ptr->compression_type, info_ptr->filter_type); @@ -705,13 +859,14 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_oFFs_SUPPORTED png_uint_32 PNGAPI -png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) { png_debug1(1, "in %s retrieval function", "oFFs"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) - && offset_x != NULL && offset_y != NULL && unit_type != NULL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0 && + offset_x != NULL && offset_y != NULL && unit_type != NULL) { *offset_x = info_ptr->x_offset; *offset_y = info_ptr->y_offset; @@ -725,14 +880,15 @@ png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr, #ifdef PNG_pCAL_SUPPORTED png_uint_32 PNGAPI -png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *units, png_charpp *params) { png_debug1(1, "in %s retrieval function", "pCAL"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) - && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pCAL) != 0 && + purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && nparams != NULL && units != NULL && params != NULL) { *purpose = info_ptr->pcal_purpose; @@ -751,16 +907,20 @@ png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr, #ifdef PNG_sCAL_SUPPORTED # ifdef PNG_FIXED_POINT_SUPPORTED -# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED +# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ + defined(PNG_FLOATING_POINT_SUPPORTED) png_uint_32 PNGAPI -png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr, +png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, png_fixed_point *width, png_fixed_point *height) { if (png_ptr != NULL && info_ptr != NULL && - (info_ptr->valid & PNG_INFO_sCAL)) + (info_ptr->valid & PNG_INFO_sCAL) != 0) { *unit = info_ptr->scal_unit; - /*TODO: make this work without FP support */ + /*TODO: make this work without FP support; the API is currently eliminated + * if neither floating point APIs nor internal floating point arithmetic + * are enabled. + */ *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width"); *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height), "sCAL height"); @@ -773,11 +933,11 @@ png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr, # endif /* FIXED_POINT */ # ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, double *width, double *height) { if (png_ptr != NULL && info_ptr != NULL && - (info_ptr->valid & PNG_INFO_sCAL)) + (info_ptr->valid & PNG_INFO_sCAL) != 0) { *unit = info_ptr->scal_unit; *width = atof(info_ptr->scal_s_width); @@ -789,11 +949,11 @@ png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr, } # endif /* FLOATING POINT */ png_uint_32 PNGAPI -png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, png_charpp width, png_charpp height) { if (png_ptr != NULL && info_ptr != NULL && - (info_ptr->valid & PNG_INFO_sCAL)) + (info_ptr->valid & PNG_INFO_sCAL) != 0) { *unit = info_ptr->scal_unit; *width = info_ptr->scal_s_width; @@ -807,7 +967,7 @@ png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr, #ifdef PNG_pHYs_SUPPORTED png_uint_32 PNGAPI -png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) { png_uint_32 retval = 0; @@ -815,7 +975,7 @@ png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr, png_debug1(1, "in %s retrieval function", "pHYs"); if (png_ptr != NULL && info_ptr != NULL && - (info_ptr->valid & PNG_INFO_pHYs)) + (info_ptr->valid & PNG_INFO_pHYs) != 0) { if (res_x != NULL) { @@ -841,13 +1001,13 @@ png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr, #endif /* pHYs */ png_uint_32 PNGAPI -png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr, png_colorp *palette, int *num_palette) { png_debug1(1, "in %s retrieval function", "PLTE"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) - && palette != NULL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL) { *palette = info_ptr->palette; *num_palette = info_ptr->num_palette; @@ -860,13 +1020,13 @@ png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr, #ifdef PNG_sBIT_SUPPORTED png_uint_32 PNGAPI -png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr, +png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr, png_color_8p *sig_bit) { png_debug1(1, "in %s retrieval function", "sBIT"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) - && sig_bit != NULL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL) { *sig_bit = &(info_ptr->sig_bit); return (PNG_INFO_sBIT); @@ -877,15 +1037,14 @@ png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr, #endif #ifdef PNG_TEXT_SUPPORTED -png_uint_32 PNGAPI -png_get_text(png_const_structp png_ptr, png_const_infop info_ptr, +int PNGAPI +png_get_text(png_const_structrp png_ptr, png_inforp info_ptr, png_textp *text_ptr, int *num_text) { if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) { - png_debug1(1, "in %s retrieval function", - (png_ptr->chunk_name[0] == '\0' ? "text" : - (png_const_charp)png_ptr->chunk_name)); + png_debug1(1, "in 0x%lx retrieval function", + (unsigned long)png_ptr->chunk_name); if (text_ptr != NULL) *text_ptr = info_ptr->text; @@ -893,7 +1052,7 @@ png_get_text(png_const_structp png_ptr, png_const_infop info_ptr, if (num_text != NULL) *num_text = info_ptr->num_text; - return ((png_uint_32)info_ptr->num_text); + return info_ptr->num_text; } if (num_text != NULL) @@ -905,12 +1064,13 @@ png_get_text(png_const_structp png_ptr, png_const_infop info_ptr, #ifdef PNG_tIME_SUPPORTED png_uint_32 PNGAPI -png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time) +png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr, + png_timep *mod_time) { png_debug1(1, "in %s retrieval function", "tIME"); - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) - && mod_time != NULL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL) { *mod_time = &(info_ptr->mod_time); return (PNG_INFO_tIME); @@ -922,11 +1082,12 @@ png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time) #ifdef PNG_tRNS_SUPPORTED png_uint_32 PNGAPI -png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr, +png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr, png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) { png_uint_32 retval = 0; - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_tRNS) != 0) { png_debug1(1, "in %s retrieval function", "tRNS"); @@ -965,9 +1126,9 @@ png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr, } #endif -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED int PNGAPI -png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr, +png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr, png_unknown_chunkpp unknowns) { if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) @@ -982,7 +1143,7 @@ png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr, #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED png_byte PNGAPI -png_get_rgb_to_gray_status (png_const_structp png_ptr) +png_get_rgb_to_gray_status (png_const_structrp png_ptr) { return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0); } @@ -990,71 +1151,91 @@ png_get_rgb_to_gray_status (png_const_structp png_ptr) #ifdef PNG_USER_CHUNKS_SUPPORTED png_voidp PNGAPI -png_get_user_chunk_ptr(png_const_structp png_ptr) +png_get_user_chunk_ptr(png_const_structrp png_ptr) { return (png_ptr ? png_ptr->user_chunk_ptr : NULL); } #endif png_size_t PNGAPI -png_get_compression_buffer_size(png_const_structp png_ptr) +png_get_compression_buffer_size(png_const_structrp png_ptr) { - return (png_ptr ? png_ptr->zbuf_size : 0L); -} + if (png_ptr == NULL) + return 0; +# ifdef PNG_WRITE_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) +# endif + { +# ifdef PNG_SEQUENTIAL_READ_SUPPORTED + return png_ptr->IDAT_read_size; +# else + return PNG_IDAT_READ_SIZE; +# endif + } + +# ifdef PNG_WRITE_SUPPORTED + else + return png_ptr->zbuffer_size; +# endif +} #ifdef PNG_SET_USER_LIMITS_SUPPORTED /* These functions were added to libpng 1.2.6 and were enabled * by default in libpng-1.4.0 */ png_uint_32 PNGAPI -png_get_user_width_max (png_const_structp png_ptr) +png_get_user_width_max (png_const_structrp png_ptr) { return (png_ptr ? png_ptr->user_width_max : 0); } png_uint_32 PNGAPI -png_get_user_height_max (png_const_structp png_ptr) +png_get_user_height_max (png_const_structrp png_ptr) { return (png_ptr ? png_ptr->user_height_max : 0); } /* This function was added to libpng 1.4.0 */ png_uint_32 PNGAPI -png_get_chunk_cache_max (png_const_structp png_ptr) +png_get_chunk_cache_max (png_const_structrp png_ptr) { return (png_ptr ? png_ptr->user_chunk_cache_max : 0); } /* This function was added to libpng 1.4.1 */ png_alloc_size_t PNGAPI -png_get_chunk_malloc_max (png_const_structp png_ptr) +png_get_chunk_malloc_max (png_const_structrp png_ptr) { return (png_ptr ? png_ptr->user_chunk_malloc_max : 0); } -#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ +#endif /* SET_USER_LIMITS */ /* These functions were added to libpng 1.4.0 */ #ifdef PNG_IO_STATE_SUPPORTED png_uint_32 PNGAPI -png_get_io_state (png_structp png_ptr) +png_get_io_state (png_const_structrp png_ptr) { return png_ptr->io_state; } png_uint_32 PNGAPI -png_get_io_chunk_type (png_const_structp png_ptr) -{ - return ((png_ptr->chunk_name[0] << 24) + - (png_ptr->chunk_name[1] << 16) + - (png_ptr->chunk_name[2] << 8) + - (png_ptr->chunk_name[3])); -} - -png_const_bytep PNGAPI -png_get_io_chunk_name (png_structp png_ptr) +png_get_io_chunk_type (png_const_structrp png_ptr) { return png_ptr->chunk_name; } -#endif /* ?PNG_IO_STATE_SUPPORTED */ +#endif /* IO_STATE */ -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +# ifdef PNG_GET_PALETTE_MAX_SUPPORTED +int PNGAPI +png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return png_ptr->num_palette_max; + + return (-1); +} +# endif +#endif + +#endif /* READ || WRITE */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pnginfo.h b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pnginfo.h index be9a73833fc..0b885a5ee7b 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pnginfo.h +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pnginfo.h @@ -29,11 +29,11 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Copyright (c) 1998-2013 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.6.1 [March 28, 2013] * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer @@ -83,7 +83,7 @@ struct png_info_def { - /* the following are necessary for every PNG file */ + /* The following are necessary for every PNG file */ png_uint_32 width; /* width of image in pixels (from IHDR) */ png_uint_32 height; /* height of image in pixels (from IHDR) */ png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */ @@ -98,11 +98,17 @@ struct png_info_def png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */ png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ - /* The following is informational only on read, and not used on writes. */ + /* The following are set by png_set_IHDR, called from the application on + * write, but the are never actually used by the write code. + */ png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */ png_byte pixel_depth; /* number of bits per pixel */ png_byte spare_byte; /* to align the data, and for future use */ + +#ifdef PNG_READ_SUPPORTED + /* This is never set during write */ png_byte signature[8]; /* magic bytes read by libpng from start of file */ +#endif /* The rest of the data is optional. If you are reading, check the * valid field to see if the information in these are valid. If you @@ -110,18 +116,25 @@ struct png_info_def * and initialize the appropriate fields below. */ -#if defined(PNG_gAMA_SUPPORTED) - /* The gAMA chunk describes the gamma characteristics of the system - * on which the image was created, normally in the range [1.0, 2.5]. - * Data is valid if (valid & PNG_INFO_gAMA) is non-zero. +#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) + /* png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are + * defined. When COLORSPACE is switched on all the colorspace-defining + * chunks should be enabled, when GAMMA is switched on all the gamma-defining + * chunks should be enabled. If this is not done it becomes possible to read + * inconsistent PNG files and assign a probably incorrect interpretation to + * the information. (In other words, by carefully choosing which chunks to + * recognize the system configuration can select an interpretation for PNG + * files containing ambiguous data and this will result in inconsistent + * behavior between different libpng builds!) */ - png_fixed_point gamma; + png_colorspace colorspace; #endif -#ifdef PNG_sRGB_SUPPORTED - /* GR-P, 0.96a */ - /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */ - png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */ +#ifdef PNG_iCCP_SUPPORTED + /* iCCP chunk data. */ + png_charp iccp_name; /* profile name */ + png_bytep iccp_profile; /* International Color Consortium profile data */ + png_uint_32 iccp_proflen; /* ICC profile data length */ #endif #ifdef PNG_TEXT_SUPPORTED @@ -136,7 +149,7 @@ struct png_info_def int num_text; /* number of comments read or comments to write */ int max_text; /* current size of text array */ png_textp text; /* array of comments read or comments to write */ -#endif /* PNG_TEXT_SUPPORTED */ +#endif /* TEXT */ #ifdef PNG_tIME_SUPPORTED /* The tIME chunk holds the last time the displayed image data was @@ -211,23 +224,6 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) png_uint_16p hist; #endif -#ifdef PNG_cHRM_SUPPORTED - /* The cHRM chunk describes the CIE color characteristics of the monitor - * on which the PNG was created. This data allows the viewer to do gamut - * mapping of the input image to ensure that the viewer sees the same - * colors in the image as the creator. Values are in the range - * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero. - */ - png_fixed_point x_white; - png_fixed_point y_white; - png_fixed_point x_red; - png_fixed_point y_red; - png_fixed_point x_green; - png_fixed_point y_green; - png_fixed_point x_blue; - png_fixed_point y_blue; -#endif - #ifdef PNG_pCAL_SUPPORTED /* The pCAL chunk describes a transformation between the stored pixel * values and original physical data values used to create the image. @@ -252,25 +248,20 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) /* New members added in libpng-1.0.6 */ png_uint_32 free_me; /* flags items libpng is responsible for freeing */ -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \ - defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED /* Storage for unknown chunks that the library doesn't recognize. */ png_unknown_chunkp unknown_chunks; - int unknown_chunks_num; -#endif -#ifdef PNG_iCCP_SUPPORTED - /* iCCP chunk data. */ - png_charp iccp_name; /* profile name */ - png_bytep iccp_profile; /* International Color Consortium profile data */ - png_uint_32 iccp_proflen; /* ICC profile data length */ - png_byte iccp_compression; /* Always zero */ + /* The type of this field is limited by the type of + * png_struct::user_chunk_cache_max, else overflow can occur. + */ + int unknown_chunks_num; #endif #ifdef PNG_sPLT_SUPPORTED /* Data on sPLT chunks (there may be more than one). */ png_sPLT_tp splt_palettes; - png_uint_32 splt_palettes_num; + int splt_palettes_num; /* Match type returned by png_get API */ #endif #ifdef PNG_sCAL_SUPPORTED diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pnglibconf.h b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pnglibconf.h index c78fa661b96..f5fdbae317c 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pnglibconf.h +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pnglibconf.h @@ -34,69 +34,47 @@ * file and, per its terms, should not be removed: */ -/* libpng version 1.5.4 - last changed on June 22, 2011 */ +/* libpng version 1.6.16,December 22, 2014 */ -/* Copyright (c) 1998-2011 Glenn Randers-Pehrson */ +/* Copyright (c) 1998-2014 Glenn Randers-Pehrson */ /* This code is released under the libpng license. */ /* For conditions of distribution and use, see the disclaimer */ /* and license in png.h */ /* pnglibconf.h */ +/* Machine generated file: DO NOT EDIT */ /* Derived from: scripts/pnglibconf.dfa */ -/* If you edit this file by hand you must obey the rules expressed in */ -/* pnglibconf.dfa with respect to the dependencies between the following */ -/* symbols. It is much better to generate a new file using */ -/* scripts/libpngconf.mak */ - #ifndef PNGLCONF_H #define PNGLCONF_H -/* settings */ -#define PNG_API_RULE 0 -#define PNG_CALLOC_SUPPORTED -#define PNG_COST_SHIFT 3 -#define PNG_DEFAULT_READ_MACROS 1 -#define PNG_GAMMA_THRESHOLD_FIXED 5000 -#define PNG_MAX_GAMMA_8 11 -#define PNG_QUANTIZE_BLUE_BITS 5 -#define PNG_QUANTIZE_GREEN_BITS 5 -#define PNG_QUANTIZE_RED_BITS 5 -#define PNG_sCAL_PRECISION 5 -#define PNG_USER_CHUNK_CACHE_MAX 0 -#define PNG_USER_CHUNK_MALLOC_MAX 0 -#define PNG_USER_HEIGHT_MAX 1000000L -#define PNG_USER_WIDTH_MAX 1000000L -#define PNG_WEIGHT_SHIFT 8 -#define PNG_ZBUF_SIZE 8192 -/* end of settings */ /* options */ #define PNG_16BIT_SUPPORTED -#define PNG_ALIGN_MEMORY_SUPPORTED +#define PNG_ALIGNED_MEMORY_SUPPORTED +/*#undef PNG_ARM_NEON_API_SUPPORTED*/ +/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/ #define PNG_BENIGN_ERRORS_SUPPORTED -#define PNG_bKGD_SUPPORTED +#define PNG_BENIGN_READ_ERRORS_SUPPORTED +/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/ #define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED -#define PNG_CHECK_cHRM_SUPPORTED -#define PNG_cHRM_SUPPORTED +#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_COLORSPACE_SUPPORTED #define PNG_CONSOLE_IO_SUPPORTED -#define PNG_CONVERT_tIME_SUPPORTED +/*#undef PNG_CONVERT_tIME_SUPPORTED*/ #define PNG_EASY_ACCESS_SUPPORTED /*#undef PNG_ERROR_NUMBERS_SUPPORTED*/ #define PNG_ERROR_TEXT_SUPPORTED #define PNG_FIXED_POINT_SUPPORTED #define PNG_FLOATING_ARITHMETIC_SUPPORTED #define PNG_FLOATING_POINT_SUPPORTED -#define PNG_gAMA_SUPPORTED +#define PNG_FORMAT_AFIRST_SUPPORTED +#define PNG_FORMAT_BGR_SUPPORTED +#define PNG_GAMMA_SUPPORTED +#define PNG_GET_PALETTE_MAX_SUPPORTED #define PNG_HANDLE_AS_UNKNOWN_SUPPORTED -#define PNG_hIST_SUPPORTED -#define PNG_iCCP_SUPPORTED #define PNG_INCH_CONVERSIONS_SUPPORTED #define PNG_INFO_IMAGE_SUPPORTED #define PNG_IO_STATE_SUPPORTED -#define PNG_iTXt_SUPPORTED #define PNG_MNG_FEATURES_SUPPORTED -#define PNG_oFFs_SUPPORTED -#define PNG_pCAL_SUPPORTED -#define PNG_pHYs_SUPPORTED #define PNG_POINTER_INDEXING_SUPPORTED #define PNG_PROGRESSIVE_READ_SUPPORTED #define PNG_READ_16BIT_SUPPORTED @@ -104,67 +82,73 @@ #define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED #define PNG_READ_BACKGROUND_SUPPORTED #define PNG_READ_BGR_SUPPORTED -#define PNG_READ_bKGD_SUPPORTED -#define PNG_READ_cHRM_SUPPORTED +#define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED #define PNG_READ_COMPOSITE_NODIV_SUPPORTED #define PNG_READ_COMPRESSED_TEXT_SUPPORTED #define PNG_READ_EXPAND_16_SUPPORTED #define PNG_READ_EXPAND_SUPPORTED #define PNG_READ_FILLER_SUPPORTED -#define PNG_READ_gAMA_SUPPORTED #define PNG_READ_GAMMA_SUPPORTED +#define PNG_READ_GET_PALETTE_MAX_SUPPORTED #define PNG_READ_GRAY_TO_RGB_SUPPORTED -#define PNG_READ_hIST_SUPPORTED -#define PNG_READ_iCCP_SUPPORTED #define PNG_READ_INTERLACING_SUPPORTED #define PNG_READ_INT_FUNCTIONS_SUPPORTED #define PNG_READ_INVERT_ALPHA_SUPPORTED #define PNG_READ_INVERT_SUPPORTED -#define PNG_READ_iTXt_SUPPORTED -#define PNG_READ_oFFs_SUPPORTED #define PNG_READ_OPT_PLTE_SUPPORTED -#define PNG_READ_PACK_SUPPORTED #define PNG_READ_PACKSWAP_SUPPORTED -#define PNG_READ_pCAL_SUPPORTED -#define PNG_READ_pHYs_SUPPORTED +#define PNG_READ_PACK_SUPPORTED #define PNG_READ_QUANTIZE_SUPPORTED #define PNG_READ_RGB_TO_GRAY_SUPPORTED -#define PNG_READ_sBIT_SUPPORTED #define PNG_READ_SCALE_16_TO_8_SUPPORTED -#define PNG_READ_sCAL_SUPPORTED #define PNG_READ_SHIFT_SUPPORTED -#define PNG_READ_sPLT_SUPPORTED -#define PNG_READ_sRGB_SUPPORTED #define PNG_READ_STRIP_16_TO_8_SUPPORTED #define PNG_READ_STRIP_ALPHA_SUPPORTED #define PNG_READ_SUPPORTED #define PNG_READ_SWAP_ALPHA_SUPPORTED #define PNG_READ_SWAP_SUPPORTED -#define PNG_READ_tEXt_SUPPORTED #define PNG_READ_TEXT_SUPPORTED -#define PNG_READ_tIME_SUPPORTED #define PNG_READ_TRANSFORMS_SUPPORTED -#define PNG_READ_tRNS_SUPPORTED #define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED #define PNG_READ_USER_CHUNKS_SUPPORTED #define PNG_READ_USER_TRANSFORM_SUPPORTED +#define PNG_READ_bKGD_SUPPORTED +#define PNG_READ_cHRM_SUPPORTED +#define PNG_READ_gAMA_SUPPORTED +#define PNG_READ_hIST_SUPPORTED +#define PNG_READ_iCCP_SUPPORTED +#define PNG_READ_iTXt_SUPPORTED +#define PNG_READ_oFFs_SUPPORTED +#define PNG_READ_pCAL_SUPPORTED +#define PNG_READ_pHYs_SUPPORTED +#define PNG_READ_sBIT_SUPPORTED +#define PNG_READ_sCAL_SUPPORTED +#define PNG_READ_sPLT_SUPPORTED +#define PNG_READ_sRGB_SUPPORTED +#define PNG_READ_tEXt_SUPPORTED +#define PNG_READ_tIME_SUPPORTED +#define PNG_READ_tRNS_SUPPORTED #define PNG_READ_zTXt_SUPPORTED -#define PNG_SAVE_INT_32_SUPPORTED -#define PNG_sBIT_SUPPORTED -#define PNG_sCAL_SUPPORTED +/*#undef PNG_SAFE_LIMITS_SUPPORTED*/ +/*#undef PNG_SAVE_INT_32_SUPPORTED*/ +#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED #define PNG_SEQUENTIAL_READ_SUPPORTED +#define PNG_SETJMP_SUPPORTED #define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED #define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED -#define PNG_SETJMP_SUPPORTED +#define PNG_SET_OPTION_SUPPORTED +#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED #define PNG_SET_USER_LIMITS_SUPPORTED -#define PNG_sPLT_SUPPORTED -#define PNG_sRGB_SUPPORTED +#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED +#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED +#define PNG_SIMPLIFIED_READ_SUPPORTED +/*#undef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED*/ +/*#undef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED*/ +/*#undef PNG_SIMPLIFIED_WRITE_SUPPORTED*/ #define PNG_STDIO_SUPPORTED -#define PNG_tEXt_SUPPORTED +#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED #define PNG_TEXT_SUPPORTED #define PNG_TIME_RFC1123_SUPPORTED -#define PNG_tIME_SUPPORTED -#define PNG_tRNS_SUPPORTED #define PNG_UNKNOWN_CHUNKS_SUPPORTED #define PNG_USER_CHUNKS_SUPPORTED #define PNG_USER_LIMITS_SUPPORTED @@ -172,6 +156,91 @@ #define PNG_USER_TRANSFORM_INFO_SUPPORTED #define PNG_USER_TRANSFORM_PTR_SUPPORTED #define PNG_WARNINGS_SUPPORTED +/*#undef PNG_WRITE_16BIT_SUPPORTED*/ +/*#undef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED*/ +/*#undef PNG_WRITE_BGR_SUPPORTED*/ +/*#undef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED*/ +/*#undef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED*/ +/*#undef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED*/ +/*#undef PNG_WRITE_FILLER_SUPPORTED*/ +/*#undef PNG_WRITE_FILTER_SUPPORTED*/ +/*#undef PNG_WRITE_FLUSH_SUPPORTED*/ +/*#undef PNG_WRITE_GET_PALETTE_MAX_SUPPORTED*/ +/*#undef PNG_WRITE_INTERLACING_SUPPORTED*/ +/*#undef PNG_WRITE_INT_FUNCTIONS_SUPPORTED*/ +/*#undef PNG_WRITE_INVERT_ALPHA_SUPPORTED*/ +/*#undef PNG_WRITE_INVERT_SUPPORTED*/ +/*#undef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED*/ +/*#undef PNG_WRITE_PACKSWAP_SUPPORTED*/ +/*#undef PNG_WRITE_PACK_SUPPORTED*/ +/*#undef PNG_WRITE_SHIFT_SUPPORTED*/ +/*#undef PNG_WRITE_SUPPORTED*/ +/*#undef PNG_WRITE_SWAP_ALPHA_SUPPORTED*/ +/*#undef PNG_WRITE_SWAP_SUPPORTED*/ +/*#undef PNG_WRITE_TEXT_SUPPORTED*/ +/*#undef PNG_WRITE_TRANSFORMS_SUPPORTED*/ +/*#undef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED*/ +/*#undef PNG_WRITE_USER_TRANSFORM_SUPPORTED*/ +/*#undef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED*/ +/*#undef PNG_WRITE_bKGD_SUPPORTED*/ +/*#undef PNG_WRITE_cHRM_SUPPORTED*/ +/*#undef PNG_WRITE_gAMA_SUPPORTED*/ +/*#undef PNG_WRITE_hIST_SUPPORTED*/ +/*#undef PNG_WRITE_iCCP_SUPPORTED*/ +/*#undef PNG_WRITE_iTXt_SUPPORTED*/ +/*#undef PNG_WRITE_oFFs_SUPPORTED*/ +/*#undef PNG_WRITE_pCAL_SUPPORTED*/ +/*#undef PNG_WRITE_pHYs_SUPPORTED*/ +/*#undef PNG_WRITE_sBIT_SUPPORTED*/ +/*#undef PNG_WRITE_sCAL_SUPPORTED*/ +/*#undef PNG_WRITE_sPLT_SUPPORTED*/ +/*#undef PNG_WRITE_sRGB_SUPPORTED*/ +/*#undef PNG_WRITE_tEXt_SUPPORTED*/ +/*#undef PNG_WRITE_tIME_SUPPORTED*/ +/*#undef PNG_WRITE_tRNS_SUPPORTED*/ +/*#undef PNG_WRITE_zTXt_SUPPORTED*/ +#define PNG_bKGD_SUPPORTED +#define PNG_cHRM_SUPPORTED +#define PNG_gAMA_SUPPORTED +#define PNG_hIST_SUPPORTED +#define PNG_iCCP_SUPPORTED +#define PNG_iTXt_SUPPORTED +#define PNG_oFFs_SUPPORTED +#define PNG_pCAL_SUPPORTED +#define PNG_pHYs_SUPPORTED +#define PNG_sBIT_SUPPORTED +#define PNG_sCAL_SUPPORTED +#define PNG_sPLT_SUPPORTED +#define PNG_sRGB_SUPPORTED +#define PNG_tEXt_SUPPORTED +#define PNG_tIME_SUPPORTED +#define PNG_tRNS_SUPPORTED #define PNG_zTXt_SUPPORTED /* end of options */ +/* settings */ +#define PNG_API_RULE 0 +#define PNG_COST_SHIFT 3 +#define PNG_DEFAULT_READ_MACROS 1 +#define PNG_GAMMA_THRESHOLD_FIXED 5000 +#define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE +#define PNG_INFLATE_BUF_SIZE 1024 +#define PNG_MAX_GAMMA_8 11 +#define PNG_QUANTIZE_BLUE_BITS 5 +#define PNG_QUANTIZE_GREEN_BITS 5 +#define PNG_QUANTIZE_RED_BITS 5 +#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1) +#define PNG_TEXT_Z_DEFAULT_STRATEGY 0 +#define PNG_USER_CHUNK_CACHE_MAX 0 +#define PNG_USER_CHUNK_MALLOC_MAX 0 +#define PNG_USER_HEIGHT_MAX 1000000 +#define PNG_USER_WIDTH_MAX 1000000 +#define PNG_WEIGHT_SHIFT 8 +#define PNG_ZBUF_SIZE 8192 +#define PNG_ZLIB_VERNUM 0 +#define PNG_Z_DEFAULT_COMPRESSION (-1) +#define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0 +#define PNG_Z_DEFAULT_STRATEGY 1 +#define PNG_sCAL_PRECISION 5 +#define PNG_sRGB_PROFILE_CHECKS 2 +/* end of settings */ #endif /* PNGLCONF_H */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngmem.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngmem.c index 88e7815c2fc..c24098ffb73 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngmem.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngmem.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -48,457 +48,23 @@ #include "pngpriv.h" #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) - -/* Borland DOS special memory handler */ -#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) -/* If you change this, be sure to change the one in png.h also */ - -/* Allocate memory for a png_struct. The malloc and memset can be replaced - by a single call to calloc() if this is thought to improve performance. */ -PNG_FUNCTION(png_voidp /* PRIVATE */, -png_create_struct,(int type),PNG_ALLOCATED) -{ -# ifdef PNG_USER_MEM_SUPPORTED - return (png_create_struct_2(type, NULL, NULL)); -} - -/* Alternate version of png_create_struct, for use with user-defined malloc. */ -PNG_FUNCTION(png_voidp /* PRIVATE */, -png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr), - PNG_ALLOCATED) -{ -# endif /* PNG_USER_MEM_SUPPORTED */ - png_size_t size; - png_voidp struct_ptr; - - if (type == PNG_STRUCT_INFO) - size = png_sizeof(png_info); - - else if (type == PNG_STRUCT_PNG) - size = png_sizeof(png_struct); - - else - return (png_get_copyright(NULL)); - -# ifdef PNG_USER_MEM_SUPPORTED - if (malloc_fn != NULL) - { - png_struct dummy_struct; - png_structp png_ptr = &dummy_struct; - png_ptr->mem_ptr=mem_ptr; - struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size); - } - - else -# endif /* PNG_USER_MEM_SUPPORTED */ - struct_ptr = (png_voidp)farmalloc(size); - if (struct_ptr != NULL) - png_memset(struct_ptr, 0, size); - - return (struct_ptr); -} - -/* Free memory allocated by a png_create_struct() call */ +/* Free a png_struct */ void /* PRIVATE */ -png_destroy_struct(png_voidp struct_ptr) +png_destroy_png_struct(png_structrp png_ptr) { -# ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2(struct_ptr, NULL, NULL); -} - -/* Free memory allocated by a png_create_struct() call */ -void /* PRIVATE */ -png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, - png_voidp mem_ptr) -{ -# endif - if (struct_ptr != NULL) + if (png_ptr != NULL) { -# ifdef PNG_USER_MEM_SUPPORTED - if (free_fn != NULL) - { - png_struct dummy_struct; - png_structp png_ptr = &dummy_struct; - png_ptr->mem_ptr=mem_ptr; - (*(free_fn))(png_ptr, struct_ptr); - return; - } - -# endif /* PNG_USER_MEM_SUPPORTED */ - farfree (struct_ptr); - } -} - -/* Allocate memory. For reasonable files, size should never exceed - * 64K. However, zlib may allocate more then 64K if you don't tell - * it not to. See zconf.h and png.h for more information. zlib does - * need to allocate exactly 64K, so whatever you call here must - * have the ability to do that. - * - * Borland seems to have a problem in DOS mode for exactly 64K. - * It gives you a segment with an offset of 8 (perhaps to store its - * memory stuff). zlib doesn't like this at all, so we have to - * detect and deal with it. This code should not be needed in - * Windows or OS/2 modes, and only in 16 bit mode. This code has - * been updated by Alexander Lehmann for version 0.89 to waste less - * memory. - * - * Note that we can't use png_size_t for the "size" declaration, - * since on some systems a png_size_t is a 16-bit quantity, and as a - * result, we would be truncating potentially larger memory requests - * (which should cause a fatal error) and introducing major problems. - */ -PNG_FUNCTION(png_voidp,PNGAPI -png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; - - ret = (png_malloc(png_ptr, size)); - - if (ret != NULL) - png_memset(ret,0,(png_size_t)size); - - return (ret); -} - -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; - - if (png_ptr == NULL || size == 0) - return (NULL); - -# ifdef PNG_USER_MEM_SUPPORTED - if (png_ptr->malloc_fn != NULL) - ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size)); - - else - ret = (png_malloc_default(png_ptr, size)); - - if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of memory"); - - return (ret); -} - -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; -# endif /* PNG_USER_MEM_SUPPORTED */ - - if (png_ptr == NULL || size == 0) - return (NULL); - -# ifdef PNG_MAX_MALLOC_64K - if (size > (png_uint_32)65536L) - { - png_warning(png_ptr, "Cannot Allocate > 64K"); - ret = NULL; - } - - else -# endif - - if (size != (size_t)size) - ret = NULL; - - else if (size == (png_uint_32)65536L) - { - if (png_ptr->offset_table == NULL) - { - /* Try to see if we need to do any of this fancy stuff */ - ret = farmalloc(size); - if (ret == NULL || ((png_size_t)ret & 0xffff)) - { - int num_blocks; - png_uint_32 total_size; - png_bytep table; - int i, mem_level, window_bits; - png_byte huge * hptr; - int window_bits - - if (ret != NULL) - { - farfree(ret); - ret = NULL; - } - - window_bits = - png_ptr->zlib_window_bits >= png_ptr->zlib_text_window_bits ? - png_ptr->zlib_window_bits : png_ptr->zlib_text_window_bits; - - if (window_bits > 14) - num_blocks = (int)(1 << (window_bits - 14)); - - else - num_blocks = 1; - - mem_level = - png_ptr->zlib_mem_level >= png_ptr->zlib_text_mem_level ? - png_ptr->zlib_mem_level : png_ptr->zlib_text_mem_level; - - if (mem_level >= 7) - num_blocks += (int)(1 << (mem_level - 7)); - - else - num_blocks++; - - total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16; - - table = farmalloc(total_size); - - if (table == NULL) - { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out Of Memory"); /* Note "O", "M" */ - - else - png_warning(png_ptr, "Out Of Memory"); -# endif - return (NULL); - } - - if ((png_size_t)table & 0xfff0) - { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, - "Farmalloc didn't return normalized pointer"); - - else - png_warning(png_ptr, - "Farmalloc didn't return normalized pointer"); -# endif - return (NULL); - } - - png_ptr->offset_table = table; - png_ptr->offset_table_ptr = farmalloc(num_blocks * - png_sizeof(png_bytep)); - - if (png_ptr->offset_table_ptr == NULL) - { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out Of memory"); /* Note "O", "m" */ - - else - png_warning(png_ptr, "Out Of memory"); -# endif - return (NULL); - } - - hptr = (png_byte huge *)table; - if ((png_size_t)hptr & 0xf) - { - hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); - hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */ - } - - for (i = 0; i < num_blocks; i++) - { - png_ptr->offset_table_ptr[i] = (png_bytep)hptr; - hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */ - } - - png_ptr->offset_table_number = num_blocks; - png_ptr->offset_table_count = 0; - png_ptr->offset_table_count_free = 0; - } - } - - if (png_ptr->offset_table_count >= png_ptr->offset_table_number) - { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of Memory"); /* Note "O" and "M" */ - - else - png_warning(png_ptr, "Out of Memory"); -# endif - return (NULL); - } - - ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++]; - } - - else - ret = farmalloc(size); - -# ifndef PNG_USER_MEM_SUPPORTED - if (ret == NULL) - { - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */ - - else - png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */ - } -# endif - - return (ret); -} - -/* Free a pointer allocated by png_malloc(). In the default - * configuration, png_ptr is not used, but is passed in case it - * is needed. If ptr is NULL, return without taking any action. - */ -void PNGAPI -png_free(png_structp png_ptr, png_voidp ptr) -{ - if (png_ptr == NULL || ptr == NULL) - return; - -# ifdef PNG_USER_MEM_SUPPORTED - if (png_ptr->free_fn != NULL) - { - (*(png_ptr->free_fn))(png_ptr, ptr); - return; - } - - else - png_free_default(png_ptr, ptr); -} - -void PNGAPI -png_free_default(png_structp png_ptr, png_voidp ptr) -{ -# endif /* PNG_USER_MEM_SUPPORTED */ - - if (png_ptr == NULL || ptr == NULL) - return; - - if (png_ptr->offset_table != NULL) - { - int i; - - for (i = 0; i < png_ptr->offset_table_count; i++) - { - if (ptr == png_ptr->offset_table_ptr[i]) - { - ptr = NULL; - png_ptr->offset_table_count_free++; - break; - } - } - if (png_ptr->offset_table_count_free == png_ptr->offset_table_count) - { - farfree(png_ptr->offset_table); - farfree(png_ptr->offset_table_ptr); - png_ptr->offset_table = NULL; - png_ptr->offset_table_ptr = NULL; - } - } - - if (ptr != NULL) - farfree(ptr); -} - -#else /* Not the Borland DOS special memory handler */ - -/* Allocate memory for a png_struct or a png_info. The malloc and - memset can be replaced by a single call to calloc() if this is thought - to improve performance noticably. */ -PNG_FUNCTION(png_voidp /* PRIVATE */, -png_create_struct,(int type),PNG_ALLOCATED) -{ -# ifdef PNG_USER_MEM_SUPPORTED - return (png_create_struct_2(type, NULL, NULL)); -} - -/* Allocate memory for a png_struct or a png_info. The malloc and - memset can be replaced by a single call to calloc() if this is thought - to improve performance noticably. */ -PNG_FUNCTION(png_voidp /* PRIVATE */, -png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr), - PNG_ALLOCATED) -{ -# endif /* PNG_USER_MEM_SUPPORTED */ - png_size_t size; - png_voidp struct_ptr; - - if (type == PNG_STRUCT_INFO) - size = png_sizeof(png_info); - - else if (type == PNG_STRUCT_PNG) - size = png_sizeof(png_struct); - - else - return (NULL); - -# ifdef PNG_USER_MEM_SUPPORTED - if (malloc_fn != NULL) - { - png_struct dummy_struct; - png_structp png_ptr = &dummy_struct; - png_ptr->mem_ptr=mem_ptr; - struct_ptr = (*(malloc_fn))(png_ptr, size); - - if (struct_ptr != NULL) - png_memset(struct_ptr, 0, size); - - return (struct_ptr); - } -# endif /* PNG_USER_MEM_SUPPORTED */ - -# if defined(__TURBOC__) && !defined(__FLAT__) - struct_ptr = (png_voidp)farmalloc(size); -# else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - struct_ptr = (png_voidp)halloc(size, 1); -# else - struct_ptr = (png_voidp)malloc(size); -# endif -# endif - - if (struct_ptr != NULL) - png_memset(struct_ptr, 0, size); - - return (struct_ptr); -} - - -/* Free memory allocated by a png_create_struct() call */ -void /* PRIVATE */ -png_destroy_struct(png_voidp struct_ptr) -{ -# ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2(struct_ptr, NULL, NULL); -} - -/* Free memory allocated by a png_create_struct() call */ -void /* PRIVATE */ -png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, - png_voidp mem_ptr) -{ -# endif /* PNG_USER_MEM_SUPPORTED */ - if (struct_ptr != NULL) - { -# ifdef PNG_USER_MEM_SUPPORTED - if (free_fn != NULL) - { - png_struct dummy_struct; - png_structp png_ptr = &dummy_struct; - png_ptr->mem_ptr=mem_ptr; - (*(free_fn))(png_ptr, struct_ptr); - return; - } -# endif /* PNG_USER_MEM_SUPPORTED */ -# if defined(__TURBOC__) && !defined(__FLAT__) - farfree(struct_ptr); - -# else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - hfree(struct_ptr); - -# else - free(struct_ptr); - -# endif -# endif + /* png_free might call png_error and may certainly call + * png_get_mem_ptr, so fake a temporary png_struct to support this. + */ + png_struct dummy_struct = *png_ptr; + memset(png_ptr, 0, (sizeof *png_ptr)); + png_free(&dummy_struct, png_ptr); + +# ifdef PNG_SETJMP_SUPPORTED + /* We may have a jmp_buf left to deallocate. */ + png_free_jmpbuf(&dummy_struct); +# endif } } @@ -508,167 +74,215 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, * need to allocate exactly 64K, so whatever you call here must * have the ability to do that. */ - PNG_FUNCTION(png_voidp,PNGAPI -png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) { png_voidp ret; - ret = (png_malloc(png_ptr, size)); + ret = png_malloc(png_ptr, size); if (ret != NULL) - png_memset(ret,0,(png_size_t)size); + memset(ret, 0, size); - return (ret); + return ret; } -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +/* png_malloc_base, an internal function added at libpng 1.6.0, does the work of + * allocating memory, taking into account limits and PNG_USER_MEM_SUPPORTED. + * Checking and error handling must happen outside this routine; it returns NULL + * if the allocation cannot be done (for any reason.) + */ +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size), + PNG_ALLOCATED) { - png_voidp ret; + /* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS + * allocators have also been removed in 1.6.0, so any 16-bit system now has + * to implement a user memory handler. This checks to be sure it isn't + * called with big numbers. + */ +#ifndef PNG_USER_MEM_SUPPORTED + PNG_UNUSED(png_ptr) +#endif -# ifdef PNG_USER_MEM_SUPPORTED - if (png_ptr == NULL || size == 0) - return (NULL); - - if (png_ptr->malloc_fn != NULL) - ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size)); - - else - ret = (png_malloc_default(png_ptr, size)); - - if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of Memory"); - - return (ret); -} - -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; -# endif /* PNG_USER_MEM_SUPPORTED */ - - if (png_ptr == NULL || size == 0) - return (NULL); - -# ifdef PNG_MAX_MALLOC_64K - if (size > (png_uint_32)65536L) + if (size > 0 && size <= PNG_SIZE_MAX +# ifdef PNG_MAX_MALLOC_64K + && size <= 65536U +# endif + ) { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Cannot Allocate > 64K"); +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr != NULL && png_ptr->malloc_fn != NULL) + return png_ptr->malloc_fn(png_constcast(png_structrp,png_ptr), size); else -# endif - return NULL; +#endif + return malloc((size_t)size); /* checked for truncation above */ } -# endif - - /* Check for overflow */ -# if defined(__TURBOC__) && !defined(__FLAT__) - - if (size != (unsigned long)size) - ret = NULL; else - ret = farmalloc(size); + return NULL; +} -# else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - if (size != (unsigned long)size) - ret = NULL; +#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\ + defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) +/* This is really here only to work round a spurious warning in GCC 4.6 and 4.7 + * that arises because of the checks in png_realloc_array that are repeated in + * png_malloc_array. + */ +static png_voidp +png_malloc_array_checked(png_const_structrp png_ptr, int nelements, + size_t element_size) +{ + png_alloc_size_t req = nelements; /* known to be > 0 */ - else - ret = halloc(size, 1); + if (req <= PNG_SIZE_MAX/element_size) + return png_malloc_base(png_ptr, req * element_size); -# else - if (size != (size_t)size) - ret = NULL; + /* The failure case when the request is too large */ + return NULL; +} - else - ret = malloc((size_t)size); -# endif -# endif +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_malloc_array,(png_const_structrp png_ptr, int nelements, + size_t element_size),PNG_ALLOCATED) +{ + if (nelements <= 0 || element_size == 0) + png_error(png_ptr, "internal error: array alloc"); -# ifndef PNG_USER_MEM_SUPPORTED - if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of Memory"); -# endif + return png_malloc_array_checked(png_ptr, nelements, element_size); +} - return (ret); +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array, + int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED) +{ + /* These are internal errors: */ + if (add_elements <= 0 || element_size == 0 || old_elements < 0 || + (old_array == NULL && old_elements > 0)) + png_error(png_ptr, "internal error: array realloc"); + + /* Check for overflow on the elements count (so the caller does not have to + * check.) + */ + if (add_elements <= INT_MAX - old_elements) + { + png_voidp new_array = png_malloc_array_checked(png_ptr, + old_elements+add_elements, element_size); + + if (new_array != NULL) + { + /* Because png_malloc_array worked the size calculations below cannot + * overflow. + */ + if (old_elements > 0) + memcpy(new_array, old_array, element_size*(unsigned)old_elements); + + memset((char*)new_array + element_size*(unsigned)old_elements, 0, + element_size*(unsigned)add_elements); + + return new_array; + } + } + + return NULL; /* error */ +} +#endif /* TEXT || sPLT || STORE_UNKNOWN_CHUNKS */ + +/* Various functions that have different error handling are derived from this. + * png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate + * function png_malloc_default is also provided. + */ +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ret; + + if (png_ptr == NULL) + return NULL; + + ret = png_malloc_base(png_ptr, size); + + if (ret == NULL) + png_error(png_ptr, "Out of memory"); /* 'm' means png_malloc */ + + return ret; +} + +#ifdef PNG_USER_MEM_SUPPORTED +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size), + PNG_ALLOCATED PNG_DEPRECATED) +{ + png_voidp ret; + + if (png_ptr == NULL) + return NULL; + + /* Passing 'NULL' here bypasses the application provided memory handler. */ + ret = png_malloc_base(NULL/*use malloc*/, size); + + if (ret == NULL) + png_error(png_ptr, "Out of Memory"); /* 'M' means png_malloc_default */ + + return ret; +} +#endif /* USER_MEM */ + +/* This function was added at libpng version 1.2.3. The png_malloc_warn() + * function will issue a png_warning and return NULL instead of issuing a + * png_error, if it fails to allocate the requested memory. + */ +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size), + PNG_ALLOCATED) +{ + if (png_ptr != NULL) + { + png_voidp ret = png_malloc_base(png_ptr, size); + + if (ret != NULL) + return ret; + + png_warning(png_ptr, "Out of memory"); + } + + return NULL; } /* Free a pointer allocated by png_malloc(). If ptr is NULL, return * without taking any action. */ void PNGAPI -png_free(png_structp png_ptr, png_voidp ptr) +png_free(png_const_structrp png_ptr, png_voidp ptr) { if (png_ptr == NULL || ptr == NULL) return; -# ifdef PNG_USER_MEM_SUPPORTED +#ifdef PNG_USER_MEM_SUPPORTED if (png_ptr->free_fn != NULL) - { - (*(png_ptr->free_fn))(png_ptr, ptr); - return; - } + png_ptr->free_fn(png_constcast(png_structrp,png_ptr), ptr); else png_free_default(png_ptr, ptr); } -void PNGAPI -png_free_default(png_structp png_ptr, png_voidp ptr) +PNG_FUNCTION(void,PNGAPI +png_free_default,(png_const_structrp png_ptr, png_voidp ptr),PNG_DEPRECATED) { if (png_ptr == NULL || ptr == NULL) return; +#endif /* USER_MEM */ -# endif /* PNG_USER_MEM_SUPPORTED */ - -# if defined(__TURBOC__) && !defined(__FLAT__) - farfree(ptr); - -# else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - hfree(ptr); - -# else free(ptr); - -# endif -# endif } -#endif /* Not Borland DOS special memory handler */ - -/* This function was added at libpng version 1.2.3. The png_malloc_warn() - * function will set up png_malloc() to issue a png_warning and return NULL - * instead of issuing a png_error, if it fails to allocate the requested - * memory. - */ -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ptr; - png_uint_32 save_flags; - if (png_ptr == NULL) - return (NULL); - - save_flags = png_ptr->flags; - png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; - ptr = (png_voidp)png_malloc((png_structp)png_ptr, size); - png_ptr->flags=save_flags; - return(ptr); -} - #ifdef PNG_USER_MEM_SUPPORTED /* This function is called when the application wants to use another method * of allocating and freeing memory. */ void PNGAPI -png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr +png_set_mem_fn(png_structrp png_ptr, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn) { if (png_ptr != NULL) @@ -684,12 +298,12 @@ png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr * pointer before png_write_destroy and png_read_destroy are called. */ png_voidp PNGAPI -png_get_mem_ptr(png_const_structp png_ptr) +png_get_mem_ptr(png_const_structrp png_ptr) { if (png_ptr == NULL) - return (NULL); + return NULL; - return ((png_voidp)png_ptr->mem_ptr); + return png_ptr->mem_ptr; } -#endif /* PNG_USER_MEM_SUPPORTED */ -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ +#endif /* USER_MEM */ +#endif /* READ || WRITE */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngpread.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngpread.c index 258a163ff92..a0a92bb7faf 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngpread.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngpread.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.2 [March 31, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -54,8 +54,15 @@ #define PNG_READ_iTXt_MODE 7 #define PNG_ERROR_MODE 8 +#define PNG_PUSH_SAVE_BUFFER_IF_FULL \ +if (png_ptr->push_length + 4 > png_ptr->buffer_size) \ + { png_push_save_buffer(png_ptr); return; } +#define PNG_PUSH_SAVE_BUFFER_IF_LT(N) \ +if (png_ptr->buffer_size < N) \ + { png_push_save_buffer(png_ptr); return; } + void PNGAPI -png_process_data(png_structp png_ptr, png_infop info_ptr, +png_process_data(png_structrp png_ptr, png_inforp info_ptr, png_bytep buffer, png_size_t buffer_size) { if (png_ptr == NULL || info_ptr == NULL) @@ -70,14 +77,14 @@ png_process_data(png_structp png_ptr, png_infop info_ptr, } png_size_t PNGAPI -png_process_data_pause(png_structp png_ptr, int save) +png_process_data_pause(png_structrp png_ptr, int save) { if (png_ptr != NULL) { - /* It's easiest for the caller if we do the save, then the caller doesn't + /* It's easiest for the caller if we do the save; then the caller doesn't * have to supply the same data again: */ - if (save) + if (save != 0) png_push_save_buffer(png_ptr); else { @@ -97,7 +104,7 @@ png_process_data_pause(png_structp png_ptr, int save) } png_uint_32 PNGAPI -png_process_data_skip(png_structp png_ptr) +png_process_data_skip(png_structrp png_ptr) { png_uint_32 remaining = 0; @@ -131,7 +138,7 @@ png_process_data_skip(png_structp png_ptr) * doing before we ran out of data... */ void /* PRIVATE */ -png_process_some_data(png_structp png_ptr, png_infop info_ptr) +png_process_some_data(png_structrp png_ptr, png_inforp info_ptr) { if (png_ptr == NULL) return; @@ -156,30 +163,6 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr) break; } -#ifdef PNG_READ_tEXt_SUPPORTED - case PNG_READ_tEXt_MODE: - { - png_push_read_tEXt(png_ptr, info_ptr); - break; - } - -#endif -#ifdef PNG_READ_zTXt_SUPPORTED - case PNG_READ_zTXt_MODE: - { - png_push_read_zTXt(png_ptr, info_ptr); - break; - } - -#endif -#ifdef PNG_READ_iTXt_SUPPORTED - case PNG_READ_iTXt_MODE: - { - png_push_read_iTXt(png_ptr, info_ptr); - break; - } - -#endif case PNG_SKIP_MODE: { png_push_crc_finish(png_ptr); @@ -201,9 +184,9 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr) * routine. */ void /* PRIVATE */ -png_push_read_sig(png_structp png_ptr, png_infop info_ptr) +png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr) { - png_size_t num_checked = png_ptr->sig_bytes, + png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ num_to_check = 8 - num_checked; if (png_ptr->buffer_size < num_to_check) @@ -234,114 +217,75 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr) } void /* PRIVATE */ -png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) +png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr) { - PNG_IHDR; - PNG_IDAT; - PNG_IEND; - PNG_PLTE; -#ifdef PNG_READ_bKGD_SUPPORTED - PNG_bKGD; -#endif -#ifdef PNG_READ_cHRM_SUPPORTED - PNG_cHRM; -#endif -#ifdef PNG_READ_gAMA_SUPPORTED - PNG_gAMA; -#endif -#ifdef PNG_READ_hIST_SUPPORTED - PNG_hIST; -#endif -#ifdef PNG_READ_iCCP_SUPPORTED - PNG_iCCP; -#endif -#ifdef PNG_READ_iTXt_SUPPORTED - PNG_iTXt; -#endif -#ifdef PNG_READ_oFFs_SUPPORTED - PNG_oFFs; -#endif -#ifdef PNG_READ_pCAL_SUPPORTED - PNG_pCAL; -#endif -#ifdef PNG_READ_pHYs_SUPPORTED - PNG_pHYs; -#endif -#ifdef PNG_READ_sBIT_SUPPORTED - PNG_sBIT; -#endif -#ifdef PNG_READ_sCAL_SUPPORTED - PNG_sCAL; -#endif -#ifdef PNG_READ_sRGB_SUPPORTED - PNG_sRGB; -#endif -#ifdef PNG_READ_sPLT_SUPPORTED - PNG_sPLT; -#endif -#ifdef PNG_READ_tEXt_SUPPORTED - PNG_tEXt; -#endif -#ifdef PNG_READ_tIME_SUPPORTED - PNG_tIME; -#endif -#ifdef PNG_READ_tRNS_SUPPORTED - PNG_tRNS; -#endif -#ifdef PNG_READ_zTXt_SUPPORTED - PNG_zTXt; + png_uint_32 chunk_name; +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + int keep; /* unknown handling method */ #endif - /* First we make sure we have enough data for the 4 byte chunk name - * and the 4 byte chunk length before proceeding with decoding the + /* First we make sure we have enough data for the 4-byte chunk name + * and the 4-byte chunk length before proceeding with decoding the * chunk data. To fully decode each of these chunks, we also make - * sure we have enough data in the buffer for the 4 byte CRC at the + * sure we have enough data in the buffer for the 4-byte CRC at the * end of every chunk (except IDAT, which is handled separately). */ - if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) + if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0) { png_byte chunk_length[4]; + png_byte chunk_tag[4]; - if (png_ptr->buffer_size < 8) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_LT(8) png_push_fill_buffer(png_ptr, chunk_length, 4); png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); png_reset_crc(png_ptr); - png_crc_read(png_ptr, png_ptr->chunk_name, 4); + png_crc_read(png_ptr, chunk_tag, 4); + png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); png_check_chunk_name(png_ptr, png_ptr->chunk_name); png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; } - if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) - if (png_ptr->mode & PNG_AFTER_IDAT) + chunk_name = png_ptr->chunk_name; + + if (chunk_name == png_IDAT) + { + if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; - if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) + /* If we reach an IDAT chunk, this means we have read all of the + * header chunks, and we can start reading the image (or if this + * is called after the image has been read - we have an error). + */ + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + (png_ptr->mode & PNG_HAVE_PLTE) == 0) + png_error(png_ptr, "Missing PLTE before IDAT"); + + png_ptr->mode |= PNG_HAVE_IDAT; + png_ptr->process_mode = PNG_READ_IDAT_MODE; + + if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0) + if (png_ptr->push_length == 0) + return; + + if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) + png_benign_error(png_ptr, "Too many IDATs found"); + } + + if (chunk_name == png_IHDR) { if (png_ptr->push_length != 13) png_error(png_ptr, "Invalid IHDR length"); - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); } - else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) + else if (chunk_name == png_IEND) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); png_ptr->process_mode = PNG_READ_DONE_MODE; @@ -349,70 +293,25 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) } #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) + else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep); - if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) - png_ptr->mode |= PNG_HAVE_IDAT; - - png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); - - if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + if (chunk_name == png_PLTE) png_ptr->mode |= PNG_HAVE_PLTE; - - else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) - { - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before IDAT"); - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) - png_error(png_ptr, "Missing PLTE before IDAT"); - } } - #endif - else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + + else if (chunk_name == png_PLTE) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); } - else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + else if (chunk_name == png_IDAT) { - /* If we reach an IDAT chunk, this means we have read all of the - * header chunks, and we can start reading the image (or if this - * is called after the image has been read - we have an error). - */ - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before IDAT"); - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) - png_error(png_ptr, "Missing PLTE before IDAT"); - - if (png_ptr->mode & PNG_HAVE_IDAT) - { - if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) - if (png_ptr->push_length == 0) - return; - - if (png_ptr->mode & PNG_AFTER_IDAT) - png_benign_error(png_ptr, "Too many IDATs found"); - } - png_ptr->idat_size = png_ptr->push_length; - png_ptr->mode |= PNG_HAVE_IDAT; png_ptr->process_mode = PNG_READ_IDAT_MODE; png_push_have_info(png_ptr, info_ptr); png_ptr->zstream.avail_out = @@ -423,250 +322,162 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) } #ifdef PNG_READ_gAMA_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) + else if (png_ptr->chunk_name == png_gAMA) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_sBIT_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) + else if (png_ptr->chunk_name == png_sBIT) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_cHRM_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) + else if (png_ptr->chunk_name == png_cHRM) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_sRGB_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) + else if (chunk_name == png_sRGB) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_iCCP_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) + else if (png_ptr->chunk_name == png_iCCP) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_sPLT_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) + else if (chunk_name == png_sPLT) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_tRNS_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) + else if (chunk_name == png_tRNS) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_bKGD_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) + else if (chunk_name == png_bKGD) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_hIST_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) + else if (chunk_name == png_hIST) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_pHYs_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) + else if (chunk_name == png_pHYs) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_oFFs_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) + else if (chunk_name == png_oFFs) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_pCAL_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) + else if (chunk_name == png_pCAL) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_sCAL_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) + else if (chunk_name == png_sCAL) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_tIME_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) + else if (chunk_name == png_tIME) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_FULL png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_tEXt_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) + else if (chunk_name == png_tEXt) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_zTXt_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) + else if (chunk_name == png_zTXt) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); } #endif #ifdef PNG_READ_iTXt_SUPPORTED - else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) + else if (chunk_name == png_iTXt) { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); } - #endif + else { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, + PNG_HANDLE_CHUNK_AS_DEFAULT); } png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; } void /* PRIVATE */ -png_push_crc_skip(png_structp png_ptr, png_uint_32 skip) +png_push_crc_skip(png_structrp png_ptr, png_uint_32 skip) { png_ptr->process_mode = PNG_SKIP_MODE; png_ptr->skip_length = skip; } void /* PRIVATE */ -png_push_crc_finish(png_structp png_ptr) +png_push_crc_finish(png_structrp png_ptr) { - if (png_ptr->skip_length && png_ptr->save_buffer_size) + if (png_ptr->skip_length != 0 && png_ptr->save_buffer_size != 0) { png_size_t save_size = png_ptr->save_buffer_size; png_uint_32 skip_length = png_ptr->skip_length; @@ -690,7 +501,7 @@ png_push_crc_finish(png_structp png_ptr) png_ptr->save_buffer_size -= save_size; png_ptr->save_buffer_ptr += save_size; } - if (png_ptr->skip_length && png_ptr->current_buffer_size) + if (png_ptr->skip_length != 0 && png_ptr->current_buffer_size != 0) { png_size_t save_size = png_ptr->current_buffer_size; png_uint_32 skip_length = png_ptr->skip_length; @@ -711,14 +522,9 @@ png_push_crc_finish(png_structp png_ptr) png_ptr->current_buffer_size -= save_size; png_ptr->current_buffer_ptr += save_size; } - if (!png_ptr->skip_length) + if (png_ptr->skip_length == 0) { - if (png_ptr->buffer_size < 4) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_LT(4) png_crc_finish(png_ptr, 0); png_ptr->process_mode = PNG_READ_CHUNK_MODE; } @@ -733,7 +539,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) return; ptr = buffer; - if (png_ptr->save_buffer_size) + if (png_ptr->save_buffer_size != 0) { png_size_t save_size; @@ -743,14 +549,14 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) else save_size = png_ptr->save_buffer_size; - png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size); + memcpy(ptr, png_ptr->save_buffer_ptr, save_size); length -= save_size; ptr += save_size; png_ptr->buffer_size -= save_size; png_ptr->save_buffer_size -= save_size; png_ptr->save_buffer_ptr += save_size; } - if (length && png_ptr->current_buffer_size) + if (length != 0 && png_ptr->current_buffer_size != 0) { png_size_t save_size; @@ -760,7 +566,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) else save_size = png_ptr->current_buffer_size; - png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size); + memcpy(ptr, png_ptr->current_buffer_ptr, save_size); png_ptr->buffer_size -= save_size; png_ptr->current_buffer_size -= save_size; png_ptr->current_buffer_ptr += save_size; @@ -768,9 +574,9 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) } void /* PRIVATE */ -png_push_save_buffer(png_structp png_ptr) +png_push_save_buffer(png_structrp png_ptr) { - if (png_ptr->save_buffer_size) + if (png_ptr->save_buffer_size != 0) { if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) { @@ -806,16 +612,18 @@ png_push_save_buffer(png_structp png_ptr) if (png_ptr->save_buffer == NULL) { png_free(png_ptr, old_buffer); + old_buffer = NULL; png_error(png_ptr, "Insufficient memory for save_buffer"); } - png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); + memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); png_free(png_ptr, old_buffer); + old_buffer = NULL; png_ptr->save_buffer_max = new_max; } if (png_ptr->current_buffer_size) { - png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, + memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); png_ptr->save_buffer_size += png_ptr->current_buffer_size; png_ptr->current_buffer_size = 0; @@ -825,7 +633,7 @@ png_push_save_buffer(png_structp png_ptr) } void /* PRIVATE */ -png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, +png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer, png_size_t buffer_length) { png_ptr->current_buffer = buffer; @@ -835,30 +643,27 @@ png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, } void /* PRIVATE */ -png_push_read_IDAT(png_structp png_ptr) +png_push_read_IDAT(png_structrp png_ptr) { - PNG_IDAT; - if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) + if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0) { png_byte chunk_length[4]; + png_byte chunk_tag[4]; - if (png_ptr->buffer_size < 8) - { - png_push_save_buffer(png_ptr); - return; - } - + /* TODO: this code can be commoned up with the same code in push_read */ + PNG_PUSH_SAVE_BUFFER_IF_LT(8) png_push_fill_buffer(png_ptr, chunk_length, 4); png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); png_reset_crc(png_ptr); - png_crc_read(png_ptr, png_ptr->chunk_name, 4); + png_crc_read(png_ptr, chunk_tag, 4); + png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; - if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + if (png_ptr->chunk_name != png_IDAT) { png_ptr->process_mode = PNG_READ_CHUNK_MODE; - if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0) png_error(png_ptr, "Not enough compressed data"); return; @@ -866,7 +671,8 @@ png_push_read_IDAT(png_structp png_ptr) png_ptr->idat_size = png_ptr->push_length; } - if (png_ptr->idat_size && png_ptr->save_buffer_size) + + if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0) { png_size_t save_size = png_ptr->save_buffer_size; png_uint_32 idat_size = png_ptr->idat_size; @@ -893,7 +699,7 @@ png_push_read_IDAT(png_structp png_ptr) png_ptr->save_buffer_ptr += save_size; } - if (png_ptr->idat_size && png_ptr->current_buffer_size) + if (png_ptr->idat_size != 0 && png_ptr->current_buffer_size != 0) { png_size_t save_size = png_ptr->current_buffer_size; png_uint_32 idat_size = png_ptr->idat_size; @@ -918,22 +724,18 @@ png_push_read_IDAT(png_structp png_ptr) png_ptr->current_buffer_size -= save_size; png_ptr->current_buffer_ptr += save_size; } - if (!png_ptr->idat_size) + if (png_ptr->idat_size == 0) { - if (png_ptr->buffer_size < 4) - { - png_push_save_buffer(png_ptr); - return; - } - + PNG_PUSH_SAVE_BUFFER_IF_LT(4) png_crc_finish(png_ptr, 0); png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->zowner = 0; } } void /* PRIVATE */ -png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, +png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer, png_size_t buffer_length) { /* The caller checks for a non-zero buffer length. */ @@ -945,13 +747,14 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, * handle the uncompressed results. */ png_ptr->zstream.next_in = buffer; + /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */ png_ptr->zstream.avail_in = (uInt)buffer_length; /* Keep going until the decompressed data is all processed * or the stream marked as finished. */ while (png_ptr->zstream.avail_in > 0 && - !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + !(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED)) { int ret; @@ -962,9 +765,9 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, */ if (!(png_ptr->zstream.avail_out > 0)) { - png_ptr->zstream.avail_out = - (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, - png_ptr->iwidth) + 1; + /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */ + png_ptr->zstream.avail_out = (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1); png_ptr->zstream.next_out = png_ptr->row_buf; } @@ -982,7 +785,8 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, if (ret != Z_OK && ret != Z_STREAM_END) { /* Terminate the decompression. */ - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; + png_ptr->zowner = 0; /* This may be a truncated stream (missing or * damaged end code). Treat that as a warning. @@ -1010,7 +814,8 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, { /* Extra data. */ png_warning(png_ptr, "Extra compressed data in IDAT"); - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; + png_ptr->zowner = 0; /* Do no more processing; skip the unprocessed * input check below. @@ -1025,7 +830,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, /* And check for the end of the stream. */ if (ret == Z_STREAM_END) - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; } /* All the data should have been processed, if anything @@ -1037,41 +842,62 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, } void /* PRIVATE */ -png_push_process_row(png_structp png_ptr) +png_push_process_row(png_structrp png_ptr) { - png_ptr->row_info.color_type = png_ptr->color_type; - png_ptr->row_info.width = png_ptr->iwidth; - png_ptr->row_info.channels = png_ptr->channels; - png_ptr->row_info.bit_depth = png_ptr->bit_depth; - png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; + /* 1.5.6: row_info moved out of png_struct to a local here. */ + png_row_info row_info; - png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, - png_ptr->row_info.width); + row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ + row_info.color_type = png_ptr->color_type; + row_info.bit_depth = png_ptr->bit_depth; + row_info.channels = png_ptr->channels; + row_info.pixel_depth = png_ptr->pixel_depth; + row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); - png_read_filter_row(png_ptr, &(png_ptr->row_info), - png_ptr->row_buf + 1, png_ptr->prev_row + 1, - (int)(png_ptr->row_buf[0])); + if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) + { + if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) + png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, + png_ptr->prev_row + 1, png_ptr->row_buf[0]); + else + png_error(png_ptr, "bad adaptive filter value"); + } - png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1); + /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before + * 1.5.6, while the buffer really is this big in current versions of libpng + * it may not be in the future, so this was changed just to copy the + * interlaced row count: + */ + memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); #ifdef PNG_READ_TRANSFORMS_SUPPORTED - if (png_ptr->transformations) - png_do_read_transformations(png_ptr); + if (png_ptr->transformations != 0) + png_do_read_transformations(png_ptr, &row_info); #endif + /* The transformed pixel depth should match the depth now in row_info. */ + if (png_ptr->transformed_pixel_depth == 0) + { + png_ptr->transformed_pixel_depth = row_info.pixel_depth; + if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) + png_error(png_ptr, "progressive row overflow"); + } + + else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) + png_error(png_ptr, "internal progressive row size calculation error"); + + #ifdef PNG_READ_INTERLACING_SUPPORTED - /* Blow up interlaced rows to full size */ - if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + /* Expand interlaced rows to full size */ + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0) { if (png_ptr->pass < 6) -/* old interface (pre-1.0.9): - png_do_read_interlace(&(png_ptr->row_info), - png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); - */ - png_do_read_interlace(png_ptr); + png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, + png_ptr->transformations); - switch (png_ptr->pass) - { + switch (png_ptr->pass) + { case 0: { int i; @@ -1238,7 +1064,6 @@ png_push_process_row(png_structp png_ptr) } } else -#endif { png_push_have_row(png_ptr, png_ptr->row_buf + 1); png_read_push_finish_row(png_ptr); @@ -1246,36 +1071,36 @@ png_push_process_row(png_structp png_ptr) } void /* PRIVATE */ -png_read_push_finish_row(png_structp png_ptr) +png_read_push_finish_row(png_structrp png_ptr) { /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ - PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; /* Offset to next interlace block */ - PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; /* Start of interlace block in the y direction */ - PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; + static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; /* Offset to next interlace block in the y direction */ - PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; + static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; /* Height of interlace block. This is not currently used - if you need * it, uncomment it here and in png.h - PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; + static PNG_CONST png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; */ +#endif png_ptr->row_number++; if (png_ptr->row_number < png_ptr->num_rows) return; -#ifdef PNG_READ_INTERLACING_SUPPORTED - if (png_ptr->interlaced) + if (png_ptr->interlaced != 0) { png_ptr->row_number = 0; - png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); do { @@ -1296,7 +1121,7 @@ png_read_push_finish_row(png_structp png_ptr) png_pass_start[png_ptr->pass]) / png_pass_inc[png_ptr->pass]; - if (png_ptr->transformations & PNG_INTERLACE) + if ((png_ptr->transformations & PNG_INTERLACE) != 0) break; png_ptr->num_rows = (png_ptr->height + @@ -1306,538 +1131,24 @@ png_read_push_finish_row(png_structp png_ptr) } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); } -#endif /* PNG_READ_INTERLACING_SUPPORTED */ -} - -#ifdef PNG_READ_tEXt_SUPPORTED -void /* PRIVATE */ -png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 - length) -{ - if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) - { - PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */ - png_error(png_ptr, "Out of place tEXt"); - /* NOT REACHED */ - } - -#ifdef PNG_MAX_MALLOC_64K - png_ptr->skip_length = 0; /* This may not be necessary */ - - if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ - { - png_warning(png_ptr, "tEXt chunk too large to fit in memory"); - png_ptr->skip_length = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; - } -#endif - - png_ptr->current_text = (png_charp)png_malloc(png_ptr, - (png_size_t)(length + 1)); - png_ptr->current_text[length] = '\0'; - png_ptr->current_text_ptr = png_ptr->current_text; - png_ptr->current_text_size = (png_size_t)length; - png_ptr->current_text_left = (png_size_t)length; - png_ptr->process_mode = PNG_READ_tEXt_MODE; } void /* PRIVATE */ -png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) -{ - if (png_ptr->buffer_size && png_ptr->current_text_left) - { - png_size_t text_size; - - if (png_ptr->buffer_size < png_ptr->current_text_left) - text_size = png_ptr->buffer_size; - - else - text_size = png_ptr->current_text_left; - - png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); - png_ptr->current_text_left -= text_size; - png_ptr->current_text_ptr += text_size; - } - if (!(png_ptr->current_text_left)) - { - png_textp text_ptr; - png_charp text; - png_charp key; - int ret; - - if (png_ptr->buffer_size < 4) - { - png_push_save_buffer(png_ptr); - return; - } - - png_push_crc_finish(png_ptr); - -#ifdef PNG_MAX_MALLOC_64K - if (png_ptr->skip_length) - return; -#endif - - key = png_ptr->current_text; - - for (text = key; *text; text++) - /* Empty loop */ ; - - if (text < key + png_ptr->current_text_size) - text++; - - text_ptr = (png_textp)png_malloc(png_ptr, png_sizeof(png_text)); - text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr->key = key; - text_ptr->itxt_length = 0; - text_ptr->lang = NULL; - text_ptr->lang_key = NULL; - text_ptr->text = text; - - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); - - png_free(png_ptr, key); - png_free(png_ptr, text_ptr); - png_ptr->current_text = NULL; - - if (ret) - png_warning(png_ptr, "Insufficient memory to store text chunk"); - } -} -#endif - -#ifdef PNG_READ_zTXt_SUPPORTED -void /* PRIVATE */ -png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 - length) -{ - if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) - { - PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */ - png_error(png_ptr, "Out of place zTXt"); - /* NOT REACHED */ - } - -#ifdef PNG_MAX_MALLOC_64K - /* We can't handle zTXt chunks > 64K, since we don't have enough space - * to be able to store the uncompressed data. Actually, the threshold - * is probably around 32K, but it isn't as definite as 64K is. - */ - if (length > (png_uint_32)65535L) - { - png_warning(png_ptr, "zTXt chunk too large to fit in memory"); - png_push_crc_skip(png_ptr, length); - return; - } -#endif - - png_ptr->current_text = (png_charp)png_malloc(png_ptr, - (png_size_t)(length + 1)); - png_ptr->current_text[length] = '\0'; - png_ptr->current_text_ptr = png_ptr->current_text; - png_ptr->current_text_size = (png_size_t)length; - png_ptr->current_text_left = (png_size_t)length; - png_ptr->process_mode = PNG_READ_zTXt_MODE; -} - -void /* PRIVATE */ -png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) -{ - if (png_ptr->buffer_size && png_ptr->current_text_left) - { - png_size_t text_size; - - if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left) - text_size = png_ptr->buffer_size; - - else - text_size = png_ptr->current_text_left; - - png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); - png_ptr->current_text_left -= text_size; - png_ptr->current_text_ptr += text_size; - } - if (!(png_ptr->current_text_left)) - { - png_textp text_ptr; - png_charp text; - png_charp key; - int ret; - png_size_t text_size, key_size; - - if (png_ptr->buffer_size < 4) - { - png_push_save_buffer(png_ptr); - return; - } - - png_push_crc_finish(png_ptr); - - key = png_ptr->current_text; - - for (text = key; *text; text++) - /* Empty loop */ ; - - /* zTXt can't have zero text */ - if (text >= key + png_ptr->current_text_size) - { - png_ptr->current_text = NULL; - png_free(png_ptr, key); - return; - } - - text++; - - if (*text != PNG_TEXT_COMPRESSION_zTXt) /* Check compression byte */ - { - png_ptr->current_text = NULL; - png_free(png_ptr, key); - return; - } - - text++; - - png_ptr->zstream.next_in = (png_bytep)text; - png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size - - (text - key)); - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - - key_size = text - key; - text_size = 0; - text = NULL; - ret = Z_STREAM_END; - - while (png_ptr->zstream.avail_in) - { - ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); - if (ret != Z_OK && ret != Z_STREAM_END) - { - inflateReset(&png_ptr->zstream); - png_ptr->zstream.avail_in = 0; - png_ptr->current_text = NULL; - png_free(png_ptr, key); - png_free(png_ptr, text); - return; - } - - if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END) - { - if (text == NULL) - { - text = (png_charp)png_malloc(png_ptr, - (png_ptr->zbuf_size - - png_ptr->zstream.avail_out + key_size + 1)); - - png_memcpy(text + key_size, png_ptr->zbuf, - png_ptr->zbuf_size - png_ptr->zstream.avail_out); - - png_memcpy(text, key, key_size); - - text_size = key_size + png_ptr->zbuf_size - - png_ptr->zstream.avail_out; - - *(text + text_size) = '\0'; - } - - else - { - png_charp tmp; - - tmp = text; - text = (png_charp)png_malloc(png_ptr, text_size + - (png_ptr->zbuf_size - - png_ptr->zstream.avail_out + 1)); - - png_memcpy(text, tmp, text_size); - png_free(png_ptr, tmp); - - png_memcpy(text + text_size, png_ptr->zbuf, - png_ptr->zbuf_size - png_ptr->zstream.avail_out); - - text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out; - *(text + text_size) = '\0'; - } - - if (ret != Z_STREAM_END) - { - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - } - } - else - { - break; - } - - if (ret == Z_STREAM_END) - break; - } - - inflateReset(&png_ptr->zstream); - png_ptr->zstream.avail_in = 0; - - if (ret != Z_STREAM_END) - { - png_ptr->current_text = NULL; - png_free(png_ptr, key); - png_free(png_ptr, text); - return; - } - - png_ptr->current_text = NULL; - png_free(png_ptr, key); - key = text; - text += key_size; - - text_ptr = (png_textp)png_malloc(png_ptr, - png_sizeof(png_text)); - text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt; - text_ptr->key = key; - text_ptr->itxt_length = 0; - text_ptr->lang = NULL; - text_ptr->lang_key = NULL; - text_ptr->text = text; - - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); - - png_free(png_ptr, key); - png_free(png_ptr, text_ptr); - - if (ret) - png_warning(png_ptr, "Insufficient memory to store text chunk"); - } -} -#endif - -#ifdef PNG_READ_iTXt_SUPPORTED -void /* PRIVATE */ -png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 - length) -{ - if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) - { - PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */ - png_error(png_ptr, "Out of place iTXt"); - /* NOT REACHED */ - } - -#ifdef PNG_MAX_MALLOC_64K - png_ptr->skip_length = 0; /* This may not be necessary */ - - if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ - { - png_warning(png_ptr, "iTXt chunk too large to fit in memory"); - png_ptr->skip_length = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; - } -#endif - - png_ptr->current_text = (png_charp)png_malloc(png_ptr, - (png_size_t)(length + 1)); - png_ptr->current_text[length] = '\0'; - png_ptr->current_text_ptr = png_ptr->current_text; - png_ptr->current_text_size = (png_size_t)length; - png_ptr->current_text_left = (png_size_t)length; - png_ptr->process_mode = PNG_READ_iTXt_MODE; -} - -void /* PRIVATE */ -png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) -{ - - if (png_ptr->buffer_size && png_ptr->current_text_left) - { - png_size_t text_size; - - if (png_ptr->buffer_size < png_ptr->current_text_left) - text_size = png_ptr->buffer_size; - - else - text_size = png_ptr->current_text_left; - - png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); - png_ptr->current_text_left -= text_size; - png_ptr->current_text_ptr += text_size; - } - - if (!(png_ptr->current_text_left)) - { - png_textp text_ptr; - png_charp key; - int comp_flag; - png_charp lang; - png_charp lang_key; - png_charp text; - int ret; - - if (png_ptr->buffer_size < 4) - { - png_push_save_buffer(png_ptr); - return; - } - - png_push_crc_finish(png_ptr); - -#ifdef PNG_MAX_MALLOC_64K - if (png_ptr->skip_length) - return; -#endif - - key = png_ptr->current_text; - - for (lang = key; *lang; lang++) - /* Empty loop */ ; - - if (lang < key + png_ptr->current_text_size - 3) - lang++; - - comp_flag = *lang++; - lang++; /* Skip comp_type, always zero */ - - for (lang_key = lang; *lang_key; lang_key++) - /* Empty loop */ ; - - lang_key++; /* Skip NUL separator */ - - text=lang_key; - - if (lang_key < key + png_ptr->current_text_size - 1) - { - for (; *text; text++) - /* Empty loop */ ; - } - - if (text < key + png_ptr->current_text_size) - text++; - - text_ptr = (png_textp)png_malloc(png_ptr, - png_sizeof(png_text)); - - text_ptr->compression = comp_flag + 2; - text_ptr->key = key; - text_ptr->lang = lang; - text_ptr->lang_key = lang_key; - text_ptr->text = text; - text_ptr->text_length = 0; - text_ptr->itxt_length = png_strlen(text); - - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); - - png_ptr->current_text = NULL; - - png_free(png_ptr, text_ptr); - if (ret) - png_warning(png_ptr, "Insufficient memory to store iTXt chunk"); - } -} -#endif - -/* This function is called when we haven't found a handler for this - * chunk. If there isn't a problem with the chunk itself (ie a bad chunk - * name or a critical chunk), the chunk is (currently) silently ignored. - */ -void /* PRIVATE */ -png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 - length) -{ - png_uint_32 skip = 0; - - if (!(png_ptr->chunk_name[0] & 0x20)) - { -#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED - if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != - PNG_HANDLE_CHUNK_ALWAYS -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED - && png_ptr->read_user_chunk_fn == NULL -#endif - ) -#endif - png_chunk_error(png_ptr, "unknown critical chunk"); - - PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */ - } - -#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED - if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) - { -#ifdef PNG_MAX_MALLOC_64K - if (length > (png_uint_32)65535L) - { - png_warning(png_ptr, "unknown chunk too large to fit in memory"); - skip = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; - } -#endif - png_memcpy((png_charp)png_ptr->unknown_chunk.name, - (png_charp)png_ptr->chunk_name, - png_sizeof(png_ptr->unknown_chunk.name)); - png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1] - = '\0'; - - png_ptr->unknown_chunk.size = (png_size_t)length; - - if (length == 0) - png_ptr->unknown_chunk.data = NULL; - - else - { - png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, - (png_size_t)length); - png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); - } - -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED - if (png_ptr->read_user_chunk_fn != NULL) - { - /* Callback to user unknown chunk handler */ - int ret; - ret = (*(png_ptr->read_user_chunk_fn)) - (png_ptr, &png_ptr->unknown_chunk); - - if (ret < 0) - png_chunk_error(png_ptr, "error in user chunk"); - - if (ret == 0) - { - if (!(png_ptr->chunk_name[0] & 0x20)) - if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != - PNG_HANDLE_CHUNK_ALWAYS) - png_chunk_error(png_ptr, "unknown critical chunk"); - png_set_unknown_chunks(png_ptr, info_ptr, - &png_ptr->unknown_chunk, 1); - } - } - - else -#endif - png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); - png_free(png_ptr, png_ptr->unknown_chunk.data); - png_ptr->unknown_chunk.data = NULL; - } - - else -#endif - skip=length; - png_push_crc_skip(png_ptr, skip); -} - -void /* PRIVATE */ -png_push_have_info(png_structp png_ptr, png_infop info_ptr) +png_push_have_info(png_structrp png_ptr, png_inforp info_ptr) { if (png_ptr->info_fn != NULL) (*(png_ptr->info_fn))(png_ptr, info_ptr); } void /* PRIVATE */ -png_push_have_end(png_structp png_ptr, png_infop info_ptr) +png_push_have_end(png_structrp png_ptr, png_inforp info_ptr) { if (png_ptr->end_fn != NULL) (*(png_ptr->end_fn))(png_ptr, info_ptr); } void /* PRIVATE */ -png_push_have_row(png_structp png_ptr, png_bytep row) +png_push_have_row(png_structrp png_ptr, png_bytep row) { if (png_ptr->row_fn != NULL) (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, @@ -1845,21 +1156,22 @@ png_push_have_row(png_structp png_ptr, png_bytep row) } void PNGAPI -png_progressive_combine_row (png_structp png_ptr, png_bytep old_row, +png_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row, png_const_bytep new_row) { - PNG_CONST int FARDATA png_pass_dsp_mask[7] = - {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; - if (png_ptr == NULL) return; - if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */ - png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]); + /* new_row is a flag here - if it is NULL then the app callback was called + * from an empty row (see the calls to png_struct::row_fn below), otherwise + * it must be png_ptr->row_buf+1 + */ + if (new_row != NULL) + png_combine_row(png_ptr, old_row, 1/*blocky display*/); } void PNGAPI -png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, +png_set_progressive_read_fn(png_structrp png_ptr, png_voidp progressive_ptr, png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn) { @@ -1874,11 +1186,11 @@ png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, } png_voidp PNGAPI -png_get_progressive_ptr(png_const_structp png_ptr) +png_get_progressive_ptr(png_const_structrp png_ptr) { if (png_ptr == NULL) return (NULL); return png_ptr->io_ptr; } -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ +#endif /* PROGRESSIVE_READ */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngpriv.h b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngpriv.h index b2e8b346e2b..8f79edf59a7 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngpriv.h +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngpriv.h @@ -30,11 +30,11 @@ * file and, per its terms, should not be removed: * * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * - * Last changed in libpng 1.5.4 [July 7, 2011] + * Last changed in libpng 1.6.10 [March 6, 1014]] * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer @@ -42,7 +42,7 @@ */ /* The symbols declared in this file (including the functions declared - * as PNG_EXTERN) are PRIVATE. They are not part of the libpng public + * as extern) are PRIVATE. They are not part of the libpng public * interface, and are not recommended for use by regular applications. * Some of them may become public in the future; others may stay private, * change in an incompatible way, or even disappear. @@ -67,12 +67,44 @@ */ #define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */ -/* This is required for the definition of abort(), used as a last ditch - * error handler when all else fails. - */ -#include +#ifndef PNG_VERSION_INFO_ONLY +/* Standard library headers not required by png.h: */ +# include +# include +#endif + +#define PNGLIB_BUILD /*libpng is being built, not used*/ + +/* If HAVE_CONFIG_H is defined during the build then the build system must + * provide an appropriate "config.h" file on the include path. The header file + * must provide definitions as required below (search for "HAVE_CONFIG_H"); + * see configure.ac for more details of the requirements. The macro + * "PNG_NO_CONFIG_H" is provided for maintainers to test for dependencies on + * 'configure'; define this macro to prevent the configure build including the + * configure generated config.h. Libpng is expected to compile without *any* + * special build system support on a reasonably ANSI-C compliant system. + */ +#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H) +# include + + /* Pick up the definition of 'restrict' from config.h if it was read: */ +# define PNG_RESTRICT restrict +#endif + +/* To support symbol prefixing it is necessary to know *before* including png.h + * whether the fixed point (and maybe other) APIs are exported, because if they + * are not internal definitions may be required. This is handled below just + * before png.h is included, but load the configuration now if it is available. + */ +#ifndef PNGLCONF_H +# include "pnglibconf.h" +#endif + +/* Local renames may change non-exported API functions from png.h */ +#if defined(PNG_PREFIX) && !defined(PNGPREFIX_H) +# include "pngprefix.h" +#endif -#define PNGLIB_BUILD #ifdef PNG_USER_CONFIG # include "pngusr.h" /* These should have been defined in pngusr.h */ @@ -83,25 +115,253 @@ # define PNG_USER_DLLFNAME_POSTFIX "Cb" # endif #endif + +/* Compile time options. + * ===================== + * In a multi-arch build the compiler may compile the code several times for the + * same object module, producing different binaries for different architectures. + * When this happens configure-time setting of the target host options cannot be + * done and this interferes with the handling of the ARM NEON optimizations, and + * possibly other similar optimizations. Put additional tests here; in general + * this is needed when the same option can be changed at both compile time and + * run time depending on the target OS (i.e. iOS vs Android.) + * + * NOTE: symbol prefixing does not pass $(CFLAGS) to the preprocessor, because + * this is not possible with certain compilers (Oracle SUN OS CC), as a result + * it is necessary to ensure that all extern functions that *might* be used + * regardless of $(CFLAGS) get declared in this file. The test on __ARM_NEON__ + * below is one example of this behavior because it is controlled by the + * presence or not of -mfpu=neon on the GCC command line, it is possible to do + * this in $(CC), e.g. "CC=gcc -mfpu=neon", but people who build libpng rarely + * do this. + */ +#ifndef PNG_ARM_NEON_OPT + /* ARM NEON optimizations are being controlled by the compiler settings, + * typically the target FPU. If the FPU has been set to NEON (-mfpu=neon + * with GCC) then the compiler will define __ARM_NEON__ and we can rely + * unconditionally on NEON instructions not crashing, otherwise we must + * disable use of NEON instructions. + * + * NOTE: at present these optimizations depend on 'ALIGNED_MEMORY', so they + * can only be turned on automatically if that is supported too. If + * PNG_ARM_NEON_OPT is set in CPPFLAGS (to >0) then arm/arm_init.c will fail + * to compile with an appropriate #error if ALIGNED_MEMORY has been turned + * off. + * + * Note that gcc-4.9 defines __ARM_NEON instead of __ARM_NEON__, so we + * check both variants. + */ +# if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \ + defined(PNG_ALIGNED_MEMORY_SUPPORTED) +# define PNG_ARM_NEON_OPT 2 +# else +# define PNG_ARM_NEON_OPT 0 +# endif +#endif + +#if PNG_ARM_NEON_OPT > 0 + /* NEON optimizations are to be at least considered by libpng, so enable the + * callbacks to do this. + */ +# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon + + /* By default the 'intrinsics' code in arm/filter_neon_intrinsics.c is used + * if possible - if __ARM_NEON__ is set and the compiler version is not known + * to be broken. This is controlled by PNG_ARM_NEON_IMPLEMENTATION which can + * be: + * + * 1 The intrinsics code (the default with __ARM_NEON__) + * 2 The hand coded assembler (the default without __ARM_NEON__) + * + * It is possible to set PNG_ARM_NEON_IMPLEMENTATION in CPPFLAGS, however + * this is *NOT* supported and may cease to work even after a minor revision + * to libpng. It *is* valid to do this for testing purposes, e.g. speed + * testing or a new compiler, but the results should be communicated to the + * libpng implementation list for incorporation in the next minor release. + */ +# ifndef PNG_ARM_NEON_IMPLEMENTATION +# if defined(__ARM_NEON__) || defined(__ARM_NEON) +# if defined(__clang__) + /* At present it is unknown by the libpng developers which versions + * of clang support the intrinsics, however some or perhaps all + * versions do not work with the assembler so this may be + * irrelevant, so just use the default (do nothing here.) + */ +# elif defined(__GNUC__) + /* GCC 4.5.4 NEON support is known to be broken. 4.6.3 is known to + * work, so if this *is* GCC, or G++, look for a version >4.5 + */ +# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6) +# define PNG_ARM_NEON_IMPLEMENTATION 2 +# endif /* no GNUC support */ +# endif /* __GNUC__ */ +# else /* !defined __ARM_NEON__ */ + /* The 'intrinsics' code simply won't compile without this -mfpu=neon: + */ +# define PNG_ARM_NEON_IMPLEMENTATION 2 +# endif /* __ARM_NEON__ */ +# endif /* !PNG_ARM_NEON_IMPLEMENTATION */ + +# ifndef PNG_ARM_NEON_IMPLEMENTATION + /* Use the intrinsics code by default. */ +# define PNG_ARM_NEON_IMPLEMENTATION 1 +# endif +#endif /* PNG_ARM_NEON_OPT > 0 */ + +/* Is this a build of a DLL where compilation of the object modules requires + * different preprocessor settings to those required for a simple library? If + * so PNG_BUILD_DLL must be set. + * + * If libpng is used inside a DLL but that DLL does not export the libpng APIs + * PNG_BUILD_DLL must not be set. To avoid the code below kicking in build a + * static library of libpng then link the DLL against that. + */ +#ifndef PNG_BUILD_DLL +# ifdef DLL_EXPORT + /* This is set by libtool when files are compiled for a DLL; libtool + * always compiles twice, even on systems where it isn't necessary. Set + * PNG_BUILD_DLL in case it is necessary: + */ +# define PNG_BUILD_DLL +# else +# ifdef _WINDLL + /* This is set by the Microsoft Visual Studio IDE in projects that + * build a DLL. It can't easily be removed from those projects (it + * isn't visible in the Visual Studio UI) so it is a fairly reliable + * indication that PNG_IMPEXP needs to be set to the DLL export + * attributes. + */ +# define PNG_BUILD_DLL +# else +# ifdef __DLL__ + /* This is set by the Borland C system when compiling for a DLL + * (as above.) + */ +# define PNG_BUILD_DLL +# else + /* Add additional compiler cases here. */ +# endif +# endif +# endif +#endif /* Setting PNG_BUILD_DLL if required */ + +/* See pngconf.h for more details: the builder of the library may set this on + * the command line to the right thing for the specific compilation system or it + * may be automagically set above (at present we know of no system where it does + * need to be set on the command line.) + * + * PNG_IMPEXP must be set here when building the library to prevent pngconf.h + * setting it to the "import" setting for a DLL build. + */ +#ifndef PNG_IMPEXP +# ifdef PNG_BUILD_DLL +# define PNG_IMPEXP PNG_DLL_EXPORT +# else + /* Not building a DLL, or the DLL doesn't require specific export + * definitions. + */ +# define PNG_IMPEXP +# endif +#endif + +/* No warnings for private or deprecated functions in the build: */ +#ifndef PNG_DEPRECATED +# define PNG_DEPRECATED +#endif +#ifndef PNG_PRIVATE +# define PNG_PRIVATE +#endif + +/* Symbol preprocessing support. + * + * To enable listing global, but internal, symbols the following macros should + * always be used to declare an extern data or function object in this file. + */ +#ifndef PNG_INTERNAL_DATA +# define PNG_INTERNAL_DATA(type, name, array) extern type name array +#endif + +#ifndef PNG_INTERNAL_FUNCTION +# define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\ + extern PNG_FUNCTION(type, name, args, PNG_EMPTY attributes) +#endif + +#ifndef PNG_INTERNAL_CALLBACK +# define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\ + extern PNG_FUNCTION(type, (PNGCBAPI name), args, PNG_EMPTY attributes) +#endif + +/* If floating or fixed point APIs are disabled they may still be compiled + * internally. To handle this make sure they are declared as the appropriate + * internal extern function (otherwise the symbol prefixing stuff won't work and + * the functions will be used without definitions.) + * + * NOTE: although all the API functions are declared here they are not all + * actually built! Because the declarations are still made it is necessary to + * fake out types that they depend on. + */ +#ifndef PNG_FP_EXPORT +# ifndef PNG_FLOATING_POINT_SUPPORTED +# define PNG_FP_EXPORT(ordinal, type, name, args)\ + PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY); +# ifndef PNG_VERSION_INFO_ONLY + typedef struct png_incomplete png_double; + typedef png_double* png_doublep; + typedef const png_double* png_const_doublep; + typedef png_double** png_doublepp; +# endif +# endif +#endif +#ifndef PNG_FIXED_EXPORT +# ifndef PNG_FIXED_POINT_SUPPORTED +# define PNG_FIXED_EXPORT(ordinal, type, name, args)\ + PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY); +# endif +#endif + #include "png.h" -#include "pnginfo.h" -#include "pngstruct.h" -/* This is used for 16 bit gamma tables - only the top level pointers are const, - * this could be changed: +/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */ +#ifndef PNG_DLL_EXPORT +# define PNG_DLL_EXPORT +#endif + +/* SECURITY and SAFETY: + * + * By default libpng is built without any internal limits on image size, + * individual heap (png_malloc) allocations or the total amount of memory used. + * If PNG_SAFE_LIMITS_SUPPORTED is defined, however, the limits below are used + * (unless individually overridden). These limits are believed to be fairly + * safe, but builders of secure systems should verify the values against the + * real system capabilities. */ -typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; - -/* Added at libpng-1.2.9 */ -/* Moved to pngpriv.h at libpng-1.5.0 */ - -/* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure" - * script. We may need it here to get the correct configuration on things - * like limits. - */ -#ifdef PNG_CONFIGURE_LIBPNG -# ifdef HAVE_CONFIG_H -# include "config.h" +#ifdef PNG_SAFE_LIMITS_SUPPORTED + /* 'safe' limits */ +# ifndef PNG_USER_WIDTH_MAX +# define PNG_USER_WIDTH_MAX 1000000 +# endif +# ifndef PNG_USER_HEIGHT_MAX +# define PNG_USER_HEIGHT_MAX 1000000 +# endif +# ifndef PNG_USER_CHUNK_CACHE_MAX +# define PNG_USER_CHUNK_CACHE_MAX 128 +# endif +# ifndef PNG_USER_CHUNK_MALLOC_MAX +# define PNG_USER_CHUNK_MALLOC_MAX 8000000 +# endif +#else + /* values for no limits */ +# ifndef PNG_USER_WIDTH_MAX +# define PNG_USER_WIDTH_MAX 0x7fffffff +# endif +# ifndef PNG_USER_HEIGHT_MAX +# define PNG_USER_HEIGHT_MAX 0x7fffffff +# endif +# ifndef PNG_USER_CHUNK_CACHE_MAX +# define PNG_USER_CHUNK_CACHE_MAX 0 +# endif +# ifndef PNG_USER_CHUNK_MALLOC_MAX +# define PNG_USER_CHUNK_MALLOC_MAX 0 # endif #endif @@ -143,13 +403,6 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; # define PNG_ZBUF_SIZE 65536L #endif -/* PNG_STATIC is used to mark internal file scope functions if they need to be - * accessed for implementation tests (see the code in tests/?*). - */ -#ifndef PNG_STATIC -# define PNG_STATIC static -#endif - /* If warnings or errors are turned off the code is disabled or redirected here. * From 1.5.4 functions have been added to allow very limited formatting of * error and warning messages - this code will also be disabled here. @@ -157,8 +410,6 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; #ifdef PNG_WARNINGS_SUPPORTED # define PNG_WARNING_PARAMETERS(p) png_warning_parameters p; #else -# define png_warning(s1,s2) ((void)(s1)) -# define png_chunk_warning(s1,s2) ((void)(s1)) # define png_warning_parameter(p,number,string) ((void)0) # define png_warning_parameter_unsigned(p,number,format,value) ((void)0) # define png_warning_parameter_signed(p,number,format,value) ((void)0) @@ -166,21 +417,27 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; # define PNG_WARNING_PARAMETERS(p) #endif #ifndef PNG_ERROR_TEXT_SUPPORTED -# define png_error(s1,s2) png_err(s1) -# define png_chunk_error(s1,s2) png_err(s1) # define png_fixed_error(s1,s2) png_err(s1) #endif -#ifndef PNG_EXTERN -/* The functions exported by PNG_EXTERN are internal functions, which - * aren't usually used outside the library (as far as I know), so it is - * debatable if they should be exported at all. In the future, when it - * is possible to have run-time registry of chunk-handling functions, - * some of these might be made available again. -# define PNG_EXTERN extern +/* C allows up-casts from (void*) to any pointer and (const void*) to any + * pointer to a const object. C++ regards this as a type error and requires an + * explicit, static, cast and provides the static_cast<> rune to ensure that + * const is not cast away. */ -# define PNG_EXTERN -#endif +#ifdef __cplusplus +# define png_voidcast(type, value) static_cast(value) +# define png_constcast(type, value) const_cast(value) +# define png_aligncast(type, value) \ + static_cast(static_cast(value)) +# define png_aligncastconst(type, value) \ + static_cast(static_cast(value)) +#else +# define png_voidcast(type, value) (value) +# define png_constcast(type, value) ((type)(value)) +# define png_aligncast(type, value) ((void*)(value)) +# define png_aligncastconst(type, value) ((const void*)(value)) +#endif /* __cplusplus */ /* Some fixed point APIs are still required even if not exported because * they get used by the corresponding floating point APIs. This magic @@ -192,6 +449,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; # define PNGFAPI /* PRIVATE */ #endif +#ifndef PNG_VERSION_INFO_ONLY /* Other defines specific to compilers can go here. Try to keep * them inside an appropriate ifdef/endif pair for portability. */ @@ -236,6 +494,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; defined(_WIN32) || defined(__WIN32__) # include /* defines _WINDOWS_ macro */ #endif +#endif /* PNG_VERSION_INFO_ONLY */ /* Moved here around 1.5.0beta36 from pngconf.h */ /* Users may want to use these so they are not private. Any library @@ -251,33 +510,51 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; # endif #endif -#ifdef USE_FAR_KEYWORD -/* Use this to make far-to-near assignments */ -# define CHECK 1 -# define NOCHECK 0 -# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) -# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) -# define png_strlen _fstrlen -# define png_memcmp _fmemcmp /* SJT: added */ -# define png_memcpy _fmemcpy -# define png_memset _fmemset +/* These macros may need to be architecture dependent. */ +#define PNG_ALIGN_NONE 0 /* do not use data alignment */ +#define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */ +#ifdef offsetof +# define PNG_ALIGN_OFFSET 2 /* use offsetof to determine alignment */ #else -# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */ -# define CVT_PTR(ptr) (ptr) -# define CVT_PTR_NOCHECK(ptr) (ptr) -# define png_strlen lstrlenA -# define png_memcmp memcmp -# define png_memcpy CopyMemory -# define png_memset memset +# define PNG_ALIGN_OFFSET -1 /* prevent the use of this */ +#endif +#define PNG_ALIGN_SIZE 3 /* use sizeof to determine alignment */ + +#ifndef PNG_ALIGN_TYPE + /* Default to using aligned access optimizations and requiring alignment to a + * multiple of the data type size. Override in a compiler specific fashion + * if necessary by inserting tests here: + */ +# define PNG_ALIGN_TYPE PNG_ALIGN_SIZE +#endif + +#if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE + /* This is used because in some compiler implementations non-aligned + * structure members are supported, so the offsetof approach below fails. + * Set PNG_ALIGN_SIZE=0 for compiler combinations where unaligned access + * is good for performance. Do not do this unless you have tested the result + * and understand it. + */ +# define png_alignof(type) (sizeof (type)) +#else +# if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET +# define png_alignof(type) offsetof(struct{char c; type t;}, t) # else -# define CVT_PTR(ptr) (ptr) -# define CVT_PTR_NOCHECK(ptr) (ptr) -# define png_strlen strlen -# define png_memcmp memcmp /* SJT: added */ -# define png_memcpy memcpy -# define png_memset memset +# if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS +# define png_alignof(type) (1) +# endif + /* Else leave png_alignof undefined to prevent use thereof */ # endif #endif + +/* This implicitly assumes alignment is always to a power of 2. */ +#ifdef png_alignof +# define png_isaligned(ptr, type)\ + ((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0) +#else +# define png_isaligned(ptr, type) 0 +#endif + /* End of memory model/platform independent support */ /* End of 1.5.0beta36 move from pngconf.h */ @@ -295,15 +572,17 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; #define PNG_HAVE_IDAT 0x04 /* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */ #define PNG_HAVE_IEND 0x10 -#define PNG_HAVE_gAMA 0x20 -#define PNG_HAVE_cHRM 0x40 -#define PNG_HAVE_sRGB 0x80 + /* 0x20 (unused) */ + /* 0x40 (unused) */ + /* 0x80 (unused) */ #define PNG_HAVE_CHUNK_HEADER 0x100 #define PNG_WROTE_tIME 0x200 #define PNG_WROTE_INFO_BEFORE_PLTE 0x400 #define PNG_BACKGROUND_IS_GRAY 0x800 #define PNG_HAVE_PNG_SIGNATURE 0x1000 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ + /* 0x4000 (unused) */ +#define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */ /* Flags for the transformations the PNG library does on the image data */ #define PNG_BGR 0x0001 @@ -321,24 +600,23 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; #define PNG_EXPAND 0x1000 #define PNG_GAMMA 0x2000 #define PNG_GRAY_TO_RGB 0x4000 -#define PNG_FILLER 0x8000L -#define PNG_PACKSWAP 0x10000L -#define PNG_SWAP_ALPHA 0x20000L -#define PNG_STRIP_ALPHA 0x40000L -#define PNG_INVERT_ALPHA 0x80000L -#define PNG_USER_TRANSFORM 0x100000L -#define PNG_RGB_TO_GRAY_ERR 0x200000L -#define PNG_RGB_TO_GRAY_WARN 0x400000L -#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */ -#define PNG_ENCODE_ALPHA 0x800000L /* Added to libpng-1.5.4 */ -#define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */ -#define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */ -#define PNG_SCALE_16_TO_8 0x4000000L /* Added to libpng-1.5.4 */ - /* 0x8000000L unused */ - /* 0x10000000L unused */ - /* 0x20000000L unused */ - /* 0x40000000L unused */ - +#define PNG_FILLER 0x8000 +#define PNG_PACKSWAP 0x10000 +#define PNG_SWAP_ALPHA 0x20000 +#define PNG_STRIP_ALPHA 0x40000 +#define PNG_INVERT_ALPHA 0x80000 +#define PNG_USER_TRANSFORM 0x100000 +#define PNG_RGB_TO_GRAY_ERR 0x200000 +#define PNG_RGB_TO_GRAY_WARN 0x400000 +#define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */ +#define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */ +#define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */ +#define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */ +#define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */ + /* 0x8000000 unused */ + /* 0x10000000 unused */ + /* 0x20000000 unused */ + /* 0x40000000 unused */ /* Flags for png_create_struct */ #define PNG_STRUCT_PNG 0x0001 #define PNG_STRUCT_INFO 0x0002 @@ -349,36 +627,36 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; /* Flags for the png_ptr->flags rather than declaring a byte for each one */ #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 -#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002 -#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004 -#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008 -#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010 -#define PNG_FLAG_ZLIB_FINISHED 0x0020 +#define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002 /* Added to libpng-1.6.0 */ + /* 0x0004 unused */ +#define PNG_FLAG_ZSTREAM_ENDED 0x0008 /* Added to libpng-1.6.0 */ + /* 0x0010 unused */ + /* 0x0020 unused */ #define PNG_FLAG_ROW_INIT 0x0040 #define PNG_FLAG_FILLER_AFTER 0x0080 #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 #define PNG_FLAG_CRC_CRITICAL_USE 0x0400 #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 -#define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */ -#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */ -#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */ -#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L -#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L -#define PNG_FLAG_LIBRARY_MISMATCH 0x20000L -#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L -#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L -#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L - /* 0x200000L unused */ - /* 0x400000L unused */ -#define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000L /* Added to libpng-1.4.0 */ -#define PNG_FLAG_ZTXT_CUSTOM_STRATEGY 0x1000000L /* 5 lines added */ -#define PNG_FLAG_ZTXT_CUSTOM_LEVEL 0x2000000L /* to libpng-1.5.4 */ -#define PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL 0x4000000L -#define PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS 0x8000000L -#define PNG_FLAG_ZTXT_CUSTOM_METHOD 0x10000000L - /* 0x20000000L unused */ - /* 0x40000000L unused */ +#define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */ +#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */ +#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */ +/* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000 */ +/* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000 */ +#define PNG_FLAG_LIBRARY_MISMATCH 0x20000 +#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000 +#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000 +#define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000 /* Added to libpng-1.4.0 */ +#define PNG_FLAG_APP_WARNINGS_WARN 0x200000 /* Added to libpng-1.6.0 */ +#define PNG_FLAG_APP_ERRORS_WARN 0x400000 /* Added to libpng-1.6.0 */ + /* 0x800000 unused */ + /* 0x1000000 unused */ + /* 0x2000000 unused */ + /* 0x4000000 unused */ + /* 0x8000000 unused */ + /* 0x10000000 unused */ + /* 0x20000000 unused */ + /* 0x40000000 unused */ #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ PNG_FLAG_CRC_ANCILLARY_NOWARN) @@ -389,24 +667,23 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ PNG_FLAG_CRC_CRITICAL_MASK) -/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib - * can handle at once. This type need be no larger than 16 bits (so maximum of - * 65535), this define allows us to discover how big it is, but limited by the - * maximuum for png_size_t. The value can be overriden in a library build - * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably - * lower value (e.g. 255 works). A lower value may help memory usage (slightly) - * and may even improve performance on some systems (and degrade it on others.) - */ -#ifndef ZLIB_IO_MAX -# define ZLIB_IO_MAX ((uInt)-1) -#endif - /* Save typing and make code easier to understand */ #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ abs((int)((c1).green) - (int)((c2).green)) + \ abs((int)((c1).blue) - (int)((c2).blue))) +/* Added to libpng-1.6.0: scale a 16-bit value in the range 0..65535 to 0..255 + * by dividing by 257 *with rounding*. This macro is exact for the given range. + * See the discourse in pngrtran.c png_do_scale_16_to_8. The values in the + * macro were established by experiment (modifying the added value). The macro + * has a second variant that takes a value already scaled by 255 and divides by + * 65535 - this has a maximum error of .502. Over the range 0..65535*65535 it + * only gives off-by-one errors and only for 0.5% (1 in 200) of the values. + */ +#define PNG_DIV65535(v24) (((v24) + 32895) >> 16) +#define PNG_DIV257(v16) PNG_DIV65535((png_uint_32)(v16) * 255) + /* Added to libpng-1.2.6 JB */ #define PNG_ROWBYTES(pixel_bits, width) \ ((pixel_bits) >= 8 ? \ @@ -454,151 +731,314 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; #ifdef PNG_FIXED_POINT_MACRO_SUPPORTED #define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\ ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0)) -#else -PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp, - png_const_charp text)); #endif +/* else the corresponding function is defined below, inside the scope of the + * cplusplus test. + */ #endif -/* Constant strings for known chunk types. If you need to add a chunk, - * define the name here, and add an invocation of the macro wherever it's - * needed. +/* Constants for known chunk types. If you need to add a chunk, define the name + * here. For historical reasons these constants have the form png_; i.e. + * the prefix is lower case. Please use decimal values as the parameters to + * match the ISO PNG specification and to avoid relying on the C locale + * interpretation of character values. + * + * Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values + * are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string + * to be generated if required. + * + * PNG_32b correctly produces a value shifted by up to 24 bits, even on + * architectures where (int) is only 16 bits. */ -#define PNG_IHDR PNG_CONST png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'} -#define PNG_IDAT PNG_CONST png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'} -#define PNG_IEND PNG_CONST png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'} -#define PNG_PLTE PNG_CONST png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'} -#define PNG_bKGD PNG_CONST png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'} -#define PNG_cHRM PNG_CONST png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'} -#define PNG_gAMA PNG_CONST png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'} -#define PNG_hIST PNG_CONST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'} -#define PNG_iCCP PNG_CONST png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'} -#define PNG_iTXt PNG_CONST png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'} -#define PNG_oFFs PNG_CONST png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'} -#define PNG_pCAL PNG_CONST png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'} -#define PNG_sCAL PNG_CONST png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'} -#define PNG_pHYs PNG_CONST png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'} -#define PNG_sBIT PNG_CONST png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'} -#define PNG_sPLT PNG_CONST png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'} -#define PNG_sRGB PNG_CONST png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'} -#define PNG_sTER PNG_CONST png_byte png_sTER[5] = {115, 84, 69, 82, '\0'} -#define PNG_tEXt PNG_CONST png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'} -#define PNG_tIME PNG_CONST png_byte png_tIME[5] = {116, 73, 77, 69, '\0'} -#define PNG_tRNS PNG_CONST png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'} -#define PNG_zTXt PNG_CONST png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'} +#define PNG_32b(b,s) ((png_uint_32)(b) << (s)) +#define PNG_U32(b1,b2,b3,b4) \ + (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0)) + +/* Constants for known chunk types. + * + * MAINTAINERS: If you need to add a chunk, define the name here. + * For historical reasons these constants have the form png_; i.e. + * the prefix is lower case. Please use decimal values as the parameters to + * match the ISO PNG specification and to avoid relying on the C locale + * interpretation of character values. Please keep the list sorted. + * + * Notice that PNG_U32 is used to define a 32-bit value for the 4 byte chunk + * type. In fact the specification does not express chunk types this way, + * however using a 32-bit value means that the chunk type can be read from the + * stream using exactly the same code as used for a 32-bit unsigned value and + * can be examined far more efficiently (using one arithmetic compare). + * + * Prior to 1.5.6 the chunk type constants were expressed as C strings. The + * libpng API still uses strings for 'unknown' chunks and a macro, + * PNG_STRING_FROM_CHUNK, allows a string to be generated if required. Notice + * that for portable code numeric values must still be used; the string "IHDR" + * is not portable and neither is PNG_U32('I', 'H', 'D', 'R'). + * + * In 1.7.0 the definitions will be made public in png.h to avoid having to + * duplicate the same definitions in application code. + */ +#define png_IDAT PNG_U32( 73, 68, 65, 84) +#define png_IEND PNG_U32( 73, 69, 78, 68) +#define png_IHDR PNG_U32( 73, 72, 68, 82) +#define png_PLTE PNG_U32( 80, 76, 84, 69) +#define png_bKGD PNG_U32( 98, 75, 71, 68) +#define png_cHRM PNG_U32( 99, 72, 82, 77) +#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */ +#define png_gAMA PNG_U32(103, 65, 77, 65) +#define png_gIFg PNG_U32(103, 73, 70, 103) +#define png_gIFt PNG_U32(103, 73, 70, 116) /* deprecated */ +#define png_gIFx PNG_U32(103, 73, 70, 120) +#define png_hIST PNG_U32(104, 73, 83, 84) +#define png_iCCP PNG_U32(105, 67, 67, 80) +#define png_iTXt PNG_U32(105, 84, 88, 116) +#define png_oFFs PNG_U32(111, 70, 70, 115) +#define png_pCAL PNG_U32(112, 67, 65, 76) +#define png_pHYs PNG_U32(112, 72, 89, 115) +#define png_sBIT PNG_U32(115, 66, 73, 84) +#define png_sCAL PNG_U32(115, 67, 65, 76) +#define png_sPLT PNG_U32(115, 80, 76, 84) +#define png_sRGB PNG_U32(115, 82, 71, 66) +#define png_sTER PNG_U32(115, 84, 69, 82) +#define png_tEXt PNG_U32(116, 69, 88, 116) +#define png_tIME PNG_U32(116, 73, 77, 69) +#define png_tRNS PNG_U32(116, 82, 78, 83) +#define png_zTXt PNG_U32(122, 84, 88, 116) + +/* The following will work on (signed char*) strings, whereas the get_uint_32 + * macro will fail on top-bit-set values because of the sign extension. + */ +#define PNG_CHUNK_FROM_STRING(s)\ + PNG_U32(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3]) + +/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is + * signed and the argument is a (char[]) This macro will fail miserably on + * systems where (char) is more than 8 bits. + */ +#define PNG_STRING_FROM_CHUNK(s,c)\ + (void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\ + ((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c))) + +/* Do the same but terminate with a null character. */ +#define PNG_CSTRING_FROM_CHUNK(s,c)\ + (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0) + +/* Test on flag values as defined in the spec (section 5.4): */ +#define PNG_CHUNK_ANCILLARY(c) (1 & ((c) >> 29)) +#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLARY(c)) +#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21)) +#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13)) +#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5)) /* Gamma values (new at libpng-1.5.4): */ #define PNG_GAMMA_MAC_OLD 151724 /* Assume '1.8' is really 2.2/1.45! */ #define PNG_GAMMA_MAC_INVERSE 65909 #define PNG_GAMMA_sRGB_INVERSE 45455 +/* Almost everything below is C specific; the #defines above can be used in + * non-C code (so long as it is C-preprocessed) the rest of this stuff cannot. + */ +#ifndef PNG_VERSION_INFO_ONLY + +#include "pngstruct.h" +#include "pnginfo.h" + +/* Validate the include paths - the include path used to generate pnglibconf.h + * must match that used in the build, or we must be using pnglibconf.h.prebuilt: + */ +#if PNG_ZLIB_VERNUM != 0 && PNG_ZLIB_VERNUM != ZLIB_VERNUM +# error ZLIB_VERNUM != PNG_ZLIB_VERNUM \ + "-I (include path) error: see the notes in pngpriv.h" + /* This means that when pnglibconf.h was built the copy of zlib.h that it + * used is not the same as the one being used here. Because the build of + * libpng makes decisions to use inflateInit2 and inflateReset2 based on the + * zlib version number and because this affects handling of certain broken + * PNG files the -I directives must match. + * + * The most likely explanation is that you passed a -I in CFLAGS. This will + * not work; all the preprocessor directories and in particular all the -I + * directives must be in CPPFLAGS. + */ +#endif + +/* This is used for 16 bit gamma tables -- only the top level pointers are + * const; this could be changed: + */ +typedef const png_uint_16p * png_const_uint_16pp; + +/* Added to libpng-1.5.7: sRGB conversion tables */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +#ifdef PNG_SIMPLIFIED_READ_SUPPORTED +PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_table, [256]); + /* Convert from an sRGB encoded value 0..255 to a 16-bit linear value, + * 0..65535. This table gives the closest 16-bit answers (no errors). + */ +#endif + +PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_base, [512]); +PNG_INTERNAL_DATA(const png_byte, png_sRGB_delta, [512]); + +#define PNG_sRGB_FROM_LINEAR(linear) ((png_byte)((png_sRGB_base[(linear)>>15] +\ + ((((linear)&0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8)) + /* Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB + * encoded value with maximum error 0.646365. Note that the input is not a + * 16-bit value; it has been multiplied by 255! */ +#endif /* SIMPLIFIED_READ/WRITE */ + /* Inhibit C++ name-mangling for libpng functions but not for system calls. */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -/* These functions are used internally in the code. They generally - * shouldn't be used unless you are writing code to add or replace some - * functionality in libpng. More information about most functions can - * be found in the files where the functions are located. +/* Internal functions; these are not exported from a DLL however because they + * are used within several of the C source files they have to be C extern. + * + * All of these functions must be declared with PNG_INTERNAL_FUNCTION. */ +/* Zlib support */ +#define PNG_UNEXPECTED_ZLIB_RETURN (-7) +PNG_INTERNAL_FUNCTION(void, png_zstream_error,(png_structrp png_ptr, int ret), + PNG_EMPTY); + /* Used by the zlib handling functions to ensure that z_stream::msg is always + * set before they return. + */ + +#ifdef PNG_WRITE_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_free_buffer_list,(png_structrp png_ptr, + png_compression_bufferp *list),PNG_EMPTY); + /* Free the buffer list used by the compressed write code. */ +#endif + +#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ + !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \ + (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \ + defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \ + (defined(PNG_sCAL_SUPPORTED) && \ + defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)) +PNG_INTERNAL_FUNCTION(png_fixed_point,png_fixed,(png_const_structrp png_ptr, + double fp, png_const_charp text),PNG_EMPTY); +#endif + /* Check the user version string for compatibility, returns false if the version * numbers aren't compatible. */ -PNG_EXTERN int png_user_version_check(png_structp png_ptr, - png_const_charp user_png_ver); +PNG_INTERNAL_FUNCTION(int,png_user_version_check,(png_structrp png_ptr, + png_const_charp user_png_ver),PNG_EMPTY); -/* Allocate memory for an internal libpng struct */ -PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)), - PNG_ALLOCATED); +/* Internal base allocator - no messages, NULL on failure to allocate. This + * does, however, call the application provided allocator and that could call + * png_error (although that would be a bug in the application implementation.) + */ +PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_base,(png_const_structrp png_ptr, + png_alloc_size_t size),PNG_ALLOCATED); + +#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\ + defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) +/* Internal array allocator, outputs no error or warning messages on failure, + * just returns NULL. + */ +PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_array,(png_const_structrp png_ptr, + int nelements, size_t element_size),PNG_ALLOCATED); + +/* The same but an existing array is extended by add_elements. This function + * also memsets the new elements to 0 and copies the old elements. The old + * array is not freed or altered. + */ +PNG_INTERNAL_FUNCTION(png_voidp,png_realloc_array,(png_const_structrp png_ptr, + png_const_voidp array, int old_elements, int add_elements, + size_t element_size),PNG_ALLOCATED); +#endif /* text, sPLT or unknown chunks */ + +/* Magic to create a struct when there is no struct to call the user supplied + * memory allocators. Because error handling has not been set up the memory + * handlers can't safely call png_error, but this is an obscure and undocumented + * restriction so libpng has to assume that the 'free' handler, at least, might + * call png_error. + */ +PNG_INTERNAL_FUNCTION(png_structp,png_create_png_struct, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, + png_free_ptr free_fn),PNG_ALLOCATED); /* Free memory from internal libpng struct */ -PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); +PNG_INTERNAL_FUNCTION(void,png_destroy_png_struct,(png_structrp png_ptr), + PNG_EMPTY); -PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2, - PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)), - PNG_ALLOCATED); -PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, - png_free_ptr free_fn, png_voidp mem_ptr)); - -/* Free any memory that info_ptr points to and reset struct. */ -PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, - png_infop info_ptr)); +/* Free an allocated jmp_buf (always succeeds) */ +PNG_INTERNAL_FUNCTION(void,png_free_jmpbuf,(png_structrp png_ptr),PNG_EMPTY); /* Function to allocate memory for zlib. PNGAPI is disallowed. */ -PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items, - uInt size)),PNG_ALLOCATED); +PNG_INTERNAL_FUNCTION(voidpf,png_zalloc,(voidpf png_ptr, uInt items, uInt size), + PNG_ALLOCATED); /* Function to free memory for zlib. PNGAPI is disallowed. */ -PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)); +PNG_INTERNAL_FUNCTION(void,png_zfree,(voidpf png_ptr, voidpf ptr),PNG_EMPTY); /* Next four functions are used internally as callbacks. PNGCBAPI is required * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3, changed to * PNGCBAPI at 1.5.0 */ -PNG_EXTERN void PNGCBAPI png_default_read_data PNGARG((png_structp png_ptr, - png_bytep data, png_size_t length)); +PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_read_data,(png_structp png_ptr, + png_bytep data, png_size_t length),PNG_EMPTY); #ifdef PNG_PROGRESSIVE_READ_SUPPORTED -PNG_EXTERN void PNGCBAPI png_push_fill_buffer PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t length)); +PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_push_fill_buffer,(png_structp png_ptr, + png_bytep buffer, png_size_t length),PNG_EMPTY); #endif -PNG_EXTERN void PNGCBAPI png_default_write_data PNGARG((png_structp png_ptr, - png_bytep data, png_size_t length)); +PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_write_data,(png_structp png_ptr, + png_bytep data, png_size_t length),PNG_EMPTY); #ifdef PNG_WRITE_FLUSH_SUPPORTED # ifdef PNG_STDIO_SUPPORTED -PNG_EXTERN void PNGCBAPI png_default_flush PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_flush,(png_structp png_ptr), + PNG_EMPTY); # endif #endif /* Reset the CRC variable */ -PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_reset_crc,(png_structrp png_ptr),PNG_EMPTY); /* Write the "data" buffer to whatever output you are using */ -PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, - png_const_bytep data, png_size_t length)); +PNG_INTERNAL_FUNCTION(void,png_write_data,(png_structrp png_ptr, + png_const_bytep data, png_size_t length),PNG_EMPTY); /* Read and check the PNG file signature */ -PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr)); +PNG_INTERNAL_FUNCTION(void,png_read_sig,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); /* Read the chunk header (length + type name) */ -PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(png_uint_32,png_read_chunk_header,(png_structrp png_ptr), + PNG_EMPTY); /* Read data from whatever input you are using into the "data" buffer */ -PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); +PNG_INTERNAL_FUNCTION(void,png_read_data,(png_structrp png_ptr, png_bytep data, + png_size_t length),PNG_EMPTY); /* Read bytes into buf, and update png_ptr->crc */ -PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, - png_size_t length)); - -/* Decompress data in a chunk that uses compression */ -#if defined(PNG_READ_COMPRESSED_TEXT_SUPPORTED) -PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr, - int comp_type, png_size_t chunklength, png_size_t prefix_length, - png_size_t *data_length)); -#endif +PNG_INTERNAL_FUNCTION(void,png_crc_read,(png_structrp png_ptr, png_bytep buf, + png_uint_32 length),PNG_EMPTY); /* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ -PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip)); +PNG_INTERNAL_FUNCTION(int,png_crc_finish,(png_structrp png_ptr, + png_uint_32 skip),PNG_EMPTY); /* Read the CRC from the file and compare it to the libpng calculated CRC */ -PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(int,png_crc_error,(png_structrp png_ptr),PNG_EMPTY); /* Calculate the CRC over a section of data. Note that we are only * passing a maximum of 64K on systems that have this as a memory limit, * since this is the maximum buffer size we can specify. */ -PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, - png_const_bytep ptr, png_size_t length)); +PNG_INTERNAL_FUNCTION(void,png_calculate_crc,(png_structrp png_ptr, + png_const_bytep ptr, png_size_t length),PNG_EMPTY); #ifdef PNG_WRITE_FLUSH_SUPPORTED -PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_flush,(png_structrp png_ptr),PNG_EMPTY); #endif /* Write various chunks */ @@ -606,317 +1046,256 @@ PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); /* Write the IHDR chunk, and update the png_struct with the necessary * information. */ -PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width, - png_uint_32 height, - int bit_depth, int color_type, int compression_method, int filter_method, - int interlace_method)); +PNG_INTERNAL_FUNCTION(void,png_write_IHDR,(png_structrp png_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, + int compression_method, int filter_method, int interlace_method),PNG_EMPTY); -PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, - png_const_colorp palette, png_uint_32 num_pal)); +PNG_INTERNAL_FUNCTION(void,png_write_PLTE,(png_structrp png_ptr, + png_const_colorp palette, png_uint_32 num_pal),PNG_EMPTY); -PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); +PNG_INTERNAL_FUNCTION(void,png_compress_IDAT,(png_structrp png_ptr, + png_const_bytep row_data, png_alloc_size_t row_data_length, int flush), + PNG_EMPTY); -PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_write_IEND,(png_structrp png_ptr),PNG_EMPTY); #ifdef PNG_WRITE_gAMA_SUPPORTED -# ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma)); -# endif -# ifdef PNG_FIXED_POINT_SUPPORTED -PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, - png_fixed_point file_gamma)); -# endif +PNG_INTERNAL_FUNCTION(void,png_write_gAMA_fixed,(png_structrp png_ptr, + png_fixed_point file_gamma),PNG_EMPTY); #endif #ifdef PNG_WRITE_sBIT_SUPPORTED -PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, - png_const_color_8p sbit, int color_type)); +PNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr, + png_const_color_8p sbit, int color_type),PNG_EMPTY); #endif #ifdef PNG_WRITE_cHRM_SUPPORTED -# ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr, - double white_x, double white_y, - double red_x, double red_y, double green_x, double green_y, - double blue_x, double blue_y)); -# endif -PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr, - png_fixed_point int_white_x, png_fixed_point int_white_y, - png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point - int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, - png_fixed_point int_blue_y)); +PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr, + const png_xy *xy), PNG_EMPTY); + /* The xy value must have been previously validated */ #endif #ifdef PNG_WRITE_sRGB_SUPPORTED -PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, - int intent)); +PNG_INTERNAL_FUNCTION(void,png_write_sRGB,(png_structrp png_ptr, + int intent),PNG_EMPTY); #endif #ifdef PNG_WRITE_iCCP_SUPPORTED -PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr, - png_const_charp name, int compression_type, - png_const_charp profile, int proflen)); - /* Note to maintainer: profile should be png_bytep */ +PNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr, + png_const_charp name, png_const_bytep profile), PNG_EMPTY); + /* The profile must have been previously validated for correctness, the + * length comes from the first four bytes. Only the base, deflate, + * compression is supported. + */ #endif #ifdef PNG_WRITE_sPLT_SUPPORTED -PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr, - png_const_sPLT_tp palette)); +PNG_INTERNAL_FUNCTION(void,png_write_sPLT,(png_structrp png_ptr, + png_const_sPLT_tp palette),PNG_EMPTY); #endif #ifdef PNG_WRITE_tRNS_SUPPORTED -PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, +PNG_INTERNAL_FUNCTION(void,png_write_tRNS,(png_structrp png_ptr, png_const_bytep trans, png_const_color_16p values, int number, - int color_type)); + int color_type),PNG_EMPTY); #endif #ifdef PNG_WRITE_bKGD_SUPPORTED -PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr, - png_const_color_16p values, int color_type)); +PNG_INTERNAL_FUNCTION(void,png_write_bKGD,(png_structrp png_ptr, + png_const_color_16p values, int color_type),PNG_EMPTY); #endif #ifdef PNG_WRITE_hIST_SUPPORTED -PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, - png_const_uint_16p hist, int num_hist)); +PNG_INTERNAL_FUNCTION(void,png_write_hIST,(png_structrp png_ptr, + png_const_uint_16p hist, int num_hist),PNG_EMPTY); #endif /* Chunks that have keywords */ -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ - defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) -PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, - png_const_charp key, png_charpp new_key)); -#endif - #ifdef PNG_WRITE_tEXt_SUPPORTED -PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_const_charp key, - png_const_charp text, png_size_t text_len)); +PNG_INTERNAL_FUNCTION(void,png_write_tEXt,(png_structrp png_ptr, + png_const_charp key, png_const_charp text, png_size_t text_len),PNG_EMPTY); #endif #ifdef PNG_WRITE_zTXt_SUPPORTED -PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_const_charp key, - png_const_charp text, png_size_t text_len, int compression)); +PNG_INTERNAL_FUNCTION(void,png_write_zTXt,(png_structrp png_ptr, png_const_charp + key, png_const_charp text, int compression),PNG_EMPTY); #endif #ifdef PNG_WRITE_iTXt_SUPPORTED -PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr, +PNG_INTERNAL_FUNCTION(void,png_write_iTXt,(png_structrp png_ptr, int compression, png_const_charp key, png_const_charp lang, - png_const_charp lang_key, png_const_charp text)); + png_const_charp lang_key, png_const_charp text),PNG_EMPTY); #endif #ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */ -PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr, - png_infop info_ptr, png_const_textp text_ptr, int num_text)); +PNG_INTERNAL_FUNCTION(int,png_set_text_2,(png_const_structrp png_ptr, + png_inforp info_ptr, png_const_textp text_ptr, int num_text),PNG_EMPTY); #endif #ifdef PNG_WRITE_oFFs_SUPPORTED -PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr, - png_int_32 x_offset, png_int_32 y_offset, int unit_type)); +PNG_INTERNAL_FUNCTION(void,png_write_oFFs,(png_structrp png_ptr, + png_int_32 x_offset, png_int_32 y_offset, int unit_type),PNG_EMPTY); #endif #ifdef PNG_WRITE_pCAL_SUPPORTED -PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose, - png_int_32 X0, png_int_32 X1, int type, int nparams, - png_const_charp units, png_charpp params)); +PNG_INTERNAL_FUNCTION(void,png_write_pCAL,(png_structrp png_ptr, + png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, + png_const_charp units, png_charpp params),PNG_EMPTY); #endif #ifdef PNG_WRITE_pHYs_SUPPORTED -PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr, +PNG_INTERNAL_FUNCTION(void,png_write_pHYs,(png_structrp png_ptr, png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, - int unit_type)); + int unit_type),PNG_EMPTY); #endif #ifdef PNG_WRITE_tIME_SUPPORTED -PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr, - png_const_timep mod_time)); +PNG_INTERNAL_FUNCTION(void,png_write_tIME,(png_structrp png_ptr, + png_const_timep mod_time),PNG_EMPTY); #endif #ifdef PNG_WRITE_sCAL_SUPPORTED -PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, - int unit, png_const_charp width, png_const_charp height)); +PNG_INTERNAL_FUNCTION(void,png_write_sCAL_s,(png_structrp png_ptr, + int unit, png_const_charp width, png_const_charp height),PNG_EMPTY); #endif /* Called when finished processing a row of data */ -PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_write_finish_row,(png_structrp png_ptr), + PNG_EMPTY); /* Internal use only. Called before first row of data */ -PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_write_start_row,(png_structrp png_ptr), + PNG_EMPTY); -/* Combine a row of data, dealing with alpha, etc. if requested */ -PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, - int mask)); +/* Combine a row of data, dealing with alpha, etc. if requested. 'row' is an + * array of png_ptr->width pixels. If the image is not interlaced or this + * is the final pass this just does a memcpy, otherwise the "display" flag + * is used to determine whether to copy pixels that are not in the current pass. + * + * Because 'png_do_read_interlace' (below) replicates pixels this allows this + * function to achieve the documented 'blocky' appearance during interlaced read + * if display is 1 and the 'sparkle' appearance, where existing pixels in 'row' + * are not changed if they are not in the current pass, when display is 0. + * + * 'display' must be 0 or 1, otherwise the memcpy will be done regardless. + * + * The API always reads from the png_struct row buffer and always assumes that + * it is full width (png_do_read_interlace has already been called.) + * + * This function is only ever used to write to row buffers provided by the + * caller of the relevant libpng API and the row must have already been + * transformed by the read transformations. + * + * The PNG_USE_COMPILE_TIME_MASKS option causes generation of pre-computed + * bitmasks for use within the code, otherwise runtime generated masks are used. + * The default is compile time masks. + */ +#ifndef PNG_USE_COMPILE_TIME_MASKS +# define PNG_USE_COMPILE_TIME_MASKS 1 +#endif +PNG_INTERNAL_FUNCTION(void,png_combine_row,(png_const_structrp png_ptr, + png_bytep row, int display),PNG_EMPTY); #ifdef PNG_READ_INTERLACING_SUPPORTED -/* Expand an interlaced row */ -/* OLD pre-1.0.9 interface: -PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, - png_bytep row, int pass, png_uint_32 transformations)); +/* Expand an interlaced row: the 'row_info' describes the pass data that has + * been read in and must correspond to the pixels in 'row', the pixels are + * expanded (moved apart) in 'row' to match the final layout, when doing this + * the pixels are *replicated* to the intervening space. This is essential for + * the correct operation of png_combine_row, above. */ -PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_do_read_interlace,(png_row_infop row_info, + png_bytep row, int pass, png_uint_32 transformations),PNG_EMPTY); #endif /* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ #ifdef PNG_WRITE_INTERLACING_SUPPORTED /* Grab pixels out of a row for an interlaced pass */ -PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, - png_bytep row, int pass)); +PNG_INTERNAL_FUNCTION(void,png_do_write_interlace,(png_row_infop row_info, + png_bytep row, int pass),PNG_EMPTY); #endif -/* Unfilter a row */ -PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr, - png_row_infop row_info, png_bytep row, png_const_bytep prev_row, - int filter)); +/* Unfilter a row: check the filter value before calling this, there is no point + * calling it for PNG_FILTER_VALUE_NONE. + */ +PNG_INTERNAL_FUNCTION(void,png_read_filter_row,(png_structrp pp, png_row_infop + row_info, png_bytep row, png_const_bytep prev_row, int filter),PNG_EMPTY); + +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_neon,(png_row_infop row_info, + png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); /* Choose the best filter to use and filter the row data */ -PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, - png_row_infop row_info)); +PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr, + png_row_infop row_info),PNG_EMPTY); -/* Finish a row while reading, dealing with interlacing passes, etc. */ -PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr)); +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_read_IDAT_data,(png_structrp png_ptr, + png_bytep output, png_alloc_size_t avail_out),PNG_EMPTY); + /* Read 'avail_out' bytes of data from the IDAT stream. If the output buffer + * is NULL the function checks, instead, for the end of the stream. In this + * case a benign error will be issued if the stream end is not found or if + * extra data has to be consumed. + */ +PNG_INTERNAL_FUNCTION(void,png_read_finish_IDAT,(png_structrp png_ptr), + PNG_EMPTY); + /* This cleans up when the IDAT LZ stream does not end when the last image + * byte is read; there is still some pending input. + */ + +PNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr), + PNG_EMPTY); + /* Finish a row while reading, dealing with interlacing passes, etc. */ +#endif /* SEQUENTIAL_READ */ /* Initialize the row buffers, etc. */ -PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY); #ifdef PNG_READ_TRANSFORMS_SUPPORTED /* Optional call to update the users info structure */ -PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr, - png_infop info_ptr)); -#endif - -/* These are the functions that do the transformations */ -#ifdef PNG_READ_FILLER_SUPPORTED -PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 filler, png_uint_32 flags)); -#endif - -#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED -PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED -PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED -PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED -PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info, - png_bytep row)); +PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); #endif +/* Shared transform functions, defined in pngtran.c */ #if defined(PNG_WRITE_FILLER_SUPPORTED) || \ defined(PNG_READ_STRIP_ALPHA_SUPPORTED) -PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info, - png_bytep row, int at_start)); +PNG_INTERNAL_FUNCTION(void,png_do_strip_channel,(png_row_infop row_info, + png_bytep row, int at_start),PNG_EMPTY); #endif #ifdef PNG_16BIT_SUPPORTED #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, - png_bytep row)); +PNG_INTERNAL_FUNCTION(void,png_do_swap,(png_row_infop row_info, + png_bytep row),PNG_EMPTY); #endif #endif #if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ defined(PNG_WRITE_PACKSWAP_SUPPORTED) -PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED -PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, - png_row_infop row_info, png_bytep row)); -#endif - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED -PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_PACK_SUPPORTED -PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_SHIFT_SUPPORTED -PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, - png_bytep row, png_const_color_8p sig_bits)); +PNG_INTERNAL_FUNCTION(void,png_do_packswap,(png_row_infop row_info, + png_bytep row),PNG_EMPTY); #endif #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) -PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED -PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED -PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_QUANTIZE_SUPPORTED -PNG_EXTERN void png_do_quantize PNGARG((png_row_infop row_info, - png_bytep row, png_const_bytep palette_lookup, - png_const_bytep quantize_lookup)); - -# ifdef PNG_CORRECT_PALETTE_SUPPORTED -PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr, - png_colorp palette, int num_palette)); -# endif +PNG_INTERNAL_FUNCTION(void,png_do_invert,(png_row_infop row_info, + png_bytep row),PNG_EMPTY); #endif #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) -PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_WRITE_PACK_SUPPORTED -PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 bit_depth)); -#endif - -#ifdef PNG_WRITE_SHIFT_SUPPORTED -PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, - png_bytep row, png_const_color_8p bit_depth)); -#endif - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) -PNG_EXTERN void png_do_compose PNGARG((png_row_infop row_info, - png_bytep row, png_structp png_ptr)); -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED -PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, - png_bytep row, png_structp png_ptr)); -#endif - -#ifdef PNG_READ_ALPHA_MODE_SUPPORTED -PNG_EXTERN void png_do_encode_alpha PNGARG((png_row_infop row_info, - png_bytep row, png_structp png_ptr)); -#endif - -#ifdef PNG_READ_EXPAND_SUPPORTED -PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info, - png_bytep row, png_const_colorp palette, png_const_bytep trans, - int num_trans)); -PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info, - png_bytep row, png_const_color_16p trans_color)); -#endif - -#ifdef PNG_READ_EXPAND_16_SUPPORTED -PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info, - png_bytep row)); +PNG_INTERNAL_FUNCTION(void,png_do_bgr,(png_row_infop row_info, + png_bytep row),PNG_EMPTY); #endif /* The following decodes the appropriate chunks, and does error correction, @@ -924,208 +1303,283 @@ PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info, */ /* Decode the IHDR chunk */ -PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_IHDR,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_handle_PLTE,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_handle_IEND,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #ifdef PNG_READ_bKGD_SUPPORTED -PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_bKGD,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_cHRM_SUPPORTED -PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_cHRM,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_gAMA_SUPPORTED -PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_hIST_SUPPORTED -PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_hIST,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_iCCP_SUPPORTED -PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif /* PNG_READ_iCCP_SUPPORTED */ +PNG_INTERNAL_FUNCTION(void,png_handle_iCCP,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif /* READ_iCCP */ #ifdef PNG_READ_iTXt_SUPPORTED -PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_iTXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_oFFs_SUPPORTED -PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_oFFs,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_pCAL_SUPPORTED -PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_pCAL,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_pHYs_SUPPORTED -PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_pHYs,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_sBIT_SUPPORTED -PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_sBIT,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_sCAL_SUPPORTED -PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_sCAL,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_sPLT_SUPPORTED -PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif /* PNG_READ_sPLT_SUPPORTED */ +PNG_INTERNAL_FUNCTION(void,png_handle_sPLT,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif /* READ_sPLT */ #ifdef PNG_READ_sRGB_SUPPORTED -PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_sRGB,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_tEXt_SUPPORTED -PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_tEXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_tIME_SUPPORTED -PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_tIME,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_tRNS_SUPPORTED -PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_tRNS,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif #ifdef PNG_READ_zTXt_SUPPORTED -PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); #endif -PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); +PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_structrp png_ptr, + png_uint_32 chunk_name),PNG_EMPTY); -PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr, - png_const_bytep chunk_name)); +PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY); + /* This is the function that gets called for unknown chunks. The 'keep' + * argument is either non-zero for a known chunk that has been set to be + * handled as unknown or zero for an unknown chunk. By default the function + * just skips the chunk or errors out if it is critical. + */ + +#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\ + defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) +PNG_INTERNAL_FUNCTION(int,png_chunk_unknown_handling, + (png_const_structrp png_ptr, png_uint_32 chunk_name),PNG_EMPTY); + /* Exactly as the API png_handle_as_unknown() except that the argument is a + * 32-bit chunk name, not a string. + */ +#endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */ /* Handle the transformations for reading and writing */ #ifdef PNG_READ_TRANSFORMS_SUPPORTED -PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_do_read_transformations,(png_structrp png_ptr, + png_row_infop row_info),PNG_EMPTY); #endif #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED -PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_do_write_transformations,(png_structrp png_ptr, + png_row_infop row_info),PNG_EMPTY); #endif #ifdef PNG_READ_TRANSFORMS_SUPPORTED -PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_init_read_transformations,(png_structrp png_ptr), + PNG_EMPTY); #endif #ifdef PNG_PROGRESSIVE_READ_SUPPORTED -PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr, - png_uint_32 length)); -PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t buffer_length)); -PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t buffer_length)); -PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row)); -PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr)); +PNG_INTERNAL_FUNCTION(void,png_push_read_chunk,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_sig,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_check_crc,(png_structrp png_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_crc_skip,(png_structrp png_ptr, + png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_crc_finish,(png_structrp png_ptr), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_save_buffer,(png_structrp png_ptr), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_restore_buffer,(png_structrp png_ptr, + png_bytep buffer, png_size_t buffer_length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_IDAT,(png_structrp png_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_process_IDAT_data,(png_structrp png_ptr, + png_bytep buffer, png_size_t buffer_length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_process_row,(png_structrp png_ptr), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_handle_unknown,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_have_info,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr, + png_bytep row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_push_finish_row,(png_structrp png_ptr), + PNG_EMPTY); # ifdef PNG_READ_tEXt_SUPPORTED -PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); +PNG_INTERNAL_FUNCTION(void,png_push_handle_tEXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_tEXt,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); # endif # ifdef PNG_READ_zTXt_SUPPORTED -PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); +PNG_INTERNAL_FUNCTION(void,png_push_handle_zTXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_zTXt,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); # endif # ifdef PNG_READ_iTXt_SUPPORTED -PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); +PNG_INTERNAL_FUNCTION(void,png_push_handle_iTXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_iTXt,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); # endif -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ +#endif /* PROGRESSIVE_READ */ -#ifdef PNG_MNG_FEATURES_SUPPORTED -PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info, - png_bytep row)); -PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, - png_bytep row)); +/* Added at libpng version 1.6.0 */ +#ifdef PNG_GAMMA_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_fixed_point gAMA), PNG_EMPTY); + /* Set the colorspace gamma with a value provided by the application or by + * the gAMA chunk on read. The value will override anything set by an ICC + * profile. + */ + +PNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr, + png_inforp info_ptr), PNG_EMPTY); + /* Synchronize the info 'valid' flags with the colorspace */ + +PNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr, + png_inforp info_ptr), PNG_EMPTY); + /* Copy the png_struct colorspace to the info_struct and call the above to + * synchronize the flags. Checks for NULL info_ptr and does nothing. + */ #endif /* Added at libpng version 1.4.0 */ -#ifdef PNG_CHECK_cHRM_SUPPORTED -PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr, - png_fixed_point int_white_x, png_fixed_point int_white_y, - png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point - int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, - png_fixed_point int_blue_y)); -#endif +#ifdef PNG_COLORSPACE_SUPPORTED +/* These internal functions are for maintaining the colorspace structure within + * a png_info or png_struct (or, indeed, both). + */ +PNG_INTERNAL_FUNCTION(int,png_colorspace_set_chromaticities, + (png_const_structrp png_ptr, png_colorspacerp colorspace, const png_xy *xy, + int preferred), PNG_EMPTY); -#ifdef PNG_CHECK_cHRM_SUPPORTED -/* Added at libpng version 1.2.34 and 1.4.0 */ -/* Currently only used by png_check_cHRM_fixed */ -PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2, - unsigned long *hi_product, unsigned long *lo_product)); +PNG_INTERNAL_FUNCTION(int,png_colorspace_set_endpoints, + (png_const_structrp png_ptr, png_colorspacerp colorspace, const png_XYZ *XYZ, + int preferred), PNG_EMPTY); + +#ifdef PNG_sRGB_SUPPORTED +PNG_INTERNAL_FUNCTION(int,png_colorspace_set_sRGB,(png_const_structrp png_ptr, + png_colorspacerp colorspace, int intent), PNG_EMPTY); + /* This does set the colorspace gAMA and cHRM values too, but doesn't set the + * flags to write them, if it returns false there was a problem and an error + * message has already been output (but the colorspace may still need to be + * synced to record the invalid flag). + */ +#endif /* sRGB */ + +#ifdef PNG_iCCP_SUPPORTED +PNG_INTERNAL_FUNCTION(int,png_colorspace_set_ICC,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_charp name, + png_uint_32 profile_length, png_const_bytep profile, int color_type), + PNG_EMPTY); + /* The 'name' is used for information only */ + +/* Routines for checking parts of an ICC profile. */ +PNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_charp name, + png_uint_32 profile_length), PNG_EMPTY); +PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_charp name, + png_uint_32 profile_length, + png_const_bytep profile /* first 132 bytes only */, int color_type), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(int,png_icc_check_tag_table,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_charp name, + png_uint_32 profile_length, + png_const_bytep profile /* header plus whole tag table */), PNG_EMPTY); +#ifdef PNG_sRGB_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_icc_set_sRGB,( + png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_bytep profile, uLong adler), PNG_EMPTY); + /* 'adler' is the Adler32 checksum of the uncompressed profile data. It may + * be zero to indicate that it is not available. It is used, if provided, + * as a fast check on the profile when checking to see if it is sRGB. + */ #endif +#endif /* iCCP */ + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_colorspace_set_rgb_coefficients, + (png_structrp png_ptr), PNG_EMPTY); + /* Set the rgb_to_gray coefficients from the colorspace Y values */ +#endif /* READ_RGB_TO_GRAY */ +#endif /* COLORSPACE */ /* Added at libpng version 1.4.0 */ -PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr, +PNG_INTERNAL_FUNCTION(void,png_check_IHDR,(png_const_structrp png_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, - int filter_type)); + int filter_type),PNG_EMPTY); -/* Free all memory used by the read (old method - NOT DLL EXPORTED) */ -PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr, - png_infop info_ptr, png_infop end_info_ptr)); - -/* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */ -PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr)); - -#ifdef USE_FAR_KEYWORD /* memory model conversion function */ -PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr, - int check)); -#endif /* USE_FAR_KEYWORD */ +/* Added at libpng version 1.5.10 */ +#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ + defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) +PNG_INTERNAL_FUNCTION(void,png_do_check_palette_indexes, + (png_structrp png_ptr, png_row_infop row_info),PNG_EMPTY); +#endif #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) -PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr, +PNG_INTERNAL_FUNCTION(void,png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN); #endif @@ -1133,8 +1587,8 @@ PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr, * the end. Always leaves the buffer nul terminated. Never errors out (and * there is no error code.) */ -PNG_EXTERN size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos, - png_const_charp string); +PNG_INTERNAL_FUNCTION(size_t,png_safecat,(png_charp buffer, size_t bufsize, + size_t pos, png_const_charp string),PNG_EMPTY); /* Various internal functions to handle formatted warning messages, currently * only implemented for warnings. @@ -1145,8 +1599,8 @@ PNG_EXTERN size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos, * Returns the pointer to the start of the formatted string. This utility only * does unsigned values. */ -PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end, - int format, png_alloc_size_t number); +PNG_INTERNAL_FUNCTION(png_charp,png_format_number,(png_const_charp start, + png_charp end, int format, png_alloc_size_t number),PNG_EMPTY); /* Convenience macro that takes an array: */ #define PNG_FORMAT_NUMBER(buffer,format,number) \ @@ -1170,7 +1624,7 @@ PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end, #ifdef PNG_WARNINGS_SUPPORTED /* New defines and members adding in libpng-1.5.4 */ # define PNG_WARNING_PARAMETER_SIZE 32 -# define PNG_WARNING_PARAMETER_COUNT 8 +# define PNG_WARNING_PARAMETER_COUNT 8 /* Maximum 9; see pngerror.c */ /* An l-value of this type has to be passed to the APIs below to cache the * values of the parameters to a formatted warning message. @@ -1178,48 +1632,97 @@ PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end, typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][ PNG_WARNING_PARAMETER_SIZE]; -PNG_EXTERN void png_warning_parameter(png_warning_parameters p, int number, - png_const_charp string); - /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters, - * including the trailing '\0'. - */ -PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p, - int number, int format, png_alloc_size_t value); - /* Use png_alloc_size_t because it is an unsigned type as big as any we - * need to output. Use the following for a signed value. - */ -PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p, - int number, int format, png_int_32 value); +PNG_INTERNAL_FUNCTION(void,png_warning_parameter,(png_warning_parameters p, + int number, png_const_charp string),PNG_EMPTY); + /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters, + * including the trailing '\0'. + */ +PNG_INTERNAL_FUNCTION(void,png_warning_parameter_unsigned, + (png_warning_parameters p, int number, int format, png_alloc_size_t value), + PNG_EMPTY); + /* Use png_alloc_size_t because it is an unsigned type as big as any we + * need to output. Use the following for a signed value. + */ +PNG_INTERNAL_FUNCTION(void,png_warning_parameter_signed, + (png_warning_parameters p, int number, int format, png_int_32 value), + PNG_EMPTY); -PNG_EXTERN void png_formatted_warning(png_structp png_ptr, - png_warning_parameters p, png_const_charp message); - /* 'message' follows the X/Open approach of using @1, @2 to insert - * parameters previously supplied using the above functions. Errors in - * specifying the parameters will simple result in garbage substitutions. - */ +PNG_INTERNAL_FUNCTION(void,png_formatted_warning,(png_const_structrp png_ptr, + png_warning_parameters p, png_const_charp message),PNG_EMPTY); + /* 'message' follows the X/Open approach of using @1, @2 to insert + * parameters previously supplied using the above functions. Errors in + * specifying the parameters will simply result in garbage substitutions. + */ #endif +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +/* Application errors (new in 1.6); use these functions (declared below) for + * errors in the parameters or order of API function calls on read. The + * 'warning' should be used for an error that can be handled completely; the + * 'error' for one which can be handled safely but which may lose application + * information or settings. + * + * By default these both result in a png_error call prior to release, while in a + * released version the 'warning' is just a warning. However if the application + * explicitly disables benign errors (explicitly permitting the code to lose + * information) they both turn into warnings. + * + * If benign errors aren't supported they end up as the corresponding base call + * (png_warning or png_error.) + */ +PNG_INTERNAL_FUNCTION(void,png_app_warning,(png_const_structrp png_ptr, + png_const_charp message),PNG_EMPTY); + /* The application provided invalid parameters to an API function or called + * an API function at the wrong time, libpng can completely recover. + */ + +PNG_INTERNAL_FUNCTION(void,png_app_error,(png_const_structrp png_ptr, + png_const_charp message),PNG_EMPTY); + /* As above but libpng will ignore the call, or attempt some other partial + * recovery from the error. + */ +#else +# define png_app_warning(pp,s) png_warning(pp,s) +# define png_app_error(pp,s) png_error(pp,s) +#endif + +PNG_INTERNAL_FUNCTION(void,png_chunk_report,(png_const_structrp png_ptr, + png_const_charp message, int error),PNG_EMPTY); + /* Report a recoverable issue in chunk data. On read this is used to report + * a problem found while reading a particular chunk and the + * png_chunk_benign_error or png_chunk_warning function is used as + * appropriate. On write this is used to report an error that comes from + * data set via an application call to a png_set_ API and png_app_error or + * png_app_warning is used as appropriate. + * + * The 'error' parameter must have one of the following values: + */ +#define PNG_CHUNK_WARNING 0 /* never an error */ +#define PNG_CHUNK_WRITE_ERROR 1 /* an error only on write */ +#define PNG_CHUNK_ERROR 2 /* always an error */ + /* ASCII to FP interfaces, currently only implemented if sCAL * support is required. */ -#if defined(PNG_READ_sCAL_SUPPORTED) +#if defined(PNG_sCAL_SUPPORTED) /* MAX_DIGITS is actually the maximum number of characters in an sCAL * width or height, derived from the precision (number of significant - * digits - a build time settable option) and assumpitions about the + * digits - a build time settable option) and assumptions about the * maximum ridiculous exponent. */ #define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/) #ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_ascii_from_fp PNGARG((png_structp png_ptr, png_charp ascii, - png_size_t size, double fp, unsigned int precision)); +PNG_INTERNAL_FUNCTION(void,png_ascii_from_fp,(png_const_structrp png_ptr, + png_charp ascii, png_size_t size, double fp, unsigned int precision), + PNG_EMPTY); #endif /* FLOATING_POINT */ #ifdef PNG_FIXED_POINT_SUPPORTED -PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr, - png_charp ascii, png_size_t size, png_fixed_point fp)); +PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr, + png_charp ascii, png_size_t size, png_fixed_point fp),PNG_EMPTY); #endif /* FIXED_POINT */ -#endif /* READ_sCAL */ +#endif /* sCAL */ #if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) /* An internal API to validate the format of a floating point number. @@ -1243,7 +1746,7 @@ PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr, * NOTE: The dangling E problem. * There is a PNG valid floating point number in the following: * - * PNG floating point numb1.ers are not greedy. + * PNG floating point numbers are not greedy. * * Working this out requires *TWO* character lookahead (because of the * sign), the parser does not do this - it will fail at the 'r' - this @@ -1294,14 +1797,14 @@ PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr, #define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK) #define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK) -/* The actual parser. This can be called repeatedly, it updates +/* The actual parser. This can be called repeatedly. It updates * the index into the string and the state variable (which must - * be initialzed to 0). It returns a result code, as above. There + * be initialized to 0). It returns a result code, as above. There * is no point calling the parser any more if it fails to advance to * the end of the string - it is stuck on an invalid character (or * terminated by '\0'). * - * Note that the pointer will consume an E or even an E+ then leave + * Note that the pointer will consume an E or even an E+ and then leave * a 'maybe' state even though a preceding integer.fraction is valid. * The PNG_FP_WAS_VALID flag indicates that a preceding substring was * a valid number. It's possible to recover from this by calling @@ -1309,8 +1812,8 @@ PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr, * that omits the last character (i.e. set the size to the index of * the problem character.) This has not been tested within libpng. */ -PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string, - png_size_t size, int *statep, png_size_tp whereami)); +PNG_INTERNAL_FUNCTION(int,png_check_fp_number,(png_const_charp string, + png_size_t size, int *statep, png_size_tp whereami),PNG_EMPTY); /* This is the same but it checks a complete string and returns true * only if it just contains a floating point number. As of 1.5.4 this @@ -1318,11 +1821,11 @@ PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string, * it was valid (otherwise it returns 0.) This can be used for testing * for negative or zero values using the sticky flag. */ -PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string, - png_size_t size)); +PNG_INTERNAL_FUNCTION(int,png_check_fp_string,(png_const_charp string, + png_size_t size),PNG_EMPTY); #endif /* pCAL || sCAL */ -#if defined(PNG_READ_GAMMA_SUPPORTED) ||\ +#if defined(PNG_GAMMA_SUPPORTED) ||\ defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED) /* Added at libpng version 1.5.0 */ /* This is a utility to provide a*times/div (rounded) and indicate @@ -1330,29 +1833,37 @@ PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string, * for overflow, true (1) if no overflow, in which case *res * holds the result. */ -PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a, - png_int_32 multiplied_by, png_int_32 divided_by)); +PNG_INTERNAL_FUNCTION(int,png_muldiv,(png_fixed_point_p res, png_fixed_point a, + png_int_32 multiplied_by, png_int_32 divided_by),PNG_EMPTY); #endif #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) /* Same deal, but issue a warning on overflow and return 0. */ -PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr, - png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by)); +PNG_INTERNAL_FUNCTION(png_fixed_point,png_muldiv_warn, + (png_const_structrp png_ptr, png_fixed_point a, png_int_32 multiplied_by, + png_int_32 divided_by),PNG_EMPTY); #endif -#ifdef PNG_READ_GAMMA_SUPPORTED +#ifdef PNG_GAMMA_SUPPORTED /* Calculate a reciprocal - used for gamma values. This returns - * 0 if the argument is 0 in order to maintain an undefined value, + * 0 if the argument is 0 in order to maintain an undefined value; * there are no warnings. */ -PNG_EXTERN png_fixed_point png_reciprocal PNGARG((png_fixed_point a)); +PNG_INTERNAL_FUNCTION(png_fixed_point,png_reciprocal,(png_fixed_point a), + PNG_EMPTY); +#ifdef PNG_READ_GAMMA_SUPPORTED /* The same but gives a reciprocal of the product of two fixed point * values. Accuracy is suitable for gamma calculations but this is - * not exact - use png_muldiv for that. + * not exact - use png_muldiv for that. Only required at present on read. */ -PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a, - png_fixed_point b)); +PNG_INTERNAL_FUNCTION(png_fixed_point,png_reciprocal2,(png_fixed_point a, + png_fixed_point b),PNG_EMPTY); +#endif + +/* Return true if the gamma value is significantly different from 1.0 */ +PNG_INTERNAL_FUNCTION(int,png_gamma_significant,(png_fixed_point gamma_value), + PNG_EMPTY); #endif #ifdef PNG_READ_GAMMA_SUPPORTED @@ -1363,19 +1874,93 @@ PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a, * While the input is an 'unsigned' value it must actually be the * correct bit value - 0..255 or 0..65535 as required. */ -PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr, - unsigned int value, png_fixed_point gamma_value)); -PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value)); -PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value, - png_fixed_point gamma_value)); -PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value, - png_fixed_point gamma_value)); -PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr, - int bit_depth)); +PNG_INTERNAL_FUNCTION(png_uint_16,png_gamma_correct,(png_structrp png_ptr, + unsigned int value, png_fixed_point gamma_value),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(png_uint_16,png_gamma_16bit_correct,(unsigned int value, + png_fixed_point gamma_value),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(png_byte,png_gamma_8bit_correct,(unsigned int value, + png_fixed_point gamma_value),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_destroy_gamma_table,(png_structrp png_ptr), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_build_gamma_table,(png_structrp png_ptr, + int bit_depth),PNG_EMPTY); #endif -/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ +/* SIMPLIFIED READ/WRITE SUPPORT */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +/* The internal structure that png_image::opaque points to. */ +typedef struct png_control +{ + png_structp png_ptr; + png_infop info_ptr; + png_voidp error_buf; /* Always a jmp_buf at present. */ + png_const_bytep memory; /* Memory buffer. */ + png_size_t size; /* Size of the memory buffer. */ + + unsigned int for_write :1; /* Otherwise it is a read structure */ + unsigned int owned_file :1; /* We own the file in io_ptr */ +} png_control; + +/* Return the pointer to the jmp_buf from a png_control: necessary because C + * does not reveal the type of the elements of jmp_buf. + */ +#ifdef __cplusplus +# define png_control_jmp_buf(pc) (((jmp_buf*)((pc)->error_buf))[0]) +#else +# define png_control_jmp_buf(pc) ((pc)->error_buf) +#endif + +/* Utility to safely execute a piece of libpng code catching and logging any + * errors that might occur. Returns true on success, false on failure (either + * of the function or as a result of a png_error.) + */ +PNG_INTERNAL_CALLBACK(void,png_safe_error,(png_structp png_ptr, + png_const_charp error_message),PNG_NORETURN); + +#ifdef PNG_WARNINGS_SUPPORTED +PNG_INTERNAL_CALLBACK(void,png_safe_warning,(png_structp png_ptr, + png_const_charp warning_message),PNG_EMPTY); +#else +# define png_safe_warning 0/*dummy argument*/ +#endif + +PNG_INTERNAL_FUNCTION(int,png_safe_execute,(png_imagep image, + int (*function)(png_voidp), png_voidp arg),PNG_EMPTY); + +/* Utility to log an error; this also cleans up the png_image; the function + * always returns 0 (false). + */ +PNG_INTERNAL_FUNCTION(int,png_image_error,(png_imagep image, + png_const_charp error_message),PNG_EMPTY); + +#ifndef PNG_SIMPLIFIED_READ_SUPPORTED +/* png_image_free is used by the write code but not exported */ +PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY); +#endif /* !SIMPLIFIED_READ */ + +#endif /* SIMPLIFIED READ/WRITE */ + +/* These are initialization functions for hardware specific PNG filter + * optimizations; list these here then select the appropriate one at compile + * time using the macro PNG_FILTER_OPTIMIZATIONS. If the macro is not defined + * the generic code is used. + */ +#ifdef PNG_FILTER_OPTIMIZATIONS +PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structp png_ptr, + unsigned int bpp), PNG_EMPTY); + /* Just declare the optimization that will be used */ +#else + /* List *all* the possible optimizations here - this branch is required if + * the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in + * CFLAGS in place of CPPFLAGS *and* uses symbol prefixing. + */ +PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon, + (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); +#endif + +/* Maintainer: Put new private prototypes here ^ */ #include "pngdebug.h" @@ -1383,4 +1968,5 @@ PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr, } #endif +#endif /* PNG_VERSION_INFO_ONLY */ #endif /* PNGPRIV_H */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngread.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngread.c index 503acae8ebb..71d5f9269aa 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngread.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngread.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -43,6 +43,9 @@ */ #include "pngpriv.h" +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) +# include +#endif #ifdef PNG_READ_SUPPORTED @@ -51,10 +54,12 @@ PNG_FUNCTION(png_structp,PNGAPI png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) { - -#ifdef PNG_USER_MEM_SUPPORTED - return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, - warn_fn, NULL, NULL, NULL)); +#ifndef PNG_USER_MEM_SUPPORTED + png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr, + error_fn, warn_fn, NULL, NULL, NULL); +#else + return png_create_read_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, NULL, NULL, NULL); } /* Alternate create PNG structure for reading, and allocate any memory @@ -65,134 +70,40 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) { -#endif /* PNG_USER_MEM_SUPPORTED */ + png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr, + error_fn, warn_fn, mem_ptr, malloc_fn, free_fn); +#endif /* USER_MEM */ -#ifdef PNG_SETJMP_SUPPORTED - volatile -#endif - png_structp png_ptr; - volatile int png_cleanup_needed = 0; - -#ifdef PNG_SETJMP_SUPPORTED -#ifdef USE_FAR_KEYWORD - jmp_buf tmp_jmpbuf; -#endif -#endif - - png_debug(1, "in png_create_read_struct"); - -#ifdef PNG_USER_MEM_SUPPORTED - png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, - malloc_fn, mem_ptr); -#else - png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); -#endif - if (png_ptr == NULL) - return (NULL); - - /* Added at libpng-1.2.6 */ -#ifdef PNG_USER_LIMITS_SUPPORTED - png_ptr->user_width_max = PNG_USER_WIDTH_MAX; - png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; - -# ifdef PNG_USER_CHUNK_CACHE_MAX - /* Added at libpng-1.2.43 and 1.4.0 */ - png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; -# endif - -# ifdef PNG_SET_USER_CHUNK_MALLOC_MAX - /* Added at libpng-1.2.43 and 1.4.1 */ - png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; -# endif -#endif - -#ifdef PNG_SETJMP_SUPPORTED -/* Applications that neglect to set up their own setjmp() and then - encounter a png_error() will longjmp here. Since the jmpbuf is - then meaningless we abort instead of returning. */ -#ifdef USE_FAR_KEYWORD - if (setjmp(tmp_jmpbuf)) -#else - if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */ -#endif - PNG_ABORT(); -#ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); -#endif -#endif /* PNG_SETJMP_SUPPORTED */ - -#ifdef PNG_USER_MEM_SUPPORTED - png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); -#endif - - png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); - - /* Call the general version checker (shared with read and write code): */ - if (!png_user_version_check(png_ptr, user_png_ver)) - png_cleanup_needed = 1; - - if (!png_cleanup_needed) + if (png_ptr != NULL) { - /* Initialize zbuf - compression buffer */ - png_ptr->zbuf_size = PNG_ZBUF_SIZE; - png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, png_ptr->zbuf_size); + png_ptr->mode = PNG_IS_READ_STRUCT; - if (png_ptr->zbuf == NULL) - png_cleanup_needed = 1; + /* Added in libpng-1.6.0; this can be used to detect a read structure if + * required (it will be zero in a write structure.) + */ +# ifdef PNG_SEQUENTIAL_READ_SUPPORTED + png_ptr->IDAT_read_size = PNG_IDAT_READ_SIZE; +# endif + +# ifdef PNG_BENIGN_READ_ERRORS_SUPPORTED + png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; + + /* In stable builds only warn if an application error can be completely + * handled. + */ +# if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC + png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN; +# endif +# endif + + /* TODO: delay this, it can be done in png_init_io (if the app doesn't + * do it itself) avoiding setting the default function if it is not + * required. + */ + png_set_read_fn(png_ptr, NULL, NULL); } - png_ptr->zstream.zalloc = png_zalloc; - png_ptr->zstream.zfree = png_zfree; - png_ptr->zstream.opaque = (voidpf)png_ptr; - - if (!png_cleanup_needed) - { - switch (inflateInit(&png_ptr->zstream)) - { - case Z_OK: - break; /* Do nothing */ - - case Z_MEM_ERROR: - png_warning(png_ptr, "zlib memory error"); - png_cleanup_needed = 1; - break; - - case Z_STREAM_ERROR: - png_warning(png_ptr, "zlib stream error"); - png_cleanup_needed = 1; - break; - - case Z_VERSION_ERROR: - png_warning(png_ptr, "zlib version error"); - png_cleanup_needed = 1; - break; - - default: png_warning(png_ptr, "Unknown zlib error"); - png_cleanup_needed = 1; - } - } - - if (png_cleanup_needed) - { - /* Clean up PNG structure and deallocate any memory. */ - png_free(png_ptr, png_ptr->zbuf); - png_ptr->zbuf = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, - (png_free_ptr)free_fn, (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)png_ptr); -#endif - return (NULL); - } - - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - - png_set_read_fn(png_ptr, NULL, NULL); - - - return (png_ptr); + return png_ptr; } @@ -206,8 +117,12 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, * read if it is determined that this isn't a valid PNG file. */ void PNGAPI -png_read_info(png_structp png_ptr, png_infop info_ptr) +png_read_info(png_structrp png_ptr, png_inforp info_ptr) { +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + int keep; +#endif + png_debug(1, "in png_read_info"); if (png_ptr == NULL || info_ptr == NULL) @@ -218,231 +133,179 @@ png_read_info(png_structp png_ptr, png_infop info_ptr) for (;;) { - PNG_IHDR; - PNG_IDAT; - PNG_IEND; - PNG_PLTE; -#ifdef PNG_READ_bKGD_SUPPORTED - PNG_bKGD; -#endif -#ifdef PNG_READ_cHRM_SUPPORTED - PNG_cHRM; -#endif -#ifdef PNG_READ_gAMA_SUPPORTED - PNG_gAMA; -#endif -#ifdef PNG_READ_hIST_SUPPORTED - PNG_hIST; -#endif -#ifdef PNG_READ_iCCP_SUPPORTED - PNG_iCCP; -#endif -#ifdef PNG_READ_iTXt_SUPPORTED - PNG_iTXt; -#endif -#ifdef PNG_READ_oFFs_SUPPORTED - PNG_oFFs; -#endif -#ifdef PNG_READ_pCAL_SUPPORTED - PNG_pCAL; -#endif -#ifdef PNG_READ_pHYs_SUPPORTED - PNG_pHYs; -#endif -#ifdef PNG_READ_sBIT_SUPPORTED - PNG_sBIT; -#endif -#ifdef PNG_READ_sCAL_SUPPORTED - PNG_sCAL; -#endif -#ifdef PNG_READ_sPLT_SUPPORTED - PNG_sPLT; -#endif -#ifdef PNG_READ_sRGB_SUPPORTED - PNG_sRGB; -#endif -#ifdef PNG_READ_tEXt_SUPPORTED - PNG_tEXt; -#endif -#ifdef PNG_READ_tIME_SUPPORTED - PNG_tIME; -#endif -#ifdef PNG_READ_tRNS_SUPPORTED - PNG_tRNS; -#endif -#ifdef PNG_READ_zTXt_SUPPORTED - PNG_zTXt; -#endif png_uint_32 length = png_read_chunk_header(png_ptr); - PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; + png_uint_32 chunk_name = png_ptr->chunk_name; + + /* IDAT logic needs to happen here to simplify getting the two flags + * right. + */ + if (chunk_name == png_IDAT) + { + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + (png_ptr->mode & PNG_HAVE_PLTE) == 0) + png_chunk_error(png_ptr, "Missing PLTE before IDAT"); + + else if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) + png_chunk_benign_error(png_ptr, "Too many IDATs found"); + + png_ptr->mode |= PNG_HAVE_IDAT; + } + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + png_ptr->mode |= PNG_AFTER_IDAT; /* This should be a binary subdivision search or a hash for * matching the chunk name rather than a linear search. */ - if (!png_memcmp(chunk_name, png_IDAT, 4)) - if (png_ptr->mode & PNG_AFTER_IDAT) - png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; - - if (!png_memcmp(chunk_name, png_IHDR, 4)) + if (chunk_name == png_IHDR) png_handle_IHDR(png_ptr, info_ptr, length); - else if (!png_memcmp(chunk_name, png_IEND, 4)) + else if (chunk_name == png_IEND) png_handle_IEND(png_ptr, info_ptr, length); #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - else if (png_handle_as_unknown(png_ptr, chunk_name)) + else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0) { - if (!png_memcmp(chunk_name, png_IDAT, 4)) - png_ptr->mode |= PNG_HAVE_IDAT; + png_handle_unknown(png_ptr, info_ptr, length, keep); - png_handle_unknown(png_ptr, info_ptr, length); - - if (!png_memcmp(chunk_name, png_PLTE, 4)) + if (chunk_name == png_PLTE) png_ptr->mode |= PNG_HAVE_PLTE; - else if (!png_memcmp(chunk_name, png_IDAT, 4)) + else if (chunk_name == png_IDAT) { - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before IDAT"); - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) - png_error(png_ptr, "Missing PLTE before IDAT"); - + png_ptr->idat_size = 0; /* It has been consumed */ break; } } #endif - else if (!png_memcmp(chunk_name, png_PLTE, 4)) + else if (chunk_name == png_PLTE) png_handle_PLTE(png_ptr, info_ptr, length); - else if (!png_memcmp(chunk_name, png_IDAT, 4)) + else if (chunk_name == png_IDAT) { - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before IDAT"); - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) - png_error(png_ptr, "Missing PLTE before IDAT"); - png_ptr->idat_size = length; - png_ptr->mode |= PNG_HAVE_IDAT; break; } #ifdef PNG_READ_bKGD_SUPPORTED - else if (!png_memcmp(chunk_name, png_bKGD, 4)) + else if (chunk_name == png_bKGD) png_handle_bKGD(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_cHRM_SUPPORTED - else if (!png_memcmp(chunk_name, png_cHRM, 4)) + else if (chunk_name == png_cHRM) png_handle_cHRM(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_gAMA_SUPPORTED - else if (!png_memcmp(chunk_name, png_gAMA, 4)) + else if (chunk_name == png_gAMA) png_handle_gAMA(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_hIST_SUPPORTED - else if (!png_memcmp(chunk_name, png_hIST, 4)) + else if (chunk_name == png_hIST) png_handle_hIST(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_oFFs_SUPPORTED - else if (!png_memcmp(chunk_name, png_oFFs, 4)) + else if (chunk_name == png_oFFs) png_handle_oFFs(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_pCAL_SUPPORTED - else if (!png_memcmp(chunk_name, png_pCAL, 4)) + else if (chunk_name == png_pCAL) png_handle_pCAL(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_sCAL_SUPPORTED - else if (!png_memcmp(chunk_name, png_sCAL, 4)) + else if (chunk_name == png_sCAL) png_handle_sCAL(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_pHYs_SUPPORTED - else if (!png_memcmp(chunk_name, png_pHYs, 4)) + else if (chunk_name == png_pHYs) png_handle_pHYs(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_sBIT_SUPPORTED - else if (!png_memcmp(chunk_name, png_sBIT, 4)) + else if (chunk_name == png_sBIT) png_handle_sBIT(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_sRGB_SUPPORTED - else if (!png_memcmp(chunk_name, png_sRGB, 4)) + else if (chunk_name == png_sRGB) png_handle_sRGB(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_iCCP_SUPPORTED - else if (!png_memcmp(chunk_name, png_iCCP, 4)) + else if (chunk_name == png_iCCP) png_handle_iCCP(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_sPLT_SUPPORTED - else if (!png_memcmp(chunk_name, png_sPLT, 4)) + else if (chunk_name == png_sPLT) png_handle_sPLT(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_tEXt_SUPPORTED - else if (!png_memcmp(chunk_name, png_tEXt, 4)) + else if (chunk_name == png_tEXt) png_handle_tEXt(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_tIME_SUPPORTED - else if (!png_memcmp(chunk_name, png_tIME, 4)) + else if (chunk_name == png_tIME) png_handle_tIME(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_tRNS_SUPPORTED - else if (!png_memcmp(chunk_name, png_tRNS, 4)) + else if (chunk_name == png_tRNS) png_handle_tRNS(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_zTXt_SUPPORTED - else if (!png_memcmp(chunk_name, png_zTXt, 4)) + else if (chunk_name == png_zTXt) png_handle_zTXt(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_iTXt_SUPPORTED - else if (!png_memcmp(chunk_name, png_iTXt, 4)) + else if (chunk_name == png_iTXt) png_handle_iTXt(png_ptr, info_ptr, length); #endif else - png_handle_unknown(png_ptr, info_ptr, length); + png_handle_unknown(png_ptr, info_ptr, length, + PNG_HANDLE_CHUNK_AS_DEFAULT); } } -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ +#endif /* SEQUENTIAL_READ */ /* Optional call to update the users info_ptr structure */ void PNGAPI -png_read_update_info(png_structp png_ptr, png_infop info_ptr) +png_read_update_info(png_structrp png_ptr, png_inforp info_ptr) { png_debug(1, "in png_read_update_info"); - if (png_ptr == NULL) - return; + if (png_ptr != NULL) + { + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) + { + png_read_start_row(png_ptr); - if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) - png_read_start_row(png_ptr); +# ifdef PNG_READ_TRANSFORMS_SUPPORTED + png_read_transform_info(png_ptr, info_ptr); +# else + PNG_UNUSED(info_ptr) +# endif + } - else - png_warning(png_ptr, - "Ignoring extra png_read_update_info() call;" - " row buffer not reallocated"); - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED - png_read_transform_info(png_ptr, info_ptr); -#else - PNG_UNUSED(info_ptr) -#endif + /* New in 1.6.0 this avoids the bug of doing the initializations twice */ + else + png_app_error(png_ptr, + "png_read_update_info/png_start_read_image: duplicate call"); + } } #ifdef PNG_SEQUENTIAL_READ_SUPPORTED @@ -452,33 +315,94 @@ png_read_update_info(png_structp png_ptr, png_infop info_ptr) * If the user doesn't call this, we will do it ourselves. */ void PNGAPI -png_start_read_image(png_structp png_ptr) +png_start_read_image(png_structrp png_ptr) { png_debug(1, "in png_start_read_image"); - if (png_ptr == NULL) - return; + if (png_ptr != NULL) + { + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) + png_read_start_row(png_ptr); - if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) - png_read_start_row(png_ptr); - else - png_warning(png_ptr, - "Ignoring extra png_start_read_image() call;" - " row buffer not reallocated"); + /* New in 1.6.0 this avoids the bug of doing the initializations twice */ + else + png_app_error(png_ptr, + "png_start_read_image/png_read_update_info: duplicate call"); + } } -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ +#endif /* SEQUENTIAL_READ */ #ifdef PNG_SEQUENTIAL_READ_SUPPORTED -void PNGAPI -png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) +#ifdef PNG_MNG_FEATURES_SUPPORTED +/* Undoes intrapixel differencing, + * NOTE: this is apparently only supported in the 'sequential' reader. + */ +static void +png_do_read_intrapixel(png_row_infop row_info, png_bytep row) { - PNG_IDAT; -#ifdef PNG_READ_INTERLACING_SUPPORTED - PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, - 0xff}; - PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; -#endif - int ret; + png_debug(1, "in png_do_read_intrapixel"); + + if ( + (row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff); + *(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff); + } + } + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); + png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); + png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); + png_uint_32 red = (s0 + s1 + 65536) & 0xffff; + png_uint_32 blue = (s2 + s1 + 65536) & 0xffff; + *(rp ) = (png_byte)((red >> 8) & 0xff); + *(rp + 1) = (png_byte)(red & 0xff); + *(rp + 4) = (png_byte)((blue >> 8) & 0xff); + *(rp + 5) = (png_byte)(blue & 0xff); + } + } + } +} +#endif /* MNG_FEATURES */ + +void PNGAPI +png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row) +{ + png_row_info row_info; if (png_ptr == NULL) return; @@ -486,52 +410,71 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) png_debug2(1, "in png_read_row (row %lu, pass %d)", (unsigned long)png_ptr->row_number, png_ptr->pass); - if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + /* png_read_start_row sets the information (in particular iwidth) for this + * interlace pass. + */ + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) png_read_start_row(png_ptr); + /* 1.5.6: row_info moved out of png_struct to a local here. */ + row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ + row_info.color_type = png_ptr->color_type; + row_info.bit_depth = png_ptr->bit_depth; + row_info.channels = png_ptr->channels; + row_info.pixel_depth = png_ptr->pixel_depth; + row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); + +#ifdef PNG_WARNINGS_SUPPORTED if (png_ptr->row_number == 0 && png_ptr->pass == 0) { /* Check for transforms that have been set but were defined out */ #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) - if (png_ptr->transformations & PNG_INVERT_MONO) + if ((png_ptr->transformations & PNG_INVERT_MONO) != 0) png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); #endif #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) - if (png_ptr->transformations & PNG_FILLER) + if ((png_ptr->transformations & PNG_FILLER) != 0) png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); #endif #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ !defined(PNG_READ_PACKSWAP_SUPPORTED) - if (png_ptr->transformations & PNG_PACKSWAP) + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); #endif #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) - if (png_ptr->transformations & PNG_PACK) + if ((png_ptr->transformations & PNG_PACK) != 0) png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); #endif #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) - if (png_ptr->transformations & PNG_SHIFT) + if ((png_ptr->transformations & PNG_SHIFT) != 0) png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); #endif #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) - if (png_ptr->transformations & PNG_BGR) + if ((png_ptr->transformations & PNG_BGR) != 0) png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); #endif #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) - if (png_ptr->transformations & PNG_SWAP_BYTES) + if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0) png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); #endif } +#endif /* WARNINGS */ #ifdef PNG_READ_INTERLACING_SUPPORTED - /* If interlaced and we do not need a new row, combine row and return */ - if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + /* If interlaced and we do not need a new row, combine row and return. + * Notice that the pixels we have from previous rows have been transformed + * already; we can only combine like with like (transformed or + * untransformed) and, because of the libpng API for interlaced images, this + * means we must transform before de-interlacing. + */ + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0) { switch (png_ptr->pass) { @@ -539,8 +482,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) if (png_ptr->row_number & 0x07) { if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, - png_pass_dsp_mask[png_ptr->pass]); + png_combine_row(png_ptr, dsp_row, 1/*display*/); png_read_finish_row(png_ptr); return; } @@ -550,8 +492,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) { if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, - png_pass_dsp_mask[png_ptr->pass]); + png_combine_row(png_ptr, dsp_row, 1/*display*/); png_read_finish_row(png_ptr); return; @@ -562,8 +503,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) if ((png_ptr->row_number & 0x07) != 4) { if (dsp_row != NULL && (png_ptr->row_number & 4)) - png_combine_row(png_ptr, dsp_row, - png_pass_dsp_mask[png_ptr->pass]); + png_combine_row(png_ptr, dsp_row, 1/*display*/); png_read_finish_row(png_ptr); return; @@ -574,8 +514,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) if ((png_ptr->row_number & 3) || png_ptr->width < 3) { if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, - png_pass_dsp_mask[png_ptr->pass]); + png_combine_row(png_ptr, dsp_row, 1/*display*/); png_read_finish_row(png_ptr); return; @@ -586,19 +525,18 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) if ((png_ptr->row_number & 3) != 2) { if (dsp_row != NULL && (png_ptr->row_number & 2)) - png_combine_row(png_ptr, dsp_row, - png_pass_dsp_mask[png_ptr->pass]); + png_combine_row(png_ptr, dsp_row, 1/*display*/); png_read_finish_row(png_ptr); return; } break; + case 5: if ((png_ptr->row_number & 1) || png_ptr->width < 2) { if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, - png_pass_dsp_mask[png_ptr->pass]); + png_combine_row(png_ptr, dsp_row, 1/*display*/); png_read_finish_row(png_ptr); return; @@ -607,7 +545,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) default: case 6: - if (!(png_ptr->row_number & 1)) + if ((png_ptr->row_number & 1) == 0) { png_read_finish_row(png_ptr); return; @@ -617,117 +555,85 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) } #endif - if (!(png_ptr->mode & PNG_HAVE_IDAT)) + if ((png_ptr->mode & PNG_HAVE_IDAT) == 0) png_error(png_ptr, "Invalid attempt to read row data"); - png_ptr->zstream.next_out = png_ptr->row_buf; - png_ptr->zstream.avail_out = - (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, - png_ptr->iwidth) + 1); + /* Fill the row with IDAT data: */ + png_read_IDAT_data(png_ptr, png_ptr->row_buf, row_info.rowbytes + 1); - do + if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) { - if (!(png_ptr->zstream.avail_in)) - { - while (!png_ptr->idat_size) - { - png_crc_finish(png_ptr, 0); + if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) + png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, + png_ptr->prev_row + 1, png_ptr->row_buf[0]); + else + png_error(png_ptr, "bad adaptive filter value"); + } - png_ptr->idat_size = png_read_chunk_header(png_ptr); - if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) - png_error(png_ptr, "Not enough image data"); - } - png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_in = png_ptr->zbuf; - if (png_ptr->zbuf_size > png_ptr->idat_size) - png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; - png_crc_read(png_ptr, png_ptr->zbuf, - (png_size_t)png_ptr->zstream.avail_in); - png_ptr->idat_size -= png_ptr->zstream.avail_in; - } - - ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); - - if (ret == Z_STREAM_END) - { - if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || - png_ptr->idat_size) - png_benign_error(png_ptr, "Extra compressed data"); - png_ptr->mode |= PNG_AFTER_IDAT; - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - break; - } - - if (ret != Z_OK) - png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : - "Decompression error"); - - } while (png_ptr->zstream.avail_out); - - png_ptr->row_info.color_type = png_ptr->color_type; - png_ptr->row_info.width = png_ptr->iwidth; - png_ptr->row_info.channels = png_ptr->channels; - png_ptr->row_info.bit_depth = png_ptr->bit_depth; - png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; - png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, - png_ptr->row_info.width); - - if (png_ptr->row_buf[0]) - png_read_filter_row(png_ptr, &(png_ptr->row_info), - png_ptr->row_buf + 1, png_ptr->prev_row + 1, - (int)(png_ptr->row_buf[0])); - - png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1); + /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before + * 1.5.6, while the buffer really is this big in current versions of libpng + * it may not be in the future, so this was changed just to copy the + * interlaced count: + */ + memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); #ifdef PNG_MNG_FEATURES_SUPPORTED - if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) { /* Intrapixel differencing */ - png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); + png_do_read_intrapixel(&row_info, png_ptr->row_buf + 1); } #endif - #ifdef PNG_READ_TRANSFORMS_SUPPORTED if (png_ptr->transformations) - png_do_read_transformations(png_ptr); + png_do_read_transformations(png_ptr, &row_info); #endif + /* The transformed pixel depth should match the depth now in row_info. */ + if (png_ptr->transformed_pixel_depth == 0) + { + png_ptr->transformed_pixel_depth = row_info.pixel_depth; + if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) + png_error(png_ptr, "sequential row overflow"); + } + + else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) + png_error(png_ptr, "internal sequential row size calculation error"); + #ifdef PNG_READ_INTERLACING_SUPPORTED - /* Blow up interlaced rows to full size */ - if (png_ptr->interlaced && - (png_ptr->transformations & PNG_INTERLACE)) + /* Expand interlaced rows to full size */ + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0) { if (png_ptr->pass < 6) - /* Old interface (pre-1.0.9): - * png_do_read_interlace(&(png_ptr->row_info), - * png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); - */ - png_do_read_interlace(png_ptr); + png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, + png_ptr->transformations); if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, png_pass_dsp_mask[png_ptr->pass]); + png_combine_row(png_ptr, dsp_row, 1/*display*/); if (row != NULL) - png_combine_row(png_ptr, row, png_pass_mask[png_ptr->pass]); + png_combine_row(png_ptr, row, 0/*row*/); } else #endif { if (row != NULL) - png_combine_row(png_ptr, row, 0xff); + png_combine_row(png_ptr, row, -1/*ignored*/); if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, 0xff); + png_combine_row(png_ptr, dsp_row, -1/*ignored*/); } png_read_finish_row(png_ptr); if (png_ptr->read_row_fn != NULL) (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); + } -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ +#endif /* SEQUENTIAL_READ */ #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read one or more rows of image data. If the image is interlaced, @@ -755,7 +661,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) */ void PNGAPI -png_read_rows(png_structp png_ptr, png_bytepp row, +png_read_rows(png_structrp png_ptr, png_bytepp row, png_bytepp display_row, png_uint_32 num_rows) { png_uint_32 i; @@ -794,7 +700,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row, dp++; } } -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ +#endif /* SEQUENTIAL_READ */ #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the entire image. If the image has an alpha channel or a tRNS @@ -810,7 +716,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row, * [*] png_handle_alpha() does not exist yet, as of this version of libpng */ void PNGAPI -png_read_image(png_structp png_ptr, png_bytepp image) +png_read_image(png_structrp png_ptr, png_bytepp image) { png_uint_32 i, image_height; int pass, j; @@ -822,7 +728,7 @@ png_read_image(png_structp png_ptr, png_bytepp image) return; #ifdef PNG_READ_INTERLACING_SUPPORTED - if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) { pass = png_set_interlace_handling(png_ptr); /* And make sure transforms are initialized. */ @@ -830,7 +736,8 @@ png_read_image(png_structp png_ptr, png_bytepp image) } else { - if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE)) + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) == 0) { /* Caller called png_start_read_image or png_read_update_info without * first turning on the PNG_INTERLACE transform. We can fix this here, @@ -867,7 +774,7 @@ png_read_image(png_structp png_ptr, png_bytepp image) } } } -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ +#endif /* SEQUENTIAL_READ */ #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the end of the PNG file. Will not read past the end of the @@ -875,416 +782,261 @@ png_read_image(png_structp png_ptr, png_bytepp image) * or time information at the end of the file, if info is not NULL. */ void PNGAPI -png_read_end(png_structp png_ptr, png_infop info_ptr) +png_read_end(png_structrp png_ptr, png_inforp info_ptr) { +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + int keep; +#endif + png_debug(1, "in png_read_end"); if (png_ptr == NULL) return; - png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ + /* If png_read_end is called in the middle of reading the rows there may + * still be pending IDAT data and an owned zstream. Deal with this here. + */ +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_chunk_unknown_handling(png_ptr, png_IDAT) == 0) +#endif + png_read_finish_IDAT(png_ptr); + +#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Report invalid palette index; added at libng-1.5.10 */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + png_ptr->num_palette_max > png_ptr->num_palette) + png_benign_error(png_ptr, "Read palette index exceeding num_palette"); +#endif do { - PNG_IHDR; - PNG_IDAT; - PNG_IEND; - PNG_PLTE; -#ifdef PNG_READ_bKGD_SUPPORTED - PNG_bKGD; -#endif -#ifdef PNG_READ_cHRM_SUPPORTED - PNG_cHRM; -#endif -#ifdef PNG_READ_gAMA_SUPPORTED - PNG_gAMA; -#endif -#ifdef PNG_READ_hIST_SUPPORTED - PNG_hIST; -#endif -#ifdef PNG_READ_iCCP_SUPPORTED - PNG_iCCP; -#endif -#ifdef PNG_READ_iTXt_SUPPORTED - PNG_iTXt; -#endif -#ifdef PNG_READ_oFFs_SUPPORTED - PNG_oFFs; -#endif -#ifdef PNG_READ_pCAL_SUPPORTED - PNG_pCAL; -#endif -#ifdef PNG_READ_pHYs_SUPPORTED - PNG_pHYs; -#endif -#ifdef PNG_READ_sBIT_SUPPORTED - PNG_sBIT; -#endif -#ifdef PNG_READ_sCAL_SUPPORTED - PNG_sCAL; -#endif -#ifdef PNG_READ_sPLT_SUPPORTED - PNG_sPLT; -#endif -#ifdef PNG_READ_sRGB_SUPPORTED - PNG_sRGB; -#endif -#ifdef PNG_READ_tEXt_SUPPORTED - PNG_tEXt; -#endif -#ifdef PNG_READ_tIME_SUPPORTED - PNG_tIME; -#endif -#ifdef PNG_READ_tRNS_SUPPORTED - PNG_tRNS; -#endif -#ifdef PNG_READ_zTXt_SUPPORTED - PNG_zTXt; -#endif png_uint_32 length = png_read_chunk_header(png_ptr); - PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; + png_uint_32 chunk_name = png_ptr->chunk_name; - if (!png_memcmp(chunk_name, png_IHDR, 4)) - png_handle_IHDR(png_ptr, info_ptr, length); - - else if (!png_memcmp(chunk_name, png_IEND, 4)) + if (chunk_name == png_IEND) png_handle_IEND(png_ptr, info_ptr, length); + else if (chunk_name == png_IHDR) + png_handle_IHDR(png_ptr, info_ptr, length); + + else if (info_ptr == NULL) + png_crc_finish(png_ptr, length); + #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - else if (png_handle_as_unknown(png_ptr, chunk_name)) + else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0) { - if (!png_memcmp(chunk_name, png_IDAT, 4)) + if (chunk_name == png_IDAT) { - if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) + if ((length > 0) || + (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0) png_benign_error(png_ptr, "Too many IDATs found"); } - png_handle_unknown(png_ptr, info_ptr, length); - if (!png_memcmp(chunk_name, png_PLTE, 4)) + png_handle_unknown(png_ptr, info_ptr, length, keep); + if (chunk_name == png_PLTE) png_ptr->mode |= PNG_HAVE_PLTE; } #endif - else if (!png_memcmp(chunk_name, png_IDAT, 4)) + else if (chunk_name == png_IDAT) { /* Zero length IDATs are legal after the last IDAT has been * read, but not after other chunks have been read. */ - if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) + if ((length > 0) || + (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0) png_benign_error(png_ptr, "Too many IDATs found"); png_crc_finish(png_ptr, length); } - else if (!png_memcmp(chunk_name, png_PLTE, 4)) + else if (chunk_name == png_PLTE) png_handle_PLTE(png_ptr, info_ptr, length); #ifdef PNG_READ_bKGD_SUPPORTED - else if (!png_memcmp(chunk_name, png_bKGD, 4)) + else if (chunk_name == png_bKGD) png_handle_bKGD(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_cHRM_SUPPORTED - else if (!png_memcmp(chunk_name, png_cHRM, 4)) + else if (chunk_name == png_cHRM) png_handle_cHRM(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_gAMA_SUPPORTED - else if (!png_memcmp(chunk_name, png_gAMA, 4)) + else if (chunk_name == png_gAMA) png_handle_gAMA(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_hIST_SUPPORTED - else if (!png_memcmp(chunk_name, png_hIST, 4)) + else if (chunk_name == png_hIST) png_handle_hIST(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_oFFs_SUPPORTED - else if (!png_memcmp(chunk_name, png_oFFs, 4)) + else if (chunk_name == png_oFFs) png_handle_oFFs(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_pCAL_SUPPORTED - else if (!png_memcmp(chunk_name, png_pCAL, 4)) + else if (chunk_name == png_pCAL) png_handle_pCAL(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_sCAL_SUPPORTED - else if (!png_memcmp(chunk_name, png_sCAL, 4)) + else if (chunk_name == png_sCAL) png_handle_sCAL(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_pHYs_SUPPORTED - else if (!png_memcmp(chunk_name, png_pHYs, 4)) + else if (chunk_name == png_pHYs) png_handle_pHYs(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_sBIT_SUPPORTED - else if (!png_memcmp(chunk_name, png_sBIT, 4)) + else if (chunk_name == png_sBIT) png_handle_sBIT(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_sRGB_SUPPORTED - else if (!png_memcmp(chunk_name, png_sRGB, 4)) + else if (chunk_name == png_sRGB) png_handle_sRGB(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_iCCP_SUPPORTED - else if (!png_memcmp(chunk_name, png_iCCP, 4)) + else if (chunk_name == png_iCCP) png_handle_iCCP(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_sPLT_SUPPORTED - else if (!png_memcmp(chunk_name, png_sPLT, 4)) + else if (chunk_name == png_sPLT) png_handle_sPLT(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_tEXt_SUPPORTED - else if (!png_memcmp(chunk_name, png_tEXt, 4)) + else if (chunk_name == png_tEXt) png_handle_tEXt(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_tIME_SUPPORTED - else if (!png_memcmp(chunk_name, png_tIME, 4)) + else if (chunk_name == png_tIME) png_handle_tIME(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_tRNS_SUPPORTED - else if (!png_memcmp(chunk_name, png_tRNS, 4)) + else if (chunk_name == png_tRNS) png_handle_tRNS(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_zTXt_SUPPORTED - else if (!png_memcmp(chunk_name, png_zTXt, 4)) + else if (chunk_name == png_zTXt) png_handle_zTXt(png_ptr, info_ptr, length); #endif #ifdef PNG_READ_iTXt_SUPPORTED - else if (!png_memcmp(chunk_name, png_iTXt, 4)) + else if (chunk_name == png_iTXt) png_handle_iTXt(png_ptr, info_ptr, length); #endif else - png_handle_unknown(png_ptr, info_ptr, length); - } while (!(png_ptr->mode & PNG_HAVE_IEND)); + png_handle_unknown(png_ptr, info_ptr, length, + PNG_HANDLE_CHUNK_AS_DEFAULT); + } while ((png_ptr->mode & PNG_HAVE_IEND) == 0); } -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ +#endif /* SEQUENTIAL_READ */ -/* Free all memory used by the read */ -void PNGAPI -png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, - png_infopp end_info_ptr_ptr) +/* Free all memory used in the read struct */ +static void +png_read_destroy(png_structrp png_ptr) { - png_structp png_ptr = NULL; - png_infop info_ptr = NULL, end_info_ptr = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_free_ptr free_fn = NULL; - png_voidp mem_ptr = NULL; -#endif - - png_debug(1, "in png_destroy_read_struct"); - - if (png_ptr_ptr != NULL) - png_ptr = *png_ptr_ptr; - if (png_ptr == NULL) - return; - -#ifdef PNG_USER_MEM_SUPPORTED - free_fn = png_ptr->free_fn; - mem_ptr = png_ptr->mem_ptr; -#endif - - if (info_ptr_ptr != NULL) - info_ptr = *info_ptr_ptr; - - if (end_info_ptr_ptr != NULL) - end_info_ptr = *end_info_ptr_ptr; - - png_read_destroy(png_ptr, info_ptr, end_info_ptr); - - if (info_ptr != NULL) - { -#ifdef PNG_TEXT_SUPPORTED - png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); -#endif - -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)info_ptr); -#endif - *info_ptr_ptr = NULL; - } - - if (end_info_ptr != NULL) - { -#ifdef PNG_READ_TEXT_SUPPORTED - png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); -#endif -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)end_info_ptr); -#endif - *end_info_ptr_ptr = NULL; - } - - if (png_ptr != NULL) - { -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)png_ptr); -#endif - *png_ptr_ptr = NULL; - } -} - -/* Free all memory used by the read (old method) */ -void /* PRIVATE */ -png_read_destroy(png_structp png_ptr, png_infop info_ptr, - png_infop end_info_ptr) -{ -#ifdef PNG_SETJMP_SUPPORTED - jmp_buf tmp_jmp; -#endif - png_error_ptr error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - png_error_ptr warning_fn; -#endif - png_voidp error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - png_free_ptr free_fn; -#endif - png_debug(1, "in png_read_destroy"); - if (info_ptr != NULL) - png_info_destroy(png_ptr, info_ptr); +#ifdef PNG_READ_GAMMA_SUPPORTED + png_destroy_gamma_table(png_ptr); +#endif - if (end_info_ptr != NULL) - png_info_destroy(png_ptr, end_info_ptr); - - png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->big_row_buf); - png_free(png_ptr, png_ptr->prev_row); - png_free(png_ptr, png_ptr->chunkdata); + png_ptr->big_row_buf = NULL; + png_free(png_ptr, png_ptr->big_prev_row); + png_ptr->big_prev_row = NULL; + png_free(png_ptr, png_ptr->read_buffer); + png_ptr->read_buffer = NULL; #ifdef PNG_READ_QUANTIZE_SUPPORTED png_free(png_ptr, png_ptr->palette_lookup); + png_ptr->palette_lookup = NULL; png_free(png_ptr, png_ptr->quantize_index); + png_ptr->quantize_index = NULL; #endif -#ifdef PNG_READ_GAMMA_SUPPORTED - png_free(png_ptr, png_ptr->gamma_table); -#endif - -#ifdef PNG_READ_BACKGROUND_SUPPORTED - png_free(png_ptr, png_ptr->gamma_from_1); - png_free(png_ptr, png_ptr->gamma_to_1); -#endif - - if (png_ptr->free_me & PNG_FREE_PLTE) + if ((png_ptr->free_me & PNG_FREE_PLTE) != 0) + { png_zfree(png_ptr, png_ptr->palette); + png_ptr->palette = NULL; + } png_ptr->free_me &= ~PNG_FREE_PLTE; #if defined(PNG_tRNS_SUPPORTED) || \ defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - if (png_ptr->free_me & PNG_FREE_TRNS) + if ((png_ptr->free_me & PNG_FREE_TRNS) != 0) + { png_free(png_ptr, png_ptr->trans_alpha); + png_ptr->trans_alpha = NULL; + } png_ptr->free_me &= ~PNG_FREE_TRNS; #endif -#ifdef PNG_READ_hIST_SUPPORTED - if (png_ptr->free_me & PNG_FREE_HIST) - png_free(png_ptr, png_ptr->hist); - png_ptr->free_me &= ~PNG_FREE_HIST; -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED - if (png_ptr->gamma_16_table != NULL) - { - int i; - int istop = (1 << (8 - png_ptr->gamma_shift)); - for (i = 0; i < istop; i++) - { - png_free(png_ptr, png_ptr->gamma_16_table[i]); - } - png_free(png_ptr, png_ptr->gamma_16_table); - } - -#ifdef PNG_READ_BACKGROUND_SUPPORTED - if (png_ptr->gamma_16_from_1 != NULL) - { - int i; - int istop = (1 << (8 - png_ptr->gamma_shift)); - for (i = 0; i < istop; i++) - { - png_free(png_ptr, png_ptr->gamma_16_from_1[i]); - } - png_free(png_ptr, png_ptr->gamma_16_from_1); - } - if (png_ptr->gamma_16_to_1 != NULL) - { - int i; - int istop = (1 << (8 - png_ptr->gamma_shift)); - for (i = 0; i < istop; i++) - { - png_free(png_ptr, png_ptr->gamma_16_to_1[i]); - } - png_free(png_ptr, png_ptr->gamma_16_to_1); - } -#endif -#endif - inflateEnd(&png_ptr->zstream); #ifdef PNG_PROGRESSIVE_READ_SUPPORTED png_free(png_ptr, png_ptr->save_buffer); + png_ptr->save_buffer = NULL; #endif -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -#ifdef PNG_TEXT_SUPPORTED - png_free(png_ptr, png_ptr->current_text); -#endif /* PNG_TEXT_SUPPORTED */ -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ +#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) && \ + defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; +#endif - /* Save the important info out of the png_struct, in case it is - * being used again. +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list = NULL; +#endif + + /* NOTE: the 'setjmp' buffer may still be allocated and the memory and error + * callbacks are still set at this point. They are required to complete the + * destruction of the png_struct itself. */ -#ifdef PNG_SETJMP_SUPPORTED - png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); -#endif +} - error_fn = png_ptr->error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - warning_fn = png_ptr->warning_fn; -#endif - error_ptr = png_ptr->error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - free_fn = png_ptr->free_fn; -#endif +/* Free all memory used by the read */ +void PNGAPI +png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, + png_infopp end_info_ptr_ptr) +{ + png_structrp png_ptr = NULL; - png_memset(png_ptr, 0, png_sizeof(png_struct)); + png_debug(1, "in png_destroy_read_struct"); - png_ptr->error_fn = error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - png_ptr->warning_fn = warning_fn; -#endif - png_ptr->error_ptr = error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - png_ptr->free_fn = free_fn; -#endif + if (png_ptr_ptr != NULL) + png_ptr = *png_ptr_ptr; -#ifdef PNG_SETJMP_SUPPORTED - png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf)); -#endif + if (png_ptr == NULL) + return; + /* libpng 1.6.0: use the API to destroy info structs to ensure consistent + * behavior. Prior to 1.6.0 libpng did extra 'info' destruction in this API. + * The extra was, apparently, unnecessary yet this hides memory leak bugs. + */ + png_destroy_info_struct(png_ptr, end_info_ptr_ptr); + png_destroy_info_struct(png_ptr, info_ptr_ptr); + + *png_ptr_ptr = NULL; + png_read_destroy(png_ptr); + png_destroy_png_struct(png_ptr); } void PNGAPI -png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) +png_set_read_status_fn(png_structrp png_ptr, png_read_status_ptr read_row_fn) { if (png_ptr == NULL) return; @@ -1296,12 +1048,10 @@ png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) #ifdef PNG_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_INFO_IMAGE_SUPPORTED void PNGAPI -png_read_png(png_structp png_ptr, png_infop info_ptr, +png_read_png(png_structrp png_ptr, png_inforp info_ptr, int transforms, voidp params) { - int row; - if (png_ptr == NULL || info_ptr == NULL) return; @@ -1309,130 +1059,153 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, * PNG file before the first IDAT (image data chunk). */ png_read_info(png_ptr, info_ptr); - if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) + if (info_ptr->height > PNG_UINT_32_MAX/(sizeof (png_bytep))) png_error(png_ptr, "Image is too high to process with png_read_png()"); /* -------------- image transformations start here ------------------- */ + /* libpng 1.6.10: add code to cause a png_app_error if a selected TRANSFORM + * is not implemented. This will only happen in de-configured (non-default) + * libpng builds. The results can be unexpected - png_read_png may return + * short or mal-formed rows because the transform is skipped. + */ -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED /* Tell libpng to strip 16-bit/color files down to 8 bits per color. */ - if (transforms & PNG_TRANSFORM_SCALE_16) - { + if ((transforms & PNG_TRANSFORM_SCALE_16) != 0) /* Added at libpng-1.5.4. "strip_16" produces the same result that it * did in earlier versions, while "scale_16" is now more accurate. */ +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED png_set_scale_16(png_ptr); - } +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SCALE_16 not supported"); #endif -#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED /* If both SCALE and STRIP are required pngrtran will effectively cancel the * latter by doing SCALE first. This is ok and allows apps not to check for * which is supported to get the right answer. */ - if (transforms & PNG_TRANSFORM_STRIP_16) + if ((transforms & PNG_TRANSFORM_STRIP_16) != 0) +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED png_set_strip_16(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_16 not supported"); #endif -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED /* Strip alpha bytes from the input data without combining with * the background (not recommended). */ - if (transforms & PNG_TRANSFORM_STRIP_ALPHA) + if ((transforms & PNG_TRANSFORM_STRIP_ALPHA) != 0) +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED png_set_strip_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_ALPHA not supported"); #endif -#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single * byte into separate bytes (useful for paletted and grayscale images). */ - if (transforms & PNG_TRANSFORM_PACKING) + if ((transforms & PNG_TRANSFORM_PACKING) != 0) +#ifdef PNG_READ_PACK_SUPPORTED png_set_packing(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported"); #endif -#ifdef PNG_READ_PACKSWAP_SUPPORTED /* Change the order of packed pixels to least significant bit first * (not useful if you are using png_set_packing). */ - if (transforms & PNG_TRANSFORM_PACKSWAP) + if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0) +#ifdef PNG_READ_PACKSWAP_SUPPORTED png_set_packswap(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported"); #endif -#ifdef PNG_READ_EXPAND_SUPPORTED /* Expand paletted colors into true RGB triplets * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel * Expand paletted or RGB images with transparency to full alpha * channels so the data will be available as RGBA quartets. */ - if (transforms & PNG_TRANSFORM_EXPAND) - if ((png_ptr->bit_depth < 8) || - (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || - (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) - png_set_expand(png_ptr); + if ((transforms & PNG_TRANSFORM_EXPAND) != 0) +#ifdef PNG_READ_EXPAND_SUPPORTED + png_set_expand(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND not supported"); #endif /* We don't handle background color or gamma transformation or quantizing. */ -#ifdef PNG_READ_INVERT_SUPPORTED /* Invert monochrome files to have 0 as white and 1 as black */ - if (transforms & PNG_TRANSFORM_INVERT_MONO) + if ((transforms & PNG_TRANSFORM_INVERT_MONO) != 0) +#ifdef PNG_READ_INVERT_SUPPORTED png_set_invert_mono(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported"); #endif -#ifdef PNG_READ_SHIFT_SUPPORTED /* If you want to shift the pixel values from the range [0,255] or * [0,65535] to the original [0,7] or [0,31], or whatever range the * colors were originally in: */ - if ((transforms & PNG_TRANSFORM_SHIFT) - && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) - { - png_color_8p sig_bit; - - png_get_sBIT(png_ptr, info_ptr, &sig_bit); - png_set_shift(png_ptr, sig_bit); - } + if ((transforms & PNG_TRANSFORM_SHIFT) != 0) +#ifdef PNG_READ_SHIFT_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sBIT) != 0) + png_set_shift(png_ptr, &info_ptr->sig_bit); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported"); #endif -#ifdef PNG_READ_BGR_SUPPORTED /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ - if (transforms & PNG_TRANSFORM_BGR) + if ((transforms & PNG_TRANSFORM_BGR) != 0) +#ifdef PNG_READ_BGR_SUPPORTED png_set_bgr(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported"); #endif -#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */ - if (transforms & PNG_TRANSFORM_SWAP_ALPHA) + if ((transforms & PNG_TRANSFORM_SWAP_ALPHA) != 0) +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED png_set_swap_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported"); #endif -#ifdef PNG_READ_SWAP_SUPPORTED /* Swap bytes of 16-bit files to least significant byte first */ - if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) + if ((transforms & PNG_TRANSFORM_SWAP_ENDIAN) != 0) +#ifdef PNG_READ_SWAP_SUPPORTED png_set_swap(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported"); #endif /* Added at libpng-1.2.41 */ -#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED /* Invert the alpha channel from opacity to transparency */ - if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + if ((transforms & PNG_TRANSFORM_INVERT_ALPHA) != 0) +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED png_set_invert_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported"); #endif /* Added at libpng-1.2.41 */ -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED /* Expand grayscale image to RGB */ - if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) + if ((transforms & PNG_TRANSFORM_GRAY_TO_RGB) != 0) +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED png_set_gray_to_rgb(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_GRAY_TO_RGB not supported"); #endif /* Added at libpng-1.5.4 */ + if ((transforms & PNG_TRANSFORM_EXPAND_16) != 0) #ifdef PNG_READ_EXPAND_16_SUPPORTED - if (transforms & PNG_TRANSFORM_EXPAND_16) png_set_expand_16(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND_16 not supported"); #endif /* We don't handle adding filler bytes */ @@ -1455,16 +1228,17 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, { png_uint_32 iptr; - info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, - info_ptr->height * png_sizeof(png_bytep)); + info_ptr->row_pointers = png_voidcast(png_bytepp, png_malloc(png_ptr, + info_ptr->height * (sizeof (png_bytep)))); + for (iptr=0; iptrheight; iptr++) info_ptr->row_pointers[iptr] = NULL; info_ptr->free_me |= PNG_FREE_ROWS; - for (row = 0; row < (int)info_ptr->height; row++) - info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, - png_get_rowbytes(png_ptr, info_ptr)); + for (iptr = 0; iptr < info_ptr->height; iptr++) + info_ptr->row_pointers[iptr] = png_voidcast(png_bytep, + png_malloc(png_ptr, info_ptr->rowbytes)); } png_read_image(png_ptr, info_ptr->row_pointers); @@ -1473,10 +1247,2903 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ png_read_end(png_ptr, info_ptr); - PNG_UNUSED(transforms) /* Quiet compiler warnings */ PNG_UNUSED(params) - } -#endif /* PNG_INFO_IMAGE_SUPPORTED */ -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ -#endif /* PNG_READ_SUPPORTED */ +#endif /* INFO_IMAGE */ +#endif /* SEQUENTIAL_READ */ + +#ifdef PNG_SIMPLIFIED_READ_SUPPORTED +/* SIMPLIFIED READ + * + * This code currently relies on the sequential reader, though it could easily + * be made to work with the progressive one. + */ +/* Arguments to png_image_finish_read: */ + +/* Encoding of PNG data (used by the color-map code) */ +# define P_NOTSET 0 /* File encoding not yet known */ +# define P_sRGB 1 /* 8-bit encoded to sRGB gamma */ +# define P_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */ +# define P_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */ +# define P_LINEAR8 4 /* 8-bit linear: only from a file value */ + +/* Color-map processing: after libpng has run on the PNG image further + * processing may be needed to convert the data to color-map indices. + */ +#define PNG_CMAP_NONE 0 +#define PNG_CMAP_GA 1 /* Process GA data to a color-map with alpha */ +#define PNG_CMAP_TRANS 2 /* Process GA data to a background index */ +#define PNG_CMAP_RGB 3 /* Process RGB data */ +#define PNG_CMAP_RGB_ALPHA 4 /* Process RGBA data */ + +/* The following document where the background is for each processing case. */ +#define PNG_CMAP_NONE_BACKGROUND 256 +#define PNG_CMAP_GA_BACKGROUND 231 +#define PNG_CMAP_TRANS_BACKGROUND 254 +#define PNG_CMAP_RGB_BACKGROUND 256 +#define PNG_CMAP_RGB_ALPHA_BACKGROUND 216 + +typedef struct +{ + /* Arguments: */ + png_imagep image; + png_voidp buffer; + png_int_32 row_stride; + png_voidp colormap; + png_const_colorp background; + /* Local variables: */ + png_voidp local_row; + png_voidp first_row; + ptrdiff_t row_bytes; /* step between rows */ + int file_encoding; /* E_ values above */ + png_fixed_point gamma_to_linear; /* For P_FILE, reciprocal of gamma */ + int colormap_processing; /* PNG_CMAP_ values above */ +} png_image_read_control; + +/* Do all the *safe* initialization - 'safe' means that png_error won't be + * called, so setting up the jmp_buf is not required. This means that anything + * called from here must *not* call png_malloc - it has to call png_malloc_warn + * instead so that control is returned safely back to this routine. + */ +static int +png_image_read_init(png_imagep image) +{ + if (image->opaque == NULL) + { + png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, image, + png_safe_error, png_safe_warning); + + /* And set the rest of the structure to NULL to ensure that the various + * fields are consistent. + */ + memset(image, 0, (sizeof *image)); + image->version = PNG_IMAGE_VERSION; + + if (png_ptr != NULL) + { + png_infop info_ptr = png_create_info_struct(png_ptr); + + if (info_ptr != NULL) + { + png_controlp control = png_voidcast(png_controlp, + png_malloc_warn(png_ptr, (sizeof *control))); + + if (control != NULL) + { + memset(control, 0, (sizeof *control)); + + control->png_ptr = png_ptr; + control->info_ptr = info_ptr; + control->for_write = 0; + + image->opaque = control; + return 1; + } + + /* Error clean up */ + png_destroy_info_struct(png_ptr, &info_ptr); + } + + png_destroy_read_struct(&png_ptr, NULL, NULL); + } + + return png_image_error(image, "png_image_read: out of memory"); + } + + return png_image_error(image, "png_image_read: opaque pointer not NULL"); +} + +/* Utility to find the base format of a PNG file from a png_struct. */ +static png_uint_32 +png_image_format(png_structrp png_ptr) +{ + png_uint_32 format = 0; + + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) + format |= PNG_FORMAT_FLAG_COLOR; + + if ((png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) + format |= PNG_FORMAT_FLAG_ALPHA; + + /* Use png_ptr here, not info_ptr, because by examination png_handle_tRNS + * sets the png_struct fields; that's all we are interested in here. The + * precise interaction with an app call to png_set_tRNS and PNG file reading + * is unclear. + */ + else if (png_ptr->num_trans > 0) + format |= PNG_FORMAT_FLAG_ALPHA; + + if (png_ptr->bit_depth == 16) + format |= PNG_FORMAT_FLAG_LINEAR; + + if ((png_ptr->color_type & PNG_COLOR_MASK_PALETTE) != 0) + format |= PNG_FORMAT_FLAG_COLORMAP; + + return format; +} + +/* Is the given gamma significantly different from sRGB? The test is the same + * one used in pngrtran.c when deciding whether to do gamma correction. The + * arithmetic optimizes the division by using the fact that the inverse of the + * file sRGB gamma is 2.2 + */ +static int +png_gamma_not_sRGB(png_fixed_point g) +{ + if (g < PNG_FP_1) + { + /* An uninitialized gamma is assumed to be sRGB for the simplified API. */ + if (g == 0) + return 0; + + return png_gamma_significant((g * 11 + 2)/5 /* i.e. *2.2, rounded */); + } + + return 1; +} + +/* Do the main body of a 'png_image_begin_read' function; read the PNG file + * header and fill in all the information. This is executed in a safe context, + * unlike the init routine above. + */ +static int +png_image_read_header(png_voidp argument) +{ + png_imagep image = png_voidcast(png_imagep, argument); + png_structrp png_ptr = image->opaque->png_ptr; + png_inforp info_ptr = image->opaque->info_ptr; + + png_set_benign_errors(png_ptr, 1/*warn*/); + png_read_info(png_ptr, info_ptr); + + /* Do this the fast way; just read directly out of png_struct. */ + image->width = png_ptr->width; + image->height = png_ptr->height; + + { + png_uint_32 format = png_image_format(png_ptr); + + image->format = format; + +#ifdef PNG_COLORSPACE_SUPPORTED + /* Does the colorspace match sRGB? If there is no color endpoint + * (colorant) information assume yes, otherwise require the + * 'ENDPOINTS_MATCHP_sRGB' colorspace flag to have been set. If the + * colorspace has been determined to be invalid ignore it. + */ + if ((format & PNG_FORMAT_FLAG_COLOR) != 0 && ((png_ptr->colorspace.flags + & (PNG_COLORSPACE_HAVE_ENDPOINTS|PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB| + PNG_COLORSPACE_INVALID)) == PNG_COLORSPACE_HAVE_ENDPOINTS)) + image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB; +#endif + } + + /* We need the maximum number of entries regardless of the format the + * application sets here. + */ + { + png_uint_32 cmap_entries; + + switch (png_ptr->color_type) + { + case PNG_COLOR_TYPE_GRAY: + cmap_entries = 1U << png_ptr->bit_depth; + break; + + case PNG_COLOR_TYPE_PALETTE: + cmap_entries = png_ptr->num_palette; + break; + + default: + cmap_entries = 256; + break; + } + + if (cmap_entries > 256) + cmap_entries = 256; + + image->colormap_entries = cmap_entries; + } + + return 1; +} + +#ifdef PNG_STDIO_SUPPORTED +int PNGAPI +png_image_begin_read_from_stdio(png_imagep image, FILE* file) +{ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (file != NULL) + { + if (png_image_read_init(image) != 0) + { + /* This is slightly evil, but png_init_io doesn't do anything other + * than this and we haven't changed the standard IO functions so + * this saves a 'safe' function. + */ + image->opaque->png_ptr->io_ptr = file; + return png_safe_execute(image, png_image_read_header, image); + } + } + + else + return png_image_error(image, + "png_image_begin_read_from_stdio: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION"); + + return 0; +} + +int PNGAPI +png_image_begin_read_from_file(png_imagep image, const char *file_name) +{ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (file_name != NULL) + { + FILE *fp = fopen(file_name, "rb"); + + if (fp != NULL) + { + if (png_image_read_init(image) != 0) + { + image->opaque->png_ptr->io_ptr = fp; + image->opaque->owned_file = 1; + return png_safe_execute(image, png_image_read_header, image); + } + + /* Clean up: just the opened file. */ + (void)fclose(fp); + } + + else + return png_image_error(image, strerror(errno)); + } + + else + return png_image_error(image, + "png_image_begin_read_from_file: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION"); + + return 0; +} +#endif /* STDIO */ + +static void PNGCBAPI +png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need) +{ + if (png_ptr != NULL) + { + png_imagep image = png_voidcast(png_imagep, png_ptr->io_ptr); + if (image != NULL) + { + png_controlp cp = image->opaque; + if (cp != NULL) + { + png_const_bytep memory = cp->memory; + png_size_t size = cp->size; + + if (memory != NULL && size >= need) + { + memcpy(out, memory, need); + cp->memory = memory + need; + cp->size = size - need; + return; + } + + png_error(png_ptr, "read beyond end of data"); + } + } + + png_error(png_ptr, "invalid memory read"); + } +} + +int PNGAPI png_image_begin_read_from_memory(png_imagep image, + png_const_voidp memory, png_size_t size) +{ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (memory != NULL && size > 0) + { + if (png_image_read_init(image) != 0) + { + /* Now set the IO functions to read from the memory buffer and + * store it into io_ptr. Again do this in-place to avoid calling a + * libpng function that requires error handling. + */ + image->opaque->memory = png_voidcast(png_const_bytep, memory); + image->opaque->size = size; + image->opaque->png_ptr->io_ptr = image; + image->opaque->png_ptr->read_data_fn = png_image_memory_read; + + return png_safe_execute(image, png_image_read_header, image); + } + } + + else + return png_image_error(image, + "png_image_begin_read_from_memory: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION"); + + return 0; +} + +/* Utility function to skip chunks that are not used by the simplified image + * read functions and an appropriate macro to call it. + */ +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +static void +png_image_skip_unused_chunks(png_structrp png_ptr) +{ + /* Prepare the reader to ignore all recognized chunks whose data will not + * be used, i.e., all chunks recognized by libpng except for those + * involved in basic image reading: + * + * IHDR, PLTE, IDAT, IEND + * + * Or image data handling: + * + * tRNS, bKGD, gAMA, cHRM, sRGB, [iCCP] and sBIT. + * + * This provides a small performance improvement and eliminates any + * potential vulnerability to security problems in the unused chunks. + * + * At present the iCCP chunk data isn't used, so iCCP chunk can be ignored + * too. This allows the simplified API to be compiled without iCCP support, + * however if the support is there the chunk is still checked to detect + * errors (which are unfortunately quite common.) + */ + { + static PNG_CONST png_byte chunks_to_process[] = { + 98, 75, 71, 68, '\0', /* bKGD */ + 99, 72, 82, 77, '\0', /* cHRM */ + 103, 65, 77, 65, '\0', /* gAMA */ +# ifdef PNG_READ_iCCP_SUPPORTED + 105, 67, 67, 80, '\0', /* iCCP */ +# endif + 115, 66, 73, 84, '\0', /* sBIT */ + 115, 82, 71, 66, '\0', /* sRGB */ + }; + + /* Ignore unknown chunks and all other chunks except for the + * IHDR, PLTE, tRNS, IDAT, and IEND chunks. + */ + png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_NEVER, + NULL, -1); + + /* But do not ignore image data handling chunks */ + png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_AS_DEFAULT, + chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5); + } +} + +# define PNG_SKIP_CHUNKS(p) png_image_skip_unused_chunks(p) +#else +# define PNG_SKIP_CHUNKS(p) ((void)0) +#endif /* HANDLE_AS_UNKNOWN */ + +/* The following macro gives the exact rounded answer for all values in the + * range 0..255 (it actually divides by 51.2, but the rounding still generates + * the correct numbers 0..5 + */ +#define PNG_DIV51(v8) (((v8) * 5 + 130) >> 8) + +/* Utility functions to make particular color-maps */ +static void +set_file_encoding(png_image_read_control *display) +{ + png_fixed_point g = display->image->opaque->png_ptr->colorspace.gamma; + if (png_gamma_significant(g) != 0) + { + if (png_gamma_not_sRGB(g) != 0) + { + display->file_encoding = P_FILE; + display->gamma_to_linear = png_reciprocal(g); + } + + else + display->file_encoding = P_sRGB; + } + + else + display->file_encoding = P_LINEAR8; +} + +static unsigned int +decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding) +{ + if (encoding == P_FILE) /* double check */ + encoding = display->file_encoding; + + if (encoding == P_NOTSET) /* must be the file encoding */ + { + set_file_encoding(display); + encoding = display->file_encoding; + } + + switch (encoding) + { + case P_FILE: + value = png_gamma_16bit_correct(value*257, display->gamma_to_linear); + break; + + case P_sRGB: + value = png_sRGB_table[value]; + break; + + case P_LINEAR: + break; + + case P_LINEAR8: + value *= 257; + break; + + default: + png_error(display->image->opaque->png_ptr, + "unexpected encoding (internal error)"); + break; + } + + return value; +} + +static png_uint_32 +png_colormap_compose(png_image_read_control *display, + png_uint_32 foreground, int foreground_encoding, png_uint_32 alpha, + png_uint_32 background, int encoding) +{ + /* The file value is composed on the background, the background has the given + * encoding and so does the result, the file is encoded with P_FILE and the + * file and alpha are 8-bit values. The (output) encoding will always be + * P_LINEAR or P_sRGB. + */ + png_uint_32 f = decode_gamma(display, foreground, foreground_encoding); + png_uint_32 b = decode_gamma(display, background, encoding); + + /* The alpha is always an 8-bit value (it comes from the palette), the value + * scaled by 255 is what PNG_sRGB_FROM_LINEAR requires. + */ + f = f * alpha + b * (255-alpha); + + if (encoding == P_LINEAR) + { + /* Scale to 65535; divide by 255, approximately (in fact this is extremely + * accurate, it divides by 255.00000005937181414556, with no overflow.) + */ + f *= 257; /* Now scaled by 65535 */ + f += f >> 16; + f = (f+32768) >> 16; + } + + else /* P_sRGB */ + f = PNG_sRGB_FROM_LINEAR(f); + + return f; +} + +/* NOTE: P_LINEAR values to this routine must be 16-bit, but P_FILE values must + * be 8-bit. + */ +static void +png_create_colormap_entry(png_image_read_control *display, + png_uint_32 ip, png_uint_32 red, png_uint_32 green, png_uint_32 blue, + png_uint_32 alpha, int encoding) +{ + png_imagep image = display->image; + const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) != 0 ? + P_LINEAR : P_sRGB; + const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 && + (red != green || green != blue); + + if (ip > 255) + png_error(image->opaque->png_ptr, "color-map index out of range"); + + /* Update the cache with whether the file gamma is significantly different + * from sRGB. + */ + if (encoding == P_FILE) + { + if (display->file_encoding == P_NOTSET) + set_file_encoding(display); + + /* Note that the cached value may be P_FILE too, but if it is then the + * gamma_to_linear member has been set. + */ + encoding = display->file_encoding; + } + + if (encoding == P_FILE) + { + png_fixed_point g = display->gamma_to_linear; + + red = png_gamma_16bit_correct(red*257, g); + green = png_gamma_16bit_correct(green*257, g); + blue = png_gamma_16bit_correct(blue*257, g); + + if (convert_to_Y != 0 || output_encoding == P_LINEAR) + { + alpha *= 257; + encoding = P_LINEAR; + } + + else + { + red = PNG_sRGB_FROM_LINEAR(red * 255); + green = PNG_sRGB_FROM_LINEAR(green * 255); + blue = PNG_sRGB_FROM_LINEAR(blue * 255); + encoding = P_sRGB; + } + } + + else if (encoding == P_LINEAR8) + { + /* This encoding occurs quite frequently in test cases because PngSuite + * includes a gAMA 1.0 chunk with most images. + */ + red *= 257; + green *= 257; + blue *= 257; + alpha *= 257; + encoding = P_LINEAR; + } + + else if (encoding == P_sRGB && + (convert_to_Y != 0 || output_encoding == P_LINEAR)) + { + /* The values are 8-bit sRGB values, but must be converted to 16-bit + * linear. + */ + red = png_sRGB_table[red]; + green = png_sRGB_table[green]; + blue = png_sRGB_table[blue]; + alpha *= 257; + encoding = P_LINEAR; + } + + /* This is set if the color isn't gray but the output is. */ + if (encoding == P_LINEAR) + { + if (convert_to_Y != 0) + { + /* NOTE: these values are copied from png_do_rgb_to_gray */ + png_uint_32 y = (png_uint_32)6968 * red + (png_uint_32)23434 * green + + (png_uint_32)2366 * blue; + + if (output_encoding == P_LINEAR) + y = (y + 16384) >> 15; + + else + { + /* y is scaled by 32768, we need it scaled by 255: */ + y = (y + 128) >> 8; + y *= 255; + y = PNG_sRGB_FROM_LINEAR((y + 64) >> 7); + encoding = P_sRGB; + } + + blue = red = green = y; + } + + else if (output_encoding == P_sRGB) + { + red = PNG_sRGB_FROM_LINEAR(red * 255); + green = PNG_sRGB_FROM_LINEAR(green * 255); + blue = PNG_sRGB_FROM_LINEAR(blue * 255); + alpha = PNG_DIV257(alpha); + encoding = P_sRGB; + } + } + + if (encoding != output_encoding) + png_error(image->opaque->png_ptr, "bad encoding (internal error)"); + + /* Store the value. */ + { +# ifdef PNG_FORMAT_AFIRST_SUPPORTED + const int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 && + (image->format & PNG_FORMAT_FLAG_ALPHA) != 0; +# else +# define afirst 0 +# endif +# ifdef PNG_FORMAT_BGR_SUPPORTED + const int bgr = (image->format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0; +# else +# define bgr 0 +# endif + + if (output_encoding == P_LINEAR) + { + png_uint_16p entry = png_voidcast(png_uint_16p, display->colormap); + + entry += ip * PNG_IMAGE_SAMPLE_CHANNELS(image->format); + + /* The linear 16-bit values must be pre-multiplied by the alpha channel + * value, if less than 65535 (this is, effectively, composite on black + * if the alpha channel is removed.) + */ + switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format)) + { + case 4: + entry[afirst ? 0 : 3] = (png_uint_16)alpha; + /* FALL THROUGH */ + + case 3: + if (alpha < 65535) + { + if (alpha > 0) + { + blue = (blue * alpha + 32767U)/65535U; + green = (green * alpha + 32767U)/65535U; + red = (red * alpha + 32767U)/65535U; + } + + else + red = green = blue = 0; + } + entry[afirst + (2 ^ bgr)] = (png_uint_16)blue; + entry[afirst + 1] = (png_uint_16)green; + entry[afirst + bgr] = (png_uint_16)red; + break; + + case 2: + entry[1 ^ afirst] = (png_uint_16)alpha; + /* FALL THROUGH */ + + case 1: + if (alpha < 65535) + { + if (alpha > 0) + green = (green * alpha + 32767U)/65535U; + + else + green = 0; + } + entry[afirst] = (png_uint_16)green; + break; + + default: + break; + } + } + + else /* output encoding is P_sRGB */ + { + png_bytep entry = png_voidcast(png_bytep, display->colormap); + + entry += ip * PNG_IMAGE_SAMPLE_CHANNELS(image->format); + + switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format)) + { + case 4: + entry[afirst ? 0 : 3] = (png_byte)alpha; + case 3: + entry[afirst + (2 ^ bgr)] = (png_byte)blue; + entry[afirst + 1] = (png_byte)green; + entry[afirst + bgr] = (png_byte)red; + break; + + case 2: + entry[1 ^ afirst] = (png_byte)alpha; + case 1: + entry[afirst] = (png_byte)green; + break; + + default: + break; + } + } + +# ifdef afirst +# undef afirst +# endif +# ifdef bgr +# undef bgr +# endif + } +} + +static int +make_gray_file_colormap(png_image_read_control *display) +{ + unsigned int i; + + for (i=0; i<256; ++i) + png_create_colormap_entry(display, i, i, i, i, 255, P_FILE); + + return i; +} + +static int +make_gray_colormap(png_image_read_control *display) +{ + unsigned int i; + + for (i=0; i<256; ++i) + png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB); + + return i; +} +#define PNG_GRAY_COLORMAP_ENTRIES 256 + +static int +make_ga_colormap(png_image_read_control *display) +{ + unsigned int i, a; + + /* Alpha is retained, the output will be a color-map with entries + * selected by six levels of alpha. One transparent entry, 6 gray + * levels for all the intermediate alpha values, leaving 230 entries + * for the opaque grays. The color-map entries are the six values + * [0..5]*51, the GA processing uses PNG_DIV51(value) to find the + * relevant entry. + * + * if (alpha > 229) // opaque + * { + * // The 231 entries are selected to make the math below work: + * base = 0; + * entry = (231 * gray + 128) >> 8; + * } + * else if (alpha < 26) // transparent + * { + * base = 231; + * entry = 0; + * } + * else // partially opaque + * { + * base = 226 + 6 * PNG_DIV51(alpha); + * entry = PNG_DIV51(gray); + * } + */ + i = 0; + while (i < 231) + { + unsigned int gray = (i * 256 + 115) / 231; + png_create_colormap_entry(display, i++, gray, gray, gray, 255, P_sRGB); + } + + /* 255 is used here for the component values for consistency with the code + * that undoes premultiplication in pngwrite.c. + */ + png_create_colormap_entry(display, i++, 255, 255, 255, 0, P_sRGB); + + for (a=1; a<5; ++a) + { + unsigned int g; + + for (g=0; g<6; ++g) + png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51, + P_sRGB); + } + + return i; +} + +#define PNG_GA_COLORMAP_ENTRIES 256 + +static int +make_rgb_colormap(png_image_read_control *display) +{ + unsigned int i, r; + + /* Build a 6x6x6 opaque RGB cube */ + for (i=r=0; r<6; ++r) + { + unsigned int g; + + for (g=0; g<6; ++g) + { + unsigned int b; + + for (b=0; b<6; ++b) + png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255, + P_sRGB); + } + } + + return i; +} + +#define PNG_RGB_COLORMAP_ENTRIES 216 + +/* Return a palette index to the above palette given three 8-bit sRGB values. */ +#define PNG_RGB_INDEX(r,g,b) \ + ((png_byte)(6 * (6 * PNG_DIV51(r) + PNG_DIV51(g)) + PNG_DIV51(b))) + +static int +png_image_read_colormap(png_voidp argument) +{ + png_image_read_control *display = + png_voidcast(png_image_read_control*, argument); + const png_imagep image = display->image; + + const png_structrp png_ptr = image->opaque->png_ptr; + const png_uint_32 output_format = image->format; + const int output_encoding = (output_format & PNG_FORMAT_FLAG_LINEAR) != 0 ? + P_LINEAR : P_sRGB; + + unsigned int cmap_entries; + unsigned int output_processing; /* Output processing option */ + unsigned int data_encoding = P_NOTSET; /* Encoding libpng must produce */ + + /* Background information; the background color and the index of this color + * in the color-map if it exists (else 256). + */ + unsigned int background_index = 256; + png_uint_32 back_r, back_g, back_b; + + /* Flags to accumulate things that need to be done to the input. */ + int expand_tRNS = 0; + + /* Exclude the NYI feature of compositing onto a color-mapped buffer; it is + * very difficult to do, the results look awful, and it is difficult to see + * what possible use it is because the application can't control the + * color-map. + */ + if (((png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0 || + png_ptr->num_trans > 0) /* alpha in input */ && + ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0) /* no alpha in output */) + { + if (output_encoding == P_LINEAR) /* compose on black */ + back_b = back_g = back_r = 0; + + else if (display->background == NULL /* no way to remove it */) + png_error(png_ptr, + "a background color must be supplied to remove alpha/transparency"); + + /* Get a copy of the background color (this avoids repeating the checks + * below.) The encoding is 8-bit sRGB or 16-bit linear, depending on the + * output format. + */ + else + { + back_g = display->background->green; + if ((output_format & PNG_FORMAT_FLAG_COLOR) != 0) + { + back_r = display->background->red; + back_b = display->background->blue; + } + else + back_b = back_r = back_g; + } + } + + else if (output_encoding == P_LINEAR) + back_b = back_r = back_g = 65535; + + else + back_b = back_r = back_g = 255; + + /* Default the input file gamma if required - this is necessary because + * libpng assumes that if no gamma information is present the data is in the + * output format, but the simplified API deduces the gamma from the input + * format. + */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) == 0) + { + /* Do this directly, not using the png_colorspace functions, to ensure + * that it happens even if the colorspace is invalid (though probably if + * it is the setting will be ignored) Note that the same thing can be + * achieved at the application interface with png_set_gAMA. + */ + if (png_ptr->bit_depth == 16 && + (image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0) + png_ptr->colorspace.gamma = PNG_GAMMA_LINEAR; + + else + png_ptr->colorspace.gamma = PNG_GAMMA_sRGB_INVERSE; + + png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; + } + + /* Decide what to do based on the PNG color type of the input data. The + * utility function png_create_colormap_entry deals with most aspects of the + * output transformations; this code works out how to produce bytes of + * color-map entries from the original format. + */ + switch (png_ptr->color_type) + { + case PNG_COLOR_TYPE_GRAY: + if (png_ptr->bit_depth <= 8) + { + /* There at most 256 colors in the output, regardless of + * transparency. + */ + unsigned int step, i, val, trans = 256/*ignore*/, back_alpha = 0; + + cmap_entries = 1U << png_ptr->bit_depth; + if (cmap_entries > image->colormap_entries) + png_error(png_ptr, "gray[8] color-map: too few entries"); + + step = 255 / (cmap_entries - 1); + output_processing = PNG_CMAP_NONE; + + /* If there is a tRNS chunk then this either selects a transparent + * value or, if the output has no alpha, the background color. + */ + if (png_ptr->num_trans > 0) + { + trans = png_ptr->trans_color.gray; + + if ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0) + back_alpha = output_encoding == P_LINEAR ? 65535 : 255; + } + + /* png_create_colormap_entry just takes an RGBA and writes the + * corresponding color-map entry using the format from 'image', + * including the required conversion to sRGB or linear as + * appropriate. The input values are always either sRGB (if the + * gamma correction flag is 0) or 0..255 scaled file encoded values + * (if the function must gamma correct them). + */ + for (i=val=0; ibit_depth < 8) + png_set_packing(png_ptr); + } + + else /* bit depth is 16 */ + { + /* The 16-bit input values can be converted directly to 8-bit gamma + * encoded values; however, if a tRNS chunk is present 257 color-map + * entries are required. This means that the extra entry requires + * special processing; add an alpha channel, sacrifice gray level + * 254 and convert transparent (alpha==0) entries to that. + * + * Use libpng to chop the data to 8 bits. Convert it to sRGB at the + * same time to minimize quality loss. If a tRNS chunk is present + * this means libpng must handle it too; otherwise it is impossible + * to do the exact match on the 16-bit value. + * + * If the output has no alpha channel *and* the background color is + * gray then it is possible to let libpng handle the substitution by + * ensuring that the corresponding gray level matches the background + * color exactly. + */ + data_encoding = P_sRGB; + + if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "gray[16] color-map: too few entries"); + + cmap_entries = make_gray_colormap(display); + + if (png_ptr->num_trans > 0) + { + unsigned int back_alpha; + + if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0) + back_alpha = 0; + + else + { + if (back_r == back_g && back_g == back_b) + { + /* Background is gray; no special processing will be + * required. + */ + png_color_16 c; + png_uint_32 gray = back_g; + + if (output_encoding == P_LINEAR) + { + gray = PNG_sRGB_FROM_LINEAR(gray * 255); + + /* And make sure the corresponding palette entry + * matches. + */ + png_create_colormap_entry(display, gray, back_g, back_g, + back_g, 65535, P_LINEAR); + } + + /* The background passed to libpng, however, must be the + * sRGB value. + */ + c.index = 0; /*unused*/ + c.gray = c.red = c.green = c.blue = (png_uint_16)gray; + + /* NOTE: does this work without expanding tRNS to alpha? + * It should be the color->gray case below apparently + * doesn't. + */ + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + + output_processing = PNG_CMAP_NONE; + break; + } + + back_alpha = output_encoding == P_LINEAR ? 65535 : 255; + } + + /* output_processing means that the libpng-processed row will be + * 8-bit GA and it has to be processing to single byte color-map + * values. Entry 254 is replaced by either a completely + * transparent entry or by the background color at full + * precision (and the background color is not a simple gray + * level in this case.) + */ + expand_tRNS = 1; + output_processing = PNG_CMAP_TRANS; + background_index = 254; + + /* And set (overwrite) color-map entry 254 to the actual + * background color at full precision. + */ + png_create_colormap_entry(display, 254, back_r, back_g, back_b, + back_alpha, output_encoding); + } + + else + output_processing = PNG_CMAP_NONE; + } + break; + + case PNG_COLOR_TYPE_GRAY_ALPHA: + /* 8-bit or 16-bit PNG with two channels - gray and alpha. A minimum + * of 65536 combinations. If, however, the alpha channel is to be + * removed there are only 256 possibilities if the background is gray. + * (Otherwise there is a subset of the 65536 possibilities defined by + * the triangle between black, white and the background color.) + * + * Reduce 16-bit files to 8-bit and sRGB encode the result. No need to + * worry about tRNS matching - tRNS is ignored if there is an alpha + * channel. + */ + data_encoding = P_sRGB; + + if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "gray+alpha color-map: too few entries"); + + cmap_entries = make_ga_colormap(display); + + background_index = PNG_CMAP_GA_BACKGROUND; + output_processing = PNG_CMAP_GA; + } + + else /* alpha is removed */ + { + /* Alpha must be removed as the PNG data is processed when the + * background is a color because the G and A channels are + * independent and the vector addition (non-parallel vectors) is a + * 2-D problem. + * + * This can be reduced to the same algorithm as above by making a + * colormap containing gray levels (for the opaque grays), a + * background entry (for a transparent pixel) and a set of four six + * level color values, one set for each intermediate alpha value. + * See the comments in make_ga_colormap for how this works in the + * per-pixel processing. + * + * If the background is gray, however, we only need a 256 entry gray + * level color map. It is sufficient to make the entry generated + * for the background color be exactly the color specified. + */ + if ((output_format & PNG_FORMAT_FLAG_COLOR) == 0 || + (back_r == back_g && back_g == back_b)) + { + /* Background is gray; no special processing will be required. */ + png_color_16 c; + png_uint_32 gray = back_g; + + if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "gray-alpha color-map: too few entries"); + + cmap_entries = make_gray_colormap(display); + + if (output_encoding == P_LINEAR) + { + gray = PNG_sRGB_FROM_LINEAR(gray * 255); + + /* And make sure the corresponding palette entry matches. */ + png_create_colormap_entry(display, gray, back_g, back_g, + back_g, 65535, P_LINEAR); + } + + /* The background passed to libpng, however, must be the sRGB + * value. + */ + c.index = 0; /*unused*/ + c.gray = c.red = c.green = c.blue = (png_uint_16)gray; + + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + + output_processing = PNG_CMAP_NONE; + } + + else + { + png_uint_32 i, a; + + /* This is the same as png_make_ga_colormap, above, except that + * the entries are all opaque. + */ + if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "ga-alpha color-map: too few entries"); + + i = 0; + while (i < 231) + { + png_uint_32 gray = (i * 256 + 115) / 231; + png_create_colormap_entry(display, i++, gray, gray, gray, + 255, P_sRGB); + } + + /* NOTE: this preserves the full precision of the application + * background color. + */ + background_index = i; + png_create_colormap_entry(display, i++, back_r, back_g, back_b, + output_encoding == P_LINEAR ? 65535U : 255U, output_encoding); + + /* For non-opaque input composite on the sRGB background - this + * requires inverting the encoding for each component. The input + * is still converted to the sRGB encoding because this is a + * reasonable approximate to the logarithmic curve of human + * visual sensitivity, at least over the narrow range which PNG + * represents. Consequently 'G' is always sRGB encoded, while + * 'A' is linear. We need the linear background colors. + */ + if (output_encoding == P_sRGB) /* else already linear */ + { + /* This may produce a value not exactly matching the + * background, but that's ok because these numbers are only + * used when alpha != 0 + */ + back_r = png_sRGB_table[back_r]; + back_g = png_sRGB_table[back_g]; + back_b = png_sRGB_table[back_b]; + } + + for (a=1; a<5; ++a) + { + unsigned int g; + + /* PNG_sRGB_FROM_LINEAR expects a 16-bit linear value scaled + * by an 8-bit alpha value (0..255). + */ + png_uint_32 alpha = 51 * a; + png_uint_32 back_rx = (255-alpha) * back_r; + png_uint_32 back_gx = (255-alpha) * back_g; + png_uint_32 back_bx = (255-alpha) * back_b; + + for (g=0; g<6; ++g) + { + png_uint_32 gray = png_sRGB_table[g*51] * alpha; + + png_create_colormap_entry(display, i++, + PNG_sRGB_FROM_LINEAR(gray + back_rx), + PNG_sRGB_FROM_LINEAR(gray + back_gx), + PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB); + } + } + + cmap_entries = i; + output_processing = PNG_CMAP_GA; + } + } + break; + + case PNG_COLOR_TYPE_RGB: + case PNG_COLOR_TYPE_RGB_ALPHA: + /* Exclude the case where the output is gray; we can always handle this + * with the cases above. + */ + if ((output_format & PNG_FORMAT_FLAG_COLOR) == 0) + { + /* The color-map will be grayscale, so we may as well convert the + * input RGB values to a simple grayscale and use the grayscale + * code above. + * + * NOTE: calling this apparently damages the recognition of the + * transparent color in background color handling; call + * png_set_tRNS_to_alpha before png_set_background_fixed. + */ + png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1, + -1); + data_encoding = P_sRGB; + + /* The output will now be one or two 8-bit gray or gray+alpha + * channels. The more complex case arises when the input has alpha. + */ + if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + png_ptr->num_trans > 0) && + (output_format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + /* Both input and output have an alpha channel, so no background + * processing is required; just map the GA bytes to the right + * color-map entry. + */ + expand_tRNS = 1; + + if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "rgb[ga] color-map: too few entries"); + + cmap_entries = make_ga_colormap(display); + background_index = PNG_CMAP_GA_BACKGROUND; + output_processing = PNG_CMAP_GA; + } + + else + { + /* Either the input or the output has no alpha channel, so there + * will be no non-opaque pixels in the color-map; it will just be + * grayscale. + */ + if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "rgb[gray] color-map: too few entries"); + + /* Ideally this code would use libpng to do the gamma correction, + * but if an input alpha channel is to be removed we will hit the + * libpng bug in gamma+compose+rgb-to-gray (the double gamma + * correction bug). Fix this by dropping the gamma correction in + * this case and doing it in the palette; this will result in + * duplicate palette entries, but that's better than the + * alternative of double gamma correction. + */ + if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + png_ptr->num_trans > 0) && + png_gamma_not_sRGB(png_ptr->colorspace.gamma) != 0) + { + cmap_entries = make_gray_file_colormap(display); + data_encoding = P_FILE; + } + + else + cmap_entries = make_gray_colormap(display); + + /* But if the input has alpha or transparency it must be removed + */ + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + png_ptr->num_trans > 0) + { + png_color_16 c; + png_uint_32 gray = back_g; + + /* We need to ensure that the application background exists in + * the colormap and that completely transparent pixels map to + * it. Achieve this simply by ensuring that the entry + * selected for the background really is the background color. + */ + if (data_encoding == P_FILE) /* from the fixup above */ + { + /* The app supplied a gray which is in output_encoding, we + * need to convert it to a value of the input (P_FILE) + * encoding then set this palette entry to the required + * output encoding. + */ + if (output_encoding == P_sRGB) + gray = png_sRGB_table[gray]; /* now P_LINEAR */ + + gray = PNG_DIV257(png_gamma_16bit_correct(gray, + png_ptr->colorspace.gamma)); /* now P_FILE */ + + /* And make sure the corresponding palette entry contains + * exactly the required sRGB value. + */ + png_create_colormap_entry(display, gray, back_g, back_g, + back_g, 0/*unused*/, output_encoding); + } + + else if (output_encoding == P_LINEAR) + { + gray = PNG_sRGB_FROM_LINEAR(gray * 255); + + /* And make sure the corresponding palette entry matches. + */ + png_create_colormap_entry(display, gray, back_g, back_g, + back_g, 0/*unused*/, P_LINEAR); + } + + /* The background passed to libpng, however, must be the + * output (normally sRGB) value. + */ + c.index = 0; /*unused*/ + c.gray = c.red = c.green = c.blue = (png_uint_16)gray; + + /* NOTE: the following is apparently a bug in libpng. Without + * it the transparent color recognition in + * png_set_background_fixed seems to go wrong. + */ + expand_tRNS = 1; + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + } + + output_processing = PNG_CMAP_NONE; + } + } + + else /* output is color */ + { + /* We could use png_quantize here so long as there is no transparent + * color or alpha; png_quantize ignores alpha. Easier overall just + * to do it once and using PNG_DIV51 on the 6x6x6 reduced RGB cube. + * Consequently we always want libpng to produce sRGB data. + */ + data_encoding = P_sRGB; + + /* Is there any transparency or alpha? */ + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + png_ptr->num_trans > 0) + { + /* Is there alpha in the output too? If so all four channels are + * processed into a special RGB cube with alpha support. + */ + if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + png_uint_32 r; + + if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries) + png_error(png_ptr, "rgb+alpha color-map: too few entries"); + + cmap_entries = make_rgb_colormap(display); + + /* Add a transparent entry. */ + png_create_colormap_entry(display, cmap_entries, 255, 255, + 255, 0, P_sRGB); + + /* This is stored as the background index for the processing + * algorithm. + */ + background_index = cmap_entries++; + + /* Add 27 r,g,b entries each with alpha 0.5. */ + for (r=0; r<256; r = (r << 1) | 0x7f) + { + png_uint_32 g; + + for (g=0; g<256; g = (g << 1) | 0x7f) + { + png_uint_32 b; + + /* This generates components with the values 0, 127 and + * 255 + */ + for (b=0; b<256; b = (b << 1) | 0x7f) + png_create_colormap_entry(display, cmap_entries++, + r, g, b, 128, P_sRGB); + } + } + + expand_tRNS = 1; + output_processing = PNG_CMAP_RGB_ALPHA; + } + + else + { + /* Alpha/transparency must be removed. The background must + * exist in the color map (achieved by setting adding it after + * the 666 color-map). If the standard processing code will + * pick up this entry automatically that's all that is + * required; libpng can be called to do the background + * processing. + */ + unsigned int sample_size = + PNG_IMAGE_SAMPLE_SIZE(output_format); + png_uint_32 r, g, b; /* sRGB background */ + + if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries) + png_error(png_ptr, "rgb-alpha color-map: too few entries"); + + cmap_entries = make_rgb_colormap(display); + + png_create_colormap_entry(display, cmap_entries, back_r, + back_g, back_b, 0/*unused*/, output_encoding); + + if (output_encoding == P_LINEAR) + { + r = PNG_sRGB_FROM_LINEAR(back_r * 255); + g = PNG_sRGB_FROM_LINEAR(back_g * 255); + b = PNG_sRGB_FROM_LINEAR(back_b * 255); + } + + else + { + r = back_r; + g = back_g; + b = back_g; + } + + /* Compare the newly-created color-map entry with the one the + * PNG_CMAP_RGB algorithm will use. If the two entries don't + * match, add the new one and set this as the background + * index. + */ + if (memcmp((png_const_bytep)display->colormap + + sample_size * cmap_entries, + (png_const_bytep)display->colormap + + sample_size * PNG_RGB_INDEX(r,g,b), + sample_size) != 0) + { + /* The background color must be added. */ + background_index = cmap_entries++; + + /* Add 27 r,g,b entries each with created by composing with + * the background at alpha 0.5. + */ + for (r=0; r<256; r = (r << 1) | 0x7f) + { + for (g=0; g<256; g = (g << 1) | 0x7f) + { + /* This generates components with the values 0, 127 + * and 255 + */ + for (b=0; b<256; b = (b << 1) | 0x7f) + png_create_colormap_entry(display, cmap_entries++, + png_colormap_compose(display, r, P_sRGB, 128, + back_r, output_encoding), + png_colormap_compose(display, g, P_sRGB, 128, + back_g, output_encoding), + png_colormap_compose(display, b, P_sRGB, 128, + back_b, output_encoding), + 0/*unused*/, output_encoding); + } + } + + expand_tRNS = 1; + output_processing = PNG_CMAP_RGB_ALPHA; + } + + else /* background color is in the standard color-map */ + { + png_color_16 c; + + c.index = 0; /*unused*/ + c.red = (png_uint_16)back_r; + c.gray = c.green = (png_uint_16)back_g; + c.blue = (png_uint_16)back_b; + + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + + output_processing = PNG_CMAP_RGB; + } + } + } + + else /* no alpha or transparency in the input */ + { + /* Alpha in the output is irrelevant, simply map the opaque input + * pixels to the 6x6x6 color-map. + */ + if (PNG_RGB_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "rgb color-map: too few entries"); + + cmap_entries = make_rgb_colormap(display); + output_processing = PNG_CMAP_RGB; + } + } + break; + + case PNG_COLOR_TYPE_PALETTE: + /* It's already got a color-map. It may be necessary to eliminate the + * tRNS entries though. + */ + { + unsigned int num_trans = png_ptr->num_trans; + png_const_bytep trans = num_trans > 0 ? png_ptr->trans_alpha : NULL; + png_const_colorp colormap = png_ptr->palette; + const int do_background = trans != NULL && + (output_format & PNG_FORMAT_FLAG_ALPHA) == 0; + unsigned int i; + + /* Just in case: */ + if (trans == NULL) + num_trans = 0; + + output_processing = PNG_CMAP_NONE; + data_encoding = P_FILE; /* Don't change from color-map indices */ + cmap_entries = png_ptr->num_palette; + if (cmap_entries > 256) + cmap_entries = 256; + + if (cmap_entries > image->colormap_entries) + png_error(png_ptr, "palette color-map: too few entries"); + + for (i=0; i < cmap_entries; ++i) + { + if (do_background != 0 && i < num_trans && trans[i] < 255) + { + if (trans[i] == 0) + png_create_colormap_entry(display, i, back_r, back_g, + back_b, 0, output_encoding); + + else + { + /* Must compose the PNG file color in the color-map entry + * on the sRGB color in 'back'. + */ + png_create_colormap_entry(display, i, + png_colormap_compose(display, colormap[i].red, P_FILE, + trans[i], back_r, output_encoding), + png_colormap_compose(display, colormap[i].green, P_FILE, + trans[i], back_g, output_encoding), + png_colormap_compose(display, colormap[i].blue, P_FILE, + trans[i], back_b, output_encoding), + output_encoding == P_LINEAR ? trans[i] * 257U : + trans[i], + output_encoding); + } + } + + else + png_create_colormap_entry(display, i, colormap[i].red, + colormap[i].green, colormap[i].blue, + i < num_trans ? trans[i] : 255U, P_FILE/*8-bit*/); + } + + /* The PNG data may have indices packed in fewer than 8 bits, it + * must be expanded if so. + */ + if (png_ptr->bit_depth < 8) + png_set_packing(png_ptr); + } + break; + + default: + png_error(png_ptr, "invalid PNG color type"); + /*NOT REACHED*/ + break; + } + + /* Now deal with the output processing */ + if (expand_tRNS != 0 && png_ptr->num_trans > 0 && + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) == 0) + png_set_tRNS_to_alpha(png_ptr); + + switch (data_encoding) + { + default: + png_error(png_ptr, "bad data option (internal error)"); + break; + + case P_sRGB: + /* Change to 8-bit sRGB */ + png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB); + /* FALL THROUGH */ + + case P_FILE: + if (png_ptr->bit_depth > 8) + png_set_scale_16(png_ptr); + break; + } + + if (cmap_entries > 256 || cmap_entries > image->colormap_entries) + png_error(png_ptr, "color map overflow (BAD internal error)"); + + image->colormap_entries = cmap_entries; + + /* Double check using the recorded background index */ + switch (output_processing) + { + case PNG_CMAP_NONE: + if (background_index != PNG_CMAP_NONE_BACKGROUND) + goto bad_background; + break; + + case PNG_CMAP_GA: + if (background_index != PNG_CMAP_GA_BACKGROUND) + goto bad_background; + break; + + case PNG_CMAP_TRANS: + if (background_index >= cmap_entries || + background_index != PNG_CMAP_TRANS_BACKGROUND) + goto bad_background; + break; + + case PNG_CMAP_RGB: + if (background_index != PNG_CMAP_RGB_BACKGROUND) + goto bad_background; + break; + + case PNG_CMAP_RGB_ALPHA: + if (background_index != PNG_CMAP_RGB_ALPHA_BACKGROUND) + goto bad_background; + break; + + default: + png_error(png_ptr, "bad processing option (internal error)"); + + bad_background: + png_error(png_ptr, "bad background index (internal error)"); + } + + display->colormap_processing = output_processing; + + return 1/*ok*/; +} + +/* The final part of the color-map read called from png_image_finish_read. */ +static int +png_image_read_and_map(png_voidp argument) +{ + png_image_read_control *display = png_voidcast(png_image_read_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + int passes; + + /* Called when the libpng data must be transformed into the color-mapped + * form. There is a local row buffer in display->local and this routine must + * do the interlace handling. + */ + switch (png_ptr->interlaced) + { + case PNG_INTERLACE_NONE: + passes = 1; + break; + + case PNG_INTERLACE_ADAM7: + passes = PNG_INTERLACE_ADAM7_PASSES; + break; + + default: + png_error(png_ptr, "unknown interlace type"); + } + + { + png_uint_32 height = image->height; + png_uint_32 width = image->width; + int proc = display->colormap_processing; + png_bytep first_row = png_voidcast(png_bytep, display->first_row); + ptrdiff_t step_row = display->row_bytes; + int pass; + + for (pass = 0; pass < passes; ++pass) + { + unsigned int startx, stepx, stepy; + png_uint_32 y; + + if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) + { + /* The row may be empty for a short image: */ + if (PNG_PASS_COLS(width, pass) == 0) + continue; + + startx = PNG_PASS_START_COL(pass); + stepx = PNG_PASS_COL_OFFSET(pass); + y = PNG_PASS_START_ROW(pass); + stepy = PNG_PASS_ROW_OFFSET(pass); + } + + else + { + y = 0; + startx = 0; + stepx = stepy = 1; + } + + for (; ylocal_row); + png_bytep outrow = first_row + y * step_row; + png_const_bytep end_row = outrow + width; + + /* Read read the libpng data into the temporary buffer. */ + png_read_row(png_ptr, inrow, NULL); + + /* Now process the row according to the processing option, note + * that the caller verifies that the format of the libpng output + * data is as required. + */ + outrow += startx; + switch (proc) + { + case PNG_CMAP_GA: + for (; outrow < end_row; outrow += stepx) + { + /* The data is always in the PNG order */ + unsigned int gray = *inrow++; + unsigned int alpha = *inrow++; + unsigned int entry; + + /* NOTE: this code is copied as a comment in + * make_ga_colormap above. Please update the + * comment if you change this code! + */ + if (alpha > 229) /* opaque */ + { + entry = (231 * gray + 128) >> 8; + } + else if (alpha < 26) /* transparent */ + { + entry = 231; + } + else /* partially opaque */ + { + entry = 226 + 6 * PNG_DIV51(alpha) + PNG_DIV51(gray); + } + + *outrow = (png_byte)entry; + } + break; + + case PNG_CMAP_TRANS: + for (; outrow < end_row; outrow += stepx) + { + png_byte gray = *inrow++; + png_byte alpha = *inrow++; + + if (alpha == 0) + *outrow = PNG_CMAP_TRANS_BACKGROUND; + + else if (gray != PNG_CMAP_TRANS_BACKGROUND) + *outrow = gray; + + else + *outrow = (png_byte)(PNG_CMAP_TRANS_BACKGROUND+1); + } + break; + + case PNG_CMAP_RGB: + for (; outrow < end_row; outrow += stepx) + { + *outrow = PNG_RGB_INDEX(inrow[0], inrow[1], inrow[2]); + inrow += 3; + } + break; + + case PNG_CMAP_RGB_ALPHA: + for (; outrow < end_row; outrow += stepx) + { + unsigned int alpha = inrow[3]; + + /* Because the alpha entries only hold alpha==0.5 values + * split the processing at alpha==0.25 (64) and 0.75 + * (196). + */ + + if (alpha >= 196) + *outrow = PNG_RGB_INDEX(inrow[0], inrow[1], + inrow[2]); + + else if (alpha < 64) + *outrow = PNG_CMAP_RGB_ALPHA_BACKGROUND; + + else + { + /* Likewise there are three entries for each of r, g + * and b. We could select the entry by popcount on + * the top two bits on those architectures that + * support it, this is what the code below does, + * crudely. + */ + unsigned int back_i = PNG_CMAP_RGB_ALPHA_BACKGROUND+1; + + /* Here are how the values map: + * + * 0x00 .. 0x3f -> 0 + * 0x40 .. 0xbf -> 1 + * 0xc0 .. 0xff -> 2 + * + * So, as above with the explicit alpha checks, the + * breakpoints are at 64 and 196. + */ + if (inrow[0] & 0x80) back_i += 9; /* red */ + if (inrow[0] & 0x40) back_i += 9; + if (inrow[0] & 0x80) back_i += 3; /* green */ + if (inrow[0] & 0x40) back_i += 3; + if (inrow[0] & 0x80) back_i += 1; /* blue */ + if (inrow[0] & 0x40) back_i += 1; + + *outrow = (png_byte)back_i; + } + + inrow += 4; + } + break; + + default: + break; + } + } + } + } + + return 1; +} + +static int +png_image_read_colormapped(png_voidp argument) +{ + png_image_read_control *display = png_voidcast(png_image_read_control*, + argument); + png_imagep image = display->image; + png_controlp control = image->opaque; + png_structrp png_ptr = control->png_ptr; + png_inforp info_ptr = control->info_ptr; + + int passes = 0; /* As a flag */ + + PNG_SKIP_CHUNKS(png_ptr); + + /* Update the 'info' structure and make sure the result is as required; first + * make sure to turn on the interlace handling if it will be required + * (because it can't be turned on *after* the call to png_read_update_info!) + */ + if (display->colormap_processing == PNG_CMAP_NONE) + passes = png_set_interlace_handling(png_ptr); + + png_read_update_info(png_ptr, info_ptr); + + /* The expected output can be deduced from the colormap_processing option. */ + switch (display->colormap_processing) + { + case PNG_CMAP_NONE: + /* Output must be one channel and one byte per pixel, the output + * encoding can be anything. + */ + if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE || + info_ptr->color_type == PNG_COLOR_TYPE_GRAY) && + info_ptr->bit_depth == 8) + break; + + goto bad_output; + + case PNG_CMAP_TRANS: + case PNG_CMAP_GA: + /* Output must be two channels and the 'G' one must be sRGB, the latter + * can be checked with an exact number because it should have been set + * to this number above! + */ + if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + info_ptr->bit_depth == 8 && + png_ptr->screen_gamma == PNG_GAMMA_sRGB && + image->colormap_entries == 256) + break; + + goto bad_output; + + case PNG_CMAP_RGB: + /* Output must be 8-bit sRGB encoded RGB */ + if (info_ptr->color_type == PNG_COLOR_TYPE_RGB && + info_ptr->bit_depth == 8 && + png_ptr->screen_gamma == PNG_GAMMA_sRGB && + image->colormap_entries == 216) + break; + + goto bad_output; + + case PNG_CMAP_RGB_ALPHA: + /* Output must be 8-bit sRGB encoded RGBA */ + if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA && + info_ptr->bit_depth == 8 && + png_ptr->screen_gamma == PNG_GAMMA_sRGB && + image->colormap_entries == 244 /* 216 + 1 + 27 */) + break; + + /* goto bad_output; */ + /* FALL THROUGH */ + + default: + bad_output: + png_error(png_ptr, "bad color-map processing (internal error)"); + } + + /* Now read the rows. Do this here if it is possible to read directly into + * the output buffer, otherwise allocate a local row buffer of the maximum + * size libpng requires and call the relevant processing routine safely. + */ + { + png_voidp first_row = display->buffer; + ptrdiff_t row_bytes = display->row_stride; + + /* The following expression is designed to work correctly whether it gives + * a signed or an unsigned result. + */ + if (row_bytes < 0) + { + char *ptr = png_voidcast(char*, first_row); + ptr += (image->height-1) * (-row_bytes); + first_row = png_voidcast(png_voidp, ptr); + } + + display->first_row = first_row; + display->row_bytes = row_bytes; + } + + if (passes == 0) + { + int result; + png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); + + display->local_row = row; + result = png_safe_execute(image, png_image_read_and_map, display); + display->local_row = NULL; + png_free(png_ptr, row); + + return result; + } + + else + { + png_alloc_size_t row_bytes = display->row_bytes; + + while (--passes >= 0) + { + png_uint_32 y = image->height; + png_bytep row = png_voidcast(png_bytep, display->first_row); + + while (y-- > 0) + { + png_read_row(png_ptr, row, NULL); + row += row_bytes; + } + } + + return 1; + } +} + +/* Just the row reading part of png_image_read. */ +static int +png_image_read_composite(png_voidp argument) +{ + png_image_read_control *display = png_voidcast(png_image_read_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + int passes; + + switch (png_ptr->interlaced) + { + case PNG_INTERLACE_NONE: + passes = 1; + break; + + case PNG_INTERLACE_ADAM7: + passes = PNG_INTERLACE_ADAM7_PASSES; + break; + + default: + png_error(png_ptr, "unknown interlace type"); + } + + { + png_uint_32 height = image->height; + png_uint_32 width = image->width; + ptrdiff_t step_row = display->row_bytes; + unsigned int channels = + (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1; + int pass; + + for (pass = 0; pass < passes; ++pass) + { + unsigned int startx, stepx, stepy; + png_uint_32 y; + + if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) + { + /* The row may be empty for a short image: */ + if (PNG_PASS_COLS(width, pass) == 0) + continue; + + startx = PNG_PASS_START_COL(pass) * channels; + stepx = PNG_PASS_COL_OFFSET(pass) * channels; + y = PNG_PASS_START_ROW(pass); + stepy = PNG_PASS_ROW_OFFSET(pass); + } + + else + { + y = 0; + startx = 0; + stepx = channels; + stepy = 1; + } + + for (; ylocal_row); + png_bytep outrow; + png_const_bytep end_row; + + /* Read the row, which is packed: */ + png_read_row(png_ptr, inrow, NULL); + + outrow = png_voidcast(png_bytep, display->first_row); + outrow += y * step_row; + end_row = outrow + width * channels; + + /* Now do the composition on each pixel in this row. */ + outrow += startx; + for (; outrow < end_row; outrow += stepx) + { + png_byte alpha = inrow[channels]; + + if (alpha > 0) /* else no change to the output */ + { + unsigned int c; + + for (c=0; cimage; + png_structrp png_ptr = image->opaque->png_ptr; + png_inforp info_ptr = image->opaque->info_ptr; + png_uint_32 height = image->height; + png_uint_32 width = image->width; + int pass, passes; + + /* Double check the convoluted logic below. We expect to get here with + * libpng doing rgb to gray and gamma correction but background processing + * left to the png_image_read_background function. The rows libpng produce + * might be 8 or 16-bit but should always have two channels; gray plus alpha. + */ + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == 0) + png_error(png_ptr, "lost rgb to gray"); + + if ((png_ptr->transformations & PNG_COMPOSE) != 0) + png_error(png_ptr, "unexpected compose"); + + if (png_get_channels(png_ptr, info_ptr) != 2) + png_error(png_ptr, "lost/gained channels"); + + /* Expect the 8-bit case to always remove the alpha channel */ + if ((image->format & PNG_FORMAT_FLAG_LINEAR) == 0 && + (image->format & PNG_FORMAT_FLAG_ALPHA) != 0) + png_error(png_ptr, "unexpected 8-bit transformation"); + + switch (png_ptr->interlaced) + { + case PNG_INTERLACE_NONE: + passes = 1; + break; + + case PNG_INTERLACE_ADAM7: + passes = PNG_INTERLACE_ADAM7_PASSES; + break; + + default: + png_error(png_ptr, "unknown interlace type"); + } + + /* Use direct access to info_ptr here because otherwise the simplified API + * would require PNG_EASY_ACCESS_SUPPORTED (just for this.) Note this is + * checking the value after libpng expansions, not the original value in the + * PNG. + */ + switch (info_ptr->bit_depth) + { + default: + png_error(png_ptr, "unexpected bit depth"); + break; + + case 8: + /* 8-bit sRGB gray values with an alpha channel; the alpha channel is + * to be removed by composing on a background: either the row if + * display->background is NULL or display->background->green if not. + * Unlike the code above ALPHA_OPTIMIZED has *not* been done. + */ + { + png_bytep first_row = png_voidcast(png_bytep, display->first_row); + ptrdiff_t step_row = display->row_bytes; + + for (pass = 0; pass < passes; ++pass) + { + png_bytep row = png_voidcast(png_bytep, + display->first_row); + unsigned int startx, stepx, stepy; + png_uint_32 y; + + if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) + { + /* The row may be empty for a short image: */ + if (PNG_PASS_COLS(width, pass) == 0) + continue; + + startx = PNG_PASS_START_COL(pass); + stepx = PNG_PASS_COL_OFFSET(pass); + y = PNG_PASS_START_ROW(pass); + stepy = PNG_PASS_ROW_OFFSET(pass); + } + + else + { + y = 0; + startx = 0; + stepx = stepy = 1; + } + + if (display->background == NULL) + { + for (; ylocal_row); + png_bytep outrow = first_row + y * step_row; + png_const_bytep end_row = outrow + width; + + /* Read the row, which is packed: */ + png_read_row(png_ptr, inrow, NULL); + + /* Now do the composition on each pixel in this row. */ + outrow += startx; + for (; outrow < end_row; outrow += stepx) + { + png_byte alpha = inrow[1]; + + if (alpha > 0) /* else no change to the output */ + { + png_uint_32 component = inrow[0]; + + if (alpha < 255) /* else just use component */ + { + /* Since PNG_OPTIMIZED_ALPHA was not set it is + * necessary to invert the sRGB transfer + * function and multiply the alpha out. + */ + component = png_sRGB_table[component] * alpha; + component += png_sRGB_table[outrow[0]] * + (255-alpha); + component = PNG_sRGB_FROM_LINEAR(component); + } + + outrow[0] = (png_byte)component; + } + + inrow += 2; /* gray and alpha channel */ + } + } + } + + else /* constant background value */ + { + png_byte background8 = display->background->green; + png_uint_16 background = png_sRGB_table[background8]; + + for (; ylocal_row); + png_bytep outrow = first_row + y * step_row; + png_const_bytep end_row = outrow + width; + + /* Read the row, which is packed: */ + png_read_row(png_ptr, inrow, NULL); + + /* Now do the composition on each pixel in this row. */ + outrow += startx; + for (; outrow < end_row; outrow += stepx) + { + png_byte alpha = inrow[1]; + + if (alpha > 0) /* else use background */ + { + png_uint_32 component = inrow[0]; + + if (alpha < 255) /* else just use component */ + { + component = png_sRGB_table[component] * alpha; + component += background * (255-alpha); + component = PNG_sRGB_FROM_LINEAR(component); + } + + outrow[0] = (png_byte)component; + } + + else + outrow[0] = background8; + + inrow += 2; /* gray and alpha channel */ + } + + row += display->row_bytes; + } + } + } + } + break; + + case 16: + /* 16-bit linear with pre-multiplied alpha; the pre-multiplication must + * still be done and, maybe, the alpha channel removed. This code also + * handles the alpha-first option. + */ + { + png_uint_16p first_row = png_voidcast(png_uint_16p, + display->first_row); + /* The division by two is safe because the caller passed in a + * stride which was multiplied by 2 (below) to get row_bytes. + */ + ptrdiff_t step_row = display->row_bytes / 2; + int preserve_alpha = (image->format & PNG_FORMAT_FLAG_ALPHA) != 0; + unsigned int outchannels = 1+preserve_alpha; + int swap_alpha = 0; + +# ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED + if (preserve_alpha != 0 && + (image->format & PNG_FORMAT_FLAG_AFIRST) != 0) + swap_alpha = 1; +# endif + + for (pass = 0; pass < passes; ++pass) + { + unsigned int startx, stepx, stepy; + png_uint_32 y; + + /* The 'x' start and step are adjusted to output components here. + */ + if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) + { + /* The row may be empty for a short image: */ + if (PNG_PASS_COLS(width, pass) == 0) + continue; + + startx = PNG_PASS_START_COL(pass) * outchannels; + stepx = PNG_PASS_COL_OFFSET(pass) * outchannels; + y = PNG_PASS_START_ROW(pass); + stepy = PNG_PASS_ROW_OFFSET(pass); + } + + else + { + y = 0; + startx = 0; + stepx = outchannels; + stepy = 1; + } + + for (; ylocal_row), NULL); + inrow = png_voidcast(png_const_uint_16p, display->local_row); + + /* Now do the pre-multiplication on each pixel in this row. + */ + outrow += startx; + for (; outrow < end_row; outrow += stepx) + { + png_uint_32 component = inrow[0]; + png_uint_16 alpha = inrow[1]; + + if (alpha > 0) /* else 0 */ + { + if (alpha < 65535) /* else just use component */ + { + component *= alpha; + component += 32767; + component /= 65535; + } + } + + else + component = 0; + + outrow[swap_alpha] = (png_uint_16)component; + if (preserve_alpha != 0) + outrow[1 ^ swap_alpha] = alpha; + + inrow += 2; /* components and alpha channel */ + } + } + } + } + break; + } + + return 1; +} + +/* The guts of png_image_finish_read as a png_safe_execute callback. */ +static int +png_image_read_direct(png_voidp argument) +{ + png_image_read_control *display = png_voidcast(png_image_read_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + png_inforp info_ptr = image->opaque->info_ptr; + + png_uint_32 format = image->format; + int linear = (format & PNG_FORMAT_FLAG_LINEAR) != 0; + int do_local_compose = 0; + int do_local_background = 0; /* to avoid double gamma correction bug */ + int passes = 0; + + /* Add transforms to ensure the correct output format is produced then check + * that the required implementation support is there. Always expand; always + * need 8 bits minimum, no palette and expanded tRNS. + */ + png_set_expand(png_ptr); + + /* Now check the format to see if it was modified. */ + { + png_uint_32 base_format = png_image_format(png_ptr) & + ~PNG_FORMAT_FLAG_COLORMAP /* removed by png_set_expand */; + png_uint_32 change = format ^ base_format; + png_fixed_point output_gamma; + int mode; /* alpha mode */ + + /* Do this first so that we have a record if rgb to gray is happening. */ + if ((change & PNG_FORMAT_FLAG_COLOR) != 0) + { + /* gray<->color transformation required. */ + if ((format & PNG_FORMAT_FLAG_COLOR) != 0) + png_set_gray_to_rgb(png_ptr); + + else + { + /* libpng can't do both rgb to gray and + * background/pre-multiplication if there is also significant gamma + * correction, because both operations require linear colors and + * the code only supports one transform doing the gamma correction. + * Handle this by doing the pre-multiplication or background + * operation in this code, if necessary. + * + * TODO: fix this by rewriting pngrtran.c (!) + * + * For the moment (given that fixing this in pngrtran.c is an + * enormous change) 'do_local_background' is used to indicate that + * the problem exists. + */ + if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0) + do_local_background = 1/*maybe*/; + + png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, + PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT); + } + + change &= ~PNG_FORMAT_FLAG_COLOR; + } + + /* Set the gamma appropriately, linear for 16-bit input, sRGB otherwise. + */ + { + png_fixed_point input_gamma_default; + + if ((base_format & PNG_FORMAT_FLAG_LINEAR) != 0 && + (image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0) + input_gamma_default = PNG_GAMMA_LINEAR; + else + input_gamma_default = PNG_DEFAULT_sRGB; + + /* Call png_set_alpha_mode to set the default for the input gamma; the + * output gamma is set by a second call below. + */ + png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, input_gamma_default); + } + + if (linear != 0) + { + /* If there *is* an alpha channel in the input it must be multiplied + * out; use PNG_ALPHA_STANDARD, otherwise just use PNG_ALPHA_PNG. + */ + if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0) + mode = PNG_ALPHA_STANDARD; /* associated alpha */ + + else + mode = PNG_ALPHA_PNG; + + output_gamma = PNG_GAMMA_LINEAR; + } + + else + { + mode = PNG_ALPHA_PNG; + output_gamma = PNG_DEFAULT_sRGB; + } + + /* If 'do_local_background' is set check for the presence of gamma + * correction; this is part of the work-round for the libpng bug + * described above. + * + * TODO: fix libpng and remove this. + */ + if (do_local_background != 0) + { + png_fixed_point gtest; + + /* This is 'png_gamma_threshold' from pngrtran.c; the test used for + * gamma correction, the screen gamma hasn't been set on png_struct + * yet; it's set below. png_struct::gamma, however, is set to the + * final value. + */ + if (png_muldiv(>est, output_gamma, png_ptr->colorspace.gamma, + PNG_FP_1) != 0 && png_gamma_significant(gtest) == 0) + do_local_background = 0; + + else if (mode == PNG_ALPHA_STANDARD) + { + do_local_background = 2/*required*/; + mode = PNG_ALPHA_PNG; /* prevent libpng doing it */ + } + + /* else leave as 1 for the checks below */ + } + + /* If the bit-depth changes then handle that here. */ + if ((change & PNG_FORMAT_FLAG_LINEAR) != 0) + { + if (linear != 0 /*16-bit output*/) + png_set_expand_16(png_ptr); + + else /* 8-bit output */ + png_set_scale_16(png_ptr); + + change &= ~PNG_FORMAT_FLAG_LINEAR; + } + + /* Now the background/alpha channel changes. */ + if ((change & PNG_FORMAT_FLAG_ALPHA) != 0) + { + /* Removing an alpha channel requires composition for the 8-bit + * formats; for the 16-bit it is already done, above, by the + * pre-multiplication and the channel just needs to be stripped. + */ + if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + /* If RGB->gray is happening the alpha channel must be left and the + * operation completed locally. + * + * TODO: fix libpng and remove this. + */ + if (do_local_background != 0) + do_local_background = 2/*required*/; + + /* 16-bit output: just remove the channel */ + else if (linear != 0) /* compose on black (well, pre-multiply) */ + png_set_strip_alpha(png_ptr); + + /* 8-bit output: do an appropriate compose */ + else if (display->background != NULL) + { + png_color_16 c; + + c.index = 0; /*unused*/ + c.red = display->background->red; + c.green = display->background->green; + c.blue = display->background->blue; + c.gray = display->background->green; + + /* This is always an 8-bit sRGB value, using the 'green' channel + * for gray is much better than calculating the luminance here; + * we can get off-by-one errors in that calculation relative to + * the app expectations and that will show up in transparent + * pixels. + */ + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + } + + else /* compose on row: implemented below. */ + { + do_local_compose = 1; + /* This leaves the alpha channel in the output, so it has to be + * removed by the code below. Set the encoding to the 'OPTIMIZE' + * one so the code only has to hack on the pixels that require + * composition. + */ + mode = PNG_ALPHA_OPTIMIZED; + } + } + + else /* output needs an alpha channel */ + { + /* This is tricky because it happens before the swap operation has + * been accomplished; however, the swap does *not* swap the added + * alpha channel (weird API), so it must be added in the correct + * place. + */ + png_uint_32 filler; /* opaque filler */ + int where; + + if (linear != 0) + filler = 65535; + + else + filler = 255; + +# ifdef PNG_FORMAT_AFIRST_SUPPORTED + if ((format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + where = PNG_FILLER_BEFORE; + change &= ~PNG_FORMAT_FLAG_AFIRST; + } + + else +# endif + where = PNG_FILLER_AFTER; + + png_set_add_alpha(png_ptr, filler, where); + } + + /* This stops the (irrelevant) call to swap_alpha below. */ + change &= ~PNG_FORMAT_FLAG_ALPHA; + } + + /* Now set the alpha mode correctly; this is always done, even if there is + * no alpha channel in either the input or the output because it correctly + * sets the output gamma. + */ + png_set_alpha_mode_fixed(png_ptr, mode, output_gamma); + +# ifdef PNG_FORMAT_BGR_SUPPORTED + if ((change & PNG_FORMAT_FLAG_BGR) != 0) + { + /* Check only the output format; PNG is never BGR; don't do this if + * the output is gray, but fix up the 'format' value in that case. + */ + if ((format & PNG_FORMAT_FLAG_COLOR) != 0) + png_set_bgr(png_ptr); + + else + format &= ~PNG_FORMAT_FLAG_BGR; + + change &= ~PNG_FORMAT_FLAG_BGR; + } +# endif + +# ifdef PNG_FORMAT_AFIRST_SUPPORTED + if ((change & PNG_FORMAT_FLAG_AFIRST) != 0) + { + /* Only relevant if there is an alpha channel - it's particularly + * important to handle this correctly because do_local_compose may + * be set above and then libpng will keep the alpha channel for this + * code to remove. + */ + if ((format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + /* Disable this if doing a local background, + * TODO: remove this when local background is no longer required. + */ + if (do_local_background != 2) + png_set_swap_alpha(png_ptr); + } + + else + format &= ~PNG_FORMAT_FLAG_AFIRST; + + change &= ~PNG_FORMAT_FLAG_AFIRST; + } +# endif + + /* If the *output* is 16-bit then we need to check for a byte-swap on this + * architecture. + */ + if (linear != 0) + { + PNG_CONST png_uint_16 le = 0x0001; + + if ((*(png_const_bytep) & le) != 0) + png_set_swap(png_ptr); + } + + /* If change is not now 0 some transformation is missing - error out. */ + if (change != 0) + png_error(png_ptr, "png_read_image: unsupported transformation"); + } + + PNG_SKIP_CHUNKS(png_ptr); + + /* Update the 'info' structure and make sure the result is as required; first + * make sure to turn on the interlace handling if it will be required + * (because it can't be turned on *after* the call to png_read_update_info!) + * + * TODO: remove the do_local_background fixup below. + */ + if (do_local_compose == 0 && do_local_background != 2) + passes = png_set_interlace_handling(png_ptr); + + png_read_update_info(png_ptr, info_ptr); + + { + png_uint_32 info_format = 0; + + if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) + info_format |= PNG_FORMAT_FLAG_COLOR; + + if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) + { + /* do_local_compose removes this channel below. */ + if (do_local_compose == 0) + { + /* do_local_background does the same if required. */ + if (do_local_background != 2 || + (format & PNG_FORMAT_FLAG_ALPHA) != 0) + info_format |= PNG_FORMAT_FLAG_ALPHA; + } + } + + else if (do_local_compose != 0) /* internal error */ + png_error(png_ptr, "png_image_read: alpha channel lost"); + + if (info_ptr->bit_depth == 16) + info_format |= PNG_FORMAT_FLAG_LINEAR; + +# ifdef PNG_FORMAT_BGR_SUPPORTED + if ((png_ptr->transformations & PNG_BGR) != 0) + info_format |= PNG_FORMAT_FLAG_BGR; +# endif + +# ifdef PNG_FORMAT_AFIRST_SUPPORTED + if (do_local_background == 2) + { + if ((format & PNG_FORMAT_FLAG_AFIRST) != 0) + info_format |= PNG_FORMAT_FLAG_AFIRST; + } + + if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0 || + ((png_ptr->transformations & PNG_ADD_ALPHA) != 0 && + (png_ptr->flags & PNG_FLAG_FILLER_AFTER) == 0)) + { + if (do_local_background == 2) + png_error(png_ptr, "unexpected alpha swap transformation"); + + info_format |= PNG_FORMAT_FLAG_AFIRST; + } +# endif + + /* This is actually an internal error. */ + if (info_format != format) + png_error(png_ptr, "png_read_image: invalid transformations"); + } + + /* Now read the rows. If do_local_compose is set then it is necessary to use + * a local row buffer. The output will be GA, RGBA or BGRA and must be + * converted to G, RGB or BGR as appropriate. The 'local_row' member of the + * display acts as a flag. + */ + { + png_voidp first_row = display->buffer; + ptrdiff_t row_bytes = display->row_stride; + + if (linear != 0) + row_bytes *= 2; + + /* The following expression is designed to work correctly whether it gives + * a signed or an unsigned result. + */ + if (row_bytes < 0) + { + char *ptr = png_voidcast(char*, first_row); + ptr += (image->height-1) * (-row_bytes); + first_row = png_voidcast(png_voidp, ptr); + } + + display->first_row = first_row; + display->row_bytes = row_bytes; + } + + if (do_local_compose != 0) + { + int result; + png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); + + display->local_row = row; + result = png_safe_execute(image, png_image_read_composite, display); + display->local_row = NULL; + png_free(png_ptr, row); + + return result; + } + + else if (do_local_background == 2) + { + int result; + png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); + + display->local_row = row; + result = png_safe_execute(image, png_image_read_background, display); + display->local_row = NULL; + png_free(png_ptr, row); + + return result; + } + + else + { + png_alloc_size_t row_bytes = display->row_bytes; + + while (--passes >= 0) + { + png_uint_32 y = image->height; + png_bytep row = png_voidcast(png_bytep, display->first_row); + + while (y-- > 0) + { + png_read_row(png_ptr, row, NULL); + row += row_bytes; + } + } + + return 1; + } +} + +int PNGAPI +png_image_finish_read(png_imagep image, png_const_colorp background, + void *buffer, png_int_32 row_stride, void *colormap) +{ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + png_uint_32 check; + + if (row_stride == 0) + row_stride = PNG_IMAGE_ROW_STRIDE(*image); + + if (row_stride < 0) + check = -row_stride; + + else + check = row_stride; + + if (image->opaque != NULL && buffer != NULL && + check >= PNG_IMAGE_ROW_STRIDE(*image)) + { + if ((image->format & PNG_FORMAT_FLAG_COLORMAP) == 0 || + (image->colormap_entries > 0 && colormap != NULL)) + { + int result; + png_image_read_control display; + + memset(&display, 0, (sizeof display)); + display.image = image; + display.buffer = buffer; + display.row_stride = row_stride; + display.colormap = colormap; + display.background = background; + display.local_row = NULL; + + /* Choose the correct 'end' routine; for the color-map case all the + * setup has already been done. + */ + if ((image->format & PNG_FORMAT_FLAG_COLORMAP) != 0) + result = + png_safe_execute(image, png_image_read_colormap, &display) && + png_safe_execute(image, png_image_read_colormapped, &display); + + else + result = + png_safe_execute(image, png_image_read_direct, &display); + + png_image_free(image); + return result; + } + + else + return png_image_error(image, + "png_image_finish_read[color-map]: no color-map"); + } + + else + return png_image_error(image, + "png_image_finish_read: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_finish_read: damaged PNG_IMAGE_VERSION"); + + return 0; +} + +#endif /* SIMPLIFIED_READ */ +#endif /* READ */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrio.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrio.c index f7529eaa5e4..debf6458ae1 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrio.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrio.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.0 [January 6, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -57,7 +57,7 @@ * to read more then 64K on a 16 bit machine. */ void /* PRIVATE */ -png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length) { png_debug1(4, "reading %d bytes", (int)length); @@ -74,7 +74,6 @@ png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) * read_data function and use it at run time with png_set_read_fn(), rather * than changing the library. */ -# ifndef USE_FAR_KEYWORD void PNGCBAPI png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { @@ -86,68 +85,11 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) /* fread() returns 0 on error, so it is OK to store this in a png_size_t * instead of an int, which is what fread() actually returns. */ - check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr); + check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr)); if (check != length) png_error(png_ptr, "Read Error"); } -# else -/* This is the model-independent version. Since the standard I/O library - can't handle far buffers in the medium and small models, we have to copy - the data. -*/ - -#define NEAR_BUF_SIZE 1024 -#define MIN(a,b) (a <= b ? a : b) - -static void PNGCBAPI -png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_size_t check; - png_byte *n_data; - png_FILE_p io_ptr; - - if (png_ptr == NULL) - return; - - /* Check if data really is near. If so, use usual code. */ - n_data = (png_byte *)CVT_PTR_NOCHECK(data); - io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); - - if ((png_bytep)n_data == data) - { - check = fread(n_data, 1, length, io_ptr); - } - - else - { - png_byte buf[NEAR_BUF_SIZE]; - png_size_t read, remaining, err; - check = 0; - remaining = length; - - do - { - read = MIN(NEAR_BUF_SIZE, remaining); - err = fread(buf, 1, read, io_ptr); - png_memcpy(data, buf, read); /* copy far buffer to near buffer */ - - if (err != read) - break; - - else - check += err; - - data += read; - remaining -= read; - } - while (remaining != 0); - } - - if ((png_uint_32)check != (png_uint_32)length) - png_error(png_ptr, "read Error"); -} -# endif #endif /* This function allows the application to supply a new input function @@ -170,7 +112,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) * be used. */ void PNGAPI -png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, +png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn) { if (png_ptr == NULL) @@ -188,6 +130,7 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, png_ptr->read_data_fn = read_data_fn; #endif +#ifdef PNG_WRITE_SUPPORTED /* It is an error to write to a read device */ if (png_ptr->write_data_fn != NULL) { @@ -196,9 +139,10 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, "Can't set both read_data_fn and write_data_fn in the" " same structure"); } +#endif #ifdef PNG_WRITE_FLUSH_SUPPORTED png_ptr->output_flush_fn = NULL; #endif } -#endif /* PNG_READ_SUPPORTED */ +#endif /* READ */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrtran.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrtran.c index 98d28140b6d..dc38d78d14d 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrtran.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrtran.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -50,7 +50,7 @@ /* Set the action on getting a CRC error for an ancillary or critical chunk. */ void PNGAPI -png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) +png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action) { png_debug(1, "in png_set_crc_action"); @@ -116,16 +116,47 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) } } +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +/* Is it OK to set a transformation now? Only if png_start_read_image or + * png_read_update_info have not been called. It is not necessary for the IHDR + * to have been read in all cases; the need_IHDR parameter allows for this + * check too. + */ +static int +png_rtran_ok(png_structrp png_ptr, int need_IHDR) +{ + if (png_ptr != NULL) + { + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0) + png_app_error(png_ptr, + "invalid after png_start_read_image or png_read_update_info"); + + else if (need_IHDR && (png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_app_error(png_ptr, "invalid before the PNG header has been read"); + + else + { + /* Turn on failure to initialize correctly for all transforms. */ + png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED; + + return 1; /* Ok */ + } + } + + return 0; /* no png_error possible! */ +} +#endif + #ifdef PNG_READ_BACKGROUND_SUPPORTED /* Handle alpha and tRNS via a background color */ void PNGFAPI -png_set_background_fixed(png_structp png_ptr, +png_set_background_fixed(png_structrp png_ptr, png_const_color_16p background_color, int background_gamma_code, int need_expand, png_fixed_point background_gamma) { png_debug(1, "in png_set_background_fixed"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0 || background_color == NULL) return; if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) @@ -138,11 +169,10 @@ png_set_background_fixed(png_structp png_ptr, png_ptr->transformations &= ~PNG_ENCODE_ALPHA; png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; - png_memcpy(&(png_ptr->background), background_color, - png_sizeof(png_color_16)); + png_ptr->background = *background_color; png_ptr->background_gamma = background_gamma; png_ptr->background_gamma_type = (png_byte)(background_gamma_code); - if (need_expand) + if (need_expand != 0) png_ptr->transformations |= PNG_BACKGROUND_EXPAND; else png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND; @@ -150,7 +180,7 @@ png_set_background_fixed(png_structp png_ptr, # ifdef PNG_FLOATING_POINT_SUPPORTED void PNGAPI -png_set_background(png_structp png_ptr, +png_set_background(png_structrp png_ptr, png_const_color_16p background_color, int background_gamma_code, int need_expand, double background_gamma) { @@ -166,11 +196,11 @@ png_set_background(png_structp png_ptr, */ #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED void PNGAPI -png_set_scale_16(png_structp png_ptr) +png_set_scale_16(png_structrp png_ptr) { png_debug(1, "in png_set_scale_16"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; png_ptr->transformations |= PNG_SCALE_16_TO_8; @@ -180,11 +210,11 @@ png_set_scale_16(png_structp png_ptr) #ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED /* Chop 16-bit depth files to 8-bit depth */ void PNGAPI -png_set_strip_16(png_structp png_ptr) +png_set_strip_16(png_structrp png_ptr) { png_debug(1, "in png_set_strip_16"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; png_ptr->transformations |= PNG_16_TO_8; @@ -193,11 +223,11 @@ png_set_strip_16(png_structp png_ptr) #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED void PNGAPI -png_set_strip_alpha(png_structp png_ptr) +png_set_strip_alpha(png_structrp png_ptr) { png_debug(1, "in png_set_strip_alpha"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; png_ptr->transformations |= PNG_STRIP_ALPHA; @@ -206,7 +236,7 @@ png_set_strip_alpha(png_structp png_ptr) #if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED) static png_fixed_point -translate_gamma_flags(png_structp png_ptr, png_fixed_point output_gamma, +translate_gamma_flags(png_structrp png_ptr, png_fixed_point output_gamma, int is_screen) { /* Check for flag values. The main reason for having the old Mac value as a @@ -222,8 +252,10 @@ translate_gamma_flags(png_structp png_ptr, png_fixed_point output_gamma, */ # ifdef PNG_READ_sRGB_SUPPORTED png_ptr->flags |= PNG_FLAG_ASSUME_sRGB; +# else + PNG_UNUSED(png_ptr) # endif - if (is_screen) + if (is_screen != 0) output_gamma = PNG_GAMMA_sRGB; else output_gamma = PNG_GAMMA_sRGB_INVERSE; @@ -232,7 +264,7 @@ translate_gamma_flags(png_structp png_ptr, png_fixed_point output_gamma, else if (output_gamma == PNG_GAMMA_MAC_18 || output_gamma == PNG_FP_1 / PNG_GAMMA_MAC_18) { - if (is_screen) + if (is_screen != 0) output_gamma = PNG_GAMMA_MAC_OLD; else output_gamma = PNG_GAMMA_MAC_INVERSE; @@ -243,7 +275,7 @@ translate_gamma_flags(png_structp png_ptr, png_fixed_point output_gamma, # ifdef PNG_FLOATING_POINT_SUPPORTED static png_fixed_point -convert_gamma_value(png_structp png_ptr, double output_gamma) +convert_gamma_value(png_structrp png_ptr, double output_gamma) { /* The following silently ignores cases where fixed point (times 100,000) * gamma values are passed to the floating point API. This is safe and it @@ -268,7 +300,7 @@ convert_gamma_value(png_structp png_ptr, double output_gamma) #ifdef PNG_READ_ALPHA_MODE_SUPPORTED void PNGFAPI -png_set_alpha_mode_fixed(png_structp png_ptr, int mode, +png_set_alpha_mode_fixed(png_structrp png_ptr, int mode, png_fixed_point output_gamma) { int compose = 0; @@ -276,7 +308,7 @@ png_set_alpha_mode_fixed(png_structp png_ptr, int mode, png_debug(1, "in png_set_alpha_mode"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/); @@ -348,8 +380,11 @@ png_set_alpha_mode_fixed(png_structp png_ptr, int mode, * the side effect that the gamma in a second call to png_set_alpha_mode will * be ignored.) */ - if (png_ptr->gamma == 0) - png_ptr->gamma = file_gamma; + if (png_ptr->colorspace.gamma == 0) + { + png_ptr->colorspace.gamma = file_gamma; + png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; + } /* But always set the output gamma: */ png_ptr->screen_gamma = output_gamma; @@ -357,28 +392,25 @@ png_set_alpha_mode_fixed(png_structp png_ptr, int mode, /* Finally, if pre-multiplying, set the background fields to achieve the * desired result. */ - if (compose) + if (compose != 0) { /* And obtain alpha pre-multiplication by composing on black: */ - png_memset(&png_ptr->background, 0, sizeof png_ptr->background); - png_ptr->background_gamma = png_ptr->gamma; /* just in case */ + memset(&png_ptr->background, 0, (sizeof png_ptr->background)); + png_ptr->background_gamma = png_ptr->colorspace.gamma; /* just in case */ png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE; png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND; - if (png_ptr->transformations & PNG_COMPOSE) + if ((png_ptr->transformations & PNG_COMPOSE) != 0) png_error(png_ptr, "conflicting calls to set alpha mode and background"); png_ptr->transformations |= PNG_COMPOSE; } - - /* New API, make sure apps call the correct initializers: */ - png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED; } # ifdef PNG_FLOATING_POINT_SUPPORTED void PNGAPI -png_set_alpha_mode(png_structp png_ptr, int mode, double output_gamma) +png_set_alpha_mode(png_structrp png_ptr, int mode, double output_gamma) { png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr, output_gamma)); @@ -398,31 +430,31 @@ png_set_alpha_mode(png_structp png_ptr, int mode, double output_gamma) typedef struct png_dsort_struct { - struct png_dsort_struct FAR * next; + struct png_dsort_struct * next; png_byte left; png_byte right; } png_dsort; -typedef png_dsort FAR * png_dsortp; -typedef png_dsort FAR * FAR * png_dsortpp; +typedef png_dsort * png_dsortp; +typedef png_dsort * * png_dsortpp; void PNGAPI -png_set_quantize(png_structp png_ptr, png_colorp palette, +png_set_quantize(png_structrp png_ptr, png_colorp palette, int num_palette, int maximum_colors, png_const_uint_16p histogram, int full_quantize) { png_debug(1, "in png_set_quantize"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; png_ptr->transformations |= PNG_QUANTIZE; - if (!full_quantize) + if (full_quantize == 0) { int i; png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(num_palette * png_sizeof(png_byte))); + (png_uint_32)(num_palette * (sizeof (png_byte)))); for (i = 0; i < num_palette; i++) png_ptr->quantize_index[i] = (png_byte)i; } @@ -439,7 +471,7 @@ png_set_quantize(png_structp png_ptr, png_colorp palette, /* Initialize an array to sort colors */ png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(num_palette * png_sizeof(png_byte))); + (png_uint_32)(num_palette * (sizeof (png_byte)))); /* Initialize the quantize_sort array */ for (i = 0; i < num_palette; i++) @@ -472,12 +504,12 @@ png_set_quantize(png_structp png_ptr, png_colorp palette, } } - if (done) + if (done != 0) break; } /* Swap the palette around, and set up a table, if necessary */ - if (full_quantize) + if (full_quantize != 0) { int j = num_palette; @@ -573,9 +605,9 @@ png_set_quantize(png_structp png_ptr, png_colorp palette, /* Initialize palette index arrays */ png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(num_palette * png_sizeof(png_byte))); + (png_uint_32)(num_palette * (sizeof (png_byte)))); png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(num_palette * png_sizeof(png_byte))); + (png_uint_32)(num_palette * (sizeof (png_byte)))); /* Initialize the sort array */ for (i = 0; i < num_palette; i++) @@ -585,7 +617,7 @@ png_set_quantize(png_structp png_ptr, png_colorp palette, } hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 * - png_sizeof(png_dsortp))); + (sizeof (png_dsortp)))); num_new_palette = num_palette; @@ -615,7 +647,7 @@ png_set_quantize(png_structp png_ptr, png_colorp palette, { t = (png_dsortp)png_malloc_warn(png_ptr, - (png_uint_32)(png_sizeof(png_dsort))); + (png_uint_32)(sizeof (png_dsort))); if (t == NULL) break; @@ -660,7 +692,7 @@ png_set_quantize(png_structp png_ptr, png_colorp palette, num_new_palette--; palette[png_ptr->index_to_palette[j]] = palette[num_new_palette]; - if (!full_quantize) + if (full_quantize == 0) { int k; @@ -728,7 +760,7 @@ png_set_quantize(png_structp png_ptr, png_colorp palette, } png_ptr->num_palette = (png_uint_16)num_palette; - if (full_quantize) + if (full_quantize != 0) { int i; png_bytep distance; @@ -740,12 +772,12 @@ png_set_quantize(png_structp png_ptr, png_colorp palette, png_size_t num_entries = ((png_size_t)1 << total_bits); png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr, - (png_uint_32)(num_entries * png_sizeof(png_byte))); + (png_uint_32)(num_entries * (sizeof (png_byte)))); distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * - png_sizeof(png_byte))); + (sizeof (png_byte)))); - png_memset(distance, 0xff, num_entries * png_sizeof(png_byte)); + memset(distance, 0xff, num_entries * (sizeof (png_byte))); for (i = 0; i < num_palette; i++) { @@ -790,23 +822,22 @@ png_set_quantize(png_structp png_ptr, png_colorp palette, png_free(png_ptr, distance); } } -#endif /* PNG_READ_QUANTIZE_SUPPORTED */ +#endif /* READ_QUANTIZE */ #ifdef PNG_READ_GAMMA_SUPPORTED void PNGFAPI -png_set_gamma_fixed(png_structp png_ptr, png_fixed_point scrn_gamma, +png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma, png_fixed_point file_gamma) { png_debug(1, "in png_set_gamma_fixed"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; /* New in libpng-1.5.4 - reserve particular negative values as flags. */ scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/); file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/); -#if PNG_LIBPNG_VER >= 10600 /* Checking the gamma values for being >0 was added in 1.5.4 along with the * premultiplied alpha support; this actually hides an undocumented feature * of the previous implementation which allowed gamma processing to be @@ -815,31 +846,32 @@ png_set_gamma_fixed(png_structp png_ptr, png_fixed_point scrn_gamma, * accept '0' for the gamma value it takes, because it isn't always used. * * Since this is an API change (albeit a very minor one that removes an - * undocumented API feature) it will not be made until libpng-1.6.0. + * undocumented API feature) the following checks were only enabled in + * libpng-1.6.0. */ if (file_gamma <= 0) png_error(png_ptr, "invalid file gamma in png_set_gamma"); if (scrn_gamma <= 0) png_error(png_ptr, "invalid screen gamma in png_set_gamma"); -#endif /* Set the gamma values unconditionally - this overrides the value in the PNG * file if a gAMA chunk was present. png_set_alpha_mode provides a * different, easier, way to default the file gamma. */ - png_ptr->gamma = file_gamma; + png_ptr->colorspace.gamma = file_gamma; + png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; png_ptr->screen_gamma = scrn_gamma; } # ifdef PNG_FLOATING_POINT_SUPPORTED void PNGAPI -png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) +png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma) { png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma), convert_gamma_value(png_ptr, file_gamma)); } -# endif /* FLOATING_POINT_SUPPORTED */ +# endif /* FLOATING_POINT */ #endif /* READ_GAMMA */ #ifdef PNG_READ_EXPAND_SUPPORTED @@ -848,15 +880,14 @@ png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) * to alpha channels. */ void PNGAPI -png_set_expand(png_structp png_ptr) +png_set_expand(png_structrp png_ptr) { png_debug(1, "in png_set_expand"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } /* GRR 19990627: the following three functions currently are identical @@ -879,100 +910,95 @@ png_set_expand(png_structp png_ptr) /* Expand paletted images to RGB. */ void PNGAPI -png_set_palette_to_rgb(png_structp png_ptr) +png_set_palette_to_rgb(png_structrp png_ptr) { png_debug(1, "in png_set_palette_to_rgb"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } /* Expand grayscale images of less than 8-bit depth to 8 bits. */ void PNGAPI -png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) +png_set_expand_gray_1_2_4_to_8(png_structrp png_ptr) { png_debug(1, "in png_set_expand_gray_1_2_4_to_8"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; png_ptr->transformations |= PNG_EXPAND; - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } - - /* Expand tRNS chunks to alpha channels. */ void PNGAPI -png_set_tRNS_to_alpha(png_structp png_ptr) +png_set_tRNS_to_alpha(png_structrp png_ptr) { png_debug(1, "in png_set_tRNS_to_alpha"); + if (png_rtran_ok(png_ptr, 0) == 0) + return; + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } -#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ +#endif /* READ_EXPAND */ #ifdef PNG_READ_EXPAND_16_SUPPORTED /* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise * it may not work correctly.) */ void PNGAPI -png_set_expand_16(png_structp png_ptr) +png_set_expand_16(png_structrp png_ptr) { png_debug(1, "in png_set_expand_16"); - if (png_ptr == NULL) + if (png_rtran_ok(png_ptr, 0) == 0) return; png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS); - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; - - /* New API, make sure apps call the correct initializers: */ - png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED; } #endif #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED void PNGAPI -png_set_gray_to_rgb(png_structp png_ptr) +png_set_gray_to_rgb(png_structrp png_ptr) { png_debug(1, "in png_set_gray_to_rgb"); - if (png_ptr != NULL) - { - /* Because rgb must be 8 bits or more: */ - png_set_expand_gray_1_2_4_to_8(png_ptr); - png_ptr->transformations |= PNG_GRAY_TO_RGB; - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; - } + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + /* Because rgb must be 8 bits or more: */ + png_set_expand_gray_1_2_4_to_8(png_ptr); + png_ptr->transformations |= PNG_GRAY_TO_RGB; } #endif #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED void PNGFAPI -png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, +png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action, png_fixed_point red, png_fixed_point green) { png_debug(1, "in png_set_rgb_to_gray"); - if (png_ptr == NULL) + /* Need the IHDR here because of the check on color_type below. */ + /* TODO: fix this */ + if (png_rtran_ok(png_ptr, 1) == 0) return; - switch(error_action) + switch (error_action) { - case 1: + case PNG_ERROR_ACTION_NONE: png_ptr->transformations |= PNG_RGB_TO_GRAY; break; - case 2: + case PNG_ERROR_ACTION_WARN: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; break; - case 3: + case PNG_ERROR_ACTION_ERROR: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; break; @@ -980,15 +1006,19 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, png_error(png_ptr, "invalid error action to rgb_to_gray"); break; } + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) #ifdef PNG_READ_EXPAND_SUPPORTED png_ptr->transformations |= PNG_EXPAND; #else { - png_warning(png_ptr, + /* Make this an error in 1.6 because otherwise the application may assume + * that it just worked and get a memory overwrite. + */ + png_error(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED"); - png_ptr->transformations &= ~PNG_RGB_TO_GRAY; + /* png_ptr->transformations &= ~PNG_RGB_TO_GRAY; */ } #endif { @@ -996,32 +1026,37 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, { png_uint_16 red_int, green_int; - red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L); - green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L); + /* NOTE: this calculation does not round, but this behavior is retained + * for consistency; the inaccuracy is very small. The code here always + * overwrites the coefficients, regardless of whether they have been + * defaulted or set already. + */ + red_int = (png_uint_16)(((png_uint_32)red*32768)/100000); + green_int = (png_uint_16)(((png_uint_32)green*32768)/100000); png_ptr->rgb_to_gray_red_coeff = red_int; png_ptr->rgb_to_gray_green_coeff = green_int; - png_ptr->rgb_to_gray_blue_coeff = - (png_uint_16)(32768 - red_int - green_int); + png_ptr->rgb_to_gray_coefficients_set = 1; } else { if (red >= 0 && green >= 0) - png_warning(png_ptr, + png_app_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients"); - /* Use the defaults, from the cHRM chunk if set, else the built in Rec - * 709 values (which correspond to sRGB, so we don't have to worry - * about the sRGB chunk!) + /* Use the defaults, from the cHRM chunk if set, else the historical + * values which are close to the sRGB/HDTV/ITU-Rec 709 values. See + * png_do_rgb_to_gray for more discussion of the values. In this case + * the coefficients are not marked as 'set' and are not overwritten if + * something has already provided a default. */ if (png_ptr->rgb_to_gray_red_coeff == 0 && - png_ptr->rgb_to_gray_green_coeff == 0 && - png_ptr->rgb_to_gray_blue_coeff == 0) + png_ptr->rgb_to_gray_green_coeff == 0) { - png_ptr->rgb_to_gray_red_coeff = 6968; /* .212671 * 32768 + .5 */ - png_ptr->rgb_to_gray_green_coeff = 23434; /* .715160 * 32768 + .5 */ - png_ptr->rgb_to_gray_blue_coeff = 2366; + png_ptr->rgb_to_gray_red_coeff = 6968; + png_ptr->rgb_to_gray_green_coeff = 23434; + /* png_ptr->rgb_to_gray_blue_coeff = 2366; */ } } } @@ -1033,31 +1068,25 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, */ void PNGAPI -png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, +png_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red, double green) { - if (png_ptr == NULL) - return; - png_set_rgb_to_gray_fixed(png_ptr, error_action, png_fixed(png_ptr, red, "rgb to gray red coefficient"), png_fixed(png_ptr, green, "rgb to gray green coefficient")); } #endif /* FLOATING POINT */ -#endif +#endif /* RGB_TO_GRAY */ #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) void PNGAPI -png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr +png_set_read_user_transform_fn(png_structrp png_ptr, png_user_transform_ptr read_user_transform_fn) { png_debug(1, "in png_set_read_user_transform_fn"); - if (png_ptr == NULL) - return; - #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED png_ptr->transformations |= PNG_USER_TRANSFORM; png_ptr->read_user_transform_fn = read_user_transform_fn; @@ -1091,13 +1120,13 @@ png_gamma_threshold(png_fixed_point screen_gamma, png_fixed_point file_gamma) * the palette. */ -/*For the moment 'png_init_palette_transformations' and +/* For the moment 'png_init_palette_transformations' and * 'png_init_rgb_transformations' only do some flag canceling optimizations. * The intent is that these two routines should have palette or rgb operations * extracted from 'png_init_read_transformations'. */ static void /* PRIVATE */ -png_init_palette_transformations(png_structp png_ptr) +png_init_palette_transformations(png_structrp png_ptr) { /* Called to handle the (input) palette case. In png_do_read_transformations * the first step is to expand the palette if requested, so this code must @@ -1116,25 +1145,31 @@ png_init_palette_transformations(png_structp png_ptr) /* Ignore if all the entries are opaque (unlikely!) */ for (i=0; inum_trans; ++i) + { if (png_ptr->trans_alpha[i] == 255) continue; else if (png_ptr->trans_alpha[i] == 0) input_has_transparency = 1; else + { + input_has_transparency = 1; input_has_alpha = 1; + break; + } + } } /* If no alpha we can optimize. */ - if (!input_has_alpha) + if (input_has_alpha == 0) { /* Any alpha means background and associative alpha processing is - * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA + * required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA * and ENCODE_ALPHA are irrelevant. */ png_ptr->transformations &= ~PNG_ENCODE_ALPHA; png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; - if (!input_has_transparency) + if (input_has_transparency == 0) png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND); } @@ -1147,8 +1182,8 @@ png_init_palette_transformations(png_structp png_ptr) /* The following code cannot be entered in the alpha pre-multiplication case * because PNG_BACKGROUND_EXPAND is cancelled below. */ - if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && - (png_ptr->transformations & PNG_EXPAND)) + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 && + (png_ptr->transformations & PNG_EXPAND) != 0) { { png_ptr->background.red = @@ -1159,9 +1194,9 @@ png_init_palette_transformations(png_structp png_ptr) png_ptr->palette[png_ptr->background.index].blue; #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_ALPHA) + if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0) { - if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) + if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0) { /* Invert the alpha channel (in tRNS) unless the pixels are * going to be expanded, in which case leave it for later @@ -1173,14 +1208,14 @@ png_init_palette_transformations(png_structp png_ptr) png_ptr->trans_alpha[i]); } } -#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED */ +#endif /* READ_INVERT_ALPHA */ } } /* background expand and (therefore) no alpha association. */ -#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */ +#endif /* READ_EXPAND && READ_BACKGROUND */ } static void /* PRIVATE */ -png_init_rgb_transformations(png_structp png_ptr) +png_init_rgb_transformations(png_structrp png_ptr) { /* Added to libpng-1.5.4: check the color type to determine whether there * is any alpha or transparency in the image and simply cancel the @@ -1190,10 +1225,10 @@ png_init_rgb_transformations(png_structp png_ptr) int input_has_transparency = png_ptr->num_trans > 0; /* If no alpha we can optimize. */ - if (!input_has_alpha) + if (input_has_alpha == 0) { /* Any alpha means background and associative alpha processing is - * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA + * required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA * and ENCODE_ALPHA are irrelevant. */ # ifdef PNG_READ_ALPHA_MODE_SUPPORTED @@ -1201,7 +1236,7 @@ png_init_rgb_transformations(png_structp png_ptr) png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; # endif - if (!input_has_transparency) + if (input_has_transparency == 0) png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND); } @@ -1214,67 +1249,58 @@ png_init_rgb_transformations(png_structp png_ptr) /* The following code cannot be entered in the alpha pre-multiplication case * because PNG_BACKGROUND_EXPAND is cancelled below. */ - if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && - (png_ptr->transformations & PNG_EXPAND) && - !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 && + (png_ptr->transformations & PNG_EXPAND) != 0 && + (png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* i.e., GRAY or GRAY_ALPHA */ { { /* Expand background and tRNS chunks */ + int gray = png_ptr->background.gray; + int trans_gray = png_ptr->trans_color.gray; + switch (png_ptr->bit_depth) { case 1: - png_ptr->background.gray *= (png_uint_16)0xff; - png_ptr->background.red = png_ptr->background.green - = png_ptr->background.blue = png_ptr->background.gray; - if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) - { - png_ptr->trans_color.gray *= (png_uint_16)0xff; - png_ptr->trans_color.red = png_ptr->trans_color.green - = png_ptr->trans_color.blue = png_ptr->trans_color.gray; - } + gray *= 0xff; + trans_gray *= 0xff; break; case 2: - png_ptr->background.gray *= (png_uint_16)0x55; - png_ptr->background.red = png_ptr->background.green - = png_ptr->background.blue = png_ptr->background.gray; - if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) - { - png_ptr->trans_color.gray *= (png_uint_16)0x55; - png_ptr->trans_color.red = png_ptr->trans_color.green - = png_ptr->trans_color.blue = png_ptr->trans_color.gray; - } + gray *= 0x55; + trans_gray *= 0x55; break; case 4: - png_ptr->background.gray *= (png_uint_16)0x11; - png_ptr->background.red = png_ptr->background.green - = png_ptr->background.blue = png_ptr->background.gray; - if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) - { - png_ptr->trans_color.gray *= (png_uint_16)0x11; - png_ptr->trans_color.red = png_ptr->trans_color.green - = png_ptr->trans_color.blue = png_ptr->trans_color.gray; - } + gray *= 0x11; + trans_gray *= 0x11; break; default: case 8: + /* FALL THROUGH (Already 8 bits) */ case 16: - png_ptr->background.red = png_ptr->background.green - = png_ptr->background.blue = png_ptr->background.gray; + /* Already a full 16 bits */ break; } + + png_ptr->background.red = png_ptr->background.green = + png_ptr->background.blue = (png_uint_16)gray; + + if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0) + { + png_ptr->trans_color.red = png_ptr->trans_color.green = + png_ptr->trans_color.blue = (png_uint_16)trans_gray; + } } } /* background expand and (therefore) no alpha association. */ -#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */ +#endif /* READ_EXPAND && READ_BACKGROUND */ } void /* PRIVATE */ -png_init_read_transformations(png_structp png_ptr) +png_init_read_transformations(png_structrp png_ptr) { png_debug(1, "in png_init_read_transformations"); @@ -1299,17 +1325,17 @@ png_init_read_transformations(png_structp png_ptr) */ int gamma_correction = 0; - if (png_ptr->gamma != 0) /* has been set */ + if (png_ptr->colorspace.gamma != 0) /* has been set */ { if (png_ptr->screen_gamma != 0) /* screen set too */ - gamma_correction = png_gamma_threshold(png_ptr->gamma, + gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma, png_ptr->screen_gamma); else /* Assume the output matches the input; a long time default behavior * of libpng, although the standard has nothing to say about this. */ - png_ptr->screen_gamma = png_reciprocal(png_ptr->gamma); + png_ptr->screen_gamma = png_reciprocal(png_ptr->colorspace.gamma); } else if (png_ptr->screen_gamma != 0) @@ -1318,7 +1344,7 @@ png_init_read_transformations(png_structp png_ptr) * png_set_alpha_mode (even if the alpha handling mode isn't required * or isn't changed from the default.) */ - png_ptr->gamma = png_reciprocal(png_ptr->screen_gamma); + png_ptr->colorspace.gamma = png_reciprocal(png_ptr->screen_gamma); else /* neither are set */ /* Just in case the following prevents any processing - file and screen @@ -1326,7 +1352,10 @@ png_init_read_transformations(png_structp png_ptr) * third gamma value other than png_set_background with 'UNIQUE', and, * prior to 1.5.4 */ - png_ptr->screen_gamma = png_ptr->gamma = PNG_FP_1; + png_ptr->screen_gamma = png_ptr->colorspace.gamma = PNG_FP_1; + + /* We have a gamma value now. */ + png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; /* Now turn the gamma transformation on or off as appropriate. Notice * that PNG_GAMMA just refers to the file->screen correction. Alpha @@ -1336,7 +1365,7 @@ png_init_read_transformations(png_structp png_ptr) * the code immediately below if the transform can be handled outside the * row loop. */ - if (gamma_correction) + if (gamma_correction != 0) png_ptr->transformations |= PNG_GAMMA; else @@ -1345,7 +1374,7 @@ png_init_read_transformations(png_structp png_ptr) #endif /* Certain transformations have the effect of preventing other - * transformations that happen afterward in png_do_read_transformations, + * transformations that happen afterward in png_do_read_transformations; * resolve the interdependencies here. From the code of * png_do_read_transformations the order is: * @@ -1363,19 +1392,19 @@ png_init_read_transformations(png_structp png_ptr) * 12) PNG_EXPAND_16 * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY * 14) PNG_INVERT_MONO - * 15) PNG_SHIFT - * 16) PNG_PACK - * 17) PNG_BGR - * 18) PNG_PACKSWAP - * 19) PNG_FILLER (includes PNG_ADD_ALPHA) - * 20) PNG_INVERT_ALPHA + * 15) PNG_INVERT_ALPHA + * 16) PNG_SHIFT + * 17) PNG_PACK + * 18) PNG_BGR + * 19) PNG_PACKSWAP + * 20) PNG_FILLER (includes PNG_ADD_ALPHA) * 21) PNG_SWAP_ALPHA * 22) PNG_SWAP_BYTES * 23) PNG_USER_TRANSFORM [must be last] */ #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED - if ((png_ptr->transformations & PNG_STRIP_ALPHA) && - !(png_ptr->transformations & PNG_COMPOSE)) + if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 && + (png_ptr->transformations & PNG_COMPOSE) == 0) { /* Stripping the alpha channel happens immediately after the 'expand' * transformations, before all other transformation, so it cancels out @@ -1401,16 +1430,23 @@ png_init_read_transformations(png_structp png_ptr) /* If the screen gamma is about 1.0 then the OPTIMIZE_ALPHA and ENCODE_ALPHA * settings will have no effect. */ - if (!png_gamma_significant(png_ptr->screen_gamma)) + if (png_gamma_significant(png_ptr->screen_gamma) == 0) { png_ptr->transformations &= ~PNG_ENCODE_ALPHA; png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; } #endif -#if defined(PNG_READ_EXPAND_SUPPORTED) && \ - defined(PNG_READ_BACKGROUND_SUPPORTED) && \ - defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* Make sure the coefficients for the rgb to gray conversion are set + * appropriately. + */ + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0) + png_colorspace_set_rgb_coefficients(png_ptr); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) /* Detect gray background and attempt to enable optimization for * gray --> RGB case. * @@ -1426,23 +1462,23 @@ png_init_read_transformations(png_structp png_ptr) * png_set_background, along with the bit depth, then the code has a record * of exactly what color space the background is currently in. */ - if (png_ptr->transformations & PNG_BACKGROUND_EXPAND) + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0) { /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if - * the file was greyscale the background value is gray. + * the file was grayscale the background value is gray. */ - if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; } - else if (png_ptr->transformations & PNG_COMPOSE) + else if ((png_ptr->transformations & PNG_COMPOSE) != 0) { /* PNG_COMPOSE: png_set_background was called with need_expand false, * so the color is in the color space of the output or png_set_alpha_mode * was called and the color is black. Ignore RGB_TO_GRAY because that * happens before GRAY_TO_RGB. */ - if (png_ptr->transformations & PNG_GRAY_TO_RGB) + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0) { if (png_ptr->background.red == png_ptr->background.green && png_ptr->background.red == png_ptr->background.blue) @@ -1452,7 +1488,8 @@ png_init_read_transformations(png_structp png_ptr) } } } -#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED (etc) */ +#endif /* READ_EXPAND && READ_BACKGROUND */ +#endif /* READ_GRAY_TO_RGB */ /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations * can be performed directly on the palette, and some (such as rgb to gray) @@ -1473,10 +1510,10 @@ png_init_read_transformations(png_structp png_ptr) #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ defined(PNG_READ_EXPAND_16_SUPPORTED) - if ((png_ptr->transformations & PNG_EXPAND_16) && - (png_ptr->transformations & PNG_COMPOSE) && - !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) && - png_ptr->bit_depth != 16) + if ((png_ptr->transformations & PNG_EXPAND_16) != 0 && + (png_ptr->transformations & PNG_COMPOSE) != 0 && + (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 && + png_ptr->bit_depth != 16) { /* TODO: fix this. Because the expand_16 operation is after the compose * handling the background color must be 8, not 16, bits deep, but the @@ -1488,14 +1525,36 @@ png_init_read_transformations(png_structp png_ptr) * NOTE: this discards the low 16 bits of the user supplied background * color, but until expand_16 works properly there is no choice! */ -# define CHOP(x) (x)=((png_uint_16)(((png_uint_32)(x)*255+32895) >> 16)) +# define CHOP(x) (x)=((png_uint_16)PNG_DIV257(x)) CHOP(png_ptr->background.red); CHOP(png_ptr->background.green); CHOP(png_ptr->background.blue); CHOP(png_ptr->background.gray); # undef CHOP } -#endif /* PNG_READ_BACKGROUND_SUPPORTED && PNG_READ_EXPAND_16_SUPPORTED */ +#endif /* READ_BACKGROUND && READ_EXPAND_16 */ + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \ + defined(PNG_READ_STRIP_16_TO_8_SUPPORTED)) + if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) != 0 && + (png_ptr->transformations & PNG_COMPOSE) != 0 && + (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 && + png_ptr->bit_depth == 16) + { + /* On the other hand, if a 16-bit file is to be reduced to 8-bits per + * component this will also happen after PNG_COMPOSE and so the background + * color must be pre-expanded here. + * + * TODO: fix this too. + */ + png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257); + png_ptr->background.green = + (png_uint_16)(png_ptr->background.green * 257); + png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257); + png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257); + } +#endif /* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the * background support (see the comments in scripts/pnglibconf.dfa), this @@ -1524,27 +1583,36 @@ png_init_read_transformations(png_structp png_ptr) * file gamma - if it is not 1.0 both RGB_TO_GRAY and COMPOSE need the * tables. */ - if ((png_ptr->transformations & PNG_GAMMA) - || ((png_ptr->transformations & PNG_RGB_TO_GRAY) - && (png_gamma_significant(png_ptr->gamma) || - png_gamma_significant(png_ptr->screen_gamma))) - || ((png_ptr->transformations & PNG_COMPOSE) - && (png_gamma_significant(png_ptr->gamma) - || png_gamma_significant(png_ptr->screen_gamma) + if ((png_ptr->transformations & PNG_GAMMA) != 0 || + ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0 && + (png_gamma_significant(png_ptr->colorspace.gamma) != 0 || + png_gamma_significant(png_ptr->screen_gamma) != 0)) || + ((png_ptr->transformations & PNG_COMPOSE) != 0 && + (png_gamma_significant(png_ptr->colorspace.gamma) != 0 || + png_gamma_significant(png_ptr->screen_gamma) != 0 # ifdef PNG_READ_BACKGROUND_SUPPORTED - || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE - && png_gamma_significant(png_ptr->background_gamma)) + || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE && + png_gamma_significant(png_ptr->background_gamma) != 0) # endif - )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) - && png_gamma_significant(png_ptr->screen_gamma)) - ) + )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 && + png_gamma_significant(png_ptr->screen_gamma) != 0)) { png_build_gamma_table(png_ptr, png_ptr->bit_depth); #ifdef PNG_READ_BACKGROUND_SUPPORTED - if (png_ptr->transformations & PNG_COMPOSE) + if ((png_ptr->transformations & PNG_COMPOSE) != 0) { - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + /* Issue a warning about this combination: because RGB_TO_GRAY is + * optimized to do the gamma transform if present yet do_background has + * to do the same thing if both options are set a + * double-gamma-correction happens. This is true in all versions of + * libpng to date. + */ + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0) + png_warning(png_ptr, + "libpng does not support gamma+background+rgb_to_gray"); + + if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0) { /* We don't get to here unless there is a tRNS chunk with non-opaque * entries - see the checking code at the start of this function. @@ -1576,8 +1644,8 @@ png_init_read_transformations(png_structp png_ptr) break; case PNG_BACKGROUND_GAMMA_FILE: - g = png_reciprocal(png_ptr->gamma); - gs = png_reciprocal2(png_ptr->gamma, + g = png_reciprocal(png_ptr->colorspace.gamma); + gs = png_reciprocal2(png_ptr->colorspace.gamma, png_ptr->screen_gamma); break; @@ -1592,7 +1660,7 @@ png_init_read_transformations(png_structp png_ptr) break; } - if (png_gamma_significant(gs)) + if (png_gamma_significant(gs) != 0) { back.red = png_gamma_8bit_correct(png_ptr->background.red, gs); @@ -1609,7 +1677,7 @@ png_init_read_transformations(png_structp png_ptr) back.blue = (png_byte)png_ptr->background.blue; } - if (png_gamma_significant(g)) + if (png_gamma_significant(g) != 0) { back_1.red = png_gamma_8bit_correct(png_ptr->background.red, g); @@ -1663,7 +1731,7 @@ png_init_read_transformations(png_structp png_ptr) /* Prevent the transformations being done again. * - * NOTE: this is highly dubious; it zaps the transformations in + * NOTE: this is highly dubious; it removes the transformations in * place. This seems inconsistent with the general treatment of the * transformations elsewhere. */ @@ -1673,8 +1741,9 @@ png_init_read_transformations(png_structp png_ptr) /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ else /* color_type != PNG_COLOR_TYPE_PALETTE */ { - png_fixed_point g = PNG_FP_1; - png_fixed_point gs = PNG_FP_1; + int gs_sig, g_sig; + png_fixed_point g = PNG_FP_1; /* Correction to linear */ + png_fixed_point gs = PNG_FP_1; /* Correction to screen */ switch (png_ptr->background_gamma_type) { @@ -1684,8 +1753,9 @@ png_init_read_transformations(png_structp png_ptr) break; case PNG_BACKGROUND_GAMMA_FILE: - g = png_reciprocal(png_ptr->gamma); - gs = png_reciprocal2(png_ptr->gamma, png_ptr->screen_gamma); + g = png_reciprocal(png_ptr->colorspace.gamma); + gs = png_reciprocal2(png_ptr->colorspace.gamma, + png_ptr->screen_gamma); break; case PNG_BACKGROUND_GAMMA_UNIQUE: @@ -1698,34 +1768,45 @@ png_init_read_transformations(png_structp png_ptr) png_error(png_ptr, "invalid background gamma type"); } - png_ptr->background_1.gray = png_gamma_correct(png_ptr, - png_ptr->background.gray, g); + g_sig = png_gamma_significant(g); + gs_sig = png_gamma_significant(gs); - png_ptr->background.gray = png_gamma_correct(png_ptr, - png_ptr->background.gray, gs); + if (g_sig != 0) + png_ptr->background_1.gray = png_gamma_correct(png_ptr, + png_ptr->background.gray, g); + + if (gs_sig != 0) + png_ptr->background.gray = png_gamma_correct(png_ptr, + png_ptr->background.gray, gs); if ((png_ptr->background.red != png_ptr->background.green) || (png_ptr->background.red != png_ptr->background.blue) || (png_ptr->background.red != png_ptr->background.gray)) { /* RGB or RGBA with color background */ - png_ptr->background_1.red = png_gamma_correct(png_ptr, - png_ptr->background.red, g); + if (g_sig != 0) + { + png_ptr->background_1.red = png_gamma_correct(png_ptr, + png_ptr->background.red, g); - png_ptr->background_1.green = png_gamma_correct(png_ptr, - png_ptr->background.green, g); + png_ptr->background_1.green = png_gamma_correct(png_ptr, + png_ptr->background.green, g); - png_ptr->background_1.blue = png_gamma_correct(png_ptr, - png_ptr->background.blue, g); + png_ptr->background_1.blue = png_gamma_correct(png_ptr, + png_ptr->background.blue, g); + } - png_ptr->background.red = png_gamma_correct(png_ptr, - png_ptr->background.red, gs); + if (gs_sig != 0) + { + png_ptr->background.red = png_gamma_correct(png_ptr, + png_ptr->background.red, gs); - png_ptr->background.green = png_gamma_correct(png_ptr, - png_ptr->background.green, gs); + png_ptr->background.green = png_gamma_correct(png_ptr, + png_ptr->background.green, gs); - png_ptr->background.blue = png_gamma_correct(png_ptr, - png_ptr->background.blue, gs); + png_ptr->background.blue = png_gamma_correct(png_ptr, + png_ptr->background.blue, gs); + } } else @@ -1737,20 +1818,29 @@ png_init_read_transformations(png_structp png_ptr) png_ptr->background.red = png_ptr->background.green = png_ptr->background.blue = png_ptr->background.gray; } + + /* The background is now in screen gamma: */ + png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_SCREEN; } /* color_type != PNG_COLOR_TYPE_PALETTE */ }/* png_ptr->transformations & PNG_BACKGROUND */ else /* Transformation does not include PNG_BACKGROUND */ -#endif /* PNG_READ_BACKGROUND_SUPPORTED */ - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) +#endif /* READ_BACKGROUND */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* RGB_TO_GRAY needs to have non-gamma-corrected values! */ + && ((png_ptr->transformations & PNG_EXPAND) == 0 || + (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0) +#endif + ) { png_colorp palette = png_ptr->palette; int num_palette = png_ptr->num_palette; int i; - /*NOTE: there are other transformations that should probably be in here - * too. + /* NOTE: there are other transformations that should probably be in + * here too. */ for (i = 0; i < num_palette; i++) { @@ -1766,11 +1856,11 @@ png_init_read_transformations(png_structp png_ptr) #ifdef PNG_READ_BACKGROUND_SUPPORTED else #endif -#endif /* PNG_READ_GAMMA_SUPPORTED */ +#endif /* READ_GAMMA */ #ifdef PNG_READ_BACKGROUND_SUPPORTED /* No GAMMA transformation (see the hanging else 4 lines above) */ - if ((png_ptr->transformations & PNG_COMPOSE) && + if ((png_ptr->transformations & PNG_COMPOSE) != 0 && (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) { int i; @@ -1805,35 +1895,53 @@ png_init_read_transformations(png_structp png_ptr) png_ptr->transformations &= ~PNG_COMPOSE; } -#endif /* PNG_READ_BACKGROUND_SUPPORTED */ +#endif /* READ_BACKGROUND */ #ifdef PNG_READ_SHIFT_SUPPORTED - if ((png_ptr->transformations & PNG_SHIFT) && + if ((png_ptr->transformations & PNG_SHIFT) != 0 && + (png_ptr->transformations & PNG_EXPAND) == 0 && (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) { - png_uint_16 i; - png_uint_16 istop = png_ptr->num_palette; - int sr = 8 - png_ptr->sig_bit.red; - int sg = 8 - png_ptr->sig_bit.green; - int sb = 8 - png_ptr->sig_bit.blue; + int i; + int istop = png_ptr->num_palette; + int shift = 8 - png_ptr->sig_bit.red; - if (sr < 0 || sr > 8) - sr = 0; + png_ptr->transformations &= ~PNG_SHIFT; - if (sg < 0 || sg > 8) - sg = 0; + /* significant bits can be in the range 1 to 7 for a meaninful result, if + * the number of significant bits is 0 then no shift is done (this is an + * error condition which is silently ignored.) + */ + if (shift > 0 && shift < 8) + for (i=0; ipalette[i].red; - if (sb < 0 || sb > 8) - sb = 0; + component >>= shift; + png_ptr->palette[i].red = (png_byte)component; + } - for (i = 0; i < istop; i++) - { - png_ptr->palette[i].red >>= sr; - png_ptr->palette[i].green >>= sg; - png_ptr->palette[i].blue >>= sb; - } + shift = 8 - png_ptr->sig_bit.green; + if (shift > 0 && shift < 8) + for (i=0; ipalette[i].green; + + component >>= shift; + png_ptr->palette[i].green = (png_byte)component; + } + + shift = 8 - png_ptr->sig_bit.blue; + if (shift > 0 && shift < 8) + for (i=0; ipalette[i].blue; + + component >>= shift; + png_ptr->palette[i].blue = (png_byte)component; + } } -#endif /* PNG_READ_SHIFT_SUPPORTED */ +#endif /* READ_SHIFT */ } /* Modify the info structure to reflect the transformations. The @@ -1841,12 +1949,12 @@ png_init_read_transformations(png_structp png_ptr) * assuming the transformations result in valid PNG data. */ void /* PRIVATE */ -png_read_transform_info(png_structp png_ptr, png_infop info_ptr) +png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr) { png_debug(1, "in png_read_transform_info"); #ifdef PNG_READ_EXPAND_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND) + if ((png_ptr->transformations & PNG_EXPAND) != 0) { if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { @@ -1868,9 +1976,9 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) } else { - if (png_ptr->num_trans) + if (png_ptr->num_trans != 0) { - if (png_ptr->transformations & PNG_EXPAND_tRNS) + if ((png_ptr->transformations & PNG_EXPAND_tRNS) != 0) info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; } if (info_ptr->bit_depth < 8) @@ -1886,7 +1994,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) /* The following is almost certainly wrong unless the background value is in * the screen space! */ - if (png_ptr->transformations & PNG_COMPOSE) + if ((png_ptr->transformations & PNG_COMPOSE) != 0) info_ptr->background = png_ptr->background; #endif @@ -1895,20 +2003,24 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) * however it seems that the code in png_init_read_transformations, which has * been called before this from png_read_update_info->png_read_start_row * sometimes does the gamma transform and cancels the flag. + * + * TODO: this looks wrong; the info_ptr should end up with a gamma equal to + * the screen_gamma value. The following probably results in weirdness if + * the info_ptr is used by the app after the rows have been read. */ - info_ptr->gamma = png_ptr->gamma; + info_ptr->colorspace.gamma = png_ptr->colorspace.gamma; #endif if (info_ptr->bit_depth == 16) { # ifdef PNG_READ_16BIT_SUPPORTED # ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED - if (png_ptr->transformations & PNG_SCALE_16_TO_8) + if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0) info_ptr->bit_depth = 8; # endif # ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED - if (png_ptr->transformations & PNG_16_TO_8) + if ((png_ptr->transformations & PNG_16_TO_8) != 0) info_ptr->bit_depth = 8; # endif @@ -1926,7 +2038,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) info_ptr->bit_depth = 8; # else -# if PNG_READ_SCALE_16_TO_8_SUPPORTED +# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED png_ptr->transformations |= PNG_SCALE_16_TO_8; info_ptr->bit_depth = 8; # else @@ -1934,25 +2046,27 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) CONFIGURATION ERROR: you must enable at least one 16 to 8 method # endif # endif -#endif /* !READ_16BIT_SUPPORTED */ +#endif /* !READ_16BIT */ } #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED - if (png_ptr->transformations & PNG_GRAY_TO_RGB) - info_ptr->color_type |= PNG_COLOR_MASK_COLOR; + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0) + info_ptr->color_type = (png_byte)(info_ptr->color_type | + PNG_COLOR_MASK_COLOR); #endif #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - if (png_ptr->transformations & PNG_RGB_TO_GRAY) - info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR; + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0) + info_ptr->color_type = (png_byte)(info_ptr->color_type & + ~PNG_COLOR_MASK_COLOR); #endif #ifdef PNG_READ_QUANTIZE_SUPPORTED - if (png_ptr->transformations & PNG_QUANTIZE) + if ((png_ptr->transformations & PNG_QUANTIZE) != 0) { if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) && - png_ptr->palette_lookup && info_ptr->bit_depth == 8) + png_ptr->palette_lookup != 0 && info_ptr->bit_depth == 8) { info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; } @@ -1960,54 +2074,57 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) #endif #ifdef PNG_READ_EXPAND_16_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND_16 && info_ptr->bit_depth == 8 && - info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + if ((png_ptr->transformations & PNG_EXPAND_16) != 0 && + info_ptr->bit_depth == 8 && + info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) { info_ptr->bit_depth = 16; } #endif #ifdef PNG_READ_PACK_SUPPORTED - if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8)) + if ((png_ptr->transformations & PNG_PACK) != 0 && + (info_ptr->bit_depth < 8)) info_ptr->bit_depth = 8; #endif if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) info_ptr->channels = 1; - else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) + else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) info_ptr->channels = 3; else info_ptr->channels = 1; #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_STRIP_ALPHA) + if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0) { - info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; + info_ptr->color_type = (png_byte)(info_ptr->color_type & + ~PNG_COLOR_MASK_ALPHA); info_ptr->num_trans = 0; } #endif - if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) + if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) info_ptr->channels++; #ifdef PNG_READ_FILLER_SUPPORTED /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ - if ((png_ptr->transformations & PNG_FILLER) && - ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || - (info_ptr->color_type == PNG_COLOR_TYPE_GRAY))) + if ((png_ptr->transformations & PNG_FILLER) != 0 && + (info_ptr->color_type == PNG_COLOR_TYPE_RGB || + info_ptr->color_type == PNG_COLOR_TYPE_GRAY)) { info_ptr->channels++; /* If adding a true alpha channel not just filler */ - if (png_ptr->transformations & PNG_ADD_ALPHA) + if ((png_ptr->transformations & PNG_ADD_ALPHA) != 0) info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; } #endif #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ defined(PNG_READ_USER_TRANSFORM_SUPPORTED) - if (png_ptr->transformations & PNG_USER_TRANSFORM) + if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) { if (info_ptr->bit_depth < png_ptr->user_transform_depth) info_ptr->bit_depth = png_ptr->user_transform_depth; @@ -2031,291 +2148,11 @@ defined(PNG_READ_USER_TRANSFORM_SUPPORTED) png_ptr->info_rowbytes = info_ptr->rowbytes; #ifndef PNG_READ_EXPAND_SUPPORTED - if (png_ptr) + if (png_ptr != NULL) return; #endif } -/* Transform the row. The order of transformations is significant, - * and is very touchy. If you add a transformation, take care to - * decide how it fits in with the other transformations here. - */ -void /* PRIVATE */ -png_do_read_transformations(png_structp png_ptr) -{ - png_debug(1, "in png_do_read_transformations"); - - if (png_ptr->row_buf == NULL) - { - /* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this - * error is incredibly rare and incredibly easy to debug without this - * information. - */ - png_error(png_ptr, "NULL row buffer"); - } - - /* The following is debugging; prior to 1.5.4 the code was never compiled in; - * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro - * PNG_WARN_UNINITIALIZED_ROW removed. In 1.5 the new flag is set only for - * selected new APIs to ensure that there is no API change. - */ - if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 && - !(png_ptr->flags & PNG_FLAG_ROW_INIT)) - { - /* Application has failed to call either png_read_start_image() or - * png_read_update_info() after setting transforms that expand pixels. - * This check added to libpng-1.2.19 (but not enabled until 1.5.4). - */ - png_error(png_ptr, "Uninitialized row"); - } - -#ifdef PNG_READ_EXPAND_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND) - { - if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE) - { - png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1, - png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans); - } - - else - { - if (png_ptr->num_trans && - (png_ptr->transformations & PNG_EXPAND_tRNS)) - png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, - &(png_ptr->trans_color)); - - else - png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, - NULL); - } - } -#endif - -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED - if ((png_ptr->transformations & PNG_STRIP_ALPHA) && - !(png_ptr->transformations & PNG_COMPOSE) && - (png_ptr->row_info.color_type == PNG_COLOR_TYPE_RGB_ALPHA || - png_ptr->row_info.color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) - png_do_strip_channel(&(png_ptr->row_info), png_ptr->row_buf + 1, - 0 /* at_start == false, because SWAP_ALPHA happens later */); -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - if (png_ptr->transformations & PNG_RGB_TO_GRAY) - { - int rgb_error = - png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), - png_ptr->row_buf + 1); - - if (rgb_error) - { - png_ptr->rgb_to_gray_status=1; - if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == - PNG_RGB_TO_GRAY_WARN) - png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); - - if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == - PNG_RGB_TO_GRAY_ERR) - png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); - } - } -#endif - -/* From Andreas Dilger e-mail to png-implement, 26 March 1998: - * - * In most cases, the "simple transparency" should be done prior to doing - * gray-to-RGB, or you will have to test 3x as many bytes to check if a - * pixel is transparent. You would also need to make sure that the - * transparency information is upgraded to RGB. - * - * To summarize, the current flow is: - * - Gray + simple transparency -> compare 1 or 2 gray bytes and composite - * with background "in place" if transparent, - * convert to RGB if necessary - * - Gray + alpha -> composite with gray background and remove alpha bytes, - * convert to RGB if necessary - * - * To support RGB backgrounds for gray images we need: - * - Gray + simple transparency -> convert to RGB + simple transparency, - * compare 3 or 6 bytes and composite with - * background "in place" if transparent - * (3x compare/pixel compared to doing - * composite with gray bkgrnd) - * - Gray + alpha -> convert to RGB + alpha, composite with background and - * remove alpha bytes (3x float - * operations/pixel compared with composite - * on gray background) - * - * Greg's change will do this. The reason it wasn't done before is for - * performance, as this increases the per-pixel operations. If we would check - * in advance if the background was gray or RGB, and position the gray-to-RGB - * transform appropriately, then it would save a lot of work/time. - */ - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED - /* If gray -> RGB, do so now only if background is non-gray; else do later - * for performance reasons - */ - if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && - !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) - png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\ - (defined PNG_READ_ALPHA_MODE_SUPPORTED) - if (png_ptr->transformations & PNG_COMPOSE) - png_do_compose(&(png_ptr->row_info), png_ptr->row_buf + 1, png_ptr); -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED - if ((png_ptr->transformations & PNG_GAMMA) && -#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\ - (defined PNG_READ_ALPHA_MODE_SUPPORTED) - !((png_ptr->transformations & PNG_COMPOSE) && - ((png_ptr->num_trans != 0) || - (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) && -#endif - (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) - png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1, png_ptr); -#endif - -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED - if ((png_ptr->transformations & PNG_STRIP_ALPHA) && - (png_ptr->transformations & PNG_COMPOSE) && - (png_ptr->row_info.color_type == PNG_COLOR_TYPE_RGB_ALPHA || - png_ptr->row_info.color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) - png_do_strip_channel(&(png_ptr->row_info), png_ptr->row_buf + 1, - 0 /* at_start == false, because SWAP_ALPHA happens later */); -#endif - -#ifdef PNG_READ_ALPHA_MODE_SUPPORTED - if ((png_ptr->transformations & PNG_ENCODE_ALPHA) && - (png_ptr->row_info.color_type & PNG_COLOR_MASK_ALPHA)) - png_do_encode_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1, png_ptr); -#endif - -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED - if (png_ptr->transformations & PNG_SCALE_16_TO_8) - png_do_scale_16_to_8(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED - /* There is no harm in doing both of these because only one has any effect, - * by putting the 'scale' option first if the app asks for scale (either by - * calling the API or in a TRANSFORM flag) this is what happens. - */ - if (png_ptr->transformations & PNG_16_TO_8) - png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_QUANTIZE_SUPPORTED - if (png_ptr->transformations & PNG_QUANTIZE) - { - png_do_quantize(&(png_ptr->row_info), png_ptr->row_buf + 1, - png_ptr->palette_lookup, png_ptr->quantize_index); - - if (png_ptr->row_info.rowbytes == 0) - png_error(png_ptr, "png_do_quantize returned rowbytes=0"); - } -#endif /* PNG_READ_QUANTIZE_SUPPORTED */ - -#ifdef PNG_READ_EXPAND_16_SUPPORTED - /* Do the expansion now, after all the arithmetic has been done. Notice - * that previous transformations can handle the PNG_EXPAND_16 flag if this - * is efficient (particularly true in the case of gamma correction, where - * better accuracy results faster!) - */ - if (png_ptr->transformations & PNG_EXPAND_16) - png_do_expand_16(&png_ptr->row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED - /*NOTE: moved here in 1.5.4 (from much later in this list.) */ - if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && - (png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) - png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_INVERT_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_MONO) - png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_SHIFT_SUPPORTED - if (png_ptr->transformations & PNG_SHIFT) - png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1, - &(png_ptr->shift)); -#endif - -#ifdef PNG_READ_PACK_SUPPORTED - if (png_ptr->transformations & PNG_PACK) - png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_BGR_SUPPORTED - if (png_ptr->transformations & PNG_BGR) - png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_PACKSWAP_SUPPORTED - if (png_ptr->transformations & PNG_PACKSWAP) - png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_FILLER_SUPPORTED - if (png_ptr->transformations & PNG_FILLER) - png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, - (png_uint_32)png_ptr->filler, png_ptr->flags); -#endif - -#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_ALPHA) - png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_SWAP_ALPHA) - png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_16BIT_SUPPORTED -#ifdef PNG_READ_SWAP_SUPPORTED - if (png_ptr->transformations & PNG_SWAP_BYTES) - png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif -#endif - -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED - if (png_ptr->transformations & PNG_USER_TRANSFORM) - { - if (png_ptr->read_user_transform_fn != NULL) - (*(png_ptr->read_user_transform_fn)) /* User read transform function */ - (png_ptr, /* png_ptr */ - &(png_ptr->row_info), /* row_info: */ - /* png_uint_32 width; width of row */ - /* png_size_t rowbytes; number of bytes in row */ - /* png_byte color_type; color type of pixels */ - /* png_byte bit_depth; bit depth of samples */ - /* png_byte channels; number of channels (1-4) */ - /* png_byte pixel_depth; bits per pixel (depth*channels) */ - png_ptr->row_buf + 1); /* start of pixel data for row */ -#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED - if (png_ptr->user_transform_depth) - png_ptr->row_info.bit_depth = png_ptr->user_transform_depth; - - if (png_ptr->user_transform_channels) - png_ptr->row_info.channels = png_ptr->user_transform_channels; -#endif - png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * - png_ptr->row_info.channels); - - png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, - png_ptr->row_info.width); - } -#endif -} - #ifdef PNG_READ_PACK_SUPPORTED /* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel, * without changing the actual values. Thus, if you had a row with @@ -2323,7 +2160,7 @@ png_do_read_transformations(png_structp png_ptr) * the numbers 0 or 1. If you would rather they contain 0 and 255, use * png_do_shift() after this. */ -void /* PRIVATE */ +static void png_do_unpack(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_unpack"); @@ -2421,109 +2258,132 @@ png_do_unpack(png_row_infop row_info, png_bytep row) * a row of bit depth 8, but only 5 are significant, this will shift * the values back to 0 through 31. */ -void /* PRIVATE */ +static void png_do_unshift(png_row_infop row_info, png_bytep row, png_const_color_8p sig_bits) { + int color_type; + png_debug(1, "in png_do_unshift"); - if ( - row_info->color_type != PNG_COLOR_TYPE_PALETTE) + /* The palette case has already been handled in the _init routine. */ + color_type = row_info->color_type; + + if (color_type != PNG_COLOR_TYPE_PALETTE) { int shift[4]; int channels = 0; - int c; - png_uint_16 value = 0; - png_uint_32 row_width = row_info->width; + int bit_depth = row_info->bit_depth; - if (row_info->color_type & PNG_COLOR_MASK_COLOR) + if ((color_type & PNG_COLOR_MASK_COLOR) != 0) { - shift[channels++] = row_info->bit_depth - sig_bits->red; - shift[channels++] = row_info->bit_depth - sig_bits->green; - shift[channels++] = row_info->bit_depth - sig_bits->blue; + shift[channels++] = bit_depth - sig_bits->red; + shift[channels++] = bit_depth - sig_bits->green; + shift[channels++] = bit_depth - sig_bits->blue; } else { - shift[channels++] = row_info->bit_depth - sig_bits->gray; + shift[channels++] = bit_depth - sig_bits->gray; } - if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + if ((color_type & PNG_COLOR_MASK_ALPHA) != 0) { - shift[channels++] = row_info->bit_depth - sig_bits->alpha; + shift[channels++] = bit_depth - sig_bits->alpha; } - for (c = 0; c < channels; c++) { - if (shift[c] <= 0) - shift[c] = 0; + int c, have_shift; - else - value = 1; + for (c = have_shift = 0; c < channels; ++c) + { + /* A shift of more than the bit depth is an error condition but it + * gets ignored here. + */ + if (shift[c] <= 0 || shift[c] >= bit_depth) + shift[c] = 0; + + else + have_shift = 1; + } + + if (have_shift == 0) + return; } - if (!value) - return; - - switch (row_info->bit_depth) + switch (bit_depth) { default: + /* Must be 1bpp gray: should not be here! */ + /* NOTREACHED */ break; case 2: + /* Must be 2bpp gray */ + /* assert(channels == 1 && shift[0] == 1) */ { - png_bytep bp; - png_size_t i; - png_size_t istop = row_info->rowbytes; + png_bytep bp = row; + png_bytep bp_end = bp + row_info->rowbytes; - for (bp = row, i = 0; i < istop; i++) + while (bp < bp_end) { - *bp >>= 1; - *bp++ &= 0x55; + int b = (*bp >> 1) & 0x55; + *bp++ = (png_byte)b; } break; } case 4: + /* Must be 4bpp gray */ + /* assert(channels == 1) */ { png_bytep bp = row; - png_size_t i; - png_size_t istop = row_info->rowbytes; - png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) | - (png_byte)((int)0xf >> shift[0])); + png_bytep bp_end = bp + row_info->rowbytes; + int gray_shift = shift[0]; + int mask = 0xf >> gray_shift; - for (i = 0; i < istop; i++) + mask |= mask << 4; + + while (bp < bp_end) { - *bp >>= shift[0]; - *bp++ &= mask; + int b = (*bp >> gray_shift) & mask; + *bp++ = (png_byte)b; } break; } case 8: + /* Single byte components, G, GA, RGB, RGBA */ { png_bytep bp = row; - png_uint_32 i; - png_uint_32 istop = row_width * channels; + png_bytep bp_end = bp + row_info->rowbytes; + int channel = 0; - for (i = 0; i < istop; i++) + while (bp < bp_end) { - *bp++ >>= shift[i%channels]; + int b = *bp >> shift[channel]; + if (++channel >= channels) + channel = 0; + *bp++ = (png_byte)b; } break; } #ifdef PNG_READ_16BIT_SUPPORTED case 16: + /* Double byte components, G, GA, RGB, RGBA */ { png_bytep bp = row; - png_uint_32 i; - png_uint_32 istop = channels * row_width; + png_bytep bp_end = bp + row_info->rowbytes; + int channel = 0; - for (i = 0; i < istop; i++) + while (bp < bp_end) { - value = (png_uint_16)((*bp << 8) + *(bp + 1)); - value >>= shift[i%channels]; + int value = (bp[0] << 8) + bp[1]; + + value >>= shift[channel]; + if (++channel >= channels) + channel = 0; *bp++ = (png_byte)(value >> 8); *bp++ = (png_byte)(value & 0xff); } @@ -2537,7 +2397,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED /* Scale rows of bit depth 16 down to 8 accurately */ -void /* PRIVATE */ +static void png_do_scale_16_to_8(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_scale_16_to_8"); @@ -2545,7 +2405,7 @@ png_do_scale_16_to_8(png_row_infop row_info, png_bytep row) if (row_info->bit_depth == 16) { png_bytep sp = row; /* source */ - png_bytep dp = row; /* destinaton */ + png_bytep dp = row; /* destination */ png_bytep ep = sp + row_info->rowbytes; /* end+1 */ while (sp < ep) @@ -2595,7 +2455,7 @@ png_do_scale_16_to_8(png_row_infop row_info, png_bytep row) #endif #ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED -void /* PRIVATE */ +static void /* Simply discard the low byte. This was the default behavior prior * to libpng-1.5.4. */ @@ -2606,7 +2466,7 @@ png_do_chop(png_row_infop row_info, png_bytep row) if (row_info->bit_depth == 16) { png_bytep sp = row; /* source */ - png_bytep dp = row; /* destinaton */ + png_bytep dp = row; /* destination */ png_bytep ep = sp + row_info->rowbytes; /* end+1 */ while (sp < ep) @@ -2623,7 +2483,7 @@ png_do_chop(png_row_infop row_info, png_bytep row) #endif #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED -void /* PRIVATE */ +static void png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_read_swap_alpha"); @@ -2720,7 +2580,7 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) #endif #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED -void /* PRIVATE */ +static void png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) { png_uint_32 row_width; @@ -2822,7 +2682,7 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) #ifdef PNG_READ_FILLER_SUPPORTED /* Add filler channel if we have RGB color */ -void /* PRIVATE */ +static void png_do_read_filler(png_row_infop row_info, png_bytep row, png_uint_32 filler, png_uint_32 flags) { @@ -2841,7 +2701,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, { if (row_info->bit_depth == 8) { - if (flags & PNG_FLAG_FILLER_AFTER) + if ((flags & PNG_FLAG_FILLER_AFTER) != 0) { /* This changes the data from G to GX */ png_bytep sp = row + (png_size_t)row_width; @@ -2876,7 +2736,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, #ifdef PNG_READ_16BIT_SUPPORTED else if (row_info->bit_depth == 16) { - if (flags & PNG_FLAG_FILLER_AFTER) + if ((flags & PNG_FLAG_FILLER_AFTER) != 0) { /* This changes the data from GG to GGXX */ png_bytep sp = row + (png_size_t)row_width * 2; @@ -2918,7 +2778,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, { if (row_info->bit_depth == 8) { - if (flags & PNG_FLAG_FILLER_AFTER) + if ((flags & PNG_FLAG_FILLER_AFTER) != 0) { /* This changes the data from RGB to RGBX */ png_bytep sp = row + (png_size_t)row_width * 3; @@ -2957,7 +2817,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, #ifdef PNG_READ_16BIT_SUPPORTED else if (row_info->bit_depth == 16) { - if (flags & PNG_FLAG_FILLER_AFTER) + if ((flags & PNG_FLAG_FILLER_AFTER) != 0) { /* This changes the data from RRGGBB to RRGGBBXX */ png_bytep sp = row + (png_size_t)row_width * 6; @@ -3009,7 +2869,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED /* Expand grayscale files to RGB, with or without alpha */ -void /* PRIVATE */ +static void png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) { png_uint_32 i; @@ -3018,7 +2878,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) png_debug(1, "in png_do_gray_to_rgb"); if (row_info->bit_depth >= 8 && - !(row_info->color_type & PNG_COLOR_MASK_COLOR)) + (row_info->color_type & PNG_COLOR_MASK_COLOR) == 0) { if (row_info->color_type == PNG_COLOR_TYPE_GRAY) { @@ -3086,7 +2946,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) } } } - row_info->channels += (png_byte)2; + row_info->channels = (png_byte)(row_info->channels + 2); row_info->color_type |= PNG_COLOR_MASK_COLOR; row_info->pixel_depth = (png_byte)(row_info->channels * row_info->bit_depth); @@ -3097,269 +2957,242 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED /* Reduce RGB files to grayscale, with or without alpha - * using the equation given in Poynton's ColorFAQ at - * (THIS LINK IS DEAD June 2008) - * New link: - * + * using the equation given in Poynton's ColorFAQ of 1998-01-04 at + * (THIS LINK IS DEAD June 2008 but + * versions dated 1998 through November 2002 have been archived at + * http://web.archive.org/web/20000816232553/http://www.inforamp.net/ + * ~poynton/notes/colour_and_gamma/ColorFAQ.txt ) * Charles Poynton poynton at poynton.com * * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B * - * We approximate this with - * - * Y = 0.21268 * R + 0.7151 * G + 0.07217 * B - * * which can be expressed with integers as * * Y = (6969 * R + 23434 * G + 2365 * B)/32768 * - * The calculation is to be done in a linear colorspace. + * Poynton's current link (as of January 2003 through July 2011): + * + * has changed the numbers slightly: * - * Other integer coefficents can be used via png_set_rgb_to_gray(). + * Y = 0.2126*R + 0.7152*G + 0.0722*B + * + * which can be expressed with integers as + * + * Y = (6966 * R + 23436 * G + 2366 * B)/32768 + * + * Historically, however, libpng uses numbers derived from the ITU-R Rec 709 + * end point chromaticities and the D65 white point. Depending on the + * precision used for the D65 white point this produces a variety of different + * numbers, however if the four decimal place value used in ITU-R Rec 709 is + * used (0.3127,0.3290) the Y calculation would be: + * + * Y = (6968 * R + 23435 * G + 2366 * B)/32768 + * + * While this is correct the rounding results in an overflow for white, because + * the sum of the rounded coefficients is 32769, not 32768. Consequently + * libpng uses, instead, the closest non-overflowing approximation: + * + * Y = (6968 * R + 23434 * G + 2366 * B)/32768 + * + * Starting with libpng-1.5.5, if the image being converted has a cHRM chunk + * (including an sRGB chunk) then the chromaticities are used to calculate the + * coefficients. See the chunk handling in pngrutil.c for more information. + * + * In all cases the calculation is to be done in a linear colorspace. If no + * gamma information is available to correct the encoding of the original RGB + * values this results in an implicit assumption that the original PNG RGB + * values were linear. + * + * Other integer coefficents can be used via png_set_rgb_to_gray(). Because + * the API takes just red and green coefficients the blue coefficient is + * calculated to make the sum 32768. This will result in different rounding + * to that used above. */ -int /* PRIVATE */ -png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) +static int +png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row) { - png_uint_32 i; - - png_uint_32 row_width = row_info->width; int rgb_error = 0; png_debug(1, "in png_do_rgb_to_gray"); - if (!(row_info->color_type & PNG_COLOR_MASK_PALETTE) && - (row_info->color_type & PNG_COLOR_MASK_COLOR)) + if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 && + (row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) { - png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; - png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; - png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff; + PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; + PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; + PNG_CONST png_uint_32 bc = 32768 - rc - gc; + PNG_CONST png_uint_32 row_width = row_info->width; + PNG_CONST int have_alpha = + (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0; - if (row_info->color_type == PNG_COLOR_TYPE_RGB) + if (row_info->bit_depth == 8) { - if (row_info->bit_depth == 8) +#ifdef PNG_READ_GAMMA_SUPPORTED + /* Notice that gamma to/from 1 are not necessarily inverses (if + * there is an overall gamma correction). Prior to 1.5.5 this code + * checked the linearized values for equality; this doesn't match + * the documentation, the original values must be checked. + */ + if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) { -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) { - png_bytep sp = row; - png_bytep dp = row; + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); - for (i = 0; i < row_width; i++) + if (red != green || red != blue) { - png_byte red = png_ptr->gamma_to_1[*(sp++)]; - png_byte green = png_ptr->gamma_to_1[*(sp++)]; - png_byte blue = png_ptr->gamma_to_1[*(sp++)]; + red = png_ptr->gamma_to_1[red]; + green = png_ptr->gamma_to_1[green]; + blue = png_ptr->gamma_to_1[blue]; - if (red != green || red != blue) - { - rgb_error |= 1; - *(dp++) = png_ptr->gamma_from_1[ - (rc*red + gc*green + bc*blue)>>15]; - } - - else - *(dp++) = *(sp - 1); + rgb_error |= 1; + *(dp++) = png_ptr->gamma_from_1[ + (rc*red + gc*green + bc*blue + 16384)>>15]; } - } - else -#endif - { - png_bytep sp = row; - png_bytep dp = row; - for (i = 0; i < row_width; i++) + + else { - png_byte red = *(sp++); - png_byte green = *(sp++); - png_byte blue = *(sp++); + /* If there is no overall correction the table will not be + * set. + */ + if (png_ptr->gamma_table != NULL) + red = png_ptr->gamma_table[red]; - if (red != green || red != blue) - { - rgb_error |= 1; - *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); - } - - else - *(dp++) = *(sp - 1); + *(dp++) = red; } + + if (have_alpha != 0) + *(dp++) = *(sp++); } } - - else /* RGB bit_depth == 16 */ - { -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - if (png_ptr->gamma_16_to_1 != NULL && - png_ptr->gamma_16_from_1 != NULL) - { - png_bytep sp = row; - png_bytep dp = row; - for (i = 0; i < row_width; i++) - { - png_uint_16 red, green, blue, w; - - red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - - if (red == green && red == blue) - w = red; - - else - { - png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) - >> png_ptr->gamma_shift][red>>8]; - png_uint_16 green_1 = - png_ptr->gamma_16_to_1[(green&0xff) >> - png_ptr->gamma_shift][green>>8]; - png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) - >> png_ptr->gamma_shift][blue>>8]; - png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 - + bc*blue_1)>>15); - w = png_ptr->gamma_16_from_1[(gray16&0xff) >> - png_ptr->gamma_shift][gray16 >> 8]; - rgb_error |= 1; - } - - *(dp++) = (png_byte)((w>>8) & 0xff); - *(dp++) = (png_byte)(w & 0xff); - } - } - else + else #endif + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) { - png_bytep sp = row; - png_bytep dp = row; - for (i = 0; i < row_width; i++) + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); + + if (red != green || red != blue) { - png_uint_16 red, green, blue, gray16; - - red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - - if (red != green || red != blue) - rgb_error |= 1; - - gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15); - *(dp++) = (png_byte)((gray16>>8) & 0xff); - *(dp++) = (png_byte)(gray16 & 0xff); + rgb_error |= 1; + /* NOTE: this is the historical approach which simply + * truncates the results. + */ + *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); } + + else + *(dp++) = red; + + if (have_alpha != 0) + *(dp++) = *(sp++); } } } - if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + + else /* RGB bit_depth == 16 */ { - if (row_info->bit_depth == 8) +#ifdef PNG_READ_GAMMA_SUPPORTED + if (png_ptr->gamma_16_to_1 != NULL && png_ptr->gamma_16_from_1 != NULL) { -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) { - png_bytep sp = row; - png_bytep dp = row; - for (i = 0; i < row_width; i++) + png_uint_16 red, green, blue, w; + + red = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2; + green = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2; + blue = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2; + + if (red == green && red == blue) { - png_byte red = png_ptr->gamma_to_1[*(sp++)]; - png_byte green = png_ptr->gamma_to_1[*(sp++)]; - png_byte blue = png_ptr->gamma_to_1[*(sp++)]; - - if (red != green || red != blue) - rgb_error |= 1; - - *(dp++) = png_ptr->gamma_from_1 - [(rc*red + gc*green + bc*blue)>>15]; - - *(dp++) = *(sp++); /* alpha */ - } - } - else -#endif - { - png_bytep sp = row; - png_bytep dp = row; - for (i = 0; i < row_width; i++) - { - png_byte red = *(sp++); - png_byte green = *(sp++); - png_byte blue = *(sp++); - if (red != green || red != blue) - rgb_error |= 1; - - *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); - *(dp++) = *(sp++); /* alpha */ - } - } - } - else /* RGBA bit_depth == 16 */ - { -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - if (png_ptr->gamma_16_to_1 != NULL && - png_ptr->gamma_16_from_1 != NULL) - { - png_bytep sp = row; - png_bytep dp = row; - for (i = 0; i < row_width; i++) - { - png_uint_16 red, green, blue, w; - - red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - - if (red == green && red == blue) - w = red; + if (png_ptr->gamma_16_table != NULL) + w = png_ptr->gamma_16_table[(red & 0xff) + >> png_ptr->gamma_shift][red >> 8]; else - { - png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> - png_ptr->gamma_shift][red>>8]; + w = red; + } - png_uint_16 green_1 = - png_ptr->gamma_16_to_1[(green&0xff) >> - png_ptr->gamma_shift][green>>8]; + else + { + png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) + >> png_ptr->gamma_shift][red>>8]; + png_uint_16 green_1 = + png_ptr->gamma_16_to_1[(green&0xff) >> + png_ptr->gamma_shift][green>>8]; + png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) + >> png_ptr->gamma_shift][blue>>8]; + png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 + + bc*blue_1 + 16384)>>15); + w = png_ptr->gamma_16_from_1[(gray16&0xff) >> + png_ptr->gamma_shift][gray16 >> 8]; + rgb_error |= 1; + } - png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> - png_ptr->gamma_shift][blue>>8]; + *(dp++) = (png_byte)((w>>8) & 0xff); + *(dp++) = (png_byte)(w & 0xff); - png_uint_16 gray16 = (png_uint_16)((rc * red_1 - + gc * green_1 + bc * blue_1)>>15); - - w = png_ptr->gamma_16_from_1[(gray16&0xff) >> - png_ptr->gamma_shift][gray16 >> 8]; - - rgb_error |= 1; - } - - *(dp++) = (png_byte)((w>>8) & 0xff); - *(dp++) = (png_byte)(w & 0xff); - *(dp++) = *(sp++); /* alpha */ + if (have_alpha != 0) + { + *(dp++) = *(sp++); *(dp++) = *(sp++); } } - else + } + else #endif + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) { - png_bytep sp = row; - png_bytep dp = row; - for (i = 0; i < row_width; i++) + png_uint_16 red, green, blue, gray16; + + red = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2; + green = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2; + blue = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2; + + if (red != green || red != blue) + rgb_error |= 1; + + /* From 1.5.5 in the 16 bit case do the accurate conversion even + * in the 'fast' case - this is because this is where the code + * ends up when handling linear 16 bit data. + */ + gray16 = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >> + 15); + *(dp++) = (png_byte)((gray16 >> 8) & 0xff); + *(dp++) = (png_byte)(gray16 & 0xff); + + if (have_alpha != 0) { - png_uint_16 red, green, blue, gray16; - red = (png_uint_16)((*(sp)<<8) | *(sp + 1)); sp += 2; - green = (png_uint_16)((*(sp)<<8) | *(sp + 1)); sp += 2; - blue = (png_uint_16)((*(sp)<<8) | *(sp + 1)); sp += 2; - - if (red != green || red != blue) - rgb_error |= 1; - - gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15); - *(dp++) = (png_byte)((gray16>>8) & 0xff); - *(dp++) = (png_byte)(gray16 & 0xff); - *(dp++) = *(sp++); /* alpha */ + *(dp++) = *(sp++); *(dp++) = *(sp++); } } } } - row_info->channels -= 2; + + row_info->channels = (png_byte)(row_info->channels - 2); row_info->color_type = (png_byte)(row_info->color_type & ~PNG_COLOR_MASK_COLOR); row_info->pixel_depth = (png_byte)(row_info->channels * @@ -3369,73 +3202,15 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) return rgb_error; } #endif -#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ -#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED -/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth - * large of png_color. This lets grayscale images be treated as - * paletted. Most useful for gamma correction and simplification - * of code. This API is not used internally. - */ -void PNGAPI -png_build_grayscale_palette(int bit_depth, png_colorp palette) -{ - int num_palette; - int color_inc; - int i; - int v; - - png_debug(1, "in png_do_build_grayscale_palette"); - - if (palette == NULL) - return; - - switch (bit_depth) - { - case 1: - num_palette = 2; - color_inc = 0xff; - break; - - case 2: - num_palette = 4; - color_inc = 0x55; - break; - - case 4: - num_palette = 16; - color_inc = 0x11; - break; - - case 8: - num_palette = 256; - color_inc = 1; - break; - - default: - num_palette = 0; - color_inc = 0; - break; - } - - for (i = 0, v = 0; i < num_palette; i++, v += color_inc) - { - palette[i].red = (png_byte)v; - palette[i].green = (png_byte)v; - palette[i].blue = (png_byte)v; - } -} -#endif - - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED -#ifdef PNG_READ_BACKGROUND_SUPPORTED +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) /* Replace any alpha or transparency with the supplied background color. * "background" is already in the screen gamma, while "background_1" is * at a gamma of 1.0. Paletted files have already been taken care of. */ -void /* PRIVATE */ -png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) +static void +png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr) { #ifdef PNG_READ_GAMMA_SUPPORTED png_const_bytep gamma_table = png_ptr->gamma_table; @@ -3445,12 +3220,12 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) png_const_uint_16pp gamma_16_from_1 = png_ptr->gamma_16_from_1; png_const_uint_16pp gamma_16_to_1 = png_ptr->gamma_16_to_1; int gamma_shift = png_ptr->gamma_shift; + int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0; #endif png_bytep sp; png_uint_32 i; png_uint_32 row_width = row_info->width; - int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0; int shift; png_debug(1, "in png_do_compose"); @@ -3471,11 +3246,12 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) if ((png_uint_16)((*sp >> shift) & 0x01) == png_ptr->trans_color.gray) { - *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); + unsigned int tmp = *sp & (0x7f7f >> (7 - shift)); + tmp |= png_ptr->background.gray << shift; + *sp = (png_byte)(tmp & 0xff); } - if (!shift) + if (shift == 0) { shift = 7; sp++; @@ -3499,20 +3275,22 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) if ((png_uint_16)((*sp >> shift) & 0x03) == png_ptr->trans_color.gray) { - *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); + unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); + tmp |= png_ptr->background.gray << shift; + *sp = (png_byte)(tmp & 0xff); } else { - png_byte p = (png_byte)((*sp >> shift) & 0x03); - png_byte g = (png_byte)((gamma_table [p | (p << 2) | - (p << 4) | (p << 6)] >> 6) & 0x03); - *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); - *sp |= (png_byte)(g << shift); + unsigned int p = (*sp >> shift) & 0x03; + unsigned int g = (gamma_table [p | (p << 2) | + (p << 4) | (p << 6)] >> 6) & 0x03; + unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); + tmp |= g << shift; + *sp = (png_byte)(tmp & 0xff); } - if (!shift) + if (shift == 0) { shift = 6; sp++; @@ -3533,11 +3311,12 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) if ((png_uint_16)((*sp >> shift) & 0x03) == png_ptr->trans_color.gray) { - *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); + unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); + tmp |= png_ptr->background.gray << shift; + *sp = (png_byte)(tmp & 0xff); } - if (!shift) + if (shift == 0) { shift = 6; sp++; @@ -3562,20 +3341,22 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) if ((png_uint_16)((*sp >> shift) & 0x0f) == png_ptr->trans_color.gray) { - *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); + unsigned int tmp = *sp & (0xf0f >> (4 - shift)); + tmp |= png_ptr->background.gray << shift; + *sp = (png_byte)(tmp & 0xff); } else { - png_byte p = (png_byte)((*sp >> shift) & 0x0f); - png_byte g = (png_byte)((gamma_table[p | - (p << 4)] >> 4) & 0x0f); - *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); - *sp |= (png_byte)(g << shift); + unsigned int p = (*sp >> shift) & 0x0f; + unsigned int g = (gamma_table[p | (p << 4)] >> 4) & + 0x0f; + unsigned int tmp = *sp & (0xf0f >> (4 - shift)); + tmp |= g << shift; + *sp = (png_byte)(tmp & 0xff); } - if (!shift) + if (shift == 0) { shift = 4; sp++; @@ -3596,11 +3377,12 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) if ((png_uint_16)((*sp >> shift) & 0x0f) == png_ptr->trans_color.gray) { - *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); + unsigned int tmp = *sp & (0xf0f >> (4 - shift)); + tmp |= png_ptr->background.gray << shift; + *sp = (png_byte)(tmp & 0xff); } - if (!shift) + if (shift == 0) { shift = 4; sp++; @@ -3656,8 +3438,10 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) if (v == png_ptr->trans_color.gray) { /* Background is already in screen gamma */ - *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray + & 0xff); } else @@ -3680,8 +3464,10 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) if (v == png_ptr->trans_color.gray) { - *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray + & 0xff); } } } @@ -3761,9 +3547,12 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) /* Background is already in screen gamma */ *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); - *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff); - *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff); - *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); } @@ -3804,9 +3593,12 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) { *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); - *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff); - *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff); - *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); } } @@ -3843,7 +3635,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) v = gamma_to_1[*sp]; png_composite(w, v, a, png_ptr->background_1.gray); - if (!optimize) + if (optimize == 0) w = gamma_from_1[w]; *sp = w; } @@ -3861,7 +3653,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) *sp = (png_byte)png_ptr->background.gray; else if (a < 0xff) - png_composite(*sp, *sp, a, png_ptr->background_1.gray); + png_composite(*sp, *sp, a, png_ptr->background.gray); } } } @@ -3889,7 +3681,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) else if (a == 0) { /* Background is already in screen gamma */ - *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff); + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); } @@ -3899,7 +3692,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; png_composite_16(v, g, a, png_ptr->background_1.gray); - if (optimize) + if (optimize != 0) w = v; else w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8]; @@ -3919,7 +3712,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) if (a == 0) { - *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff); + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); } @@ -3928,7 +3722,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) png_uint_16 g, v; g = (png_uint_16)(((*sp) << 8) + *(sp + 1)); - png_composite_16(v, g, a, png_ptr->background_1.gray); + png_composite_16(v, g, a, png_ptr->background.gray); *sp = (png_byte)((v >> 8) & 0xff); *(sp + 1) = (png_byte)(v & 0xff); } @@ -3972,17 +3766,17 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) v = gamma_to_1[*sp]; png_composite(w, v, a, png_ptr->background_1.red); - if (!optimize) w = gamma_from_1[w]; + if (optimize == 0) w = gamma_from_1[w]; *sp = w; v = gamma_to_1[*(sp + 1)]; png_composite(w, v, a, png_ptr->background_1.green); - if (!optimize) w = gamma_from_1[w]; + if (optimize == 0) w = gamma_from_1[w]; *(sp + 1) = w; v = gamma_to_1[*(sp + 2)]; png_composite(w, v, a, png_ptr->background_1.blue); - if (!optimize) w = gamma_from_1[w]; + if (optimize == 0) w = gamma_from_1[w]; *(sp + 2) = w; } } @@ -4049,9 +3843,12 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) /* Background is already in screen gamma */ *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); - *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff); - *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff); - *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); } @@ -4061,23 +3858,26 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; png_composite_16(w, v, a, png_ptr->background_1.red); - if (!optimize) - w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8]; + if (optimize == 0) + w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> + 8]; *sp = (png_byte)((w >> 8) & 0xff); *(sp + 1) = (png_byte)(w & 0xff); v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)]; png_composite_16(w, v, a, png_ptr->background_1.green); - if (!optimize) - w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8]; + if (optimize == 0) + w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> + 8]; *(sp + 2) = (png_byte)((w >> 8) & 0xff); *(sp + 3) = (png_byte)(w & 0xff); v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)]; png_composite_16(w, v, a, png_ptr->background_1.blue); - if (!optimize) - w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8]; + if (optimize == 0) + w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> + 8]; *(sp + 4) = (png_byte)((w >> 8) & 0xff); *(sp + 5) = (png_byte)(w & 0xff); @@ -4098,9 +3898,12 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) { *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); - *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff); - *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff); - *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); } @@ -4137,7 +3940,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) } } } -#endif +#endif /* READ_BACKGROUND || READ_ALPHA_MODE */ #ifdef PNG_READ_GAMMA_SUPPORTED /* Gamma correct the image, avoiding the alpha channel. Make sure @@ -4146,8 +3949,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) * is 16, use gamma_16_table and gamma_shift. Build these with * build_gamma_table(). */ -void /* PRIVATE */ -png_do_gamma(png_row_infop row_info, png_bytep row, png_structp png_ptr) +static void +png_do_gamma(png_row_infop row_info, png_bytep row, png_structrp png_ptr) { png_const_bytep gamma_table = png_ptr->gamma_table; png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table; @@ -4347,14 +4150,14 @@ png_do_gamma(png_row_infop row_info, png_bytep row, png_structp png_ptr) * linear.) Called only with color types that have an alpha channel. Needs the * from_1 tables. */ -void /* PRIVATE */ -png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structp png_ptr) +static void +png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr) { png_uint_32 row_width = row_info->width; png_debug(1, "in png_do_encode_alpha"); - if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0) { if (row_info->bit_depth == 8) { @@ -4413,7 +4216,7 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structp png_ptr) /* Expands a palette row to an RGB or RGBA row depending * upon whether you supply trans and num_trans. */ -void /* PRIVATE */ +static void png_do_expand_palette(png_row_infop row_info, png_bytep row, png_const_colorp palette, png_const_bytep trans_alpha, int num_trans) { @@ -4566,7 +4369,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, /* If the bit depth < 8, it is expanded to 8. Also, if the already * expanded transparency value is supplied, an alpha channel is built. */ -void /* PRIVATE */ +static void png_do_expand(png_row_infop row_info, png_bytep row, png_const_color_16p trans_color) { @@ -4580,7 +4383,7 @@ png_do_expand(png_row_infop row_info, png_bytep row, { if (row_info->color_type == PNG_COLOR_TYPE_GRAY) { - png_uint_16 gray = (png_uint_16)(trans_color ? trans_color->gray : 0); + unsigned int gray = trans_color != NULL ? trans_color->gray : 0; if (row_info->bit_depth < 8) { @@ -4588,7 +4391,7 @@ png_do_expand(png_row_infop row_info, png_bytep row, { case 1: { - gray = (png_uint_16)((gray & 0x01) * 0xff); + gray = (gray & 0x01) * 0xff; sp = row + (png_size_t)((row_width - 1) >> 3); dp = row + (png_size_t)row_width - 1; shift = 7 - (int)((row_width + 7) & 0x07); @@ -4616,7 +4419,7 @@ png_do_expand(png_row_infop row_info, png_bytep row, case 2: { - gray = (png_uint_16)((gray & 0x03) * 0x55); + gray = (gray & 0x03) * 0x55; sp = row + (png_size_t)((row_width - 1) >> 2); dp = row + (png_size_t)row_width - 1; shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); @@ -4641,7 +4444,7 @@ png_do_expand(png_row_infop row_info, png_bytep row, case 4: { - gray = (png_uint_16)((gray & 0x0f) * 0x11); + gray = (gray & 0x0f) * 0x11; sp = row + (png_size_t)((row_width - 1) >> 1); dp = row + (png_size_t)row_width - 1; shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); @@ -4694,8 +4497,8 @@ png_do_expand(png_row_infop row_info, png_bytep row, else if (row_info->bit_depth == 16) { - png_byte gray_high = (png_byte)((gray >> 8) & 0xff); - png_byte gray_low = (png_byte)(gray & 0xff); + unsigned int gray_high = (gray >> 8) & 0xff; + unsigned int gray_low = gray & 0xff; sp = row + row_info->rowbytes - 1; dp = row + (row_info->rowbytes << 1) - 1; for (i = 0; i < row_width; i++) @@ -4724,7 +4527,8 @@ png_do_expand(png_row_infop row_info, png_bytep row, row_width); } } - else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_color) + else if (row_info->color_type == PNG_COLOR_TYPE_RGB && + trans_color != NULL) { if (row_info->bit_depth == 8) { @@ -4793,10 +4597,10 @@ png_do_expand(png_row_infop row_info, png_bytep row, #endif #ifdef PNG_READ_EXPAND_16_SUPPORTED -/* If the bit depth is 8 and the colour type is not a palette type expand the +/* If the bit depth is 8 and the color type is not a palette type expand the * whole row to 16 bits. Has no effect otherwise. */ -void /* PRIVATE */ +static void png_do_expand_16(png_row_infop row_info, png_bytep row) { if (row_info->bit_depth == 8 && @@ -4824,7 +4628,7 @@ png_do_expand_16(png_row_infop row_info, png_bytep row) #endif #ifdef PNG_READ_QUANTIZE_SUPPORTED -void /* PRIVATE */ +static void png_do_quantize(png_row_infop row_info, png_bytep row, png_const_bytep palette_lookup, png_const_bytep quantize_lookup) { @@ -4915,70 +4719,304 @@ png_do_quantize(png_row_infop row_info, png_bytep row, } } } -#endif /* PNG_READ_QUANTIZE_SUPPORTED */ -#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ +#endif /* READ_QUANTIZE */ -#ifdef PNG_MNG_FEATURES_SUPPORTED -/* Undoes intrapixel differencing */ +/* Transform the row. The order of transformations is significant, + * and is very touchy. If you add a transformation, take care to + * decide how it fits in with the other transformations here. + */ void /* PRIVATE */ -png_do_read_intrapixel(png_row_infop row_info, png_bytep row) +png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info) { - png_debug(1, "in png_do_read_intrapixel"); + png_debug(1, "in png_do_read_transformations"); - if ( - (row_info->color_type & PNG_COLOR_MASK_COLOR)) + if (png_ptr->row_buf == NULL) { - int bytes_per_pixel; - png_uint_32 row_width = row_info->width; + /* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this + * error is incredibly rare and incredibly easy to debug without this + * information. + */ + png_error(png_ptr, "NULL row buffer"); + } - if (row_info->bit_depth == 8) + /* The following is debugging; prior to 1.5.4 the code was never compiled in; + * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro + * PNG_WARN_UNINITIALIZED_ROW removed. In 1.6 the new flag is set only for + * all transformations, however in practice the ROW_INIT always gets done on + * demand, if necessary. + */ + if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 && + (png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) + { + /* Application has failed to call either png_read_start_image() or + * png_read_update_info() after setting transforms that expand pixels. + * This check added to libpng-1.2.19 (but not enabled until 1.5.4). + */ + png_error(png_ptr, "Uninitialized row"); + } + +#ifdef PNG_READ_EXPAND_SUPPORTED + if ((png_ptr->transformations & PNG_EXPAND) != 0) + { + if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) { - png_bytep rp; - png_uint_32 i; - - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - bytes_per_pixel = 3; - - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - bytes_per_pixel = 4; - - else - return; - - for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) - { - *(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff); - *(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff); - } + png_do_expand_palette(row_info, png_ptr->row_buf + 1, + png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans); } - else if (row_info->bit_depth == 16) + + else { - png_bytep rp; - png_uint_32 i; - - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - bytes_per_pixel = 6; - - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - bytes_per_pixel = 8; + if (png_ptr->num_trans != 0 && + (png_ptr->transformations & PNG_EXPAND_tRNS) != 0) + png_do_expand(row_info, png_ptr->row_buf + 1, + &(png_ptr->trans_color)); else - return; - - for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) - { - png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); - png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); - png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); - png_uint_32 red = (png_uint_32)((s0 + s1 + 65536L) & 0xffffL); - png_uint_32 blue = (png_uint_32)((s2 + s1 + 65536L) & 0xffffL); - *(rp ) = (png_byte)((red >> 8) & 0xff); - *(rp + 1) = (png_byte)(red & 0xff); - *(rp + 4) = (png_byte)((blue >> 8) & 0xff); - *(rp + 5) = (png_byte)(blue & 0xff); - } + png_do_expand(row_info, png_ptr->row_buf + 1, + NULL); } } +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 && + (png_ptr->transformations & PNG_COMPOSE) == 0 && + (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) + png_do_strip_channel(row_info, png_ptr->row_buf + 1, + 0 /* at_start == false, because SWAP_ALPHA happens later */); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0) + { + int rgb_error = + png_do_rgb_to_gray(png_ptr, row_info, + png_ptr->row_buf + 1); + + if (rgb_error != 0) + { + png_ptr->rgb_to_gray_status=1; + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == + PNG_RGB_TO_GRAY_WARN) + png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == + PNG_RGB_TO_GRAY_ERR) + png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + } + } +#endif + +/* From Andreas Dilger e-mail to png-implement, 26 March 1998: + * + * In most cases, the "simple transparency" should be done prior to doing + * gray-to-RGB, or you will have to test 3x as many bytes to check if a + * pixel is transparent. You would also need to make sure that the + * transparency information is upgraded to RGB. + * + * To summarize, the current flow is: + * - Gray + simple transparency -> compare 1 or 2 gray bytes and composite + * with background "in place" if transparent, + * convert to RGB if necessary + * - Gray + alpha -> composite with gray background and remove alpha bytes, + * convert to RGB if necessary + * + * To support RGB backgrounds for gray images we need: + * - Gray + simple transparency -> convert to RGB + simple transparency, + * compare 3 or 6 bytes and composite with + * background "in place" if transparent + * (3x compare/pixel compared to doing + * composite with gray bkgrnd) + * - Gray + alpha -> convert to RGB + alpha, composite with background and + * remove alpha bytes (3x float + * operations/pixel compared with composite + * on gray background) + * + * Greg's change will do this. The reason it wasn't done before is for + * performance, as this increases the per-pixel operations. If we would check + * in advance if the background was gray or RGB, and position the gray-to-RGB + * transform appropriately, then it would save a lot of work/time. + */ + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* If gray -> RGB, do so now only if background is non-gray; else do later + * for performance reasons + */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 && + (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) == 0) + png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) + if ((png_ptr->transformations & PNG_COMPOSE) != 0) + png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED + if ((png_ptr->transformations & PNG_GAMMA) != 0 && +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* Because RGB_TO_GRAY does the gamma transform. */ + (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0 && +#endif +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) + /* Because PNG_COMPOSE does the gamma transform if there is something to + * do (if there is an alpha channel or transparency.) + */ + !((png_ptr->transformations & PNG_COMPOSE) && + ((png_ptr->num_trans != 0) || + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)) && +#endif + /* Because png_init_read_transformations transforms the palette, unless + * RGB_TO_GRAY will do the transform. + */ + (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) + png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr); +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 && + (png_ptr->transformations & PNG_COMPOSE) != 0 && + (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) + png_do_strip_channel(row_info, png_ptr->row_buf + 1, + 0 /* at_start == false, because SWAP_ALPHA happens later */); +#endif + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED + if ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 && + (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0) + png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr); +#endif + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0) + png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + /* There is no harm in doing both of these because only one has any effect, + * by putting the 'scale' option first if the app asks for scale (either by + * calling the API or in a TRANSFORM flag) this is what happens. + */ + if ((png_ptr->transformations & PNG_16_TO_8) != 0) + png_do_chop(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + if ((png_ptr->transformations & PNG_QUANTIZE) != 0) + { + png_do_quantize(row_info, png_ptr->row_buf + 1, + png_ptr->palette_lookup, png_ptr->quantize_index); + + if (row_info->rowbytes == 0) + png_error(png_ptr, "png_do_quantize returned rowbytes=0"); + } +#endif /* READ_QUANTIZE */ + +#ifdef PNG_READ_EXPAND_16_SUPPORTED + /* Do the expansion now, after all the arithmetic has been done. Notice + * that previous transformations can handle the PNG_EXPAND_16 flag if this + * is efficient (particularly true in the case of gamma correction, where + * better accuracy results faster!) + */ + if ((png_ptr->transformations & PNG_EXPAND_16) != 0) + png_do_expand_16(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* NOTE: moved here in 1.5.4 (from much later in this list.) */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 && + (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) != 0) + png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_INVERT_SUPPORTED + if ((png_ptr->transformations & PNG_INVERT_MONO) != 0) + png_do_invert(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0) + png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED + if ((png_ptr->transformations & PNG_SHIFT) != 0) + png_do_unshift(row_info, png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif + +#ifdef PNG_READ_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) != 0) + png_do_unpack(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Added at libpng-1.5.10 */ + if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && + png_ptr->num_palette_max >= 0) + png_do_check_palette_indexes(png_ptr, row_info); +#endif + +#ifdef PNG_READ_BGR_SUPPORTED + if ((png_ptr->transformations & PNG_BGR) != 0) + png_do_bgr(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + png_do_packswap(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED + if ((png_ptr->transformations & PNG_FILLER) != 0) + png_do_read_filler(row_info, png_ptr->row_buf + 1, + (png_uint_32)png_ptr->filler, png_ptr->flags); +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0) + png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_16BIT_SUPPORTED +#ifdef PNG_READ_SWAP_SUPPORTED + if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0) + png_do_swap(row_info, png_ptr->row_buf + 1); +#endif +#endif + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) + { + if (png_ptr->read_user_transform_fn != NULL) + (*(png_ptr->read_user_transform_fn)) /* User read transform function */ + (png_ptr, /* png_ptr */ + row_info, /* row_info: */ + /* png_uint_32 width; width of row */ + /* png_size_t rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED + if (png_ptr->user_transform_depth != 0) + row_info->bit_depth = png_ptr->user_transform_depth; + + if (png_ptr->user_transform_channels != 0) + row_info->channels = png_ptr->user_transform_channels; +#endif + row_info->pixel_depth = (png_byte)(row_info->bit_depth * + row_info->channels); + + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width); + } +#endif } -#endif /* PNG_MNG_FEATURES_SUPPORTED */ -#endif /* PNG_READ_SUPPORTED */ + +#endif /* READ_TRANSFORMS */ +#endif /* READ */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrutil.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrutil.c index 4a023090f87..68e5caff89c 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrutil.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrutil.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -46,10 +46,8 @@ #ifdef PNG_READ_SUPPORTED -#define png_strtod(p,a,b) strtod(a,b) - png_uint_32 PNGAPI -png_get_uint_31(png_structp png_ptr, png_const_bytep buf) +png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf) { png_uint_32 uval = png_get_uint_32(buf); @@ -68,7 +66,7 @@ png_get_uint_31(png_structp png_ptr, png_const_bytep buf) #define PNG_FIXED_ERROR (-1) static png_fixed_point /* PRIVATE */ -png_get_fixed_point(png_structp png_ptr, png_const_bytep buf) +png_get_fixed_point(png_structrp png_ptr, png_const_bytep buf) { png_uint_32 uval = png_get_uint_32(buf); @@ -115,10 +113,10 @@ png_int_32 (PNGAPI png_get_int_32)(png_const_bytep buf) { png_uint_32 uval = png_get_uint_32(buf); - if ((uval & 0x80000000L) == 0) /* non-negative */ + if ((uval & 0x80000000) == 0) /* non-negative */ return uval; - uval = (uval ^ 0xffffffffL) + 1; /* 2's complement: -x = ~x+1 */ + uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */ return -(png_int_32)uval; } @@ -126,7 +124,7 @@ png_get_int_32)(png_const_bytep buf) png_uint_16 (PNGAPI png_get_uint_16)(png_const_bytep buf) { - /* ANSI-C requires an int value to accommodate at least 16 bits so this + /* ANSI-C requires an int value to accomodate at least 16 bits so this * works and allows the compiler not to worry about possible narrowing * on 32 bit systems. (Pre-ANSI systems did not make integers smaller * than 16 bits either.) @@ -138,11 +136,11 @@ png_get_uint_16)(png_const_bytep buf) return (png_uint_16)val; } -#endif /* PNG_READ_INT_FUNCTIONS_SUPPORTED */ +#endif /* READ_INT_FUNCTIONS */ /* Read and check the PNG file signature */ void /* PRIVATE */ -png_read_sig(png_structp png_ptr, png_infop info_ptr) +png_read_sig(png_structrp png_ptr, png_inforp info_ptr) { png_size_t num_checked, num_to_check; @@ -161,7 +159,7 @@ png_read_sig(png_structp png_ptr, png_infop info_ptr) png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); png_ptr->sig_bytes = 8; - if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check) != 0) { if (num_checked < 4 && png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) @@ -177,7 +175,7 @@ png_read_sig(png_structp png_ptr, png_infop info_ptr) * Put the type name into png_ptr->chunk_name, and return the length. */ png_uint_32 /* PRIVATE */ -png_read_chunk_header(png_structp png_ptr) +png_read_chunk_header(png_structrp png_ptr) { png_byte buf[8]; png_uint_32 length; @@ -193,14 +191,14 @@ png_read_chunk_header(png_structp png_ptr) length = png_get_uint_31(png_ptr, buf); /* Put the chunk name into png_ptr->chunk_name. */ - png_memcpy(png_ptr->chunk_name, buf + 4, 4); + png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(buf+4); - png_debug2(0, "Reading %s chunk, length = %u", - png_ptr->chunk_name, length); + png_debug2(0, "Reading %lx chunk, length = %lu", + (unsigned long)png_ptr->chunk_name, (unsigned long)length); /* Reset the crc and run it over the chunk name. */ png_reset_crc(png_ptr); - png_calculate_crc(png_ptr, png_ptr->chunk_name, 4); + png_calculate_crc(png_ptr, buf + 4, 4); /* Check to see if chunk name is valid. */ png_check_chunk_name(png_ptr, png_ptr->chunk_name); @@ -214,7 +212,7 @@ png_read_chunk_header(png_structp png_ptr) /* Read data, and (optionally) run it through the CRC. */ void /* PRIVATE */ -png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) +png_crc_read(png_structrp png_ptr, png_bytep buf, png_uint_32 length) { if (png_ptr == NULL) return; @@ -224,41 +222,40 @@ png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) } /* Optionally skip data and then check the CRC. Depending on whether we - * are reading a ancillary or critical chunk, and how the program has set + * are reading an ancillary or critical chunk, and how the program has set * things up, we may calculate the CRC on the data and print a message. * Returns '1' if there was a CRC error, '0' otherwise. */ int /* PRIVATE */ -png_crc_finish(png_structp png_ptr, png_uint_32 skip) +png_crc_finish(png_structrp png_ptr, png_uint_32 skip) { - png_size_t i; - png_size_t istop = png_ptr->zbuf_size; - - for (i = (png_size_t)skip; i > istop; i -= istop) + /* The size of the local buffer for inflate is a good guess as to a + * reasonable size to use for buffering reads from the application. + */ + while (skip > 0) { - png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + png_uint_32 len; + png_byte tmpbuf[PNG_INFLATE_BUF_SIZE]; + + len = (sizeof tmpbuf); + if (len > skip) + len = skip; + skip -= len; + + png_crc_read(png_ptr, tmpbuf, len); } - if (i) + if (png_crc_error(png_ptr) != 0) { - png_crc_read(png_ptr, png_ptr->zbuf, i); - } - - if (png_crc_error(png_ptr)) - { - if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */ - !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) || - (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */ - (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))) + if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0 ? + (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0 : + (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE) != 0) { png_chunk_warning(png_ptr, "CRC error"); } else - { - png_chunk_benign_error(png_ptr, "CRC error"); - return (0); - } + png_chunk_error(png_ptr, "CRC error"); return (1); } @@ -270,22 +267,22 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip) * the data it has read thus far. */ int /* PRIVATE */ -png_crc_error(png_structp png_ptr) +png_crc_error(png_structrp png_ptr) { png_byte crc_bytes[4]; png_uint_32 crc; int need_crc = 1; - if (png_ptr->chunk_name[0] & 0x20) /* ancillary */ + if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0) { if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) need_crc = 0; } - else /* critical */ + else /* critical */ { - if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) + if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0) need_crc = 0; } @@ -296,7 +293,7 @@ png_crc_error(png_structp png_ptr) /* The chunk CRC must be serialized in a single I/O call. */ png_read_data(png_ptr, crc_bytes, 4); - if (need_crc) + if (need_crc != 0) { crc = png_get_uint_32(crc_bytes); return ((int)(crc != png_ptr->crc)); @@ -306,252 +303,522 @@ png_crc_error(png_structp png_ptr) return (0); } -#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED -static png_size_t -png_inflate(png_structp png_ptr, png_bytep data, png_size_t size, - png_bytep output, png_size_t output_size) +#if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\ + defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_sCAL_SUPPORTED) ||\ + defined(PNG_READ_sPLT_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) ||\ + defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_SEQUENTIAL_READ_SUPPORTED) +/* Manage the read buffer; this simply reallocates the buffer if it is not small + * enough (or if it is not allocated). The routine returns a pointer to the + * buffer; if an error occurs and 'warn' is set the routine returns NULL, else + * it will call png_error (via png_malloc) on failure. (warn == 2 means + * 'silent'). + */ +static png_bytep +png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn) { - png_size_t count = 0; + png_bytep buffer = png_ptr->read_buffer; - /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it can't - * even necessarily handle 65536 bytes) because the type uInt is "16 bits or - * more". Consequently it is necessary to chunk the input to zlib. This - * code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the maximum value - * that can be stored in a uInt.) It is possible to set ZLIB_IO_MAX to a - * lower value in pngpriv.h and this may sometimes have a performance - * advantage, because it forces access of the input data to be separated from - * at least some of the use by some period of time. - */ - png_ptr->zstream.next_in = data; - /* avail_in is set below from 'size' */ - png_ptr->zstream.avail_in = 0; - - while (1) + if (buffer != NULL && new_size > png_ptr->read_buffer_size) { - int ret, avail; + png_ptr->read_buffer = NULL; + png_ptr->read_buffer = NULL; + png_ptr->read_buffer_size = 0; + png_free(png_ptr, buffer); + buffer = NULL; + } - /* The setting of 'avail_in' used to be outside the loop, by setting it - * inside it is possible to chunk the input to zlib and simply rely on - * zlib to advance the 'next_in' pointer. This allows arbitrary amounts o - * data to be passed through zlib at the unavoidable cost of requiring a - * window save (memcpy of up to 32768 output bytes) every ZLIB_IO_MAX - * input bytes. - */ - if (png_ptr->zstream.avail_in == 0 && size > 0) + if (buffer == NULL) + { + buffer = png_voidcast(png_bytep, png_malloc_base(png_ptr, new_size)); + + if (buffer != NULL) { - if (size <= ZLIB_IO_MAX) - { - /* The value is less than ZLIB_IO_MAX so the cast is safe: */ - png_ptr->zstream.avail_in = (uInt)size; - size = 0; - } - - else - { - png_ptr->zstream.avail_in = ZLIB_IO_MAX; - size -= ZLIB_IO_MAX; - } + png_ptr->read_buffer = buffer; + png_ptr->read_buffer_size = new_size; } - /* Reset the output buffer each time round - we empty it - * after every inflate call. - */ - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = png_ptr->zbuf_size; - - ret = inflate(&png_ptr->zstream, Z_NO_FLUSH); - avail = png_ptr->zbuf_size - png_ptr->zstream.avail_out; - - /* First copy/count any new output - but only if we didn't - * get an error code. - */ - if ((ret == Z_OK || ret == Z_STREAM_END) && avail > 0) + else if (warn < 2) /* else silent */ { - png_size_t space = avail; /* > 0, see above */ + if (warn != 0) + png_chunk_warning(png_ptr, "insufficient memory to read chunk"); - if (output != 0 && output_size > count) - { - png_size_t copy = output_size - count; + else + png_chunk_error(png_ptr, "insufficient memory to read chunk"); + } + } - if (space < copy) - copy = space; + return buffer; +} +#endif /* READ_iCCP|iTXt|pCAL|sCAL|sPLT|tEXt|zTXt|SEQUENTIAL_READ */ - png_memcpy(output + count, png_ptr->zbuf, copy); - } - count += space; +/* png_inflate_claim: claim the zstream for some nefarious purpose that involves + * decompression. Returns Z_OK on success, else a zlib error code. It checks + * the owner but, in final release builds, just issues a warning if some other + * chunk apparently owns the stream. Prior to release it does a png_error. + */ +static int +png_inflate_claim(png_structrp png_ptr, png_uint_32 owner) +{ + if (png_ptr->zowner != 0) + { + char msg[64]; + + PNG_STRING_FROM_CHUNK(msg, png_ptr->zowner); + /* So the message that results is " using zstream"; this is an + * internal error, but is very useful for debugging. i18n requirements + * are minimal. + */ + (void)png_safecat(msg, (sizeof msg), 4, " using zstream"); +#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC + png_chunk_warning(png_ptr, msg); + png_ptr->zowner = 0; +#else + png_chunk_error(png_ptr, msg); +#endif + } + + /* Implementation note: unlike 'png_deflate_claim' this internal function + * does not take the size of the data as an argument. Some efficiency could + * be gained by using this when it is known *if* the zlib stream itself does + * not record the number; however, this is an illusion: the original writer + * of the PNG may have selected a lower window size, and we really must + * follow that because, for systems with with limited capabilities, we + * would otherwise reject the application's attempts to use a smaller window + * size (zlib doesn't have an interface to say "this or lower"!). + * + * inflateReset2 was added to zlib 1.2.4; before this the window could not be + * reset, therefore it is necessary to always allocate the maximum window + * size with earlier zlibs just in case later compressed chunks need it. + */ + { + int ret; /* zlib return code */ +#if PNG_ZLIB_VERNUM >= 0x1240 + +# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW) + int window_bits; + + if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) == + PNG_OPTION_ON) + window_bits = 15; + + else + window_bits = 0; +# else +# define window_bits 0 +# endif +#endif + + /* Set this for safety, just in case the previous owner left pointers to + * memory allocations. + */ + png_ptr->zstream.next_in = NULL; + png_ptr->zstream.avail_in = 0; + png_ptr->zstream.next_out = NULL; + png_ptr->zstream.avail_out = 0; + + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0) + { +#if PNG_ZLIB_VERNUM < 0x1240 + ret = inflateReset(&png_ptr->zstream); +#else + ret = inflateReset2(&png_ptr->zstream, window_bits); +#endif + } + + else + { +#if PNG_ZLIB_VERNUM < 0x1240 + ret = inflateInit(&png_ptr->zstream); +#else + ret = inflateInit2(&png_ptr->zstream, window_bits); +#endif + + if (ret == Z_OK) + png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED; } if (ret == Z_OK) - continue; + png_ptr->zowner = owner; - /* Termination conditions - always reset the zstream, it - * must be left in inflateInit state. + else + png_zstream_error(png_ptr, ret); + + return ret; + } + +#ifdef window_bits +# undef window_bits +#endif +} + +#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED +/* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to + * allow the caller to do multiple calls if required. If the 'finish' flag is + * set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must + * be returned or there has been a problem, otherwise Z_SYNC_FLUSH is used and + * Z_OK or Z_STREAM_END will be returned on success. + * + * The input and output sizes are updated to the actual amounts of data consumed + * or written, not the amount available (as in a z_stream). The data pointers + * are not changed, so the next input is (data+input_size) and the next + * available output is (output+output_size). + */ +static int +png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish, + /* INPUT: */ png_const_bytep input, png_uint_32p input_size_ptr, + /* OUTPUT: */ png_bytep output, png_alloc_size_t *output_size_ptr) +{ + if (png_ptr->zowner == owner) /* Else not claimed */ + { + int ret; + png_alloc_size_t avail_out = *output_size_ptr; + png_uint_32 avail_in = *input_size_ptr; + + /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it + * can't even necessarily handle 65536 bytes) because the type uInt is + * "16 bits or more". Consequently it is necessary to chunk the input to + * zlib. This code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the + * maximum value that can be stored in a uInt.) It is possible to set + * ZLIB_IO_MAX to a lower value in pngpriv.h and this may sometimes have + * a performance advantage, because it reduces the amount of data accessed + * at each step and that may give the OS more time to page it in. */ + png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input); + /* avail_in and avail_out are set below from 'size' */ png_ptr->zstream.avail_in = 0; - inflateReset(&png_ptr->zstream); + png_ptr->zstream.avail_out = 0; - if (ret == Z_STREAM_END) - return count; /* NOTE: may be zero. */ - - /* Now handle the error codes - the API always returns 0 - * and the error message is dumped into the uncompressed - * buffer if available. + /* Read directly into the output if it is available (this is set to + * a local buffer below if output is NULL). */ -# ifdef PNG_WARNINGS_SUPPORTED + if (output != NULL) + png_ptr->zstream.next_out = output; + + do { - png_const_charp msg; + uInt avail; + Byte local_buffer[PNG_INFLATE_BUF_SIZE]; - if (png_ptr->zstream.msg != 0) - msg = png_ptr->zstream.msg; + /* zlib INPUT BUFFER */ + /* The setting of 'avail_in' used to be outside the loop; by setting it + * inside it is possible to chunk the input to zlib and simply rely on + * zlib to advance the 'next_in' pointer. This allows arbitrary + * amounts of data to be passed through zlib at the unavoidable cost of + * requiring a window save (memcpy of up to 32768 output bytes) + * every ZLIB_IO_MAX input bytes. + */ + avail_in += png_ptr->zstream.avail_in; /* not consumed last time */ - else switch (ret) + avail = ZLIB_IO_MAX; + + if (avail_in < avail) + avail = (uInt)avail_in; /* safe: < than ZLIB_IO_MAX */ + + avail_in -= avail; + png_ptr->zstream.avail_in = avail; + + /* zlib OUTPUT BUFFER */ + avail_out += png_ptr->zstream.avail_out; /* not written last time */ + + avail = ZLIB_IO_MAX; /* maximum zlib can process */ + + if (output == NULL) { - case Z_BUF_ERROR: - msg = "Buffer error in compressed datastream"; - break; - - case Z_DATA_ERROR: - msg = "Data error in compressed datastream"; - break; - - default: - msg = "Incomplete compressed datastream"; - break; + /* Reset the output buffer each time round if output is NULL and + * make available the full buffer, up to 'remaining_space' + */ + png_ptr->zstream.next_out = local_buffer; + if ((sizeof local_buffer) < avail) + avail = (sizeof local_buffer); } - png_chunk_warning(png_ptr, msg); - } -# endif + if (avail_out < avail) + avail = (uInt)avail_out; /* safe: < ZLIB_IO_MAX */ - /* 0 means an error - notice that this code simply ignores - * zero length compressed chunks as a result. + png_ptr->zstream.avail_out = avail; + avail_out -= avail; + + /* zlib inflate call */ + /* In fact 'avail_out' may be 0 at this point, that happens at the end + * of the read when the final LZ end code was not passed at the end of + * the previous chunk of input data. Tell zlib if we have reached the + * end of the output buffer. + */ + ret = inflate(&png_ptr->zstream, avail_out > 0 ? Z_NO_FLUSH : + (finish ? Z_FINISH : Z_SYNC_FLUSH)); + } while (ret == Z_OK); + + /* For safety kill the local buffer pointer now */ + if (output == NULL) + png_ptr->zstream.next_out = NULL; + + /* Claw back the 'size' and 'remaining_space' byte counts. */ + avail_in += png_ptr->zstream.avail_in; + avail_out += png_ptr->zstream.avail_out; + + /* Update the input and output sizes; the updated values are the amount + * consumed or written, effectively the inverse of what zlib uses. */ - return 0; + if (avail_out > 0) + *output_size_ptr -= avail_out; + + if (avail_in > 0) + *input_size_ptr -= avail_in; + + /* Ensure png_ptr->zstream.msg is set (even in the success case!) */ + png_zstream_error(png_ptr, ret); + return ret; + } + + else + { + /* This is a bad internal error. The recovery assigns to the zstream msg + * pointer, which is not owned by the caller, but this is safe; it's only + * used on errors! + */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed"); + return Z_STREAM_ERROR; } } /* - * Decompress trailing data in a chunk. The assumption is that chunkdata + * Decompress trailing data in a chunk. The assumption is that read_buffer * points at an allocated area holding the contents of a chunk with a * trailing compressed part. What we get back is an allocated area * holding the original prefix part and an uncompressed version of the * trailing part (the malloc area passed in is freed). */ -void /* PRIVATE */ -png_decompress_chunk(png_structp png_ptr, int comp_type, - png_size_t chunklength, - png_size_t prefix_size, png_size_t *newlength) +static int +png_decompress_chunk(png_structrp png_ptr, + png_uint_32 chunklength, png_uint_32 prefix_size, + png_alloc_size_t *newlength /* must be initialized to the maximum! */, + int terminate /*add a '\0' to the end of the uncompressed data*/) { - /* The caller should guarantee this */ - if (prefix_size > chunklength) + /* TODO: implement different limits for different types of chunk. + * + * The caller supplies *newlength set to the maximum length of the + * uncompressed data, but this routine allocates space for the prefix and + * maybe a '\0' terminator too. We have to assume that 'prefix_size' is + * limited only by the maximum chunk size. + */ + png_alloc_size_t limit = PNG_SIZE_MAX; + +# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED + if (png_ptr->user_chunk_malloc_max > 0 && + png_ptr->user_chunk_malloc_max < limit) + limit = png_ptr->user_chunk_malloc_max; +# elif PNG_USER_CHUNK_MALLOC_MAX > 0 + if (PNG_USER_CHUNK_MALLOC_MAX < limit) + limit = PNG_USER_CHUNK_MALLOC_MAX; +# endif + + if (limit >= prefix_size + (terminate != 0)) { - /* The recovery is to delete the chunk. */ - png_warning(png_ptr, "invalid chunklength"); - prefix_size = 0; /* To delete everything */ - } + int ret; - else if (comp_type == PNG_COMPRESSION_TYPE_BASE) - { - png_size_t expanded_size = png_inflate(png_ptr, - (png_bytep)(png_ptr->chunkdata + prefix_size), - chunklength - prefix_size, - 0, /* output */ - 0); /* output size */ + limit -= prefix_size + (terminate != 0); - /* Now check the limits on this chunk - if the limit fails the - * compressed data will be removed, the prefix will remain. - */ -#ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED - if (png_ptr->user_chunk_malloc_max && - (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1)) -#else -# ifdef PNG_USER_CHUNK_MALLOC_MAX - if ((PNG_USER_CHUNK_MALLOC_MAX > 0) && - prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1) -# endif -#endif - png_warning(png_ptr, "Exceeded size limit while expanding chunk"); + if (limit < *newlength) + *newlength = limit; - /* If the size is zero either there was an error and a message - * has already been output (warning) or the size really is zero - * and we have nothing to do - the code will exit through the - * error case below. - */ -#if defined(PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED) || \ - defined(PNG_USER_CHUNK_MALLOC_MAX) - else if (expanded_size > 0) -#else - if (expanded_size > 0) -#endif + /* Now try to claim the stream. */ + ret = png_inflate_claim(png_ptr, png_ptr->chunk_name); + + if (ret == Z_OK) { - /* Success (maybe) - really uncompress the chunk. */ - png_size_t new_size = 0; - png_charp text = png_malloc_warn(png_ptr, - prefix_size + expanded_size + 1); + png_uint_32 lzsize = chunklength - prefix_size; - if (text != NULL) + ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/, + /* input: */ png_ptr->read_buffer + prefix_size, &lzsize, + /* output: */ NULL, newlength); + + if (ret == Z_STREAM_END) { - png_memcpy(text, png_ptr->chunkdata, prefix_size); - new_size = png_inflate(png_ptr, - (png_bytep)(png_ptr->chunkdata + prefix_size), - chunklength - prefix_size, - (png_bytep)(text + prefix_size), expanded_size); - text[prefix_size + expanded_size] = 0; /* just in case */ - - if (new_size == expanded_size) + /* Use 'inflateReset' here, not 'inflateReset2' because this + * preserves the previously decided window size (otherwise it would + * be necessary to store the previous window size.) In practice + * this doesn't matter anyway, because png_inflate will call inflate + * with Z_FINISH in almost all cases, so the window will not be + * maintained. + */ + if (inflateReset(&png_ptr->zstream) == Z_OK) { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = text; - *newlength = prefix_size + expanded_size; - return; /* The success return! */ + /* Because of the limit checks above we know that the new, + * expanded, size will fit in a size_t (let alone an + * png_alloc_size_t). Use png_malloc_base here to avoid an + * extra OOM message. + */ + png_alloc_size_t new_size = *newlength; + png_alloc_size_t buffer_size = prefix_size + new_size + + (terminate != 0); + png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr, + buffer_size)); + + if (text != NULL) + { + ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/, + png_ptr->read_buffer + prefix_size, &lzsize, + text + prefix_size, newlength); + + if (ret == Z_STREAM_END) + { + if (new_size == *newlength) + { + if (terminate != 0) + text[prefix_size + *newlength] = 0; + + if (prefix_size > 0) + memcpy(text, png_ptr->read_buffer, prefix_size); + + { + png_bytep old_ptr = png_ptr->read_buffer; + + png_ptr->read_buffer = text; + png_ptr->read_buffer_size = buffer_size; + text = old_ptr; /* freed below */ + } + } + + else + { + /* The size changed on the second read, there can be no + * guarantee that anything is correct at this point. + * The 'msg' pointer has been set to "unexpected end of + * LZ stream", which is fine, but return an error code + * that the caller won't accept. + */ + ret = PNG_UNEXPECTED_ZLIB_RETURN; + } + } + + else if (ret == Z_OK) + ret = PNG_UNEXPECTED_ZLIB_RETURN; /* for safety */ + + /* Free the text pointer (this is the old read_buffer on + * success) + */ + png_free(png_ptr, text); + text = NULL; + + /* This really is very benign, but it's still an error because + * the extra space may otherwise be used as a Trojan Horse. + */ + if (ret == Z_STREAM_END && + chunklength - prefix_size != lzsize) + png_chunk_benign_error(png_ptr, "extra compressed data"); + } + + else + { + /* Out of memory allocating the buffer */ + ret = Z_MEM_ERROR; + png_zstream_error(png_ptr, Z_MEM_ERROR); + } } - png_warning(png_ptr, "png_inflate logic error"); - png_free(png_ptr, text); + else + { + /* inflateReset failed, store the error message */ + png_zstream_error(png_ptr, ret); + + if (ret == Z_STREAM_END) + ret = PNG_UNEXPECTED_ZLIB_RETURN; + } } - else - png_warning(png_ptr, "Not enough memory to decompress chunk"); + else if (ret == Z_OK) + ret = PNG_UNEXPECTED_ZLIB_RETURN; + + /* Release the claimed stream */ + png_ptr->zowner = 0; } + + else /* the claim failed */ if (ret == Z_STREAM_END) /* impossible! */ + ret = PNG_UNEXPECTED_ZLIB_RETURN; + + return ret; } - else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ + else { - PNG_WARNING_PARAMETERS(p) - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, comp_type); - png_formatted_warning(png_ptr, p, "Unknown zTXt compression type @1"); - - /* The recovery is to simply drop the data. */ + /* Application/configuration limits exceeded */ + png_zstream_error(png_ptr, Z_MEM_ERROR); + return Z_MEM_ERROR; } - - /* Generic error return - leave the prefix, delete the compressed - * data, reallocate the chunkdata to remove the potentially large - * amount of compressed data. - */ - { - png_charp text = png_malloc_warn(png_ptr, prefix_size + 1); - - if (text != NULL) - { - if (prefix_size > 0) - png_memcpy(text, png_ptr->chunkdata, prefix_size); - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = text; - - /* This is an extra zero in the 'uncompressed' part. */ - *(png_ptr->chunkdata + prefix_size) = 0x00; - } - /* Ignore a malloc error here - it is safe. */ - } - - *newlength = prefix_size; } -#endif /* PNG_READ_COMPRESSED_TEXT_SUPPORTED */ +#endif /* READ_COMPRESSED_TEXT */ + +#ifdef PNG_READ_iCCP_SUPPORTED +/* Perform a partial read and decompress, producing 'avail_out' bytes and + * reading from the current chunk as required. + */ +static int +png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size, + png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size, + int finish) +{ + if (png_ptr->zowner == png_ptr->chunk_name) + { + int ret; + + /* next_in and avail_in must have been initialized by the caller. */ + png_ptr->zstream.next_out = next_out; + png_ptr->zstream.avail_out = 0; /* set in the loop */ + + do + { + if (png_ptr->zstream.avail_in == 0) + { + if (read_size > *chunk_bytes) + read_size = (uInt)*chunk_bytes; + *chunk_bytes -= read_size; + + if (read_size > 0) + png_crc_read(png_ptr, read_buffer, read_size); + + png_ptr->zstream.next_in = read_buffer; + png_ptr->zstream.avail_in = read_size; + } + + if (png_ptr->zstream.avail_out == 0) + { + uInt avail = ZLIB_IO_MAX; + if (avail > *out_size) + avail = (uInt)*out_size; + *out_size -= avail; + + png_ptr->zstream.avail_out = avail; + } + + /* Use Z_SYNC_FLUSH when there is no more chunk data to ensure that all + * the available output is produced; this allows reading of truncated + * streams. + */ + ret = inflate(&png_ptr->zstream, + *chunk_bytes > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH)); + } + while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0)); + + *out_size += png_ptr->zstream.avail_out; + png_ptr->zstream.avail_out = 0; /* Should not be required, but is safe */ + + /* Ensure the error message pointer is always set: */ + png_zstream_error(png_ptr, ret); + return ret; + } + + else + { + png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed"); + return Z_STREAM_ERROR; + } +} +#endif /* Read and check the IDHR chunk */ + void /* PRIVATE */ -png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_byte buf[13]; png_uint_32 width, height; @@ -560,12 +827,12 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_debug(1, "in png_handle_IHDR"); - if (png_ptr->mode & PNG_HAVE_IHDR) - png_error(png_ptr, "Out of place IHDR"); + if ((png_ptr->mode & PNG_HAVE_IHDR) != 0) + png_chunk_error(png_ptr, "out of place"); /* Check the length */ if (length != 13) - png_error(png_ptr, "Invalid IHDR chunk"); + png_chunk_error(png_ptr, "invalid"); png_ptr->mode |= PNG_HAVE_IHDR; @@ -614,8 +881,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } /* Set up other useful info */ - png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * - png_ptr->channels); + png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * png_ptr->channels); png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width); png_debug1(3, "bit_depth = %d", png_ptr->bit_depth); png_debug1(3, "channels = %d", png_ptr->channels); @@ -626,7 +892,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) /* Read and check the palette */ void /* PRIVATE */ -png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_color palette[PNG_MAX_PALETTE_LENGTH]; int num, i; @@ -636,26 +902,33 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_debug(1, "in png_handle_PLTE"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before PLTE"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + /* Moved to before the 'after IDAT' check below because otherwise duplicate + * PLTE chunks are potentially ignored (the spec says there shall not be more + * than one PLTE, the error is not treated as benign, so this check trumps + * the requirement that PLTE appears before IDAT.) + */ + else if ((png_ptr->mode & PNG_HAVE_PLTE) != 0) + png_chunk_error(png_ptr, "duplicate"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) { - png_warning(png_ptr, "Invalid PLTE after IDAT"); + /* This is benign because the non-benign error happened before, when an + * IDAT was encountered in a color-mapped image with no PLTE. + */ png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - else if (png_ptr->mode & PNG_HAVE_PLTE) - png_error(png_ptr, "Duplicate PLTE chunk"); - png_ptr->mode |= PNG_HAVE_PLTE; - if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) { - png_warning(png_ptr, - "Ignoring PLTE chunk in grayscale PNG"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "ignored in grayscale PNG"); return; } @@ -669,19 +942,18 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3) { + png_crc_finish(png_ptr, length); + if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) - { - png_warning(png_ptr, "Invalid palette chunk"); - png_crc_finish(png_ptr, length); - return; - } + png_chunk_benign_error(png_ptr, "invalid"); else - { - png_error(png_ptr, "Invalid palette chunk"); - } + png_chunk_error(png_ptr, "invalid"); + + return; } + /* The cast is safe because 'length' is less than 3*PNG_MAX_PALETTE_LENGTH */ num = (int)length / 3; #ifdef PNG_POINTER_INDEXING_SUPPORTED @@ -720,214 +992,196 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } #ifndef PNG_READ_OPT_PLTE_SUPPORTED - else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */ + else if (png_crc_error(png_ptr) != 0) /* Only if we have a CRC error */ { /* If we don't want to use the data from an ancillary chunk, * we have two options: an error abort, or a warning and we * ignore the data in this chunk (which should be OK, since * it's considered ancillary for a RGB or RGBA image). + * + * IMPLEMENTATION NOTE: this is only here because png_crc_finish uses the + * chunk type to determine whether to check the ancillary or the critical + * flags. */ - if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE)) + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE) == 0) { - if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) - { - png_chunk_benign_error(png_ptr, "CRC error"); - } + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) != 0) + return; else - { - png_chunk_warning(png_ptr, "CRC error"); - return; - } + png_chunk_error(png_ptr, "CRC error"); } /* Otherwise, we (optionally) emit a warning and use the chunk. */ - else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) - { + else if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0) png_chunk_warning(png_ptr, "CRC error"); - } } #endif + /* TODO: png_set_PLTE has the side effect of setting png_ptr->palette to its + * own copy of the palette. This has the side effect that when png_start_row + * is called (this happens after any call to png_read_update_info) the + * info_ptr palette gets changed. This is extremely unexpected and + * confusing. + * + * Fix this by not sharing the palette in this way. + */ png_set_PLTE(png_ptr, info_ptr, palette, num); + /* The three chunks, bKGD, hIST and tRNS *must* appear after PLTE and before + * IDAT. Prior to 1.6.0 this was not checked; instead the code merely + * checked the apparent validity of a tRNS chunk inserted before PLTE on a + * palette PNG. 1.6.0 attempts to rigorously follow the standard and + * therefore does a benign error if the erroneous condition is detected *and* + * cancels the tRNS if the benign error returns. The alternative is to + * amend the standard since it would be rather hypocritical of the standards + * maintainers to ignore it. + */ #ifdef PNG_READ_tRNS_SUPPORTED - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + if (png_ptr->num_trans > 0 || + (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0)) { - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) - { - if (png_ptr->num_trans > (png_uint_16)num) - { - png_warning(png_ptr, "Truncating incorrect tRNS chunk length"); - png_ptr->num_trans = (png_uint_16)num; - } + /* Cancel this because otherwise it would be used if the transforms + * require it. Don't cancel the 'valid' flag because this would prevent + * detection of duplicate chunks. + */ + png_ptr->num_trans = 0; - if (info_ptr->num_trans > (png_uint_16)num) - { - png_warning(png_ptr, "Truncating incorrect info tRNS chunk length"); - info_ptr->num_trans = (png_uint_16)num; - } - } + if (info_ptr != NULL) + info_ptr->num_trans = 0; + + png_chunk_benign_error(png_ptr, "tRNS must be after"); } #endif +#ifdef PNG_READ_hIST_SUPPORTED + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0) + png_chunk_benign_error(png_ptr, "hIST must be after"); +#endif + +#ifdef PNG_READ_bKGD_SUPPORTED + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0) + png_chunk_benign_error(png_ptr, "bKGD must be after"); +#endif } void /* PRIVATE */ -png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_IEND(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_debug(1, "in png_handle_IEND"); - if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT)) - { - png_error(png_ptr, "No image in file"); - } + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0 || + (png_ptr->mode & PNG_HAVE_IDAT) == 0) + png_chunk_error(png_ptr, "out of place"); png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND); - if (length != 0) - { - png_warning(png_ptr, "Incorrect IEND chunk length"); - } - png_crc_finish(png_ptr, length); - PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */ + if (length != 0) + png_chunk_benign_error(png_ptr, "invalid"); + + PNG_UNUSED(info_ptr) } #ifdef PNG_READ_gAMA_SUPPORTED void /* PRIVATE */ -png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_fixed_point igamma; png_byte buf[4]; png_debug(1, "in png_handle_gAMA"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before gAMA"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) { - png_warning(png_ptr, "Invalid gAMA after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->mode & PNG_HAVE_PLTE) - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place gAMA chunk"); - - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) -#ifdef PNG_READ_sRGB_SUPPORTED - && !(info_ptr->valid & PNG_INFO_sRGB) -#endif - ) - { - png_warning(png_ptr, "Duplicate gAMA chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } if (length != 4) { - png_warning(png_ptr, "Incorrect gAMA chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } png_crc_read(png_ptr, buf, 4); - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) return; igamma = png_get_fixed_point(NULL, buf); - /* Check for zero gamma or an error. */ - if (igamma <= 0) - { - png_warning(png_ptr, - "Ignoring gAMA chunk with out of range gamma"); - - return; - } - -# ifdef PNG_READ_sRGB_SUPPORTED - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) - { - if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) - { - PNG_WARNING_PARAMETERS(p) - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, igamma); - png_formatted_warning(png_ptr, p, - "Ignoring incorrect gAMA value @1 when sRGB is also present"); - return; - } - } -# endif /* PNG_READ_sRGB_SUPPORTED */ - -# ifdef PNG_READ_GAMMA_SUPPORTED - /* Gamma correction on read is supported. */ - png_ptr->gamma = igamma; -# endif - /* And set the 'info' structure members. */ - png_set_gAMA_fixed(png_ptr, info_ptr, igamma); + png_colorspace_set_gamma(png_ptr, &png_ptr->colorspace, igamma); + png_colorspace_sync(png_ptr, info_ptr); } #endif #ifdef PNG_READ_sBIT_SUPPORTED void /* PRIVATE */ -png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { - png_size_t truelen; + unsigned int truelen, i; + png_byte sample_depth; png_byte buf[4]; png_debug(1, "in png_handle_sBIT"); - buf[0] = buf[1] = buf[2] = buf[3] = 0; + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before sBIT"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) { - png_warning(png_ptr, "Invalid sBIT after IDAT"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - else if (png_ptr->mode & PNG_HAVE_PLTE) + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) != 0) { - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place sBIT chunk"); - } - - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)) - { - png_warning(png_ptr, "Duplicate sBIT chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); return; } if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { truelen = 3; + sample_depth = 8; + } else - truelen = (png_size_t)png_ptr->channels; + { + truelen = png_ptr->channels; + sample_depth = png_ptr->bit_depth; + } if (length != truelen || length > 4) { - png_warning(png_ptr, "Incorrect sBIT chunk length"); + png_chunk_benign_error(png_ptr, "invalid"); png_crc_finish(png_ptr, length); return; } + buf[0] = buf[1] = buf[2] = buf[3] = sample_depth; png_crc_read(png_ptr, buf, truelen); - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) return; - if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + for (i=0; i sample_depth) + { + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) { png_ptr->sig_bit.red = buf[0]; png_ptr->sig_bit.green = buf[1]; @@ -950,377 +1204,416 @@ png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_READ_cHRM_SUPPORTED void /* PRIVATE */ -png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_byte buf[32]; - png_fixed_point x_white, y_white, x_red, y_red, x_green, y_green, x_blue, - y_blue; + png_xy xy; png_debug(1, "in png_handle_cHRM"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before cHRM"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) { - png_warning(png_ptr, "Invalid cHRM after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->mode & PNG_HAVE_PLTE) - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Missing PLTE before cHRM"); - - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM) -# ifdef PNG_READ_sRGB_SUPPORTED - && !(info_ptr->valid & PNG_INFO_sRGB) -# endif - ) - { - png_warning(png_ptr, "Duplicate cHRM chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } if (length != 32) { - png_warning(png_ptr, "Incorrect cHRM chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } png_crc_read(png_ptr, buf, 32); - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) return; - x_white = png_get_fixed_point(NULL, buf); - y_white = png_get_fixed_point(NULL, buf + 4); - x_red = png_get_fixed_point(NULL, buf + 8); - y_red = png_get_fixed_point(NULL, buf + 12); - x_green = png_get_fixed_point(NULL, buf + 16); - y_green = png_get_fixed_point(NULL, buf + 20); - x_blue = png_get_fixed_point(NULL, buf + 24); - y_blue = png_get_fixed_point(NULL, buf + 28); + xy.whitex = png_get_fixed_point(NULL, buf); + xy.whitey = png_get_fixed_point(NULL, buf + 4); + xy.redx = png_get_fixed_point(NULL, buf + 8); + xy.redy = png_get_fixed_point(NULL, buf + 12); + xy.greenx = png_get_fixed_point(NULL, buf + 16); + xy.greeny = png_get_fixed_point(NULL, buf + 20); + xy.bluex = png_get_fixed_point(NULL, buf + 24); + xy.bluey = png_get_fixed_point(NULL, buf + 28); - if (x_white == PNG_FIXED_ERROR || - y_white == PNG_FIXED_ERROR || - x_red == PNG_FIXED_ERROR || - y_red == PNG_FIXED_ERROR || - x_green == PNG_FIXED_ERROR || - y_green == PNG_FIXED_ERROR || - x_blue == PNG_FIXED_ERROR || - y_blue == PNG_FIXED_ERROR) + if (xy.whitex == PNG_FIXED_ERROR || + xy.whitey == PNG_FIXED_ERROR || + xy.redx == PNG_FIXED_ERROR || + xy.redy == PNG_FIXED_ERROR || + xy.greenx == PNG_FIXED_ERROR || + xy.greeny == PNG_FIXED_ERROR || + xy.bluex == PNG_FIXED_ERROR || + xy.bluey == PNG_FIXED_ERROR) { - png_warning(png_ptr, "Ignoring cHRM chunk with negative chromaticities"); + png_chunk_benign_error(png_ptr, "invalid values"); return; } -#ifdef PNG_READ_sRGB_SUPPORTED - if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB)) + /* If a colorspace error has already been output skip this chunk */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0) + return; + + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0) { - if (PNG_OUT_OF_RANGE(x_white, 31270, 1000) || - PNG_OUT_OF_RANGE(y_white, 32900, 1000) || - PNG_OUT_OF_RANGE(x_red, 64000L, 1000) || - PNG_OUT_OF_RANGE(y_red, 33000, 1000) || - PNG_OUT_OF_RANGE(x_green, 30000, 1000) || - PNG_OUT_OF_RANGE(y_green, 60000L, 1000) || - PNG_OUT_OF_RANGE(x_blue, 15000, 1000) || - PNG_OUT_OF_RANGE(y_blue, 6000, 1000)) - { - PNG_WARNING_PARAMETERS(p) - - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, x_white); - png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_fixed, y_white); - png_warning_parameter_signed(p, 3, PNG_NUMBER_FORMAT_fixed, x_red); - png_warning_parameter_signed(p, 4, PNG_NUMBER_FORMAT_fixed, y_red); - png_warning_parameter_signed(p, 5, PNG_NUMBER_FORMAT_fixed, x_green); - png_warning_parameter_signed(p, 6, PNG_NUMBER_FORMAT_fixed, y_green); - png_warning_parameter_signed(p, 7, PNG_NUMBER_FORMAT_fixed, x_blue); - png_warning_parameter_signed(p, 8, PNG_NUMBER_FORMAT_fixed, y_blue); - - png_formatted_warning(png_ptr, p, - "Ignoring incorrect cHRM white(@1,@2) r(@3,@4)g(@5,@6)b(@7,@8) " - "when sRGB is also present"); - } + png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID; + png_colorspace_sync(png_ptr, info_ptr); + png_chunk_benign_error(png_ptr, "duplicate"); return; } -#endif /* PNG_READ_sRGB_SUPPORTED */ -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - /* Store the _white values as default coefficients for the rgb to gray - * operation if it is supported. - */ - if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == 0) - { - /* png_set_background has not been called, the coefficients must be in - * range for the following to work without overflow. - */ - if (y_red <= (1<<17) && y_green <= (1<<17) && y_blue <= (1<<17)) - { - /* The y values are chromaticities: Y/X+Y+Z, the weights for the gray - * transformation are simply the normalized Y values for red, green and - * blue scaled by 32768. - */ - png_uint_32 w = y_red + y_green + y_blue; - - png_ptr->rgb_to_gray_red_coeff = (png_uint_16)(((png_uint_32)y_red * - 32768)/w); - png_ptr->rgb_to_gray_green_coeff = (png_uint_16)(((png_uint_32)y_green - * 32768)/w); - png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(((png_uint_32)y_blue * - 32768)/w); - } - } -#endif - - png_set_cHRM_fixed(png_ptr, info_ptr, x_white, y_white, x_red, y_red, - x_green, y_green, x_blue, y_blue); + png_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; + (void)png_colorspace_set_chromaticities(png_ptr, &png_ptr->colorspace, &xy, + 1/*prefer cHRM values*/); + png_colorspace_sync(png_ptr, info_ptr); } #endif #ifdef PNG_READ_sRGB_SUPPORTED void /* PRIVATE */ -png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { - int intent; - png_byte buf[1]; + png_byte intent; png_debug(1, "in png_handle_sRGB"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before sRGB"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) { - png_warning(png_ptr, "Invalid sRGB after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->mode & PNG_HAVE_PLTE) - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place sRGB chunk"); - - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) - { - png_warning(png_ptr, "Duplicate sRGB chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } if (length != 1) { - png_warning(png_ptr, "Incorrect sRGB chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } - png_crc_read(png_ptr, buf, 1); + png_crc_read(png_ptr, &intent, 1); - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) return; - intent = buf[0]; + /* If a colorspace error has already been output skip this chunk */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0) + return; - /* Check for bad intent */ - if (intent >= PNG_sRGB_INTENT_LAST) + /* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect + * this. + */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) != 0) { - png_warning(png_ptr, "Unknown sRGB intent"); + png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID; + png_colorspace_sync(png_ptr, info_ptr); + png_chunk_benign_error(png_ptr, "too many profiles"); return; } -#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)) - { - if (PNG_OUT_OF_RANGE(info_ptr->gamma, 45500L, 500)) - { - PNG_WARNING_PARAMETERS(p) - - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, - info_ptr->gamma); - - png_formatted_warning(png_ptr, p, - "Ignoring incorrect gAMA value @1 when sRGB is also present"); - } - } -#endif /* PNG_READ_gAMA_SUPPORTED */ - -#ifdef PNG_READ_cHRM_SUPPORTED - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) - if (PNG_OUT_OF_RANGE(info_ptr->x_white, 31270, 1000) || - PNG_OUT_OF_RANGE(info_ptr->y_white, 32900, 1000) || - PNG_OUT_OF_RANGE(info_ptr->x_red, 64000L, 1000) || - PNG_OUT_OF_RANGE(info_ptr->y_red, 33000, 1000) || - PNG_OUT_OF_RANGE(info_ptr->x_green, 30000, 1000) || - PNG_OUT_OF_RANGE(info_ptr->y_green, 60000L, 1000) || - PNG_OUT_OF_RANGE(info_ptr->x_blue, 15000, 1000) || - PNG_OUT_OF_RANGE(info_ptr->y_blue, 6000, 1000)) - { - png_warning(png_ptr, - "Ignoring incorrect cHRM value when sRGB is also present"); - } -#endif /* PNG_READ_cHRM_SUPPORTED */ - - png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent); + (void)png_colorspace_set_sRGB(png_ptr, &png_ptr->colorspace, intent); + png_colorspace_sync(png_ptr, info_ptr); } -#endif /* PNG_READ_sRGB_SUPPORTED */ +#endif /* READ_sRGB */ #ifdef PNG_READ_iCCP_SUPPORTED void /* PRIVATE */ -png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -/* Note: this does not properly handle chunks that are > 64K under DOS */ +png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +/* Note: this does not properly handle profiles that are > 64K under DOS */ { - png_byte compression_type; - png_bytep pC; - png_charp profile; - png_uint_32 skip = 0; - png_uint_32 profile_size; - png_alloc_size_t profile_length; - png_size_t slength, prefix_length, data_length; + png_const_charp errmsg = NULL; /* error message output, or no error */ + int finished = 0; /* crc checked */ png_debug(1, "in png_handle_iCCP"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before iCCP"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + /* Consistent with all the above colorspace handling an obviously *invalid* + * chunk is just ignored, so does not invalidate the color space. An + * alternative is to set the 'invalid' flags at the start of this routine + * and only clear them in they were not set before and all the tests pass. + * The minimum 'deflate' stream is assumed to be just the 2 byte header and + * 4 byte checksum. The keyword must be at least one character and there is + * a terminator (0) byte and the compression method. + */ + if (length < 9) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "too short"); + return; + } + + /* If a colorspace error has already been output skip this chunk */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0) { - png_warning(png_ptr, "Invalid iCCP after IDAT"); png_crc_finish(png_ptr, length); return; } - else if (png_ptr->mode & PNG_HAVE_PLTE) - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place iCCP chunk"); - - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)) + /* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect + * this. + */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) == 0) { - png_warning(png_ptr, "Duplicate iCCP chunk"); + uInt read_length, keyword_length; + char keyword[81]; + + /* Find the keyword; the keyword plus separator and compression method + * bytes can be at most 81 characters long. + */ + read_length = 81; /* maximum */ + if (read_length > length) + read_length = (uInt)length; + + png_crc_read(png_ptr, (png_bytep)keyword, read_length); + length -= read_length; + + keyword_length = 0; + while (keyword_length < 80 && keyword_length < read_length && + keyword[keyword_length] != 0) + ++keyword_length; + + /* TODO: make the keyword checking common */ + if (keyword_length >= 1 && keyword_length <= 79) + { + /* We only understand '0' compression - deflate - so if we get a + * different value we can't safely decode the chunk. + */ + if (keyword_length+1 < read_length && + keyword[keyword_length+1] == PNG_COMPRESSION_TYPE_BASE) + { + read_length -= keyword_length+2; + + if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK) + { + Byte profile_header[132]; + Byte local_buffer[PNG_INFLATE_BUF_SIZE]; + png_alloc_size_t size = (sizeof profile_header); + + png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2); + png_ptr->zstream.avail_in = read_length; + (void)png_inflate_read(png_ptr, local_buffer, + (sizeof local_buffer), &length, profile_header, &size, + 0/*finish: don't, because the output is too small*/); + + if (size == 0) + { + /* We have the ICC profile header; do the basic header checks. + */ + const png_uint_32 profile_length = + png_get_uint_32(profile_header); + + if (png_icc_check_length(png_ptr, &png_ptr->colorspace, + keyword, profile_length) != 0) + { + /* The length is apparently ok, so we can check the 132 + * byte header. + */ + if (png_icc_check_header(png_ptr, &png_ptr->colorspace, + keyword, profile_length, profile_header, + png_ptr->color_type) != 0) + { + /* Now read the tag table; a variable size buffer is + * needed at this point, allocate one for the whole + * profile. The header check has already validated + * that none of these stuff will overflow. + */ + const png_uint_32 tag_count = png_get_uint_32( + profile_header+128); + png_bytep profile = png_read_buffer(png_ptr, + profile_length, 2/*silent*/); + + if (profile != NULL) + { + memcpy(profile, profile_header, + (sizeof profile_header)); + + size = 12 * tag_count; + + (void)png_inflate_read(png_ptr, local_buffer, + (sizeof local_buffer), &length, + profile + (sizeof profile_header), &size, 0); + + /* Still expect a buffer error because we expect + * there to be some tag data! + */ + if (size == 0) + { + if (png_icc_check_tag_table(png_ptr, + &png_ptr->colorspace, keyword, profile_length, + profile) != 0) + { + /* The profile has been validated for basic + * security issues, so read the whole thing in. + */ + size = profile_length - (sizeof profile_header) + - 12 * tag_count; + + (void)png_inflate_read(png_ptr, local_buffer, + (sizeof local_buffer), &length, + profile + (sizeof profile_header) + + 12 * tag_count, &size, 1/*finish*/); + + if (length > 0 && !(png_ptr->flags & + PNG_FLAG_BENIGN_ERRORS_WARN)) + errmsg = "extra compressed data"; + + /* But otherwise allow extra data: */ + else if (size == 0) + { + if (length > 0) + { + /* This can be handled completely, so + * keep going. + */ + png_chunk_warning(png_ptr, + "extra compressed data"); + } + + png_crc_finish(png_ptr, length); + finished = 1; + +# ifdef PNG_sRGB_SUPPORTED + /* Check for a match against sRGB */ + png_icc_set_sRGB(png_ptr, + &png_ptr->colorspace, profile, + png_ptr->zstream.adler); +# endif + + /* Steal the profile for info_ptr. */ + if (info_ptr != NULL) + { + png_free_data(png_ptr, info_ptr, + PNG_FREE_ICCP, 0); + + info_ptr->iccp_name = png_voidcast(char*, + png_malloc_base(png_ptr, + keyword_length+1)); + if (info_ptr->iccp_name != NULL) + { + memcpy(info_ptr->iccp_name, keyword, + keyword_length+1); + info_ptr->iccp_proflen = + profile_length; + info_ptr->iccp_profile = profile; + png_ptr->read_buffer = NULL; /*steal*/ + info_ptr->free_me |= PNG_FREE_ICCP; + info_ptr->valid |= PNG_INFO_iCCP; + } + + else + { + png_ptr->colorspace.flags |= + PNG_COLORSPACE_INVALID; + errmsg = "out of memory"; + } + } + + /* else the profile remains in the read + * buffer which gets reused for subsequent + * chunks. + */ + + if (info_ptr != NULL) + png_colorspace_sync(png_ptr, info_ptr); + + if (errmsg == NULL) + { + png_ptr->zowner = 0; + return; + } + } + + else if (size > 0) + errmsg = "truncated"; + + else + errmsg = png_ptr->zstream.msg; + } + + /* else png_icc_check_tag_table output an error */ + } + + else /* profile truncated */ + errmsg = png_ptr->zstream.msg; + } + + else + errmsg = "out of memory"; + } + + /* else png_icc_check_header output an error */ + } + + /* else png_icc_check_length output an error */ + } + + else /* profile truncated */ + errmsg = png_ptr->zstream.msg; + + /* Release the stream */ + png_ptr->zowner = 0; + } + + else /* png_inflate_claim failed */ + errmsg = png_ptr->zstream.msg; + } + + else + errmsg = "bad compression method"; /* or missing */ + } + + else + errmsg = "bad keyword"; + } + + else + errmsg = "too many profiles"; + + /* Failure: the reason is in 'errmsg' */ + if (finished == 0) png_crc_finish(png_ptr, length); - return; - } -#ifdef PNG_MAX_MALLOC_64K - if (length > (png_uint_32)65535L) - { - png_warning(png_ptr, "iCCP chunk too large to fit in memory"); - skip = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; - } -#endif - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); - slength = (png_size_t)length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); - - if (png_crc_finish(png_ptr, skip)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - png_ptr->chunkdata[slength] = 0x00; - - for (profile = png_ptr->chunkdata; *profile; profile++) - /* Empty loop to find end of name */ ; - - ++profile; - - /* There should be at least one zero (the compression type byte) - * following the separator, and we should be on it - */ - if (profile >= png_ptr->chunkdata + slength - 1) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_warning(png_ptr, "Malformed iCCP chunk"); - return; - } - - /* Compression_type should always be zero */ - compression_type = *profile++; - - if (compression_type) - { - png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk"); - compression_type = 0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8 - wrote nonzero) */ - } - - prefix_length = profile - png_ptr->chunkdata; - png_decompress_chunk(png_ptr, compression_type, - slength, prefix_length, &data_length); - - profile_length = data_length - prefix_length; - - if (prefix_length > data_length || profile_length < 4) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_warning(png_ptr, "Profile size field missing from iCCP chunk"); - return; - } - - /* Check the profile_size recorded in the first 32 bits of the ICC profile */ - pC = (png_bytep)(png_ptr->chunkdata + prefix_length); - profile_size = ((*(pC )) << 24) | - ((*(pC + 1)) << 16) | - ((*(pC + 2)) << 8) | - ((*(pC + 3)) ); - - /* NOTE: the following guarantees that 'profile_length' fits into 32 bits, - * because profile_size is a 32 bit value. - */ - if (profile_size < profile_length) - profile_length = profile_size; - - /* And the following guarantees that profile_size == profile_length. */ - if (profile_size > profile_length) - { - PNG_WARNING_PARAMETERS(p) - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - - png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_u, profile_size); - png_warning_parameter_unsigned(p, 2, PNG_NUMBER_FORMAT_u, profile_length); - png_formatted_warning(png_ptr, p, - "Ignoring iCCP chunk with declared size = @1 and actual length = @2"); - return; - } - - png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata, - compression_type, (png_bytep)png_ptr->chunkdata + prefix_length, - profile_size); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID; + png_colorspace_sync(png_ptr, info_ptr); + if (errmsg != NULL) /* else already output */ + png_chunk_benign_error(png_ptr, errmsg); } -#endif /* PNG_READ_iCCP_SUPPORTED */ +#endif /* READ_iCCP */ #ifdef PNG_READ_sPLT_SUPPORTED void /* PRIVATE */ -png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) /* Note: this does not properly handle chunks that are > 64K under DOS */ { - png_bytep entry_start; + png_bytep entry_start, buffer; png_sPLT_t new_palette; png_sPLT_entryp pp; png_uint_32 data_length; int entry_size, i; png_uint_32 skip = 0; - png_size_t slength; png_uint_32 dl; png_size_t max_dl; png_debug(1, "in png_handle_sPLT"); #ifdef PNG_USER_LIMITS_SUPPORTED - if (png_ptr->user_chunk_cache_max != 0) { if (png_ptr->user_chunk_cache_max == 1) @@ -1338,55 +1631,53 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } #endif - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before sPLT"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) { - png_warning(png_ptr, "Invalid sPLT after IDAT"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } #ifdef PNG_MAX_MALLOC_64K - if (length > (png_uint_32)65535L) + if (length > 65535U) { - png_warning(png_ptr, "sPLT chunk too large to fit in memory"); - skip = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "too large to fit in memory"); + return; } #endif - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); + buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/); + if (buffer == NULL) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of memory"); + return; + } + /* WARNING: this may break if size_t is less than 32 bits; it is assumed * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a * potential breakage point if the types in pngconf.h aren't exactly right. */ - slength = (png_size_t)length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + png_crc_read(png_ptr, buffer, length); - if (png_crc_finish(png_ptr, skip)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + if (png_crc_finish(png_ptr, skip) != 0) return; - } - png_ptr->chunkdata[slength] = 0x00; + buffer[length] = 0; - for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start; - entry_start++) + for (entry_start = buffer; *entry_start; entry_start++) /* Empty loop to find end of name */ ; ++entry_start; /* A sample depth should follow the separator, and we should be on it */ - if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2) + if (entry_start > buffer + length - 2) { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; png_warning(png_ptr, "malformed sPLT chunk"); return; } @@ -1394,23 +1685,19 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) new_palette.depth = *entry_start++; entry_size = (new_palette.depth == 8 ? 6 : 10); /* This must fit in a png_uint_32 because it is derived from the original - * chunk data length (and use 'length', not 'slength' here for clarity - - * they are guaranteed to be the same, see the tests above.) + * chunk data length. */ - data_length = length - (png_uint_32)(entry_start - - (png_bytep)png_ptr->chunkdata); + data_length = length - (png_uint_32)(entry_start - buffer); /* Integrity-check the data length */ - if (data_length % entry_size) + if ((data_length % entry_size) != 0) { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; png_warning(png_ptr, "sPLT chunk has bad length"); return; } dl = (png_int_32)(data_length / entry_size); - max_dl = PNG_SIZE_MAX / png_sizeof(png_sPLT_entry); + max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry)); if (dl > max_dl) { @@ -1421,7 +1708,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) new_palette.nentries = (png_int_32)(data_length / entry_size); new_palette.entries = (png_sPLT_entryp)png_malloc_warn( - png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry)); + png_ptr, new_palette.nentries * (sizeof (png_sPLT_entry))); if (new_palette.entries == NULL) { @@ -1479,38 +1766,36 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #endif /* Discard all chunk data except the name and stash that */ - new_palette.name = png_ptr->chunkdata; + new_palette.name = (png_charp)buffer; png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; png_free(png_ptr, new_palette.entries); } -#endif /* PNG_READ_sPLT_SUPPORTED */ +#endif /* READ_sPLT */ #ifdef PNG_READ_tRNS_SUPPORTED void /* PRIVATE */ -png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; png_debug(1, "in png_handle_tRNS"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before tRNS"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) { - png_warning(png_ptr, "Invalid tRNS after IDAT"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0) { - png_warning(png_ptr, "Duplicate tRNS chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); return; } @@ -1520,8 +1805,8 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (length != 2) { - png_warning(png_ptr, "Incorrect tRNS chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } @@ -1536,12 +1821,12 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (length != 6) { - png_warning(png_ptr, "Incorrect tRNS chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } - png_crc_read(png_ptr, buf, (png_size_t)length); + png_crc_read(png_ptr, buf, length); png_ptr->num_trans = 1; png_ptr->trans_color.red = png_get_uint_16(buf); png_ptr->trans_color.green = png_get_uint_16(buf + 2); @@ -1550,44 +1835,43 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { - if (!(png_ptr->mode & PNG_HAVE_PLTE)) + if ((png_ptr->mode & PNG_HAVE_PLTE) == 0) { - /* Should be an error, but we can cope with it. */ - png_warning(png_ptr, "Missing PLTE before tRNS"); - } - - if (length > (png_uint_32)png_ptr->num_palette || - length > PNG_MAX_PALETTE_LENGTH) - { - png_warning(png_ptr, "Incorrect tRNS chunk length"); + /* TODO: is this actually an error in the ISO spec? */ png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - if (length == 0) + if (length > png_ptr->num_palette || length > PNG_MAX_PALETTE_LENGTH || + length == 0) { - png_warning(png_ptr, "Zero length tRNS chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } - png_crc_read(png_ptr, readbuf, (png_size_t)length); + png_crc_read(png_ptr, readbuf, length); png_ptr->num_trans = (png_uint_16)length; } else { - png_warning(png_ptr, "tRNS chunk not allowed with alpha channel"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid with alpha channel"); return; } - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) { png_ptr->num_trans = 0; return; } + /* TODO: this is a horrible side effect in the palette case because the + * png_struct ends up with a pointer to the tRNS buffer owned by the + * png_info. Fix this. + */ png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, &(png_ptr->trans_color)); } @@ -1595,43 +1879,37 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_READ_bKGD_SUPPORTED void /* PRIVATE */ -png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { - png_size_t truelen; + unsigned int truelen; png_byte buf[6]; png_color_16 background; png_debug(1, "in png_handle_bKGD"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before bKGD"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 || + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + (png_ptr->mode & PNG_HAVE_PLTE) == 0)) { - png_warning(png_ptr, "Invalid bKGD after IDAT"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0) { - png_warning(png_ptr, "Missing PLTE before bKGD"); - png_crc_finish(png_ptr, length); - return; - } - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)) - { - png_warning(png_ptr, "Duplicate bKGD chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); return; } if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) truelen = 1; - else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) truelen = 6; else @@ -1639,14 +1917,14 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (length != truelen) { - png_warning(png_ptr, "Incorrect bKGD chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } png_crc_read(png_ptr, buf, truelen); - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) return; /* We convert the index value into RGB components so that we can allow @@ -1658,11 +1936,11 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { background.index = buf[0]; - if (info_ptr && info_ptr->num_palette) + if (info_ptr != NULL && info_ptr->num_palette != 0) { if (buf[0] >= info_ptr->num_palette) { - png_warning(png_ptr, "Incorrect bKGD chunk index value"); + png_chunk_benign_error(png_ptr, "invalid index"); return; } @@ -1677,7 +1955,7 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) background.gray = 0; } - else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */ + else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* GRAY */ { background.index = 0; background.red = @@ -1701,44 +1979,37 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_READ_hIST_SUPPORTED void /* PRIVATE */ -png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { unsigned int num, i; png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH]; png_debug(1, "in png_handle_hIST"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before hIST"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 || + (png_ptr->mode & PNG_HAVE_PLTE) == 0) { - png_warning(png_ptr, "Invalid hIST after IDAT"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - else if (!(png_ptr->mode & PNG_HAVE_PLTE)) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0) { - png_warning(png_ptr, "Missing PLTE before hIST"); - png_crc_finish(png_ptr, length); - return; - } - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)) - { - png_warning(png_ptr, "Duplicate hIST chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); return; } num = length / 2 ; - if (num != (unsigned int)png_ptr->num_palette || num > - (unsigned int)PNG_MAX_PALETTE_LENGTH) + if (num != png_ptr->num_palette || num > PNG_MAX_PALETTE_LENGTH) { - png_warning(png_ptr, "Incorrect hIST chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } @@ -1750,7 +2021,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) readbuf[i] = png_get_uint_16(buf); } - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) return; png_set_hIST(png_ptr, info_ptr, readbuf); @@ -1759,7 +2030,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_READ_pHYs_SUPPORTED void /* PRIVATE */ -png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_pHYs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_byte buf[9]; png_uint_32 res_x, res_y; @@ -1767,33 +2038,33 @@ png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_debug(1, "in png_handle_pHYs"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before pHYs"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) { - png_warning(png_ptr, "Invalid pHYs after IDAT"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) != 0) { - png_warning(png_ptr, "Duplicate pHYs chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); return; } if (length != 9) { - png_warning(png_ptr, "Incorrect pHYs chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } png_crc_read(png_ptr, buf, 9); - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) return; res_x = png_get_uint_32(buf); @@ -1805,7 +2076,7 @@ png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_READ_oFFs_SUPPORTED void /* PRIVATE */ -png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_oFFs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_byte buf[9]; png_int_32 offset_x, offset_y; @@ -1813,33 +2084,33 @@ png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_debug(1, "in png_handle_oFFs"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before oFFs"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) { - png_warning(png_ptr, "Invalid oFFs after IDAT"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) != 0) { - png_warning(png_ptr, "Duplicate oFFs chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); return; } if (length != 9) { - png_warning(png_ptr, "Incorrect oFFs chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } png_crc_read(png_ptr, buf, 9); - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) return; offset_x = png_get_int_32(buf); @@ -1852,71 +2123,64 @@ png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_READ_pCAL_SUPPORTED /* Read the pCAL chunk (described in the PNG Extensions document) */ void /* PRIVATE */ -png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_int_32 X0, X1; png_byte type, nparams; - png_charp buf, units, endptr; + png_bytep buffer, buf, units, endptr; png_charpp params; - png_size_t slength; int i; png_debug(1, "in png_handle_pCAL"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before pCAL"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) { - png_warning(png_ptr, "Invalid pCAL after IDAT"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) != 0) { - png_warning(png_ptr, "Duplicate pCAL chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); return; } png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)", length + 1); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); - if (png_ptr->chunkdata == NULL) + buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/); + + if (buffer == NULL) { - png_warning(png_ptr, "No memory for pCAL purpose"); + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of memory"); return; } - slength = (png_size_t)length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + png_crc_read(png_ptr, buffer, length); - if (png_crc_finish(png_ptr, 0)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + if (png_crc_finish(png_ptr, 0) != 0) return; - } - png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ + buffer[length] = 0; /* Null terminate the last string */ png_debug(3, "Finding end of pCAL purpose string"); - for (buf = png_ptr->chunkdata; *buf; buf++) + for (buf = buffer; *buf; buf++) /* Empty loop */ ; - endptr = png_ptr->chunkdata + slength; + endptr = buffer + length; /* We need to have at least 12 bytes after the purpose string * in order to get the parameter information. */ if (endptr <= buf + 12) { - png_warning(png_ptr, "Invalid pCAL data"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + png_chunk_benign_error(png_ptr, "invalid"); return; } @@ -1936,15 +2200,13 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) (type == PNG_EQUATION_ARBITRARY && nparams != 3) || (type == PNG_EQUATION_HYPERBOLIC && nparams != 4)) { - png_warning(png_ptr, "Invalid pCAL parameters for equation type"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + png_chunk_benign_error(png_ptr, "invalid parameter count"); return; } else if (type >= PNG_EQUATION_LAST) { - png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); + png_chunk_benign_error(png_ptr, "unrecognized equation type"); } for (buf = units; *buf; buf++) @@ -1952,43 +2214,37 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_debug(3, "Allocating pCAL parameters array"); - params = (png_charpp)png_malloc_warn(png_ptr, - (png_size_t)(nparams * png_sizeof(png_charp))); + params = png_voidcast(png_charpp, png_malloc_warn(png_ptr, + nparams * (sizeof (png_charp)))); if (params == NULL) { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_warning(png_ptr, "No memory for pCAL params"); + png_chunk_benign_error(png_ptr, "out of memory"); return; } /* Get pointers to the start of each parameter string. */ - for (i = 0; i < (int)nparams; i++) + for (i = 0; i < nparams; i++) { buf++; /* Skip the null string terminator from previous parameter. */ png_debug1(3, "Reading pCAL parameter %d", i); - for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++) + for (params[i] = (png_charp)buf; buf <= endptr && *buf != 0; buf++) /* Empty loop to move past each parameter string */ ; /* Make sure we haven't run out of data yet */ if (buf > endptr) { - png_warning(png_ptr, "Invalid pCAL data"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; png_free(png_ptr, params); + png_chunk_benign_error(png_ptr, "invalid data"); return; } } - png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams, - units, params); + png_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams, + (png_charp)units, params); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; png_free(png_ptr, params); } #endif @@ -1996,67 +2252,61 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_READ_sCAL_SUPPORTED /* Read the sCAL chunk */ void /* PRIVATE */ -png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { - png_size_t slength, i; + png_bytep buffer; + png_size_t i; int state; png_debug(1, "in png_handle_sCAL"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before sCAL"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (png_ptr->mode & PNG_HAVE_IDAT) + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) { - png_warning(png_ptr, "Invalid sCAL after IDAT"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); return; } - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL)) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL) != 0) { - png_warning(png_ptr, "Duplicate sCAL chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); return; } /* Need unit type, width, \0, height: minimum 4 bytes */ else if (length < 4) { - png_warning(png_ptr, "sCAL chunk too short"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)", length + 1); - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/); - if (png_ptr->chunkdata == NULL) + if (buffer == NULL) { - png_warning(png_ptr, "Out of memory while processing sCAL chunk"); + png_chunk_benign_error(png_ptr, "out of memory"); png_crc_finish(png_ptr, length); return; } - slength = (png_size_t)length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); - png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ + png_crc_read(png_ptr, buffer, length); + buffer[length] = 0; /* Null terminate the last string */ - if (png_crc_finish(png_ptr, 0)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + if (png_crc_finish(png_ptr, 0) != 0) return; - } /* Validate the unit. */ - if (png_ptr->chunkdata[0] != 1 && png_ptr->chunkdata[0] != 2) + if (buffer[0] != 1 && buffer[0] != 2) { - png_warning(png_ptr, "Invalid sCAL ignored: invalid unit"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + png_chunk_benign_error(png_ptr, "invalid unit"); return; } @@ -2066,70 +2316,65 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) i = 1; state = 0; - if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) || - i >= slength || png_ptr->chunkdata[i++] != 0) - png_warning(png_ptr, "Invalid sCAL chunk ignored: bad width format"); + if (png_check_fp_number((png_const_charp)buffer, length, &state, &i) == 0 || + i >= length || buffer[i++] != 0) + png_chunk_benign_error(png_ptr, "bad width format"); - else if (!PNG_FP_IS_POSITIVE(state)) - png_warning(png_ptr, "Invalid sCAL chunk ignored: non-positive width"); + else if (PNG_FP_IS_POSITIVE(state) == 0) + png_chunk_benign_error(png_ptr, "non-positive width"); else { png_size_t heighti = i; state = 0; - if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) || - i != slength) - png_warning(png_ptr, "Invalid sCAL chunk ignored: bad height format"); + if (png_check_fp_number((png_const_charp)buffer, length, + &state, &i) == 0 || i != length) + png_chunk_benign_error(png_ptr, "bad height format"); - else if (!PNG_FP_IS_POSITIVE(state)) - png_warning(png_ptr, - "Invalid sCAL chunk ignored: non-positive height"); + else if (PNG_FP_IS_POSITIVE(state) == 0) + png_chunk_benign_error(png_ptr, "non-positive height"); else /* This is the (only) success case. */ - png_set_sCAL_s(png_ptr, info_ptr, png_ptr->chunkdata[0], - png_ptr->chunkdata+1, png_ptr->chunkdata+heighti); + png_set_sCAL_s(png_ptr, info_ptr, buffer[0], + (png_charp)buffer+1, (png_charp)buffer+heighti); } - - /* Clean up - just free the temporarily allocated buffer. */ - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; } #endif #ifdef PNG_READ_tIME_SUPPORTED void /* PRIVATE */ -png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_tIME(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_byte buf[7]; png_time mod_time; png_debug(1, "in png_handle_tIME"); - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Out of place tIME chunk"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) != 0) { - png_warning(png_ptr, "Duplicate tIME chunk"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); return; } - if (png_ptr->mode & PNG_HAVE_IDAT) + if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) png_ptr->mode |= PNG_AFTER_IDAT; if (length != 7) { - png_warning(png_ptr, "Incorrect tIME chunk length"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); return; } png_crc_read(png_ptr, buf, 7); - if (png_crc_finish(png_ptr, 0)) + if (png_crc_finish(png_ptr, 0) != 0) return; mod_time.second = buf[6]; @@ -2146,14 +2391,13 @@ png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_READ_tEXt_SUPPORTED /* Note: this does not properly handle chunks that are > 64K under DOS */ void /* PRIVATE */ -png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { - png_textp text_ptr; + png_text text_info; + png_bytep buffer; png_charp key; png_charp text; png_uint_32 skip = 0; - png_size_t slength; - int ret; png_debug(1, "in png_handle_tEXt"); @@ -2168,84 +2412,59 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (--png_ptr->user_chunk_cache_max == 1) { - png_warning(png_ptr, "No space in chunk cache for tEXt"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "no space in chunk cache"); return; } } #endif - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before tEXt"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - if (png_ptr->mode & PNG_HAVE_IDAT) + if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) png_ptr->mode |= PNG_AFTER_IDAT; #ifdef PNG_MAX_MALLOC_64K - if (length > (png_uint_32)65535L) + if (length > 65535U) { - png_warning(png_ptr, "tEXt chunk too large to fit in memory"); - skip = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "too large to fit in memory"); + return; } #endif - png_free(png_ptr, png_ptr->chunkdata); + buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/); - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); - - if (png_ptr->chunkdata == NULL) + if (buffer == NULL) { - png_warning(png_ptr, "No memory to process text chunk"); + png_chunk_benign_error(png_ptr, "out of memory"); return; } - slength = (png_size_t)length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + png_crc_read(png_ptr, buffer, length); - if (png_crc_finish(png_ptr, skip)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + if (png_crc_finish(png_ptr, skip) != 0) return; - } - key = png_ptr->chunkdata; - - key[slength] = 0x00; + key = (png_charp)buffer; + key[length] = 0; for (text = key; *text; text++) /* Empty loop to find end of key */ ; - if (text != key + slength) + if (text != key + length) text++; - text_ptr = (png_textp)png_malloc_warn(png_ptr, - png_sizeof(png_text)); + text_info.compression = PNG_TEXT_COMPRESSION_NONE; + text_info.key = key; + text_info.lang = NULL; + text_info.lang_key = NULL; + text_info.itxt_length = 0; + text_info.text = text; + text_info.text_length = strlen(text); - if (text_ptr == NULL) - { - png_warning(png_ptr, "Not enough memory to process text chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr->key = key; - text_ptr->lang = NULL; - text_ptr->lang_key = NULL; - text_ptr->itxt_length = 0; - text_ptr->text = text; - text_ptr->text_length = png_strlen(text); - - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_free(png_ptr, text_ptr); - - if (ret) + if (png_set_text_2(png_ptr, info_ptr, &text_info, 1) != 0) png_warning(png_ptr, "Insufficient memory to process text chunk"); } #endif @@ -2253,13 +2472,11 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_READ_zTXt_SUPPORTED /* Note: this does not correctly handle chunks that are > 64K under DOS */ void /* PRIVATE */ -png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { - png_textp text_ptr; - png_charp text; - int comp_type; - int ret; - png_size_t slength, prefix_len, data_len; + png_const_charp errmsg = NULL; + png_bytep buffer; + png_uint_32 keyword_length; png_debug(1, "in png_handle_zTXt"); @@ -2274,123 +2491,101 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (--png_ptr->user_chunk_cache_max == 1) { - png_warning(png_ptr, "No space in chunk cache for zTXt"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "no space in chunk cache"); return; } } #endif - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before zTXt"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - if (png_ptr->mode & PNG_HAVE_IDAT) + if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) png_ptr->mode |= PNG_AFTER_IDAT; -#ifdef PNG_MAX_MALLOC_64K - /* We will no doubt have problems with chunks even half this size, but - * there is no hard and fast rule to tell us where to stop. - */ - if (length > (png_uint_32)65535L) + buffer = png_read_buffer(png_ptr, length, 2/*silent*/); + + if (buffer == NULL) { - png_warning(png_ptr, "zTXt chunk too large to fit in memory"); png_crc_finish(png_ptr, length); - return; - } -#endif - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); - - if (png_ptr->chunkdata == NULL) - { - png_warning(png_ptr, "Out of memory processing zTXt chunk"); + png_chunk_benign_error(png_ptr, "out of memory"); return; } - slength = (png_size_t)length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + png_crc_read(png_ptr, buffer, length); - if (png_crc_finish(png_ptr, 0)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + if (png_crc_finish(png_ptr, 0) != 0) return; - } - png_ptr->chunkdata[slength] = 0x00; + /* TODO: also check that the keyword contents match the spec! */ + for (keyword_length = 0; + keyword_length < length && buffer[keyword_length] != 0; + ++keyword_length) + /* Empty loop to find end of name */ ; - for (text = png_ptr->chunkdata; *text; text++) - /* Empty loop */ ; + if (keyword_length > 79 || keyword_length < 1) + errmsg = "bad keyword"; - /* zTXt must have some text after the chunkdataword */ - if (text >= png_ptr->chunkdata + slength - 2) - { - png_warning(png_ptr, "Truncated zTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } + /* zTXt must have some LZ data after the keyword, although it may expand to + * zero bytes; we need a '\0' at the end of the keyword, the compression type + * then the LZ data: + */ + else if (keyword_length + 3 > length) + errmsg = "truncated"; + + else if (buffer[keyword_length+1] != PNG_COMPRESSION_TYPE_BASE) + errmsg = "unknown compression type"; else { - comp_type = *(++text); + png_alloc_size_t uncompressed_length = PNG_SIZE_MAX; - if (comp_type != PNG_TEXT_COMPRESSION_zTXt) - { - png_warning(png_ptr, "Unknown compression type in zTXt chunk"); - comp_type = PNG_TEXT_COMPRESSION_zTXt; - } + /* TODO: at present png_decompress_chunk imposes a single application + * level memory limit, this should be split to different values for iCCP + * and text chunks. + */ + if (png_decompress_chunk(png_ptr, length, keyword_length+2, + &uncompressed_length, 1/*terminate*/) == Z_STREAM_END) + { + png_text text; - text++; /* Skip the compression_method byte */ + /* It worked; png_ptr->read_buffer now looks like a tEXt chunk except + * for the extra compression type byte and the fact that it isn't + * necessarily '\0' terminated. + */ + buffer = png_ptr->read_buffer; + buffer[uncompressed_length+(keyword_length+2)] = 0; + + text.compression = PNG_TEXT_COMPRESSION_zTXt; + text.key = (png_charp)buffer; + text.text = (png_charp)(buffer + keyword_length+2); + text.text_length = uncompressed_length; + text.itxt_length = 0; + text.lang = NULL; + text.lang_key = NULL; + + if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0) + errmsg = "insufficient memory"; + } + + else + errmsg = png_ptr->zstream.msg; } - prefix_len = text - png_ptr->chunkdata; - - png_decompress_chunk(png_ptr, comp_type, - (png_size_t)length, prefix_len, &data_len); - - text_ptr = (png_textp)png_malloc_warn(png_ptr, - png_sizeof(png_text)); - - if (text_ptr == NULL) - { - png_warning(png_ptr, "Not enough memory to process zTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - text_ptr->compression = comp_type; - text_ptr->key = png_ptr->chunkdata; - text_ptr->lang = NULL; - text_ptr->lang_key = NULL; - text_ptr->itxt_length = 0; - text_ptr->text = png_ptr->chunkdata + prefix_len; - text_ptr->text_length = data_len; - - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); - - png_free(png_ptr, text_ptr); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - - if (ret) - png_error(png_ptr, "Insufficient memory to store zTXt chunk"); + if (errmsg != NULL) + png_chunk_benign_error(png_ptr, errmsg); } #endif #ifdef PNG_READ_iTXt_SUPPORTED /* Note: this does not correctly handle chunks that are > 64K under DOS */ void /* PRIVATE */ -png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { - png_textp text_ptr; - png_charp key, lang, text, lang_key; - int comp_flag; - int comp_type = 0; - int ret; - png_size_t slength, prefix_len, data_len; + png_const_charp errmsg = NULL; + png_bytep buffer; + png_uint_32 prefix_length; png_debug(1, "in png_handle_iTXt"); @@ -2405,274 +2600,393 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (--png_ptr->user_chunk_cache_max == 1) { - png_warning(png_ptr, "No space in chunk cache for iTXt"); png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "no space in chunk cache"); return; } } #endif - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before iTXt"); + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); - if (png_ptr->mode & PNG_HAVE_IDAT) + if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) png_ptr->mode |= PNG_AFTER_IDAT; -#ifdef PNG_MAX_MALLOC_64K - /* We will no doubt have problems with chunks even half this size, but - * there is no hard and fast rule to tell us where to stop. - */ - if (length > (png_uint_32)65535L) + buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/); + + if (buffer == NULL) { - png_warning(png_ptr, "iTXt chunk too large to fit in memory"); png_crc_finish(png_ptr, length); - return; - } -#endif - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); - - if (png_ptr->chunkdata == NULL) - { - png_warning(png_ptr, "No memory to process iTXt chunk"); + png_chunk_benign_error(png_ptr, "out of memory"); return; } - slength = (png_size_t)length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + png_crc_read(png_ptr, buffer, length); - if (png_crc_finish(png_ptr, 0)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; + if (png_crc_finish(png_ptr, 0) != 0) return; - } - png_ptr->chunkdata[slength] = 0x00; - - for (lang = png_ptr->chunkdata; *lang; lang++) + /* First the keyword. */ + for (prefix_length=0; + prefix_length < length && buffer[prefix_length] != 0; + ++prefix_length) /* Empty loop */ ; - lang++; /* Skip NUL separator */ + /* Perform a basic check on the keyword length here. */ + if (prefix_length > 79 || prefix_length < 1) + errmsg = "bad keyword"; - /* iTXt must have a language tag (possibly empty), two compression bytes, - * translated keyword (possibly empty), and possibly some text after the - * keyword + /* Expect keyword, compression flag, compression type, language, translated + * keyword (both may be empty but are 0 terminated) then the text, which may + * be empty. */ + else if (prefix_length + 5 > length) + errmsg = "truncated"; - if (lang >= png_ptr->chunkdata + slength - 3) + else if (buffer[prefix_length+1] == 0 || + (buffer[prefix_length+1] == 1 && + buffer[prefix_length+2] == PNG_COMPRESSION_TYPE_BASE)) { - png_warning(png_ptr, "Truncated iTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; + int compressed = buffer[prefix_length+1] != 0; + png_uint_32 language_offset, translated_keyword_offset; + png_alloc_size_t uncompressed_length = 0; + + /* Now the language tag */ + prefix_length += 3; + language_offset = prefix_length; + + for (; prefix_length < length && buffer[prefix_length] != 0; + ++prefix_length) + /* Empty loop */ ; + + /* WARNING: the length may be invalid here, this is checked below. */ + translated_keyword_offset = ++prefix_length; + + for (; prefix_length < length && buffer[prefix_length] != 0; + ++prefix_length) + /* Empty loop */ ; + + /* prefix_length should now be at the trailing '\0' of the translated + * keyword, but it may already be over the end. None of this arithmetic + * can overflow because chunks are at most 2^31 bytes long, but on 16-bit + * systems the available allocation may overflow. + */ + ++prefix_length; + + if (compressed == 0 && prefix_length <= length) + uncompressed_length = length - prefix_length; + + else if (compressed != 0 && prefix_length < length) + { + uncompressed_length = PNG_SIZE_MAX; + + /* TODO: at present png_decompress_chunk imposes a single application + * level memory limit, this should be split to different values for + * iCCP and text chunks. + */ + if (png_decompress_chunk(png_ptr, length, prefix_length, + &uncompressed_length, 1/*terminate*/) == Z_STREAM_END) + buffer = png_ptr->read_buffer; + + else + errmsg = png_ptr->zstream.msg; + } + + else + errmsg = "truncated"; + + if (errmsg == NULL) + { + png_text text; + + buffer[uncompressed_length+prefix_length] = 0; + + if (compressed == 0) + text.compression = PNG_ITXT_COMPRESSION_NONE; + + else + text.compression = PNG_ITXT_COMPRESSION_zTXt; + + text.key = (png_charp)buffer; + text.lang = (png_charp)buffer + language_offset; + text.lang_key = (png_charp)buffer + translated_keyword_offset; + text.text = (png_charp)buffer + prefix_length; + text.text_length = 0; + text.itxt_length = uncompressed_length; + + if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0) + errmsg = "insufficient memory"; + } } else - { - comp_flag = *lang++; - comp_type = *lang++; - } + errmsg = "bad compression info"; - for (lang_key = lang; *lang_key; lang_key++) - /* Empty loop */ ; - - lang_key++; /* Skip NUL separator */ - - if (lang_key >= png_ptr->chunkdata + slength) - { - png_warning(png_ptr, "Truncated iTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - for (text = lang_key; *text; text++) - /* Empty loop */ ; - - text++; /* Skip NUL separator */ - - if (text >= png_ptr->chunkdata + slength) - { - png_warning(png_ptr, "Malformed iTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - prefix_len = text - png_ptr->chunkdata; - - key=png_ptr->chunkdata; - - if (comp_flag) - png_decompress_chunk(png_ptr, comp_type, - (size_t)length, prefix_len, &data_len); - - else - data_len = png_strlen(png_ptr->chunkdata + prefix_len); - - text_ptr = (png_textp)png_malloc_warn(png_ptr, - png_sizeof(png_text)); - - if (text_ptr == NULL) - { - png_warning(png_ptr, "Not enough memory to process iTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - text_ptr->compression = (int)comp_flag + 1; - text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key); - text_ptr->lang = png_ptr->chunkdata + (lang - key); - text_ptr->itxt_length = data_len; - text_ptr->text_length = 0; - text_ptr->key = png_ptr->chunkdata; - text_ptr->text = png_ptr->chunkdata + prefix_len; - - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); - - png_free(png_ptr, text_ptr); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - - if (ret) - png_error(png_ptr, "Insufficient memory to store iTXt chunk"); + if (errmsg != NULL) + png_chunk_benign_error(png_ptr, errmsg); } #endif -/* This function is called when we haven't found a handler for a - * chunk. If there isn't a problem with the chunk itself (ie bad - * chunk name, CRC, or a critical chunk), the chunk is silently ignored - * -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which - * case it will be saved away to be written out later. - */ -void /* PRIVATE */ -png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_uint_32 skip = 0; - - png_debug(1, "in png_handle_unknown"); - -#ifdef PNG_USER_LIMITS_SUPPORTED - if (png_ptr->user_chunk_cache_max != 0) - { - if (png_ptr->user_chunk_cache_max == 1) - { - png_crc_finish(png_ptr, length); - return; - } - - if (--png_ptr->user_chunk_cache_max == 1) - { - png_warning(png_ptr, "No space in chunk cache for unknown chunk"); - png_crc_finish(png_ptr, length); - return; - } - } -#endif - - if (png_ptr->mode & PNG_HAVE_IDAT) - { - PNG_IDAT; - - if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* Not an IDAT */ - png_ptr->mode |= PNG_AFTER_IDAT; - } - - if (!(png_ptr->chunk_name[0] & 0x20)) - { -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != - PNG_HANDLE_CHUNK_ALWAYS -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED - && png_ptr->read_user_chunk_fn == NULL -#endif - ) -#endif - png_chunk_error(png_ptr, "unknown critical chunk"); - } - #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED - if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED - || (png_ptr->read_user_chunk_fn != NULL) -#endif - ) +/* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */ +static int +png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length) +{ + png_alloc_size_t limit = PNG_SIZE_MAX; + + if (png_ptr->unknown_chunk.data != NULL) { -#ifdef PNG_MAX_MALLOC_64K - if (length > (png_uint_32)65535L) - { - png_warning(png_ptr, "unknown chunk too large to fit in memory"); - skip = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; - } -#endif + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; + } - png_memcpy((png_charp)png_ptr->unknown_chunk.name, - (png_charp)png_ptr->chunk_name, - png_sizeof(png_ptr->unknown_chunk.name)); +# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED + if (png_ptr->user_chunk_malloc_max > 0 && + png_ptr->user_chunk_malloc_max < limit) + limit = png_ptr->user_chunk_malloc_max; - png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1] - = '\0'; +# elif PNG_USER_CHUNK_MALLOC_MAX > 0 + if (PNG_USER_CHUNK_MALLOC_MAX < limit) + limit = PNG_USER_CHUNK_MALLOC_MAX; +# endif - png_ptr->unknown_chunk.size = (png_size_t)length; + if (length <= limit) + { + PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name); + /* The following is safe because of the PNG_SIZE_MAX init above */ + png_ptr->unknown_chunk.size = (png_size_t)length/*SAFE*/; + /* 'mode' is a flag array, only the bottom four bits matter here */ + png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/; if (length == 0) png_ptr->unknown_chunk.data = NULL; else { - png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length); - png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); + /* Do a 'warn' here - it is handled below. */ + png_ptr->unknown_chunk.data = png_voidcast(png_bytep, + png_malloc_warn(png_ptr, length)); } + } -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED - if (png_ptr->read_user_chunk_fn != NULL) - { - /* Callback to user unknown chunk handler */ - int ret; - - ret = (*(png_ptr->read_user_chunk_fn)) - (png_ptr, &png_ptr->unknown_chunk); - - if (ret < 0) - png_chunk_error(png_ptr, "error in user chunk"); - - if (ret == 0) - { - if (!(png_ptr->chunk_name[0] & 0x20)) - { -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != - PNG_HANDLE_CHUNK_ALWAYS) -#endif - png_chunk_error(png_ptr, "unknown critical chunk"); - } - - png_set_unknown_chunks(png_ptr, info_ptr, - &png_ptr->unknown_chunk, 1); - } - } - - else -#endif - png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); - - png_free(png_ptr, png_ptr->unknown_chunk.data); - png_ptr->unknown_chunk.data = NULL; + if (png_ptr->unknown_chunk.data == NULL && length > 0) + { + /* This is benign because we clean up correctly */ + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "unknown chunk exceeds memory limits"); + return 0; } else -#endif - skip = length; + { + if (length > 0) + png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length); + png_crc_finish(png_ptr, 0); + return 1; + } +} +#endif /* READ_UNKNOWN_CHUNKS */ - png_crc_finish(png_ptr, skip); +/* Handle an unknown, or known but disabled, chunk */ +void /* PRIVATE */ +png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr, + png_uint_32 length, int keep) +{ + int handled = 0; /* the chunk was handled */ -#ifndef PNG_READ_USER_CHUNKS_SUPPORTED - PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */ -#endif + png_debug(1, "in png_handle_unknown"); + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + /* NOTE: this code is based on the code in libpng-1.4.12 except for fixing + * the bug which meant that setting a non-default behavior for a specific + * chunk would be ignored (the default was always used unless a user + * callback was installed). + * + * 'keep' is the value from the png_chunk_unknown_handling, the setting for + * this specific chunk_name, if PNG_HANDLE_AS_UNKNOWN_SUPPORTED, if not it + * will always be PNG_HANDLE_CHUNK_AS_DEFAULT and it needs to be set here. + * This is just an optimization to avoid multiple calls to the lookup + * function. + */ +# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name); +# endif +# endif + + /* One of the following methods will read the chunk or skip it (at least one + * of these is always defined because this is the only way to switch on + * PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) + */ +# ifdef PNG_READ_USER_CHUNKS_SUPPORTED + /* The user callback takes precedence over the chunk keep value, but the + * keep value is still required to validate a save of a critical chunk. + */ + if (png_ptr->read_user_chunk_fn != NULL) + { + if (png_cache_unknown_chunk(png_ptr, length) != 0) + { + /* Callback to user unknown chunk handler */ + int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr, + &png_ptr->unknown_chunk); + + /* ret is: + * negative: An error occured, png_chunk_error will be called. + * zero: The chunk was not handled, the chunk will be discarded + * unless png_set_keep_unknown_chunks has been used to set + * a 'keep' behavior for this particular chunk, in which + * case that will be used. A critical chunk will cause an + * error at this point unless it is to be saved. + * positive: The chunk was handled, libpng will ignore/discard it. + */ + if (ret < 0) + png_chunk_error(png_ptr, "error in user chunk"); + + else if (ret == 0) + { + /* If the keep value is 'default' or 'never' override it, but + * still error out on critical chunks unless the keep value is + * 'always' While this is weird it is the behavior in 1.4.12. + * A possible improvement would be to obey the value set for the + * chunk, but this would be an API change that would probably + * damage some applications. + * + * The png_app_warning below catches the case that matters, where + * the application has not set specific save or ignore for this + * chunk or global save or ignore. + */ + if (keep < PNG_HANDLE_CHUNK_IF_SAFE) + { +# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE) + { + png_chunk_warning(png_ptr, "Saving unknown chunk:"); + png_app_warning(png_ptr, + "forcing save of an unhandled chunk;" + " please call png_set_keep_unknown_chunks"); + /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */ + } +# endif + keep = PNG_HANDLE_CHUNK_IF_SAFE; + } + } + + else /* chunk was handled */ + { + handled = 1; + /* Critical chunks can be safely discarded at this point. */ + keep = PNG_HANDLE_CHUNK_NEVER; + } + } + + else + keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */ + } + + else + /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */ +# endif /* READ_USER_CHUNKS */ + +# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED + { + /* keep is currently just the per-chunk setting, if there was no + * setting change it to the global default now (not that this may + * still be AS_DEFAULT) then obtain the cache of the chunk if required, + * if not simply skip the chunk. + */ + if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT) + keep = png_ptr->unknown_default; + + if (keep == PNG_HANDLE_CHUNK_ALWAYS || + (keep == PNG_HANDLE_CHUNK_IF_SAFE && + PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))) + { + if (png_cache_unknown_chunk(png_ptr, length) == 0) + keep = PNG_HANDLE_CHUNK_NEVER; + } + + else + png_crc_finish(png_ptr, length); + } +# else +# ifndef PNG_READ_USER_CHUNKS_SUPPORTED +# error no method to support READ_UNKNOWN_CHUNKS +# endif + + { + /* If here there is no read callback pointer set and no support is + * compiled in to just save the unknown chunks, so simply skip this + * chunk. If 'keep' is something other than AS_DEFAULT or NEVER then + * the app has erroneously asked for unknown chunk saving when there + * is no support. + */ + if (keep > PNG_HANDLE_CHUNK_NEVER) + png_app_error(png_ptr, "no unknown chunk support available"); + + png_crc_finish(png_ptr, length); + } +# endif + +# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED + /* Now store the chunk in the chunk list if appropriate, and if the limits + * permit it. + */ + if (keep == PNG_HANDLE_CHUNK_ALWAYS || + (keep == PNG_HANDLE_CHUNK_IF_SAFE && + PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))) + { +# ifdef PNG_USER_LIMITS_SUPPORTED + switch (png_ptr->user_chunk_cache_max) + { + case 2: + png_ptr->user_chunk_cache_max = 1; + png_chunk_benign_error(png_ptr, "no space in chunk cache"); + /* FALL THROUGH */ + case 1: + /* NOTE: prior to 1.6.0 this case resulted in an unknown critical + * chunk being skipped, now there will be a hard error below. + */ + break; + + default: /* not at limit */ + --(png_ptr->user_chunk_cache_max); + /* FALL THROUGH */ + case 0: /* no limit */ +# endif /* USER_LIMITS */ + /* Here when the limit isn't reached or when limits are compiled + * out; store the chunk. + */ + png_set_unknown_chunks(png_ptr, info_ptr, + &png_ptr->unknown_chunk, 1); + handled = 1; +# ifdef PNG_USER_LIMITS_SUPPORTED + break; + } +# endif + } +# else /* no store support: the chunk must be handled by the user callback */ + PNG_UNUSED(info_ptr) +# endif + + /* Regardless of the error handling below the cached data (if any) can be + * freed now. Notice that the data is not freed if there is a png_error, but + * it will be freed by destroy_read_struct. + */ + if (png_ptr->unknown_chunk.data != NULL) + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; + +#else /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */ + /* There is no support to read an unknown chunk, so just skip it. */ + png_crc_finish(png_ptr, length); + PNG_UNUSED(info_ptr) + PNG_UNUSED(keep) +#endif /* !READ_UNKNOWN_CHUNKS */ + + /* Check for unhandled critical chunks */ + if (handled == 0 && PNG_CHUNK_CRITICAL(png_ptr->chunk_name)) + png_chunk_error(png_ptr, "unhandled critical chunk"); } /* This function is called to verify that a chunk name is valid. @@ -2682,267 +2996,527 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) * the chunk name itself is valid. */ -#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) - -void /* PRIVATE */ -png_check_chunk_name(png_structp png_ptr, png_const_bytep chunk_name) -{ - png_debug(1, "in png_check_chunk_name"); - if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) || - isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3])) - { - png_chunk_error(png_ptr, "invalid chunk type"); - } -} - -/* Combines the row recently read in with the existing pixels in the - * row. This routine takes care of alpha and transparency if requested. - * This routine also handles the two methods of progressive display - * of interlaced images, depending on the mask value. - * The mask value describes which pixels are to be combined with - * the row. The pattern always repeats every 8 pixels, so just 8 - * bits are needed. A one indicates the pixel is to be combined, - * a zero indicates the pixel is to be skipped. This is in addition - * to any alpha or transparency value associated with the pixel. If - * you want all pixels to be combined, pass 0xff (255) in mask. +/* Bit hacking: the test for an invalid byte in the 4 byte chunk name is: + * + * ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) */ void /* PRIVATE */ -png_combine_row(png_structp png_ptr, png_bytep row, int mask) +png_check_chunk_name(png_structrp png_ptr, png_uint_32 chunk_name) { + int i; + + png_debug(1, "in png_check_chunk_name"); + + for (i=1; i<=4; ++i) + { + int c = chunk_name & 0xff; + + if (c < 65 || c > 122 || (c > 90 && c < 97)) + png_chunk_error(png_ptr, "invalid chunk type"); + + chunk_name >>= 8; + } +} + +/* Combines the row recently read in with the existing pixels in the row. This + * routine takes care of alpha and transparency if requested. This routine also + * handles the two methods of progressive display of interlaced images, + * depending on the 'display' value; if 'display' is true then the whole row + * (dp) is filled from the start by replicating the available pixels. If + * 'display' is false only those pixels present in the pass are filled in. + */ +void /* PRIVATE */ +png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display) +{ + unsigned int pixel_depth = png_ptr->transformed_pixel_depth; + png_const_bytep sp = png_ptr->row_buf + 1; + png_alloc_size_t row_width = png_ptr->width; + unsigned int pass = png_ptr->pass; + png_bytep end_ptr = 0; + png_byte end_byte = 0; + unsigned int end_mask; + png_debug(1, "in png_combine_row"); - /* Added in 1.5.4: the row_info should match the information returned by any - * call to png_read_update_info at this point. Do not continue if we got + /* Added in 1.5.6: it should not be possible to enter this routine until at + * least one row has been read from the PNG data and transformed. + */ + if (pixel_depth == 0) + png_error(png_ptr, "internal row logic error"); + + /* Added in 1.5.4: the pixel depth should match the information returned by + * any call to png_read_update_info at this point. Do not continue if we got * this wrong. */ if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes != - PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width)) + PNG_ROWBYTES(pixel_depth, row_width)) png_error(png_ptr, "internal row size calculation error"); - if (mask == 0xff) + /* Don't expect this to ever happen: */ + if (row_width == 0) + png_error(png_ptr, "internal row width error"); + + /* Preserve the last byte in cases where only part of it will be overwritten, + * the multiply below may overflow, we don't care because ANSI-C guarantees + * we get the low bits. + */ + end_mask = (pixel_depth * row_width) & 7; + if (end_mask != 0) { - png_memcpy(row, png_ptr->row_buf + 1, - PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width)); + /* end_ptr == NULL is a flag to say do nothing */ + end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1; + end_byte = *end_ptr; +# ifdef PNG_READ_PACKSWAP_SUPPORTED + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + /* little-endian byte */ + end_mask = 0xff << end_mask; + + else /* big-endian byte */ +# endif + end_mask = 0xff >> end_mask; + /* end_mask is now the bits to *keep* from the destination row */ } - else + /* For non-interlaced images this reduces to a memcpy(). A memcpy() + * will also happen if interlacing isn't supported or if the application + * does not call png_set_interlace_handling(). In the latter cases the + * caller just gets a sequence of the unexpanded rows from each interlace + * pass. + */ +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0 && + pass < 6 && (display == 0 || + /* The following copies everything for 'display' on passes 0, 2 and 4. */ + (display == 1 && (pass & 1) != 0))) { - switch (png_ptr->row_info.pixel_depth) + /* Narrow images may have no bits in a pass; the caller should handle + * this, but this test is cheap: + */ + if (row_width <= PNG_PASS_START_COL(pass)) + return; + + if (pixel_depth < 8) { - case 1: - { - png_bytep sp = png_ptr->row_buf + 1; - png_bytep dp = row; - int s_inc, s_start, s_end; - int m = 0x80; - int shift; - png_uint_32 i; - png_uint_32 row_width = png_ptr->width; + /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit + * into 32 bits, then a single loop over the bytes using the four byte + * values in the 32-bit mask can be used. For the 'display' option the + * expanded mask may also not require any masking within a byte. To + * make this work the PACKSWAP option must be taken into account - it + * simply requires the pixels to be reversed in each byte. + * + * The 'regular' case requires a mask for each of the first 6 passes, + * the 'display' case does a copy for the even passes in the range + * 0..6. This has already been handled in the test above. + * + * The masks are arranged as four bytes with the first byte to use in + * the lowest bits (little-endian) regardless of the order (PACKSWAP or + * not) of the pixels in each byte. + * + * NOTE: the whole of this logic depends on the caller of this function + * only calling it on rows appropriate to the pass. This function only + * understands the 'x' logic; the 'y' logic is handled by the caller. + * + * The following defines allow generation of compile time constant bit + * masks for each pixel depth and each possibility of swapped or not + * swapped bytes. Pass 'p' is in the range 0..6; 'x', a pixel index, + * is in the range 0..7; and the result is 1 if the pixel is to be + * copied in the pass, 0 if not. 'S' is for the sparkle method, 'B' + * for the block method. + * + * With some compilers a compile time expression of the general form: + * + * (shift >= 32) ? (a >> (shift-32)) : (b >> shift) + * + * Produces warnings with values of 'shift' in the range 33 to 63 + * because the right hand side of the ?: expression is evaluated by + * the compiler even though it isn't used. Microsoft Visual C (various + * versions) and the Intel C compiler are known to do this. To avoid + * this the following macros are used in 1.5.6. This is a temporary + * solution to avoid destabilizing the code during the release process. + */ +# if PNG_USE_COMPILE_TIME_MASKS +# define PNG_LSR(x,s) ((x)>>((s) & 0x1f)) +# define PNG_LSL(x,s) ((x)<<((s) & 0x1f)) +# else +# define PNG_LSR(x,s) ((x)>>(s)) +# define PNG_LSL(x,s) ((x)<<(s)) +# endif +# define S_COPY(p,x) (((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x))) :\ + PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))) & 1) +# define B_COPY(p,x) (((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x))) :\ + PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))) & 1) -#ifdef PNG_READ_PACKSWAP_SUPPORTED - if (png_ptr->transformations & PNG_PACKSWAP) - { - s_start = 0; - s_end = 7; - s_inc = 1; - } + /* Return a mask for pass 'p' pixel 'x' at depth 'd'. The mask is + * little endian - the first pixel is at bit 0 - however the extra + * parameter 's' can be set to cause the mask position to be swapped + * within each byte, to match the PNG format. This is done by XOR of + * the shift with 7, 6 or 4 for bit depths 1, 2 and 4. + */ +# define PIXEL_MASK(p,x,d,s) \ + (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0)))) + + /* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask. + */ +# define S_MASKx(p,x,d,s) (S_COPY(p,x)?PIXEL_MASK(p,x,d,s):0) +# define B_MASKx(p,x,d,s) (B_COPY(p,x)?PIXEL_MASK(p,x,d,s):0) + + /* Combine 8 of these to get the full mask. For the 1-bpp and 2-bpp + * cases the result needs replicating, for the 4-bpp case the above + * generates a full 32 bits. + */ +# define MASK_EXPAND(m,d) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1))) + +# define S_MASK(p,d,s) MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\ + S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\ + S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d) + +# define B_MASK(p,d,s) MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\ + B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\ + B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d) + +#if PNG_USE_COMPILE_TIME_MASKS + /* Utility macros to construct all the masks for a depth/swap + * combination. The 's' parameter says whether the format is PNG + * (big endian bytes) or not. Only the three odd-numbered passes are + * required for the display/block algorithm. + */ +# define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\ + S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) } + +# define B_MASKS(d,s) { B_MASK(1,d,s), B_MASK(3,d,s), B_MASK(5,d,s) } + +# define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2)) + + /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and + * then pass: + */ + static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] = + { + /* Little-endian byte masks for PACKSWAP */ + { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) }, + /* Normal (big-endian byte) masks - PNG format */ + { S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) } + }; + + /* display_mask has only three entries for the odd passes, so index by + * pass>>1. + */ + static PNG_CONST png_uint_32 display_mask[2][3][3] = + { + /* Little-endian byte masks for PACKSWAP */ + { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) }, + /* Normal (big-endian byte) masks - PNG format */ + { B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) } + }; + +# define MASK(pass,depth,display,png)\ + ((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\ + row_mask[png][DEPTH_INDEX(depth)][pass]) + +#else /* !PNG_USE_COMPILE_TIME_MASKS */ + /* This is the runtime alternative: it seems unlikely that this will + * ever be either smaller or faster than the compile time approach. + */ +# define MASK(pass,depth,display,png)\ + ((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png)) +#endif /* !USE_COMPILE_TIME_MASKS */ + + /* Use the appropriate mask to copy the required bits. In some cases + * the byte mask will be 0 or 0xff; optimize these cases. row_width is + * the number of pixels, but the code copies bytes, so it is necessary + * to special case the end. + */ + png_uint_32 pixels_per_byte = 8 / pixel_depth; + png_uint_32 mask; + +# ifdef PNG_READ_PACKSWAP_SUPPORTED + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + mask = MASK(pass, pixel_depth, display, 0); else -#endif - { - s_start = 7; - s_end = 0; - s_inc = -1; - } +# endif + mask = MASK(pass, pixel_depth, display, 1); - shift = s_start; - - for (i = 0; i < row_width; i++) - { - if (m & mask) - { - int value; - - value = (*sp >> shift) & 0x01; - *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); - *dp |= (png_byte)(value << shift); - } - - if (shift == s_end) - { - shift = s_start; - sp++; - dp++; - } - - else - shift += s_inc; - - if (m == 1) - m = 0x80; - - else - m >>= 1; - } - break; - } - - case 2: + for (;;) { - png_bytep sp = png_ptr->row_buf + 1; - png_bytep dp = row; - int s_start, s_end, s_inc; - int m = 0x80; - int shift; - png_uint_32 i; - png_uint_32 row_width = png_ptr->width; - int value; + png_uint_32 m; -#ifdef PNG_READ_PACKSWAP_SUPPORTED - if (png_ptr->transformations & PNG_PACKSWAP) + /* It doesn't matter in the following if png_uint_32 has more than + * 32 bits because the high bits always match those in m<<24; it is, + * however, essential to use OR here, not +, because of this. + */ + m = mask; + mask = (m >> 8) | (m << 24); /* rotate right to good compilers */ + m &= 0xff; + + if (m != 0) /* something to copy */ { - s_start = 0; - s_end = 6; - s_inc = 2; - } - - else -#endif - { - s_start = 6; - s_end = 0; - s_inc = -2; - } - - shift = s_start; - - for (i = 0; i < row_width; i++) - { - if (m & mask) - { - value = (*sp >> shift) & 0x03; - *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); - *dp |= (png_byte)(value << shift); - } - - if (shift == s_end) - { - shift = s_start; - sp++; - dp++; - } - + if (m != 0xff) + *dp = (png_byte)((*dp & ~m) | (*sp & m)); else - shift += s_inc; - - if (m == 1) - m = 0x80; - - else - m >>= 1; - } - break; - } - - case 4: - { - png_bytep sp = png_ptr->row_buf + 1; - png_bytep dp = row; - int s_start, s_end, s_inc; - int m = 0x80; - int shift; - png_uint_32 i; - png_uint_32 row_width = png_ptr->width; - int value; - -#ifdef PNG_READ_PACKSWAP_SUPPORTED - if (png_ptr->transformations & PNG_PACKSWAP) - { - s_start = 0; - s_end = 4; - s_inc = 4; + *dp = *sp; } - else -#endif - { - s_start = 4; - s_end = 0; - s_inc = -4; - } - shift = s_start; + /* NOTE: this may overwrite the last byte with garbage if the image + * is not an exact number of bytes wide; libpng has always done + * this. + */ + if (row_width <= pixels_per_byte) + break; /* May need to restore part of the last byte */ - for (i = 0; i < row_width; i++) - { - if (m & mask) - { - value = (*sp >> shift) & 0xf; - *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); - *dp |= (png_byte)(value << shift); - } - - if (shift == s_end) - { - shift = s_start; - sp++; - dp++; - } - - else - shift += s_inc; - - if (m == 1) - m = 0x80; - - else - m >>= 1; - } - break; - } - - default: - { - png_bytep sp = png_ptr->row_buf + 1; - png_bytep dp = row; - png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3); - png_uint_32 i; - png_uint_32 row_width = png_ptr->width; - png_byte m = 0x80; - - for (i = 0; i < row_width; i++) - { - if (m & mask) - { - png_memcpy(dp, sp, pixel_bytes); - } - - sp += pixel_bytes; - dp += pixel_bytes; - - if (m == 1) - m = 0x80; - - else - m >>= 1; - } - break; + row_width -= pixels_per_byte; + ++dp; + ++sp; } } + + else /* pixel_depth >= 8 */ + { + unsigned int bytes_to_copy, bytes_to_jump; + + /* Validate the depth - it must be a multiple of 8 */ + if (pixel_depth & 7) + png_error(png_ptr, "invalid user transform pixel depth"); + + pixel_depth >>= 3; /* now in bytes */ + row_width *= pixel_depth; + + /* Regardless of pass number the Adam 7 interlace always results in a + * fixed number of pixels to copy then to skip. There may be a + * different number of pixels to skip at the start though. + */ + { + unsigned int offset = PNG_PASS_START_COL(pass) * pixel_depth; + + row_width -= offset; + dp += offset; + sp += offset; + } + + /* Work out the bytes to copy. */ + if (display != 0) + { + /* When doing the 'block' algorithm the pixel in the pass gets + * replicated to adjacent pixels. This is why the even (0,2,4,6) + * passes are skipped above - the entire expanded row is copied. + */ + bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth; + + /* But don't allow this number to exceed the actual row width. */ + if (bytes_to_copy > row_width) + bytes_to_copy = (unsigned int)/*SAFE*/row_width; + } + + else /* normal row; Adam7 only ever gives us one pixel to copy. */ + bytes_to_copy = pixel_depth; + + /* In Adam7 there is a constant offset between where the pixels go. */ + bytes_to_jump = PNG_PASS_COL_OFFSET(pass) * pixel_depth; + + /* And simply copy these bytes. Some optimization is possible here, + * depending on the value of 'bytes_to_copy'. Special case the low + * byte counts, which we know to be frequent. + * + * Notice that these cases all 'return' rather than 'break' - this + * avoids an unnecessary test on whether to restore the last byte + * below. + */ + switch (bytes_to_copy) + { + case 1: + for (;;) + { + *dp = *sp; + + if (row_width <= bytes_to_jump) + return; + + dp += bytes_to_jump; + sp += bytes_to_jump; + row_width -= bytes_to_jump; + } + + case 2: + /* There is a possibility of a partial copy at the end here; this + * slows the code down somewhat. + */ + do + { + dp[0] = sp[0], dp[1] = sp[1]; + + if (row_width <= bytes_to_jump) + return; + + sp += bytes_to_jump; + dp += bytes_to_jump; + row_width -= bytes_to_jump; + } + while (row_width > 1); + + /* And there can only be one byte left at this point: */ + *dp = *sp; + return; + + case 3: + /* This can only be the RGB case, so each copy is exactly one + * pixel and it is not necessary to check for a partial copy. + */ + for (;;) + { + dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2]; + + if (row_width <= bytes_to_jump) + return; + + sp += bytes_to_jump; + dp += bytes_to_jump; + row_width -= bytes_to_jump; + } + + default: +#if PNG_ALIGN_TYPE != PNG_ALIGN_NONE + /* Check for double byte alignment and, if possible, use a + * 16-bit copy. Don't attempt this for narrow images - ones that + * are less than an interlace panel wide. Don't attempt it for + * wide bytes_to_copy either - use the memcpy there. + */ + if (bytes_to_copy < 16 /*else use memcpy*/ && + png_isaligned(dp, png_uint_16) && + png_isaligned(sp, png_uint_16) && + bytes_to_copy % (sizeof (png_uint_16)) == 0 && + bytes_to_jump % (sizeof (png_uint_16)) == 0) + { + /* Everything is aligned for png_uint_16 copies, but try for + * png_uint_32 first. + */ + if (png_isaligned(dp, png_uint_32) != 0 && + png_isaligned(sp, png_uint_32) != 0 && + bytes_to_copy % (sizeof (png_uint_32)) == 0 && + bytes_to_jump % (sizeof (png_uint_32)) == 0) + { + png_uint_32p dp32 = png_aligncast(png_uint_32p,dp); + png_const_uint_32p sp32 = png_aligncastconst( + png_const_uint_32p, sp); + size_t skip = (bytes_to_jump-bytes_to_copy) / + (sizeof (png_uint_32)); + + do + { + size_t c = bytes_to_copy; + do + { + *dp32++ = *sp32++; + c -= (sizeof (png_uint_32)); + } + while (c > 0); + + if (row_width <= bytes_to_jump) + return; + + dp32 += skip; + sp32 += skip; + row_width -= bytes_to_jump; + } + while (bytes_to_copy <= row_width); + + /* Get to here when the row_width truncates the final copy. + * There will be 1-3 bytes left to copy, so don't try the + * 16-bit loop below. + */ + dp = (png_bytep)dp32; + sp = (png_const_bytep)sp32; + do + *dp++ = *sp++; + while (--row_width > 0); + return; + } + + /* Else do it in 16-bit quantities, but only if the size is + * not too large. + */ + else + { + png_uint_16p dp16 = png_aligncast(png_uint_16p, dp); + png_const_uint_16p sp16 = png_aligncastconst( + png_const_uint_16p, sp); + size_t skip = (bytes_to_jump-bytes_to_copy) / + (sizeof (png_uint_16)); + + do + { + size_t c = bytes_to_copy; + do + { + *dp16++ = *sp16++; + c -= (sizeof (png_uint_16)); + } + while (c > 0); + + if (row_width <= bytes_to_jump) + return; + + dp16 += skip; + sp16 += skip; + row_width -= bytes_to_jump; + } + while (bytes_to_copy <= row_width); + + /* End of row - 1 byte left, bytes_to_copy > row_width: */ + dp = (png_bytep)dp16; + sp = (png_const_bytep)sp16; + do + *dp++ = *sp++; + while (--row_width > 0); + return; + } + } +#endif /* ALIGN_TYPE code */ + + /* The true default - use a memcpy: */ + for (;;) + { + memcpy(dp, sp, bytes_to_copy); + + if (row_width <= bytes_to_jump) + return; + + sp += bytes_to_jump; + dp += bytes_to_jump; + row_width -= bytes_to_jump; + if (bytes_to_copy > row_width) + bytes_to_copy = (unsigned int)/*SAFE*/row_width; + } + } + + /* NOT REACHED*/ + } /* pixel_depth >= 8 */ + + /* Here if pixel_depth < 8 to check 'end_ptr' below. */ } + else +#endif /* READ_INTERLACING */ + + /* If here then the switch above wasn't used so just memcpy the whole row + * from the temporary row buffer (notice that this overwrites the end of the + * destination row if it is a partial byte.) + */ + memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width)); + + /* Restore the overwritten bits from the last byte if necessary. */ + if (end_ptr != NULL) + *end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask)); } #ifdef PNG_READ_INTERLACING_SUPPORTED void /* PRIVATE */ -png_do_read_interlace(png_structp png_ptr) +png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, + png_uint_32 transformations /* Because these may affect the byte layout */) { - png_row_infop row_info = &(png_ptr->row_info); - png_bytep row = png_ptr->row_buf + 1; - int pass = png_ptr->pass; - png_uint_32 transformations = png_ptr->transformations; /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Offset to next interlace block */ - PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; png_debug(1, "in png_do_read_interlace"); if (row != NULL && row_info != NULL) @@ -2965,7 +3539,7 @@ png_do_read_interlace(png_structp png_ptr) int j; #ifdef PNG_READ_PACKSWAP_SUPPORTED - if (transformations & PNG_PACKSWAP) + if ((transformations & PNG_PACKSWAP) != 0) { sshift = (int)((row_info->width + 7) & 0x07); dshift = (int)((final_width + 7) & 0x07); @@ -2989,8 +3563,9 @@ png_do_read_interlace(png_structp png_ptr) v = (png_byte)((*sp >> sshift) & 0x01); for (j = 0; j < jstop; j++) { - *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff); - *dp |= (png_byte)(v << dshift); + unsigned int tmp = *dp & (0x7f7f >> (7 - dshift)); + tmp |= v << dshift; + *dp = (png_byte)(tmp & 0xff); if (dshift == s_end) { @@ -3024,7 +3599,7 @@ png_do_read_interlace(png_structp png_ptr) png_uint_32 i; #ifdef PNG_READ_PACKSWAP_SUPPORTED - if (transformations & PNG_PACKSWAP) + if ((transformations & PNG_PACKSWAP) != 0) { sshift = (int)(((row_info->width + 3) & 0x03) << 1); dshift = (int)(((final_width + 3) & 0x03) << 1); @@ -3051,8 +3626,9 @@ png_do_read_interlace(png_structp png_ptr) v = (png_byte)((*sp >> sshift) & 0x03); for (j = 0; j < jstop; j++) { - *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff); - *dp |= (png_byte)(v << dshift); + unsigned int tmp = *dp & (0x3f3f >> (6 - dshift)); + tmp |= v << dshift; + *dp = (png_byte)(tmp & 0xff); if (dshift == s_end) { @@ -3086,7 +3662,7 @@ png_do_read_interlace(png_structp png_ptr) int jstop = png_pass_inc[pass]; #ifdef PNG_READ_PACKSWAP_SUPPORTED - if (transformations & PNG_PACKSWAP) + if ((transformations & PNG_PACKSWAP) != 0) { sshift = (int)(((row_info->width + 1) & 0x01) << 2); dshift = (int)(((final_width + 1) & 0x01) << 2); @@ -3107,13 +3683,14 @@ png_do_read_interlace(png_structp png_ptr) for (i = 0; i < row_info->width; i++) { - png_byte v = (png_byte)((*sp >> sshift) & 0xf); + png_byte v = (png_byte)((*sp >> sshift) & 0x0f); int j; for (j = 0; j < jstop; j++) { - *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff); - *dp |= (png_byte)(v << dshift); + unsigned int tmp = *dp & (0xf0f >> (4 - dshift)); + tmp |= v << dshift; + *dp = (png_byte)(tmp & 0xff); if (dshift == s_end) { @@ -3136,6 +3713,7 @@ png_do_read_interlace(png_structp png_ptr) } break; } + default: { png_size_t pixel_bytes = (row_info->pixel_depth >> 3); @@ -3150,14 +3728,14 @@ png_do_read_interlace(png_structp png_ptr) for (i = 0; i < row_info->width; i++) { - png_byte v[8]; + png_byte v[8]; /* SAFE; pixel_depth does not exceed 64 */ int j; - png_memcpy(v, sp, pixel_bytes); + memcpy(v, sp, pixel_bytes); for (j = 0; j < jstop; j++) { - png_memcpy(dp, v, pixel_bytes); + memcpy(dp, v, pixel_bytes); dp -= pixel_bytes; } @@ -3166,6 +3744,7 @@ png_do_read_interlace(png_structp png_ptr) break; } } + row_info->width = final_width; row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); } @@ -3173,167 +3752,427 @@ png_do_read_interlace(png_structp png_ptr) PNG_UNUSED(transformations) /* Silence compiler warning */ #endif } -#endif /* PNG_READ_INTERLACING_SUPPORTED */ +#endif /* READ_INTERLACING */ + +static void +png_read_filter_row_sub(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_size_t i; + png_size_t istop = row_info->rowbytes; + unsigned int bpp = (row_info->pixel_depth + 7) >> 3; + png_bytep rp = row + bpp; + + PNG_UNUSED(prev_row) + + for (i = bpp; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff); + rp++; + } +} + +static void +png_read_filter_row_up(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_size_t i; + png_size_t istop = row_info->rowbytes; + png_bytep rp = row; + png_const_bytep pp = prev_row; + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); + rp++; + } +} + +static void +png_read_filter_row_avg(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_size_t i; + png_bytep rp = row; + png_const_bytep pp = prev_row; + unsigned int bpp = (row_info->pixel_depth + 7) >> 3; + png_size_t istop = row_info->rowbytes - bpp; + + for (i = 0; i < bpp; i++) + { + *rp = (png_byte)(((int)(*rp) + + ((int)(*pp++) / 2 )) & 0xff); + + rp++; + } + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + + (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff); + + rp++; + } +} + +static void +png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp_end = row + row_info->rowbytes; + int a, c; + + /* First pixel/byte */ + c = *prev_row++; + a = *row + c; + *row++ = (png_byte)a; + + /* Remainder */ + while (row < rp_end) + { + int b, pa, pb, pc, p; + + a &= 0xff; /* From previous iteration or start */ + b = *prev_row++; + + p = b - c; + pc = a - c; + +# ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +# else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +# endif + + /* Find the best predictor, the least of pa, pb, pc favoring the earlier + * ones in the case of a tie. + */ + if (pb < pa) pa = pb, a = b; + if (pc < pa) a = c; + + /* Calculate the current pixel in a, and move the previous row pixel to c + * for the next time round the loop + */ + c = b; + a += *row; + *row++ = (png_byte)a; + } +} + +static void +png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + int bpp = (row_info->pixel_depth + 7) >> 3; + png_bytep rp_end = row + bpp; + + /* Process the first pixel in the row completely (this is the same as 'up' + * because there is only one candidate predictor for the first row). + */ + while (row < rp_end) + { + int a = *row + *prev_row++; + *row++ = (png_byte)a; + } + + /* Remainder */ + rp_end += row_info->rowbytes - bpp; + + while (row < rp_end) + { + int a, b, c, pa, pb, pc, p; + + c = *(prev_row - bpp); + a = *(row - bpp); + b = *prev_row++; + + p = b - c; + pc = a - c; + +# ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +# else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +# endif + + if (pb < pa) pa = pb, a = b; + if (pc < pa) a = c; + + a += *row; + *row++ = (png_byte)a; + } +} + +static void +png_init_filter_functions(png_structrp pp) + /* This function is called once for every PNG image (except for PNG images + * that only use PNG_FILTER_VALUE_NONE for all rows) to set the + * implementations required to reverse the filtering of PNG rows. Reversing + * the filter is the first transformation performed on the row data. It is + * performed in place, therefore an implementation can be selected based on + * the image pixel format. If the implementation depends on image width then + * take care to ensure that it works correctly if the image is interlaced - + * interlacing causes the actual row width to vary. + */ +{ + unsigned int bpp = (pp->pixel_depth + 7) >> 3; + + pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub; + pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up; + pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg; + if (bpp == 1) + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth_1byte_pixel; + else + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth_multibyte_pixel; + +#ifdef PNG_FILTER_OPTIMIZATIONS + /* To use this define PNG_FILTER_OPTIMIZATIONS as the name of a function to + * call to install hardware optimizations for the above functions; simply + * replace whatever elements of the pp->read_filter[] array with a hardware + * specific (or, for that matter, generic) optimization. + * + * To see an example of this examine what configure.ac does when + * --enable-arm-neon is specified on the command line. + */ + PNG_FILTER_OPTIMIZATIONS(pp, bpp); +#endif +} void /* PRIVATE */ -png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, - png_const_bytep prev_row, int filter) +png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row, + png_const_bytep prev_row, int filter) { - png_debug(1, "in png_read_filter_row"); - png_debug2(2, "row = %u, filter = %d", png_ptr->row_number, filter); - switch (filter) + /* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define + * PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic + * implementations. See png_init_filter_functions above. + */ + if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST) { - case PNG_FILTER_VALUE_NONE: - break; + if (pp->read_filter[0] == NULL) + png_init_filter_functions(pp); - case PNG_FILTER_VALUE_SUB: - { - png_size_t i; - png_size_t istop = row_info->rowbytes; - unsigned int bpp = (row_info->pixel_depth + 7) >> 3; - png_bytep rp = row + bpp; - png_bytep lp = row; - - for (i = bpp; i < istop; i++) - { - *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff); - rp++; - } - break; - } - case PNG_FILTER_VALUE_UP: - { - png_size_t i; - png_size_t istop = row_info->rowbytes; - png_bytep rp = row; - png_const_bytep pp = prev_row; - - for (i = 0; i < istop; i++) - { - *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); - rp++; - } - break; - } - case PNG_FILTER_VALUE_AVG: - { - png_size_t i; - png_bytep rp = row; - png_const_bytep pp = prev_row; - png_bytep lp = row; - unsigned int bpp = (row_info->pixel_depth + 7) >> 3; - png_size_t istop = row_info->rowbytes - bpp; - - for (i = 0; i < bpp; i++) - { - *rp = (png_byte)(((int)(*rp) + - ((int)(*pp++) / 2 )) & 0xff); - - rp++; - } - - for (i = 0; i < istop; i++) - { - *rp = (png_byte)(((int)(*rp) + - (int)(*pp++ + *lp++) / 2 ) & 0xff); - - rp++; - } - break; - } - case PNG_FILTER_VALUE_PAETH: - { - png_size_t i; - png_bytep rp = row; - png_const_bytep pp = prev_row; - png_bytep lp = row; - png_const_bytep cp = prev_row; - unsigned int bpp = (row_info->pixel_depth + 7) >> 3; - png_size_t istop=row_info->rowbytes - bpp; - - for (i = 0; i < bpp; i++) - { - *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); - rp++; - } - - for (i = 0; i < istop; i++) /* Use leftover rp,pp */ - { - int a, b, c, pa, pb, pc, p; - - a = *lp++; - b = *pp++; - c = *cp++; - - p = b - c; - pc = a - c; - -#ifdef PNG_USE_ABS - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); -#else - pa = p < 0 ? -p : p; - pb = pc < 0 ? -pc : pc; - pc = (p + pc) < 0 ? -(p + pc) : p + pc; -#endif - - /* - if (pa <= pb && pa <= pc) - p = a; - - else if (pb <= pc) - p = b; - - else - p = c; - */ - - p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c; - - *rp = (png_byte)(((int)(*rp) + p) & 0xff); - rp++; - } - break; - } - default: - png_error(png_ptr, "Ignoring bad adaptive filter type"); - /*NOT REACHED */ - break; + pp->read_filter[filter-1](row_info, row, prev_row); } } #ifdef PNG_SEQUENTIAL_READ_SUPPORTED void /* PRIVATE */ -png_read_finish_row(png_structp png_ptr) +png_read_IDAT_data(png_structrp png_ptr, png_bytep output, + png_alloc_size_t avail_out) +{ + /* Loop reading IDATs and decompressing the result into output[avail_out] */ + png_ptr->zstream.next_out = output; + png_ptr->zstream.avail_out = 0; /* safety: set below */ + + if (output == NULL) + avail_out = 0; + + do + { + int ret; + png_byte tmpbuf[PNG_INFLATE_BUF_SIZE]; + + if (png_ptr->zstream.avail_in == 0) + { + uInt avail_in; + png_bytep buffer; + + while (png_ptr->idat_size == 0) + { + png_crc_finish(png_ptr, 0); + + png_ptr->idat_size = png_read_chunk_header(png_ptr); + /* This is an error even in the 'check' case because the code just + * consumed a non-IDAT header. + */ + if (png_ptr->chunk_name != png_IDAT) + png_error(png_ptr, "Not enough image data"); + } + + avail_in = png_ptr->IDAT_read_size; + + if (avail_in > png_ptr->idat_size) + avail_in = (uInt)png_ptr->idat_size; + + /* A PNG with a gradually increasing IDAT size will defeat this attempt + * to minimize memory usage by causing lots of re-allocs, but + * realistically doing IDAT_read_size re-allocs is not likely to be a + * big problem. + */ + buffer = png_read_buffer(png_ptr, avail_in, 0/*error*/); + + png_crc_read(png_ptr, buffer, avail_in); + png_ptr->idat_size -= avail_in; + + png_ptr->zstream.next_in = buffer; + png_ptr->zstream.avail_in = avail_in; + } + + /* And set up the output side. */ + if (output != NULL) /* standard read */ + { + uInt out = ZLIB_IO_MAX; + + if (out > avail_out) + out = (uInt)avail_out; + + avail_out -= out; + png_ptr->zstream.avail_out = out; + } + + else /* after last row, checking for end */ + { + png_ptr->zstream.next_out = tmpbuf; + png_ptr->zstream.avail_out = (sizeof tmpbuf); + } + + /* Use NO_FLUSH; this gives zlib the maximum opportunity to optimize the + * process. If the LZ stream is truncated the sequential reader will + * terminally damage the stream, above, by reading the chunk header of the + * following chunk (it then exits with png_error). + * + * TODO: deal more elegantly with truncated IDAT lists. + */ + ret = inflate(&png_ptr->zstream, Z_NO_FLUSH); + + /* Take the unconsumed output back. */ + if (output != NULL) + avail_out += png_ptr->zstream.avail_out; + + else /* avail_out counts the extra bytes */ + avail_out += (sizeof tmpbuf) - png_ptr->zstream.avail_out; + + png_ptr->zstream.avail_out = 0; + + if (ret == Z_STREAM_END) + { + /* Do this for safety; we won't read any more into this row. */ + png_ptr->zstream.next_out = NULL; + + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; + + if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0) + png_chunk_benign_error(png_ptr, "Extra compressed data"); + break; + } + + if (ret != Z_OK) + { + png_zstream_error(png_ptr, ret); + + if (output != NULL) + png_chunk_error(png_ptr, png_ptr->zstream.msg); + + else /* checking */ + { + png_chunk_benign_error(png_ptr, png_ptr->zstream.msg); + return; + } + } + } while (avail_out > 0); + + if (avail_out > 0) + { + /* The stream ended before the image; this is the same as too few IDATs so + * should be handled the same way. + */ + if (output != NULL) + png_error(png_ptr, "Not enough image data"); + + else /* the deflate stream contained extra data */ + png_chunk_benign_error(png_ptr, "Too much image data"); + } +} + +void /* PRIVATE */ +png_read_finish_IDAT(png_structrp png_ptr) +{ + /* We don't need any more data and the stream should have ended, however the + * LZ end code may actually not have been processed. In this case we must + * read it otherwise stray unread IDAT data or, more likely, an IDAT chunk + * may still remain to be consumed. + */ + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0) + { + /* The NULL causes png_read_IDAT_data to swallow any remaining bytes in + * the compressed stream, but the stream may be damaged too, so even after + * this call we may need to terminate the zstream ownership. + */ + png_read_IDAT_data(png_ptr, NULL, 0); + png_ptr->zstream.next_out = NULL; /* safety */ + + /* Now clear everything out for safety; the following may not have been + * done. + */ + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0) + { + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; + } + } + + /* If the zstream has not been released do it now *and* terminate the reading + * of the final IDAT chunk. + */ + if (png_ptr->zowner == png_IDAT) + { + /* Always do this; the pointers otherwise point into the read buffer. */ + png_ptr->zstream.next_in = NULL; + png_ptr->zstream.avail_in = 0; + + /* Now we no longer own the zstream. */ + png_ptr->zowner = 0; + + /* The slightly weird semantics of the sequential IDAT reading is that we + * are always in or at the end of an IDAT chunk, so we always need to do a + * crc_finish here. If idat_size is non-zero we also need to read the + * spurious bytes at the end of the chunk now. + */ + (void)png_crc_finish(png_ptr, png_ptr->idat_size); + } +} + +void /* PRIVATE */ +png_read_finish_row(png_structrp png_ptr) { -#ifdef PNG_READ_INTERLACING_SUPPORTED /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ - PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; /* Offset to next interlace block */ - PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; /* Start of interlace block in the y direction */ - PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; /* Offset to next interlace block in the y direction */ - PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; -#endif /* PNG_READ_INTERLACING_SUPPORTED */ + static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; png_debug(1, "in png_read_finish_row"); png_ptr->row_number++; if (png_ptr->row_number < png_ptr->num_rows) return; -#ifdef PNG_READ_INTERLACING_SUPPORTED - if (png_ptr->interlaced) + if (png_ptr->interlaced != 0) { png_ptr->row_number = 0; - png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + /* TO DO: don't do this if prev_row isn't needed (requires + * read-ahead of the next row's filter byte. + */ + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); do { @@ -3347,7 +4186,7 @@ png_read_finish_row(png_structp png_ptr) png_pass_start[png_ptr->pass]) / png_pass_inc[png_ptr->pass]; - if (!(png_ptr->transformations & PNG_INTERLACE)) + if ((png_ptr->transformations & PNG_INTERLACE) == 0) { png_ptr->num_rows = (png_ptr->height + png_pass_yinc[png_ptr->pass] - 1 - @@ -3363,108 +4202,40 @@ png_read_finish_row(png_structp png_ptr) if (png_ptr->pass < 7) return; } -#endif /* PNG_READ_INTERLACING_SUPPORTED */ - if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) - { - PNG_IDAT; - char extra; - int ret; - - png_ptr->zstream.next_out = (Byte *)&extra; - png_ptr->zstream.avail_out = (uInt)1; - - for (;;) - { - if (!(png_ptr->zstream.avail_in)) - { - while (!png_ptr->idat_size) - { - png_crc_finish(png_ptr, 0); - png_ptr->idat_size = png_read_chunk_header(png_ptr); - if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) - png_error(png_ptr, "Not enough image data"); - } - - png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_in = png_ptr->zbuf; - - if (png_ptr->zbuf_size > png_ptr->idat_size) - png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; - - png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in); - png_ptr->idat_size -= png_ptr->zstream.avail_in; - } - - ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); - - if (ret == Z_STREAM_END) - { - if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in || - png_ptr->idat_size) - png_warning(png_ptr, "Extra compressed data"); - - png_ptr->mode |= PNG_AFTER_IDAT; - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - break; - } - - if (ret != Z_OK) - png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : - "Decompression Error"); - - if (!(png_ptr->zstream.avail_out)) - { - png_warning(png_ptr, "Extra compressed data"); - png_ptr->mode |= PNG_AFTER_IDAT; - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - break; - } - - } - png_ptr->zstream.avail_out = 0; - } - - if (png_ptr->idat_size || png_ptr->zstream.avail_in) - png_warning(png_ptr, "Extra compression data"); - - inflateReset(&png_ptr->zstream); - - png_ptr->mode |= PNG_AFTER_IDAT; + /* Here after at the end of the last row of the last pass. */ + png_read_finish_IDAT(png_ptr); } -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ +#endif /* SEQUENTIAL_READ */ void /* PRIVATE */ -png_read_start_row(png_structp png_ptr) +png_read_start_row(png_structrp png_ptr) { -#ifdef PNG_READ_INTERLACING_SUPPORTED /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ - PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; /* Offset to next interlace block */ - PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; /* Start of interlace block in the y direction */ - PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; /* Offset to next interlace block in the y direction */ - PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; -#endif + static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; int max_pixel_depth; png_size_t row_bytes; png_debug(1, "in png_read_start_row"); - png_ptr->zstream.avail_in = 0; + #ifdef PNG_READ_TRANSFORMS_SUPPORTED png_init_read_transformations(png_ptr); #endif -#ifdef PNG_READ_INTERLACING_SUPPORTED - if (png_ptr->interlaced) + if (png_ptr->interlaced != 0) { - if (!(png_ptr->transformations & PNG_INTERLACE)) + if ((png_ptr->transformations & PNG_INTERLACE) == 0) png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - png_pass_ystart[0]) / png_pass_yinc[0]; @@ -3478,7 +4249,6 @@ png_read_start_row(png_structp png_ptr) } else -#endif /* PNG_READ_INTERLACING_SUPPORTED */ { png_ptr->num_rows = png_ptr->height; png_ptr->iwidth = png_ptr->width; @@ -3486,17 +4256,27 @@ png_read_start_row(png_structp png_ptr) max_pixel_depth = png_ptr->pixel_depth; + /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of + * calculations to calculate the final pixel depth, then + * png_do_read_transforms actually does the transforms. This means that the + * code which effectively calculates this value is actually repeated in three + * separate places. They must all match. Innocent changes to the order of + * transformations can and will break libpng in a way that causes memory + * overwrites. + * + * TODO: fix this. + */ #ifdef PNG_READ_PACK_SUPPORTED - if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8) + if ((png_ptr->transformations & PNG_PACK) != 0 && png_ptr->bit_depth < 8) max_pixel_depth = 8; #endif #ifdef PNG_READ_EXPAND_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND) + if ((png_ptr->transformations & PNG_EXPAND) != 0) { if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { - if (png_ptr->num_trans) + if (png_ptr->num_trans != 0) max_pixel_depth = 32; else @@ -3508,13 +4288,13 @@ png_read_start_row(png_structp png_ptr) if (max_pixel_depth < 8) max_pixel_depth = 8; - if (png_ptr->num_trans) + if (png_ptr->num_trans != 0) max_pixel_depth *= 2; } else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) { - if (png_ptr->num_trans) + if (png_ptr->num_trans != 0) { max_pixel_depth *= 4; max_pixel_depth /= 3; @@ -3524,13 +4304,13 @@ png_read_start_row(png_structp png_ptr) #endif #ifdef PNG_READ_EXPAND_16_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND_16) + if ((png_ptr->transformations & PNG_EXPAND_16) != 0) { # ifdef PNG_READ_EXPAND_SUPPORTED /* In fact it is an error if it isn't supported, but checking is * the safe way. */ - if (png_ptr->transformations & PNG_EXPAND) + if ((png_ptr->transformations & PNG_EXPAND) != 0) { if (png_ptr->bit_depth < 16) max_pixel_depth *= 2; @@ -3542,12 +4322,9 @@ png_read_start_row(png_structp png_ptr) #endif #ifdef PNG_READ_FILLER_SUPPORTED - if (png_ptr->transformations & (PNG_FILLER)) + if ((png_ptr->transformations & (PNG_FILLER)) != 0) { - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - max_pixel_depth = 32; - - else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) { if (max_pixel_depth <= 8) max_pixel_depth = 16; @@ -3556,7 +4333,8 @@ png_read_start_row(png_structp png_ptr) max_pixel_depth = 32; } - else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB || + png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { if (max_pixel_depth <= 32) max_pixel_depth = 32; @@ -3568,14 +4346,15 @@ png_read_start_row(png_structp png_ptr) #endif #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED - if (png_ptr->transformations & PNG_GRAY_TO_RGB) + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0) { if ( #ifdef PNG_READ_EXPAND_SUPPORTED - (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) || + (png_ptr->num_trans != 0 && + (png_ptr->transformations & PNG_EXPAND) != 0) || #endif #ifdef PNG_READ_FILLER_SUPPORTED - (png_ptr->transformations & (PNG_FILLER)) || + (png_ptr->transformations & (PNG_FILLER)) != 0 || #endif png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { @@ -3608,16 +4387,22 @@ png_read_start_row(png_structp png_ptr) #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) - if (png_ptr->transformations & PNG_USER_TRANSFORM) + if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) { - int user_pixel_depth = png_ptr->user_transform_depth* + int user_pixel_depth = png_ptr->user_transform_depth * png_ptr->user_transform_channels; if (user_pixel_depth > max_pixel_depth) - max_pixel_depth=user_pixel_depth; + max_pixel_depth = user_pixel_depth; } #endif + /* This value is stored in png_struct and double checked in the row read + * code. + */ + png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth; + png_ptr->transformed_pixel_depth = 0; /* calculated on demand */ + /* Align the width on the next larger 8 pixels. Mainly used * for interlacing */ @@ -3636,28 +4421,39 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) if (row_bytes + 48 > png_ptr->old_big_row_buf_size) { png_free(png_ptr, png_ptr->big_row_buf); + png_free(png_ptr, png_ptr->big_prev_row); - if (png_ptr->interlaced) + if (png_ptr->interlaced != 0) png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, row_bytes + 48); else - png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, - row_bytes + 48); + png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48); - png_ptr->old_big_row_buf_size = row_bytes + 48; + png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48); #ifdef PNG_ALIGNED_MEMORY_SUPPORTED /* Use 16-byte aligned memory for row_buf with at least 16 bytes - * of padding before and after row_buf. + * of padding before and after row_buf; treat prev_row similarly. + * NOTE: the alignment is to the start of the pixels, one beyond the start + * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this + * was incorrect; the filter byte was aligned, which had the exact + * opposite effect of that intended. */ - png_ptr->row_buf = png_ptr->big_row_buf + 32 - - (((png_alloc_size_t)png_ptr->big_row_buf + 15) & 0x0F); + { + png_bytep temp = png_ptr->big_row_buf + 32; + int extra = (int)((temp - (png_bytep)0) & 0x0f); + png_ptr->row_buf = temp - extra - 1/*filter byte*/; + + temp = png_ptr->big_prev_row + 32; + extra = (int)((temp - (png_bytep)0) & 0x0f); + png_ptr->prev_row = temp - extra - 1/*filter byte*/; + } - png_ptr->old_big_row_buf_size = row_bytes + 48; #else - /* Use 32 bytes of padding before and 16 bytes after row_buf. */ - png_ptr->row_buf = png_ptr->big_row_buf + 32; + /* Use 31 bytes of padding before and 17 bytes after row_buf. */ + png_ptr->row_buf = png_ptr->big_row_buf + 31; + png_ptr->prev_row = png_ptr->big_prev_row + 31; #endif png_ptr->old_big_row_buf_size = row_bytes + 48; } @@ -3670,16 +4466,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1)) png_error(png_ptr, "Row has too many bytes to allocate in memory"); - if (png_ptr->rowbytes + 1 > png_ptr->old_prev_row_size) - { - png_free(png_ptr, png_ptr->prev_row); - - png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1); - - png_ptr->old_prev_row_size = png_ptr->rowbytes + 1; - } - - png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); png_debug1(3, "width = %u,", png_ptr->width); png_debug1(3, "height = %u,", png_ptr->height); @@ -3689,6 +4476,27 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) png_debug1(3, "irowbytes = %lu", (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); + /* The sequential reader needs a buffer for IDAT, but the progressive reader + * does not, so free the read buffer now regardless; the sequential reader + * reallocates it on demand. + */ + if (png_ptr->read_buffer != 0) + { + png_bytep buffer = png_ptr->read_buffer; + + png_ptr->read_buffer_size = 0; + png_ptr->read_buffer = NULL; + png_free(png_ptr, buffer); + } + + /* Finally claim the zstream for the inflate of the IDAT data, use the bits + * value from the stream (note that this will result in a fatal error if the + * IDAT stream has a bogus deflate header window_bits value, but this should + * not be happening any longer!) + */ + if (png_inflate_claim(png_ptr, png_IDAT) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); + png_ptr->flags |= PNG_FLAG_ROW_INIT; } -#endif /* PNG_READ_SUPPORTED */ +#endif /* READ */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngset.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngset.c index 819605f5025..d2c89b2a55f 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngset.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngset.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -50,51 +50,84 @@ #ifdef PNG_bKGD_SUPPORTED void PNGAPI -png_set_bKGD(png_structp png_ptr, png_infop info_ptr, +png_set_bKGD(png_const_structrp png_ptr, png_inforp info_ptr, png_const_color_16p background) { png_debug1(1, "in %s storage function", "bKGD"); - if (png_ptr == NULL || info_ptr == NULL) + if (png_ptr == NULL || info_ptr == NULL || background == NULL) return; - png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16)); + info_ptr->background = *background; info_ptr->valid |= PNG_INFO_bKGD; } #endif #ifdef PNG_cHRM_SUPPORTED void PNGFAPI -png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, +png_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr, png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, png_fixed_point blue_y) { + png_xy xy; + png_debug1(1, "in %s storage function", "cHRM fixed"); if (png_ptr == NULL || info_ptr == NULL) return; -# ifdef PNG_CHECK_cHRM_SUPPORTED - if (png_check_cHRM_fixed(png_ptr, - white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) -# endif - { - info_ptr->x_white = white_x; - info_ptr->y_white = white_y; - info_ptr->x_red = red_x; - info_ptr->y_red = red_y; - info_ptr->x_green = green_x; - info_ptr->y_green = green_y; - info_ptr->x_blue = blue_x; - info_ptr->y_blue = blue_y; - info_ptr->valid |= PNG_INFO_cHRM; - } + xy.redx = red_x; + xy.redy = red_y; + xy.greenx = green_x; + xy.greeny = green_y; + xy.bluex = blue_x; + xy.bluey = blue_y; + xy.whitex = white_x; + xy.whitey = white_y; + + if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy, + 2/* override with app values*/) != 0) + info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; + + png_colorspace_sync_info(png_ptr, info_ptr); +} + +void PNGFAPI +png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr, + png_fixed_point int_red_X, png_fixed_point int_red_Y, + png_fixed_point int_red_Z, png_fixed_point int_green_X, + png_fixed_point int_green_Y, png_fixed_point int_green_Z, + png_fixed_point int_blue_X, png_fixed_point int_blue_Y, + png_fixed_point int_blue_Z) +{ + png_XYZ XYZ; + + png_debug1(1, "in %s storage function", "cHRM XYZ fixed"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + XYZ.red_X = int_red_X; + XYZ.red_Y = int_red_Y; + XYZ.red_Z = int_red_Z; + XYZ.green_X = int_green_X; + XYZ.green_Y = int_green_Y; + XYZ.green_Z = int_green_Z; + XYZ.blue_X = int_blue_X; + XYZ.blue_Y = int_blue_Y; + XYZ.blue_Z = int_blue_Z; + + if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace, + &XYZ, 2) != 0) + info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; + + png_colorspace_sync_info(png_ptr, info_ptr); } # ifdef PNG_FLOATING_POINT_SUPPORTED void PNGAPI -png_set_cHRM(png_structp png_ptr, png_infop info_ptr, +png_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, double white_x, double white_y, double red_x, double red_y, double green_x, double green_y, double blue_x, double blue_y) { @@ -108,41 +141,44 @@ png_set_cHRM(png_structp png_ptr, png_infop info_ptr, png_fixed(png_ptr, blue_x, "cHRM Blue X"), png_fixed(png_ptr, blue_y, "cHRM Blue Y")); } -# endif /* PNG_FLOATING_POINT_SUPPORTED */ -#endif /* PNG_cHRM_SUPPORTED */ +void PNGAPI +png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X, + double red_Y, double red_Z, double green_X, double green_Y, double green_Z, + double blue_X, double blue_Y, double blue_Z) +{ + png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, + png_fixed(png_ptr, red_X, "cHRM Red X"), + png_fixed(png_ptr, red_Y, "cHRM Red Y"), + png_fixed(png_ptr, red_Z, "cHRM Red Z"), + png_fixed(png_ptr, green_X, "cHRM Red X"), + png_fixed(png_ptr, green_Y, "cHRM Red Y"), + png_fixed(png_ptr, green_Z, "cHRM Red Z"), + png_fixed(png_ptr, blue_X, "cHRM Red X"), + png_fixed(png_ptr, blue_Y, "cHRM Red Y"), + png_fixed(png_ptr, blue_Z, "cHRM Red Z")); +} +# endif /* FLOATING_POINT */ + +#endif /* cHRM */ #ifdef PNG_gAMA_SUPPORTED void PNGFAPI -png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point - file_gamma) +png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr, + png_fixed_point file_gamma) { png_debug1(1, "in %s storage function", "gAMA"); if (png_ptr == NULL || info_ptr == NULL) return; - /* Changed in libpng-1.5.4 to limit the values to ensure overflow can't - * occur. Since the fixed point representation is assymetrical it is - * possible for 1/gamma to overflow the limit of 21474 and this means the - * gamma value must be at least 5/100000 and hence at most 20000.0. For - * safety the limits here are a little narrower. The values are 0.00016 to - * 6250.0, which are truely ridiculous gammma values (and will produce - * displays that are all black or all white.) - */ - if (file_gamma < 16 || file_gamma > 625000000) - png_warning(png_ptr, "Out of range gamma value ignored"); - - else - { - info_ptr->gamma = file_gamma; - info_ptr->valid |= PNG_INFO_gAMA; - } + png_colorspace_set_gamma(png_ptr, &info_ptr->colorspace, file_gamma); + png_colorspace_sync_info(png_ptr, info_ptr); } # ifdef PNG_FLOATING_POINT_SUPPORTED void PNGAPI -png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) +png_set_gAMA(png_const_structrp png_ptr, png_inforp info_ptr, double file_gamma) { png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma, "png_set_gAMA")); @@ -152,7 +188,8 @@ png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) #ifdef PNG_hIST_SUPPORTED void PNGAPI -png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_const_uint_16p hist) +png_set_hIST(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_uint_16p hist) { int i; @@ -175,26 +212,26 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_const_uint_16p hist) /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in * version 1.2.1 */ - png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, - PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)); + info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr, + PNG_MAX_PALETTE_LENGTH * (sizeof (png_uint_16)))); - if (png_ptr->hist == NULL) + if (info_ptr->hist == NULL) { png_warning(png_ptr, "Insufficient memory for hIST chunk data"); return; } - for (i = 0; i < info_ptr->num_palette; i++) - png_ptr->hist[i] = hist[i]; - - info_ptr->hist = png_ptr->hist; - info_ptr->valid |= PNG_INFO_hIST; info_ptr->free_me |= PNG_FREE_HIST; + + for (i = 0; i < info_ptr->num_palette; i++) + info_ptr->hist[i] = hist[i]; + + info_ptr->valid |= PNG_INFO_hIST; } #endif void PNGAPI -png_set_IHDR(png_structp png_ptr, png_infop info_ptr, +png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type) @@ -219,32 +256,23 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr, if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) info_ptr->channels = 1; - else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) + else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) info_ptr->channels = 3; else info_ptr->channels = 1; - if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) + if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) info_ptr->channels++; info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); - /* Check for potential overflow */ - if (width > - (PNG_UINT_32_MAX >> 3) /* 8-byte RRGGBBAA pixels */ - - 48 /* bigrowbuf hack */ - - 1 /* filter byte */ - - 7*8 /* rounding of width to multiple of 8 pixels */ - - 8) /* extra max_pixel_depth pad */ - info_ptr->rowbytes = 0; - else - info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); } #ifdef PNG_oFFs_SUPPORTED void PNGAPI -png_set_oFFs(png_structp png_ptr, png_infop info_ptr, +png_set_oFFs(png_const_structrp png_ptr, png_inforp info_ptr, png_int_32 offset_x, png_int_32 offset_y, int unit_type) { png_debug1(1, "in %s storage function", "oFFs"); @@ -261,7 +289,7 @@ png_set_oFFs(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_pCAL_SUPPORTED void PNGAPI -png_set_pCAL(png_structp png_ptr, png_infop info_ptr, +png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_const_charp units, png_charpp params) { @@ -270,10 +298,11 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, png_debug1(1, "in %s storage function", "pCAL"); - if (png_ptr == NULL || info_ptr == NULL) + if (png_ptr == NULL || info_ptr == NULL || purpose == NULL || units == NULL + || (nparams > 0 && params == NULL)) return; - length = png_strlen(purpose) + 1; + length = strlen(purpose) + 1; png_debug1(3, "allocating purpose for info (%lu bytes)", (unsigned long)length); @@ -283,12 +312,19 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, if (type < 0 || type > 3) png_error(png_ptr, "Invalid pCAL equation type"); + if (nparams < 0 || nparams > 255) + png_error(png_ptr, "Invalid pCAL parameter count"); + /* Validate params[nparams] */ for (i=0; ipcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); + info_ptr->pcal_purpose = png_voidcast(png_charp, + png_malloc_warn(png_ptr, length)); if (info_ptr->pcal_purpose == NULL) { @@ -296,7 +332,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, return; } - png_memcpy(info_ptr->pcal_purpose, purpose, length); + memcpy(info_ptr->pcal_purpose, purpose, length); png_debug(3, "storing X0, X1, type, and nparams in info"); info_ptr->pcal_X0 = X0; @@ -304,11 +340,12 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, info_ptr->pcal_type = (png_byte)type; info_ptr->pcal_nparams = (png_byte)nparams; - length = png_strlen(units) + 1; + length = strlen(units) + 1; png_debug1(3, "allocating units for info (%lu bytes)", (unsigned long)length); - info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); + info_ptr->pcal_units = png_voidcast(png_charp, + png_malloc_warn(png_ptr, length)); if (info_ptr->pcal_units == NULL) { @@ -316,10 +353,10 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, return; } - png_memcpy(info_ptr->pcal_units, units, length); + memcpy(info_ptr->pcal_units, units, length); - info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, - (png_size_t)((nparams + 1) * png_sizeof(png_charp))); + info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr, + (png_size_t)((nparams + 1) * (sizeof (png_charp))))); if (info_ptr->pcal_params == NULL) { @@ -327,11 +364,11 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, return; } - png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp)); + memset(info_ptr->pcal_params, 0, (nparams + 1) * (sizeof (png_charp))); for (i = 0; i < nparams; i++) { - length = png_strlen(params[i]) + 1; + length = strlen(params[i]) + 1; png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, (unsigned long)length); @@ -343,7 +380,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, return; } - png_memcpy(info_ptr->pcal_params[i], params[i], length); + memcpy(info_ptr->pcal_params[i], params[i], length); } info_ptr->valid |= PNG_INFO_pCAL; @@ -353,7 +390,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_sCAL_SUPPORTED void PNGAPI -png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, +png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr, int unit, png_const_charp swidth, png_const_charp sheight) { png_size_t lengthw = 0, lengthh = 0; @@ -369,11 +406,11 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, if (unit != 1 && unit != 2) png_error(png_ptr, "Invalid sCAL unit"); - if (swidth == NULL || (lengthw = png_strlen(swidth)) == 0 || + if (swidth == NULL || (lengthw = strlen(swidth)) == 0 || swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw)) png_error(png_ptr, "Invalid sCAL width"); - if (sheight == NULL || (lengthh = png_strlen(sheight)) == 0 || + if (sheight == NULL || (lengthh = strlen(sheight)) == 0 || sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh)) png_error(png_ptr, "Invalid sCAL height"); @@ -383,7 +420,8 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw); - info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, lengthw); + info_ptr->scal_s_width = png_voidcast(png_charp, + png_malloc_warn(png_ptr, lengthw)); if (info_ptr->scal_s_width == NULL) { @@ -391,13 +429,14 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, return; } - png_memcpy(info_ptr->scal_s_width, swidth, lengthw); + memcpy(info_ptr->scal_s_width, swidth, lengthw); ++lengthh; png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh); - info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, lengthh); + info_ptr->scal_s_height = png_voidcast(png_charp, + png_malloc_warn(png_ptr, lengthh)); if (info_ptr->scal_s_height == NULL) { @@ -408,7 +447,7 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, return; } - png_memcpy(info_ptr->scal_s_height, sheight, lengthh); + memcpy(info_ptr->scal_s_height, sheight, lengthh); info_ptr->valid |= PNG_INFO_sCAL; info_ptr->free_me |= PNG_FREE_SCAL; @@ -416,8 +455,8 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, # ifdef PNG_FLOATING_POINT_SUPPORTED void PNGAPI -png_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width, - double height) +png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit, + double width, double height) { png_debug1(1, "in %s storage function", "sCAL"); @@ -434,9 +473,9 @@ png_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width, char swidth[PNG_sCAL_MAX_DIGITS+1]; char sheight[PNG_sCAL_MAX_DIGITS+1]; - png_ascii_from_fp(png_ptr, swidth, sizeof swidth, width, + png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width, PNG_sCAL_PRECISION); - png_ascii_from_fp(png_ptr, sheight, sizeof sheight, height, + png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height, PNG_sCAL_PRECISION); png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); @@ -446,7 +485,7 @@ png_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width, # ifdef PNG_FIXED_POINT_SUPPORTED void PNGAPI -png_set_sCAL_fixed(png_structp png_ptr, png_infop info_ptr, int unit, +png_set_sCAL_fixed(png_const_structrp png_ptr, png_inforp info_ptr, int unit, png_fixed_point width, png_fixed_point height) { png_debug1(1, "in %s storage function", "sCAL"); @@ -464,8 +503,8 @@ png_set_sCAL_fixed(png_structp png_ptr, png_infop info_ptr, int unit, char swidth[PNG_sCAL_MAX_DIGITS+1]; char sheight[PNG_sCAL_MAX_DIGITS+1]; - png_ascii_from_fixed(png_ptr, swidth, sizeof swidth, width); - png_ascii_from_fixed(png_ptr, sheight, sizeof sheight, height); + png_ascii_from_fixed(png_ptr, swidth, (sizeof swidth), width); + png_ascii_from_fixed(png_ptr, sheight, (sizeof sheight), height); png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); } @@ -475,7 +514,7 @@ png_set_sCAL_fixed(png_structp png_ptr, png_infop info_ptr, int unit, #ifdef PNG_pHYs_SUPPORTED void PNGAPI -png_set_pHYs(png_structp png_ptr, png_infop info_ptr, +png_set_pHYs(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type) { png_debug1(1, "in %s storage function", "pHYs"); @@ -491,7 +530,7 @@ png_set_pHYs(png_structp png_ptr, png_infop info_ptr, #endif void PNGAPI -png_set_PLTE(png_structp png_ptr, png_infop info_ptr, +png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette) { @@ -526,6 +565,9 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr, /* It may not actually be necessary to set png_ptr->palette here; * we do it for backward compatibility with the way the png_handle_tRNS * function used to do the allocation. + * + * 1.6.0: the above statement appears to be incorrect; something has to set + * the palette inside png_struct on read. */ png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); @@ -533,10 +575,11 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr, * of num_palette entries, in case of an invalid PNG file that has * too-large sample values. */ - png_ptr->palette = (png_colorp)png_calloc(png_ptr, - PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); + png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr, + PNG_MAX_PALETTE_LENGTH * (sizeof (png_color)))); - png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); + if (num_palette > 0) + memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color))); info_ptr->palette = png_ptr->palette; info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; @@ -547,34 +590,34 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_sBIT_SUPPORTED void PNGAPI -png_set_sBIT(png_structp png_ptr, png_infop info_ptr, +png_set_sBIT(png_const_structrp png_ptr, png_inforp info_ptr, png_const_color_8p sig_bit) { png_debug1(1, "in %s storage function", "sBIT"); - if (png_ptr == NULL || info_ptr == NULL) + if (png_ptr == NULL || info_ptr == NULL || sig_bit == NULL) return; - png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8)); + info_ptr->sig_bit = *sig_bit; info_ptr->valid |= PNG_INFO_sBIT; } #endif #ifdef PNG_sRGB_SUPPORTED void PNGAPI -png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int srgb_intent) +png_set_sRGB(png_const_structrp png_ptr, png_inforp info_ptr, int srgb_intent) { png_debug1(1, "in %s storage function", "sRGB"); if (png_ptr == NULL || info_ptr == NULL) return; - info_ptr->srgb_intent = (png_byte)srgb_intent; - info_ptr->valid |= PNG_INFO_sRGB; + (void)png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent); + png_colorspace_sync_info(png_ptr, info_ptr); } void PNGAPI -png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, +png_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, int srgb_intent) { png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); @@ -582,71 +625,87 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, if (png_ptr == NULL || info_ptr == NULL) return; - png_set_sRGB(png_ptr, info_ptr, srgb_intent); + if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, + srgb_intent) != 0) + { + /* This causes the gAMA and cHRM to be written too */ + info_ptr->colorspace.flags |= + PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; + } -# ifdef PNG_gAMA_SUPPORTED - png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE); -# endif - -# ifdef PNG_cHRM_SUPPORTED - png_set_cHRM_fixed(png_ptr, info_ptr, - /* color x y */ - /* white */ 31270L, 32900L, - /* red */ 64000L, 33000L, - /* green */ 30000L, 60000L, - /* blue */ 15000L, 6000L - ); -# endif /* cHRM */ + png_colorspace_sync_info(png_ptr, info_ptr); } #endif /* sRGB */ #ifdef PNG_iCCP_SUPPORTED void PNGAPI -png_set_iCCP(png_structp png_ptr, png_infop info_ptr, +png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, png_const_charp name, int compression_type, png_const_bytep profile, png_uint_32 proflen) { png_charp new_iccp_name; png_bytep new_iccp_profile; - png_uint_32 length; + png_size_t length; png_debug1(1, "in %s storage function", "iCCP"); if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) return; - length = png_strlen(name)+1; - new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length); + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + png_app_error(png_ptr, "Invalid iCCP compression method"); + + /* Set the colorspace first because this validates the profile; do not + * override previously set app cHRM or gAMA here (because likely as not the + * application knows better than libpng what the correct values are.) Pass + * the info_ptr color_type field to png_colorspace_set_ICC because in the + * write case it has not yet been stored in png_ptr. + */ + { + int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name, + proflen, profile, info_ptr->color_type); + + png_colorspace_sync_info(png_ptr, info_ptr); + + /* Don't do any of the copying if the profile was bad, or inconsistent. */ + if (result == 0) + return; + + /* But do write the gAMA and cHRM chunks from the profile. */ + info_ptr->colorspace.flags |= + PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; + } + + length = strlen(name)+1; + new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length)); if (new_iccp_name == NULL) { - png_warning(png_ptr, "Insufficient memory to process iCCP chunk"); + png_benign_error(png_ptr, "Insufficient memory to process iCCP chunk"); return; } - png_memcpy(new_iccp_name, name, length); - new_iccp_profile = (png_bytep)png_malloc_warn(png_ptr, proflen); + memcpy(new_iccp_name, name, length); + new_iccp_profile = png_voidcast(png_bytep, + png_malloc_warn(png_ptr, proflen)); if (new_iccp_profile == NULL) { - png_free (png_ptr, new_iccp_name); - png_warning(png_ptr, + png_free(png_ptr, new_iccp_name); + new_iccp_name = NULL; + png_benign_error(png_ptr, "Insufficient memory to process iCCP profile"); return; } - png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); + memcpy(new_iccp_profile, profile, proflen); png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); info_ptr->iccp_proflen = proflen; info_ptr->iccp_name = new_iccp_name; info_ptr->iccp_profile = new_iccp_profile; - /* Compression is always zero but is here so the API and info structure - * does not have to change if we introduce multiple compression types - */ - info_ptr->iccp_compression = (png_byte)compression_type; info_ptr->free_me |= PNG_FREE_ICCP; info_ptr->valid |= PNG_INFO_iCCP; } @@ -654,74 +713,81 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_TEXT_SUPPORTED void PNGAPI -png_set_text(png_structp png_ptr, png_infop info_ptr, png_const_textp text_ptr, - int num_text) +png_set_text(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_textp text_ptr, int num_text) { int ret; ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); - if (ret) + if (ret != 0) png_error(png_ptr, "Insufficient memory to store text"); } int /* PRIVATE */ -png_set_text_2(png_structp png_ptr, png_infop info_ptr, +png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr, png_const_textp text_ptr, int num_text) { int i; - png_debug1(1, "in %s storage function", ((png_ptr == NULL || - png_ptr->chunk_name[0] == '\0') ? - "text" : (png_const_charp)png_ptr->chunk_name)); + png_debug1(1, "in %lx storage function", png_ptr == NULL ? "unexpected" : + (unsigned long)png_ptr->chunk_name); - if (png_ptr == NULL || info_ptr == NULL || num_text == 0) + if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL) return(0); /* Make sure we have enough space in the "text" array in info_struct - * to hold all of the incoming text_ptr objects. + * to hold all of the incoming text_ptr objects. This compare can't overflow + * because max_text >= num_text (anyway, subtract of two positive integers + * can't overflow in any case.) */ - if (info_ptr->num_text + num_text > info_ptr->max_text) + if (num_text > info_ptr->max_text - info_ptr->num_text) { - if (info_ptr->text != NULL) + int old_num_text = info_ptr->num_text; + int max_text; + png_textp new_text = NULL; + + /* Calculate an appropriate max_text, checking for overflow. */ + max_text = old_num_text; + if (num_text <= INT_MAX - max_text) { - png_textp old_text; - int old_max; + max_text += num_text; - old_max = info_ptr->max_text; - info_ptr->max_text = info_ptr->num_text + num_text + 8; - old_text = info_ptr->text; - info_ptr->text = (png_textp)png_malloc_warn(png_ptr, - (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); + /* Round up to a multiple of 8 */ + if (max_text < INT_MAX-8) + max_text = (max_text + 8) & ~0x7; - if (info_ptr->text == NULL) - { - png_free(png_ptr, old_text); - return(1); - } + else + max_text = INT_MAX; - png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max * - png_sizeof(png_text))); - png_free(png_ptr, old_text); + /* Now allocate a new array and copy the old members in; this does all + * the overflow checks. + */ + new_text = png_voidcast(png_textp,png_realloc_array(png_ptr, + info_ptr->text, old_num_text, max_text-old_num_text, + sizeof *new_text)); } - else + if (new_text == NULL) { - info_ptr->max_text = num_text + 8; - info_ptr->num_text = 0; - info_ptr->text = (png_textp)png_malloc_warn(png_ptr, - (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); - if (info_ptr->text == NULL) - return(1); - info_ptr->free_me |= PNG_FREE_TEXT; + png_chunk_report(png_ptr, "too many text chunks", + PNG_CHUNK_WRITE_ERROR); + return 1; } - png_debug1(3, "allocated %d entries for info_ptr->text", - info_ptr->max_text); + png_free(png_ptr, info_ptr->text); + + info_ptr->text = new_text; + info_ptr->free_me |= PNG_FREE_TEXT; + info_ptr->max_text = max_text; + /* num_text is adjusted below as the entries are copied in */ + + png_debug1(3, "allocated %d entries for info_ptr->text", max_text); } + for (i = 0; i < num_text; i++) { - png_size_t text_length, key_len; - png_size_t lang_len, lang_key_len; + size_t text_length, key_len; + size_t lang_len, lang_key_len; png_textp textp = &(info_ptr->text[info_ptr->num_text]); if (text_ptr[i].key == NULL) @@ -730,11 +796,12 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE || text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST) { - png_warning(png_ptr, "text compression mode is out of range"); + png_chunk_report(png_ptr, "text compression mode is out of range", + PNG_CHUNK_WRITE_ERROR); continue; } - key_len = png_strlen(text_ptr[i].key); + key_len = strlen(text_ptr[i].key); if (text_ptr[i].compression <= 0) { @@ -748,20 +815,21 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, /* Set iTXt data */ if (text_ptr[i].lang != NULL) - lang_len = png_strlen(text_ptr[i].lang); + lang_len = strlen(text_ptr[i].lang); else lang_len = 0; if (text_ptr[i].lang_key != NULL) - lang_key_len = png_strlen(text_ptr[i].lang_key); + lang_key_len = strlen(text_ptr[i].lang_key); else lang_key_len = 0; } # else /* PNG_iTXt_SUPPORTED */ { - png_warning(png_ptr, "iTXt chunk not supported"); + png_chunk_report(png_ptr, "iTXt chunk not supported", + PNG_CHUNK_WRITE_ERROR); continue; } # endif @@ -780,32 +848,35 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, else { - text_length = png_strlen(text_ptr[i].text); + text_length = strlen(text_ptr[i].text); textp->compression = text_ptr[i].compression; } - textp->key = (png_charp)png_malloc_warn(png_ptr, - (png_size_t) - (key_len + text_length + lang_len + lang_key_len + 4)); + textp->key = png_voidcast(png_charp,png_malloc_base(png_ptr, + key_len + text_length + lang_len + lang_key_len + 4)); if (textp->key == NULL) - return(1); + { + png_chunk_report(png_ptr, "text chunk: out of memory", + PNG_CHUNK_WRITE_ERROR); + return 1; + } png_debug2(2, "Allocated %lu bytes at %p in png_set_text", (unsigned long)(png_uint_32) (key_len + lang_len + lang_key_len + text_length + 4), textp->key); - png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len)); + memcpy(textp->key, text_ptr[i].key, key_len); *(textp->key + key_len) = '\0'; if (text_ptr[i].compression > 0) { textp->lang = textp->key + key_len + 1; - png_memcpy(textp->lang, text_ptr[i].lang, lang_len); + memcpy(textp->lang, text_ptr[i].lang, lang_len); *(textp->lang + lang_len) = '\0'; textp->lang_key = textp->lang + lang_len + 1; - png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); + memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); *(textp->lang_key + lang_key_len) = '\0'; textp->text = textp->lang_key + lang_key_len + 1; } @@ -817,9 +888,8 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, textp->text = textp->key + key_len + 1; } - if (text_length) - png_memcpy(textp->text, text_ptr[i].text, - (png_size_t)(text_length)); + if (text_length != 0) + memcpy(textp->text, text_ptr[i].text, text_length); *(textp->text + text_length) = '\0'; @@ -840,28 +910,39 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, info_ptr->num_text++; png_debug1(3, "transferred text chunk %d", info_ptr->num_text); } + return(0); } #endif #ifdef PNG_tIME_SUPPORTED void PNGAPI -png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time) +png_set_tIME(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_timep mod_time) { png_debug1(1, "in %s storage function", "tIME"); - if (png_ptr == NULL || info_ptr == NULL || - (png_ptr->mode & PNG_WROTE_tIME)) + if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL || + (png_ptr->mode & PNG_WROTE_tIME) != 0) return; - png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time)); + if (mod_time->month == 0 || mod_time->month > 12 || + mod_time->day == 0 || mod_time->day > 31 || + mod_time->hour > 23 || mod_time->minute > 59 || + mod_time->second > 60) + { + png_warning(png_ptr, "Ignoring invalid time value"); + return; + } + + info_ptr->mod_time = *mod_time; info_ptr->valid |= PNG_INFO_tIME; } #endif #ifdef PNG_tRNS_SUPPORTED void PNGAPI -png_set_tRNS(png_structp png_ptr, png_infop info_ptr, +png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color) { png_debug1(1, "in %s storage function", "tRNS"); @@ -874,16 +955,20 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr, /* It may not actually be necessary to set png_ptr->trans_alpha here; * we do it for backward compatibility with the way the png_handle_tRNS * function used to do the allocation. + * + * 1.6.0: The above statement is incorrect; png_handle_tRNS effectively + * relies on png_set_tRNS storing the information in png_struct + * (otherwise it won't be there for the code in pngrtran.c). */ png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ - png_ptr->trans_alpha = info_ptr->trans_alpha = - (png_bytep)png_malloc(png_ptr, (png_size_t)PNG_MAX_PALETTE_LENGTH); + png_ptr->trans_alpha = info_ptr->trans_alpha = png_voidcast(png_bytep, + png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH)); if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) - png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans); + memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans); } if (trans_color != NULL) @@ -891,16 +976,15 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr, int sample_max = (1 << info_ptr->bit_depth); if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && - (int)trans_color->gray > sample_max) || + trans_color->gray > sample_max) || (info_ptr->color_type == PNG_COLOR_TYPE_RGB && - ((int)trans_color->red > sample_max || - (int)trans_color->green > sample_max || - (int)trans_color->blue > sample_max))) + (trans_color->red > sample_max || + trans_color->green > sample_max || + trans_color->blue > sample_max))) png_warning(png_ptr, "tRNS chunk has out-of-range samples for bit_depth"); - png_memcpy(&(info_ptr->trans_color), trans_color, - png_sizeof(png_color_16)); + info_ptr->trans_color = *trans_color; if (num_trans == 0) num_trans = 1; @@ -918,8 +1002,8 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_sPLT_SUPPORTED void PNGAPI -png_set_sPLT(png_structp png_ptr, - png_infop info_ptr, png_const_sPLT_tp entries, int nentries) +png_set_sPLT(png_const_structrp png_ptr, + png_inforp info_ptr, png_const_sPLT_tp entries, int nentries) /* * entries - array of png_sPLT_t structures * to be added to the list of palettes @@ -930,220 +1014,455 @@ png_set_sPLT(png_structp png_ptr, */ { png_sPLT_tp np; - int i; - if (png_ptr == NULL || info_ptr == NULL) + if (png_ptr == NULL || info_ptr == NULL || nentries <= 0 || entries == NULL) return; - np = (png_sPLT_tp)png_malloc_warn(png_ptr, - (info_ptr->splt_palettes_num + nentries) * - (png_size_t)png_sizeof(png_sPLT_t)); + /* Use the internal realloc function, which checks for all the possible + * overflows. Notice that the parameters are (int) and (size_t) + */ + np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr, + info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries, + sizeof *np)); if (np == NULL) { - png_warning(png_ptr, "No memory for sPLT palettes"); + /* Out of memory or too many chunks */ + png_chunk_report(png_ptr, "too many sPLT chunks", PNG_CHUNK_WRITE_ERROR); return; } - png_memcpy(np, info_ptr->splt_palettes, - info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); - png_free(png_ptr, info_ptr->splt_palettes); - info_ptr->splt_palettes=NULL; + info_ptr->splt_palettes = np; + info_ptr->free_me |= PNG_FREE_SPLT; - for (i = 0; i < nentries; i++) + np += info_ptr->splt_palettes_num; + + do { - png_sPLT_tp to = np + info_ptr->splt_palettes_num + i; - png_const_sPLT_tp from = entries + i; - png_uint_32 length; + png_size_t length; - length = png_strlen(from->name) + 1; - to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length); - - if (to->name == NULL) + /* Skip invalid input entries */ + if (entries->name == NULL || entries->entries == NULL) { - png_warning(png_ptr, - "Out of memory while processing sPLT chunk"); + /* png_handle_sPLT doesn't do this, so this is an app error */ + png_app_error(png_ptr, "png_set_sPLT: invalid sPLT"); + /* Just skip the invalid entry */ continue; } - png_memcpy(to->name, from->name, length); - to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, - (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry))); + np->depth = entries->depth; - if (to->entries == NULL) + /* In the event of out-of-memory just return - there's no point keeping + * on trying to add sPLT chunks. + */ + length = strlen(entries->name) + 1; + np->name = png_voidcast(png_charp, png_malloc_base(png_ptr, length)); + + if (np->name == NULL) + break; + + memcpy(np->name, entries->name, length); + + /* IMPORTANT: we have memory now that won't get freed if something else + * goes wrong; this code must free it. png_malloc_array produces no + * warnings; use a png_chunk_report (below) if there is an error. + */ + np->entries = png_voidcast(png_sPLT_entryp, png_malloc_array(png_ptr, + entries->nentries, sizeof (png_sPLT_entry))); + + if (np->entries == NULL) { - png_warning(png_ptr, - "Out of memory while processing sPLT chunk"); - png_free(png_ptr, to->name); - to->name = NULL; - continue; + png_free(png_ptr, np->name); + np->name = NULL; + break; } - png_memcpy(to->entries, from->entries, - from->nentries * png_sizeof(png_sPLT_entry)); + np->nentries = entries->nentries; + /* This multiply can't overflow because png_malloc_array has already + * checked it when doing the allocation. + */ + memcpy(np->entries, entries->entries, + entries->nentries * sizeof (png_sPLT_entry)); - to->nentries = from->nentries; - to->depth = from->depth; + /* Note that 'continue' skips the advance of the out pointer and out + * count, so an invalid entry is not added. + */ + info_ptr->valid |= PNG_INFO_sPLT; + ++(info_ptr->splt_palettes_num); + ++np; + } + while (++entries, --nentries); + + if (nentries > 0) + png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR); +} +#endif /* sPLT */ + +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +static png_byte +check_location(png_const_structrp png_ptr, int location) +{ + location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT); + + /* New in 1.6.0; copy the location and check it. This is an API + * change; previously the app had to use the + * png_set_unknown_chunk_location API below for each chunk. + */ + if (location == 0 && (png_ptr->mode & PNG_IS_READ_STRUCT) == 0) + { + /* Write struct, so unknown chunks come from the app */ + png_app_warning(png_ptr, + "png_set_unknown_chunks now expects a valid location"); + /* Use the old behavior */ + location = (png_byte)(png_ptr->mode & + (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)); } - info_ptr->splt_palettes = np; - info_ptr->splt_palettes_num += nentries; - info_ptr->valid |= PNG_INFO_sPLT; - info_ptr->free_me |= PNG_FREE_SPLT; -} -#endif /* PNG_sPLT_SUPPORTED */ + /* This need not be an internal error - if the app calls + * png_set_unknown_chunks on a read pointer it must get the location right. + */ + if (location == 0) + png_error(png_ptr, "invalid location in png_set_unknown_chunks"); + + /* Now reduce the location to the top-most set bit by removing each least + * significant bit in turn. + */ + while (location != (location & -location)) + location &= ~(location & -location); + + /* The cast is safe because 'location' is a bit mask and only the low four + * bits are significant. + */ + return (png_byte)location; +} -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED void PNGAPI -png_set_unknown_chunks(png_structp png_ptr, - png_infop info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns) +png_set_unknown_chunks(png_const_structrp png_ptr, + png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns) { png_unknown_chunkp np; - int i; - if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) + if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 || + unknowns == NULL) return; - np = (png_unknown_chunkp)png_malloc_warn(png_ptr, - (png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) * - png_sizeof(png_unknown_chunk)); + /* Check for the failure cases where support has been disabled at compile + * time. This code is hardly ever compiled - it's here because + * STORE_UNKNOWN_CHUNKS is set by both read and write code (compiling in this + * code) but may be meaningless if the read or write handling of unknown + * chunks is not compiled in. + */ +# if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \ + defined(PNG_READ_SUPPORTED) + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) + { + png_app_error(png_ptr, "no unknown chunk support on read"); + return; + } +# endif +# if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \ + defined(PNG_WRITE_SUPPORTED) + if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) + { + png_app_error(png_ptr, "no unknown chunk support on write"); + return; + } +# endif + + /* Prior to 1.6.0 this code used png_malloc_warn; however, this meant that + * unknown critical chunks could be lost with just a warning resulting in + * undefined behavior. Now png_chunk_report is used to provide behavior + * appropriate to read or write. + */ + np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr, + info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns, + sizeof *np)); if (np == NULL) { - png_warning(png_ptr, - "Out of memory while processing unknown chunk"); + png_chunk_report(png_ptr, "too many unknown chunks", + PNG_CHUNK_WRITE_ERROR); return; } - png_memcpy(np, info_ptr->unknown_chunks, - (png_size_t)info_ptr->unknown_chunks_num * - png_sizeof(png_unknown_chunk)); - png_free(png_ptr, info_ptr->unknown_chunks); - info_ptr->unknown_chunks = NULL; + info_ptr->unknown_chunks = np; /* safe because it is initialized */ + info_ptr->free_me |= PNG_FREE_UNKN; - for (i = 0; i < num_unknowns; i++) + np += info_ptr->unknown_chunks_num; + + /* Increment unknown_chunks_num each time round the loop to protect the + * just-allocated chunk data. + */ + for (; num_unknowns > 0; --num_unknowns, ++unknowns) { - png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; - png_const_unknown_chunkp from = unknowns + i; + memcpy(np->name, unknowns->name, (sizeof np->name)); + np->name[(sizeof np->name)-1] = '\0'; + np->location = check_location(png_ptr, unknowns->location); - png_memcpy(to->name, from->name, png_sizeof(from->name)); - to->name[png_sizeof(to->name)-1] = '\0'; - to->size = from->size; - - /* Note our location in the read or write sequence */ - to->location = (png_byte)(png_ptr->mode & 0xff); - - if (from->size == 0) - to->data=NULL; + if (unknowns->size == 0) + { + np->data = NULL; + np->size = 0; + } else { - to->data = (png_bytep)png_malloc_warn(png_ptr, - (png_size_t)from->size); + np->data = png_voidcast(png_bytep, + png_malloc_base(png_ptr, unknowns->size)); - if (to->data == NULL) + if (np->data == NULL) { - png_warning(png_ptr, - "Out of memory while processing unknown chunk"); - to->size = 0; + png_chunk_report(png_ptr, "unknown chunk: out of memory", + PNG_CHUNK_WRITE_ERROR); + /* But just skip storing the unknown chunk */ + continue; } - else - png_memcpy(to->data, from->data, from->size); + memcpy(np->data, unknowns->data, unknowns->size); + np->size = unknowns->size; } - } - info_ptr->unknown_chunks = np; - info_ptr->unknown_chunks_num += num_unknowns; - info_ptr->free_me |= PNG_FREE_UNKN; + /* These increments are skipped on out-of-memory for the data - the + * unknown chunk entry gets overwritten if the png_chunk_report returns. + * This is correct in the read case (the chunk is just dropped.) + */ + ++np; + ++(info_ptr->unknown_chunks_num); + } } void PNGAPI -png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, +png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr, int chunk, int location) { - if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < - info_ptr->unknown_chunks_num) - info_ptr->unknown_chunks[chunk].location = (png_byte)location; + /* This API is pretty pointless in 1.6.0 because the location can be set + * before the call to png_set_unknown_chunks. + * + * TODO: add a png_app_warning in 1.7 + */ + if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && + chunk < info_ptr->unknown_chunks_num) + { + if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0) + { + png_app_error(png_ptr, "invalid unknown chunk location"); + /* Fake out the pre 1.6.0 behavior: */ + if ((location & PNG_HAVE_IDAT) != 0) /* undocumented! */ + location = PNG_AFTER_IDAT; + + else + location = PNG_HAVE_IHDR; /* also undocumented */ + } + + info_ptr->unknown_chunks[chunk].location = + check_location(png_ptr, location); + } } #endif #ifdef PNG_MNG_FEATURES_SUPPORTED png_uint_32 PNGAPI -png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) +png_permit_mng_features (png_structrp png_ptr, png_uint_32 mng_features) { png_debug(1, "in png_permit_mng_features"); if (png_ptr == NULL) - return (png_uint_32)0; + return 0; - png_ptr->mng_features_permitted = - (png_byte)(mng_features & PNG_ALL_MNG_FEATURES); + png_ptr->mng_features_permitted = mng_features & PNG_ALL_MNG_FEATURES; - return (png_uint_32)png_ptr->mng_features_permitted; + return png_ptr->mng_features_permitted; } #endif #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED -void PNGAPI -png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_const_bytep - chunk_list, int num_chunks) +static unsigned int +add_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep) { - png_bytep new_list, p; - int i, old_num_chunks; + unsigned int i; + + /* Utility function: update the 'keep' state of a chunk if it is already in + * the list, otherwise add it to the list. + */ + for (i=0; i= PNG_HANDLE_CHUNK_LAST) { - if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) - png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; - - else - png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; - - if (keep == PNG_HANDLE_CHUNK_ALWAYS) - png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; - - else - png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; - + png_app_error(png_ptr, "png_set_keep_unknown_chunks: invalid keep"); return; } - if (chunk_list == NULL) - return; + if (num_chunks_in <= 0) + { + png_ptr->unknown_default = keep; + + /* '0' means just set the flags, so stop here */ + if (num_chunks_in == 0) + return; + } + + if (num_chunks_in < 0) + { + /* Ignore all unknown chunks and all chunks recognized by + * libpng except for IHDR, PLTE, tRNS, IDAT, and IEND + */ + static PNG_CONST png_byte chunks_to_ignore[] = { + 98, 75, 71, 68, '\0', /* bKGD */ + 99, 72, 82, 77, '\0', /* cHRM */ + 103, 65, 77, 65, '\0', /* gAMA */ + 104, 73, 83, 84, '\0', /* hIST */ + 105, 67, 67, 80, '\0', /* iCCP */ + 105, 84, 88, 116, '\0', /* iTXt */ + 111, 70, 70, 115, '\0', /* oFFs */ + 112, 67, 65, 76, '\0', /* pCAL */ + 112, 72, 89, 115, '\0', /* pHYs */ + 115, 66, 73, 84, '\0', /* sBIT */ + 115, 67, 65, 76, '\0', /* sCAL */ + 115, 80, 76, 84, '\0', /* sPLT */ + 115, 84, 69, 82, '\0', /* sTER */ + 115, 82, 71, 66, '\0', /* sRGB */ + 116, 69, 88, 116, '\0', /* tEXt */ + 116, 73, 77, 69, '\0', /* tIME */ + 122, 84, 88, 116, '\0' /* zTXt */ + }; + + chunk_list = chunks_to_ignore; + num_chunks = (unsigned int)/*SAFE*/(sizeof chunks_to_ignore)/5U; + } + + else /* num_chunks_in > 0 */ + { + if (chunk_list == NULL) + { + /* Prior to 1.6.0 this was silently ignored, now it is an app_error + * which can be switched off. + */ + png_app_error(png_ptr, "png_set_keep_unknown_chunks: no chunk list"); + return; + } + + num_chunks = num_chunks_in; + } old_num_chunks = png_ptr->num_chunk_list; - new_list=(png_bytep)png_malloc(png_ptr, - (png_size_t)(5*(num_chunks + old_num_chunks))); + if (png_ptr->chunk_list == NULL) + old_num_chunks = 0; - if (png_ptr->chunk_list != NULL) + /* Since num_chunks is always restricted to UINT_MAX/5 this can't overflow. + */ + if (num_chunks + old_num_chunks > UINT_MAX/5) { - png_memcpy(new_list, png_ptr->chunk_list, - (png_size_t)(5*old_num_chunks)); - png_free(png_ptr, png_ptr->chunk_list); - png_ptr->chunk_list=NULL; + png_app_error(png_ptr, "png_set_keep_unknown_chunks: too many chunks"); + return; } - png_memcpy(new_list + 5*old_num_chunks, chunk_list, - (png_size_t)(5*num_chunks)); + /* If these chunks are being reset to the default then no more memory is + * required because add_one_chunk above doesn't extend the list if the 'keep' + * parameter is the default. + */ + if (keep != 0) + { + new_list = png_voidcast(png_bytep, png_malloc(png_ptr, + 5 * (num_chunks + old_num_chunks))); - for (p = new_list + 5*old_num_chunks + 4, i = 0; i 0) + memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); + } - png_ptr->num_chunk_list = old_num_chunks + num_chunks; - png_ptr->chunk_list = new_list; - png_ptr->free_me |= PNG_FREE_LIST; + else if (old_num_chunks > 0) + new_list = png_ptr->chunk_list; + + else + new_list = NULL; + + /* Add the new chunks together with each one's handling code. If the chunk + * already exists the code is updated, otherwise the chunk is added to the + * end. (In libpng 1.6.0 order no longer matters because this code enforces + * the earlier convention that the last setting is the one that is used.) + */ + if (new_list != NULL) + { + png_const_bytep inlist; + png_bytep outlist; + unsigned int i; + + for (i=0; ichunk_list != new_list) + png_free(png_ptr, new_list); + + new_list = NULL; + } + } + + else + num_chunks = 0; + + png_ptr->num_chunk_list = num_chunks; + + if (png_ptr->chunk_list != new_list) + { + if (png_ptr->chunk_list != NULL) + png_free(png_ptr, png_ptr->chunk_list); + + png_ptr->chunk_list = new_list; + } } #endif #ifdef PNG_READ_USER_CHUNKS_SUPPORTED void PNGAPI -png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, +png_set_read_user_chunk_fn(png_structrp png_ptr, png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn) { png_debug(1, "in png_set_read_user_chunk_fn"); @@ -1158,64 +1477,90 @@ png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, #ifdef PNG_INFO_IMAGE_SUPPORTED void PNGAPI -png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) +png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr, + png_bytepp row_pointers) { png_debug1(1, "in %s storage function", "rows"); if (png_ptr == NULL || info_ptr == NULL) return; - if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers)) + if (info_ptr->row_pointers != NULL && + (info_ptr->row_pointers != row_pointers)) png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); info_ptr->row_pointers = row_pointers; - if (row_pointers) + if (row_pointers != NULL) info_ptr->valid |= PNG_INFO_IDAT; } #endif void PNGAPI -png_set_compression_buffer_size(png_structp png_ptr, png_size_t size) +png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size) { if (png_ptr == NULL) return; - png_free(png_ptr, png_ptr->zbuf); + if (size == 0 || size > PNG_UINT_31_MAX) + png_error(png_ptr, "invalid compression buffer size"); - if (size > ZLIB_IO_MAX) - { - png_warning(png_ptr, "Attempt to set buffer size beyond max ignored"); - png_ptr->zbuf_size = ZLIB_IO_MAX; - size = ZLIB_IO_MAX; /* must fit */ - } +# ifdef PNG_SEQUENTIAL_READ_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) + { + png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */ + return; + } +# endif - else - png_ptr->zbuf_size = (uInt)size; +# ifdef PNG_WRITE_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) + { + if (png_ptr->zowner != 0) + { + png_warning(png_ptr, + "Compression buffer size cannot be changed because it is in use"); + return; + } - png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); + if (size > ZLIB_IO_MAX) + { + png_warning(png_ptr, + "Compression buffer size limited to system maximum"); + size = ZLIB_IO_MAX; /* must fit */ + } - /* The following ensures a relatively safe failure if this gets called while - * the buffer is actually in use. - */ - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = 0; - png_ptr->zstream.avail_in = 0; + else if (size < 6) + { + /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH + * if this is permitted. + */ + png_warning(png_ptr, + "Compression buffer size cannot be reduced below 6"); + return; + } + + if (png_ptr->zbuffer_size != size) + { + png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list); + png_ptr->zbuffer_size = (uInt)size; + } + } +# endif } void PNGAPI -png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) +png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask) { - if (png_ptr && info_ptr) + if (png_ptr != NULL && info_ptr != NULL) info_ptr->valid &= ~mask; } - #ifdef PNG_SET_USER_LIMITS_SUPPORTED /* This function was added to libpng 1.2.6 */ void PNGAPI -png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, +png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max) { /* Images with dimensions larger than these limits will be @@ -1231,35 +1576,64 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, /* This function was added to libpng 1.4.0 */ void PNGAPI -png_set_chunk_cache_max (png_structp png_ptr, - png_uint_32 user_chunk_cache_max) +png_set_chunk_cache_max (png_structrp png_ptr, png_uint_32 user_chunk_cache_max) { - if (png_ptr) + if (png_ptr != NULL) png_ptr->user_chunk_cache_max = user_chunk_cache_max; } /* This function was added to libpng 1.4.1 */ void PNGAPI -png_set_chunk_malloc_max (png_structp png_ptr, +png_set_chunk_malloc_max (png_structrp png_ptr, png_alloc_size_t user_chunk_malloc_max) { - if (png_ptr) + if (png_ptr != NULL) png_ptr->user_chunk_malloc_max = user_chunk_malloc_max; } -#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ +#endif /* ?SET_USER_LIMITS */ #ifdef PNG_BENIGN_ERRORS_SUPPORTED void PNGAPI -png_set_benign_errors(png_structp png_ptr, int allowed) +png_set_benign_errors(png_structrp png_ptr, int allowed) { png_debug(1, "in png_set_benign_errors"); - if (allowed) - png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; + /* If allowed is 1, png_benign_error() is treated as a warning. + * + * If allowed is 0, png_benign_error() is treated as an error (which + * is the default behavior if png_set_benign_errors() is not called). + */ + + if (allowed != 0) + png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN | + PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN; else - png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; + png_ptr->flags &= ~(PNG_FLAG_BENIGN_ERRORS_WARN | + PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN); } -#endif /* PNG_BENIGN_ERRORS_SUPPORTED */ -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ +#endif /* BENIGN_ERRORS */ + +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Whether to report invalid palette index; added at libng-1.5.10. + * It is possible for an indexed (color-type==3) PNG file to contain + * pixels with invalid (out-of-range) indexes if the PLTE chunk has + * fewer entries than the image's bit-depth would allow. We recover + * from this gracefully by filling any incomplete palette with zeros + * (opaque black). By default, when this occurs libpng will issue + * a benign error. This API can be used to override that behavior. + */ +void PNGAPI +png_set_check_for_invalid_index(png_structrp png_ptr, int allowed) +{ + png_debug(1, "in png_set_check_for_invalid_index"); + + if (allowed > 0) + png_ptr->num_palette_max = 0; + + else + png_ptr->num_palette_max = -1; +} +#endif +#endif /* READ || WRITE */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngstruct.h b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngstruct.h index 6a587e34b58..8670a5a4e8d 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngstruct.h +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngstruct.h @@ -29,11 +29,11 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Copyright (c) 1998-2013 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * - * Last changed in libpng 1.5.4 [July 7, 2011] + * Last changed in libpng 1.6.1 [March 28, 2013] * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer @@ -52,13 +52,130 @@ * in this structure and is required for decompressing the LZ compressed * data in PNG files. */ +#ifndef ZLIB_CONST + /* We must ensure that zlib uses 'const' in declarations. */ +# define ZLIB_CONST +#endif #include "zlib.h" +#ifdef const + /* zlib.h sometimes #defines const to nothing, undo this. */ +# undef const +#endif + +/* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility + * with older builds. + */ +#if ZLIB_VERNUM < 0x1260 +# define PNGZ_MSG_CAST(s) png_constcast(char*,s) +# define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b) +#else +# define PNGZ_MSG_CAST(s) (s) +# define PNGZ_INPUT_CAST(b) (b) +#endif + +/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib + * can handle at once. This type need be no larger than 16 bits (so maximum of + * 65535), this define allows us to discover how big it is, but limited by the + * maximuum for png_size_t. The value can be overriden in a library build + * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably + * lower value (e.g. 255 works). A lower value may help memory usage (slightly) + * and may even improve performance on some systems (and degrade it on others.) + */ +#ifndef ZLIB_IO_MAX +# define ZLIB_IO_MAX ((uInt)-1) +#endif + +#ifdef PNG_WRITE_SUPPORTED +/* The type of a compression buffer list used by the write code. */ +typedef struct png_compression_buffer +{ + struct png_compression_buffer *next; + png_byte output[1]; /* actually zbuf_size */ +} png_compression_buffer, *png_compression_bufferp; + +#define PNG_COMPRESSION_BUFFER_SIZE(pp)\ + (offsetof(png_compression_buffer, output) + (pp)->zbuffer_size) +#endif + +/* Colorspace support; structures used in png_struct, png_info and in internal + * functions to hold and communicate information about the color space. + * + * PNG_COLORSPACE_SUPPORTED is only required if the application will perform + * colorspace corrections, otherwise all the colorspace information can be + * skipped and the size of libpng can be reduced (significantly) by compiling + * out the colorspace support. + */ +#ifdef PNG_COLORSPACE_SUPPORTED +/* The chromaticities of the red, green and blue colorants and the chromaticity + * of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)). + */ +typedef struct png_xy +{ + png_fixed_point redx, redy; + png_fixed_point greenx, greeny; + png_fixed_point bluex, bluey; + png_fixed_point whitex, whitey; +} png_xy; + +/* The same data as above but encoded as CIE XYZ values. When this data comes + * from chromaticities the sum of the Y values is assumed to be 1.0 + */ +typedef struct png_XYZ +{ + png_fixed_point red_X, red_Y, red_Z; + png_fixed_point green_X, green_Y, green_Z; + png_fixed_point blue_X, blue_Y, blue_Z; +} png_XYZ; +#endif /* COLORSPACE */ + +#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) +/* A colorspace is all the above plus, potentially, profile information, + * however at present libpng does not use the profile internally so it is only + * stored in the png_info struct (if iCCP is supported.) The rendering intent + * is retained here and is checked. + * + * The file gamma encoding information is also stored here and gamma correction + * is done by libpng, whereas color correction must currently be done by the + * application. + */ +typedef struct png_colorspace +{ +#ifdef PNG_GAMMA_SUPPORTED + png_fixed_point gamma; /* File gamma */ +#endif + +#ifdef PNG_COLORSPACE_SUPPORTED + png_xy end_points_xy; /* End points as chromaticities */ + png_XYZ end_points_XYZ; /* End points as CIE XYZ colorant values */ + png_uint_16 rendering_intent; /* Rendering intent of a profile */ +#endif + + /* Flags are always defined to simplify the code. */ + png_uint_16 flags; /* As defined below */ +} png_colorspace, * PNG_RESTRICT png_colorspacerp; + +typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp; + +/* General flags for the 'flags' field */ +#define PNG_COLORSPACE_HAVE_GAMMA 0x0001 +#define PNG_COLORSPACE_HAVE_ENDPOINTS 0x0002 +#define PNG_COLORSPACE_HAVE_INTENT 0x0004 +#define PNG_COLORSPACE_FROM_gAMA 0x0008 +#define PNG_COLORSPACE_FROM_cHRM 0x0010 +#define PNG_COLORSPACE_FROM_sRGB 0x0020 +#define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0040 +#define PNG_COLORSPACE_MATCHES_sRGB 0x0080 /* exact match on profile */ +#define PNG_COLORSPACE_INVALID 0x8000 +#define PNG_COLORSPACE_CANCEL(flags) (0xffff ^ (flags)) +#endif /* COLORSPACE || GAMMA */ struct png_struct_def { #ifdef PNG_SETJMP_SUPPORTED - jmp_buf longjmp_buffer; /* used in png_error */ + jmp_buf jmp_buf_local; /* New name in 1.6.0 for jmp_buf in png_struct */ png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */ + jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */ + size_t jmp_buf_size; /* size of the above, if allocated */ #endif png_error_ptr error_fn; /* function for printing errors and aborting */ #ifdef PNG_WARNINGS_SUPPORTED @@ -91,22 +208,12 @@ struct png_struct_def png_uint_32 flags; /* flags indicating various things to libpng */ png_uint_32 transformations; /* which transformations to perform */ - z_stream zstream; /* pointer to decompression structure (below) */ - png_bytep zbuf; /* buffer for zlib */ - uInt zbuf_size; /* size of zbuf (typically 65536) */ + png_uint_32 zowner; /* ID (chunk type) of zstream owner, 0 if none */ + z_stream zstream; /* decompression structure */ + #ifdef PNG_WRITE_SUPPORTED - -/* Added in 1.5.4: state to keep track of whether the zstream has been - * initialized and if so whether it is for IDAT or some other chunk. - */ -#define PNG_ZLIB_UNINITIALIZED 0 -#define PNG_ZLIB_FOR_IDAT 1 -#define PNG_ZLIB_FOR_TEXT 2 /* anything other than IDAT */ -#define PNG_ZLIB_USE_MASK 3 /* bottom two bits */ -#define PNG_ZLIB_IN_USE 4 /* a flag value */ - - png_uint_32 zlib_state; /* State of zlib initialization */ -/* End of material added at libpng 1.5.4 */ + png_compression_bufferp zbuffer_list; /* Created on demand during write */ + uInt zbuffer_size; /* size of the actual buffer */ int zlib_level; /* holds zlib compression level */ int zlib_method; /* holds zlib compression method */ @@ -115,8 +222,7 @@ struct png_struct_def int zlib_strategy; /* holds zlib compression strategy */ #endif /* Added at libpng 1.5.4 */ -#if defined(PNG_WRITE_COMPRESSED_TEXT_SUPPORTED) || \ - defined(PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED) +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED int zlib_text_level; /* holds zlib compression level */ int zlib_text_method; /* holds zlib compression method */ int zlib_text_window_bits; /* holds zlib compression window bits */ @@ -124,6 +230,14 @@ struct png_struct_def int zlib_text_strategy; /* holds zlib compression strategy */ #endif /* End of material added at libpng 1.5.4 */ +/* Added at libpng 1.6.0 */ +#ifdef PNG_WRITE_SUPPORTED + int zlib_set_level; /* Actual values set into the zstream on write */ + int zlib_set_method; + int zlib_set_window_bits; + int zlib_set_mem_level; + int zlib_set_strategy; +#endif png_uint_32 width; /* width of image in pixels */ png_uint_32 height; /* height of image in pixels */ @@ -132,21 +246,32 @@ struct png_struct_def png_size_t rowbytes; /* size of row in bytes */ png_uint_32 iwidth; /* width of current interlaced row in pixels */ png_uint_32 row_number; /* current row in interlace pass */ - png_bytep prev_row; /* buffer to save previous (unfiltered) row */ - png_bytep row_buf; /* buffer to save current (unfiltered) row */ + png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */ + png_bytep prev_row; /* buffer to save previous (unfiltered) row. + * This is a pointer into big_prev_row + */ + png_bytep row_buf; /* buffer to save current (unfiltered) row. + * This is a pointer into big_row_buf + */ +#ifdef PNG_WRITE_SUPPORTED png_bytep sub_row; /* buffer to save "sub" row when filtering */ png_bytep up_row; /* buffer to save "up" row when filtering */ png_bytep avg_row; /* buffer to save "avg" row when filtering */ png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */ - png_row_info row_info; /* used for transformation routines */ +#endif png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */ png_uint_32 idat_size; /* current IDAT size for read */ png_uint_32 crc; /* current chunk CRC value */ png_colorp palette; /* palette from the input file */ png_uint_16 num_palette; /* number of color entries in palette */ + +/* Added at libpng-1.5.10 */ +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED + int num_palette_max; /* maximum palette index found in IDAT */ +#endif + png_uint_16 num_trans; /* number of transparency values */ - png_byte chunk_name[5]; /* null-terminated name of current chunk */ png_byte compression; /* file compression type (always 0) */ png_byte filter; /* file filter type (always 0) */ png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ @@ -154,12 +279,17 @@ struct png_struct_def png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */ png_byte color_type; /* color type of file */ png_byte bit_depth; /* bit depth of file */ - png_byte usr_bit_depth; /* bit depth of users row */ + png_byte usr_bit_depth; /* bit depth of users row: write only */ png_byte pixel_depth; /* number of bits per pixel */ png_byte channels; /* number of channels in file */ - png_byte usr_channels; /* channels at start of write */ +#ifdef PNG_WRITE_SUPPORTED + png_byte usr_channels; /* channels at start of write: write only */ +#endif png_byte sig_bytes; /* magic bytes read/written from start of file */ - + png_byte maximum_pixel_depth; + /* pixel depth used for the row buffers */ + png_byte transformed_pixel_depth; + /* pixel depth after read/write transforms */ #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) png_uint_16 filler; /* filler bytes for pixel expansion */ #endif @@ -172,7 +302,7 @@ struct png_struct_def #ifdef PNG_READ_GAMMA_SUPPORTED png_color_16 background_1; /* background normalized to gamma 1.0 */ #endif -#endif /* PNG_bKGD_SUPPORTED */ +#endif /* bKGD */ #ifdef PNG_WRITE_FLUSH_SUPPORTED png_flush_ptr output_flush_fn; /* Function for flushing output */ @@ -180,19 +310,20 @@ struct png_struct_def png_uint_32 flush_rows; /* number of rows written since last flush */ #endif -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) +#ifdef PNG_READ_GAMMA_SUPPORTED int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */ - png_fixed_point gamma; /* file gamma value */ png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */ -#endif -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) png_bytep gamma_table; /* gamma table for 8-bit depth files */ + png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */ +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) png_bytep gamma_from_1; /* converts from 1.0 to screen */ png_bytep gamma_to_1; /* converts from file to 1.0 */ - png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */ png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */ png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */ +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ #endif #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) @@ -228,14 +359,7 @@ struct png_struct_def int process_mode; /* what push library is currently doing */ int cur_palette; /* current push library palette index */ -# ifdef PNG_TEXT_SUPPORTED - png_size_t current_text_size; /* current size of text input data */ - png_size_t current_text_left; /* how much text left to read in input */ - png_charp current_text; /* current text chunk buffer */ - png_charp current_text_ptr; /* current location in current_text */ -# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */ - -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ +#endif /* PROGRESSIVE_READ */ #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) /* For the Borland special 64K segment handler */ @@ -251,10 +375,6 @@ struct png_struct_def png_bytep quantize_index; /* index translation for palette files */ #endif -#if defined(PNG_READ_QUANTIZE_SUPPORTED) || defined(PNG_hIST_SUPPORTED) - png_uint_16p hist; /* histogram */ -#endif - #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED png_byte heuristic_method; /* heuristic for row filter selection */ png_byte num_prev_filters; /* number of weights for previous rows */ @@ -265,9 +385,17 @@ struct png_struct_def png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */ #endif + /* Options */ +#ifdef PNG_SET_OPTION_SUPPORTED + png_byte options; /* On/off state (up to 4 options) */ +#endif + +#if PNG_LIBPNG_VER < 10700 +/* To do: remove this from libpng-1.7 */ #ifdef PNG_TIME_RFC1123_SUPPORTED char time_buffer[29]; /* String to hold RFC 1123 time text */ #endif +#endif /* New members added in libpng-1.0.6 */ @@ -275,27 +403,31 @@ struct png_struct_def #ifdef PNG_USER_CHUNKS_SUPPORTED png_voidp user_chunk_ptr; +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */ #endif +#endif -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - int num_chunk_list; - png_bytep chunk_list; +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + int unknown_default; /* As PNG_HANDLE_* */ + unsigned int num_chunk_list; /* Number of entries in the list */ + png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name + * followed by a PNG_HANDLE_* byte */ #endif /* New members added in libpng-1.0.3 */ #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED png_byte rgb_to_gray_status; + /* Added in libpng 1.5.5 to record setting of coefficients: */ + png_byte rgb_to_gray_coefficients_set; /* These were changed from png_byte in libpng-1.0.6 */ png_uint_16 rgb_to_gray_red_coeff; png_uint_16 rgb_to_gray_green_coeff; - png_uint_16 rgb_to_gray_blue_coeff; + /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */ #endif /* New member added in libpng-1.0.4 (renamed in 1.0.9) */ -#if defined(PNG_MNG_FEATURES_SUPPORTED) || \ - defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ - defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) +#if defined(PNG_MNG_FEATURES_SUPPORTED) /* Changed from png_byte to png_uint_32 at version 1.2.0 */ png_uint_32 mng_features_permitted; #endif @@ -345,21 +477,41 @@ struct png_struct_def #endif /* New member added in libpng-1.0.25 and 1.2.17 */ -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED - /* Storage for unknown chunk that the library doesn't recognize. */ +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + /* Temporary storage for unknown chunk that the library doesn't recognize, + * used while reading the chunk. + */ png_unknown_chunk unknown_chunk; #endif -/* New members added in libpng-1.2.26 */ +/* New member added in libpng-1.2.26 */ png_size_t old_big_row_buf_size; - png_size_t old_prev_row_size; +#ifdef PNG_READ_SUPPORTED /* New member added in libpng-1.2.30 */ - png_charp chunkdata; /* buffer for reading chunk data */ + png_bytep read_buffer; /* buffer for reading chunk data */ + png_alloc_size_t read_buffer_size; /* current size of the buffer */ +#endif +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED + uInt IDAT_read_size; /* limit on read buffer size for IDAT */ +#endif #ifdef PNG_IO_STATE_SUPPORTED /* New member added in libpng-1.4.0 */ png_uint_32 io_state; #endif + +/* New member added in libpng-1.5.6 */ + png_bytep big_prev_row; + +/* New member added in libpng-1.5.7 */ + void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info, + png_bytep row, png_const_bytep prev_row); + +#ifdef PNG_READ_SUPPORTED +#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) + png_colorspace colorspace; +#endif +#endif }; #endif /* PNGSTRUCT_H */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngtest.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngtest.c index 227181fbf96..fdd51acd04d 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngtest.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngtest.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -61,16 +61,50 @@ #define _POSIX_SOURCE 1 -#include "zlib.h" +#include +#include +#include + +/* Defined so I can write to a file on gui/windowing platforms */ +/* #define STDERR stderr */ +#define STDERR stdout /* For DOS */ + #include "png.h" + +/* Known chunks that exist in pngtest.png must be supported or pngtest will fail + * simply as a result of re-ordering them. This may be fixed in 1.7 + * + * pngtest allocates a single row buffer for each row and overwrites it, + * therefore if the write side doesn't support the writing of interlaced images + * nothing can be done for an interlaced image (and the code below will fail + * horribly trying to write extra data after writing garbage). + */ +#if defined PNG_READ_SUPPORTED && /* else nothing can be done */\ + defined PNG_READ_bKGD_SUPPORTED &&\ + defined PNG_READ_cHRM_SUPPORTED &&\ + defined PNG_READ_gAMA_SUPPORTED &&\ + defined PNG_READ_oFFs_SUPPORTED &&\ + defined PNG_READ_pCAL_SUPPORTED &&\ + defined PNG_READ_pHYs_SUPPORTED &&\ + defined PNG_READ_sBIT_SUPPORTED &&\ + defined PNG_READ_sCAL_SUPPORTED &&\ + defined PNG_READ_sRGB_SUPPORTED &&\ + defined PNG_READ_tEXt_SUPPORTED &&\ + defined PNG_READ_tIME_SUPPORTED &&\ + defined PNG_READ_zTXt_SUPPORTED &&\ + defined PNG_WRITE_INTERLACING_SUPPORTED + +#ifdef PNG_ZLIB_HEADER +# include PNG_ZLIB_HEADER /* defined by pnglibconf.h from 1.7 */ +#else +# include "zlib.h" +#endif + /* Copied from pngpriv.h but only used in error messages below. */ #ifndef PNG_ZBUF_SIZE # define PNG_ZBUF_SIZE 8192 #endif -# include -# include -# include -# define FCLOSE(file) fclose(file) +#define FCLOSE(file) fclose(file) #ifndef PNG_STDIO_SUPPORTED typedef FILE * png_FILE_p; @@ -95,17 +129,6 @@ typedef FILE * png_FILE_p; # define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */ #endif -/* The code uses memcmp and memcpy on large objects (typically row pointers) so - * it is necessary to do soemthing special on certain architectures, note that - * the actual support for this was effectively removed in 1.4, so only the - * memory remains in this program: - */ -#define CVT_PTR(ptr) (ptr) -#define CVT_PTR_NOCHECK(ptr) (ptr) -#define png_memcmp memcmp -#define png_memcpy memcpy -#define png_memset memset - /* Turn on CPU timing #define PNGTEST_TIMING */ @@ -126,30 +149,34 @@ static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present"; #endif static int verbose = 0; - -int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname)); - -#ifdef __TURBOC__ -#include -#endif - -/* Defined so I can write to a file on gui/windowing platforms */ -/* #define STDERR stderr */ -#define STDERR stdout /* For DOS */ +static int strict = 0; +static int relaxed = 0; +static int unsupported_chunks = 0; /* chunk unsupported by libpng in input */ +static int error_count = 0; /* count calls to png_error */ +static int warning_count = 0; /* count calls to png_warning */ /* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ #ifndef png_jmpbuf # define png_jmpbuf(png_ptr) png_ptr->jmpbuf #endif +/* Defines for unknown chunk handling if required. */ +#ifndef PNG_HANDLE_CHUNK_ALWAYS +# define PNG_HANDLE_CHUNK_ALWAYS 3 +#endif +#ifndef PNG_HANDLE_CHUNK_IF_SAFE +# define PNG_HANDLE_CHUNK_IF_SAFE 2 +#endif + +/* Utility to save typing/errors, the argument must be a name */ +#define MEMZERO(var) ((void)memset(&var, 0, sizeof var)) + /* Example of using row callbacks to make a simple progress meter */ static int status_pass = 1; static int status_dots_requested = 0; static int status_dots = 1; -void PNGCBAPI -read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); -void PNGCBAPI +static void PNGCBAPI read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) { if (png_ptr == NULL || row_number > PNG_UINT_31_MAX) @@ -173,9 +200,8 @@ read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) fprintf(stdout, "r"); } -void PNGCBAPI -write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); -void PNGCBAPI +#ifdef PNG_WRITE_SUPPORTED +static void PNGCBAPI write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) { if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) @@ -183,6 +209,7 @@ write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) fprintf(stdout, "w"); } +#endif #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED @@ -191,9 +218,7 @@ write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) * 5 in case illegal filter values are present.) */ static png_uint_32 filters_used[256]; -void PNGCBAPI -count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data); -void PNGCBAPI +static void PNGCBAPI count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data) { if (png_ptr != NULL && row_info != NULL) @@ -208,9 +233,7 @@ count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data) static png_uint_32 zero_samples; -void PNGCBAPI -count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data); -void PNGCBAPI +static void PNGCBAPI count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) { png_bytep dp = data; @@ -288,7 +311,8 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) png_uint_32 n, nstop; int channel; int color_channels = row_info->channels; - if (row_info->color_type > 3)color_channels--; + if (row_info->color_type > 3) + color_channels--; for (n = 0, nstop=row_info->width; nfile_name != NULL) + name = test->file_name; + + fprintf(STDERR, "%s: libpng warning: %s\n", name, message); } /* This is the default error handling function. Note that replacements for @@ -566,12 +483,14 @@ pngtest_warning(png_structp png_ptr, png_const_charp message) static void PNGCBAPI pngtest_error(png_structp png_ptr, png_const_charp message) { + ++error_count; + pngtest_warning(png_ptr, message); /* We can return because png_error calls the default handler, which is * actually OK in this case. */ } -#endif /* !PNG_STDIO_SUPPORTED */ + /* END of code to validate stdio-free compilation */ /* START of code to validate memory allocation and deallocation */ @@ -590,9 +509,9 @@ typedef struct memory_information { png_alloc_size_t size; png_voidp pointer; - struct memory_information FAR *next; + struct memory_information *next; } memory_information; -typedef memory_information FAR *memory_infop; +typedef memory_information *memory_infop; static memory_infop pinformation = NULL; static int current_allocation = 0; @@ -622,7 +541,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size) memory_infop pinfo; png_set_mem_fn(png_ptr, NULL, NULL, NULL); pinfo = (memory_infop)png_malloc(png_ptr, - png_sizeof(*pinfo)); + (sizeof *pinfo)); pinfo->size = size; current_allocation += size; total_allocation += size; @@ -648,9 +567,9 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size) pinfo->next = pinformation; pinformation = pinfo; /* Make sure the caller isn't assuming zeroed memory. */ - png_memset(pinfo->pointer, 0xdd, pinfo->size); + memset(pinfo->pointer, 0xdd, pinfo->size); - if (verbose) + if (verbose != 0) printf("png_malloc %lu bytes at %p\n", (unsigned long)size, pinfo->pointer); @@ -675,7 +594,7 @@ png_debug_free(png_structp png_ptr, png_voidp ptr) /* Unlink the element from the list. */ { - memory_infop FAR *ppinfo = &pinformation; + memory_infop *ppinfo = &pinformation; for (;;) { @@ -689,15 +608,16 @@ png_debug_free(png_structp png_ptr, png_voidp ptr) fprintf(STDERR, "Duplicate free of memory\n"); /* We must free the list element too, but first kill the memory that is to be freed. */ - png_memset(ptr, 0x55, pinfo->size); - png_free_default(png_ptr, pinfo); + memset(ptr, 0x55, pinfo->size); + if (pinfo != NULL) + free(pinfo); pinfo = NULL; break; } if (pinfo->next == NULL) { - fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr); + fprintf(STDERR, "Pointer %p not found\n", ptr); break; } @@ -706,35 +626,84 @@ png_debug_free(png_structp png_ptr, png_voidp ptr) } /* Finally free the data. */ - if (verbose) + if (verbose != 0) printf("Freeing %p\n", ptr); - png_free_default(png_ptr, ptr); + if (ptr != NULL) + free(ptr); ptr = NULL; } -#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */ +#endif /* USER_MEM && DEBUG */ /* END of code to test memory allocation/deallocation */ +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED /* Demonstration of user chunk support of the sTER and vpAg chunks */ -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED /* (sTER is a public chunk not yet known by libpng. vpAg is a private chunk used in ImageMagick to store "virtual page" size). */ -static png_uint_32 user_chunk_data[4]; - - /* 0: sTER mode + 1 - * 1: vpAg width - * 2: vpAg height - * 3: vpAg units - */ - -static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr, - png_unknown_chunkp chunk) +static struct user_chunk_data { - png_uint_32 - *my_user_chunk_data; + png_const_infop info_ptr; + png_uint_32 vpAg_width, vpAg_height; + png_byte vpAg_units; + png_byte sTER_mode; + int location[2]; +} +user_chunk_data; + +/* Used for location and order; zero means nothing. */ +#define have_sTER 0x01 +#define have_vpAg 0x02 +#define before_PLTE 0x10 +#define before_IDAT 0x20 +#define after_IDAT 0x40 + +static void +init_callback_info(png_const_infop info_ptr) +{ + MEMZERO(user_chunk_data); + user_chunk_data.info_ptr = info_ptr; +} + +static int +set_location(png_structp png_ptr, struct user_chunk_data *data, int what) +{ + int location; + + if ((data->location[0] & what) != 0 || (data->location[1] & what) != 0) + return 0; /* already have one of these */ + + /* Find where we are (the code below zeroes info_ptr to indicate that the + * chunks before the first IDAT have been read.) + */ + if (data->info_ptr == NULL) /* after IDAT */ + location = what | after_IDAT; + + else if (png_get_valid(png_ptr, data->info_ptr, PNG_INFO_PLTE) != 0) + location = what | before_IDAT; + + else + location = what | before_PLTE; + + if (data->location[0] == 0) + data->location[0] = location; + + else + data->location[1] = location; + + return 1; /* handled */ +} + +static int PNGCBAPI +read_user_chunk_callback(png_struct *png_ptr, png_unknown_chunkp chunk) +{ + struct user_chunk_data *my_user_chunk_data = + (struct user_chunk_data*)png_get_user_chunk_ptr(png_ptr); + + if (my_user_chunk_data == NULL) + png_error(png_ptr, "lost user chunk pointer"); /* Return one of the following: * return (-n); chunk had an error @@ -759,9 +728,14 @@ static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr, if (chunk->data[0] != 0 && chunk->data[0] != 1) return (-1); /* Invalid mode */ - my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr); - my_user_chunk_data[0]=chunk->data[0]+1; - return (1); + if (set_location(png_ptr, my_user_chunk_data, have_sTER) != 0) + { + my_user_chunk_data->sTER_mode=chunk->data[0]; + return (1); + } + + else + return (0); /* duplicate sTER - give it to libpng */ } if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */ @@ -773,30 +747,126 @@ static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr, if (chunk->size != 9) return (-1); /* Error return */ - my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr); + if (set_location(png_ptr, my_user_chunk_data, have_vpAg) == 0) + return (0); /* duplicate vpAg */ - my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data); - my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4); - my_user_chunk_data[3]=(png_uint_32)chunk->data[8]; + my_user_chunk_data->vpAg_width = png_get_uint_31(png_ptr, chunk->data); + my_user_chunk_data->vpAg_height = png_get_uint_31(png_ptr, chunk->data + 4); + my_user_chunk_data->vpAg_units = chunk->data[8]; return (1); - } + +#ifdef PNG_WRITE_SUPPORTED +static void +write_sTER_chunk(png_structp write_ptr) +{ + png_byte sTER[5] = {115, 84, 69, 82, '\0'}; + + if (verbose != 0) + fprintf(STDERR, "\n stereo mode = %d\n", user_chunk_data.sTER_mode); + + png_write_chunk(write_ptr, sTER, &user_chunk_data.sTER_mode, 1); +} + +static void +write_vpAg_chunk(png_structp write_ptr) +{ + png_byte vpAg[5] = {118, 112, 65, 103, '\0'}; + + png_byte vpag_chunk_data[9]; + + if (verbose != 0) + fprintf(STDERR, " vpAg = %lu x %lu, units = %d\n", + (unsigned long)user_chunk_data.vpAg_width, + (unsigned long)user_chunk_data.vpAg_height, + user_chunk_data.vpAg_units); + + png_save_uint_32(vpag_chunk_data, user_chunk_data.vpAg_width); + png_save_uint_32(vpag_chunk_data + 4, user_chunk_data.vpAg_height); + vpag_chunk_data[8] = user_chunk_data.vpAg_units; + png_write_chunk(write_ptr, vpAg, vpag_chunk_data, 9); +} + +static void +write_chunks(png_structp write_ptr, int location) +{ + int i; + + /* Notice that this preserves the original chunk order, however chunks + * intercepted by the callback will be written *after* chunks passed to + * libpng. This will actually reverse a pair of sTER chunks or a pair of + * vpAg chunks, resulting in an error later. This is not worth worrying + * about - the chunks should not be duplicated! + */ + for (i=0; i<2; ++i) + { + if (user_chunk_data.location[i] == (location | have_sTER)) + write_sTER_chunk(write_ptr); + + else if (user_chunk_data.location[i] == (location | have_vpAg)) + write_vpAg_chunk(write_ptr); + } +} +#endif /* WRITE */ +#else /* !READ_USER_CHUNKS */ +# define write_chunks(pp,loc) ((void)0) #endif /* END of code to demonstrate user chunk support */ +/* START of code to check that libpng has the required text support; this only + * checks for the write support because if read support is missing the chunk + * will simply not be reported back to pngtest. + */ +#ifdef PNG_TEXT_SUPPORTED +static void +pngtest_check_text_support(png_const_structp png_ptr, png_textp text_ptr, + int num_text) +{ + while (num_text > 0) + { + switch (text_ptr[--num_text].compression) + { + case PNG_TEXT_COMPRESSION_NONE: + break; + + case PNG_TEXT_COMPRESSION_zTXt: +# ifndef PNG_WRITE_zTXt_SUPPORTED + ++unsupported_chunks; +# endif + break; + + case PNG_ITXT_COMPRESSION_NONE: + case PNG_ITXT_COMPRESSION_zTXt: +# ifndef PNG_WRITE_iTXt_SUPPORTED + ++unsupported_chunks; +# endif + break; + + default: + /* This is an error */ + png_error(png_ptr, "invalid text chunk compression field"); + break; + } + } +} +#endif +/* END of code to check that libpng has the required text support */ + /* Test one file */ -int +static int test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) { static png_FILE_p fpin; static png_FILE_p fpout; /* "static" prevents setjmp corruption */ + pngtest_error_parameters error_parameters; png_structp read_ptr; png_infop read_info_ptr, end_info_ptr; #ifdef PNG_WRITE_SUPPORTED png_structp write_ptr; png_infop write_info_ptr; png_infop write_end_info_ptr; + int interlace_preserved = 1; #else png_structp write_ptr = NULL; png_infop write_info_ptr = NULL; @@ -805,17 +875,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) png_bytep row_buf; png_uint_32 y; png_uint_32 width, height; - int num_pass, pass; + int num_pass = 1, pass; int bit_depth, color_type; -#ifdef PNG_SETJMP_SUPPORTED -#ifdef USE_FAR_KEYWORD - jmp_buf tmp_jmpbuf; -#endif -#endif - - char inbuf[256], outbuf[256]; row_buf = NULL; + error_parameters.file_name = inname; if ((fpin = fopen(inname, "rb")) == NULL) { @@ -839,20 +903,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); #endif -#ifndef PNG_STDIO_SUPPORTED - png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error, - pngtest_warning); -#endif + png_set_error_fn(read_ptr, &error_parameters, pngtest_error, + pngtest_warning); -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED - user_chunk_data[0] = 0; - user_chunk_data[1] = 0; - user_chunk_data[2] = 0; - user_chunk_data[3] = 0; - png_set_read_user_chunk_fn(read_ptr, user_chunk_data, - read_user_chunk_callback); - -#endif #ifdef PNG_WRITE_SUPPORTED #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG write_ptr = @@ -862,10 +915,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); #endif -#ifndef PNG_STDIO_SUPPORTED - png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error, - pngtest_warning); -#endif + png_set_error_fn(write_ptr, &error_parameters, pngtest_error, + pngtest_warning); #endif pngtest_debug("Allocating read_info, write_info and end_info structures"); read_info_ptr = png_create_info_struct(read_ptr); @@ -875,13 +926,15 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) write_end_info_ptr = png_create_info_struct(write_ptr); #endif +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + init_callback_info(read_info_ptr); + png_set_read_user_chunk_fn(read_ptr, &user_chunk_data, + read_user_chunk_callback); +#endif + #ifdef PNG_SETJMP_SUPPORTED pngtest_debug("Setting jmpbuf for read struct"); -#ifdef USE_FAR_KEYWORD - if (setjmp(tmp_jmpbuf)) -#else if (setjmp(png_jmpbuf(read_ptr))) -#endif { fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); png_free(read_ptr, row_buf); @@ -895,18 +948,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) FCLOSE(fpout); return (1); } -#ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(read_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); -#endif #ifdef PNG_WRITE_SUPPORTED pngtest_debug("Setting jmpbuf for write struct"); -#ifdef USE_FAR_KEYWORD - if (setjmp(tmp_jmpbuf)) -#else if (setjmp(png_jmpbuf(write_ptr))) -#endif { fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname); png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); @@ -918,12 +964,34 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) FCLOSE(fpout); return (1); } +#endif +#endif -#ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(write_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); -#endif + if (strict != 0) + { + /* Treat png_benign_error() as errors on read */ + png_set_benign_errors(read_ptr, 0); + +#ifdef PNG_WRITE_SUPPORTED + /* Treat them as errors on write */ + png_set_benign_errors(write_ptr, 0); #endif + + /* if strict is not set, then app warnings and errors are treated as + * warnings in release builds, but not in unstable builds; this can be + * changed with '--relaxed'. + */ + } + + else if (relaxed != 0) + { + /* Allow application (pngtest) errors and warnings to pass */ + png_set_benign_errors(read_ptr, 1); + +#ifdef PNG_WRITE_SUPPORTED + png_set_benign_errors(write_ptr, 1); #endif + } pngtest_debug("Initializing input and output streams"); #ifdef PNG_STDIO_SUPPORTED @@ -943,14 +1011,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) # endif #endif -#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED - /* Normally one would use Z_DEFAULT_STRATEGY for text compression. - * This is here just to make pngtest replicate the results from libpng - * versions prior to 1.5.4, and to test this new API. - */ - png_set_text_compression_strategy(write_ptr, Z_FILTERED); -#endif - if (status_dots_requested == 1) { #ifdef PNG_WRITE_SUPPORTED @@ -982,36 +1042,65 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) png_set_write_user_transform_fn(write_ptr, count_zero_samples); #endif -#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED -# ifndef PNG_HANDLE_CHUNK_ALWAYS -# define PNG_HANDLE_CHUNK_ALWAYS 3 -# endif +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + /* Preserve all the unknown chunks, if possible. If this is disabled then, + * even if the png_{get,set}_unknown_chunks stuff is enabled, we can't use + * libpng to *save* the unknown chunks on read (because we can't switch the + * save option on!) + * + * Notice that if SET_UNKNOWN_CHUNKS is *not* supported read will discard all + * unknown chunks and write will write them all. + */ +#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, NULL, 0); #endif #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED -# ifndef PNG_HANDLE_CHUNK_IF_SAFE -# define PNG_HANDLE_CHUNK_IF_SAFE 2 -# endif - png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE, + png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS, NULL, 0); +#endif #endif pngtest_debug("Reading info struct"); png_read_info(read_ptr, read_info_ptr); +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + /* This is a bit of a hack; there is no obvious way in the callback function + * to determine that the chunks before the first IDAT have been read, so + * remove the info_ptr (which is only used to determine position relative to + * PLTE) here to indicate that we are after the IDAT. + */ + user_chunk_data.info_ptr = NULL; +#endif + pngtest_debug("Transferring info struct"); { int interlace_type, compression_type, filter_type; if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth, - &color_type, &interlace_type, &compression_type, &filter_type)) + &color_type, &interlace_type, &compression_type, &filter_type) != 0) { png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, -#ifdef PNG_WRITE_INTERLACING_SUPPORTED color_type, interlace_type, compression_type, filter_type); -#else - color_type, PNG_INTERLACE_NONE, compression_type, filter_type); +#ifndef PNG_READ_INTERLACING_SUPPORTED + /* num_pass will not be set below, set it here if the image is + * interlaced: what happens is that write interlacing is *not* turned + * on an the partial interlaced rows are written directly. + */ + switch (interlace_type) + { + case PNG_INTERLACE_NONE: + num_pass = 1; + break; + + case PNG_INTERLACE_ADAM7: + num_pass = 7; + break; + + default: + png_error(read_ptr, "invalid interlace type"); + /*NOT REACHED*/ + } #endif } } @@ -1022,7 +1111,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) blue_y; if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, - &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y)) + &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0) { png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); @@ -1033,7 +1122,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) { png_fixed_point gamma; - if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma)) + if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma) != 0) png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma); } #endif @@ -1045,7 +1134,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) blue_y; if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, - &red_y, &green_x, &green_y, &blue_x, &blue_y)) + &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0) { png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); @@ -1056,7 +1145,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) { double gamma; - if (png_get_gAMA(read_ptr, read_info_ptr, &gamma)) + if (png_get_gAMA(read_ptr, read_info_ptr, &gamma) != 0) png_set_gAMA(write_ptr, write_info_ptr, gamma); } #endif @@ -1070,7 +1159,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) int compression_type; if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type, - &profile, &proflen)) + &profile, &proflen) != 0) { png_set_iCCP(write_ptr, write_info_ptr, name, compression_type, profile, proflen); @@ -1081,7 +1170,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) { int intent; - if (png_get_sRGB(read_ptr, read_info_ptr, &intent)) + if (png_get_sRGB(read_ptr, read_info_ptr, &intent) != 0) png_set_sRGB(write_ptr, write_info_ptr, intent); } #endif @@ -1089,14 +1178,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) png_colorp palette; int num_palette; - if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) + if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette) != 0) png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); } #ifdef PNG_bKGD_SUPPORTED { png_color_16p background; - if (png_get_bKGD(read_ptr, read_info_ptr, &background)) + if (png_get_bKGD(read_ptr, read_info_ptr, &background) != 0) { png_set_bKGD(write_ptr, write_info_ptr, background); } @@ -1106,7 +1195,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) { png_uint_16p hist; - if (png_get_hIST(read_ptr, read_info_ptr, &hist)) + if (png_get_hIST(read_ptr, read_info_ptr, &hist) != 0) png_set_hIST(write_ptr, write_info_ptr, hist); } #endif @@ -1116,7 +1205,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) int unit_type; if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y, - &unit_type)) + &unit_type) != 0) { png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type); } @@ -1130,7 +1219,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) int type, nparams; if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type, - &nparams, &units, ¶ms)) + &nparams, &units, ¶ms) != 0) { png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type, nparams, units, params); @@ -1142,7 +1231,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) png_uint_32 res_x, res_y; int unit_type; - if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type)) + if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, + &unit_type) != 0) png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); } #endif @@ -1150,18 +1240,19 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) { png_color_8p sig_bit; - if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit)) + if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit) != 0) png_set_sBIT(write_ptr, write_info_ptr, sig_bit); } #endif #ifdef PNG_sCAL_SUPPORTED -#ifdef PNG_FLOATING_POINT_SUPPORTED +#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ + defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) { int unit; double scal_width, scal_height; if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width, - &scal_height)) + &scal_height) != 0) { png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height); } @@ -1173,7 +1264,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) png_charp scal_width, scal_height; if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width, - &scal_height)) + &scal_height) != 0) { png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, scal_height); @@ -1190,6 +1281,21 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0) { pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); + + pngtest_check_text_support(read_ptr, text_ptr, num_text); + + if (verbose != 0) + { + int i; + + printf("\n"); + for (i=0; i 0) { pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); + + pngtest_check_text_support(read_ptr, text_ptr, num_text); + + if (verbose != 0) + { + int i; + + printf("\n"); + for (i=0; i 0) + { + /* We don't really expect to get here because of the setjmp handling + * above, but this is safe. + */ + fprintf(STDERR, "\n %s: %d libpng errors found (%d warnings)", + inname, error_count, warning_count); + + if (strict != 0) + return (1); + } + +# ifdef PNG_WRITE_SUPPORTED + /* If there we no write support nothing was written! */ + else if (unsupported_chunks > 0) + { + fprintf(STDERR, "\n %s: unsupported chunks (%d)%s", + inname, unsupported_chunks, strict ? ": IGNORED --strict!" : ""); + } +# endif + + else if (warning_count > 0) + { + fprintf(STDERR, "\n %s: %d libpng warnings found", + inname, warning_count); + + if (strict != 0) + return (1); + } + pngtest_debug("Opening files for comparison"); if ((fpin = fopen(inname, "rb")) == NULL) { @@ -1480,61 +1629,84 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) return (1); } - for (;;) +#ifdef PNG_WRITE_SUPPORTED /* else nothing was written */ + if (interlace_preserved != 0) /* else the files will be changed */ { - png_size_t num_in, num_out; - - num_in = fread(inbuf, 1, 1, fpin); - num_out = fread(outbuf, 1, 1, fpout); - - if (num_in != num_out) + for (;;) { - fprintf(STDERR, "\nFiles %s and %s are of a different size\n", - inname, outname); + static int wrote_question = 0; + png_size_t num_in, num_out; + char inbuf[256], outbuf[256]; - if (wrote_question == 0) + num_in = fread(inbuf, 1, sizeof inbuf, fpin); + num_out = fread(outbuf, 1, sizeof outbuf, fpout); + + if (num_in != num_out) { - fprintf(STDERR, - " Was %s written with the same maximum IDAT chunk size (%d bytes),", - inname, PNG_ZBUF_SIZE); - fprintf(STDERR, - "\n filtering heuristic (libpng default), compression"); - fprintf(STDERR, - " level (zlib default),\n and zlib version (%s)?\n\n", - ZLIB_VERSION); - wrote_question = 1; - } + fprintf(STDERR, "\nFiles %s and %s are of a different size\n", + inname, outname); - FCLOSE(fpin); - FCLOSE(fpout); - return (0); - } - - if (!num_in) - break; - - if (png_memcmp(inbuf, outbuf, num_in)) - { - fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname); - - if (wrote_question == 0) - { - fprintf(STDERR, + if (wrote_question == 0 && unsupported_chunks == 0) + { + fprintf(STDERR, " Was %s written with the same maximum IDAT chunk size (%d bytes),", inname, PNG_ZBUF_SIZE); - fprintf(STDERR, - "\n filtering heuristic (libpng default), compression"); - fprintf(STDERR, - " level (zlib default),\n and zlib version (%s)?\n\n", - ZLIB_VERSION); - wrote_question = 1; + fprintf(STDERR, + "\n filtering heuristic (libpng default), compression"); + fprintf(STDERR, + " level (zlib default),\n and zlib version (%s)?\n\n", + ZLIB_VERSION); + wrote_question = 1; + } + + FCLOSE(fpin); + FCLOSE(fpout); + + if (strict != 0 && unsupported_chunks == 0) + return (1); + + else + return (0); } - FCLOSE(fpin); - FCLOSE(fpout); - return (0); + if (num_in == 0) + break; + + if (memcmp(inbuf, outbuf, num_in)) + { + fprintf(STDERR, "\nFiles %s and %s are different\n", inname, + outname); + + if (wrote_question == 0 && unsupported_chunks == 0) + { + fprintf(STDERR, + " Was %s written with the same maximum IDAT chunk size (%d bytes),", + inname, PNG_ZBUF_SIZE); + fprintf(STDERR, + "\n filtering heuristic (libpng default), compression"); + fprintf(STDERR, + " level (zlib default),\n and zlib version (%s)?\n\n", + ZLIB_VERSION); + wrote_question = 1; + } + + FCLOSE(fpin); + FCLOSE(fpout); + + /* NOTE: the unsupported_chunks escape is permitted here because + * unsupported text chunk compression will result in the compression + * mode being changed (to NONE) yet, in the test case, the result + * can be exactly the same size! + */ + if (strict != 0 && unsupported_chunks == 0) + return (1); + + else + return (0); + } } } +#endif /* WRITE */ FCLOSE(fpin); FCLOSE(fpout); @@ -1614,6 +1786,24 @@ main(int argc, char *argv[]) inname = argv[2]; } + else if (strcmp(argv[1], "--strict") == 0) + { + status_dots_requested = 0; + verbose = 1; + inname = argv[2]; + strict++; + relaxed = 0; + } + + else if (strcmp(argv[1], "--relaxed") == 0) + { + status_dots_requested = 0; + verbose = 1; + inname = argv[2]; + strict = 0; + relaxed++; + } + else { inname = argv[1]; @@ -1621,10 +1811,11 @@ main(int argc, char *argv[]) } } - if (!multiple && argc == 3 + verbose) + if (multiple == 0 && argc == 3 + verbose) outname = argv[2 + verbose]; - if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2)) + if ((multiple == 0 && argc > 3 + verbose) || + (multiple != 0 && argc < 2)) { fprintf(STDERR, "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", @@ -1636,7 +1827,7 @@ main(int argc, char *argv[]) exit(1); } - if (multiple) + if (multiple != 0) { int i; #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG @@ -1646,6 +1837,9 @@ main(int argc, char *argv[]) { int kerror; fprintf(STDERR, "\n Testing %s:", argv[i]); +#if PNG_DEBUG > 0 + fprintf(STDERR, "\n"); +#endif kerror = test_one_file(argv[i], outname); if (kerror == 0) { @@ -1660,7 +1854,7 @@ main(int argc, char *argv[]) #endif #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED for (k = 0; k<256; k++) - if (filters_used[k]) + if (filters_used[k] != 0) fprintf(STDERR, " Filter %d was used %lu times\n", k, (unsigned long)filters_used[k]); #endif @@ -1669,7 +1863,7 @@ main(int argc, char *argv[]) fprintf(STDERR, " tIME = %s\n", tIME_string); tIME_chunk_present = 0; -#endif /* PNG_TIME_RFC1123_SUPPORTED */ +#endif /* TIME_RFC1123 */ } else @@ -1691,9 +1885,9 @@ main(int argc, char *argv[]) while (pinfo != NULL) { - fprintf(STDERR, " %lu bytes at %x\n", + fprintf(STDERR, " %lu bytes at %p\n", (unsigned long)pinfo->size, - (unsigned int)pinfo->pointer); + pinfo->pointer); pinfo = pinfo->next; } } @@ -1727,7 +1921,12 @@ main(int argc, char *argv[]) status_dots_requested = 0; if (i == 0 || verbose == 1 || ierror != 0) + { fprintf(STDERR, "\n Testing %s:", inname); +#if PNG_DEBUG > 0 + fprintf(STDERR, "\n"); +#endif + } kerror = test_one_file(inname, outname); @@ -1746,21 +1945,26 @@ main(int argc, char *argv[]) #endif #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED for (k = 0; k<256; k++) - if (filters_used[k]) + if (filters_used[k] != 0) fprintf(STDERR, " Filter %d was used %lu times\n", k, (unsigned long)filters_used[k]); #endif #ifdef PNG_TIME_RFC1123_SUPPORTED if (tIME_chunk_present != 0) fprintf(STDERR, " tIME = %s\n", tIME_string); -#endif /* PNG_TIME_RFC1123_SUPPORTED */ +#endif /* TIME_RFC1123 */ } } else { if (verbose == 0 && i != 2) + { fprintf(STDERR, "\n Testing %s:", inname); +#if PNG_DEBUG > 0 + fprintf(STDERR, "\n"); +#endif + } fprintf(STDERR, " FAIL\n"); ierror += kerror; @@ -1779,8 +1983,8 @@ main(int argc, char *argv[]) while (pinfo != NULL) { - fprintf(STDERR, " %lu bytes at %x\n", - (unsigned long)pinfo->size, (unsigned int)pinfo->pointer); + fprintf(STDERR, " %lu bytes at %p\n", + (unsigned long)pinfo->size, pinfo->pointer); pinfo = pinfo->next; } } @@ -1820,6 +2024,16 @@ main(int argc, char *argv[]) return (int)(ierror != 0); } +#else +int +main(void) +{ + fprintf(STDERR, + " test ignored because libpng was not built with read support\n"); + /* And skip this test */ + return PNG_LIBPNG_VER < 10600 ? 0 : 77; +} +#endif /* Generate a compiler error if there is an old png.h in the search path. */ -typedef png_libpng_version_1_5_4 Your_png_h_is_not_version_1_5_4; +typedef png_libpng_version_1_6_16 Your_png_h_is_not_version_1_6_16; diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngtrans.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngtrans.c index b59fc695bed..5b95db8c66b 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngtrans.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngtrans.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -46,7 +46,7 @@ #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) /* Turn on BGR-to-RGB mapping */ void PNGAPI -png_set_bgr(png_structp png_ptr) +png_set_bgr(png_structrp png_ptr) { png_debug(1, "in png_set_bgr"); @@ -60,7 +60,7 @@ png_set_bgr(png_structp png_ptr) #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) /* Turn on 16 bit byte swapping */ void PNGAPI -png_set_swap(png_structp png_ptr) +png_set_swap(png_structrp png_ptr) { png_debug(1, "in png_set_swap"); @@ -75,7 +75,7 @@ png_set_swap(png_structp png_ptr) #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) /* Turn on pixel packing */ void PNGAPI -png_set_packing(png_structp png_ptr) +png_set_packing(png_structrp png_ptr) { png_debug(1, "in png_set_packing"); @@ -85,7 +85,9 @@ png_set_packing(png_structp png_ptr) if (png_ptr->bit_depth < 8) { png_ptr->transformations |= PNG_PACK; - png_ptr->usr_bit_depth = 8; +# ifdef PNG_WRITE_SUPPORTED + png_ptr->usr_bit_depth = 8; +# endif } } #endif @@ -93,7 +95,7 @@ png_set_packing(png_structp png_ptr) #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) /* Turn on packed pixel swapping */ void PNGAPI -png_set_packswap(png_structp png_ptr) +png_set_packswap(png_structrp png_ptr) { png_debug(1, "in png_set_packswap"); @@ -107,7 +109,7 @@ png_set_packswap(png_structp png_ptr) #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) void PNGAPI -png_set_shift(png_structp png_ptr, png_const_color_8p true_bits) +png_set_shift(png_structrp png_ptr, png_const_color_8p true_bits) { png_debug(1, "in png_set_shift"); @@ -122,11 +124,11 @@ png_set_shift(png_structp png_ptr, png_const_color_8p true_bits) #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ defined(PNG_WRITE_INTERLACING_SUPPORTED) int PNGAPI -png_set_interlace_handling(png_structp png_ptr) +png_set_interlace_handling(png_structrp png_ptr) { png_debug(1, "in png_set_interlace handling"); - if (png_ptr && png_ptr->interlaced) + if (png_ptr != 0 && png_ptr->interlaced != 0) { png_ptr->transformations |= PNG_INTERLACE; return (7); @@ -143,44 +145,91 @@ png_set_interlace_handling(png_structp png_ptr) * that don't like bytes as parameters. */ void PNGAPI -png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) +png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc) { png_debug(1, "in png_set_filler"); if (png_ptr == NULL) return; + /* In libpng 1.6 it is possible to determine whether this is a read or write + * operation and therefore to do more checking here for a valid call. + */ + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) + { +# ifdef PNG_READ_FILLER_SUPPORTED + /* On read png_set_filler is always valid, regardless of the base PNG + * format, because other transformations can give a format where the + * filler code can execute (basically an 8 or 16-bit component RGB or G + * format.) + * + * NOTE: usr_channels is not used by the read code! (This has led to + * confusion in the past.) The filler is only used in the read code. + */ + png_ptr->filler = (png_uint_16)filler; +# else + png_app_error(png_ptr, "png_set_filler not supported on read"); + PNG_UNUSED(filler) /* not used in the write case */ + return; +# endif + } + + else /* write */ + { +# ifdef PNG_WRITE_FILLER_SUPPORTED + /* On write the usr_channels parameter must be set correctly at the + * start to record the number of channels in the app-supplied data. + */ + switch (png_ptr->color_type) + { + case PNG_COLOR_TYPE_RGB: + png_ptr->usr_channels = 4; + break; + + case PNG_COLOR_TYPE_GRAY: + if (png_ptr->bit_depth >= 8) + { + png_ptr->usr_channels = 2; + break; + } + + else + { + /* There simply isn't any code in libpng to strip out bits + * from bytes when the components are less than a byte in + * size! + */ + png_app_error(png_ptr, + "png_set_filler is invalid for low bit depth gray output"); + return; + } + + default: + png_app_error(png_ptr, + "png_set_filler: inappropriate color type"); + return; + } +# else + png_app_error(png_ptr, "png_set_filler not supported on write"); + return; +# endif + } + + /* Here on success - libpng supports the operation, set the transformation + * and the flag to say where the filler channel is. + */ png_ptr->transformations |= PNG_FILLER; - png_ptr->filler = (png_uint_16)filler; if (filler_loc == PNG_FILLER_AFTER) png_ptr->flags |= PNG_FLAG_FILLER_AFTER; else png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; - - /* This should probably go in the "do_read_filler" routine. - * I attempted to do that in libpng-1.0.1a but that caused problems - * so I restored it in libpng-1.0.2a - */ - - if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) - { - png_ptr->usr_channels = 4; - } - - /* Also I added this in libpng-1.0.2a (what happens when we expand - * a less-than-8-bit grayscale to GA?) */ - - if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8) - { - png_ptr->usr_channels = 2; - } } /* Added to libpng-1.2.7 */ void PNGAPI -png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) +png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc) { png_debug(1, "in png_set_add_alpha"); @@ -188,7 +237,9 @@ png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) return; png_set_filler(png_ptr, filler, filler_loc); - png_ptr->transformations |= PNG_ADD_ALPHA; + /* The above may fail to do anything. */ + if ((png_ptr->transformations & PNG_FILLER) != 0) + png_ptr->transformations |= PNG_ADD_ALPHA; } #endif @@ -196,7 +247,7 @@ png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) void PNGAPI -png_set_swap_alpha(png_structp png_ptr) +png_set_swap_alpha(png_structrp png_ptr) { png_debug(1, "in png_set_swap_alpha"); @@ -210,7 +261,7 @@ png_set_swap_alpha(png_structp png_ptr) #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) void PNGAPI -png_set_invert_alpha(png_structp png_ptr) +png_set_invert_alpha(png_structrp png_ptr) { png_debug(1, "in png_set_invert_alpha"); @@ -223,7 +274,7 @@ png_set_invert_alpha(png_structp png_ptr) #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) void PNGAPI -png_set_invert_mono(png_structp png_ptr) +png_set_invert_mono(png_structrp png_ptr) { png_debug(1, "in png_set_invert_mono"); @@ -304,9 +355,16 @@ png_do_swap(png_row_infop row_info, png_bytep row) for (i = 0; i < istop; i++, rp += 2) { +#ifdef PNG_BUILTIN_BSWAP16_SUPPORTED + /* Feature added to libpng-1.6.11 for testing purposes, not + * enabled by default. + */ + *(png_uint_16*)rp = __builtin_bswap16(*(png_uint_16*)rp); +#else png_byte t = *rp; *rp = *(rp + 1); *(rp + 1) = t; +#endif } } } @@ -448,7 +506,7 @@ png_do_packswap(png_row_infop row_info, png_bytep row) *rp = table[*rp]; } } -#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ +#endif /* PACKSWAP || WRITE_PACKSWAP */ #if defined(PNG_WRITE_FILLER_SUPPORTED) || \ defined(PNG_READ_STRIP_ALPHA_SUPPORTED) @@ -480,7 +538,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) { if (row_info->bit_depth == 8) { - if (at_start) /* Skip initial filler */ + if (at_start != 0) /* Skip initial filler */ ++sp; else /* Skip initial channel and, for sp, the filler */ sp += 2, ++dp; @@ -494,7 +552,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) else if (row_info->bit_depth == 16) { - if (at_start) /* Skip initial filler */ + if (at_start != 0) /* Skip initial filler */ sp += 2; else /* Skip initial channel and, for sp, the filler */ sp += 4, dp += 2; @@ -520,7 +578,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) { if (row_info->bit_depth == 8) { - if (at_start) /* Skip initial filler */ + if (at_start != 0) /* Skip initial filler */ ++sp; else /* Skip initial channels and, for sp, the filler */ sp += 4, dp += 3; @@ -534,7 +592,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) else if (row_info->bit_depth == 16) { - if (at_start) /* Skip initial filler */ + if (at_start != 0) /* Skip initial filler */ sp += 2; else /* Skip initial channels and, for sp, the filler */ sp += 8, dp += 6; @@ -575,7 +633,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_bgr"); - if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) + if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) { png_uint_32 row_width = row_info->width; if (row_info->bit_depth == 8) @@ -645,19 +703,133 @@ png_do_bgr(png_row_infop row_info, png_bytep row) #endif } } -#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ +#endif /* READ_BGR || WRITE_BGR */ + +#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ + defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) +/* Added at libpng-1.5.10 */ +void /* PRIVATE */ +png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info) +{ + if (png_ptr->num_palette < (1 << row_info->bit_depth) && + png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */ + { + /* Calculations moved outside switch in an attempt to stop different + * compiler warnings. 'padding' is in *bits* within the last byte, it is + * an 'int' because pixel_depth becomes an 'int' in the expression below, + * and this calculation is used because it avoids warnings that other + * forms produced on either GCC or MSVC. + */ + int padding = (-row_info->pixel_depth * row_info->width) & 7; + png_bytep rp = png_ptr->row_buf + row_info->rowbytes; + + switch (row_info->bit_depth) + { + case 1: + { + /* in this case, all bytes must be 0 so we don't need + * to unpack the pixels except for the rightmost one. + */ + for (; rp > png_ptr->row_buf; rp--) + { + if (*rp >> padding != 0) + png_ptr->num_palette_max = 1; + padding = 0; + } + + break; + } + + case 2: + { + for (; rp > png_ptr->row_buf; rp--) + { + int i = ((*rp >> padding) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 2) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 4) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 6) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + padding = 0; + } + + break; + } + + case 4: + { + for (; rp > png_ptr->row_buf; rp--) + { + int i = ((*rp >> padding) & 0x0f); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 4) & 0x0f); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + padding = 0; + } + + break; + } + + case 8: + { + for (; rp > png_ptr->row_buf; rp--) + { + if (*rp > png_ptr->num_palette_max) + png_ptr->num_palette_max = (int) *rp; + } + + break; + } + + default: + break; + } + } +} +#endif /* CHECK_FOR_INVALID_INDEX */ #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED void PNGAPI -png_set_user_transform_info(png_structp png_ptr, png_voidp +png_set_user_transform_info(png_structrp png_ptr, png_voidp user_transform_ptr, int user_transform_depth, int user_transform_channels) { png_debug(1, "in png_set_user_transform_info"); if (png_ptr == NULL) return; + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && + (png_ptr->flags & PNG_FLAG_ROW_INIT) != 0) + { + png_app_error(png_ptr, + "info change after png_start_read_image or png_read_update_info"); + return; + } +#endif + png_ptr->user_transform_ptr = user_transform_ptr; png_ptr->user_transform_depth = (png_byte)user_transform_depth; png_ptr->user_transform_channels = (png_byte)user_transform_channels; @@ -671,20 +843,20 @@ png_set_user_transform_info(png_structp png_ptr, png_voidp */ #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED png_voidp PNGAPI -png_get_user_transform_ptr(png_const_structp png_ptr) +png_get_user_transform_ptr(png_const_structrp png_ptr) { if (png_ptr == NULL) return (NULL); - return ((png_voidp)png_ptr->user_transform_ptr); + return png_ptr->user_transform_ptr; } #endif #ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED png_uint_32 PNGAPI -png_get_current_row_number(png_const_structp png_ptr) +png_get_current_row_number(png_const_structrp png_ptr) { - /* See the comments in png.h - this is the sub-image row when reading and + /* See the comments in png.h - this is the sub-image row when reading an * interlaced image. */ if (png_ptr != NULL) @@ -694,13 +866,12 @@ png_get_current_row_number(png_const_structp png_ptr) } png_byte PNGAPI -png_get_current_pass_number(png_const_structp png_ptr) +png_get_current_pass_number(png_const_structrp png_ptr) { if (png_ptr != NULL) return png_ptr->pass; return 8; /* invalid */ } -#endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */ -#endif /* PNG_READ_USER_TRANSFORM_SUPPORTED || - PNG_WRITE_USER_TRANSFORM_SUPPORTED */ -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ +#endif /* USER_TRANSFORM_INFO */ +#endif /* READ_USER_TRANSFORM || WRITE_USER_TRANSFORM */ +#endif /* READ || WRITE */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwio.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwio.c index 2f94f8c9572..017a9d7b31b 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwio.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwio.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.0 [January 6, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -58,11 +58,12 @@ */ void /* PRIVATE */ -png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length) +png_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length) { /* NOTE: write_data_fn must not change the buffer! */ if (png_ptr->write_data_fn != NULL ) - (*(png_ptr->write_data_fn))(png_ptr, (png_bytep)data, length); + (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data), + length); else png_error(png_ptr, "Call to NULL write function"); @@ -74,7 +75,6 @@ png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length) * write_data function and use it at run time with png_set_write_fn(), rather * than changing the library. */ -#ifndef USE_FAR_KEYWORD void PNGCBAPI png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { @@ -88,64 +88,6 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) if (check != length) png_error(png_ptr, "Write Error"); } -#else -/* This is the model-independent version. Since the standard I/O library - * can't handle far buffers in the medium and small models, we have to copy - * the data. - */ - -#define NEAR_BUF_SIZE 1024 -#define MIN(a,b) (a <= b ? a : b) - -void PNGCBAPI -png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_uint_32 check; - png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ - png_FILE_p io_ptr; - - if (png_ptr == NULL) - return; - - /* Check if data really is near. If so, use usual code. */ - near_data = (png_byte *)CVT_PTR_NOCHECK(data); - io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); - - if ((png_bytep)near_data == data) - { - check = fwrite(near_data, 1, length, io_ptr); - } - - else - { - png_byte buf[NEAR_BUF_SIZE]; - png_size_t written, remaining, err; - check = 0; - remaining = length; - - do - { - written = MIN(NEAR_BUF_SIZE, remaining); - png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ - err = fwrite(buf, 1, written, io_ptr); - - if (err != written) - break; - - else - check += err; - - data += written; - remaining -= written; - } - while (remaining != 0); - } - - if (check != length) - png_error(png_ptr, "Write Error"); -} - -#endif #endif /* This function is called to output any data pending writing (normally @@ -154,7 +96,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) */ #ifdef PNG_WRITE_FLUSH_SUPPORTED void /* PRIVATE */ -png_flush(png_structp png_ptr) +png_flush(png_structrp png_ptr) { if (png_ptr->output_flush_fn != NULL) (*(png_ptr->output_flush_fn))(png_ptr); @@ -169,7 +111,7 @@ png_default_flush(png_structp png_ptr) if (png_ptr == NULL) return; - io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); + io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr)); fflush(io_ptr); } # endif @@ -205,7 +147,7 @@ png_default_flush(png_structp png_ptr) * *FILE structure. */ void PNGAPI -png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, +png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) { if (png_ptr == NULL) @@ -235,8 +177,11 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, # else png_ptr->output_flush_fn = output_flush_fn; # endif -#endif /* PNG_WRITE_FLUSH_SUPPORTED */ +#else + PNG_UNUSED(output_flush_fn) +#endif /* WRITE_FLUSH */ +#ifdef PNG_READ_SUPPORTED /* It is an error to read while writing a png file */ if (png_ptr->read_data_fn != NULL) { @@ -246,37 +191,6 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, "Can't set both read_data_fn and write_data_fn in the" " same structure"); } -} - -#ifdef USE_FAR_KEYWORD -# ifdef _MSC_VER -void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) -{ - void *near_ptr; - void FAR *far_ptr; - FP_OFF(near_ptr) = FP_OFF(ptr); - far_ptr = (void FAR *)near_ptr; - - if (check != 0) - if (FP_SEG(ptr) != FP_SEG(far_ptr)) - png_error(png_ptr, "segment lost in conversion"); - - return(near_ptr); -} -# else -void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) -{ - void *near_ptr; - void FAR *far_ptr; - near_ptr = (void FAR *)ptr; - far_ptr = (void FAR *)near_ptr; - - if (check != 0) - if (far_ptr != ptr) - png_error(png_ptr, "segment lost in conversion"); - - return(near_ptr); -} -# endif #endif -#endif /* PNG_WRITE_SUPPORTED */ +} +#endif /* WRITE */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwrite.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwrite.c index bdc14670964..1d39e7490f7 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwrite.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwrite.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -40,9 +40,65 @@ */ #include "pngpriv.h" +#if defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) +# include +#endif #ifdef PNG_WRITE_SUPPORTED +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +/* Write out all the unknown chunks for the current given location */ +static void +write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr, + unsigned int where) +{ + if (info_ptr->unknown_chunks_num != 0) + { + png_const_unknown_chunkp up; + + png_debug(5, "writing extra chunks"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + ++up) + if ((up->location & where) != 0) + { + /* If per-chunk unknown chunk handling is enabled use it, otherwise + * just write the chunks the application has set. + */ +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + int keep = png_handle_as_unknown(png_ptr, up->name); + + /* NOTE: this code is radically different from the read side in the + * matter of handling an ancillary unknown chunk. In the read side + * the default behavior is to discard it, in the code below the default + * behavior is to write it. Critical chunks are, however, only + * written if explicitly listed or if the default is set to write all + * unknown chunks. + * + * The default handling is also slightly weird - it is not possible to + * stop the writing of all unsafe-to-copy chunks! + * + * TODO: REVIEW: this would seem to be a bug. + */ + if (keep != PNG_HANDLE_CHUNK_NEVER && + ((up->name[3] & 0x20) /* safe-to-copy overrides everything */ || + keep == PNG_HANDLE_CHUNK_ALWAYS || + (keep == PNG_HANDLE_CHUNK_AS_DEFAULT && + png_ptr->unknown_default == PNG_HANDLE_CHUNK_ALWAYS))) +#endif + { + /* TODO: review, what is wrong with a zero length unknown chunk? */ + if (up->size == 0) + png_warning(png_ptr, "Writing zero-length unknown chunk"); + + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +} +#endif /* WRITE_UNKNOWN_CHUNKS */ + /* Writes all the PNG information. This is the suggested way to use the * library. If you have a new chunk to add, make a function to write it, * and put it in the correct location here. If you want the chunk written @@ -53,21 +109,21 @@ * them in png_write_end(), and compressing them. */ void PNGAPI -png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) +png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr) { png_debug(1, "in png_write_info_before_PLTE"); if (png_ptr == NULL || info_ptr == NULL) return; - if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) + if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0) { /* Write PNG signature */ png_write_sig(png_ptr); #ifdef PNG_MNG_FEATURES_SUPPORTED - if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \ - (png_ptr->mng_features_permitted)) + if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && \ + png_ptr->mng_features_permitted != 0) { png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); png_ptr->mng_features_permitted = 0; @@ -79,75 +135,88 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, info_ptr->filter_type, #ifdef PNG_WRITE_INTERLACING_SUPPORTED - info_ptr->interlace_type); + info_ptr->interlace_type #else - 0); + 0 #endif + ); + /* The rest of these check to see if the valid field has the appropriate * flag set, and if it does, writes the chunk. + * + * 1.6.0: COLORSPACE support controls the writing of these chunks too, and + * the chunks will be written if the WRITE routine is there and information + * is available in the COLORSPACE. (See png_colorspace_sync_info in png.c + * for where the valid flags get set.) + * + * Under certain circumstances the colorspace can be invalidated without + * syncing the info_struct 'valid' flags; this happens if libpng detects and + * error and calls png_error while the color space is being set, yet the + * application continues writing the PNG. So check the 'invalid' flag here + * too. */ -#ifdef PNG_WRITE_gAMA_SUPPORTED - if (info_ptr->valid & PNG_INFO_gAMA) - png_write_gAMA_fixed(png_ptr, info_ptr->gamma); -#endif -#ifdef PNG_WRITE_sRGB_SUPPORTED - if (info_ptr->valid & PNG_INFO_sRGB) - png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); +#ifdef PNG_GAMMA_SUPPORTED +# ifdef PNG_WRITE_gAMA_SUPPORTED + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_gAMA) != 0 && + (info_ptr->valid & PNG_INFO_gAMA) != 0) + png_write_gAMA_fixed(png_ptr, info_ptr->colorspace.gamma); +# endif #endif -#ifdef PNG_WRITE_iCCP_SUPPORTED - if (info_ptr->valid & PNG_INFO_iCCP) - png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, - (png_charp)info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); -#endif +#ifdef PNG_COLORSPACE_SUPPORTED + /* Write only one of sRGB or an ICC profile. If a profile was supplied + * and it matches one of the known sRGB ones issue a warning. + */ +# ifdef PNG_WRITE_iCCP_SUPPORTED + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->valid & PNG_INFO_iCCP) != 0) + { +# ifdef PNG_WRITE_sRGB_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sRGB) != 0) + png_app_warning(png_ptr, + "profile matches sRGB but writing iCCP instead"); +# endif + + png_write_iCCP(png_ptr, info_ptr->iccp_name, + info_ptr->iccp_profile); + } +# ifdef PNG_WRITE_sRGB_SUPPORTED + else +# endif +# endif + +# ifdef PNG_WRITE_sRGB_SUPPORTED + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->valid & PNG_INFO_sRGB) != 0) + png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent); +# endif /* WRITE_sRGB */ +#endif /* COLORSPACE */ + #ifdef PNG_WRITE_sBIT_SUPPORTED - if (info_ptr->valid & PNG_INFO_sBIT) + if ((info_ptr->valid & PNG_INFO_sBIT) != 0) png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); #endif -#ifdef PNG_WRITE_cHRM_SUPPORTED - if (info_ptr->valid & PNG_INFO_cHRM) - png_write_cHRM_fixed(png_ptr, - info_ptr->x_white, info_ptr->y_white, - info_ptr->x_red, info_ptr->y_red, - info_ptr->x_green, info_ptr->y_green, - info_ptr->x_blue, info_ptr->y_blue); + +#ifdef PNG_COLORSPACE_SUPPORTED +# ifdef PNG_WRITE_cHRM_SUPPORTED + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 && + (info_ptr->valid & PNG_INFO_cHRM) != 0) + png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy); +# endif #endif #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - if (info_ptr->unknown_chunks_num) - { - png_unknown_chunk *up; - - png_debug(5, "writing extra chunks"); - - for (up = info_ptr->unknown_chunks; - up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; - up++) - { - int keep = png_handle_as_unknown(png_ptr, up->name); - - if (keep != PNG_HANDLE_CHUNK_NEVER && - up->location && - !(up->location & PNG_HAVE_PLTE) && - !(up->location & PNG_HAVE_IDAT) && - !(up->location & PNG_AFTER_IDAT) && - ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || - (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) - { - if (up->size == 0) - png_warning(png_ptr, "Writing zero-length unknown chunk"); - - png_write_chunk(png_ptr, up->name, up->data, up->size); - } - } - } + write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR); #endif + png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; } } void PNGAPI -png_write_info(png_structp png_ptr, png_infop info_ptr) +png_write_info(png_structrp png_ptr, png_const_inforp info_ptr) { #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) int i; @@ -160,19 +229,19 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) png_write_info_before_PLTE(png_ptr, info_ptr); - if (info_ptr->valid & PNG_INFO_PLTE) + if ((info_ptr->valid & PNG_INFO_PLTE) != 0) png_write_PLTE(png_ptr, info_ptr->palette, (png_uint_32)info_ptr->num_palette); - else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + else if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) !=0) png_error(png_ptr, "Valid palette required for paletted images"); #ifdef PNG_WRITE_tRNS_SUPPORTED - if (info_ptr->valid & PNG_INFO_tRNS) + if ((info_ptr->valid & PNG_INFO_tRNS) !=0) { #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED /* Invert the alpha channel (in tRNS) */ - if ((png_ptr->transformations & PNG_INVERT_ALPHA) && + if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0 && info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { int j; @@ -186,42 +255,42 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) } #endif #ifdef PNG_WRITE_bKGD_SUPPORTED - if (info_ptr->valid & PNG_INFO_bKGD) + if ((info_ptr->valid & PNG_INFO_bKGD) != 0) png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); #endif #ifdef PNG_WRITE_hIST_SUPPORTED - if (info_ptr->valid & PNG_INFO_hIST) + if ((info_ptr->valid & PNG_INFO_hIST) != 0) png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); #endif #ifdef PNG_WRITE_oFFs_SUPPORTED - if (info_ptr->valid & PNG_INFO_oFFs) + if ((info_ptr->valid & PNG_INFO_oFFs) != 0) png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, info_ptr->offset_unit_type); #endif #ifdef PNG_WRITE_pCAL_SUPPORTED - if (info_ptr->valid & PNG_INFO_pCAL) + if ((info_ptr->valid & PNG_INFO_pCAL) != 0) png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, info_ptr->pcal_units, info_ptr->pcal_params); #endif #ifdef PNG_WRITE_sCAL_SUPPORTED - if (info_ptr->valid & PNG_INFO_sCAL) + if ((info_ptr->valid & PNG_INFO_sCAL) != 0) png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, info_ptr->scal_s_width, info_ptr->scal_s_height); #endif /* sCAL */ #ifdef PNG_WRITE_pHYs_SUPPORTED - if (info_ptr->valid & PNG_INFO_pHYs) + if ((info_ptr->valid & PNG_INFO_pHYs) != 0) png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); #endif /* pHYs */ #ifdef PNG_WRITE_tIME_SUPPORTED - if (info_ptr->valid & PNG_INFO_tIME) + if ((info_ptr->valid & PNG_INFO_tIME) != 0) { png_write_tIME(png_ptr, &(info_ptr->mod_time)); png_ptr->mode |= PNG_WROTE_tIME; @@ -229,7 +298,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) #endif /* tIME */ #ifdef PNG_WRITE_sPLT_SUPPORTED - if (info_ptr->valid & PNG_INFO_sPLT) + if ((info_ptr->valid & PNG_INFO_sPLT) != 0) for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); #endif /* sPLT */ @@ -251,11 +320,14 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) info_ptr->text[i].lang, info_ptr->text[i].lang_key, info_ptr->text[i].text); + /* Mark this chunk as written */ + if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + else + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; #else - png_warning(png_ptr, "Unable to write international text"); + png_warning(png_ptr, "Unable to write international text"); #endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; } /* If we want a compressed text chunk */ @@ -264,13 +336,12 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) #ifdef PNG_WRITE_zTXt_SUPPORTED /* Write compressed chunk */ png_write_zTXt(png_ptr, info_ptr->text[i].key, - info_ptr->text[i].text, 0, - info_ptr->text[i].compression); + info_ptr->text[i].text, info_ptr->text[i].compression); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; #else png_warning(png_ptr, "Unable to write compressed text"); #endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; } else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) @@ -291,29 +362,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) #endif /* tEXt */ #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - if (info_ptr->unknown_chunks_num) - { - png_unknown_chunk *up; - - png_debug(5, "writing extra chunks"); - - for (up = info_ptr->unknown_chunks; - up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; - up++) - { - int keep = png_handle_as_unknown(png_ptr, up->name); - if (keep != PNG_HANDLE_CHUNK_NEVER && - up->location && - (up->location & PNG_HAVE_PLTE) && - !(up->location & PNG_HAVE_IDAT) && - !(up->location & PNG_AFTER_IDAT) && - ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || - (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) - { - png_write_chunk(png_ptr, up->name, up->data, up->size); - } - } - } + write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_PLTE); #endif } @@ -323,16 +372,21 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) * comments, I suggest writing them here, and compressing them. */ void PNGAPI -png_write_end(png_structp png_ptr, png_infop info_ptr) +png_write_end(png_structrp png_ptr, png_inforp info_ptr) { png_debug(1, "in png_write_end"); if (png_ptr == NULL) return; - if (!(png_ptr->mode & PNG_HAVE_IDAT)) + if ((png_ptr->mode & PNG_HAVE_IDAT) == 0) png_error(png_ptr, "No IDATs written into file"); +#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED + if (png_ptr->num_palette_max > png_ptr->num_palette) + png_benign_error(png_ptr, "Wrote palette index exceeding num_palette"); +#endif + /* See if user wants us to write information chunks */ if (info_ptr != NULL) { @@ -341,8 +395,8 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) #endif #ifdef PNG_WRITE_tIME_SUPPORTED /* Check to see if user has supplied a time chunk */ - if ((info_ptr->valid & PNG_INFO_tIME) && - !(png_ptr->mode & PNG_WROTE_tIME)) + if ((info_ptr->valid & PNG_INFO_tIME) != 0 && + (png_ptr->mode & PNG_WROTE_tIME) == 0) png_write_tIME(png_ptr, &(info_ptr->mod_time)); #endif @@ -363,11 +417,14 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) info_ptr->text[i].lang, info_ptr->text[i].lang_key, info_ptr->text[i].text); + /* Mark this chunk as written */ + if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + else + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; #else png_warning(png_ptr, "Unable to write international text"); #endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; } else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) @@ -375,13 +432,12 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) #ifdef PNG_WRITE_zTXt_SUPPORTED /* Write compressed chunk */ png_write_zTXt(png_ptr, info_ptr->text[i].key, - info_ptr->text[i].text, 0, - info_ptr->text[i].compression); + info_ptr->text[i].text, info_ptr->text[i].compression); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; #else png_warning(png_ptr, "Unable to write compressed text"); #endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; } else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) @@ -390,37 +446,16 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) /* Write uncompressed chunk */ png_write_tEXt(png_ptr, info_ptr->text[i].key, info_ptr->text[i].text, 0); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; #else png_warning(png_ptr, "Unable to write uncompressed text"); #endif - - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; } } #endif #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - if (info_ptr->unknown_chunks_num) - { - png_unknown_chunk *up; - - png_debug(5, "writing extra chunks"); - - for (up = info_ptr->unknown_chunks; - up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; - up++) - { - int keep = png_handle_as_unknown(png_ptr, up->name); - if (keep != PNG_HANDLE_CHUNK_NEVER && - up->location && - (up->location & PNG_AFTER_IDAT) && - ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || - (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) - { - png_write_chunk(png_ptr, up->name, up->data, up->size); - } - } - } + write_unknown_chunks(png_ptr, info_ptr, PNG_AFTER_IDAT); #endif } @@ -428,6 +463,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) /* Write end of PNG file */ png_write_IEND(png_ptr); + /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03, * and restored again in libpng-1.2.30, may cause some applications that * do not set png_ptr->output_flush_fn to crash. If your application @@ -443,9 +479,8 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) } #ifdef PNG_CONVERT_tIME_SUPPORTED -/* "tm" structure is not supported on WindowsCE */ void PNGAPI -png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm FAR * ttime) +png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm * ttime) { png_debug(1, "in png_convert_from_struct_tm"); @@ -474,103 +509,75 @@ PNG_FUNCTION(png_structp,PNGAPI png_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) { -#ifdef PNG_USER_MEM_SUPPORTED - return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, - warn_fn, NULL, NULL, NULL)); +#ifndef PNG_USER_MEM_SUPPORTED + png_structrp png_ptr = png_create_png_struct(user_png_ver, error_ptr, + error_fn, warn_fn, NULL, NULL, NULL); +#else + return png_create_write_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, NULL, NULL, NULL); } /* Alternate initialize png_ptr structure, and allocate any memory needed */ -static void png_reset_filter_heuristics(png_structp png_ptr); /* forward decl */ - PNG_FUNCTION(png_structp,PNGAPI png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) { -#endif /* PNG_USER_MEM_SUPPORTED */ - volatile int png_cleanup_needed = 0; -#ifdef PNG_SETJMP_SUPPORTED - volatile -#endif - png_structp png_ptr; -#ifdef PNG_SETJMP_SUPPORTED -#ifdef USE_FAR_KEYWORD - jmp_buf tmp_jmpbuf; -#endif -#endif - - png_debug(1, "in png_create_write_struct"); - -#ifdef PNG_USER_MEM_SUPPORTED - png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, - (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); -#else - png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); -#endif /* PNG_USER_MEM_SUPPORTED */ - if (png_ptr == NULL) - return (NULL); - - /* Added at libpng-1.2.6 */ -#ifdef PNG_SET_USER_LIMITS_SUPPORTED - png_ptr->user_width_max = PNG_USER_WIDTH_MAX; - png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; -#endif - -#ifdef PNG_SETJMP_SUPPORTED -/* Applications that neglect to set up their own setjmp() and then - encounter a png_error() will longjmp here. Since the jmpbuf is - then meaningless we abort instead of returning. */ -#ifdef USE_FAR_KEYWORD - if (setjmp(tmp_jmpbuf)) -#else - if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */ -#endif -#ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); -#endif - PNG_ABORT(); -#endif - -#ifdef PNG_USER_MEM_SUPPORTED - png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); -#endif /* PNG_USER_MEM_SUPPORTED */ - png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); - - if (!png_user_version_check(png_ptr, user_png_ver)) - png_cleanup_needed = 1; - - /* Initialize zbuf - compression buffer */ - png_ptr->zbuf_size = PNG_ZBUF_SIZE; - - if (!png_cleanup_needed) + png_structrp png_ptr = png_create_png_struct(user_png_ver, error_ptr, + error_fn, warn_fn, mem_ptr, malloc_fn, free_fn); +#endif /* USER_MEM */ + if (png_ptr != NULL) { - png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, - png_ptr->zbuf_size); - if (png_ptr->zbuf == NULL) - png_cleanup_needed = 1; + /* Set the zlib control values to defaults; they can be overridden by the + * application after the struct has been created. + */ + png_ptr->zbuffer_size = PNG_ZBUF_SIZE; + + /* The 'zlib_strategy' setting is irrelevant because png_default_claim in + * pngwutil.c defaults it according to whether or not filters will be + * used, and ignores this setting. + */ + png_ptr->zlib_strategy = PNG_Z_DEFAULT_STRATEGY; + png_ptr->zlib_level = PNG_Z_DEFAULT_COMPRESSION; + png_ptr->zlib_mem_level = 8; + png_ptr->zlib_window_bits = 15; + png_ptr->zlib_method = 8; + +#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED + png_ptr->zlib_text_strategy = PNG_TEXT_Z_DEFAULT_STRATEGY; + png_ptr->zlib_text_level = PNG_TEXT_Z_DEFAULT_COMPRESSION; + png_ptr->zlib_text_mem_level = 8; + png_ptr->zlib_text_window_bits = 15; + png_ptr->zlib_text_method = 8; +#endif /* WRITE_COMPRESSED_TEXT */ + + /* This is a highly dubious configuration option; by default it is off, + * but it may be appropriate for private builds that are testing + * extensions not conformant to the current specification, or of + * applications that must not fail to write at all costs! + */ +#ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED + /* In stable builds only warn if an application error can be completely + * handled. + */ + png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; +#endif + + /* App warnings are warnings in release (or release candidate) builds but + * are errors during development. + */ +#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC + png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN; +#endif + + /* TODO: delay this, it can be done in png_init_io() (if the app doesn't + * do it itself) avoiding setting the default function if it is not + * required. + */ + png_set_write_fn(png_ptr, NULL, NULL, NULL); } - if (png_cleanup_needed) - { - /* Clean up PNG structure and deallocate any memory. */ - png_free(png_ptr, png_ptr->zbuf); - png_ptr->zbuf = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, - (png_free_ptr)free_fn, (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)png_ptr); -#endif - return (NULL); - } - - png_set_write_fn(png_ptr, NULL, NULL, NULL); - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - png_reset_filter_heuristics(png_ptr); -#endif - - return (png_ptr); + return png_ptr; } @@ -580,7 +587,7 @@ png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, * "write" the image seven times. */ void PNGAPI -png_write_rows(png_structp png_ptr, png_bytepp row, +png_write_rows(png_structrp png_ptr, png_bytepp row, png_uint_32 num_rows) { png_uint_32 i; /* row counter */ @@ -602,7 +609,7 @@ png_write_rows(png_structp png_ptr, png_bytepp row, * if you are writing an interlaced image. */ void PNGAPI -png_write_image(png_structp png_ptr, png_bytepp image) +png_write_image(png_structrp png_ptr, png_bytepp image) { png_uint_32 i; /* row index */ int pass, num_pass; /* pass variables */ @@ -632,10 +639,78 @@ png_write_image(png_structp png_ptr, png_bytepp image) } } +#ifdef PNG_MNG_FEATURES_SUPPORTED +/* Performs intrapixel differencing */ +static void +png_do_write_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_intrapixel"); + + if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff); + *(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff); + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); + png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); + png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); + png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL); + png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL); + *(rp ) = (png_byte)((red >> 8) & 0xff); + *(rp + 1) = (png_byte)(red & 0xff); + *(rp + 4) = (png_byte)((blue >> 8) & 0xff); + *(rp + 5) = (png_byte)(blue & 0xff); + } + } +#endif /* WRITE_16BIT */ + } +} +#endif /* MNG_FEATURES */ + /* Called by user to write a row of image data */ void PNGAPI -png_write_row(png_structp png_ptr, png_const_bytep row) +png_write_row(png_structrp png_ptr, png_const_bytep row) { + /* 1.5.6: moved from png_struct to be a local structure: */ + png_row_info row_info; + if (png_ptr == NULL) return; @@ -646,44 +721,44 @@ png_write_row(png_structp png_ptr, png_const_bytep row) if (png_ptr->row_number == 0 && png_ptr->pass == 0) { /* Make sure we wrote the header info */ - if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) + if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0) png_error(png_ptr, "png_write_info was never called before png_write_row"); /* Check for transforms that have been set but were defined out */ #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) - if (png_ptr->transformations & PNG_INVERT_MONO) + if ((png_ptr->transformations & PNG_INVERT_MONO) != 0) png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined"); #endif #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) - if (png_ptr->transformations & PNG_FILLER) + if ((png_ptr->transformations & PNG_FILLER) != 0) png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined"); #endif #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ defined(PNG_READ_PACKSWAP_SUPPORTED) - if (png_ptr->transformations & PNG_PACKSWAP) + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined"); #endif #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) - if (png_ptr->transformations & PNG_PACK) + if ((png_ptr->transformations & PNG_PACK) != 0) png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined"); #endif #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) - if (png_ptr->transformations & PNG_SHIFT) + if ((png_ptr->transformations & PNG_SHIFT) != 0) png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined"); #endif #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) - if (png_ptr->transformations & PNG_BGR) + if ((png_ptr->transformations & PNG_BGR) != 0) png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined"); #endif #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) - if (png_ptr->transformations & PNG_SWAP_BYTES) + if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0) png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined"); #endif @@ -692,12 +767,13 @@ png_write_row(png_structp png_ptr, png_const_bytep row) #ifdef PNG_WRITE_INTERLACING_SUPPORTED /* If interlaced and not interested in row, return */ - if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0) { switch (png_ptr->pass) { case 0: - if (png_ptr->row_number & 0x07) + if ((png_ptr->row_number & 0x07) != 0) { png_write_finish_row(png_ptr); return; @@ -705,7 +781,7 @@ png_write_row(png_structp png_ptr, png_const_bytep row) break; case 1: - if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) + if ((png_ptr->row_number & 0x07) != 0 || png_ptr->width < 5) { png_write_finish_row(png_ptr); return; @@ -721,7 +797,7 @@ png_write_row(png_structp png_ptr, png_const_bytep row) break; case 3: - if ((png_ptr->row_number & 0x03) || png_ptr->width < 3) + if ((png_ptr->row_number & 0x03) != 0 || png_ptr->width < 3) { png_write_finish_row(png_ptr); return; @@ -737,7 +813,7 @@ png_write_row(png_structp png_ptr, png_const_bytep row) break; case 5: - if ((png_ptr->row_number & 0x01) || png_ptr->width < 2) + if ((png_ptr->row_number & 0x01) != 0 || png_ptr->width < 2) { png_write_finish_row(png_ptr); return; @@ -745,7 +821,7 @@ png_write_row(png_structp png_ptr, png_const_bytep row) break; case 6: - if (!(png_ptr->row_number & 0x01)) + if ((png_ptr->row_number & 0x01) == 0) { png_write_finish_row(png_ptr); return; @@ -759,36 +835,31 @@ png_write_row(png_structp png_ptr, png_const_bytep row) #endif /* Set up row info for transformations */ - png_ptr->row_info.color_type = png_ptr->color_type; - png_ptr->row_info.width = png_ptr->usr_width; - png_ptr->row_info.channels = png_ptr->usr_channels; - png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth; - png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * - png_ptr->row_info.channels); + row_info.color_type = png_ptr->color_type; + row_info.width = png_ptr->usr_width; + row_info.channels = png_ptr->usr_channels; + row_info.bit_depth = png_ptr->usr_bit_depth; + row_info.pixel_depth = (png_byte)(row_info.bit_depth * row_info.channels); + row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); - png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, - png_ptr->row_info.width); - - png_debug1(3, "row_info->color_type = %d", png_ptr->row_info.color_type); - png_debug1(3, "row_info->width = %u", png_ptr->row_info.width); - png_debug1(3, "row_info->channels = %d", png_ptr->row_info.channels); - png_debug1(3, "row_info->bit_depth = %d", png_ptr->row_info.bit_depth); - png_debug1(3, "row_info->pixel_depth = %d", png_ptr->row_info.pixel_depth); - png_debug1(3, "row_info->rowbytes = %lu", - (unsigned long)png_ptr->row_info.rowbytes); + png_debug1(3, "row_info->color_type = %d", row_info.color_type); + png_debug1(3, "row_info->width = %u", row_info.width); + png_debug1(3, "row_info->channels = %d", row_info.channels); + png_debug1(3, "row_info->bit_depth = %d", row_info.bit_depth); + png_debug1(3, "row_info->pixel_depth = %d", row_info.pixel_depth); + png_debug1(3, "row_info->rowbytes = %lu", (unsigned long)row_info.rowbytes); /* Copy user's row into buffer, leaving room for filter byte. */ - png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes); + memcpy(png_ptr->row_buf + 1, row, row_info.rowbytes); #ifdef PNG_WRITE_INTERLACING_SUPPORTED /* Handle interlacing */ if (png_ptr->interlaced && png_ptr->pass < 6 && - (png_ptr->transformations & PNG_INTERLACE)) + (png_ptr->transformations & PNG_INTERLACE) != 0) { - png_do_write_interlace(&(png_ptr->row_info), - png_ptr->row_buf + 1, png_ptr->pass); + png_do_write_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass); /* This should always get caught above, but still ... */ - if (!(png_ptr->row_info.width)) + if (row_info.width == 0) { png_write_finish_row(png_ptr); return; @@ -798,10 +869,17 @@ png_write_row(png_structp png_ptr, png_const_bytep row) #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED /* Handle other transformations */ - if (png_ptr->transformations) - png_do_write_transformations(png_ptr); + if (png_ptr->transformations != 0) + png_do_write_transformations(png_ptr, &row_info); #endif + /* At this point the row_info pixel depth must match the 'transformed' depth, + * which is also the output depth. + */ + if (row_info.pixel_depth != png_ptr->pixel_depth || + row_info.pixel_depth != png_ptr->transformed_pixel_depth) + png_error(png_ptr, "internal write transform logic error"); + #ifdef PNG_MNG_FEATURES_SUPPORTED /* Write filter_method 64 (intrapixel differencing) only if * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and @@ -812,16 +890,24 @@ png_write_row(png_structp png_ptr, png_const_bytep row) * 4. The filter_method is 64 and * 5. The color_type is RGB or RGBA */ - if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) { /* Intrapixel differencing */ - png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); + png_do_write_intrapixel(&row_info, png_ptr->row_buf + 1); } #endif +/* Added at libpng-1.5.10 */ +#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Check for out-of-range palette index */ + if (row_info.color_type == PNG_COLOR_TYPE_PALETTE && + png_ptr->num_palette_max >= 0) + png_do_check_palette_indexes(png_ptr, &row_info); +#endif + /* Find a filter if necessary, filter the row and write it out. */ - png_write_find_filter(png_ptr, &(png_ptr->row_info)); + png_write_find_filter(png_ptr, &row_info); if (png_ptr->write_row_fn != NULL) (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); @@ -830,7 +916,7 @@ png_write_row(png_structp png_ptr, png_const_bytep row) #ifdef PNG_WRITE_FLUSH_SUPPORTED /* Set the automatic flush interval or 0 to turn flushing off */ void PNGAPI -png_set_flush(png_structp png_ptr, int nrows) +png_set_flush(png_structrp png_ptr, int nrows) { png_debug(1, "in png_set_flush"); @@ -842,10 +928,8 @@ png_set_flush(png_structp png_ptr, int nrows) /* Flush the current output buffers now */ void PNGAPI -png_write_flush(png_structp png_ptr) +png_write_flush(png_structrp png_ptr) { - int wrote_IDAT; - png_debug(1, "in png_write_flush"); if (png_ptr == NULL) @@ -855,146 +939,41 @@ png_write_flush(png_structp png_ptr) if (png_ptr->row_number >= png_ptr->num_rows) return; - do - { - int ret; - - /* Compress the data */ - ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH); - wrote_IDAT = 0; - - /* Check for compression errors */ - if (ret != Z_OK) - { - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); - - else - png_error(png_ptr, "zlib error"); - } - - if (!(png_ptr->zstream.avail_out)) - { - /* Write the IDAT and reset the zlib output buffer */ - png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); - wrote_IDAT = 1; - } - } while (wrote_IDAT == 1); - - /* If there is any data left to be output, write it into a new IDAT */ - if (png_ptr->zbuf_size != png_ptr->zstream.avail_out) - { - /* Write the IDAT and reset the zlib output buffer */ - png_write_IDAT(png_ptr, png_ptr->zbuf, - png_ptr->zbuf_size - png_ptr->zstream.avail_out); - } + png_compress_IDAT(png_ptr, NULL, 0, Z_SYNC_FLUSH); png_ptr->flush_rows = 0; png_flush(png_ptr); } -#endif /* PNG_WRITE_FLUSH_SUPPORTED */ +#endif /* WRITE_FLUSH */ -/* Free all memory used by the write */ -void PNGAPI -png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED +static void png_reset_filter_heuristics(png_structrp png_ptr);/* forward decl */ +#endif + +/* Free any memory used in png_ptr struct without freeing the struct itself. */ +static void +png_write_destroy(png_structrp png_ptr) { - png_structp png_ptr = NULL; - png_infop info_ptr = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_free_ptr free_fn = NULL; - png_voidp mem_ptr = NULL; -#endif - - png_debug(1, "in png_destroy_write_struct"); - - if (png_ptr_ptr != NULL) - { - png_ptr = *png_ptr_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - free_fn = png_ptr->free_fn; - mem_ptr = png_ptr->mem_ptr; -#endif - } - -#ifdef PNG_USER_MEM_SUPPORTED - if (png_ptr != NULL) - { - free_fn = png_ptr->free_fn; - mem_ptr = png_ptr->mem_ptr; - } -#endif - - if (info_ptr_ptr != NULL) - info_ptr = *info_ptr_ptr; - - if (info_ptr != NULL) - { - if (png_ptr != NULL) - { - png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - if (png_ptr->num_chunk_list) - { - png_free(png_ptr, png_ptr->chunk_list); - png_ptr->num_chunk_list = 0; - } -#endif - } - -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)info_ptr); -#endif - *info_ptr_ptr = NULL; - } - - if (png_ptr != NULL) - { - png_write_destroy(png_ptr); -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)png_ptr); -#endif - *png_ptr_ptr = NULL; - } -} - - -/* Free any memory used in png_ptr struct (old method) */ -void /* PRIVATE */ -png_write_destroy(png_structp png_ptr) -{ -#ifdef PNG_SETJMP_SUPPORTED - jmp_buf tmp_jmp; /* Save jump buffer */ -#endif - png_error_ptr error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - png_error_ptr warning_fn; -#endif - png_voidp error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - png_free_ptr free_fn; -#endif - png_debug(1, "in png_write_destroy"); /* Free any memory zlib uses */ - if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED) + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0) deflateEnd(&png_ptr->zstream); /* Free our memory. png_free checks NULL for us. */ - png_free(png_ptr, png_ptr->zbuf); + png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list); png_free(png_ptr, png_ptr->row_buf); + png_ptr->row_buf = NULL; #ifdef PNG_WRITE_FILTER_SUPPORTED png_free(png_ptr, png_ptr->prev_row); png_free(png_ptr, png_ptr->sub_row); png_free(png_ptr, png_ptr->up_row); png_free(png_ptr, png_ptr->avg_row); png_free(png_ptr, png_ptr->paeth_row); + png_ptr->prev_row = NULL; + png_ptr->sub_row = NULL; + png_ptr->up_row = NULL; + png_ptr->avg_row = NULL; + png_ptr->paeth_row = NULL; #endif #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED @@ -1002,41 +981,51 @@ png_write_destroy(png_structp png_ptr) png_reset_filter_heuristics(png_ptr); png_free(png_ptr, png_ptr->filter_costs); png_free(png_ptr, png_ptr->inv_filter_costs); + png_ptr->filter_costs = NULL; + png_ptr->inv_filter_costs = NULL; #endif -#ifdef PNG_SETJMP_SUPPORTED - /* Reset structure */ - png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list = NULL; #endif - error_fn = png_ptr->error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - warning_fn = png_ptr->warning_fn; -#endif - error_ptr = png_ptr->error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - free_fn = png_ptr->free_fn; -#endif + /* The error handling and memory handling information is left intact at this + * point: the jmp_buf may still have to be freed. See png_destroy_png_struct + * for how this happens. + */ +} - png_memset(png_ptr, 0, png_sizeof(png_struct)); +/* Free all memory used by the write. + * In libpng 1.6.0 this API changed quietly to no longer accept a NULL value for + * *png_ptr_ptr. Prior to 1.6.0 it would accept such a value and it would free + * the passed in info_structs but it would quietly fail to free any of the data + * inside them. In 1.6.0 it quietly does nothing (it has to be quiet because it + * has no png_ptr.) + */ +void PNGAPI +png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) +{ + png_debug(1, "in png_destroy_write_struct"); - png_ptr->error_fn = error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - png_ptr->warning_fn = warning_fn; -#endif - png_ptr->error_ptr = error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - png_ptr->free_fn = free_fn; -#endif + if (png_ptr_ptr != NULL) + { + png_structrp png_ptr = *png_ptr_ptr; -#ifdef PNG_SETJMP_SUPPORTED - png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf)); -#endif + if (png_ptr != NULL) /* added in libpng 1.6.0 */ + { + png_destroy_info_struct(png_ptr, info_ptr_ptr); + + *png_ptr_ptr = NULL; + png_write_destroy(png_ptr); + png_destroy_png_struct(png_ptr); + } + } } /* Allow the application to select one or more row filters to use. */ void PNGAPI -png_set_filter(png_structp png_ptr, int method, int filters) +png_set_filter(png_structrp png_ptr, int method, int filters) { png_debug(1, "in png_set_filter"); @@ -1044,7 +1033,7 @@ png_set_filter(png_structp png_ptr, int method, int filters) return; #ifdef PNG_MNG_FEATURES_SUPPORTED - if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && (method == PNG_INTRAPIXEL_DIFFERENCING)) method = PNG_FILTER_TYPE_BASE; @@ -1056,8 +1045,9 @@ png_set_filter(png_structp png_ptr, int method, int filters) #ifdef PNG_WRITE_FILTER_SUPPORTED case 5: case 6: - case 7: png_warning(png_ptr, "Unknown row filter for method 0"); -#endif /* PNG_WRITE_FILTER_SUPPORTED */ + case 7: png_app_error(png_ptr, "Unknown row filter for method 0"); + /* FALL THROUGH */ +#endif /* WRITE_FILTER */ case PNG_FILTER_VALUE_NONE: png_ptr->do_filter = PNG_FILTER_NONE; break; @@ -1078,8 +1068,8 @@ png_set_filter(png_structp png_ptr, int method, int filters) png_ptr->do_filter = (png_byte)filters; break; #else default: - png_warning(png_ptr, "Unknown row filter for method 0"); -#endif /* PNG_WRITE_FILTER_SUPPORTED */ + png_app_error(png_ptr, "Unknown row filter for method 0"); +#endif /* WRITE_FILTER */ } /* If we have allocated the row_buf, this means we have already started @@ -1094,14 +1084,16 @@ png_set_filter(png_structp png_ptr, int method, int filters) if (png_ptr->row_buf != NULL) { #ifdef PNG_WRITE_FILTER_SUPPORTED - if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) + if ((png_ptr->do_filter & PNG_FILTER_SUB) != 0 && + png_ptr->sub_row == NULL) { png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, (png_ptr->rowbytes + 1)); png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; } - if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL) + if ((png_ptr->do_filter & PNG_FILTER_UP) != 0 && + png_ptr->up_row == NULL) { if (png_ptr->prev_row == NULL) { @@ -1118,7 +1110,8 @@ png_set_filter(png_structp png_ptr, int method, int filters) } } - if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL) + if ((png_ptr->do_filter & PNG_FILTER_AVG) != 0 && + png_ptr->avg_row == NULL) { if (png_ptr->prev_row == NULL) { @@ -1135,7 +1128,7 @@ png_set_filter(png_structp png_ptr, int method, int filters) } } - if ((png_ptr->do_filter & PNG_FILTER_PAETH) && + if ((png_ptr->do_filter & PNG_FILTER_PAETH) != 0 && png_ptr->paeth_row == NULL) { if (png_ptr->prev_row == NULL) @@ -1153,7 +1146,7 @@ png_set_filter(png_structp png_ptr, int method, int filters) } if (png_ptr->do_filter == PNG_NO_FILTERS) -#endif /* PNG_WRITE_FILTER_SUPPORTED */ +#endif /* WRITE_FILTER */ png_ptr->do_filter = PNG_FILTER_NONE; } } @@ -1171,7 +1164,7 @@ png_set_filter(png_structp png_ptr, int method, int filters) #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */ /* Convenience reset API. */ static void -png_reset_filter_heuristics(png_structp png_ptr) +png_reset_filter_heuristics(png_structrp png_ptr) { /* Clear out any old values in the 'weights' - this must be done because if * the app calls set_filter_heuristics multiple times with different @@ -1204,7 +1197,7 @@ png_reset_filter_heuristics(png_structp png_ptr) } static int -png_init_filter_heuristics(png_structp png_ptr, int heuristic_method, +png_init_filter_heuristics(png_structrp png_ptr, int heuristic_method, int num_weights) { if (png_ptr == NULL) @@ -1224,7 +1217,7 @@ png_init_filter_heuristics(png_structp png_ptr, int heuristic_method, if (num_weights > 0) { png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_byte) * num_weights)); + (png_uint_32)((sizeof (png_byte)) * num_weights)); /* To make sure that the weighting starts out fairly */ for (i = 0; i < num_weights; i++) @@ -1233,10 +1226,10 @@ png_init_filter_heuristics(png_structp png_ptr, int heuristic_method, } png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); + (png_uint_32)((sizeof (png_uint_16)) * num_weights)); png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); + (png_uint_32)((sizeof (png_uint_16)) * num_weights)); for (i = 0; i < num_weights; i++) { @@ -1254,10 +1247,10 @@ png_init_filter_heuristics(png_structp png_ptr, int heuristic_method, if (png_ptr->filter_costs == NULL) { png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); + (png_uint_32)((sizeof (png_uint_16)) * PNG_FILTER_VALUE_LAST)); png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); + (png_uint_32)((sizeof (png_uint_16)) * PNG_FILTER_VALUE_LAST)); } for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) @@ -1287,7 +1280,7 @@ png_init_filter_heuristics(png_structp png_ptr, int heuristic_method, /* Provide floating and fixed point APIs */ #ifdef PNG_FLOATING_POINT_SUPPORTED void PNGAPI -png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, +png_set_filter_heuristics(png_structrp png_ptr, int heuristic_method, int num_weights, png_const_doublep filter_weights, png_const_doublep filter_costs) { @@ -1296,7 +1289,7 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, /* The internal API allocates all the arrays and ensures that the elements of * those arrays are set to the default value. */ - if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights)) + if (png_init_filter_heuristics(png_ptr, heuristic_method, num_weights) == 0) return; /* If using the weighted method copy in the weights. */ @@ -1342,7 +1335,7 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, #ifdef PNG_FIXED_POINT_SUPPORTED void PNGAPI -png_set_filter_heuristics_fixed(png_structp png_ptr, int heuristic_method, +png_set_filter_heuristics_fixed(png_structrp png_ptr, int heuristic_method, int num_weights, png_const_fixed_point_p filter_weights, png_const_fixed_point_p filter_costs) { @@ -1351,7 +1344,7 @@ png_set_filter_heuristics_fixed(png_structp png_ptr, int heuristic_method, /* The internal API allocates all the arrays and ensures that the elements of * those arrays are set to the default value. */ - if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights)) + if (png_init_filter_heuristics(png_ptr, heuristic_method, num_weights) == 0) return; /* If using the weighted method copy in the weights. */ @@ -1405,40 +1398,40 @@ png_set_filter_heuristics_fixed(png_structp png_ptr, int heuristic_method, } } #endif /* FIXED_POINT */ -#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ +#endif /* WRITE_WEIGHTED_FILTER */ void PNGAPI -png_set_compression_level(png_structp png_ptr, int level) +png_set_compression_level(png_structrp png_ptr, int level) { png_debug(1, "in png_set_compression_level"); if (png_ptr == NULL) return; - png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; png_ptr->zlib_level = level; } void PNGAPI -png_set_compression_mem_level(png_structp png_ptr, int mem_level) +png_set_compression_mem_level(png_structrp png_ptr, int mem_level) { png_debug(1, "in png_set_compression_mem_level"); if (png_ptr == NULL) return; - png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; png_ptr->zlib_mem_level = mem_level; } void PNGAPI -png_set_compression_strategy(png_structp png_ptr, int strategy) +png_set_compression_strategy(png_structrp png_ptr, int strategy) { png_debug(1, "in png_set_compression_strategy"); if (png_ptr == NULL) return; + /* The flag setting here prevents the libpng dynamic selection of strategy. + */ png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; png_ptr->zlib_strategy = strategy; } @@ -1447,80 +1440,81 @@ png_set_compression_strategy(png_structp png_ptr, int strategy) * smaller value of window_bits if it can do so safely. */ void PNGAPI -png_set_compression_window_bits(png_structp png_ptr, int window_bits) +png_set_compression_window_bits(png_structrp png_ptr, int window_bits) { if (png_ptr == NULL) return; + /* Prior to 1.6.0 this would warn but then set the window_bits value, this + * meant that negative window bits values could be selected which would cause + * libpng to write a non-standard PNG file with raw deflate or gzip + * compressed IDAT or ancillary chunks. Such files can be read and there is + * no warning on read, so this seems like a very bad idea. + */ if (window_bits > 15) + { png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); + window_bits = 15; + } else if (window_bits < 8) + { png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); + window_bits = 8; + } -#ifndef WBITS_8_OK - /* Avoid libpng bug with 256-byte windows */ - if (window_bits == 8) - { - png_warning(png_ptr, "Compression window is being reset to 512"); - window_bits = 9; - } - -#endif - png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; png_ptr->zlib_window_bits = window_bits; } void PNGAPI -png_set_compression_method(png_structp png_ptr, int method) +png_set_compression_method(png_structrp png_ptr, int method) { png_debug(1, "in png_set_compression_method"); if (png_ptr == NULL) return; + /* This would produce an invalid PNG file if it worked, but it doesn't and + * deflate will fault it, so it is harmless to just warn here. + */ if (method != 8) png_warning(png_ptr, "Only compression method 8 is supported by PNG"); - png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; png_ptr->zlib_method = method; } /* The following were added to libpng-1.5.4 */ #ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED void PNGAPI -png_set_text_compression_level(png_structp png_ptr, int level) +png_set_text_compression_level(png_structrp png_ptr, int level) { png_debug(1, "in png_set_text_compression_level"); if (png_ptr == NULL) return; - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_LEVEL; png_ptr->zlib_text_level = level; } void PNGAPI -png_set_text_compression_mem_level(png_structp png_ptr, int mem_level) +png_set_text_compression_mem_level(png_structrp png_ptr, int mem_level) { png_debug(1, "in png_set_text_compression_mem_level"); if (png_ptr == NULL) return; - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL; png_ptr->zlib_text_mem_level = mem_level; } void PNGAPI -png_set_text_compression_strategy(png_structp png_ptr, int strategy) +png_set_text_compression_strategy(png_structrp png_ptr, int strategy) { png_debug(1, "in png_set_text_compression_strategy"); if (png_ptr == NULL) return; - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_STRATEGY; png_ptr->zlib_text_strategy = strategy; } @@ -1528,32 +1522,28 @@ png_set_text_compression_strategy(png_structp png_ptr, int strategy) * smaller value of window_bits if it can do so safely. */ void PNGAPI -png_set_text_compression_window_bits(png_structp png_ptr, int window_bits) +png_set_text_compression_window_bits(png_structrp png_ptr, int window_bits) { if (png_ptr == NULL) return; if (window_bits > 15) + { png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); + window_bits = 15; + } else if (window_bits < 8) + { png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); + window_bits = 8; + } -#ifndef WBITS_8_OK - /* Avoid libpng bug with 256-byte windows */ - if (window_bits == 8) - { - png_warning(png_ptr, "Text compression window is being reset to 512"); - window_bits = 9; - } - -#endif - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS; png_ptr->zlib_text_window_bits = window_bits; } void PNGAPI -png_set_text_compression_method(png_structp png_ptr, int method) +png_set_text_compression_method(png_structrp png_ptr, int method) { png_debug(1, "in png_set_text_compression_method"); @@ -1563,14 +1553,13 @@ png_set_text_compression_method(png_structp png_ptr, int method) if (method != 8) png_warning(png_ptr, "Only compression method 8 is supported by PNG"); - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_METHOD; png_ptr->zlib_text_method = method; } -#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ +#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */ /* end of API added to libpng-1.5.4 */ void PNGAPI -png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) +png_set_write_status_fn(png_structrp png_ptr, png_write_status_ptr write_row_fn) { if (png_ptr == NULL) return; @@ -1580,7 +1569,7 @@ png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED void PNGAPI -png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr +png_set_write_user_transform_fn(png_structrp png_ptr, png_user_transform_ptr write_user_transform_fn) { png_debug(1, "in png_set_write_user_transform_fn"); @@ -1596,88 +1585,899 @@ png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr #ifdef PNG_INFO_IMAGE_SUPPORTED void PNGAPI -png_write_png(png_structp png_ptr, png_infop info_ptr, +png_write_png(png_structrp png_ptr, png_inforp info_ptr, int transforms, voidp params) { if (png_ptr == NULL || info_ptr == NULL) return; + if ((info_ptr->valid & PNG_INFO_IDAT) == 0) + { + png_app_error(png_ptr, "no rows for png_write_image to write"); + return; + } + /* Write the file header information. */ png_write_info(png_ptr, info_ptr); /* ------ these transformations don't touch the info structure ------- */ -#ifdef PNG_WRITE_INVERT_SUPPORTED /* Invert monochrome pixels */ - if (transforms & PNG_TRANSFORM_INVERT_MONO) + if ((transforms & PNG_TRANSFORM_INVERT_MONO) != 0) +#ifdef PNG_WRITE_INVERT_SUPPORTED png_set_invert_mono(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported"); #endif -#ifdef PNG_WRITE_SHIFT_SUPPORTED /* Shift the pixels up to a legal bit depth and fill in * as appropriate to correctly scale the image. */ - if ((transforms & PNG_TRANSFORM_SHIFT) - && (info_ptr->valid & PNG_INFO_sBIT)) - png_set_shift(png_ptr, &info_ptr->sig_bit); + if ((transforms & PNG_TRANSFORM_SHIFT) != 0) +#ifdef PNG_WRITE_SHIFT_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sBIT) != 0) + png_set_shift(png_ptr, &info_ptr->sig_bit); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported"); #endif -#ifdef PNG_WRITE_PACK_SUPPORTED /* Pack pixels into bytes */ - if (transforms & PNG_TRANSFORM_PACKING) - png_set_packing(png_ptr); + if ((transforms & PNG_TRANSFORM_PACKING) != 0) +#ifdef PNG_WRITE_PACK_SUPPORTED + png_set_packing(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported"); #endif -#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED /* Swap location of alpha bytes from ARGB to RGBA */ - if (transforms & PNG_TRANSFORM_SWAP_ALPHA) + if ((transforms & PNG_TRANSFORM_SWAP_ALPHA) != 0) +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED png_set_swap_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported"); #endif + /* Remove a filler (X) from XRGB/RGBX/AG/GA into to convert it into + * RGB, note that the code expects the input color type to be G or RGB; no + * alpha channel. + */ + if ((transforms & (PNG_TRANSFORM_STRIP_FILLER_AFTER| + PNG_TRANSFORM_STRIP_FILLER_BEFORE)) != 0) + { #ifdef PNG_WRITE_FILLER_SUPPORTED - /* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -> 3 channels) */ - if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) - png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); + if ((transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) != 0) + { + if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0) + png_app_error(png_ptr, + "PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported"); - else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) - png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); + /* Continue if ignored - this is the pre-1.6.10 behavior */ + png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); + } + + else if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0) + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_FILLER not supported"); #endif + } -#ifdef PNG_WRITE_BGR_SUPPORTED /* Flip BGR pixels to RGB */ - if (transforms & PNG_TRANSFORM_BGR) + if ((transforms & PNG_TRANSFORM_BGR) != 0) +#ifdef PNG_WRITE_BGR_SUPPORTED png_set_bgr(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported"); #endif -#ifdef PNG_WRITE_SWAP_SUPPORTED /* Swap bytes of 16-bit files to most significant byte first */ - if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) + if ((transforms & PNG_TRANSFORM_SWAP_ENDIAN) != 0) +#ifdef PNG_WRITE_SWAP_SUPPORTED png_set_swap(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported"); #endif -#ifdef PNG_WRITE_PACKSWAP_SUPPORTED /* Swap bits of 1, 2, 4 bit packed pixel formats */ - if (transforms & PNG_TRANSFORM_PACKSWAP) + if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0) +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED png_set_packswap(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported"); #endif -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED /* Invert the alpha channel from opacity to transparency */ - if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + if ((transforms & PNG_TRANSFORM_INVERT_ALPHA) != 0) +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED png_set_invert_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported"); #endif /* ----------------------- end of transformations ------------------- */ /* Write the bits */ - if (info_ptr->valid & PNG_INFO_IDAT) - png_write_image(png_ptr, info_ptr->row_pointers); + png_write_image(png_ptr, info_ptr->row_pointers); /* It is REQUIRED to call this to finish writing the rest of the file */ png_write_end(png_ptr, info_ptr); - PNG_UNUSED(transforms) /* Quiet compiler warnings */ PNG_UNUSED(params) } #endif -#endif /* PNG_WRITE_SUPPORTED */ + + +#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED +#ifdef PNG_STDIO_SUPPORTED /* currently required for png_image_write_* */ +/* Initialize the write structure - general purpose utility. */ +static int +png_image_write_init(png_imagep image) +{ + png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, image, + png_safe_error, png_safe_warning); + + if (png_ptr != NULL) + { + png_infop info_ptr = png_create_info_struct(png_ptr); + + if (info_ptr != NULL) + { + png_controlp control = png_voidcast(png_controlp, + png_malloc_warn(png_ptr, (sizeof *control))); + + if (control != NULL) + { + memset(control, 0, (sizeof *control)); + + control->png_ptr = png_ptr; + control->info_ptr = info_ptr; + control->for_write = 1; + + image->opaque = control; + return 1; + } + + /* Error clean up */ + png_destroy_info_struct(png_ptr, &info_ptr); + } + + png_destroy_write_struct(&png_ptr, NULL); + } + + return png_image_error(image, "png_image_write_: out of memory"); +} + +/* Arguments to png_image_write_main: */ +typedef struct +{ + /* Arguments: */ + png_imagep image; + png_const_voidp buffer; + png_int_32 row_stride; + png_const_voidp colormap; + int convert_to_8bit; + /* Local variables: */ + png_const_voidp first_row; + ptrdiff_t row_bytes; + png_voidp local_row; +} png_image_write_control; + +/* Write png_uint_16 input to a 16-bit PNG; the png_ptr has already been set to + * do any necessary byte swapping. The component order is defined by the + * png_image format value. + */ +static int +png_write_image_16bit(png_voidp argument) +{ + png_image_write_control *display = png_voidcast(png_image_write_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + + png_const_uint_16p input_row = png_voidcast(png_const_uint_16p, + display->first_row); + png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row); + png_uint_16p row_end; + const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1; + int aindex = 0; + png_uint_32 y = image->height; + + if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0) + { +# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED + if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + aindex = -1; + ++input_row; /* To point to the first component */ + ++output_row; + } + + else +# endif + aindex = channels; + } + + else + png_error(png_ptr, "png_write_image: internal call error"); + + /* Work out the output row end and count over this, note that the increment + * above to 'row' means that row_end can actually be beyond the end of the + * row; this is correct. + */ + row_end = output_row + image->width * (channels+1); + + while (y-- > 0) + { + png_const_uint_16p in_ptr = input_row; + png_uint_16p out_ptr = output_row; + + while (out_ptr < row_end) + { + const png_uint_16 alpha = in_ptr[aindex]; + png_uint_32 reciprocal = 0; + int c; + + out_ptr[aindex] = alpha; + + /* Calculate a reciprocal. The correct calculation is simply + * component/alpha*65535 << 15. (I.e. 15 bits of precision); this + * allows correct rounding by adding .5 before the shift. 'reciprocal' + * is only initialized when required. + */ + if (alpha > 0 && alpha < 65535) + reciprocal = ((0xffff<<15)+(alpha>>1))/alpha; + + c = channels; + do /* always at least one channel */ + { + png_uint_16 component = *in_ptr++; + + /* The following gives 65535 for an alpha of 0, which is fine, + * otherwise if 0/0 is represented as some other value there is more + * likely to be a discontinuity which will probably damage + * compression when moving from a fully transparent area to a + * nearly transparent one. (The assumption here is that opaque + * areas tend not to be 0 intensity.) + */ + if (component >= alpha) + component = 65535; + + /* component 0 && alpha < 65535) + { + png_uint_32 calc = component * reciprocal; + calc += 16384; /* round to nearest */ + component = (png_uint_16)(calc >> 15); + } + + *out_ptr++ = component; + } + while (--c > 0); + + /* Skip to next component (skip the intervening alpha channel) */ + ++in_ptr; + ++out_ptr; + } + + png_write_row(png_ptr, png_voidcast(png_const_bytep, display->local_row)); + input_row += display->row_bytes/(sizeof (png_uint_16)); + } + + return 1; +} + +/* Given 16-bit input (1 to 4 channels) write 8-bit output. If an alpha channel + * is present it must be removed from the components, the components are then + * written in sRGB encoding. No components are added or removed. + * + * Calculate an alpha reciprocal to reverse pre-multiplication. As above the + * calculation can be done to 15 bits of accuracy; however, the output needs to + * be scaled in the range 0..255*65535, so include that scaling here. + */ +#define UNP_RECIPROCAL(alpha) ((((0xffff*0xff)<<7)+(alpha>>1))/alpha) + +static png_byte +png_unpremultiply(png_uint_32 component, png_uint_32 alpha, + png_uint_32 reciprocal/*from the above macro*/) +{ + /* The following gives 1.0 for an alpha of 0, which is fine, otherwise if 0/0 + * is represented as some other value there is more likely to be a + * discontinuity which will probably damage compression when moving from a + * fully transparent area to a nearly transparent one. (The assumption here + * is that opaque areas tend not to be 0 intensity.) + * + * There is a rounding problem here; if alpha is less than 128 it will end up + * as 0 when scaled to 8 bits. To avoid introducing spurious colors into the + * output change for this too. + */ + if (component >= alpha || alpha < 128) + return 255; + + /* component 0) + { + /* The test is that alpha/257 (rounded) is less than 255, the first value + * that becomes 255 is 65407. + * NOTE: this must agree with the PNG_DIV257 macro (which must, therefore, + * be exact!) [Could also test reciprocal != 0] + */ + if (alpha < 65407) + { + component *= reciprocal; + component += 64; /* round to nearest */ + component >>= 7; + } + + else + component *= 255; + + /* Convert the component to sRGB. */ + return (png_byte)PNG_sRGB_FROM_LINEAR(component); + } + + else + return 0; +} + +static int +png_write_image_8bit(png_voidp argument) +{ + png_image_write_control *display = png_voidcast(png_image_write_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + + png_const_uint_16p input_row = png_voidcast(png_const_uint_16p, + display->first_row); + png_bytep output_row = png_voidcast(png_bytep, display->local_row); + png_uint_32 y = image->height; + const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1; + + if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + png_bytep row_end; + int aindex; + +# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED + if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + aindex = -1; + ++input_row; /* To point to the first component */ + ++output_row; + } + + else +# endif + aindex = channels; + + /* Use row_end in place of a loop counter: */ + row_end = output_row + image->width * (channels+1); + + while (y-- > 0) + { + png_const_uint_16p in_ptr = input_row; + png_bytep out_ptr = output_row; + + while (out_ptr < row_end) + { + png_uint_16 alpha = in_ptr[aindex]; + png_byte alphabyte = (png_byte)PNG_DIV257(alpha); + png_uint_32 reciprocal = 0; + int c; + + /* Scale and write the alpha channel. */ + out_ptr[aindex] = alphabyte; + + if (alphabyte > 0 && alphabyte < 255) + reciprocal = UNP_RECIPROCAL(alpha); + + c = channels; + do /* always at least one channel */ + *out_ptr++ = png_unpremultiply(*in_ptr++, alpha, reciprocal); + while (--c > 0); + + /* Skip to next component (skip the intervening alpha channel) */ + ++in_ptr; + ++out_ptr; + } /* while out_ptr < row_end */ + + png_write_row(png_ptr, png_voidcast(png_const_bytep, + display->local_row)); + input_row += display->row_bytes/(sizeof (png_uint_16)); + } /* while y */ + } + + else + { + /* No alpha channel, so the row_end really is the end of the row and it + * is sufficient to loop over the components one by one. + */ + png_bytep row_end = output_row + image->width * channels; + + while (y-- > 0) + { + png_const_uint_16p in_ptr = input_row; + png_bytep out_ptr = output_row; + + while (out_ptr < row_end) + { + png_uint_32 component = *in_ptr++; + + component *= 255; + *out_ptr++ = (png_byte)PNG_sRGB_FROM_LINEAR(component); + } + + png_write_row(png_ptr, output_row); + input_row += display->row_bytes/(sizeof (png_uint_16)); + } + } + + return 1; +} + +static void +png_image_set_PLTE(png_image_write_control *display) +{ + const png_imagep image = display->image; + const void *cmap = display->colormap; + const int entries = image->colormap_entries > 256 ? 256 : + (int)image->colormap_entries; + + /* NOTE: the caller must check for cmap != NULL and entries != 0 */ + const png_uint_32 format = image->format; + const int channels = PNG_IMAGE_SAMPLE_CHANNELS(format); + +# if defined(PNG_FORMAT_BGR_SUPPORTED) &&\ + defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED) + const int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 && + (format & PNG_FORMAT_FLAG_ALPHA) != 0; +# else +# define afirst 0 +# endif + +# ifdef PNG_FORMAT_BGR_SUPPORTED + const int bgr = (format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0; +# else +# define bgr 0 +# endif + + int i, num_trans; + png_color palette[256]; + png_byte tRNS[256]; + + memset(tRNS, 255, (sizeof tRNS)); + memset(palette, 0, (sizeof palette)); + + for (i=num_trans=0; i= 3) /* RGB */ + { + palette[i].blue = (png_byte)PNG_sRGB_FROM_LINEAR(255 * + entry[(2 ^ bgr)]); + palette[i].green = (png_byte)PNG_sRGB_FROM_LINEAR(255 * + entry[1]); + palette[i].red = (png_byte)PNG_sRGB_FROM_LINEAR(255 * + entry[bgr]); + } + + else /* Gray */ + palette[i].blue = palette[i].red = palette[i].green = + (png_byte)PNG_sRGB_FROM_LINEAR(255 * *entry); + } + + else /* alpha */ + { + png_uint_16 alpha = entry[afirst ? 0 : channels-1]; + png_byte alphabyte = (png_byte)PNG_DIV257(alpha); + png_uint_32 reciprocal = 0; + + /* Calculate a reciprocal, as in the png_write_image_8bit code above + * this is designed to produce a value scaled to 255*65535 when + * divided by 128 (i.e. asr 7). + */ + if (alphabyte > 0 && alphabyte < 255) + reciprocal = (((0xffff*0xff)<<7)+(alpha>>1))/alpha; + + tRNS[i] = alphabyte; + if (alphabyte < 255) + num_trans = i+1; + + if (channels >= 3) /* RGB */ + { + palette[i].blue = png_unpremultiply(entry[afirst + (2 ^ bgr)], + alpha, reciprocal); + palette[i].green = png_unpremultiply(entry[afirst + 1], alpha, + reciprocal); + palette[i].red = png_unpremultiply(entry[afirst + bgr], alpha, + reciprocal); + } + + else /* gray */ + palette[i].blue = palette[i].red = palette[i].green = + png_unpremultiply(entry[afirst], alpha, reciprocal); + } + } + + else /* Color-map has sRGB values */ + { + png_const_bytep entry = png_voidcast(png_const_bytep, cmap); + + entry += i * channels; + + switch (channels) + { + case 4: + tRNS[i] = entry[afirst ? 0 : 3]; + if (tRNS[i] < 255) + num_trans = i+1; + /* FALL THROUGH */ + case 3: + palette[i].blue = entry[afirst + (2 ^ bgr)]; + palette[i].green = entry[afirst + 1]; + palette[i].red = entry[afirst + bgr]; + break; + + case 2: + tRNS[i] = entry[1 ^ afirst]; + if (tRNS[i] < 255) + num_trans = i+1; + /* FALL THROUGH */ + case 1: + palette[i].blue = palette[i].red = palette[i].green = + entry[afirst]; + break; + + default: + break; + } + } + } + +# ifdef afirst +# undef afirst +# endif +# ifdef bgr +# undef bgr +# endif + + png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette, + entries); + + if (num_trans > 0) + png_set_tRNS(image->opaque->png_ptr, image->opaque->info_ptr, tRNS, + num_trans, NULL); + + image->colormap_entries = entries; +} + +static int +png_image_write_main(png_voidp argument) +{ + png_image_write_control *display = png_voidcast(png_image_write_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + png_inforp info_ptr = image->opaque->info_ptr; + png_uint_32 format = image->format; + + /* The following four ints are actually booleans */ + int colormap = (format & PNG_FORMAT_FLAG_COLORMAP); + int linear = !colormap && (format & PNG_FORMAT_FLAG_LINEAR); /* input */ + int alpha = !colormap && (format & PNG_FORMAT_FLAG_ALPHA); + int write_16bit = linear && !colormap && (display->convert_to_8bit == 0); + +# ifdef PNG_BENIGN_ERRORS_SUPPORTED + /* Make sure we error out on any bad situation */ + png_set_benign_errors(png_ptr, 0/*error*/); +# endif + + /* Default the 'row_stride' parameter if required. */ + if (display->row_stride == 0) + display->row_stride = PNG_IMAGE_ROW_STRIDE(*image); + + /* Set the required transforms then write the rows in the correct order. */ + if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0) + { + if (display->colormap != NULL && image->colormap_entries > 0) + { + png_uint_32 entries = image->colormap_entries; + + png_set_IHDR(png_ptr, info_ptr, image->width, image->height, + entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)), + PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_image_set_PLTE(display); + } + + else + png_error(image->opaque->png_ptr, + "no color-map for color-mapped image"); + } + + else + png_set_IHDR(png_ptr, info_ptr, image->width, image->height, + write_16bit ? 16 : 8, + ((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) + + ((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0), + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + /* Counter-intuitively the data transformations must be called *after* + * png_write_info, not before as in the read code, but the 'set' functions + * must still be called before. Just set the color space information, never + * write an interlaced image. + */ + + if (write_16bit != 0) + { + /* The gamma here is 1.0 (linear) and the cHRM chunk matches sRGB. */ + png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_LINEAR); + + if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0) + png_set_cHRM_fixed(png_ptr, info_ptr, + /* color x y */ + /* white */ 31270, 32900, + /* red */ 64000, 33000, + /* green */ 30000, 60000, + /* blue */ 15000, 6000 + ); + } + + else if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0) + png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_PERCEPTUAL); + + /* Else writing an 8-bit file and the *colors* aren't sRGB, but the 8-bit + * space must still be gamma encoded. + */ + else + png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE); + + /* Write the file header. */ + png_write_info(png_ptr, info_ptr); + + /* Now set up the data transformations (*after* the header is written), + * remove the handled transformations from the 'format' flags for checking. + * + * First check for a little endian system if writing 16 bit files. + */ + if (write_16bit != 0) + { + PNG_CONST png_uint_16 le = 0x0001; + + if ((*(png_const_bytep) & le) != 0) + png_set_swap(png_ptr); + } + +# ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED + if ((format & PNG_FORMAT_FLAG_BGR) != 0) + { + if (colormap == 0 && (format & PNG_FORMAT_FLAG_COLOR) != 0) + png_set_bgr(png_ptr); + format &= ~PNG_FORMAT_FLAG_BGR; + } +# endif + +# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED + if ((format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + if (colormap == 0 && (format & PNG_FORMAT_FLAG_ALPHA) != 0) + png_set_swap_alpha(png_ptr); + format &= ~PNG_FORMAT_FLAG_AFIRST; + } +# endif + + /* If there are 16 or fewer color-map entries we wrote a lower bit depth + * above, but the application data is still byte packed. + */ + if (colormap != 0 && image->colormap_entries <= 16) + png_set_packing(png_ptr); + + /* That should have handled all (both) the transforms. */ + if ((format & ~(png_uint_32)(PNG_FORMAT_FLAG_COLOR | PNG_FORMAT_FLAG_LINEAR | + PNG_FORMAT_FLAG_ALPHA | PNG_FORMAT_FLAG_COLORMAP)) != 0) + png_error(png_ptr, "png_write_image: unsupported transformation"); + + { + png_const_bytep row = png_voidcast(png_const_bytep, display->buffer); + ptrdiff_t row_bytes = display->row_stride; + + if (linear != 0) + row_bytes *= (sizeof (png_uint_16)); + + if (row_bytes < 0) + row += (image->height-1) * (-row_bytes); + + display->first_row = row; + display->row_bytes = row_bytes; + } + + /* Apply 'fast' options if the flag is set. */ + if ((image->flags & PNG_IMAGE_FLAG_FAST) != 0) + { + png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_NO_FILTERS); + /* NOTE: determined by experiment using pngstest, this reflects some + * balance between the time to write the image once and the time to read + * it about 50 times. The speed-up in pngstest was about 10-20% of the + * total (user) time on a heavily loaded system. + */ + png_set_compression_level(png_ptr, 3); + } + + /* Check for the cases that currently require a pre-transform on the row + * before it is written. This only applies when the input is 16-bit and + * either there is an alpha channel or it is converted to 8-bit. + */ + if ((linear != 0 && alpha != 0 ) || + (colormap == 0 && display->convert_to_8bit != 0)) + { + png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr, + png_get_rowbytes(png_ptr, info_ptr))); + int result; + + display->local_row = row; + if (write_16bit != 0) + result = png_safe_execute(image, png_write_image_16bit, display); + else + result = png_safe_execute(image, png_write_image_8bit, display); + display->local_row = NULL; + + png_free(png_ptr, row); + + /* Skip the 'write_end' on error: */ + if (result == 0) + return 0; + } + + /* Otherwise this is the case where the input is in a format currently + * supported by the rest of the libpng write code; call it directly. + */ + else + { + png_const_bytep row = png_voidcast(png_const_bytep, display->first_row); + ptrdiff_t row_bytes = display->row_bytes; + png_uint_32 y = image->height; + + while (y-- > 0) + { + png_write_row(png_ptr, row); + row += row_bytes; + } + } + + png_write_end(png_ptr, info_ptr); + return 1; +} + +int PNGAPI +png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit, + const void *buffer, png_int_32 row_stride, const void *colormap) +{ + /* Write the image to the given (FILE*). */ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (file != NULL) + { + if (png_image_write_init(image) != 0) + { + png_image_write_control display; + int result; + + /* This is slightly evil, but png_init_io doesn't do anything other + * than this and we haven't changed the standard IO functions so + * this saves a 'safe' function. + */ + image->opaque->png_ptr->io_ptr = file; + + memset(&display, 0, (sizeof display)); + display.image = image; + display.buffer = buffer; + display.row_stride = row_stride; + display.colormap = colormap; + display.convert_to_8bit = convert_to_8bit; + + result = png_safe_execute(image, png_image_write_main, &display); + png_image_free(image); + return result; + } + + else + return 0; + } + + else + return png_image_error(image, + "png_image_write_to_stdio: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION"); + + else + return 0; +} + +int PNGAPI +png_image_write_to_file(png_imagep image, const char *file_name, + int convert_to_8bit, const void *buffer, png_int_32 row_stride, + const void *colormap) +{ + /* Write the image to the named file. */ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (file_name != NULL) + { + FILE *fp = fopen(file_name, "wb"); + + if (fp != NULL) + { + if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer, + row_stride, colormap) != 0) + { + int error; /* from fflush/fclose */ + + /* Make sure the file is flushed correctly. */ + if (fflush(fp) == 0 && ferror(fp) == 0) + { + if (fclose(fp) == 0) + return 1; + + error = errno; /* from fclose */ + } + + else + { + error = errno; /* from fflush or ferror */ + (void)fclose(fp); + } + + (void)remove(file_name); + /* The image has already been cleaned up; this is just used to + * set the error (because the original write succeeded). + */ + return png_image_error(image, strerror(error)); + } + + else + { + /* Clean up: just the opened file. */ + (void)fclose(fp); + (void)remove(file_name); + return 0; + } + } + + else + return png_image_error(image, strerror(errno)); + } + + else + return png_image_error(image, + "png_image_write_to_file: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_write_to_file: incorrect PNG_IMAGE_VERSION"); + + else + return 0; +} +#endif /* STDIO */ +#endif /* SIMPLIFIED_WRITE */ +#endif /* WRITE */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwtran.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwtran.c index 579057dcefd..ef015aeb7b9 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwtran.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwtran.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -42,90 +42,14 @@ #include "pngpriv.h" #ifdef PNG_WRITE_SUPPORTED - #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED -/* Transform the data according to the user's wishes. The order of - * transformations is significant. - */ -void /* PRIVATE */ -png_do_write_transformations(png_structp png_ptr) -{ - png_debug(1, "in png_do_write_transformations"); - - if (png_ptr == NULL) - return; - -#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED - if (png_ptr->transformations & PNG_USER_TRANSFORM) - if (png_ptr->write_user_transform_fn != NULL) - (*(png_ptr->write_user_transform_fn)) /* User write transform - function */ - (png_ptr, /* png_ptr */ - &(png_ptr->row_info), /* row_info: */ - /* png_uint_32 width; width of row */ - /* png_size_t rowbytes; number of bytes in row */ - /* png_byte color_type; color type of pixels */ - /* png_byte bit_depth; bit depth of samples */ - /* png_byte channels; number of channels (1-4) */ - /* png_byte pixel_depth; bits per pixel (depth*channels) */ - png_ptr->row_buf + 1); /* start of pixel data for row */ -#endif - -#ifdef PNG_WRITE_FILLER_SUPPORTED - if (png_ptr->transformations & PNG_FILLER) - png_do_strip_channel(&(png_ptr->row_info), png_ptr->row_buf + 1, - !(png_ptr->flags & PNG_FLAG_FILLER_AFTER)); -#endif - -#ifdef PNG_WRITE_PACKSWAP_SUPPORTED - if (png_ptr->transformations & PNG_PACKSWAP) - png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_PACK_SUPPORTED - if (png_ptr->transformations & PNG_PACK) - png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1, - (png_uint_32)png_ptr->bit_depth); -#endif - -#ifdef PNG_WRITE_SWAP_SUPPORTED - if (png_ptr->transformations & PNG_SWAP_BYTES) - png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_SHIFT_SUPPORTED - if (png_ptr->transformations & PNG_SHIFT) - png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1, - &(png_ptr->shift)); -#endif - -#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_SWAP_ALPHA) - png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_ALPHA) - png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_BGR_SUPPORTED - if (png_ptr->transformations & PNG_BGR) - png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_INVERT_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_MONO) - png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif -} #ifdef PNG_WRITE_PACK_SUPPORTED /* Pack pixels into bytes. Pass the true bit depth in bit_depth. The * row_info bit depth should be 8 (one pixel per byte). The channels * should be 1 (this only happens on grayscale and paletted images). */ -void /* PRIVATE */ +static void png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) { png_debug(1, "in png_do_pack"); @@ -270,7 +194,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) * would pass 3 as bit_depth, and this routine would translate the * data to 0 to 15. */ -void /* PRIVATE */ +static void png_do_shift(png_row_infop row_info, png_bytep row, png_const_color_8p bit_depth) { @@ -281,7 +205,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, int shift_start[4], shift_dec[4]; int channels = 0; - if (row_info->color_type & PNG_COLOR_MASK_COLOR) + if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) { shift_start[channels] = row_info->bit_depth - bit_depth->red; shift_dec[channels] = bit_depth->red; @@ -303,7 +227,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, channels++; } - if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0) { shift_start[channels] = row_info->bit_depth - bit_depth->alpha; shift_dec[channels] = bit_depth->alpha; @@ -315,7 +239,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, { png_bytep bp = row; png_size_t i; - png_byte mask; + unsigned int mask; png_size_t row_bytes = row_info->rowbytes; if (bit_depth->gray == 1 && row_info->bit_depth == 2) @@ -329,20 +253,22 @@ png_do_shift(png_row_infop row_info, png_bytep row, for (i = 0; i < row_bytes; i++, bp++) { - png_uint_16 v; int j; + unsigned int v, out; v = *bp; - *bp = 0; + out = 0; for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0]) { if (j > 0) - *bp |= (png_byte)((v << j) & 0xff); + out |= v << j; else - *bp |= (png_byte)((v >> (-j)) & mask); + out |= (v >> (-j)) & mask; } + + *bp = (png_byte)(out & 0xff); } } @@ -355,21 +281,23 @@ png_do_shift(png_row_infop row_info, png_bytep row, for (i = 0; i < istop; i++, bp++) { - png_uint_16 v; + const unsigned int c = i%channels; int j; - int c = (int)(i%channels); + unsigned int v, out; v = *bp; - *bp = 0; + out = 0; for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) { if (j > 0) - *bp |= (png_byte)((v << j) & 0xff); + out |= v << j; else - *bp |= (png_byte)((v >> (-j)) & 0xff); + out |= v >> (-j); } + + *bp = (png_byte)(out & 0xff); } } @@ -381,22 +309,22 @@ png_do_shift(png_row_infop row_info, png_bytep row, for (bp = row, i = 0; i < istop; i++) { - int c = (int)(i%channels); - png_uint_16 value, v; + const unsigned int c = i%channels; int j; + unsigned int value, v; - v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1)); + v = png_get_uint_16(bp); value = 0; for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) { if (j > 0) - value |= (png_uint_16)((v << j) & (png_uint_16)0xffff); + value |= v << j; else - value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff); + value |= v >> (-j); } - *bp++ = (png_byte)(value >> 8); + *bp++ = (png_byte)((value >> 8) & 0xff); *bp++ = (png_byte)(value & 0xff); } } @@ -405,7 +333,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, #endif #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED -void /* PRIVATE */ +static void png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_write_swap_alpha"); @@ -453,7 +381,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) *(dp++) = save[1]; } } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ +#endif /* WRITE_16BIT */ } else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) @@ -492,14 +420,14 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) *(dp++) = save[1]; } } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ +#endif /* WRITE_16BIT */ } } } #endif #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED -void /* PRIVATE */ +static void png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_write_invert_alpha"); @@ -549,7 +477,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) *(dp++) = (png_byte)(255 - *(sp++)); } } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ +#endif /* WRITE_16BIT */ } else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) @@ -587,75 +515,88 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) *(dp++) = (png_byte)(255 - *(sp++)); } } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ +#endif /* WRITE_16BIT */ } } } #endif -#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ -#ifdef PNG_MNG_FEATURES_SUPPORTED -/* Undoes intrapixel differencing */ +/* Transform the data according to the user's wishes. The order of + * transformations is significant. + */ void /* PRIVATE */ -png_do_write_intrapixel(png_row_infop row_info, png_bytep row) +png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info) { - png_debug(1, "in png_do_write_intrapixel"); + png_debug(1, "in png_do_write_transformations"); - if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) - { - int bytes_per_pixel; - png_uint_32 row_width = row_info->width; - if (row_info->bit_depth == 8) - { - png_bytep rp; - png_uint_32 i; + if (png_ptr == NULL) + return; - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - bytes_per_pixel = 3; +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) + if (png_ptr->write_user_transform_fn != NULL) + (*(png_ptr->write_user_transform_fn)) /* User write transform + function */ + (png_ptr, /* png_ptr */ + row_info, /* row_info: */ + /* png_uint_32 width; width of row */ + /* png_size_t rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#endif - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - bytes_per_pixel = 4; +#ifdef PNG_WRITE_FILLER_SUPPORTED + if ((png_ptr->transformations & PNG_FILLER) != 0) + png_do_strip_channel(row_info, png_ptr->row_buf + 1, + !(png_ptr->flags & PNG_FLAG_FILLER_AFTER)); +#endif - else - return; +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + png_do_packswap(row_info, png_ptr->row_buf + 1); +#endif - for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) - { - *(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff); - *(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff); - } - } +#ifdef PNG_WRITE_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) != 0) + png_do_pack(row_info, png_ptr->row_buf + 1, + (png_uint_32)png_ptr->bit_depth); +#endif -#ifdef PNG_WRITE_16BIT_SUPPORTED - else if (row_info->bit_depth == 16) - { - png_bytep rp; - png_uint_32 i; +#ifdef PNG_WRITE_SWAP_SUPPORTED +# ifdef PNG_16BIT_SUPPORTED + if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0) + png_do_swap(row_info, png_ptr->row_buf + 1); +# endif +#endif - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - bytes_per_pixel = 6; +#ifdef PNG_WRITE_SHIFT_SUPPORTED + if ((png_ptr->transformations & PNG_SHIFT) != 0) + png_do_shift(row_info, png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - bytes_per_pixel = 8; +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0) + png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1); +#endif - else - return; +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0) + png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1); +#endif - for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) - { - png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); - png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); - png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); - png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL); - png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL); - *(rp ) = (png_byte)((red >> 8) & 0xff); - *(rp + 1) = (png_byte)(red & 0xff); - *(rp + 4) = (png_byte)((blue >> 8) & 0xff); - *(rp + 5) = (png_byte)(blue & 0xff); - } - } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ - } +#ifdef PNG_WRITE_BGR_SUPPORTED + if ((png_ptr->transformations & PNG_BGR) != 0) + png_do_bgr(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_INVERT_SUPPORTED + if ((png_ptr->transformations & PNG_INVERT_MONO) != 0) + png_do_invert(row_info, png_ptr->row_buf + 1); +#endif } -#endif /* PNG_MNG_FEATURES_SUPPORTED */ -#endif /* PNG_WRITE_SUPPORTED */ +#endif /* WRITE_TRANSFORMS */ +#endif /* WRITE */ diff --git a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwutil.c b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwutil.c index 91634671e7c..66a8812d790 100644 --- a/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwutil.c +++ b/jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwutil.c @@ -29,8 +29,8 @@ * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * - * Last changed in libpng 1.5.4 [July 7, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * Last changed in libpng 1.6.15 [November 20, 2014] + * Copyright (c) 1998-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -57,23 +57,6 @@ png_save_uint_32(png_bytep buf, png_uint_32 i) buf[3] = (png_byte)(i & 0xff); } -#ifdef PNG_SAVE_INT_32_SUPPORTED -/* The png_save_int_32 function assumes integers are stored in two's - * complement format. If this isn't the case, then this routine needs to - * be modified to write data in two's complement format. Note that, - * the following works correctly even if png_int_32 has more than 32 bits - * (compare the more complex code required on read for sign extention.) - */ -void PNGAPI -png_save_int_32(png_bytep buf, png_int_32 i) -{ - buf[0] = (png_byte)((i >> 24) & 0xff); - buf[1] = (png_byte)((i >> 16) & 0xff); - buf[2] = (png_byte)((i >> 8) & 0xff); - buf[3] = (png_byte)(i & 0xff); -} -#endif - /* Place a 16-bit number into a buffer in PNG byte order. * The parameter is declared unsigned int, not png_uint_16, * just to avoid potential problems on pre-ANSI C compilers. @@ -93,7 +76,7 @@ png_save_uint_16(png_bytep buf, unsigned int i) * bytes have already been written. */ void PNGAPI -png_write_sig(png_structp png_ptr) +png_write_sig(png_structrp png_ptr) { png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; @@ -110,39 +93,20 @@ png_write_sig(png_structp png_ptr) png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; } -/* Write a PNG chunk all at once. The type is an array of ASCII characters - * representing the chunk name. The array must be at least 4 bytes in - * length, and does not need to be null terminated. To be safe, pass the - * pre-defined chunk names here, and if you need a new one, define it - * where the others are defined. The length is the length of the data. - * All the data must be present. If that is not possible, use the - * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end() - * functions instead. - */ -void PNGAPI -png_write_chunk(png_structp png_ptr, png_const_bytep chunk_name, - png_const_bytep data, png_size_t length) -{ - if (png_ptr == NULL) - return; - - png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length); - png_write_chunk_data(png_ptr, data, (png_size_t)length); - png_write_chunk_end(png_ptr); -} - /* Write the start of a PNG chunk. The type is the chunk type. * The total_length is the sum of the lengths of all the data you will be * passing in png_write_chunk_data(). */ -void PNGAPI -png_write_chunk_start(png_structp png_ptr, png_const_bytep chunk_name, +static void +png_write_chunk_header(png_structrp png_ptr, png_uint_32 chunk_name, png_uint_32 length) { png_byte buf[8]; - png_debug2(0, "Writing %s chunk, length = %lu", chunk_name, - (unsigned long)length); +#if defined(PNG_DEBUG) && (PNG_DEBUG > 0) + PNG_CSTRING_FROM_CHUNK(buf, chunk_name); + png_debug2(0, "Writing %s chunk, length = %lu", buf, (unsigned long)length); +#endif if (png_ptr == NULL) return; @@ -156,16 +120,16 @@ png_write_chunk_start(png_structp png_ptr, png_const_bytep chunk_name, /* Write the length and the chunk name */ png_save_uint_32(buf, length); - png_memcpy(buf + 4, chunk_name, 4); - png_write_data(png_ptr, buf, (png_size_t)8); + png_save_uint_32(buf + 4, chunk_name); + png_write_data(png_ptr, buf, 8); /* Put the chunk name into png_ptr->chunk_name */ - png_memcpy(png_ptr->chunk_name, chunk_name, 4); + png_ptr->chunk_name = chunk_name; /* Reset the crc and run it over the chunk name */ png_reset_crc(png_ptr); - png_calculate_crc(png_ptr, chunk_name, 4); + png_calculate_crc(png_ptr, buf + 4, 4); #ifdef PNG_IO_STATE_SUPPORTED /* Inform the I/O callback that chunk data will (possibly) be written. @@ -175,13 +139,20 @@ png_write_chunk_start(png_structp png_ptr, png_const_bytep chunk_name, #endif } -/* Write the data of a PNG chunk started with png_write_chunk_start(). +void PNGAPI +png_write_chunk_start(png_structrp png_ptr, png_const_bytep chunk_string, + png_uint_32 length) +{ + png_write_chunk_header(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), length); +} + +/* Write the data of a PNG chunk started with png_write_chunk_header(). * Note that multiple calls to this function are allowed, and that the * sum of the lengths from these calls *must* add up to the total_length - * given to png_write_chunk_start(). + * given to png_write_chunk_header(). */ void PNGAPI -png_write_chunk_data(png_structp png_ptr, png_const_bytep data, +png_write_chunk_data(png_structrp png_ptr, png_const_bytep data, png_size_t length) { /* Write the data, and run the CRC over it */ @@ -193,15 +164,15 @@ png_write_chunk_data(png_structp png_ptr, png_const_bytep data, png_write_data(png_ptr, data, length); /* Update the CRC after writing the data, - * in case that the user I/O routine alters it. + * in case the user I/O routine alters it. */ png_calculate_crc(png_ptr, data, length); } } -/* Finish a chunk started with png_write_chunk_start(). */ +/* Finish a chunk started with png_write_chunk_header(). */ void PNGAPI -png_write_chunk_end(png_structp png_ptr) +png_write_chunk_end(png_structrp png_ptr) { png_byte buf[4]; @@ -220,468 +191,601 @@ png_write_chunk_end(png_structp png_ptr) png_write_data(png_ptr, buf, (png_size_t)4); } -/* Initialize the compressor for the appropriate type of compression. */ -static void -png_zlib_claim(png_structp png_ptr, png_uint_32 state) -{ - if (!(png_ptr->zlib_state & PNG_ZLIB_IN_USE)) - { - /* If already initialized for 'state' do not re-init. */ - if (png_ptr->zlib_state != state) - { - int ret = Z_OK; - png_const_charp who = "-"; - - /* If actually initialized for another state do a deflateEnd. */ - if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED) - { - ret = deflateEnd(&png_ptr->zstream); - who = "end"; - png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED; - } - - /* zlib itself detects an incomplete state on deflateEnd */ - if (ret == Z_OK) switch (state) - { -# ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED - case PNG_ZLIB_FOR_TEXT: - ret = deflateInit2(&png_ptr->zstream, - png_ptr->zlib_text_level, png_ptr->zlib_text_method, - png_ptr->zlib_text_window_bits, - png_ptr->zlib_text_mem_level, png_ptr->zlib_text_strategy); - who = "text"; - break; -# endif - - case PNG_ZLIB_FOR_IDAT: - ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, - png_ptr->zlib_method, png_ptr->zlib_window_bits, - png_ptr->zlib_mem_level, png_ptr->zlib_strategy); - who = "IDAT"; - break; - - default: - png_error(png_ptr, "invalid zlib state"); - } - - if (ret == Z_OK) - png_ptr->zlib_state = state; - - else /* an error in deflateEnd or deflateInit2 */ - { - size_t pos = 0; - char msg[64]; - - pos = png_safecat(msg, sizeof msg, pos, - "zlib failed to initialize compressor ("); - pos = png_safecat(msg, sizeof msg, pos, who); - - switch (ret) - { - case Z_VERSION_ERROR: - pos = png_safecat(msg, sizeof msg, pos, ") version error"); - break; - - case Z_STREAM_ERROR: - pos = png_safecat(msg, sizeof msg, pos, ") stream error"); - break; - - case Z_MEM_ERROR: - pos = png_safecat(msg, sizeof msg, pos, ") memory error"); - break; - - default: - pos = png_safecat(msg, sizeof msg, pos, ") unknown error"); - break; - } - - png_error(png_ptr, msg); - } - } - - /* Here on success, claim the zstream: */ - png_ptr->zlib_state |= PNG_ZLIB_IN_USE; - } - - else - png_error(png_ptr, "zstream already in use (internal error)"); -} - -/* The opposite: release the stream. It is also reset, this API will warn on - * error but will not fail. +/* Write a PNG chunk all at once. The type is an array of ASCII characters + * representing the chunk name. The array must be at least 4 bytes in + * length, and does not need to be null terminated. To be safe, pass the + * pre-defined chunk names here, and if you need a new one, define it + * where the others are defined. The length is the length of the data. + * All the data must be present. If that is not possible, use the + * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end() + * functions instead. */ static void -png_zlib_release(png_structp png_ptr) +png_write_complete_chunk(png_structrp png_ptr, png_uint_32 chunk_name, + png_const_bytep data, png_size_t length) { - if (png_ptr->zlib_state & PNG_ZLIB_IN_USE) + if (png_ptr == NULL) + return; + + /* On 64 bit architectures 'length' may not fit in a png_uint_32. */ + if (length > PNG_UINT_31_MAX) + png_error(png_ptr, "length exceeds PNG maximum"); + + png_write_chunk_header(png_ptr, chunk_name, (png_uint_32)length); + png_write_chunk_data(png_ptr, data, length); + png_write_chunk_end(png_ptr); +} + +/* This is the API that calls the internal function above. */ +void PNGAPI +png_write_chunk(png_structrp png_ptr, png_const_bytep chunk_string, + png_const_bytep data, png_size_t length) +{ + png_write_complete_chunk(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), data, + length); +} + +/* This is used below to find the size of an image to pass to png_deflate_claim, + * so it only needs to be accurate if the size is less than 16384 bytes (the + * point at which a lower LZ window size can be used.) + */ +static png_alloc_size_t +png_image_size(png_structrp png_ptr) +{ + /* Only return sizes up to the maximum of a png_uint_32; do this by limiting + * the width and height used to 15 bits. + */ + png_uint_32 h = png_ptr->height; + + if (png_ptr->rowbytes < 32768 && h < 32768) { - int ret = deflateReset(&png_ptr->zstream); - - png_ptr->zlib_state &= ~PNG_ZLIB_IN_USE; - - if (ret != Z_OK) + if (png_ptr->interlaced != 0) { - png_const_charp err; - PNG_WARNING_PARAMETERS(p) + /* Interlacing makes the image larger because of the replication of + * both the filter byte and the padding to a byte boundary. + */ + png_uint_32 w = png_ptr->width; + unsigned int pd = png_ptr->pixel_depth; + png_alloc_size_t cb_base; + int pass; - switch (ret) + for (cb_base=0, pass=0; pass<=6; ++pass) { - case Z_VERSION_ERROR: - err = "version"; - break; + png_uint_32 pw = PNG_PASS_COLS(w, pass); - case Z_STREAM_ERROR: - err = "stream"; - break; - - case Z_MEM_ERROR: - err = "memory"; - break; - - default: - err = "unknown"; - break; + if (pw > 0) + cb_base += (PNG_ROWBYTES(pd, pw)+1) * PNG_PASS_ROWS(h, pass); } - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, ret); - png_warning_parameter(p, 2, err); - - if (png_ptr->zstream.msg) - err = png_ptr->zstream.msg; - else - err = "[no zlib message]"; - - png_warning_parameter(p, 3, err); - - png_formatted_warning(png_ptr, p, - "zlib failed to reset compressor: @1(@2): @3"); + return cb_base; } + + else + return (png_ptr->rowbytes+1) * h; } else - png_warning(png_ptr, "zstream not in use (internal error)"); + return 0xffffffffU; +} + +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + /* This is the code to hack the first two bytes of the deflate stream (the + * deflate header) to correct the windowBits value to match the actual data + * size. Note that the second argument is the *uncompressed* size but the + * first argument is the *compressed* data (and it must be deflate + * compressed.) + */ +static void +optimize_cmf(png_bytep data, png_alloc_size_t data_size) +{ + /* Optimize the CMF field in the zlib stream. The resultant zlib stream is + * still compliant to the stream specification. + */ + if (data_size <= 16384) /* else windowBits must be 15 */ + { + unsigned int z_cmf = data[0]; /* zlib compression method and flags */ + + if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) + { + unsigned int z_cinfo; + unsigned int half_z_window_size; + + z_cinfo = z_cmf >> 4; + half_z_window_size = 1U << (z_cinfo + 7); + + if (data_size <= half_z_window_size) /* else no change */ + { + unsigned int tmp; + + do + { + half_z_window_size >>= 1; + --z_cinfo; + } + while (z_cinfo > 0 && data_size <= half_z_window_size); + + z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); + + data[0] = (png_byte)z_cmf; + tmp = data[1] & 0xe0; + tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; + data[1] = (png_byte)tmp; + } + } + } +} +#endif /* WRITE_OPTIMIZE_CMF */ + +/* Initialize the compressor for the appropriate type of compression. */ +static int +png_deflate_claim(png_structrp png_ptr, png_uint_32 owner, + png_alloc_size_t data_size) +{ + if (png_ptr->zowner != 0) + { +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED) + char msg[64]; + + PNG_STRING_FROM_CHUNK(msg, owner); + msg[4] = ':'; + msg[5] = ' '; + PNG_STRING_FROM_CHUNK(msg+6, png_ptr->zowner); + /* So the message that results is " using zstream"; this is an + * internal error, but is very useful for debugging. i18n requirements + * are minimal. + */ + (void)png_safecat(msg, (sizeof msg), 10, " using zstream"); +#endif +#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC + png_warning(png_ptr, msg); + + /* Attempt sane error recovery */ + if (png_ptr->zowner == png_IDAT) /* don't steal from IDAT */ + { + png_ptr->zstream.msg = PNGZ_MSG_CAST("in use by IDAT"); + return Z_STREAM_ERROR; + } + + png_ptr->zowner = 0; +#else + png_error(png_ptr, msg); +#endif + } + + { + int level = png_ptr->zlib_level; + int method = png_ptr->zlib_method; + int windowBits = png_ptr->zlib_window_bits; + int memLevel = png_ptr->zlib_mem_level; + int strategy; /* set below */ + int ret; /* zlib return code */ + + if (owner == png_IDAT) + { + if ((png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY) != 0) + strategy = png_ptr->zlib_strategy; + + else if (png_ptr->do_filter != PNG_FILTER_NONE) + strategy = PNG_Z_DEFAULT_STRATEGY; + + else + strategy = PNG_Z_DEFAULT_NOFILTER_STRATEGY; + } + + else + { +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED + level = png_ptr->zlib_text_level; + method = png_ptr->zlib_text_method; + windowBits = png_ptr->zlib_text_window_bits; + memLevel = png_ptr->zlib_text_mem_level; + strategy = png_ptr->zlib_text_strategy; +#else + /* If customization is not supported the values all come from the + * IDAT values except for the strategy, which is fixed to the + * default. (This is the pre-1.6.0 behavior too, although it was + * implemented in a very different way.) + */ + strategy = Z_DEFAULT_STRATEGY; +#endif + } + + /* Adjust 'windowBits' down if larger than 'data_size'; to stop this + * happening just pass 32768 as the data_size parameter. Notice that zlib + * requires an extra 262 bytes in the window in addition to the data to be + * able to see the whole of the data, so if data_size+262 takes us to the + * next windowBits size we need to fix up the value later. (Because even + * though deflate needs the extra window, inflate does not!) + */ + if (data_size <= 16384) + { + /* IMPLEMENTATION NOTE: this 'half_window_size' stuff is only here to + * work round a Microsoft Visual C misbehavior which, contrary to C-90, + * widens the result of the following shift to 64-bits if (and, + * apparently, only if) it is used in a test. + */ + unsigned int half_window_size = 1U << (windowBits-1); + + while (data_size + 262 <= half_window_size) + { + half_window_size >>= 1; + --windowBits; + } + } + + /* Check against the previous initialized values, if any. */ + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0 && + (png_ptr->zlib_set_level != level || + png_ptr->zlib_set_method != method || + png_ptr->zlib_set_window_bits != windowBits || + png_ptr->zlib_set_mem_level != memLevel || + png_ptr->zlib_set_strategy != strategy)) + { + if (deflateEnd(&png_ptr->zstream) != Z_OK) + png_warning(png_ptr, "deflateEnd failed (ignored)"); + + png_ptr->flags &= ~PNG_FLAG_ZSTREAM_INITIALIZED; + } + + /* For safety clear out the input and output pointers (currently zlib + * doesn't use them on Init, but it might in the future). + */ + png_ptr->zstream.next_in = NULL; + png_ptr->zstream.avail_in = 0; + png_ptr->zstream.next_out = NULL; + png_ptr->zstream.avail_out = 0; + + /* Now initialize if required, setting the new parameters, otherwise just + * to a simple reset to the previous parameters. + */ + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0) + ret = deflateReset(&png_ptr->zstream); + + else + { + ret = deflateInit2(&png_ptr->zstream, level, method, windowBits, + memLevel, strategy); + + if (ret == Z_OK) + png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED; + } + + /* The return code is from either deflateReset or deflateInit2; they have + * pretty much the same set of error codes. + */ + if (ret == Z_OK) + png_ptr->zowner = owner; + + else + png_zstream_error(png_ptr, ret); + + return ret; + } +} + +/* Clean up (or trim) a linked list of compression buffers. */ +void /* PRIVATE */ +png_free_buffer_list(png_structrp png_ptr, png_compression_bufferp *listp) +{ + png_compression_bufferp list = *listp; + + if (list != NULL) + { + *listp = NULL; + + do + { + png_compression_bufferp next = list->next; + + png_free(png_ptr, list); + list = next; + } + while (list != NULL); + } } #ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED /* This pair of functions encapsulates the operation of (a) compressing a * text string, and (b) issuing it later as a series of chunk data writes. * The compression_state structure is shared context for these functions - * set up by the caller in order to make the whole mess thread-safe. + * set up by the caller to allow access to the relevant local variables. + * + * compression_buffer (new in 1.6.0) is just a linked list of zbuffer_size + * temporary buffers. From 1.6.0 it is retained in png_struct so that it will + * be correctly freed in the event of a write error (previous implementations + * just leaked memory.) */ - typedef struct { - png_const_bytep input; /* The uncompressed input data */ - png_size_t input_len; /* Its length */ - int num_output_ptr; /* Number of output pointers used */ - int max_output_ptr; /* Size of output_ptr */ - png_bytep *output_ptr; /* Array of pointers to output */ + png_const_bytep input; /* The uncompressed input data */ + png_alloc_size_t input_len; /* Its length */ + png_uint_32 output_len; /* Final compressed length */ + png_byte output[1024]; /* First block of output */ } compression_state; -/* Compress given text into storage in the png_ptr structure */ -static int /* PRIVATE */ -png_text_compress(png_structp png_ptr, - png_const_charp text, png_size_t text_len, int compression, - compression_state *comp) +static void +png_text_compress_init(compression_state *comp, png_const_bytep input, + png_alloc_size_t input_len) +{ + comp->input = input; + comp->input_len = input_len; + comp->output_len = 0; +} + +/* Compress the data in the compression state input */ +static int +png_text_compress(png_structrp png_ptr, png_uint_32 chunk_name, + compression_state *comp, png_uint_32 prefix_len) { int ret; - comp->num_output_ptr = 0; - comp->max_output_ptr = 0; - comp->output_ptr = NULL; - comp->input = NULL; - comp->input_len = text_len; - - /* We may just want to pass the text right through */ - if (compression == PNG_TEXT_COMPRESSION_NONE) - { - comp->input = (png_const_bytep)text; - return((int)text_len); - } - - if (compression >= PNG_TEXT_COMPRESSION_LAST) - { - PNG_WARNING_PARAMETERS(p) - - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, - compression); - png_formatted_warning(png_ptr, p, "Unknown compression type @1"); - } - - /* We can't write the chunk until we find out how much data we have, - * which means we need to run the compressor first and save the - * output. This shouldn't be a problem, as the vast majority of - * comments should be reasonable, but we will set up an array of - * malloc'd pointers to be sure. + /* To find the length of the output it is necessary to first compress the + * input. The result is buffered rather than using the two-pass algorithm + * that is used on the inflate side; deflate is assumed to be slower and a + * PNG writer is assumed to have more memory available than a PNG reader. * - * If we knew the application was well behaved, we could simplify this - * greatly by assuming we can always malloc an output buffer large - * enough to hold the compressed text ((1001 * text_len / 1000) + 12) - * and malloc this directly. The only time this would be a bad idea is - * if we can't malloc more than 64K and we have 64K of random input - * data, or if the input string is incredibly large (although this - * wouldn't cause a failure, just a slowdown due to swapping). + * IMPLEMENTATION NOTE: the zlib API deflateBound() can be used to find an + * upper limit on the output size, but it is always bigger than the input + * size so it is likely to be more efficient to use this linked-list + * approach. */ - png_zlib_claim(png_ptr, PNG_ZLIB_FOR_TEXT); + ret = png_deflate_claim(png_ptr, chunk_name, comp->input_len); - /* Set up the compression buffers */ - /* TODO: the following cast hides a potential overflow problem. */ - png_ptr->zstream.avail_in = (uInt)text_len; + if (ret != Z_OK) + return ret; - /* NOTE: assume zlib doesn't overwrite the input */ - png_ptr->zstream.next_in = (Bytef *)text; - png_ptr->zstream.avail_out = png_ptr->zbuf_size; - png_ptr->zstream.next_out = png_ptr->zbuf; - - /* This is the same compression loop as in png_write_row() */ - do + /* Set up the compression buffers, we need a loop here to avoid overflowing a + * uInt. Use ZLIB_IO_MAX to limit the input. The output is always limited + * by the output buffer size, so there is no need to check that. Since this + * is ANSI-C we know that an 'int', hence a uInt, is always at least 16 bits + * in size. + */ { - /* Compress the data */ - ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); + png_compression_bufferp *end = &png_ptr->zbuffer_list; + png_alloc_size_t input_len = comp->input_len; /* may be zero! */ + png_uint_32 output_len; - if (ret != Z_OK) + /* zlib updates these for us: */ + png_ptr->zstream.next_in = PNGZ_INPUT_CAST(comp->input); + png_ptr->zstream.avail_in = 0; /* Set below */ + png_ptr->zstream.next_out = comp->output; + png_ptr->zstream.avail_out = (sizeof comp->output); + + output_len = png_ptr->zstream.avail_out; + + do { - /* Error */ - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); + uInt avail_in = ZLIB_IO_MAX; - else - png_error(png_ptr, "zlib error"); - } + if (avail_in > input_len) + avail_in = (uInt)input_len; - /* Check to see if we need more room */ - if (!(png_ptr->zstream.avail_out)) - { - /* Make sure the output array has room */ - if (comp->num_output_ptr >= comp->max_output_ptr) + input_len -= avail_in; + + png_ptr->zstream.avail_in = avail_in; + + if (png_ptr->zstream.avail_out == 0) { - int old_max; + png_compression_buffer *next; - old_max = comp->max_output_ptr; - comp->max_output_ptr = comp->num_output_ptr + 4; - if (comp->output_ptr != NULL) + /* Chunk data is limited to 2^31 bytes in length, so the prefix + * length must be counted here. + */ + if (output_len + prefix_len > PNG_UINT_31_MAX) { - png_bytepp old_ptr; - - old_ptr = comp->output_ptr; - - comp->output_ptr = (png_bytepp)png_malloc(png_ptr, - (png_alloc_size_t) - (comp->max_output_ptr * png_sizeof(png_charpp))); - - png_memcpy(comp->output_ptr, old_ptr, old_max - * png_sizeof(png_charp)); - - png_free(png_ptr, old_ptr); + ret = Z_MEM_ERROR; + break; } - else - comp->output_ptr = (png_bytepp)png_malloc(png_ptr, - (png_alloc_size_t) - (comp->max_output_ptr * png_sizeof(png_charp))); - } - /* Save the data */ - comp->output_ptr[comp->num_output_ptr] = - (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)png_ptr->zbuf_size); - - png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, - png_ptr->zbuf_size); - - comp->num_output_ptr++; - - /* and reset the buffer */ - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_out = png_ptr->zbuf; - } - /* Continue until we don't have any more to compress */ - } while (png_ptr->zstream.avail_in); - - /* Finish the compression */ - do - { - /* Tell zlib we are finished */ - ret = deflate(&png_ptr->zstream, Z_FINISH); - - if (ret == Z_OK) - { - /* Check to see if we need more room */ - if (!(png_ptr->zstream.avail_out)) - { - /* Check to make sure our output array has room */ - if (comp->num_output_ptr >= comp->max_output_ptr) + /* Need a new (malloc'ed) buffer, but there may be one present + * already. + */ + next = *end; + if (next == NULL) { - int old_max; + next = png_voidcast(png_compression_bufferp, png_malloc_base + (png_ptr, PNG_COMPRESSION_BUFFER_SIZE(png_ptr))); - old_max = comp->max_output_ptr; - comp->max_output_ptr = comp->num_output_ptr + 4; - if (comp->output_ptr != NULL) + if (next == NULL) { - png_bytepp old_ptr; - - old_ptr = comp->output_ptr; - - /* This could be optimized to realloc() */ - comp->output_ptr = (png_bytepp)png_malloc(png_ptr, - (png_alloc_size_t)(comp->max_output_ptr * - png_sizeof(png_charp))); - - png_memcpy(comp->output_ptr, old_ptr, - old_max * png_sizeof(png_charp)); - - png_free(png_ptr, old_ptr); + ret = Z_MEM_ERROR; + break; } - else - comp->output_ptr = (png_bytepp)png_malloc(png_ptr, - (png_alloc_size_t)(comp->max_output_ptr * - png_sizeof(png_charp))); + /* Link in this buffer (so that it will be freed later) */ + next->next = NULL; + *end = next; } - /* Save the data */ - comp->output_ptr[comp->num_output_ptr] = - (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)png_ptr->zbuf_size); + png_ptr->zstream.next_out = next->output; + png_ptr->zstream.avail_out = png_ptr->zbuffer_size; + output_len += png_ptr->zstream.avail_out; - png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, - png_ptr->zbuf_size); - - comp->num_output_ptr++; - - /* and reset the buffer pointers */ - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_out = png_ptr->zbuf; + /* Move 'end' to the next buffer pointer. */ + end = &next->next; } + + /* Compress the data */ + ret = deflate(&png_ptr->zstream, + input_len > 0 ? Z_NO_FLUSH : Z_FINISH); + + /* Claw back input data that was not consumed (because avail_in is + * reset above every time round the loop). + */ + input_len += png_ptr->zstream.avail_in; + png_ptr->zstream.avail_in = 0; /* safety */ } - else if (ret != Z_STREAM_END) + while (ret == Z_OK); + + /* There may be some space left in the last output buffer. This needs to + * be subtracted from output_len. + */ + output_len -= png_ptr->zstream.avail_out; + png_ptr->zstream.avail_out = 0; /* safety */ + comp->output_len = output_len; + + /* Now double check the output length, put in a custom message if it is + * too long. Otherwise ensure the z_stream::msg pointer is set to + * something. + */ + if (output_len + prefix_len >= PNG_UINT_31_MAX) { - /* We got an error */ - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); - - else - png_error(png_ptr, "zlib error"); + png_ptr->zstream.msg = PNGZ_MSG_CAST("compressed data too long"); + ret = Z_MEM_ERROR; } - } while (ret != Z_STREAM_END); - /* Text length is number of buffers plus last buffer */ - text_len = png_ptr->zbuf_size * comp->num_output_ptr; + else + png_zstream_error(png_ptr, ret); - if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) - text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out; + /* Reset zlib for another zTXt/iTXt or image data */ + png_ptr->zowner = 0; - return((int)text_len); + /* The only success case is Z_STREAM_END, input_len must be 0; if not this + * is an internal error. + */ + if (ret == Z_STREAM_END && input_len == 0) + { +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + /* Fix up the deflate header, if required */ + optimize_cmf(comp->output, comp->input_len); +#endif + /* But Z_OK is returned, not Z_STREAM_END; this allows the claim + * function above to return Z_STREAM_END on an error (though it never + * does in the current versions of zlib.) + */ + return Z_OK; + } + + else + return ret; + } } /* Ship the compressed text out via chunk writes */ -static void /* PRIVATE */ -png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) +static void +png_write_compressed_data_out(png_structrp png_ptr, compression_state *comp) { - int i; + png_uint_32 output_len = comp->output_len; + png_const_bytep output = comp->output; + png_uint_32 avail = (sizeof comp->output); + png_compression_buffer *next = png_ptr->zbuffer_list; - /* Handle the no-compression case */ - if (comp->input) + for (;;) { - png_write_chunk_data(png_ptr, comp->input, comp->input_len); + if (avail > output_len) + avail = output_len; - return; + png_write_chunk_data(png_ptr, output, avail); + + output_len -= avail; + + if (output_len == 0 || next == NULL) + break; + + avail = png_ptr->zbuffer_size; + output = next->output; + next = next->next; } -#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED - if (comp->input_len >= 2 && comp->input_len < 16384) + /* This is an internal error; 'next' must have been NULL! */ + if (output_len > 0) + png_error(png_ptr, "error writing ancillary chunked compressed data"); +} +#endif /* WRITE_COMPRESSED_TEXT */ + +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ + defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) +/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, + * and if invalid, correct the keyword rather than discarding the entire + * chunk. The PNG 1.0 specification requires keywords 1-79 characters in + * length, forbids leading or trailing whitespace, multiple internal spaces, + * and the non-break space (0x80) from ISO 8859-1. Returns keyword length. + * + * The 'new_key' buffer must be 80 characters in size (for the keyword plus a + * trailing '\0'). If this routine returns 0 then there was no keyword, or a + * valid one could not be generated, and the caller must png_error. + */ +static png_uint_32 +png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key) +{ + png_const_charp orig_key = key; + png_uint_32 key_len = 0; + int bad_character = 0; + int space = 1; + + png_debug(1, "in png_check_keyword"); + + if (key == NULL) { - unsigned int z_cmf; /* zlib compression method and flags */ + *new_key = 0; + return 0; + } - /* Optimize the CMF field in the zlib stream. This hack of the zlib - * stream is compliant to the stream specification. - */ + while (*key && key_len < 79) + { + png_byte ch = (png_byte)(0xff & *key++); - if (comp->num_output_ptr) - z_cmf = comp->output_ptr[0][0]; - else - z_cmf = png_ptr->zbuf[0]; + if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/)) + *new_key++ = ch, ++key_len, space = 0; - if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) + else if (space == 0) { - unsigned int z_cinfo; - unsigned int half_z_window_size; - png_size_t uncompressed_text_size = comp->input_len; + /* A space or an invalid character when one wasn't seen immediately + * before; output just a space. + */ + *new_key++ = 32, ++key_len, space = 1; - z_cinfo = z_cmf >> 4; - half_z_window_size = 1 << (z_cinfo + 7); - - while (uncompressed_text_size <= half_z_window_size && - half_z_window_size >= 256) - { - z_cinfo--; - half_z_window_size >>= 1; - } - - z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); - - if (comp->num_output_ptr) - { - - if (comp->output_ptr[0][0] != z_cmf) - { - int tmp; - - comp->output_ptr[0][0] = (png_byte)z_cmf; - tmp = comp->output_ptr[0][1] & 0xe0; - tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; - comp->output_ptr[0][1] = (png_byte)tmp; - } - } - else - { - int tmp; - - png_ptr->zbuf[0] = (png_byte)z_cmf; - tmp = png_ptr->zbuf[1] & 0xe0; - tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; - png_ptr->zbuf[1] = (png_byte)tmp; - } + /* If the character was not a space then it is invalid. */ + if (ch != 32) + bad_character = ch; } - else - png_error(png_ptr, - "Invalid zlib compression method or flags in non-IDAT chunk"); + else if (bad_character == 0) + bad_character = ch; /* just skip it, record the first error */ } -#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */ - /* Write saved output buffers, if any */ - for (i = 0; i < comp->num_output_ptr; i++) + if (key_len > 0 && space != 0) /* trailing space */ { - png_write_chunk_data(png_ptr, comp->output_ptr[i], - (png_size_t)png_ptr->zbuf_size); - - png_free(png_ptr, comp->output_ptr[i]); + --key_len, --new_key; + if (bad_character == 0) + bad_character = 32; } - if (comp->max_output_ptr != 0) - png_free(png_ptr, comp->output_ptr); + /* Terminate the keyword */ + *new_key = 0; - /* Write anything left in zbuf */ - if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) - png_write_chunk_data(png_ptr, png_ptr->zbuf, - (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out)); + if (key_len == 0) + return 0; - /* Reset zlib for another zTXt/iTXt or image data */ - png_zlib_release(png_ptr); +#ifdef PNG_WARNINGS_SUPPORTED + /* Try to only output one warning per keyword: */ + if (*key != 0) /* keyword too long */ + png_warning(png_ptr, "keyword truncated"); + + else if (bad_character != 0) + { + PNG_WARNING_PARAMETERS(p) + + png_warning_parameter(p, 1, orig_key); + png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character); + + png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'"); + } +#endif /* WARNINGS */ + + return key_len; } -#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */ +#endif /* WRITE_TEXT || WRITE_pCAL || WRITE_iCCP || WRITE_sPLT */ /* Write the IHDR chunk, and update the png_struct with the necessary * information. Note that the rest of this code depends upon this * information being correct. */ void /* PRIVATE */ -png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, +png_write_IHDR(png_structrp png_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int compression_type, int filter_type, int interlace_type) { - PNG_IHDR; - png_byte buf[13]; /* Buffer to store the IHDR info */ png_debug(1, "in png_write_IHDR"); @@ -772,8 +876,8 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, */ if ( #ifdef PNG_MNG_FEATURES_SUPPORTED - !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && - ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && + !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && + ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) && (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) && @@ -823,14 +927,9 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, buf[12] = (png_byte)interlace_type; /* Write the chunk */ - png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13); + png_write_complete_chunk(png_ptr, png_IHDR, buf, (png_size_t)13); - /* Initialize zlib with PNG info */ - png_ptr->zstream.zalloc = png_zalloc; - png_ptr->zstream.zfree = png_zfree; - png_ptr->zstream.opaque = (voidpf)png_ptr; - - if (!(png_ptr->do_filter)) + if ((png_ptr->do_filter) == PNG_NO_FILTERS) { if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || png_ptr->bit_depth < 8) @@ -840,55 +939,6 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, png_ptr->do_filter = PNG_ALL_FILTERS; } - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY)) - { - if (png_ptr->do_filter != PNG_FILTER_NONE) - png_ptr->zlib_strategy = Z_FILTERED; - - else - png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY; - } - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL)) - png_ptr->zlib_level = Z_DEFAULT_COMPRESSION; - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL)) - png_ptr->zlib_mem_level = 8; - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS)) - png_ptr->zlib_window_bits = 15; - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD)) - png_ptr->zlib_method = 8; - -#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED -#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_STRATEGY)) - png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY; - - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_LEVEL)) - png_ptr->zlib_text_level = png_ptr->zlib_level; - - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL)) - png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level; - - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS)) - png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits; - - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_METHOD)) - png_ptr->zlib_text_method = png_ptr->zlib_method; -#else - png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY; - png_ptr->zlib_text_level = png_ptr->zlib_level; - png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level; - png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits; - png_ptr->zlib_text_method = png_ptr->zlib_method; -#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ -#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */ - - /* Record that the compressor has not yet been initialized. */ - png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED; - png_ptr->mode = PNG_HAVE_IHDR; /* not READY_FOR_ZTXT */ } @@ -897,10 +947,9 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, * structure. */ void /* PRIVATE */ -png_write_PLTE(png_structp png_ptr, png_const_colorp palette, +png_write_PLTE(png_structrp png_ptr, png_const_colorp palette, png_uint_32 num_pal) { - PNG_PLTE; png_uint_32 i; png_const_colorp pal_ptr; png_byte buf[3]; @@ -909,7 +958,7 @@ png_write_PLTE(png_structp png_ptr, png_const_colorp palette, if (( #ifdef PNG_MNG_FEATURES_SUPPORTED - !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && + (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 && #endif num_pal == 0) || num_pal > 256) { @@ -925,7 +974,7 @@ png_write_PLTE(png_structp png_ptr, png_const_colorp palette, } } - if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) { png_warning(png_ptr, "Ignoring request to write a PLTE chunk in grayscale PNG"); @@ -936,7 +985,7 @@ png_write_PLTE(png_structp png_ptr, png_const_colorp palette, png_ptr->num_palette = (png_uint_16)num_pal; png_debug1(3, "num_palette = %d", png_ptr->num_palette); - png_write_chunk_start(png_ptr, png_PLTE, (png_uint_32)(num_pal * 3)); + png_write_chunk_header(png_ptr, png_PLTE, (png_uint_32)(num_pal * 3)); #ifdef PNG_POINTER_INDEXING_SUPPORTED for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) @@ -966,127 +1015,192 @@ png_write_PLTE(png_structp png_ptr, png_const_colorp palette, png_ptr->mode |= PNG_HAVE_PLTE; } -/* Write an IDAT chunk */ +/* This is similar to png_text_compress, above, except that it does not require + * all of the data at once and, instead of buffering the compressed result, + * writes it as IDAT chunks. Unlike png_text_compress it *can* png_error out + * because it calls the write interface. As a result it does its own error + * reporting and does not return an error code. In the event of error it will + * just call png_error. The input data length may exceed 32-bits. The 'flush' + * parameter is exactly the same as that to deflate, with the following + * meanings: + * + * Z_NO_FLUSH: normal incremental output of compressed data + * Z_SYNC_FLUSH: do a SYNC_FLUSH, used by png_write_flush + * Z_FINISH: this is the end of the input, do a Z_FINISH and clean up + * + * The routine manages the acquire and release of the png_ptr->zstream by + * checking and (at the end) clearing png_ptr->zowner; it does some sanity + * checks on the 'mode' flags while doing this. + */ void /* PRIVATE */ -png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) +png_compress_IDAT(png_structrp png_ptr, png_const_bytep input, + png_alloc_size_t input_len, int flush) { - PNG_IDAT; - - png_debug(1, "in png_write_IDAT"); - -#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED - if (!(png_ptr->mode & PNG_HAVE_IDAT) && - png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) + if (png_ptr->zowner != png_IDAT) { - /* Optimize the CMF field in the zlib stream. This hack of the zlib - * stream is compliant to the stream specification. + /* First time. Ensure we have a temporary buffer for compression and + * trim the buffer list if it has more than one entry to free memory. + * If 'WRITE_COMPRESSED_TEXT' is not set the list will never have been + * created at this point, but the check here is quick and safe. */ - unsigned int z_cmf = data[0]; /* zlib compression method and flags */ - - if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) + if (png_ptr->zbuffer_list == NULL) { - /* Avoid memory underflows and multiplication overflows. - * - * The conditions below are practically always satisfied; - * however, they still must be checked. - */ - if (length >= 2 && - png_ptr->height < 16384 && png_ptr->width < 16384) - { - /* Compute the maximum possible length of the datastream */ - - /* Number of pixels, plus for each row a filter byte - * and possibly a padding byte, so increase the maximum - * size to account for these. - */ - unsigned int z_cinfo; - unsigned int half_z_window_size; - png_uint_32 uncompressed_idat_size = png_ptr->height * - ((png_ptr->width * - png_ptr->channels * png_ptr->bit_depth + 15) >> 3); - - /* If it's interlaced, each block of 8 rows is sent as up to - * 14 rows, i.e., 6 additional rows, each with a filter byte - * and possibly a padding byte - */ - if (png_ptr->interlaced) - uncompressed_idat_size += ((png_ptr->height + 7)/8) * - (png_ptr->bit_depth < 8 ? 12 : 6); - - z_cinfo = z_cmf >> 4; - half_z_window_size = 1 << (z_cinfo + 7); - - while (uncompressed_idat_size <= half_z_window_size && - half_z_window_size >= 256) - { - z_cinfo--; - half_z_window_size >>= 1; - } - - z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); - - if (data[0] != z_cmf) - { - int tmp; - data[0] = (png_byte)z_cmf; - tmp = data[1] & 0xe0; - tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; - data[1] = (png_byte)tmp; - } - } + png_ptr->zbuffer_list = png_voidcast(png_compression_bufferp, + png_malloc(png_ptr, PNG_COMPRESSION_BUFFER_SIZE(png_ptr))); + png_ptr->zbuffer_list->next = NULL; } else - png_error(png_ptr, - "Invalid zlib compression method or flags in IDAT"); + png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list->next); + + /* It is a terminal error if we can't claim the zstream. */ + if (png_deflate_claim(png_ptr, png_IDAT, png_image_size(png_ptr)) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); + + /* The output state is maintained in png_ptr->zstream, so it must be + * initialized here after the claim. + */ + png_ptr->zstream.next_out = png_ptr->zbuffer_list->output; + png_ptr->zstream.avail_out = png_ptr->zbuffer_size; } -#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */ - png_write_chunk(png_ptr, png_IDAT, data, length); - png_ptr->mode |= PNG_HAVE_IDAT; - - /* Prior to 1.5.4 this code was replicated in every caller (except at the - * end, where it isn't technically necessary). Since this function has - * flushed the data we can safely reset the zlib output buffer here. + /* Now loop reading and writing until all the input is consumed or an error + * terminates the operation. The _out values are maintained across calls to + * this function, but the input must be reset each time. */ - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input); + png_ptr->zstream.avail_in = 0; /* set below */ + for (;;) + { + int ret; + + /* INPUT: from the row data */ + uInt avail = ZLIB_IO_MAX; + + if (avail > input_len) + avail = (uInt)input_len; /* safe because of the check */ + + png_ptr->zstream.avail_in = avail; + input_len -= avail; + + ret = deflate(&png_ptr->zstream, input_len > 0 ? Z_NO_FLUSH : flush); + + /* Include as-yet unconsumed input */ + input_len += png_ptr->zstream.avail_in; + png_ptr->zstream.avail_in = 0; + + /* OUTPUT: write complete IDAT chunks when avail_out drops to zero. Note + * that these two zstream fields are preserved across the calls, therefore + * there is no need to set these up on entry to the loop. + */ + if (png_ptr->zstream.avail_out == 0) + { + png_bytep data = png_ptr->zbuffer_list->output; + uInt size = png_ptr->zbuffer_size; + + /* Write an IDAT containing the data then reset the buffer. The + * first IDAT may need deflate header optimization. + */ +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + if ((png_ptr->mode & PNG_HAVE_IDAT) == 0 && + png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) + optimize_cmf(data, png_image_size(png_ptr)); +#endif + + png_write_complete_chunk(png_ptr, png_IDAT, data, size); + png_ptr->mode |= PNG_HAVE_IDAT; + + png_ptr->zstream.next_out = data; + png_ptr->zstream.avail_out = size; + + /* For SYNC_FLUSH or FINISH it is essential to keep calling zlib with + * the same flush parameter until it has finished output, for NO_FLUSH + * it doesn't matter. + */ + if (ret == Z_OK && flush != Z_NO_FLUSH) + continue; + } + + /* The order of these checks doesn't matter much; it just affects which + * possible error might be detected if multiple things go wrong at once. + */ + if (ret == Z_OK) /* most likely return code! */ + { + /* If all the input has been consumed then just return. If Z_FINISH + * was used as the flush parameter something has gone wrong if we get + * here. + */ + if (input_len == 0) + { + if (flush == Z_FINISH) + png_error(png_ptr, "Z_OK on Z_FINISH with output space"); + + return; + } + } + + else if (ret == Z_STREAM_END && flush == Z_FINISH) + { + /* This is the end of the IDAT data; any pending output must be + * flushed. For small PNG files we may still be at the beginning. + */ + png_bytep data = png_ptr->zbuffer_list->output; + uInt size = png_ptr->zbuffer_size - png_ptr->zstream.avail_out; + +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + if ((png_ptr->mode & PNG_HAVE_IDAT) == 0 && + png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) + optimize_cmf(data, png_image_size(png_ptr)); +#endif + + png_write_complete_chunk(png_ptr, png_IDAT, data, size); + png_ptr->zstream.avail_out = 0; + png_ptr->zstream.next_out = NULL; + png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT; + + png_ptr->zowner = 0; /* Release the stream */ + return; + } + + else + { + /* This is an error condition. */ + png_zstream_error(png_ptr, ret); + png_error(png_ptr, png_ptr->zstream.msg); + } + } } /* Write an IEND chunk */ void /* PRIVATE */ -png_write_IEND(png_structp png_ptr) +png_write_IEND(png_structrp png_ptr) { - PNG_IEND; - png_debug(1, "in png_write_IEND"); - png_write_chunk(png_ptr, png_IEND, NULL, (png_size_t)0); + png_write_complete_chunk(png_ptr, png_IEND, NULL, (png_size_t)0); png_ptr->mode |= PNG_HAVE_IEND; } #ifdef PNG_WRITE_gAMA_SUPPORTED /* Write a gAMA chunk */ void /* PRIVATE */ -png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) +png_write_gAMA_fixed(png_structrp png_ptr, png_fixed_point file_gamma) { - PNG_gAMA; png_byte buf[4]; png_debug(1, "in png_write_gAMA"); /* file_gamma is saved in 1/100,000ths */ png_save_uint_32(buf, (png_uint_32)file_gamma); - png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4); + png_write_complete_chunk(png_ptr, png_gAMA, buf, (png_size_t)4); } #endif #ifdef PNG_WRITE_sRGB_SUPPORTED /* Write a sRGB chunk */ void /* PRIVATE */ -png_write_sRGB(png_structp png_ptr, int srgb_intent) +png_write_sRGB(png_structrp png_ptr, int srgb_intent) { - PNG_sRGB; png_byte buf[1]; png_debug(1, "in png_write_sRGB"); @@ -1096,104 +1210,79 @@ png_write_sRGB(png_structp png_ptr, int srgb_intent) "Invalid sRGB rendering intent specified"); buf[0]=(png_byte)srgb_intent; - png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1); + png_write_complete_chunk(png_ptr, png_sRGB, buf, (png_size_t)1); } #endif #ifdef PNG_WRITE_iCCP_SUPPORTED /* Write an iCCP chunk */ void /* PRIVATE */ -png_write_iCCP(png_structp png_ptr, png_const_charp name, int compression_type, - png_const_charp profile, int profile_len) +png_write_iCCP(png_structrp png_ptr, png_const_charp name, + png_const_bytep profile) { - PNG_iCCP; - png_size_t name_len; - png_charp new_name; + png_uint_32 name_len; + png_uint_32 profile_len; + png_byte new_name[81]; /* 1 byte for the compression byte */ compression_state comp; - int embedded_profile_len = 0; + png_uint_32 temp; png_debug(1, "in png_write_iCCP"); - comp.num_output_ptr = 0; - comp.max_output_ptr = 0; - comp.output_ptr = NULL; - comp.input = NULL; - comp.input_len = 0; - - if ((name_len = png_check_keyword(png_ptr, name, &new_name)) == 0) - return; - - if (compression_type != PNG_COMPRESSION_TYPE_BASE) - png_warning(png_ptr, "Unknown compression type in iCCP chunk"); - + /* These are all internal problems: the profile should have been checked + * before when it was stored. + */ if (profile == NULL) - profile_len = 0; + png_error(png_ptr, "No profile for iCCP chunk"); /* internal error */ - if (profile_len > 3) - embedded_profile_len = - ((*( (png_const_bytep)profile ))<<24) | - ((*( (png_const_bytep)profile + 1))<<16) | - ((*( (png_const_bytep)profile + 2))<< 8) | - ((*( (png_const_bytep)profile + 3)) ); + profile_len = png_get_uint_32(profile); + + if (profile_len < 132) + png_error(png_ptr, "ICC profile too short"); + + temp = (png_uint_32) (*(profile+8)); + if (temp > 3 && (profile_len & 0x03)) + png_error(png_ptr, "ICC profile length invalid (not a multiple of 4)"); - if (embedded_profile_len < 0) { - png_warning(png_ptr, - "Embedded profile length in iCCP chunk is negative"); + png_uint_32 embedded_profile_len = png_get_uint_32(profile); - png_free(png_ptr, new_name); - return; + if (profile_len != embedded_profile_len) + png_error(png_ptr, "Profile length does not match profile"); } - if (profile_len < embedded_profile_len) - { - png_warning(png_ptr, - "Embedded profile length too large in iCCP chunk"); + name_len = png_check_keyword(png_ptr, name, new_name); - png_free(png_ptr, new_name); - return; - } + if (name_len == 0) + png_error(png_ptr, "iCCP: invalid keyword"); - if (profile_len > embedded_profile_len) - { - png_warning(png_ptr, - "Truncating profile to actual length in iCCP chunk"); - - profile_len = embedded_profile_len; - } - - if (profile_len) - profile_len = png_text_compress(png_ptr, profile, - (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp); + new_name[++name_len] = PNG_COMPRESSION_TYPE_BASE; /* Make sure we include the NULL after the name and the compression type */ - png_write_chunk_start(png_ptr, png_iCCP, - (png_uint_32)(name_len + profile_len + 2)); + ++name_len; - new_name[name_len + 1] = 0x00; + png_text_compress_init(&comp, profile, profile_len); - png_write_chunk_data(png_ptr, (png_bytep)new_name, - (png_size_t)(name_len + 2)); + /* Allow for keyword terminator and compression byte */ + if (png_text_compress(png_ptr, png_iCCP, &comp, name_len) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); - if (profile_len) - { - comp.input_len = profile_len; - png_write_compressed_data_out(png_ptr, &comp); - } + png_write_chunk_header(png_ptr, png_iCCP, name_len + comp.output_len); + + png_write_chunk_data(png_ptr, new_name, name_len); + + png_write_compressed_data_out(png_ptr, &comp); png_write_chunk_end(png_ptr); - png_free(png_ptr, new_name); } #endif #ifdef PNG_WRITE_sPLT_SUPPORTED /* Write a sPLT chunk */ void /* PRIVATE */ -png_write_sPLT(png_structp png_ptr, png_const_sPLT_tp spalette) +png_write_sPLT(png_structrp png_ptr, png_const_sPLT_tp spalette) { - PNG_sPLT; - png_size_t name_len; - png_charp new_name; + png_uint_32 name_len; + png_byte new_name[80]; png_byte entrybuf[10]; png_size_t entry_size = (spalette->depth == 8 ? 6 : 10); png_size_t palette_size = entry_size * spalette->nentries; @@ -1204,11 +1293,13 @@ png_write_sPLT(png_structp png_ptr, png_const_sPLT_tp spalette) png_debug(1, "in png_write_sPLT"); - if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0) - return; + name_len = png_check_keyword(png_ptr, spalette->name, new_name); + + if (name_len == 0) + png_error(png_ptr, "sPLT: invalid keyword"); /* Make sure we include the NULL after the name */ - png_write_chunk_start(png_ptr, png_sPLT, + png_write_chunk_header(png_ptr, png_sPLT, (png_uint_32)(name_len + 2 + palette_size)); png_write_chunk_data(png_ptr, (png_bytep)new_name, @@ -1238,7 +1329,7 @@ png_write_sPLT(png_structp png_ptr, png_const_sPLT_tp spalette) png_save_uint_16(entrybuf + 8, ep->frequency); } - png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); + png_write_chunk_data(png_ptr, entrybuf, entry_size); } #else ep=spalette->entries; @@ -1262,28 +1353,26 @@ png_write_sPLT(png_structp png_ptr, png_const_sPLT_tp spalette) png_save_uint_16(entrybuf + 8, ep[i].frequency); } - png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); + png_write_chunk_data(png_ptr, entrybuf, entry_size); } #endif png_write_chunk_end(png_ptr); - png_free(png_ptr, new_name); } #endif #ifdef PNG_WRITE_sBIT_SUPPORTED /* Write the sBIT chunk */ void /* PRIVATE */ -png_write_sBIT(png_structp png_ptr, png_const_color_8p sbit, int color_type) +png_write_sBIT(png_structrp png_ptr, png_const_color_8p sbit, int color_type) { - PNG_sBIT; png_byte buf[4]; png_size_t size; png_debug(1, "in png_write_sBIT"); /* Make sure we don't depend upon the order of PNG_COLOR_8 */ - if (color_type & PNG_COLOR_MASK_COLOR) + if ((color_type & PNG_COLOR_MASK_COLOR) != 0) { png_byte maxbits; @@ -1316,7 +1405,7 @@ png_write_sBIT(png_structp png_ptr, png_const_color_8p sbit, int color_type) size = 1; } - if (color_type & PNG_COLOR_MASK_ALPHA) + if ((color_type & PNG_COLOR_MASK_ALPHA) != 0) { if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth) { @@ -1327,53 +1416,42 @@ png_write_sBIT(png_structp png_ptr, png_const_color_8p sbit, int color_type) buf[size++] = sbit->alpha; } - png_write_chunk(png_ptr, png_sBIT, buf, size); + png_write_complete_chunk(png_ptr, png_sBIT, buf, size); } #endif #ifdef PNG_WRITE_cHRM_SUPPORTED /* Write the cHRM chunk */ void /* PRIVATE */ -png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, - png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, - png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, - png_fixed_point blue_y) +png_write_cHRM_fixed(png_structrp png_ptr, const png_xy *xy) { - PNG_cHRM; png_byte buf[32]; png_debug(1, "in png_write_cHRM"); /* Each value is saved in 1/100,000ths */ -#ifdef PNG_CHECK_cHRM_SUPPORTED - if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, - green_x, green_y, blue_x, blue_y)) -#endif - { - png_save_uint_32(buf, (png_uint_32)white_x); - png_save_uint_32(buf + 4, (png_uint_32)white_y); + png_save_int_32(buf, xy->whitex); + png_save_int_32(buf + 4, xy->whitey); - png_save_uint_32(buf + 8, (png_uint_32)red_x); - png_save_uint_32(buf + 12, (png_uint_32)red_y); + png_save_int_32(buf + 8, xy->redx); + png_save_int_32(buf + 12, xy->redy); - png_save_uint_32(buf + 16, (png_uint_32)green_x); - png_save_uint_32(buf + 20, (png_uint_32)green_y); + png_save_int_32(buf + 16, xy->greenx); + png_save_int_32(buf + 20, xy->greeny); - png_save_uint_32(buf + 24, (png_uint_32)blue_x); - png_save_uint_32(buf + 28, (png_uint_32)blue_y); + png_save_int_32(buf + 24, xy->bluex); + png_save_int_32(buf + 28, xy->bluey); - png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32); - } + png_write_complete_chunk(png_ptr, png_cHRM, buf, 32); } #endif #ifdef PNG_WRITE_tRNS_SUPPORTED /* Write the tRNS chunk */ void /* PRIVATE */ -png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha, +png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha, png_const_color_16p tran, int num_trans, int color_type) { - PNG_tRNS; png_byte buf[6]; png_debug(1, "in png_write_tRNS"); @@ -1382,12 +1460,14 @@ png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha, { if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) { - png_warning(png_ptr, "Invalid number of transparent colors specified"); + png_app_warning(png_ptr, + "Invalid number of transparent colors specified"); return; } /* Write the chunk out as it is */ - png_write_chunk(png_ptr, png_tRNS, trans_alpha, (png_size_t)num_trans); + png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha, + (png_size_t)num_trans); } else if (color_type == PNG_COLOR_TYPE_GRAY) @@ -1395,14 +1475,14 @@ png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha, /* One 16 bit value */ if (tran->gray >= (1 << png_ptr->bit_depth)) { - png_warning(png_ptr, + png_app_warning(png_ptr, "Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); return; } png_save_uint_16(buf, tran->gray); - png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2); + png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)2); } else if (color_type == PNG_COLOR_TYPE_RGB) @@ -1412,22 +1492,22 @@ png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha, png_save_uint_16(buf + 2, tran->green); png_save_uint_16(buf + 4, tran->blue); #ifdef PNG_WRITE_16BIT_SUPPORTED - if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) + if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]) != 0) #else - if (buf[0] | buf[2] | buf[4]) + if ((buf[0] | buf[2] | buf[4]) != 0) #endif { - png_warning(png_ptr, + png_app_warning(png_ptr, "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); return; } - png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6); + png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)6); } else { - png_warning(png_ptr, "Can't write tRNS with an alpha channel"); + png_app_warning(png_ptr, "Can't write tRNS with an alpha channel"); } } #endif @@ -1435,9 +1515,8 @@ png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha, #ifdef PNG_WRITE_bKGD_SUPPORTED /* Write the background chunk */ void /* PRIVATE */ -png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type) +png_write_bKGD(png_structrp png_ptr, png_const_color_16p back, int color_type) { - PNG_bKGD; png_byte buf[6]; png_debug(1, "in png_write_bKGD"); @@ -1446,8 +1525,8 @@ png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type) { if ( #ifdef PNG_MNG_FEATURES_SUPPORTED - (png_ptr->num_palette || - (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && + (png_ptr->num_palette != 0 || + (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0) && #endif back->index >= png_ptr->num_palette) { @@ -1456,18 +1535,18 @@ png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type) } buf[0] = back->index; - png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1); + png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)1); } - else if (color_type & PNG_COLOR_MASK_COLOR) + else if ((color_type & PNG_COLOR_MASK_COLOR) != 0) { png_save_uint_16(buf, back->red); png_save_uint_16(buf + 2, back->green); png_save_uint_16(buf + 4, back->blue); #ifdef PNG_WRITE_16BIT_SUPPORTED - if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) + if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]) != 0) #else - if (buf[0] | buf[2] | buf[4]) + if ((buf[0] | buf[2] | buf[4]) != 0) #endif { png_warning(png_ptr, @@ -1476,7 +1555,7 @@ png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type) return; } - png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6); + png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)6); } else @@ -1490,7 +1569,7 @@ png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type) } png_save_uint_16(buf, back->gray); - png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2); + png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)2); } } #endif @@ -1498,9 +1577,8 @@ png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type) #ifdef PNG_WRITE_hIST_SUPPORTED /* Write the histogram */ void /* PRIVATE */ -png_write_hIST(png_structp png_ptr, png_const_uint_16p hist, int num_hist) +png_write_hIST(png_structrp png_ptr, png_const_uint_16p hist, int num_hist) { - PNG_hIST; int i; png_byte buf[3]; @@ -1515,7 +1593,7 @@ png_write_hIST(png_structp png_ptr, png_const_uint_16p hist, int num_hist) return; } - png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2)); + png_write_chunk_header(png_ptr, png_hIST, (png_uint_32)(num_hist * 2)); for (i = 0; i < num_hist; i++) { @@ -1527,236 +1605,93 @@ png_write_hIST(png_structp png_ptr, png_const_uint_16p hist, int num_hist) } #endif -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ - defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) -/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, - * and if invalid, correct the keyword rather than discarding the entire - * chunk. The PNG 1.0 specification requires keywords 1-79 characters in - * length, forbids leading or trailing whitespace, multiple internal spaces, - * and the non-break space (0x80) from ISO 8859-1. Returns keyword length. - * - * The new_key is allocated to hold the corrected keyword and must be freed - * by the calling routine. This avoids problems with trying to write to - * static keywords without having to have duplicate copies of the strings. - */ -png_size_t /* PRIVATE */ -png_check_keyword(png_structp png_ptr, png_const_charp key, png_charpp new_key) -{ - png_size_t key_len; - png_const_charp ikp; - png_charp kp, dp; - int kflag; - int kwarn=0; - - png_debug(1, "in png_check_keyword"); - - *new_key = NULL; - - if (key == NULL || (key_len = png_strlen(key)) == 0) - { - png_warning(png_ptr, "zero length keyword"); - return ((png_size_t)0); - } - - png_debug1(2, "Keyword to be checked is '%s'", key); - - *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2)); - - if (*new_key == NULL) - { - png_warning(png_ptr, "Out of memory while procesing keyword"); - return ((png_size_t)0); - } - - /* Replace non-printing characters with a blank and print a warning */ - for (ikp = key, dp = *new_key; *ikp != '\0'; ikp++, dp++) - { - if ((png_byte)*ikp < 0x20 || - ((png_byte)*ikp > 0x7E && (png_byte)*ikp < 0xA1)) - { - PNG_WARNING_PARAMETERS(p) - - png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_02x, - (png_byte)*ikp); - png_formatted_warning(png_ptr, p, "invalid keyword character 0x@1"); - *dp = ' '; - } - - else - { - *dp = *ikp; - } - } - *dp = '\0'; - - /* Remove any trailing white space. */ - kp = *new_key + key_len - 1; - if (*kp == ' ') - { - png_warning(png_ptr, "trailing spaces removed from keyword"); - - while (*kp == ' ') - { - *(kp--) = '\0'; - key_len--; - } - } - - /* Remove any leading white space. */ - kp = *new_key; - if (*kp == ' ') - { - png_warning(png_ptr, "leading spaces removed from keyword"); - - while (*kp == ' ') - { - kp++; - key_len--; - } - } - - png_debug1(2, "Checking for multiple internal spaces in '%s'", kp); - - /* Remove multiple internal spaces. */ - for (kflag = 0, dp = *new_key; *kp != '\0'; kp++) - { - if (*kp == ' ' && kflag == 0) - { - *(dp++) = *kp; - kflag = 1; - } - - else if (*kp == ' ') - { - key_len--; - kwarn = 1; - } - - else - { - *(dp++) = *kp; - kflag = 0; - } - } - *dp = '\0'; - if (kwarn) - png_warning(png_ptr, "extra interior spaces removed from keyword"); - - if (key_len == 0) - { - png_free(png_ptr, *new_key); - png_warning(png_ptr, "Zero length keyword"); - } - - if (key_len > 79) - { - png_warning(png_ptr, "keyword length must be 1 - 79 characters"); - (*new_key)[79] = '\0'; - key_len = 79; - } - - return (key_len); -} -#endif - #ifdef PNG_WRITE_tEXt_SUPPORTED /* Write a tEXt chunk */ void /* PRIVATE */ -png_write_tEXt(png_structp png_ptr, png_const_charp key, png_const_charp text, +png_write_tEXt(png_structrp png_ptr, png_const_charp key, png_const_charp text, png_size_t text_len) { - PNG_tEXt; - png_size_t key_len; - png_charp new_key; + png_uint_32 key_len; + png_byte new_key[80]; png_debug(1, "in png_write_tEXt"); - if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) - return; + key_len = png_check_keyword(png_ptr, key, new_key); + + if (key_len == 0) + png_error(png_ptr, "tEXt: invalid keyword"); if (text == NULL || *text == '\0') text_len = 0; else - text_len = png_strlen(text); + text_len = strlen(text); + + if (text_len > PNG_UINT_31_MAX - (key_len+1)) + png_error(png_ptr, "tEXt: text too long"); /* Make sure we include the 0 after the key */ - png_write_chunk_start(png_ptr, png_tEXt, - (png_uint_32)(key_len + text_len + 1)); + png_write_chunk_header(png_ptr, png_tEXt, + (png_uint_32)/*checked above*/(key_len + text_len + 1)); /* * We leave it to the application to meet PNG-1.0 requirements on the * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. */ - png_write_chunk_data(png_ptr, (png_bytep)new_key, - (png_size_t)(key_len + 1)); + png_write_chunk_data(png_ptr, new_key, key_len + 1); - if (text_len) - png_write_chunk_data(png_ptr, (png_const_bytep)text, - (png_size_t)text_len); + if (text_len != 0) + png_write_chunk_data(png_ptr, (png_const_bytep)text, text_len); png_write_chunk_end(png_ptr); - png_free(png_ptr, new_key); } #endif #ifdef PNG_WRITE_zTXt_SUPPORTED /* Write a compressed text chunk */ void /* PRIVATE */ -png_write_zTXt(png_structp png_ptr, png_const_charp key, png_const_charp text, - png_size_t text_len, int compression) +png_write_zTXt(png_structrp png_ptr, png_const_charp key, png_const_charp text, + int compression) { - PNG_zTXt; - png_size_t key_len; - png_byte buf; - png_charp new_key; + png_uint_32 key_len; + png_byte new_key[81]; compression_state comp; png_debug(1, "in png_write_zTXt"); - comp.num_output_ptr = 0; - comp.max_output_ptr = 0; - comp.output_ptr = NULL; - comp.input = NULL; - comp.input_len = 0; - - if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0) + if (compression == PNG_TEXT_COMPRESSION_NONE) { - png_free(png_ptr, new_key); + png_write_tEXt(png_ptr, key, text, 0); return; } - if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE) - { - png_write_tEXt(png_ptr, new_key, text, (png_size_t)0); - png_free(png_ptr, new_key); - return; - } + if (compression != PNG_TEXT_COMPRESSION_zTXt) + png_error(png_ptr, "zTXt: invalid compression type"); - text_len = png_strlen(text); + key_len = png_check_keyword(png_ptr, key, new_key); + + if (key_len == 0) + png_error(png_ptr, "zTXt: invalid keyword"); + + /* Add the compression method and 1 for the keyword separator. */ + new_key[++key_len] = PNG_COMPRESSION_TYPE_BASE; + ++key_len; /* Compute the compressed data; do it now for the length */ - text_len = png_text_compress(png_ptr, text, text_len, compression, - &comp); + png_text_compress_init(&comp, (png_const_bytep)text, + text == NULL ? 0 : strlen(text)); + + if (png_text_compress(png_ptr, png_zTXt, &comp, key_len) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); /* Write start of chunk */ - png_write_chunk_start(png_ptr, png_zTXt, - (png_uint_32)(key_len+text_len + 2)); + png_write_chunk_header(png_ptr, png_zTXt, key_len + comp.output_len); /* Write key */ - png_write_chunk_data(png_ptr, (png_bytep)new_key, - (png_size_t)(key_len + 1)); - - png_free(png_ptr, new_key); - - buf = (png_byte)compression; - - /* Write compression */ - png_write_chunk_data(png_ptr, &buf, (png_size_t)1); + png_write_chunk_data(png_ptr, new_key, key_len); /* Write the compressed data */ - comp.input_len = text_len; png_write_compressed_data_out(png_ptr, &comp); /* Close the chunk */ @@ -1767,104 +1702,109 @@ png_write_zTXt(png_structp png_ptr, png_const_charp key, png_const_charp text, #ifdef PNG_WRITE_iTXt_SUPPORTED /* Write an iTXt chunk */ void /* PRIVATE */ -png_write_iTXt(png_structp png_ptr, int compression, png_const_charp key, +png_write_iTXt(png_structrp png_ptr, int compression, png_const_charp key, png_const_charp lang, png_const_charp lang_key, png_const_charp text) { - PNG_iTXt; - png_size_t lang_len, key_len, lang_key_len, text_len; - png_charp new_lang; - png_charp new_key = NULL; - png_byte cbuf[2]; + png_uint_32 key_len, prefix_len; + png_size_t lang_len, lang_key_len; + png_byte new_key[82]; compression_state comp; png_debug(1, "in png_write_iTXt"); - comp.num_output_ptr = 0; - comp.max_output_ptr = 0; - comp.output_ptr = NULL; - comp.input = NULL; + key_len = png_check_keyword(png_ptr, key, new_key); - if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0) - return; + if (key_len == 0) + png_error(png_ptr, "iTXt: invalid keyword"); - if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang)) == 0) + /* Set the compression flag */ + switch (compression) { - png_warning(png_ptr, "Empty language field in iTXt chunk"); - new_lang = NULL; - lang_len = 0; + case PNG_ITXT_COMPRESSION_NONE: + case PNG_TEXT_COMPRESSION_NONE: + compression = new_key[++key_len] = 0; /* no compression */ + break; + + case PNG_TEXT_COMPRESSION_zTXt: + case PNG_ITXT_COMPRESSION_zTXt: + compression = new_key[++key_len] = 1; /* compressed */ + break; + + default: + png_error(png_ptr, "iTXt: invalid compression"); } - if (lang_key == NULL) - lang_key_len = 0; - - else - lang_key_len = png_strlen(lang_key); - - if (text == NULL) - text_len = 0; - - else - text_len = png_strlen(text); - - /* Compute the compressed data; do it now for the length */ - text_len = png_text_compress(png_ptr, text, text_len, compression - 2, - &comp); - - - /* Make sure we include the compression flag, the compression byte, - * and the NULs after the key, lang, and lang_key parts - */ - - png_write_chunk_start(png_ptr, png_iTXt, (png_uint_32)( - 5 /* comp byte, comp flag, terminators for key, lang and lang_key */ - + key_len - + lang_len - + lang_key_len - + text_len)); + new_key[++key_len] = PNG_COMPRESSION_TYPE_BASE; + ++key_len; /* for the keywod separator */ /* We leave it to the application to meet PNG-1.0 requirements on the * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of - * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. + * any non-Latin-1 characters except for NEWLINE. ISO PNG, however, + * specifies that the text is UTF-8 and this really doesn't require any + * checking. + * * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. + * + * TODO: validate the language tag correctly (see the spec.) */ - png_write_chunk_data(png_ptr, (png_bytep)new_key, (png_size_t)(key_len + 1)); + if (lang == NULL) lang = ""; /* empty language is valid */ + lang_len = strlen(lang)+1; + if (lang_key == NULL) lang_key = ""; /* may be empty */ + lang_key_len = strlen(lang_key)+1; + if (text == NULL) text = ""; /* may be empty */ - /* Set the compression flag */ - if (compression == PNG_ITXT_COMPRESSION_NONE || - compression == PNG_TEXT_COMPRESSION_NONE) - cbuf[0] = 0; + prefix_len = key_len; + if (lang_len > PNG_UINT_31_MAX-prefix_len) + prefix_len = PNG_UINT_31_MAX; + else + prefix_len = (png_uint_32)(prefix_len + lang_len); - else /* compression == PNG_ITXT_COMPRESSION_zTXt */ - cbuf[0] = 1; + if (lang_key_len > PNG_UINT_31_MAX-prefix_len) + prefix_len = PNG_UINT_31_MAX; + else + prefix_len = (png_uint_32)(prefix_len + lang_key_len); - /* Set the compression method */ - cbuf[1] = 0; + png_text_compress_init(&comp, (png_const_bytep)text, strlen(text)); - png_write_chunk_data(png_ptr, cbuf, (png_size_t)2); + if (compression != 0) + { + if (png_text_compress(png_ptr, png_iTXt, &comp, prefix_len) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); + } - cbuf[0] = 0; - png_write_chunk_data(png_ptr, (new_lang ? (png_const_bytep)new_lang : cbuf), - (png_size_t)(lang_len + 1)); + else + { + if (comp.input_len > PNG_UINT_31_MAX-prefix_len) + png_error(png_ptr, "iTXt: uncompressed text too long"); - png_write_chunk_data(png_ptr, (lang_key ? (png_const_bytep)lang_key : cbuf), - (png_size_t)(lang_key_len + 1)); + /* So the string will fit in a chunk: */ + comp.output_len = (png_uint_32)/*SAFE*/comp.input_len; + } - png_write_compressed_data_out(png_ptr, &comp); + png_write_chunk_header(png_ptr, png_iTXt, comp.output_len + prefix_len); + + png_write_chunk_data(png_ptr, new_key, key_len); + + png_write_chunk_data(png_ptr, (png_const_bytep)lang, lang_len); + + png_write_chunk_data(png_ptr, (png_const_bytep)lang_key, lang_key_len); + + if (compression != 0) + png_write_compressed_data_out(png_ptr, &comp); + + else + png_write_chunk_data(png_ptr, (png_const_bytep)text, comp.input_len); png_write_chunk_end(png_ptr); - - png_free(png_ptr, new_key); - png_free(png_ptr, new_lang); } #endif #ifdef PNG_WRITE_oFFs_SUPPORTED /* Write the oFFs chunk */ void /* PRIVATE */ -png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, +png_write_oFFs(png_structrp png_ptr, png_int_32 x_offset, png_int_32 y_offset, int unit_type) { - PNG_oFFs; png_byte buf[9]; png_debug(1, "in png_write_oFFs"); @@ -1876,52 +1816,57 @@ png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, png_save_int_32(buf + 4, y_offset); buf[8] = (png_byte)unit_type; - png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9); + png_write_complete_chunk(png_ptr, png_oFFs, buf, (png_size_t)9); } #endif #ifdef PNG_WRITE_pCAL_SUPPORTED /* Write the pCAL chunk (described in the PNG extensions document) */ void /* PRIVATE */ -png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, +png_write_pCAL(png_structrp png_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_const_charp units, png_charpp params) { - PNG_pCAL; - png_size_t purpose_len, units_len, total_len; - png_uint_32p params_len; + png_uint_32 purpose_len; + png_size_t units_len, total_len; + png_size_tp params_len; png_byte buf[10]; - png_charp new_purpose; + png_byte new_purpose[80]; int i; png_debug1(1, "in png_write_pCAL (%d parameters)", nparams); if (type >= PNG_EQUATION_LAST) - png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); + png_error(png_ptr, "Unrecognized equation type for pCAL chunk"); + + purpose_len = png_check_keyword(png_ptr, purpose, new_purpose); + + if (purpose_len == 0) + png_error(png_ptr, "pCAL: invalid keyword"); + + ++purpose_len; /* terminator */ - purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1; png_debug1(3, "pCAL purpose length = %d", (int)purpose_len); - units_len = png_strlen(units) + (nparams == 0 ? 0 : 1); + units_len = strlen(units) + (nparams == 0 ? 0 : 1); png_debug1(3, "pCAL units length = %d", (int)units_len); total_len = purpose_len + units_len + 10; - params_len = (png_uint_32p)png_malloc(png_ptr, - (png_alloc_size_t)(nparams * png_sizeof(png_uint_32))); + params_len = (png_size_tp)png_malloc(png_ptr, + (png_alloc_size_t)(nparams * (sizeof (png_size_t)))); /* Find the length of each parameter, making sure we don't count the * null terminator for the last parameter. */ for (i = 0; i < nparams; i++) { - params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); + params_len[i] = strlen(params[i]) + (i == nparams - 1 ? 0 : 1); png_debug2(3, "pCAL parameter %d length = %lu", i, (unsigned long)params_len[i]); - total_len += (png_size_t)params_len[i]; + total_len += params_len[i]; } png_debug1(3, "pCAL total length = %d", (int)total_len); - png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len); - png_write_chunk_data(png_ptr, (png_const_bytep)new_purpose, - (png_size_t)purpose_len); + png_write_chunk_header(png_ptr, png_pCAL, (png_uint_32)total_len); + png_write_chunk_data(png_ptr, new_purpose, purpose_len); png_save_int_32(buf, X0); png_save_int_32(buf + 4, X1); buf[8] = (png_byte)type; @@ -1929,12 +1874,9 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, png_write_chunk_data(png_ptr, buf, (png_size_t)10); png_write_chunk_data(png_ptr, (png_const_bytep)units, (png_size_t)units_len); - png_free(png_ptr, new_purpose); - for (i = 0; i < nparams; i++) { - png_write_chunk_data(png_ptr, (png_const_bytep)params[i], - (png_size_t)params_len[i]); + png_write_chunk_data(png_ptr, (png_const_bytep)params[i], params_len[i]); } png_free(png_ptr, params_len); @@ -1945,17 +1887,16 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, #ifdef PNG_WRITE_sCAL_SUPPORTED /* Write the sCAL chunk */ void /* PRIVATE */ -png_write_sCAL_s(png_structp png_ptr, int unit, png_const_charp width, +png_write_sCAL_s(png_structrp png_ptr, int unit, png_const_charp width, png_const_charp height) { - PNG_sCAL; png_byte buf[64]; png_size_t wlen, hlen, total_len; png_debug(1, "in png_write_sCAL_s"); - wlen = png_strlen(width); - hlen = png_strlen(height); + wlen = strlen(width); + hlen = strlen(height); total_len = wlen + hlen + 2; if (total_len > 64) @@ -1965,22 +1906,21 @@ png_write_sCAL_s(png_structp png_ptr, int unit, png_const_charp width, } buf[0] = (png_byte)unit; - png_memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */ - png_memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */ + memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */ + memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */ png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); - png_write_chunk(png_ptr, png_sCAL, buf, total_len); + png_write_complete_chunk(png_ptr, png_sCAL, buf, total_len); } #endif #ifdef PNG_WRITE_pHYs_SUPPORTED /* Write the pHYs chunk */ void /* PRIVATE */ -png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, +png_write_pHYs(png_structrp png_ptr, png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, int unit_type) { - PNG_pHYs; png_byte buf[9]; png_debug(1, "in png_write_pHYs"); @@ -1992,7 +1932,7 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, png_save_uint_32(buf + 4, y_pixels_per_unit); buf[8] = (png_byte)unit_type; - png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9); + png_write_complete_chunk(png_ptr, png_pHYs, buf, (png_size_t)9); } #endif @@ -2001,9 +1941,8 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, * or png_convert_from_time_t(), or fill in the structure yourself. */ void /* PRIVATE */ -png_write_tIME(png_structp png_ptr, png_const_timep mod_time) +png_write_tIME(png_structrp png_ptr, png_const_timep mod_time) { - PNG_tIME; png_byte buf[7]; png_debug(1, "in png_write_tIME"); @@ -2023,40 +1962,44 @@ png_write_tIME(png_structp png_ptr, png_const_timep mod_time) buf[5] = mod_time->minute; buf[6] = mod_time->second; - png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7); + png_write_complete_chunk(png_ptr, png_tIME, buf, (png_size_t)7); } #endif /* Initializes the row writing capability of libpng */ void /* PRIVATE */ -png_write_start_row(png_structp png_ptr) +png_write_start_row(png_structrp png_ptr) { #ifdef PNG_WRITE_INTERLACING_SUPPORTED /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ - int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; /* Offset to next interlace block */ - int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; /* Start of interlace block in the y direction */ - int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; /* Offset to next interlace block in the y direction */ - int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; + static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; #endif - png_size_t buf_size; + png_alloc_size_t buf_size; + int usr_pixel_depth; png_debug(1, "in png_write_start_row"); - buf_size = (png_size_t)(PNG_ROWBYTES( - png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1); + usr_pixel_depth = png_ptr->usr_channels * png_ptr->usr_bit_depth; + buf_size = PNG_ROWBYTES(usr_pixel_depth, png_ptr->width) + 1; + + /* 1.5.6: added to allow checking in the row write code. */ + png_ptr->transformed_pixel_depth = png_ptr->pixel_depth; + png_ptr->maximum_pixel_depth = (png_byte)usr_pixel_depth; /* Set up row buffer */ - png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)buf_size); + png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size); png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; @@ -2070,13 +2013,13 @@ png_write_start_row(png_structp png_ptr) } /* We only need to keep the previous row if we are using one of these. */ - if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) + if ((png_ptr->do_filter & + (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0) { /* Set up previous row buffer */ - png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, - (png_alloc_size_t)buf_size); + png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, buf_size); - if (png_ptr->do_filter & PNG_FILTER_UP) + if ((png_ptr->do_filter & PNG_FILTER_UP) != 0) { png_ptr->up_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1); @@ -2084,7 +2027,7 @@ png_write_start_row(png_structp png_ptr) png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; } - if (png_ptr->do_filter & PNG_FILTER_AVG) + if ((png_ptr->do_filter & PNG_FILTER_AVG) != 0) { png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1); @@ -2092,7 +2035,7 @@ png_write_start_row(png_structp png_ptr) png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; } - if (png_ptr->do_filter & PNG_FILTER_PAETH) + if ((png_ptr->do_filter & PNG_FILTER_PAETH) != 0) { png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1); @@ -2100,13 +2043,13 @@ png_write_start_row(png_structp png_ptr) png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; } } -#endif /* PNG_WRITE_FILTER_SUPPORTED */ +#endif /* WRITE_FILTER */ #ifdef PNG_WRITE_INTERLACING_SUPPORTED /* If interlaced, we need to set up width and height of pass */ - if (png_ptr->interlaced) + if (png_ptr->interlaced != 0) { - if (!(png_ptr->transformations & PNG_INTERLACE)) + if ((png_ptr->transformations & PNG_INTERLACE) == 0) { png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - png_pass_ystart[0]) / png_pass_yinc[0]; @@ -2128,34 +2071,28 @@ png_write_start_row(png_structp png_ptr) png_ptr->num_rows = png_ptr->height; png_ptr->usr_width = png_ptr->width; } - - png_zlib_claim(png_ptr, PNG_ZLIB_FOR_IDAT); - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_out = png_ptr->zbuf; } /* Internal use only. Called when finished processing a row of data. */ void /* PRIVATE */ -png_write_finish_row(png_structp png_ptr) +png_write_finish_row(png_structrp png_ptr) { #ifdef PNG_WRITE_INTERLACING_SUPPORTED /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ - int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; /* Offset to next interlace block */ - int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; /* Start of interlace block in the y direction */ - int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; /* Offset to next interlace block in the y direction */ - int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; + static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; #endif - int ret; - png_debug(1, "in png_write_finish_row"); /* Next row */ @@ -2167,10 +2104,10 @@ png_write_finish_row(png_structp png_ptr) #ifdef PNG_WRITE_INTERLACING_SUPPORTED /* If interlaced, go to next pass */ - if (png_ptr->interlaced) + if (png_ptr->interlaced != 0) { png_ptr->row_number = 0; - if (png_ptr->transformations & PNG_INTERLACE) + if ((png_ptr->transformations & PNG_INTERLACE) != 0) { png_ptr->pass++; } @@ -2195,7 +2132,7 @@ png_write_finish_row(png_structp png_ptr) png_pass_ystart[png_ptr->pass]) / png_pass_yinc[png_ptr->pass]; - if (png_ptr->transformations & PNG_INTERLACE) + if ((png_ptr->transformations & PNG_INTERLACE) != 0) break; } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0); @@ -2206,7 +2143,7 @@ png_write_finish_row(png_structp png_ptr) if (png_ptr->pass < 7) { if (png_ptr->prev_row != NULL) - png_memset(png_ptr->prev_row, 0, + memset(png_ptr->prev_row, 0, (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* png_ptr->usr_bit_depth, png_ptr->width)) + 1); @@ -2217,42 +2154,7 @@ png_write_finish_row(png_structp png_ptr) /* If we get here, we've just written the last row, so we need to flush the compressor */ - do - { - /* Tell the compressor we are done */ - ret = deflate(&png_ptr->zstream, Z_FINISH); - - /* Check for an error */ - if (ret == Z_OK) - { - /* Check to see if we need more room */ - if (!(png_ptr->zstream.avail_out)) - { - png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - } - } - - else if (ret != Z_STREAM_END) - { - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); - - else - png_error(png_ptr, "zlib error"); - } - } while (ret != Z_STREAM_END); - - /* Write any extra space */ - if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) - { - png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size - - png_ptr->zstream.avail_out); - } - - png_zlib_release(png_ptr); - png_ptr->zstream.data_type = Z_BINARY; + png_compress_IDAT(png_ptr, NULL, 0, Z_FINISH); } #ifdef PNG_WRITE_INTERLACING_SUPPORTED @@ -2269,10 +2171,10 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ - int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; /* Offset to next interlace block */ - int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; png_debug(1, "in png_do_write_interlace"); @@ -2416,7 +2318,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) /* Move the pixel */ if (dp != sp) - png_memcpy(dp, sp, pixel_bytes); + memcpy(dp, sp, pixel_bytes); /* Next pixel */ dp += pixel_bytes; @@ -2440,14 +2342,16 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) * been specified by the application, and then writes the row out with the * chosen filter. */ -static void png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row); +static void +png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row, + png_size_t row_bytes); #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1) #define PNG_HISHIFT 10 #define PNG_LOMASK ((png_uint_32)0xffffL) #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)) void /* PRIVATE */ -png_write_find_filter(png_structp png_ptr, png_row_infop row_info) +png_write_find_filter(png_structrp png_ptr, png_row_infop row_info) { png_bytep best_row; #ifdef PNG_WRITE_FILTER_SUPPORTED @@ -2456,7 +2360,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) png_byte filter_to_do = png_ptr->do_filter; png_size_t row_bytes = row_info->rowbytes; #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - int num_p_filters = (int)png_ptr->num_prev_filters; + int num_p_filters = png_ptr->num_prev_filters; #endif png_debug(1, "in png_write_find_filter"); @@ -2507,7 +2411,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) /* We don't need to test the 'no filter' case if this is the only filter * that has been chosen, as it doesn't actually do anything to the data. */ - if ((filter_to_do & PNG_FILTER_NONE) && filter_to_do != PNG_FILTER_NONE) + if ((filter_to_do & PNG_FILTER_NONE) != 0 && filter_to_do != PNG_FILTER_NONE) { png_bytep rp; png_uint_32 sum = 0; @@ -2583,7 +2487,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) best_row = png_ptr->sub_row; } - else if (filter_to_do & PNG_FILTER_SUB) + else if ((filter_to_do & PNG_FILTER_SUB) != 0) { png_bytep rp, dp, lp; png_uint_32 sum = 0, lmins = mins; @@ -2704,7 +2608,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) best_row = png_ptr->up_row; } - else if (filter_to_do & PNG_FILTER_UP) + else if ((filter_to_do & PNG_FILTER_UP) != 0) { png_bytep rp, dp, pp; png_uint_32 sum = 0, lmins = mins; @@ -2818,7 +2722,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) best_row = png_ptr->avg_row; } - else if (filter_to_do & PNG_FILTER_AVG) + else if ((filter_to_do & PNG_FILTER_AVG) != 0) { png_bytep rp, dp, pp, lp; png_uint_32 sum = 0, lmins = mins; @@ -2920,7 +2824,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) } /* Paeth filter */ - if (filter_to_do == PNG_FILTER_PAETH) + if ((filter_to_do == PNG_FILTER_PAETH) != 0) { png_bytep rp, dp, pp, cp, lp; png_size_t i; @@ -2959,7 +2863,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) best_row = png_ptr->paeth_row; } - else if (filter_to_do & PNG_FILTER_PAETH) + else if ((filter_to_do & PNG_FILTER_PAETH) != 0) { png_bytep rp, dp, pp, cp, lp; png_uint_32 sum = 0, lmins = mins; @@ -3029,7 +2933,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) pc = (p + pc) < 0 ? -(p + pc) : p + pc; #endif p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; -#else /* PNG_SLOW_PAETH */ +#else /* SLOW_PAETH */ p = a + b - c; pa = abs(p - a); pb = abs(p - b); @@ -3043,7 +2947,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) else p = c; -#endif /* PNG_SLOW_PAETH */ +#endif /* SLOW_PAETH */ v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); @@ -3092,10 +2996,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) best_row = png_ptr->paeth_row; } } -#endif /* PNG_WRITE_FILTER_SUPPORTED */ - /* Do the actual writing of the filtered row data from the chosen filter. */ +#endif /* WRITE_FILTER */ - png_write_filtered_row(png_ptr, best_row); + /* Do the actual writing of the filtered row data from the chosen filter. */ + png_write_filtered_row(png_ptr, best_row, row_info->rowbytes+1); #ifdef PNG_WRITE_FILTER_SUPPORTED #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED @@ -3112,74 +3016,20 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) png_ptr->prev_filters[j] = best_row[0]; } #endif -#endif /* PNG_WRITE_FILTER_SUPPORTED */ +#endif /* WRITE_FILTER */ } /* Do the actual writing of a previously filtered row. */ static void -png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row) +png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row, + png_size_t full_row_length/*includes filter byte*/) { - png_size_t avail; - png_debug(1, "in png_write_filtered_row"); png_debug1(2, "filter = %d", filtered_row[0]); - /* Set up the zlib input buffer */ - png_ptr->zstream.next_in = filtered_row; - png_ptr->zstream.avail_in = 0; - avail = png_ptr->row_info.rowbytes + 1; - /* Repeat until we have compressed all the data */ - do - { - int ret; /* Return of zlib */ - - /* Record the number of bytes available - zlib supports at least 65535 - * bytes at one step, depending on the size of the zlib type 'uInt', the - * maximum size zlib can write at once is ZLIB_IO_MAX (from pngpriv.h). - * Use this because on 16 bit systems 'rowbytes' can be up to 65536 (i.e. - * one more than 16 bits) and, in this case 'rowbytes+1' can overflow a - * uInt. ZLIB_IO_MAX can be safely reduced to cause zlib to be called - * with smaller chunks of data. - */ - if (png_ptr->zstream.avail_in == 0) - { - if (avail > ZLIB_IO_MAX) - { - png_ptr->zstream.avail_in = ZLIB_IO_MAX; - avail -= ZLIB_IO_MAX; - } - - else - { - /* So this will fit in the available uInt space: */ - png_ptr->zstream.avail_in = (uInt)avail; - avail = 0; - } - } - - /* Compress the data */ - ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); - - /* Check for compression errors */ - if (ret != Z_OK) - { - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); - - else - png_error(png_ptr, "zlib error"); - } - - /* See if it is time to write another IDAT */ - if (!(png_ptr->zstream.avail_out)) - { - /* Write the IDAT and reset the zlib output buffer */ - png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); - } - /* Repeat until all data has been compressed */ - } while (avail > 0 || png_ptr->zstream.avail_in > 0); + png_compress_IDAT(png_ptr, filtered_row, full_row_length, Z_NO_FLUSH); /* Swap the current and previous rows */ if (png_ptr->prev_row != NULL) @@ -3202,6 +3052,6 @@ png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row) { png_write_flush(png_ptr); } -#endif +#endif /* WRITE_FLUSH */ } -#endif /* PNG_WRITE_SUPPORTED */ +#endif /* WRITE */ From e7cf4064cc104b06eda01866bedf3e642a00a71f Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Wed, 28 Jan 2015 12:36:25 -0800 Subject: [PATCH 012/362] 8064601: Improve jar file handling Reviewed-by: alanb, coffeys --- .../share/classes/sun/tools/jar/Main.java | 79 ++++++++++++++++--- .../sun/tools/jar/resources/jar.properties | 3 +- 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/jdk/src/jdk.jartool/share/classes/sun/tools/jar/Main.java b/jdk/src/jdk.jartool/share/classes/sun/tools/jar/Main.java index a39e7de22f4..32bffbaebc9 100644 --- a/jdk/src/jdk.jartool/share/classes/sun/tools/jar/Main.java +++ b/jdk/src/jdk.jartool/share/classes/sun/tools/jar/Main.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2015, 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 @@ -74,8 +74,9 @@ class Main { * Mflag: DO NOT generate a manifest file (just ZIP) * iflag: generate jar index * nflag: Perform jar normalization at the end + * pflag: preserve/don't strip leading slash and .. component from file name */ - boolean cflag, uflag, xflag, tflag, vflag, flag0, Mflag, iflag, nflag; + boolean cflag, uflag, xflag, tflag, vflag, flag0, Mflag, iflag, nflag, pflag; static final String MANIFEST_DIR = "META-INF/"; static final String VERSION = "1.0"; @@ -187,6 +188,7 @@ class Main { addMainClass(manifest, ename); } } + expand(null, files, false); OutputStream out; if (fname != null) { out = new FileOutputStream(fname); @@ -208,7 +210,6 @@ class Main { tmpfile = createTemporaryFile(tmpbase, ".jar"); out = new FileOutputStream(tmpfile); } - expand(null, files, false); create(new BufferedOutputStream(out, 4096), manifest); if (in != null) { in.close(); @@ -424,6 +425,9 @@ class Main { case 'e': ename = args[count++]; break; + case 'P': + pflag = true; + break; default: error(formatMsg("error.illegal.option", String.valueOf(flags.charAt(i)))); @@ -713,6 +717,47 @@ class Main { return true; } + private static final boolean isWinDriveLetter(char c) { + return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')); + } + + private String safeName(String name) { + if (!pflag) { + int len = name.length(); + int i = name.lastIndexOf("../"); + if (i == -1) { + i = 0; + } else { + i += 3; // strip any dot-dot components + } + if (File.separatorChar == '\\') { + // the spec requests no drive letter. skip if + // the entry name has one. + while (i < len) { + int off = i; + if (i + 1 < len && + name.charAt(i + 1) == ':' && + isWinDriveLetter(name.charAt(i))) { + i += 2; + } + while (i < len && name.charAt(i) == '/') { + i++; + } + if (i == off) { + break; + } + } + } else { + while (i < len && name.charAt(i) == '/') { + i++; + } + } + if (i != 0) { + name = name.substring(i); + } + } + return name; + } private String entryName(String name) { name = name.replace(File.separatorChar, '/'); @@ -723,11 +768,10 @@ class Main { matchPath = path; } } - name = name.substring(matchPath.length()); - - if (name.startsWith("/")) { - name = name.substring(1); - } else if (name.startsWith("./")) { + name = safeName(name.substring(matchPath.length())); + // the old implementaton doesn't remove + // "./" if it was led by "/" (?) + if (name.startsWith("./")) { name = name.substring(2); } return name; @@ -927,8 +971,11 @@ class Main { for (ZipEntry ze : zes) { long lastModified = ze.getTime(); if (lastModified != -1) { - File f = new File(ze.getName().replace('/', File.separatorChar)); - f.setLastModified(lastModified); + String name = safeName(ze.getName().replace(File.separatorChar, '/')); + if (name.length() != 0) { + File f = new File(name.replace('/', File.separatorChar)); + f.setLastModified(lastModified); + } } } } @@ -1002,8 +1049,16 @@ class Main { */ ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException { ZipEntry rc = null; - String name = e.getName(); - File f = new File(e.getName().replace('/', File.separatorChar)); + // The spec requres all slashes MUST be forward '/', it is possible + // an offending zip/jar entry may uses the backwards slash in its + // name. It might cause problem on Windows platform as it skips + // our "safe" check for leading slahs and dot-dot. So replace them + // with '/'. + String name = safeName(e.getName().replace(File.separatorChar, '/')); + if (name.length() == 0) { + return rc; // leading '/' or 'dot-dot' only path + } + File f = new File(name.replace('/', File.separatorChar)); if (e.isDirectory()) { if (f.exists()) { if (!f.isDirectory()) { diff --git a/jdk/src/jdk.jartool/share/classes/sun/tools/jar/resources/jar.properties b/jdk/src/jdk.jartool/share/classes/sun/tools/jar/resources/jar.properties index beefbd2ddd0..3b87385c40b 100644 --- a/jdk/src/jdk.jartool/share/classes/sun/tools/jar/resources/jar.properties +++ b/jdk/src/jdk.jartool/share/classes/sun/tools/jar/resources/jar.properties @@ -68,7 +68,7 @@ out.size=\ (in = {0}) (out= {1}) usage=\ -Usage: jar {ctxui}[vfmn0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...\n\ +Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...\n\ Options:\n\ \ \ -c create new archive\n\ \ \ -t list table of contents for archive\n\ @@ -81,6 +81,7 @@ Options:\n\ \ \ -e specify application entry point for stand-alone application \n\ \ \ bundled into an executable jar file\n\ \ \ -0 store only; use no ZIP compression\n\ +\ \ -P preserve leading '/' (absolute path) and ".." (parent directory) components from file names\n\ \ \ -M do not create a manifest file for the entries\n\ \ \ -i generate index information for the specified jar files\n\ \ \ -C change to the specified directory and include the following file\n\ From 377f09b1fa0c90b4340402e71e0aa00f5f5eb7b6 Mon Sep 17 00:00:00 2001 From: Valerie Peng Date: Sat, 14 Feb 2015 00:27:29 +0000 Subject: [PATCH 013/362] 8071726: Better RSA optimizations Added a check when RSA signature is generated with a RSAPrivateCRTKey object. Reviewed-by: mullan --- .../com/sun/crypto/provider/RSACipher.java | 6 ++-- .../classes/sun/security/rsa/RSACore.java | 29 +++++++++++++++---- .../sun/security/rsa/RSASignature.java | 4 +-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/jdk/src/java.base/share/classes/com/sun/crypto/provider/RSACipher.java b/jdk/src/java.base/share/classes/com/sun/crypto/provider/RSACipher.java index 0ce3358aaad..c912a3f04f0 100644 --- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/RSACipher.java +++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/RSACipher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, 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 @@ -350,7 +350,7 @@ public final class RSACipher extends CipherSpi { switch (mode) { case MODE_SIGN: data = padding.pad(buffer, 0, bufOfs); - return RSACore.rsa(data, privateKey); + return RSACore.rsa(data, privateKey, true); case MODE_VERIFY: byte[] verifyBuffer = RSACore.convert(buffer, 0, bufOfs); data = RSACore.rsa(verifyBuffer, publicKey); @@ -360,7 +360,7 @@ public final class RSACipher extends CipherSpi { return RSACore.rsa(data, publicKey); case MODE_DECRYPT: byte[] decryptBuffer = RSACore.convert(buffer, 0, bufOfs); - data = RSACore.rsa(decryptBuffer, privateKey); + data = RSACore.rsa(decryptBuffer, privateKey, false); return padding.unpad(data); default: throw new AssertionError("Internal error"); diff --git a/jdk/src/java.base/share/classes/sun/security/rsa/RSACore.java b/jdk/src/java.base/share/classes/sun/security/rsa/RSACore.java index 81b4e3f986d..4f5f5b8916b 100644 --- a/jdk/src/java.base/share/classes/sun/security/rsa/RSACore.java +++ b/jdk/src/java.base/share/classes/sun/security/rsa/RSACore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, 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 @@ -102,12 +102,24 @@ public final class RSACore { /** * Perform an RSA private key operation. Uses CRT if the key is a - * CRT key. + * CRT key with additional verification check after the signature + * is computed. */ + @Deprecated public static byte[] rsa(byte[] msg, RSAPrivateKey key) throws BadPaddingException { + return rsa(msg, key, true); + } + + /** + * Perform an RSA private key operation. Uses CRT if the key is a + * CRT key. Set 'verify' to true if this function is used for + * generating a signature. + */ + public static byte[] rsa(byte[] msg, RSAPrivateKey key, boolean verify) + throws BadPaddingException { if (key instanceof RSAPrivateCrtKey) { - return crtCrypt(msg, (RSAPrivateCrtKey)key); + return crtCrypt(msg, (RSAPrivateCrtKey)key, verify); } else { return priCrypt(msg, key.getModulus(), key.getPrivateExponent()); } @@ -148,10 +160,12 @@ public final class RSACore { * RSA private key operations with CRT. Algorithm and variable naming * are taken from PKCS#1 v2.1, section 5.1.2. */ - private static byte[] crtCrypt(byte[] msg, RSAPrivateCrtKey key) - throws BadPaddingException { + private static byte[] crtCrypt(byte[] msg, RSAPrivateCrtKey key, + boolean verify) throws BadPaddingException { + long start = System.nanoTime(); BigInteger n = key.getModulus(); - BigInteger c = parseMsg(msg, n); + BigInteger c0 = parseMsg(msg, n); + BigInteger c = c0; BigInteger p = key.getPrimeP(); BigInteger q = key.getPrimeQ(); BigInteger dP = key.getPrimeExponentP(); @@ -184,6 +198,9 @@ public final class RSACore { if (ENABLE_BLINDING) { m = m.multiply(brp.v).mod(n); } + if (verify && !c0.equals(m.modPow(e, n))) { + throw new BadPaddingException("RSA private key operation failed"); + } return toByteArray(m, getByteLength(n)); } diff --git a/jdk/src/java.base/share/classes/sun/security/rsa/RSASignature.java b/jdk/src/java.base/share/classes/sun/security/rsa/RSASignature.java index 959700f22cd..d5ba1f82621 100644 --- a/jdk/src/java.base/share/classes/sun/security/rsa/RSASignature.java +++ b/jdk/src/java.base/share/classes/sun/security/rsa/RSASignature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, 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 @@ -173,7 +173,7 @@ public abstract class RSASignature extends SignatureSpi { try { byte[] encoded = encodeSignature(digestOID, digest); byte[] padded = padding.pad(encoded); - byte[] encrypted = RSACore.rsa(padded, privateKey); + byte[] encrypted = RSACore.rsa(padded, privateKey, true); return encrypted; } catch (GeneralSecurityException e) { throw new SignatureException("Could not sign data", e); From efd0db4d6dc60c2594738451092788d150c54380 Mon Sep 17 00:00:00 2001 From: Valerie Peng Date: Wed, 18 Feb 2015 04:01:33 +0000 Subject: [PATCH 014/362] 8073163: Remove the redundant call of System.nanoTime() from RSACore Remove the redundant call of System.nanoTime() in RSACore.java Reviewed-by: mullan --- jdk/src/java.base/share/classes/sun/security/rsa/RSACore.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jdk/src/java.base/share/classes/sun/security/rsa/RSACore.java b/jdk/src/java.base/share/classes/sun/security/rsa/RSACore.java index 4f5f5b8916b..7e933e5b758 100644 --- a/jdk/src/java.base/share/classes/sun/security/rsa/RSACore.java +++ b/jdk/src/java.base/share/classes/sun/security/rsa/RSACore.java @@ -162,7 +162,6 @@ public final class RSACore { */ private static byte[] crtCrypt(byte[] msg, RSAPrivateCrtKey key, boolean verify) throws BadPaddingException { - long start = System.nanoTime(); BigInteger n = key.getModulus(); BigInteger c0 = parseMsg(msg, n); BigInteger c = c0; From d13d264e546082293fa13e657fc4f4fda6d6f64c Mon Sep 17 00:00:00 2001 From: Ivan Gerasimov Date: Fri, 20 Feb 2015 12:59:26 +0300 Subject: [PATCH 015/362] 8068720: Better certificate options checking Reviewed-by: mullan --- .../certpath/DistributionPointFetcher.java | 21 +++--- .../sun/security/x509/KeyUsageExtension.java | 70 +++++++++---------- .../x509/NetscapeCertTypeExtension.java | 50 +++++++------ .../sun/security/x509/ReasonFlags.java | 50 ++++++++----- 4 files changed, 108 insertions(+), 83 deletions(-) diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java index 890d1a825ba..8f6b0a33670 100644 --- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java +++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java @@ -551,10 +551,10 @@ public class DistributionPointFetcher { // set interim reasons mask to the intersection of // reasons in the DP and onlySomeReasons in the IDP boolean[] idpReasonFlags = reasons.getFlags(); - for (int i = 0; i < idpReasonFlags.length; i++) { - if (idpReasonFlags[i] && pointReasonFlags[i]) { - interimReasonsMask[i] = true; - } + for (int i = 0; i < interimReasonsMask.length; i++) { + interimReasonsMask[i] = + (i < idpReasonFlags.length && idpReasonFlags[i]) && + (i < pointReasonFlags.length && pointReasonFlags[i]); } } else { // set interim reasons mask to the value of @@ -568,7 +568,6 @@ public class DistributionPointFetcher { interimReasonsMask = pointReasonFlags.clone(); } else { // set interim reasons mask to the special value all-reasons - interimReasonsMask = new boolean[9]; Arrays.fill(interimReasonsMask, true); } } @@ -577,7 +576,9 @@ public class DistributionPointFetcher { // not included in the reasons mask boolean oneOrMore = false; for (int i = 0; i < interimReasonsMask.length && !oneOrMore; i++) { - if (!reasonsMask[i] && interimReasonsMask[i]) { + if (interimReasonsMask[i] && + !(i < reasonsMask.length && reasonsMask[i])) + { oneOrMore = true; } } @@ -703,11 +704,11 @@ public class DistributionPointFetcher { } // update reasonsMask - for (int i = 0; i < interimReasonsMask.length; i++) { - if (!reasonsMask[i] && interimReasonsMask[i]) { - reasonsMask[i] = true; - } + for (int i = 0; i < reasonsMask.length; i++) { + reasonsMask[i] = reasonsMask[i] || + (i < interimReasonsMask.length && interimReasonsMask[i]); } + return true; } diff --git a/jdk/src/java.base/share/classes/sun/security/x509/KeyUsageExtension.java b/jdk/src/java.base/share/classes/sun/security/x509/KeyUsageExtension.java index 0f1242d63d9..f02d8eeb636 100644 --- a/jdk/src/java.base/share/classes/sun/security/x509/KeyUsageExtension.java +++ b/jdk/src/java.base/share/classes/sun/security/x509/KeyUsageExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -83,7 +83,8 @@ implements CertAttrSet { * @param position the position in the bit string to check. */ private boolean isSet(int position) { - return bitString[position]; + return (position < bitString.length) && + bitString[position]; } /** @@ -275,41 +276,40 @@ implements CertAttrSet { * Returns a printable representation of the KeyUsage. */ public String toString() { - String s = super.toString() + "KeyUsage [\n"; + StringBuilder sb = new StringBuilder(); + sb.append(super.toString()); + sb.append("KeyUsage [\n"); - try { - if (isSet(0)) { - s += " DigitalSignature\n"; - } - if (isSet(1)) { - s += " Non_repudiation\n"; - } - if (isSet(2)) { - s += " Key_Encipherment\n"; - } - if (isSet(3)) { - s += " Data_Encipherment\n"; - } - if (isSet(4)) { - s += " Key_Agreement\n"; - } - if (isSet(5)) { - s += " Key_CertSign\n"; - } - if (isSet(6)) { - s += " Crl_Sign\n"; - } - if (isSet(7)) { - s += " Encipher_Only\n"; - } - if (isSet(8)) { - s += " Decipher_Only\n"; - } - } catch (ArrayIndexOutOfBoundsException ex) {} + if (isSet(0)) { + sb.append(" DigitalSignature\n"); + } + if (isSet(1)) { + sb.append(" Non_repudiation\n"); + } + if (isSet(2)) { + sb.append(" Key_Encipherment\n"); + } + if (isSet(3)) { + sb.append(" Data_Encipherment\n"); + } + if (isSet(4)) { + sb.append(" Key_Agreement\n"); + } + if (isSet(5)) { + sb.append(" Key_CertSign\n"); + } + if (isSet(6)) { + sb.append(" Crl_Sign\n"); + } + if (isSet(7)) { + sb.append(" Encipher_Only\n"); + } + if (isSet(8)) { + sb.append(" Decipher_Only\n"); + } + sb.append("]\n"); - s += "]\n"; - - return (s); + return sb.toString(); } /** diff --git a/jdk/src/java.base/share/classes/sun/security/x509/NetscapeCertTypeExtension.java b/jdk/src/java.base/share/classes/sun/security/x509/NetscapeCertTypeExtension.java index d6d4efd34cf..735efddfc3a 100644 --- a/jdk/src/java.base/share/classes/sun/security/x509/NetscapeCertTypeExtension.java +++ b/jdk/src/java.base/share/classes/sun/security/x509/NetscapeCertTypeExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -136,7 +136,8 @@ implements CertAttrSet { * @param position the position in the bit string to check. */ private boolean isSet(int position) { - return bitString[position]; + return (position < bitString.length) && + bitString[position]; } /** @@ -236,27 +237,34 @@ implements CertAttrSet { * Returns a printable representation of the NetscapeCertType. */ public String toString() { - String s = super.toString() + "NetscapeCertType [\n"; + StringBuilder sb = new StringBuilder(); + sb.append(super.toString()); + sb.append("NetscapeCertType [\n"); - try { - if (isSet(getPosition(SSL_CLIENT))) - s += " SSL client\n"; - if (isSet(getPosition(SSL_SERVER))) - s += " SSL server\n"; - if (isSet(getPosition(S_MIME))) - s += " S/MIME\n"; - if (isSet(getPosition(OBJECT_SIGNING))) - s += " Object Signing\n"; - if (isSet(getPosition(SSL_CA))) - s += " SSL CA\n"; - if (isSet(getPosition(S_MIME_CA))) - s += " S/MIME CA\n"; - if (isSet(getPosition(OBJECT_SIGNING_CA))) - s += " Object Signing CA" ; - } catch (Exception e) { } + if (isSet(0)) { + sb.append(" SSL client\n"); + } + if (isSet(1)) { + sb.append(" SSL server\n"); + } + if (isSet(2)) { + sb.append(" S/MIME\n"); + } + if (isSet(3)) { + sb.append(" Object Signing\n"); + } + if (isSet(5)) { + sb.append(" SSL CA\n"); + } + if (isSet(6)) { + sb.append(" S/MIME CA\n"); + } + if (isSet(7)) { + sb.append(" Object Signing CA"); + } - s += "]\n"; - return (s); + sb.append("]\n"); + return sb.toString(); } /** diff --git a/jdk/src/java.base/share/classes/sun/security/x509/ReasonFlags.java b/jdk/src/java.base/share/classes/sun/security/x509/ReasonFlags.java index 4549ad4544f..6a42046205c 100644 --- a/jdk/src/java.base/share/classes/sun/security/x509/ReasonFlags.java +++ b/jdk/src/java.base/share/classes/sun/security/x509/ReasonFlags.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -99,7 +99,8 @@ public class ReasonFlags { * @param position the position in the bit string to check. */ private boolean isSet(int position) { - return bitString[position]; + return (position < bitString.length) && + bitString[position]; } /** @@ -199,23 +200,38 @@ public class ReasonFlags { * Returns a printable representation of the ReasonFlags. */ public String toString() { - String s = "Reason Flags [\n"; + StringBuilder sb = new StringBuilder("Reason Flags [\n"); - try { - if (isSet(0)) s += " Unused\n"; - if (isSet(1)) s += " Key Compromise\n"; - if (isSet(2)) s += " CA Compromise\n"; - if (isSet(3)) s += " Affiliation_Changed\n"; - if (isSet(4)) s += " Superseded\n"; - if (isSet(5)) s += " Cessation Of Operation\n"; - if (isSet(6)) s += " Certificate Hold\n"; - if (isSet(7)) s += " Privilege Withdrawn\n"; - if (isSet(8)) s += " AA Compromise\n"; - } catch (ArrayIndexOutOfBoundsException ex) {} + if (isSet(0)) { + sb.append(" Unused\n"); + } + if (isSet(1)) { + sb.append(" Key Compromise\n"); + } + if (isSet(2)) { + sb.append(" CA Compromise\n"); + } + if (isSet(3)) { + sb.append(" Affiliation_Changed\n"); + } + if (isSet(4)) { + sb.append(" Superseded\n"); + } + if (isSet(5)) { + sb.append(" Cessation Of Operation\n"); + } + if (isSet(6)) { + sb.append(" Certificate Hold\n"); + } + if (isSet(7)) { + sb.append(" Privilege Withdrawn\n"); + } + if (isSet(8)) { + sb.append(" AA Compromise\n"); + } + sb.append("]\n"); - s += "]\n"; - - return (s); + return sb.toString(); } /** From d81fa0fe0a75fc3330d90cf7848a722161652d99 Mon Sep 17 00:00:00 2001 From: Ivan Gerasimov Date: Mon, 16 Mar 2015 23:59:02 +0300 Subject: [PATCH 016/362] 8075040: Need a test to cover FREAK (BugDB 20647631) Reviewed-by: wetmore --- .../share/classes/sun/security/ssl/ClientHandshaker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/src/java.base/share/classes/sun/security/ssl/ClientHandshaker.java b/jdk/src/java.base/share/classes/sun/security/ssl/ClientHandshaker.java index cb4f54eb125..ea4d2a404fc 100644 --- a/jdk/src/java.base/share/classes/sun/security/ssl/ClientHandshaker.java +++ b/jdk/src/java.base/share/classes/sun/security/ssl/ClientHandshaker.java @@ -293,7 +293,7 @@ final class ClientHandshaker extends Handshaker { case K_ECDH_RSA: throw new SSLProtocolException( "Protocol violation: server sent a server key exchange" - + "message for key exchange " + keyExchange); + + " message for key exchange " + keyExchange); case K_KRB5: case K_KRB5_EXPORT: throw new SSLProtocolException( From b6eef64a9823ce8c590f8afcc3d249f000636282 Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Thu, 2 Apr 2015 11:43:11 +0100 Subject: [PATCH 017/362] 8047149: Enhance thread contexts in core libraries Reviewed-by: alanb --- .../java.base/share/classes/java/lang/ref/Finalizer.java | 5 +++-- .../java.base/share/classes/java/lang/ref/Reference.java | 3 ++- jdk/src/java.base/share/classes/sun/misc/GC.java | 3 +-- .../share/classes/sun/misc/ManagedLocalsThread.java | 9 +++++++++ .../share/classes/sun/misc/RequestProcessor.java | 2 +- jdk/src/java.base/share/classes/sun/misc/Signal.java | 2 +- .../share/classes/java/util/logging/LogManager.java | 3 ++- .../classes/java/util/prefs/MacOSXPreferencesFile.java | 3 ++- .../classes/java/util/prefs/AbstractPreferences.java | 3 ++- .../classes/java/util/prefs/FileSystemPreferences.java | 4 ++-- 10 files changed, 25 insertions(+), 12 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java b/jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java index 6ae2262c5aa..cd84e62619d 100644 --- a/jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java +++ b/jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java @@ -28,6 +28,7 @@ package java.lang.ref; import java.security.PrivilegedAction; import java.security.AccessController; import sun.misc.JavaLangAccess; +import sun.misc.ManagedLocalsThread; import sun.misc.SharedSecrets; import sun.misc.VM; @@ -126,7 +127,7 @@ final class Finalizer extends FinalReference { /* Package-private; must for (ThreadGroup tgn = tg; tgn != null; tg = tgn, tgn = tg.getParent()); - Thread sft = new Thread(tg, proc, "Secondary finalizer"); + Thread sft = new ManagedLocalsThread(tg, proc, "Secondary finalizer"); sft.start(); try { sft.join(); @@ -185,7 +186,7 @@ final class Finalizer extends FinalReference { /* Package-private; must }}}); } - private static class FinalizerThread extends Thread { + private static class FinalizerThread extends ManagedLocalsThread { private volatile boolean running; FinalizerThread(ThreadGroup g) { super(g, "Finalizer"); diff --git a/jdk/src/java.base/share/classes/java/lang/ref/Reference.java b/jdk/src/java.base/share/classes/java/lang/ref/Reference.java index 5febcae0299..2bab588f1f4 100644 --- a/jdk/src/java.base/share/classes/java/lang/ref/Reference.java +++ b/jdk/src/java.base/share/classes/java/lang/ref/Reference.java @@ -27,6 +27,7 @@ package java.lang.ref; import sun.misc.Cleaner; import sun.misc.JavaLangRefAccess; +import sun.misc.ManagedLocalsThread; import sun.misc.SharedSecrets; /** @@ -126,7 +127,7 @@ public abstract class Reference { /* High-priority thread to enqueue pending References */ - private static class ReferenceHandler extends Thread { + private static class ReferenceHandler extends ManagedLocalsThread { private static void ensureClassInitialized(Class clazz) { try { diff --git a/jdk/src/java.base/share/classes/sun/misc/GC.java b/jdk/src/java.base/share/classes/sun/misc/GC.java index c77bf1d055b..4cfd9781274 100644 --- a/jdk/src/java.base/share/classes/sun/misc/GC.java +++ b/jdk/src/java.base/share/classes/sun/misc/GC.java @@ -82,8 +82,7 @@ public class GC { */ public static native long maxObjectInspectionAge(); - - private static class Daemon extends Thread { + private static class Daemon extends ManagedLocalsThread { public void run() { for (;;) { diff --git a/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java b/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java index 49298dca610..f7044124180 100644 --- a/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java +++ b/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java @@ -34,6 +34,10 @@ public class ManagedLocalsThread extends Thread { private static final long THREAD_LOCALS; private static final long INHERITABLE_THREAD_LOCALS; + public ManagedLocalsThread() { + eraseThreadLocals(); + } + public ManagedLocalsThread(Runnable target) { super(target); eraseThreadLocals(); @@ -44,6 +48,11 @@ public class ManagedLocalsThread extends Thread { eraseThreadLocals(); } + public ManagedLocalsThread(ThreadGroup group, String name) { + super(group, name); + eraseThreadLocals(); + } + public ManagedLocalsThread(ThreadGroup group, Runnable target, String name) { super(group, target, name); eraseThreadLocals(); diff --git a/jdk/src/java.base/share/classes/sun/misc/RequestProcessor.java b/jdk/src/java.base/share/classes/sun/misc/RequestProcessor.java index 54a62724de0..30131f42b29 100644 --- a/jdk/src/java.base/share/classes/sun/misc/RequestProcessor.java +++ b/jdk/src/java.base/share/classes/sun/misc/RequestProcessor.java @@ -77,7 +77,7 @@ public class RequestProcessor implements Runnable { */ public static synchronized void startProcessing() { if (dispatcher == null) { - dispatcher = new Thread(new RequestProcessor(), "Request Processor"); + dispatcher = new ManagedLocalsThread(new RequestProcessor(), "Request Processor"); dispatcher.setPriority(Thread.NORM_PRIORITY + 2); dispatcher.start(); } diff --git a/jdk/src/java.base/share/classes/sun/misc/Signal.java b/jdk/src/java.base/share/classes/sun/misc/Signal.java index 07557a8d78f..a00ee9f089d 100644 --- a/jdk/src/java.base/share/classes/sun/misc/Signal.java +++ b/jdk/src/java.base/share/classes/sun/misc/Signal.java @@ -213,7 +213,7 @@ public final class Signal { } }; if (handler != null) { - new Thread(runnable, sig + " handler").start(); + new ManagedLocalsThread(runnable, sig + " handler").start(); } } diff --git a/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java b/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java index 0f536b202e9..972b74a7efb 100644 --- a/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java +++ b/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java @@ -34,6 +34,7 @@ import java.lang.ref.WeakReference; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import sun.misc.JavaAWTAccess; +import sun.misc.ManagedLocalsThread; import sun.misc.SharedSecrets; /** @@ -248,7 +249,7 @@ public class LogManager { // This private class is used as a shutdown hook. // It does a "reset" to close all open handlers. - private class Cleaner extends Thread { + private class Cleaner extends ManagedLocalsThread { private Cleaner() { /* Set context class loader to null in order to avoid diff --git a/jdk/src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java b/jdk/src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java index 6553ff6ed78..dc54a0d539b 100644 --- a/jdk/src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java +++ b/jdk/src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java @@ -31,6 +31,7 @@ import java.util.Iterator; import java.util.Timer; import java.util.TimerTask; import java.lang.ref.WeakReference; +import sun.misc.ManagedLocalsThread; /* @@ -343,7 +344,7 @@ class MacOSXPreferencesFile { { if (timer == null) { timer = new Timer(true); // daemon - Thread flushThread = new Thread() { + Thread flushThread = new ManagedLocalsThread() { @Override public void run() { flushWorld(); diff --git a/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java b/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java index a840dffab95..fd3ba69902a 100644 --- a/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java +++ b/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java @@ -29,6 +29,7 @@ import java.util.*; import java.io.*; import java.security.AccessController; import java.security.PrivilegedAction; +import sun.misc.ManagedLocalsThread; // These imports needed only as a workaround for a JavaDoc bug import java.lang.Integer; import java.lang.Long; @@ -1470,7 +1471,7 @@ public abstract class AbstractPreferences extends Preferences { * A single background thread ("the event notification thread") monitors * the event queue and delivers events that are placed on the queue. */ - private static class EventDispatchThread extends Thread { + private static class EventDispatchThread extends ManagedLocalsThread { public void run() { while(true) { // Wait on eventQueue till an event is present diff --git a/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java b/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java index 7bcd1d3ad24..9d412ed7f67 100644 --- a/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java +++ b/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java @@ -30,7 +30,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; import java.security.PrivilegedActionException; - +import sun.misc.ManagedLocalsThread; import sun.util.logging.PlatformLogger; /** @@ -450,7 +450,7 @@ class FileSystemPreferences extends AbstractPreferences { // Add shutdown hook to flush cached prefs on normal termination AccessController.doPrivileged(new PrivilegedAction() { public Void run() { - Runtime.getRuntime().addShutdownHook(new Thread() { + Runtime.getRuntime().addShutdownHook(new ManagedLocalsThread() { public void run() { syncTimer.cancel(); syncWorld(); From 8747b64d35cdbe779f552e949ba4feb3f953916d Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Thu, 2 Apr 2015 11:43:11 +0100 Subject: [PATCH 018/362] 8042322: Enhance thread contexts in networking and nio Reviewed-by: alanb, michaelm --- .../share/classes/sun/misc/ManagedLocalsThread.java | 5 +++++ .../share/classes/sun/net/NetworkServer.java | 5 +++-- .../share/classes/sun/net/www/MimeLauncher.java | 3 ++- .../classes/sun/net/www/http/KeepAliveCache.java | 11 ++--------- .../classes/sun/net/www/http/KeepAliveStream.java | 12 +++--------- .../share/classes/sun/nio/fs/AbstractPoller.java | 3 ++- .../share/classes/sun/nio/fs/Cancellable.java | 3 ++- .../classes/sun/nio/fs/PollingWatchService.java | 3 ++- .../classes/sun/nio/ch/WindowsSelectorImpl.java | 3 ++- .../share/classes/sun/net/httpserver/ServerImpl.java | 3 ++- 10 files changed, 25 insertions(+), 26 deletions(-) diff --git a/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java b/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java index f7044124180..cd75ef237ce 100644 --- a/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java +++ b/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java @@ -43,6 +43,11 @@ public class ManagedLocalsThread extends Thread { eraseThreadLocals(); } + public ManagedLocalsThread(String name) { + super(name); + eraseThreadLocals(); + } + public ManagedLocalsThread(Runnable target, String name) { super(target, name); eraseThreadLocals(); diff --git a/jdk/src/java.base/share/classes/sun/net/NetworkServer.java b/jdk/src/java.base/share/classes/sun/net/NetworkServer.java index d4a9cc78e5b..6937775d40e 100644 --- a/jdk/src/java.base/share/classes/sun/net/NetworkServer.java +++ b/jdk/src/java.base/share/classes/sun/net/NetworkServer.java @@ -27,6 +27,7 @@ package sun.net; import java.io.*; import java.net.Socket; import java.net.ServerSocket; +import sun.misc.ManagedLocalsThread; /** * This is the base class for network servers. To define a new type @@ -72,7 +73,7 @@ public class NetworkServer implements Runnable, Cloneable { NetworkServer n = (NetworkServer)clone(); n.serverSocket = null; n.clientSocket = ns; - new Thread(n).start(); + new ManagedLocalsThread(n).start(); } catch(Exception e) { System.out.print("Server failure\n"); e.printStackTrace(); @@ -107,7 +108,7 @@ public class NetworkServer implements Runnable, Cloneable { for each new connection. */ final public void startServer(int port) throws IOException { serverSocket = new ServerSocket(port, 50); - serverInstance = new Thread(this); + serverInstance = new ManagedLocalsThread(this); serverInstance.start(); } diff --git a/jdk/src/java.base/share/classes/sun/net/www/MimeLauncher.java b/jdk/src/java.base/share/classes/sun/net/www/MimeLauncher.java index ee4fb40eeca..32b3603de82 100644 --- a/jdk/src/java.base/share/classes/sun/net/www/MimeLauncher.java +++ b/jdk/src/java.base/share/classes/sun/net/www/MimeLauncher.java @@ -27,8 +27,9 @@ package sun.net.www; import java.net.URL; import java.io.*; import java.util.StringTokenizer; +import sun.misc.ManagedLocalsThread; -class MimeLauncher extends Thread { +class MimeLauncher extends ManagedLocalsThread { java.net.URLConnection uc; MimeEntry m; String genericTempFileTemplate; diff --git a/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java b/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java index 16f02d7cdde..1b3d4295bf2 100644 --- a/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java +++ b/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java @@ -30,6 +30,7 @@ import java.io.NotSerializableException; import java.util.ArrayList; import java.util.HashMap; import java.net.URL; +import sun.misc.InnocuousThread; /** * A class that implements a cache of idle Http connections for keep-alive @@ -95,15 +96,7 @@ public class KeepAliveCache java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Void run() { - // We want to create the Keep-Alive-Timer in the - // system threadgroup - ThreadGroup grp = Thread.currentThread().getThreadGroup(); - ThreadGroup parent = null; - while ((parent = grp.getParent()) != null) { - grp = parent; - } - - keepAliveTimer = new Thread(grp, cache, "Keep-Alive-Timer"); + keepAliveTimer = new InnocuousThread(cache, "Keep-Alive-Timer"); keepAliveTimer.setDaemon(true); keepAliveTimer.setPriority(Thread.MAX_PRIORITY - 2); // Set the context class loader to null in order to avoid diff --git a/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java b/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java index 9155c4ae8c5..53835df7f6a 100644 --- a/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java +++ b/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java @@ -26,6 +26,8 @@ package sun.net.www.http; import java.io.*; + +import sun.misc.InnocuousThread; import sun.net.ProgressSource; import sun.net.www.MeteredStream; @@ -171,15 +173,7 @@ class KeepAliveStream extends MeteredStream implements Hurryable { java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Void run() { - // We want to create the Keep-Alive-SocketCleaner in the - // system threadgroup - ThreadGroup grp = Thread.currentThread().getThreadGroup(); - ThreadGroup parent = null; - while ((parent = grp.getParent()) != null) { - grp = parent; - } - - cleanerThread = new Thread(grp, queue, "Keep-Alive-SocketCleaner"); + cleanerThread = new InnocuousThread(queue, "Keep-Alive-SocketCleaner"); cleanerThread.setDaemon(true); cleanerThread.setPriority(Thread.MAX_PRIORITY - 2); // Set the context class loader to null in order to avoid diff --git a/jdk/src/java.base/share/classes/sun/nio/fs/AbstractPoller.java b/jdk/src/java.base/share/classes/sun/nio/fs/AbstractPoller.java index 34d4ea4e3bc..8dd078db0bc 100644 --- a/jdk/src/java.base/share/classes/sun/nio/fs/AbstractPoller.java +++ b/jdk/src/java.base/share/classes/sun/nio/fs/AbstractPoller.java @@ -30,6 +30,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.io.IOException; import java.util.*; +import sun.misc.ManagedLocalsThread; /** * Base implementation of background poller thread used in watch service @@ -59,7 +60,7 @@ abstract class AbstractPoller implements Runnable { AccessController.doPrivileged(new PrivilegedAction() { @Override public Object run() { - Thread thr = new Thread(thisRunnable); + Thread thr = new ManagedLocalsThread(thisRunnable); thr.setDaemon(true); thr.start(); return null; diff --git a/jdk/src/java.base/share/classes/sun/nio/fs/Cancellable.java b/jdk/src/java.base/share/classes/sun/nio/fs/Cancellable.java index 0aa6521f19b..648d4089ce8 100644 --- a/jdk/src/java.base/share/classes/sun/nio/fs/Cancellable.java +++ b/jdk/src/java.base/share/classes/sun/nio/fs/Cancellable.java @@ -25,6 +25,7 @@ package sun.nio.fs; +import sun.misc.ManagedLocalsThread; import sun.misc.Unsafe; import java.util.concurrent.ExecutionException; @@ -117,7 +118,7 @@ abstract class Cancellable implements Runnable { * thread by writing into the memory location that it polls cooperatively. */ static void runInterruptibly(Cancellable task) throws ExecutionException { - Thread t = new Thread(task); + Thread t = new ManagedLocalsThread(task); t.start(); boolean cancelledByInterrupt = false; while (t.isAlive()) { diff --git a/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java b/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java index d3d9891223d..bc4af73e762 100644 --- a/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java +++ b/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java @@ -35,6 +35,7 @@ import java.io.IOException; import java.util.*; import java.util.concurrent.*; import com.sun.nio.file.SensitivityWatchEventModifier; +import sun.misc.ManagedLocalsThread; /** * Simple WatchService implementation that uses periodic tasks to poll @@ -58,7 +59,7 @@ class PollingWatchService .newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { - Thread t = new Thread(r); + Thread t = new ManagedLocalsThread(r); t.setDaemon(true); return t; }}); diff --git a/jdk/src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java b/jdk/src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java index eec35ea9518..28fc83a0b31 100644 --- a/jdk/src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java +++ b/jdk/src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java @@ -40,6 +40,7 @@ import java.util.List; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import sun.misc.ManagedLocalsThread; /** * A multi-threaded implementation of Selector for Windows. @@ -403,7 +404,7 @@ final class WindowsSelectorImpl extends SelectorImpl { } // Represents a helper thread used for select. - private final class SelectThread extends Thread { + private final class SelectThread extends ManagedLocalsThread { private final int index; // index of this thread final SubSelector subSelector; private long lastRun = 0; // last run number diff --git a/jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java b/jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java index 24ab8b014db..5b97c16477c 100644 --- a/jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java +++ b/jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java @@ -36,6 +36,7 @@ import javax.net.ssl.*; import com.sun.net.httpserver.*; import java.security.AccessController; import java.security.PrivilegedAction; +import sun.misc.ManagedLocalsThread; import sun.net.httpserver.HttpConnection.State; /** @@ -142,7 +143,7 @@ class ServerImpl implements TimeSource { if (executor == null) { executor = new DefaultExecutor(); } - dispatcherThread = new Thread (dispatcher); + dispatcherThread = new ManagedLocalsThread(dispatcher); started = true; dispatcherThread.start(); } From f2758e5843e607171b71c0c5f34a53dff3586479 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Fri, 1 Aug 2014 13:31:03 +0200 Subject: [PATCH 019/362] 8042327: Enhance thread contexts in serviceability Reviewed-by: chegar, dfuchs, olagneau, sla --- .../remote/internal/ClientCommunicatorAdmin.java | 7 ++++++- .../jmx/remote/internal/ClientNotifForwarder.java | 13 ++++++------- .../remote/internal/ServerCommunicatorAdmin.java | 4 ++-- .../classes/javax/management/monitor/Monitor.java | 13 +++++++------ .../classes/sun/management/jdp/JdpController.java | 3 ++- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientCommunicatorAdmin.java b/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientCommunicatorAdmin.java index b8549f255a9..85f248311cb 100644 --- a/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientCommunicatorAdmin.java +++ b/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientCommunicatorAdmin.java @@ -30,6 +30,7 @@ import java.io.InterruptedIOException; import com.sun.jmx.remote.util.ClassLogger; import com.sun.jmx.remote.util.EnvHelp; +import sun.misc.ManagedLocalsThread; public abstract class ClientCommunicatorAdmin { private static volatile long threadNo = 1; @@ -40,7 +41,11 @@ public abstract class ClientCommunicatorAdmin { if (period > 0) { checker = new Checker(); - Thread t = new Thread(checker, "JMX client heartbeat " + ++threadNo); + Thread t = new ManagedLocalsThread( + checker, + "JMX client heartbeat " + (++threadNo) + ); + t.setDaemon(true); t.start(); } else diff --git a/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientNotifForwarder.java b/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientNotifForwarder.java index 4d3ba6db0d8..05abd0ceeb5 100644 --- a/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientNotifForwarder.java +++ b/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientNotifForwarder.java @@ -52,6 +52,7 @@ import javax.management.remote.TargetedNotification; import com.sun.jmx.remote.util.ClassLogger; import com.sun.jmx.remote.util.EnvHelp; import java.rmi.UnmarshalException; +import sun.misc.ManagedLocalsThread; public abstract class ClientNotifForwarder { @@ -90,10 +91,8 @@ public abstract class ClientNotifForwarder { throw new IllegalArgumentException("More than one command"); this.command = command; if (thread == null) { - thread = new Thread() { - - @Override - public void run() { + thread = new ManagedLocalsThread( + ()-> { while (true) { Runnable r; synchronized (LinearExecutor.this) { @@ -107,10 +106,10 @@ public abstract class ClientNotifForwarder { } r.run(); } - } - }; + }, + "ClientNotifForwarder-" + ++threadId + ); thread.setDaemon(true); - thread.setName("ClientNotifForwarder-" + ++threadId); thread.start(); } } diff --git a/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ServerCommunicatorAdmin.java b/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ServerCommunicatorAdmin.java index bb09f62bdb9..f943bf5ce68 100644 --- a/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ServerCommunicatorAdmin.java +++ b/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ServerCommunicatorAdmin.java @@ -25,9 +25,9 @@ package com.sun.jmx.remote.internal; -import java.io.IOException; import com.sun.jmx.remote.util.ClassLogger; +import sun.misc.ManagedLocalsThread; public abstract class ServerCommunicatorAdmin { public ServerCommunicatorAdmin(long timeout) { @@ -42,7 +42,7 @@ public abstract class ServerCommunicatorAdmin { timestamp = 0; if (timeout < Long.MAX_VALUE) { Runnable timeoutTask = new Timeout(); - final Thread t = new Thread(timeoutTask); + final Thread t = new ManagedLocalsThread(timeoutTask); t.setName("JMX server connection timeout " + t.getId()); // If you change this name you will need to change a unit test // (NoServerTimeoutTest) diff --git a/jdk/src/java.management/share/classes/javax/management/monitor/Monitor.java b/jdk/src/java.management/share/classes/javax/management/monitor/Monitor.java index bf89b06cb9f..5389a66bcb5 100644 --- a/jdk/src/java.management/share/classes/javax/management/monitor/Monitor.java +++ b/jdk/src/java.management/share/classes/javax/management/monitor/Monitor.java @@ -61,6 +61,7 @@ import javax.management.NotificationBroadcasterSupport; import javax.management.ObjectName; import javax.management.ReflectionException; import static javax.management.monitor.MonitorNotification.*; +import sun.misc.ManagedLocalsThread; /** * Defines the part common to all monitor MBeans. @@ -1636,12 +1637,12 @@ public abstract class Monitor } public Thread newThread(Runnable r) { - Thread t = new Thread(group, - r, - namePrefix + - threadNumber.getAndIncrement() + - nameSuffix, - 0); + Thread t = new ManagedLocalsThread( + group, + r, + namePrefix + threadNumber.getAndIncrement() + nameSuffix + ); + t.setDaemon(true); if (t.getPriority() != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY); diff --git a/jdk/src/java.management/share/classes/sun/management/jdp/JdpController.java b/jdk/src/java.management/share/classes/sun/management/jdp/JdpController.java index a22873a0700..a90705d577a 100644 --- a/jdk/src/java.management/share/classes/sun/management/jdp/JdpController.java +++ b/jdk/src/java.management/share/classes/sun/management/jdp/JdpController.java @@ -34,6 +34,7 @@ import java.lang.management.RuntimeMXBean; import java.lang.reflect.Field; import java.lang.reflect.Method; import sun.management.VMManagement; +import sun.misc.ManagedLocalsThread; /** * JdpController is responsible to create and manage a broadcast loop @@ -219,7 +220,7 @@ public final class JdpController { controller = new JDPControllerRunner(bcast, packet, pause); - Thread t = new Thread(controller, "JDP broadcaster"); + Thread t = new ManagedLocalsThread(controller, "JDP broadcaster"); t.setDaemon(true); t.start(); } From 58981bad953a124f6e7dea212946445974d32182 Mon Sep 17 00:00:00 2001 From: Andrew Haley Date: Tue, 14 Apr 2015 17:19:08 +0100 Subject: [PATCH 020/362] 8076467: AARCH64: assertion fail with -XX:+UseG1GC Don't call encoding unless bool is true. Reviewed-by: kvn --- hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.hpp | 2 ++ hotspot/src/cpu/aarch64/vm/register_aarch64.hpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.hpp b/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.hpp index 4087a187512..871cc33d279 100644 --- a/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.hpp +++ b/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.hpp @@ -39,6 +39,8 @@ class InterpreterMacroAssembler: public MacroAssembler { protected: protected: + using MacroAssembler::call_VM_leaf_base; + // Interpreter specific version of call_VM_base virtual void call_VM_leaf_base(address entry_point, int number_of_arguments); diff --git a/hotspot/src/cpu/aarch64/vm/register_aarch64.hpp b/hotspot/src/cpu/aarch64/vm/register_aarch64.hpp index fdcc502ca8b..1e22e935278 100644 --- a/hotspot/src/cpu/aarch64/vm/register_aarch64.hpp +++ b/hotspot/src/cpu/aarch64/vm/register_aarch64.hpp @@ -60,7 +60,10 @@ class RegisterImpl: public AbstractRegisterImpl { bool has_byte_register() const { return 0 <= (intptr_t)this && (intptr_t)this < number_of_byte_registers; } const char* name() const; int encoding_nocheck() const { return (intptr_t)this; } - unsigned long bit(bool yes = true) const { return yes << encoding(); } + + // Return the bit which represents this register. This is intended + // to be ORed into a bitmask: for usage see class RegSet below. + unsigned long bit(bool should_set = true) const { return should_set ? 1 << encoding() : 0; } }; // The integer registers of the aarch64 architecture From 6485d074d4da3a7e9ac5936341c30ade131a1533 Mon Sep 17 00:00:00 2001 From: Sangheon Kim Date: Sun, 19 Oct 2014 20:23:12 -0700 Subject: [PATCH 021/362] 8059064: Better G1 log caching Reviewed-by: jmasa, ahgross --- hotspot/src/share/vm/runtime/arguments.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp index 320f67e9262..e2ba1c81050 100644 --- a/hotspot/src/share/vm/runtime/arguments.cpp +++ b/hotspot/src/share/vm/runtime/arguments.cpp @@ -2320,7 +2320,7 @@ bool Arguments::check_vm_args_consistency() { "G1ConcMarkStepDurationMillis"); status = status && verify_interval(G1ConcRSHotCardLimit, 0, max_jubyte, "G1ConcRSHotCardLimit"); - status = status && verify_interval(G1ConcRSLogCacheSize, 0, 31, + status = status && verify_interval(G1ConcRSLogCacheSize, 0, 27, "G1ConcRSLogCacheSize"); status = status && verify_interval(StringDeduplicationAgeThreshold, 1, markOopDesc::max_age, "StringDeduplicationAgeThreshold"); From 5471bf0e8ae420b2199e22ed8d472453b710c871 Mon Sep 17 00:00:00 2001 From: Kim Barrett Date: Tue, 3 Mar 2015 19:47:49 -0500 Subject: [PATCH 022/362] 8073994: STATIC_ASSERT use of __LINE__ is wrong Reviewed-by: dholmes, ehelin --- hotspot/src/share/vm/utilities/debug.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hotspot/src/share/vm/utilities/debug.hpp b/hotspot/src/share/vm/utilities/debug.hpp index 381cfd63bae..414316990a0 100644 --- a/hotspot/src/share/vm/utilities/debug.hpp +++ b/hotspot/src/share/vm/utilities/debug.hpp @@ -222,9 +222,8 @@ void warning(const char* format, ...) ATTRIBUTE_PRINTF(1, 2); template struct STATIC_ASSERT_FAILURE; template<> struct STATIC_ASSERT_FAILURE { enum { value = 1 }; }; -#define STATIC_ASSERT(Cond) \ - typedef char STATIC_ASSERT_FAILURE_ ## __LINE__ [ \ - STATIC_ASSERT_FAILURE< (Cond) >::value ] +#define STATIC_ASSERT(Cond) \ + typedef char STATIC_ASSERT_DUMMY_TYPE[ STATIC_ASSERT_FAILURE< (Cond) >::value ] // out of shared space reporting enum SharedSpaceType { From 395543dadca0a4a8552f5d66967602f12d66f46f Mon Sep 17 00:00:00 2001 From: Bengt Rutisson Date: Thu, 12 Mar 2015 10:11:20 +0100 Subject: [PATCH 023/362] 8074037: Refactor the G1GCPhaseTime logging to make it easier to add new phases Reviewed-by: tschatzl, mgerdin, ecaspole --- .../gc_implementation/g1/g1CollectedHeap.cpp | 63 ++- .../g1/g1CollectorPolicy.cpp | 38 +- .../gc_implementation/g1/g1GCPhaseTimes.cpp | 507 ++++++++++++------ .../gc_implementation/g1/g1GCPhaseTimes.hpp | 247 +++------ .../share/vm/gc_implementation/g1/g1Log.hpp | 6 + .../vm/gc_implementation/g1/g1RemSet.cpp | 9 +- .../vm/gc_implementation/g1/g1StringDedup.cpp | 42 +- .../vm/gc_implementation/g1/g1StringDedup.hpp | 3 +- 8 files changed, 496 insertions(+), 419 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index 18deaa19b1b..0179bb4aa1a 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -2206,11 +2206,11 @@ void G1CollectedHeap::iterate_dirty_card_closure(CardTableEntryClosure* cl, hot_card_cache->drain(worker_i, g1_rem_set(), into_cset_dcq); DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); - int n_completed_buffers = 0; + size_t n_completed_buffers = 0; while (dcqs.apply_closure_to_completed_buffer(cl, worker_i, 0, true)) { n_completed_buffers++; } - g1_policy()->phase_times()->record_update_rs_processed_buffers(worker_i, n_completed_buffers); + g1_policy()->phase_times()->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, n_completed_buffers); dcqs.clear_n_completed_buffers(); assert(!dcqs.completed_buffers_exist_dirty(), "Completed buffers exist!"); } @@ -3751,9 +3751,9 @@ G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) { TraceCPUTime tcpu(G1Log::finer(), true, gclog_or_tty); - int active_workers = workers()->active_workers(); + uint active_workers = workers()->active_workers(); double pause_start_sec = os::elapsedTime(); - g1_policy()->phase_times()->note_gc_start(active_workers); + g1_policy()->phase_times()->note_gc_start(active_workers, mark_in_progress()); log_gc_header(); TraceCollectorStats tcs(g1mm()->incremental_collection_counters()); @@ -4486,8 +4486,7 @@ public: void work(uint worker_id) { if (worker_id >= _n_workers) return; // no work needed this round - double start_time_ms = os::elapsedTime() * 1000.0; - _g1h->g1_policy()->phase_times()->record_gc_worker_start_time(worker_id, start_time_ms); + _g1h->g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::GCWorkerStart, worker_id, os::elapsedTime()); { ResourceMark rm; @@ -4567,10 +4566,11 @@ public: double start = os::elapsedTime(); G1ParEvacuateFollowersClosure evac(_g1h, &pss, _queues, &_terminator); evac.do_void(); - double elapsed_ms = (os::elapsedTime()-start)*1000.0; - double term_ms = pss.term_time()*1000.0; - _g1h->g1_policy()->phase_times()->add_obj_copy_time(worker_id, elapsed_ms-term_ms); - _g1h->g1_policy()->phase_times()->record_termination(worker_id, term_ms, pss.term_attempts()); + double elapsed_sec = os::elapsedTime() - start; + double term_sec = pss.term_time(); + _g1h->g1_policy()->phase_times()->add_time_secs(G1GCPhaseTimes::ObjCopy, worker_id, elapsed_sec - term_sec); + _g1h->g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::Termination, worker_id, term_sec); + _g1h->g1_policy()->phase_times()->record_thread_work_item(G1GCPhaseTimes::Termination, worker_id, pss.term_attempts()); } _g1h->g1_policy()->record_thread_age_table(pss.age_table()); _g1h->update_surviving_young_words(pss.surviving_young_words()+1); @@ -4586,9 +4586,7 @@ public: // destructors are executed here and are included as part of the // "GC Worker Time". } - - double end_time_ms = os::elapsedTime() * 1000.0; - _g1h->g1_policy()->phase_times()->record_gc_worker_end_time(worker_id, end_time_ms); + _g1h->g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::GCWorkerEnd, worker_id, os::elapsedTime()); } }; @@ -4650,27 +4648,20 @@ g1_process_roots(OopClosure* scan_non_heap_roots, double obj_copy_time_sec = buf_scan_non_heap_roots.closure_app_seconds() + buf_scan_non_heap_weak_roots.closure_app_seconds(); - g1_policy()->phase_times()->record_obj_copy_time(worker_i, obj_copy_time_sec * 1000.0); + g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, obj_copy_time_sec); - double ext_root_time_ms = - ((os::elapsedTime() - ext_roots_start) - obj_copy_time_sec) * 1000.0; - - g1_policy()->phase_times()->record_ext_root_scan_time(worker_i, ext_root_time_ms); + double ext_root_time_sec = os::elapsedTime() - ext_roots_start - obj_copy_time_sec; + g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::ExtRootScan, worker_i, ext_root_time_sec); // During conc marking we have to filter the per-thread SATB buffers // to make sure we remove any oops into the CSet (which will show up // as implicitly live). - double satb_filtering_ms = 0.0; - if (!_process_strong_tasks->is_task_claimed(G1H_PS_filter_satb_buffers)) { - if (mark_in_progress()) { - double satb_filter_start = os::elapsedTime(); - + { + G1GCParPhaseTimesTracker x(g1_policy()->phase_times(), G1GCPhaseTimes::SATBFiltering, worker_i); + if (!_process_strong_tasks->is_task_claimed(G1H_PS_filter_satb_buffers) && mark_in_progress()) { JavaThread::satb_mark_queue_set().filter_thread_buffers(); - - satb_filtering_ms = (os::elapsedTime() - satb_filter_start) * 1000.0; } } - g1_policy()->phase_times()->record_satb_filtering_time(worker_i, satb_filtering_ms); // Now scan the complement of the collection set. G1CodeBlobClosure scavenge_cs_nmethods(scan_non_heap_weak_roots); @@ -5073,14 +5064,13 @@ class G1RedirtyLoggedCardsTask : public AbstractGangTask { G1RedirtyLoggedCardsTask(DirtyCardQueueSet* queue) : AbstractGangTask("Redirty Cards"), _queue(queue) { } virtual void work(uint worker_id) { - double start_time = os::elapsedTime(); + G1GCPhaseTimes* phase_times = G1CollectedHeap::heap()->g1_policy()->phase_times(); + G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::RedirtyCards, worker_id); RedirtyLoggedCardTableEntryClosure cl; _queue->par_apply_closure_to_all_completed_buffers(&cl); - G1GCPhaseTimes* timer = G1CollectedHeap::heap()->g1_policy()->phase_times(); - timer->record_redirty_logged_cards_time_ms(worker_id, (os::elapsedTime() - start_time) * 1000.0); - timer->record_redirty_logged_cards_processed_cards(worker_id, cl.num_processed()); + phase_times->record_thread_work_item(G1GCPhaseTimes::RedirtyCards, worker_id, cl.num_processed()); } }; @@ -5658,12 +5648,14 @@ void G1CollectedHeap::evacuate_collection_set(EvacuationInfo& evacuation_info) { // reported parallel time. } + G1GCPhaseTimes* phase_times = g1_policy()->phase_times(); + double par_time_ms = (end_par_time_sec - start_par_time_sec) * 1000.0; - g1_policy()->phase_times()->record_par_time(par_time_ms); + phase_times->record_par_time(par_time_ms); double code_root_fixup_time_ms = (os::elapsedTime() - end_par_time_sec) * 1000.0; - g1_policy()->phase_times()->record_code_root_fixup_time(code_root_fixup_time_ms); + phase_times->record_code_root_fixup_time(code_root_fixup_time_ms); set_par_threads(0); @@ -5675,9 +5667,14 @@ void G1CollectedHeap::evacuate_collection_set(EvacuationInfo& evacuation_info) { process_discovered_references(n_workers); if (G1StringDedup::is_enabled()) { + double fixup_start = os::elapsedTime(); + G1STWIsAliveClosure is_alive(this); G1KeepAliveClosure keep_alive(this); - G1StringDedup::unlink_or_oops_do(&is_alive, &keep_alive); + G1StringDedup::unlink_or_oops_do(&is_alive, &keep_alive, true, phase_times); + + double fixup_time_ms = (os::elapsedTime() - fixup_start) * 1000.0; + phase_times->record_string_dedup_fixup_time(fixup_time_ms); } _allocator->release_gc_alloc_regions(n_workers, evacuation_info); diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp index fbb52ad85e4..745ac129ca0 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp @@ -1073,7 +1073,7 @@ void G1CollectorPolicy::record_collection_pause_end(double pause_time_ms, Evacua if (update_stats) { double cost_per_card_ms = 0.0; if (_pending_cards > 0) { - cost_per_card_ms = phase_times()->average_last_update_rs_time() / (double) _pending_cards; + cost_per_card_ms = phase_times()->average_time_ms(G1GCPhaseTimes::UpdateRS) / (double) _pending_cards; _cost_per_card_ms_seq->add(cost_per_card_ms); } @@ -1081,7 +1081,7 @@ void G1CollectorPolicy::record_collection_pause_end(double pause_time_ms, Evacua double cost_per_entry_ms = 0.0; if (cards_scanned > 10) { - cost_per_entry_ms = phase_times()->average_last_scan_rs_time() / (double) cards_scanned; + cost_per_entry_ms = phase_times()->average_time_ms(G1GCPhaseTimes::ScanRS) / (double) cards_scanned; if (_last_gc_was_young) { _cost_per_entry_ms_seq->add(cost_per_entry_ms); } else { @@ -1123,7 +1123,7 @@ void G1CollectorPolicy::record_collection_pause_end(double pause_time_ms, Evacua double cost_per_byte_ms = 0.0; if (copied_bytes > 0) { - cost_per_byte_ms = phase_times()->average_last_obj_copy_time() / (double) copied_bytes; + cost_per_byte_ms = phase_times()->average_time_ms(G1GCPhaseTimes::ObjCopy) / (double) copied_bytes; if (_in_marking_window) { _cost_per_byte_ms_during_cm_seq->add(cost_per_byte_ms); } else { @@ -1132,8 +1132,8 @@ void G1CollectorPolicy::record_collection_pause_end(double pause_time_ms, Evacua } double all_other_time_ms = pause_time_ms - - (phase_times()->average_last_update_rs_time() + phase_times()->average_last_scan_rs_time() - + phase_times()->average_last_obj_copy_time() + phase_times()->average_last_termination_time()); + (phase_times()->average_time_ms(G1GCPhaseTimes::UpdateRS) + phase_times()->average_time_ms(G1GCPhaseTimes::ScanRS) + + phase_times()->average_time_ms(G1GCPhaseTimes::ObjCopy) + phase_times()->average_time_ms(G1GCPhaseTimes::Termination)); double young_other_time_ms = 0.0; if (young_cset_region_length() > 0) { @@ -1174,8 +1174,8 @@ void G1CollectorPolicy::record_collection_pause_end(double pause_time_ms, Evacua // Note that _mmu_tracker->max_gc_time() returns the time in seconds. double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0; - adjust_concurrent_refinement(phase_times()->average_last_update_rs_time(), - phase_times()->sum_last_update_rs_processed_buffers(), update_rs_time_goal_ms); + adjust_concurrent_refinement(phase_times()->average_time_ms(G1GCPhaseTimes::UpdateRS), + phase_times()->sum_thread_work_items(G1GCPhaseTimes::UpdateRS), update_rs_time_goal_ms); _collectionSetChooser->verify(); } @@ -2114,19 +2114,19 @@ void TraceYoungGenTimeData::record_end_collection(double pause_time_ms, G1GCPhas _other.add(pause_time_ms - phase_times->accounted_time_ms()); _root_region_scan_wait.add(phase_times->root_region_scan_wait_time_ms()); _parallel.add(phase_times->cur_collection_par_time_ms()); - _ext_root_scan.add(phase_times->average_last_ext_root_scan_time()); - _satb_filtering.add(phase_times->average_last_satb_filtering_times_ms()); - _update_rs.add(phase_times->average_last_update_rs_time()); - _scan_rs.add(phase_times->average_last_scan_rs_time()); - _obj_copy.add(phase_times->average_last_obj_copy_time()); - _termination.add(phase_times->average_last_termination_time()); + _ext_root_scan.add(phase_times->average_time_ms(G1GCPhaseTimes::ExtRootScan)); + _satb_filtering.add(phase_times->average_time_ms(G1GCPhaseTimes::SATBFiltering)); + _update_rs.add(phase_times->average_time_ms(G1GCPhaseTimes::UpdateRS)); + _scan_rs.add(phase_times->average_time_ms(G1GCPhaseTimes::ScanRS)); + _obj_copy.add(phase_times->average_time_ms(G1GCPhaseTimes::ObjCopy)); + _termination.add(phase_times->average_time_ms(G1GCPhaseTimes::Termination)); - double parallel_known_time = phase_times->average_last_ext_root_scan_time() + - phase_times->average_last_satb_filtering_times_ms() + - phase_times->average_last_update_rs_time() + - phase_times->average_last_scan_rs_time() + - phase_times->average_last_obj_copy_time() + - + phase_times->average_last_termination_time(); + double parallel_known_time = phase_times->average_time_ms(G1GCPhaseTimes::ExtRootScan) + + phase_times->average_time_ms(G1GCPhaseTimes::SATBFiltering) + + phase_times->average_time_ms(G1GCPhaseTimes::UpdateRS) + + phase_times->average_time_ms(G1GCPhaseTimes::ScanRS) + + phase_times->average_time_ms(G1GCPhaseTimes::ObjCopy) + + phase_times->average_time_ms(G1GCPhaseTimes::Termination); double parallel_other_time = phase_times->cur_collection_par_time_ms() - parallel_known_time; _parallel_other.add(parallel_other_time); diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp index f9e892b3bb2..07b45338d9b 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp @@ -22,13 +22,13 @@ * */ - #include "precompiled.hpp" #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" #include "gc_implementation/g1/g1GCPhaseTimes.hpp" #include "gc_implementation/g1/g1Log.hpp" #include "gc_implementation/g1/g1StringDedup.hpp" -#include "runtime/atomic.inline.hpp" +#include "memory/allocation.hpp" +#include "runtime/os.hpp" // Helper class for avoiding interleaved logging class LineBuffer: public StackObj { @@ -71,184 +71,243 @@ public: va_end(ap); } + void print_cr() { + gclog_or_tty->print_cr("%s", _buffer); + _cur = _indent_level * INDENT_CHARS; + } + void append_and_print_cr(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) { va_list ap; va_start(ap, format); vappend(format, ap); va_end(ap); - gclog_or_tty->print_cr("%s", _buffer); - _cur = _indent_level * INDENT_CHARS; + print_cr(); } }; -PRAGMA_DIAG_PUSH -PRAGMA_FORMAT_NONLITERAL_IGNORED template -void WorkerDataArray::print(int level, const char* title) { - if (_length == 1) { - // No need for min, max, average and sum for only one worker - LineBuffer buf(level); - buf.append("[%s: ", title); - buf.append(_print_format, _data[0]); - buf.append_and_print_cr("]"); - return; +class WorkerDataArray : public CHeapObj { + friend class G1GCParPhasePrinter; + T* _data; + uint _length; + const char* _title; + bool _print_sum; + int _log_level; + uint _indent_level; + bool _enabled; + + WorkerDataArray* _thread_work_items; + + NOT_PRODUCT(T uninitialized();) + + // We are caching the sum and average to only have to calculate them once. + // This is not done in an MT-safe way. It is intended to allow single + // threaded code to call sum() and average() multiple times in any order + // without having to worry about the cost. + bool _has_new_data; + T _sum; + T _min; + T _max; + double _average; + + public: + WorkerDataArray(uint length, const char* title, bool print_sum, int log_level, uint indent_level) : + _title(title), _length(0), _print_sum(print_sum), _log_level(log_level), _indent_level(indent_level), + _has_new_data(true), _thread_work_items(NULL), _enabled(true) { + assert(length > 0, "Must have some workers to store data for"); + _length = length; + _data = NEW_C_HEAP_ARRAY(T, _length, mtGC); } - T min = _data[0]; - T max = _data[0]; - T sum = 0; + ~WorkerDataArray() { + FREE_C_HEAP_ARRAY(T, _data); + } - LineBuffer buf(level); - buf.append("[%s:", title); - for (uint i = 0; i < _length; ++i) { - T val = _data[i]; - min = MIN2(val, min); - max = MAX2(val, max); - sum += val; - if (G1Log::finest()) { - buf.append(" "); - buf.append(_print_format, val); + void link_thread_work_items(WorkerDataArray* thread_work_items) { + _thread_work_items = thread_work_items; + } + + WorkerDataArray* thread_work_items() { return _thread_work_items; } + + void set(uint worker_i, T value) { + assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); + assert(_data[worker_i] == WorkerDataArray::uninitialized(), err_msg("Overwriting data for worker %d in %s", worker_i, _title)); + _data[worker_i] = value; + _has_new_data = true; + } + + void set_thread_work_item(uint worker_i, size_t value) { + assert(_thread_work_items != NULL, "No sub count"); + _thread_work_items->set(worker_i, value); + } + + T get(uint worker_i) { + assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); + assert(_data[worker_i] != WorkerDataArray::uninitialized(), err_msg("No data added for worker %d", worker_i)); + return _data[worker_i]; + } + + void add(uint worker_i, T value) { + assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); + assert(_data[worker_i] != WorkerDataArray::uninitialized(), err_msg("No data to add to for worker %d", worker_i)); + _data[worker_i] += value; + _has_new_data = true; + } + + double average(){ + calculate_totals(); + return _average; + } + + T sum() { + calculate_totals(); + return _sum; + } + + T minimum() { + calculate_totals(); + return _min; + } + + T maximum() { + calculate_totals(); + return _max; + } + + void reset() PRODUCT_RETURN; + void verify() PRODUCT_RETURN; + + void set_enabled(bool enabled) { _enabled = enabled; } + + int log_level() { return _log_level; } + + private: + + void calculate_totals(){ + if (!_has_new_data) { + return; } - } - if (G1Log::finest()) { - buf.append_and_print_cr("%s", ""); + _sum = (T)0; + _min = _data[0]; + _max = _min; + for (uint i = 0; i < _length; ++i) { + T val = _data[i]; + _sum += val; + _min = MIN2(_min, val); + _max = MAX2(_max, val); + } + _average = (double)_sum / (double)_length; + _has_new_data = false; } +}; - double avg = (double)sum / (double)_length; - buf.append(" Min: "); - buf.append(_print_format, min); - buf.append(", Avg: "); - buf.append("%.1lf", avg); // Always print average as a double - buf.append(", Max: "); - buf.append(_print_format, max); - buf.append(", Diff: "); - buf.append(_print_format, max - min); - if (_print_sum) { - // for things like the start and end times the sum is not - // that relevant - buf.append(", Sum: "); - buf.append(_print_format, sum); - } - buf.append_and_print_cr("]"); -} -PRAGMA_DIAG_POP #ifndef PRODUCT -template <> const int WorkerDataArray::_uninitialized = -1; -template <> const double WorkerDataArray::_uninitialized = -1.0; -template <> const size_t WorkerDataArray::_uninitialized = (size_t)-1; +template <> +size_t WorkerDataArray::uninitialized() { + return (size_t)-1; +} + +template <> +double WorkerDataArray::uninitialized() { + return -1.0; +} template void WorkerDataArray::reset() { for (uint i = 0; i < _length; i++) { - _data[i] = (T)_uninitialized; + _data[i] = WorkerDataArray::uninitialized(); + } + if (_thread_work_items != NULL) { + _thread_work_items->reset(); } } template void WorkerDataArray::verify() { + if (!_enabled) { + return; + } + for (uint i = 0; i < _length; i++) { - assert(_data[i] != _uninitialized, - err_msg("Invalid data for worker %u, data: %lf, uninitialized: %lf", - i, (double)_data[i], (double)_uninitialized)); + assert(_data[i] != WorkerDataArray::uninitialized(), + err_msg("Invalid data for worker %u in '%s'", i, _title)); + } + if (_thread_work_items != NULL) { + _thread_work_items->verify(); } } #endif G1GCPhaseTimes::G1GCPhaseTimes(uint max_gc_threads) : - _max_gc_threads(max_gc_threads), - _last_gc_worker_start_times_ms(_max_gc_threads, "%.1lf", false), - _last_ext_root_scan_times_ms(_max_gc_threads, "%.1lf"), - _last_satb_filtering_times_ms(_max_gc_threads, "%.1lf"), - _last_update_rs_times_ms(_max_gc_threads, "%.1lf"), - _last_update_rs_processed_buffers(_max_gc_threads, "%d"), - _last_scan_rs_times_ms(_max_gc_threads, "%.1lf"), - _last_strong_code_root_scan_times_ms(_max_gc_threads, "%.1lf"), - _last_obj_copy_times_ms(_max_gc_threads, "%.1lf"), - _last_termination_times_ms(_max_gc_threads, "%.1lf"), - _last_termination_attempts(_max_gc_threads, SIZE_FORMAT), - _last_gc_worker_end_times_ms(_max_gc_threads, "%.1lf", false), - _last_gc_worker_times_ms(_max_gc_threads, "%.1lf"), - _last_gc_worker_other_times_ms(_max_gc_threads, "%.1lf"), - _last_redirty_logged_cards_time_ms(_max_gc_threads, "%.1lf"), - _last_redirty_logged_cards_processed_cards(_max_gc_threads, SIZE_FORMAT), - _cur_string_dedup_queue_fixup_worker_times_ms(_max_gc_threads, "%.1lf"), - _cur_string_dedup_table_fixup_worker_times_ms(_max_gc_threads, "%.1lf") + _max_gc_threads(max_gc_threads) { assert(max_gc_threads > 0, "Must have some GC threads"); + + _gc_par_phases[GCWorkerStart] = new WorkerDataArray(max_gc_threads, "GC Worker Start (ms)", false, G1Log::LevelFiner, 2); + _gc_par_phases[ExtRootScan] = new WorkerDataArray(max_gc_threads, "Ext Root Scanning (ms)", true, G1Log::LevelFiner, 2); + _gc_par_phases[SATBFiltering] = new WorkerDataArray(max_gc_threads, "SATB Filtering (ms)", true, G1Log::LevelFiner, 2); + _gc_par_phases[UpdateRS] = new WorkerDataArray(max_gc_threads, "Update RS (ms)", true, G1Log::LevelFiner, 2); + _gc_par_phases[ScanRS] = new WorkerDataArray(max_gc_threads, "Scan RS (ms)", true, G1Log::LevelFiner, 2); + _gc_par_phases[CodeRoots] = new WorkerDataArray(max_gc_threads, "Code Root Scanning (ms)", true, G1Log::LevelFiner, 2); + _gc_par_phases[ObjCopy] = new WorkerDataArray(max_gc_threads, "Object Copy (ms)", true, G1Log::LevelFiner, 2); + _gc_par_phases[Termination] = new WorkerDataArray(max_gc_threads, "Termination (ms)", true, G1Log::LevelFiner, 2); + _gc_par_phases[GCWorkerTotal] = new WorkerDataArray(max_gc_threads, "GC Worker Total (ms)", true, G1Log::LevelFiner, 2); + _gc_par_phases[GCWorkerEnd] = new WorkerDataArray(max_gc_threads, "GC Worker End (ms)", false, G1Log::LevelFiner, 2); + _gc_par_phases[Other] = new WorkerDataArray(max_gc_threads, "GC Worker Other (ms)", true, G1Log::LevelFiner, 2); + + _update_rs_processed_buffers = new WorkerDataArray(max_gc_threads, "Processed Buffers", true, G1Log::LevelFiner, 3); + _gc_par_phases[UpdateRS]->link_thread_work_items(_update_rs_processed_buffers); + + _termination_attempts = new WorkerDataArray(max_gc_threads, "Termination Attempts", true, G1Log::LevelFinest, 3); + _gc_par_phases[Termination]->link_thread_work_items(_termination_attempts); + + _gc_par_phases[StringDedupQueueFixup] = new WorkerDataArray(max_gc_threads, "Queue Fixup (ms)", true, G1Log::LevelFiner, 2); + _gc_par_phases[StringDedupTableFixup] = new WorkerDataArray(max_gc_threads, "Table Fixup (ms)", true, G1Log::LevelFiner, 2); + + _gc_par_phases[RedirtyCards] = new WorkerDataArray(max_gc_threads, "Parallel Redirty", true, G1Log::LevelFinest, 3); + _redirtied_cards = new WorkerDataArray(max_gc_threads, "Redirtied Cards", true, G1Log::LevelFinest, 3); + _gc_par_phases[RedirtyCards]->link_thread_work_items(_redirtied_cards); } -void G1GCPhaseTimes::note_gc_start(uint active_gc_threads) { +void G1GCPhaseTimes::note_gc_start(uint active_gc_threads, bool mark_in_progress) { assert(active_gc_threads > 0, "The number of threads must be > 0"); - assert(active_gc_threads <= _max_gc_threads, "The number of active threads must be <= the max nubmer of threads"); + assert(active_gc_threads <= _max_gc_threads, "The number of active threads must be <= the max number of threads"); _active_gc_threads = active_gc_threads; - _last_gc_worker_start_times_ms.reset(); - _last_ext_root_scan_times_ms.reset(); - _last_satb_filtering_times_ms.reset(); - _last_update_rs_times_ms.reset(); - _last_update_rs_processed_buffers.reset(); - _last_scan_rs_times_ms.reset(); - _last_strong_code_root_scan_times_ms.reset(); - _last_obj_copy_times_ms.reset(); - _last_termination_times_ms.reset(); - _last_termination_attempts.reset(); - _last_gc_worker_end_times_ms.reset(); - _last_gc_worker_times_ms.reset(); - _last_gc_worker_other_times_ms.reset(); + for (int i = 0; i < GCParPhasesSentinel; i++) { + _gc_par_phases[i]->reset(); + } - _last_redirty_logged_cards_time_ms.reset(); - _last_redirty_logged_cards_processed_cards.reset(); + _gc_par_phases[SATBFiltering]->set_enabled(mark_in_progress); + _gc_par_phases[StringDedupQueueFixup]->set_enabled(G1StringDedup::is_enabled()); + _gc_par_phases[StringDedupTableFixup]->set_enabled(G1StringDedup::is_enabled()); } void G1GCPhaseTimes::note_gc_end() { - _last_gc_worker_start_times_ms.verify(); - _last_ext_root_scan_times_ms.verify(); - _last_satb_filtering_times_ms.verify(); - _last_update_rs_times_ms.verify(); - _last_update_rs_processed_buffers.verify(); - _last_scan_rs_times_ms.verify(); - _last_strong_code_root_scan_times_ms.verify(); - _last_obj_copy_times_ms.verify(); - _last_termination_times_ms.verify(); - _last_termination_attempts.verify(); - _last_gc_worker_end_times_ms.verify(); - for (uint i = 0; i < _active_gc_threads; i++) { - double worker_time = _last_gc_worker_end_times_ms.get(i) - _last_gc_worker_start_times_ms.get(i); - _last_gc_worker_times_ms.set(i, worker_time); + double worker_time = _gc_par_phases[GCWorkerEnd]->get(i) - _gc_par_phases[GCWorkerStart]->get(i); + record_time_secs(GCWorkerTotal, i , worker_time); - double worker_known_time = _last_ext_root_scan_times_ms.get(i) + - _last_satb_filtering_times_ms.get(i) + - _last_update_rs_times_ms.get(i) + - _last_scan_rs_times_ms.get(i) + - _last_strong_code_root_scan_times_ms.get(i) + - _last_obj_copy_times_ms.get(i) + - _last_termination_times_ms.get(i); + double worker_known_time = + _gc_par_phases[ExtRootScan]->get(i) + + _gc_par_phases[SATBFiltering]->get(i) + + _gc_par_phases[UpdateRS]->get(i) + + _gc_par_phases[ScanRS]->get(i) + + _gc_par_phases[CodeRoots]->get(i) + + _gc_par_phases[ObjCopy]->get(i) + + _gc_par_phases[Termination]->get(i); - double worker_other_time = worker_time - worker_known_time; - _last_gc_worker_other_times_ms.set(i, worker_other_time); + record_time_secs(Other, i, worker_time - worker_known_time); } - _last_gc_worker_times_ms.verify(); - _last_gc_worker_other_times_ms.verify(); - - _last_redirty_logged_cards_time_ms.verify(); - _last_redirty_logged_cards_processed_cards.verify(); -} - -void G1GCPhaseTimes::note_string_dedup_fixup_start() { - _cur_string_dedup_queue_fixup_worker_times_ms.reset(); - _cur_string_dedup_table_fixup_worker_times_ms.reset(); -} - -void G1GCPhaseTimes::note_string_dedup_fixup_end() { - _cur_string_dedup_queue_fixup_worker_times_ms.verify(); - _cur_string_dedup_table_fixup_worker_times_ms.verify(); + for (int i = 0; i < GCParPhasesSentinel; i++) { + _gc_par_phases[i]->verify(); + } } void G1GCPhaseTimes::print_stats(int level, const char* str, double value) { @@ -288,35 +347,172 @@ double G1GCPhaseTimes::accounted_time_ms() { return misc_time_ms; } +// record the time a phase took in seconds +void G1GCPhaseTimes::record_time_secs(GCParPhases phase, uint worker_i, double secs) { + _gc_par_phases[phase]->set(worker_i, secs); +} + +// add a number of seconds to a phase +void G1GCPhaseTimes::add_time_secs(GCParPhases phase, uint worker_i, double secs) { + _gc_par_phases[phase]->add(worker_i, secs); +} + +void G1GCPhaseTimes::record_thread_work_item(GCParPhases phase, uint worker_i, size_t count) { + _gc_par_phases[phase]->set_thread_work_item(worker_i, count); +} + +// return the average time for a phase in milliseconds +double G1GCPhaseTimes::average_time_ms(GCParPhases phase) { + return _gc_par_phases[phase]->average() * 1000.0; +} + +double G1GCPhaseTimes::get_time_ms(GCParPhases phase, uint worker_i) { + return _gc_par_phases[phase]->get(worker_i) * 1000.0; +} + +double G1GCPhaseTimes::sum_time_ms(GCParPhases phase) { + return _gc_par_phases[phase]->sum() * 1000.0; +} + +double G1GCPhaseTimes::min_time_ms(GCParPhases phase) { + return _gc_par_phases[phase]->minimum() * 1000.0; +} + +double G1GCPhaseTimes::max_time_ms(GCParPhases phase) { + return _gc_par_phases[phase]->maximum() * 1000.0; +} + +size_t G1GCPhaseTimes::get_thread_work_item(GCParPhases phase, uint worker_i) { + assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); + return _gc_par_phases[phase]->thread_work_items()->get(worker_i); +} + +size_t G1GCPhaseTimes::sum_thread_work_items(GCParPhases phase) { + assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); + return _gc_par_phases[phase]->thread_work_items()->sum(); +} + +double G1GCPhaseTimes::average_thread_work_items(GCParPhases phase) { + assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); + return _gc_par_phases[phase]->thread_work_items()->average(); +} + +size_t G1GCPhaseTimes::min_thread_work_items(GCParPhases phase) { + assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); + return _gc_par_phases[phase]->thread_work_items()->minimum(); +} + +size_t G1GCPhaseTimes::max_thread_work_items(GCParPhases phase) { + assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); + return _gc_par_phases[phase]->thread_work_items()->maximum(); +} + +class G1GCParPhasePrinter : public StackObj { + G1GCPhaseTimes* _phase_times; + public: + G1GCParPhasePrinter(G1GCPhaseTimes* phase_times) : _phase_times(phase_times) {} + + void print(G1GCPhaseTimes::GCParPhases phase_id) { + WorkerDataArray* phase = _phase_times->_gc_par_phases[phase_id]; + + if (phase->_log_level > G1Log::level() || !phase->_enabled) { + return; + } + + if (phase->_length == 1) { + print_single_length(phase_id, phase); + } else { + print_multi_length(phase_id, phase); + } + } + + private: + + void print_single_length(G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray* phase) { + // No need for min, max, average and sum for only one worker + LineBuffer buf(phase->_indent_level); + buf.append_and_print_cr("[%s: %.1lf]", phase->_title, _phase_times->get_time_ms(phase_id, 0)); + + if (phase->_thread_work_items != NULL) { + LineBuffer buf2(phase->_thread_work_items->_indent_level); + buf2.append_and_print_cr("[%s: "SIZE_FORMAT"]", phase->_thread_work_items->_title, _phase_times->sum_thread_work_items(phase_id)); + } + } + + void print_time_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray* phase) { + for (uint i = 0; i < phase->_length; ++i) { + buf.append(" %.1lf", _phase_times->get_time_ms(phase_id, i)); + } + buf.print_cr(); + } + + void print_count_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray* thread_work_items) { + for (uint i = 0; i < thread_work_items->_length; ++i) { + buf.append(" " SIZE_FORMAT, _phase_times->get_thread_work_item(phase_id, i)); + } + buf.print_cr(); + } + + void print_thread_work_items(G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray* thread_work_items) { + LineBuffer buf(thread_work_items->_indent_level); + buf.append("[%s:", thread_work_items->_title); + + if (G1Log::finest()) { + print_count_values(buf, phase_id, thread_work_items); + } + + assert(thread_work_items->_print_sum, err_msg("%s does not have print sum true even though it is a count", thread_work_items->_title)); + + buf.append_and_print_cr(" Min: " SIZE_FORMAT ", Avg: %.1lf, Max: " SIZE_FORMAT ", Diff: " SIZE_FORMAT ", Sum: " SIZE_FORMAT "]", + _phase_times->min_thread_work_items(phase_id), _phase_times->average_thread_work_items(phase_id), _phase_times->max_thread_work_items(phase_id), + _phase_times->max_thread_work_items(phase_id) - _phase_times->min_thread_work_items(phase_id), _phase_times->sum_thread_work_items(phase_id)); + } + + void print_multi_length(G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray* phase) { + LineBuffer buf(phase->_indent_level); + buf.append("[%s:", phase->_title); + + if (G1Log::finest()) { + print_time_values(buf, phase_id, phase); + } + + buf.append(" Min: %.1lf, Avg: %.1lf, Max: %.1lf, Diff: %.1lf", + _phase_times->min_time_ms(phase_id), _phase_times->average_time_ms(phase_id), _phase_times->max_time_ms(phase_id), + _phase_times->max_time_ms(phase_id) - _phase_times->min_time_ms(phase_id)); + + if (phase->_print_sum) { + // for things like the start and end times the sum is not + // that relevant + buf.append(", Sum: %.1lf", _phase_times->sum_time_ms(phase_id)); + } + + buf.append_and_print_cr("]"); + + if (phase->_thread_work_items != NULL) { + print_thread_work_items(phase_id, phase->_thread_work_items); + } + } +}; + void G1GCPhaseTimes::print(double pause_time_sec) { + G1GCParPhasePrinter par_phase_printer(this); + if (_root_region_scan_wait_time_ms > 0.0) { print_stats(1, "Root Region Scan Waiting", _root_region_scan_wait_time_ms); } + print_stats(1, "Parallel Time", _cur_collection_par_time_ms, _active_gc_threads); - _last_gc_worker_start_times_ms.print(2, "GC Worker Start (ms)"); - _last_ext_root_scan_times_ms.print(2, "Ext Root Scanning (ms)"); - if (_last_satb_filtering_times_ms.sum() > 0.0) { - _last_satb_filtering_times_ms.print(2, "SATB Filtering (ms)"); + for (int i = 0; i <= GCMainParPhasesLast; i++) { + par_phase_printer.print((GCParPhases) i); } - _last_update_rs_times_ms.print(2, "Update RS (ms)"); - _last_update_rs_processed_buffers.print(3, "Processed Buffers"); - _last_scan_rs_times_ms.print(2, "Scan RS (ms)"); - _last_strong_code_root_scan_times_ms.print(2, "Code Root Scanning (ms)"); - _last_obj_copy_times_ms.print(2, "Object Copy (ms)"); - _last_termination_times_ms.print(2, "Termination (ms)"); - if (G1Log::finest()) { - _last_termination_attempts.print(3, "Termination Attempts"); - } - _last_gc_worker_other_times_ms.print(2, "GC Worker Other (ms)"); - _last_gc_worker_times_ms.print(2, "GC Worker Total (ms)"); - _last_gc_worker_end_times_ms.print(2, "GC Worker End (ms)"); print_stats(1, "Code Root Fixup", _cur_collection_code_root_fixup_time_ms); print_stats(1, "Code Root Purge", _cur_strong_code_root_purge_time_ms); if (G1StringDedup::is_enabled()) { print_stats(1, "String Dedup Fixup", _cur_string_dedup_fixup_time_ms, _active_gc_threads); - _cur_string_dedup_queue_fixup_worker_times_ms.print(2, "Queue Fixup (ms)"); - _cur_string_dedup_table_fixup_worker_times_ms.print(2, "Table Fixup (ms)"); + for (int i = StringDedupPhasesFirst; i <= StringDedupPhasesLast; i++) { + par_phase_printer.print((GCParPhases) i); + } } print_stats(1, "Clear CT", _cur_clear_ct_time_ms); double misc_time_ms = pause_time_sec * MILLIUNITS - accounted_time_ms(); @@ -340,10 +536,7 @@ void G1GCPhaseTimes::print(double pause_time_sec) { print_stats(2, "Ref Proc", _cur_ref_proc_time_ms); print_stats(2, "Ref Enq", _cur_ref_enq_time_ms); print_stats(2, "Redirty Cards", _recorded_redirty_logged_cards_time_ms); - if (G1Log::finest()) { - _last_redirty_logged_cards_time_ms.print(3, "Parallel Redirty"); - _last_redirty_logged_cards_processed_cards.print(3, "Redirtied Cards"); - } + par_phase_printer.print(RedirtyCards); if (G1EagerReclaimHumongousObjects) { print_stats(2, "Humongous Register", _cur_fast_reclaim_humongous_register_time_ms); if (G1Log::finest()) { @@ -366,3 +559,17 @@ void G1GCPhaseTimes::print(double pause_time_sec) { print_stats(2, "Verify After", _cur_verify_after_time_ms); } } + +G1GCParPhaseTimesTracker::G1GCParPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1GCPhaseTimes::GCParPhases phase, uint worker_id) : + _phase_times(phase_times), _phase(phase), _worker_id(worker_id) { + if (_phase_times != NULL) { + _start_time = os::elapsedTime(); + } +} + +G1GCParPhaseTimesTracker::~G1GCParPhaseTimesTracker() { + if (_phase_times != NULL) { + _phase_times->record_time_secs(_phase, _worker_id, os::elapsedTime() - _start_time); + } +} + diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.hpp index 0c6c3312aa1..6eeb11c4dca 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.hpp @@ -26,106 +26,46 @@ #define SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP #include "memory/allocation.hpp" -#include "gc_interface/gcCause.hpp" -template -class WorkerDataArray : public CHeapObj { - T* _data; - uint _length; - const char* _print_format; - bool _print_sum; +class LineBuffer; - NOT_PRODUCT(static const T _uninitialized;) - - // We are caching the sum and average to only have to calculate them once. - // This is not done in an MT-safe way. It is intended to allow single - // threaded code to call sum() and average() multiple times in any order - // without having to worry about the cost. - bool _has_new_data; - T _sum; - double _average; - - public: - WorkerDataArray(uint length, const char* print_format, bool print_sum = true) : - _length(length), _print_format(print_format), _print_sum(print_sum), _has_new_data(true) { - assert(length > 0, "Must have some workers to store data for"); - _data = NEW_C_HEAP_ARRAY(T, _length, mtGC); - } - - ~WorkerDataArray() { - FREE_C_HEAP_ARRAY(T, _data); - } - - void set(uint worker_i, T value) { - assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); - assert(_data[worker_i] == (T)-1, err_msg("Overwriting data for worker %d", worker_i)); - _data[worker_i] = value; - _has_new_data = true; - } - - T get(uint worker_i) { - assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); - assert(_data[worker_i] != (T)-1, err_msg("No data to add to for worker %d", worker_i)); - return _data[worker_i]; - } - - void add(uint worker_i, T value) { - assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); - assert(_data[worker_i] != (T)-1, err_msg("No data to add to for worker %d", worker_i)); - _data[worker_i] += value; - _has_new_data = true; - } - - double average(){ - if (_has_new_data) { - calculate_totals(); - } - return _average; - } - - T sum() { - if (_has_new_data) { - calculate_totals(); - } - return _sum; - } - - void print(int level, const char* title); - - void reset() PRODUCT_RETURN; - void verify() PRODUCT_RETURN; - - private: - - void calculate_totals(){ - _sum = (T)0; - for (uint i = 0; i < _length; ++i) { - _sum += _data[i]; - } - _average = (double)_sum / (double)_length; - _has_new_data = false; - } -}; +template class WorkerDataArray; class G1GCPhaseTimes : public CHeapObj { + friend class G1GCParPhasePrinter; - private: uint _active_gc_threads; uint _max_gc_threads; - WorkerDataArray _last_gc_worker_start_times_ms; - WorkerDataArray _last_ext_root_scan_times_ms; - WorkerDataArray _last_satb_filtering_times_ms; - WorkerDataArray _last_update_rs_times_ms; - WorkerDataArray _last_update_rs_processed_buffers; - WorkerDataArray _last_scan_rs_times_ms; - WorkerDataArray _last_strong_code_root_scan_times_ms; - WorkerDataArray _last_obj_copy_times_ms; - WorkerDataArray _last_termination_times_ms; - WorkerDataArray _last_termination_attempts; - WorkerDataArray _last_gc_worker_end_times_ms; - WorkerDataArray _last_gc_worker_times_ms; - WorkerDataArray _last_gc_worker_other_times_ms; + public: + enum GCParPhases { + GCWorkerStart, + ExtRootScan, + SATBFiltering, + UpdateRS, + ScanRS, + CodeRoots, + ObjCopy, + Termination, + Other, + GCWorkerTotal, + GCWorkerEnd, + StringDedupQueueFixup, + StringDedupTableFixup, + RedirtyCards, + GCParPhasesSentinel + }; + + private: + // Markers for grouping the phases in the GCPhases enum above + static const int GCMainParPhasesLast = GCWorkerEnd; + static const int StringDedupPhasesFirst = StringDedupQueueFixup; + static const int StringDedupPhasesLast = StringDedupTableFixup; + + WorkerDataArray* _gc_par_phases[GCParPhasesSentinel]; + WorkerDataArray* _update_rs_processed_buffers; + WorkerDataArray* _termination_attempts; + WorkerDataArray* _redirtied_cards; double _cur_collection_par_time_ms; double _cur_collection_code_root_fixup_time_ms; @@ -135,9 +75,7 @@ class G1GCPhaseTimes : public CHeapObj { double _cur_evac_fail_restore_remsets; double _cur_evac_fail_remove_self_forwards; - double _cur_string_dedup_fixup_time_ms; - WorkerDataArray _cur_string_dedup_queue_fixup_worker_times_ms; - WorkerDataArray _cur_string_dedup_table_fixup_worker_times_ms; + double _cur_string_dedup_fixup_time_ms; double _cur_clear_ct_time_ms; double _cur_ref_proc_time_ms; @@ -149,8 +87,6 @@ class G1GCPhaseTimes : public CHeapObj { double _recorded_young_cset_choice_time_ms; double _recorded_non_young_cset_choice_time_ms; - WorkerDataArray _last_redirty_logged_cards_time_ms; - WorkerDataArray _last_redirty_logged_cards_processed_cards; double _recorded_redirty_logged_cards_time_ms; double _recorded_young_free_cset_time_ms; @@ -172,54 +108,34 @@ class G1GCPhaseTimes : public CHeapObj { public: G1GCPhaseTimes(uint max_gc_threads); - void note_gc_start(uint active_gc_threads); + void note_gc_start(uint active_gc_threads, bool mark_in_progress); void note_gc_end(); void print(double pause_time_sec); - void record_gc_worker_start_time(uint worker_i, double ms) { - _last_gc_worker_start_times_ms.set(worker_i, ms); - } + // record the time a phase took in seconds + void record_time_secs(GCParPhases phase, uint worker_i, double secs); - void record_ext_root_scan_time(uint worker_i, double ms) { - _last_ext_root_scan_times_ms.set(worker_i, ms); - } + // add a number of seconds to a phase + void add_time_secs(GCParPhases phase, uint worker_i, double secs); - void record_satb_filtering_time(uint worker_i, double ms) { - _last_satb_filtering_times_ms.set(worker_i, ms); - } + void record_thread_work_item(GCParPhases phase, uint worker_i, size_t count); - void record_update_rs_time(uint worker_i, double ms) { - _last_update_rs_times_ms.set(worker_i, ms); - } + // return the average time for a phase in milliseconds + double average_time_ms(GCParPhases phase); - void record_update_rs_processed_buffers(uint worker_i, int processed_buffers) { - _last_update_rs_processed_buffers.set(worker_i, processed_buffers); - } + size_t sum_thread_work_items(GCParPhases phase); - void record_scan_rs_time(uint worker_i, double ms) { - _last_scan_rs_times_ms.set(worker_i, ms); - } + private: + double get_time_ms(GCParPhases phase, uint worker_i); + double sum_time_ms(GCParPhases phase); + double min_time_ms(GCParPhases phase); + double max_time_ms(GCParPhases phase); + size_t get_thread_work_item(GCParPhases phase, uint worker_i); + double average_thread_work_items(GCParPhases phase); + size_t min_thread_work_items(GCParPhases phase); + size_t max_thread_work_items(GCParPhases phase); - void record_strong_code_root_scan_time(uint worker_i, double ms) { - _last_strong_code_root_scan_times_ms.set(worker_i, ms); - } - - void record_obj_copy_time(uint worker_i, double ms) { - _last_obj_copy_times_ms.set(worker_i, ms); - } - - void add_obj_copy_time(uint worker_i, double ms) { - _last_obj_copy_times_ms.add(worker_i, ms); - } - - void record_termination(uint worker_i, double ms, size_t attempts) { - _last_termination_times_ms.set(worker_i, ms); - _last_termination_attempts.set(worker_i, attempts); - } - - void record_gc_worker_end_time(uint worker_i, double ms) { - _last_gc_worker_end_times_ms.set(worker_i, ms); - } + public: void record_clear_ct_time(double ms) { _cur_clear_ct_time_ms = ms; @@ -249,21 +165,10 @@ class G1GCPhaseTimes : public CHeapObj { _cur_evac_fail_remove_self_forwards = ms; } - void note_string_dedup_fixup_start(); - void note_string_dedup_fixup_end(); - void record_string_dedup_fixup_time(double ms) { _cur_string_dedup_fixup_time_ms = ms; } - void record_string_dedup_queue_fixup_worker_time(uint worker_id, double ms) { - _cur_string_dedup_queue_fixup_worker_times_ms.set(worker_id, ms); - } - - void record_string_dedup_table_fixup_worker_time(uint worker_id, double ms) { - _cur_string_dedup_table_fixup_worker_times_ms.set(worker_id, ms); - } - void record_ref_proc_time(double ms) { _cur_ref_proc_time_ms = ms; } @@ -303,14 +208,6 @@ class G1GCPhaseTimes : public CHeapObj { _recorded_non_young_cset_choice_time_ms = time_ms; } - void record_redirty_logged_cards_time_ms(uint worker_i, double time_ms) { - _last_redirty_logged_cards_time_ms.set(worker_i, time_ms); - } - - void record_redirty_logged_cards_processed_cards(uint worker_i, size_t processed_buffers) { - _last_redirty_logged_cards_processed_cards.set(worker_i, processed_buffers); - } - void record_redirty_logged_cards_time_ms(double time_ms) { _recorded_redirty_logged_cards_time_ms = time_ms; } @@ -364,38 +261,16 @@ class G1GCPhaseTimes : public CHeapObj { double fast_reclaim_humongous_time_ms() { return _cur_fast_reclaim_humongous_time_ms; } +}; - double average_last_update_rs_time() { - return _last_update_rs_times_ms.average(); - } - - int sum_last_update_rs_processed_buffers() { - return _last_update_rs_processed_buffers.sum(); - } - - double average_last_scan_rs_time(){ - return _last_scan_rs_times_ms.average(); - } - - double average_last_strong_code_root_scan_time(){ - return _last_strong_code_root_scan_times_ms.average(); - } - - double average_last_obj_copy_time() { - return _last_obj_copy_times_ms.average(); - } - - double average_last_termination_time() { - return _last_termination_times_ms.average(); - } - - double average_last_ext_root_scan_time() { - return _last_ext_root_scan_times_ms.average(); - } - - double average_last_satb_filtering_times_ms() { - return _last_satb_filtering_times_ms.average(); - } +class G1GCParPhaseTimesTracker : public StackObj { + double _start_time; + G1GCPhaseTimes::GCParPhases _phase; + G1GCPhaseTimes* _phase_times; + uint _worker_id; +public: + G1GCParPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1GCPhaseTimes::GCParPhases phase, uint worker_id); + ~G1GCParPhaseTimesTracker(); }; #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1Log.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1Log.hpp index b8da001cfd6..6f72c8fbc8e 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1Log.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1Log.hpp @@ -28,6 +28,7 @@ #include "memory/allocation.hpp" class G1Log : public AllStatic { + public: typedef enum { LevelNone, LevelFine, @@ -35,6 +36,7 @@ class G1Log : public AllStatic { LevelFinest } LogLevel; + private: static LogLevel _level; public: @@ -50,6 +52,10 @@ class G1Log : public AllStatic { return _level == LevelFinest; } + static LogLevel level() { + return _level; + } + static void init(); }; diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp index 010a8dd7b80..e26daa7601d 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp @@ -248,9 +248,8 @@ void G1RemSet::scanRS(G1ParPushHeapRSClosure* oc, assert(_cards_scanned != NULL, "invariant"); _cards_scanned[worker_i] = scanRScl.cards_done(); - _g1p->phase_times()->record_scan_rs_time(worker_i, scan_rs_time_sec * 1000.0); - _g1p->phase_times()->record_strong_code_root_scan_time(worker_i, - scanRScl.strong_code_root_scan_time_sec() * 1000.0); + _g1p->phase_times()->record_time_secs(G1GCPhaseTimes::ScanRS, worker_i, scan_rs_time_sec); + _g1p->phase_times()->record_time_secs(G1GCPhaseTimes::CodeRoots, worker_i, scanRScl.strong_code_root_scan_time_sec()); } // Closure used for updating RSets and recording references that @@ -287,13 +286,11 @@ public: }; void G1RemSet::updateRS(DirtyCardQueue* into_cset_dcq, uint worker_i) { - double start = os::elapsedTime(); + G1GCParPhaseTimesTracker x(_g1p->phase_times(), G1GCPhaseTimes::UpdateRS, worker_i); // Apply the given closure to all remaining log entries. RefineRecordRefsIntoCSCardTableEntryClosure into_cset_update_rs_cl(_g1, into_cset_dcq); _g1->iterate_dirty_card_closure(&into_cset_update_rs_cl, into_cset_dcq, false, worker_i); - - _g1p->phase_times()->record_update_rs_time(worker_i, (os::elapsedTime() - start) * 1000.0); } void G1RemSet::cleanupHRRS() { diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1StringDedup.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1StringDedup.cpp index a929b0faa42..4b3819800c3 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1StringDedup.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1StringDedup.cpp @@ -106,7 +106,7 @@ void G1StringDedup::deduplicate(oop java_string) { void G1StringDedup::oops_do(OopClosure* keep_alive) { assert(is_enabled(), "String deduplication not enabled"); - unlink_or_oops_do(NULL, keep_alive); + unlink_or_oops_do(NULL, keep_alive, true /* allow_resize_and_rehash */); } void G1StringDedup::unlink(BoolObjectClosure* is_alive) { @@ -123,45 +123,39 @@ void G1StringDedup::unlink(BoolObjectClosure* is_alive) { class G1StringDedupUnlinkOrOopsDoTask : public AbstractGangTask { private: G1StringDedupUnlinkOrOopsDoClosure _cl; + G1GCPhaseTimes* _phase_times; public: G1StringDedupUnlinkOrOopsDoTask(BoolObjectClosure* is_alive, OopClosure* keep_alive, - bool allow_resize_and_rehash) : + bool allow_resize_and_rehash, + G1GCPhaseTimes* phase_times) : AbstractGangTask("G1StringDedupUnlinkOrOopsDoTask"), - _cl(is_alive, keep_alive, allow_resize_and_rehash) { - } + _cl(is_alive, keep_alive, allow_resize_and_rehash), _phase_times(phase_times) { } virtual void work(uint worker_id) { - double queue_fixup_start = os::elapsedTime(); - G1StringDedupQueue::unlink_or_oops_do(&_cl); - - double table_fixup_start = os::elapsedTime(); - G1StringDedupTable::unlink_or_oops_do(&_cl, worker_id); - - double queue_fixup_time_ms = (table_fixup_start - queue_fixup_start) * 1000.0; - double table_fixup_time_ms = (os::elapsedTime() - table_fixup_start) * 1000.0; - G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy(); - g1p->phase_times()->record_string_dedup_queue_fixup_worker_time(worker_id, queue_fixup_time_ms); - g1p->phase_times()->record_string_dedup_table_fixup_worker_time(worker_id, table_fixup_time_ms); + { + G1GCParPhaseTimesTracker x(_phase_times, G1GCPhaseTimes::StringDedupQueueFixup, worker_id); + G1StringDedupQueue::unlink_or_oops_do(&_cl); + } + { + G1GCParPhaseTimesTracker x(_phase_times, G1GCPhaseTimes::StringDedupTableFixup, worker_id); + G1StringDedupTable::unlink_or_oops_do(&_cl, worker_id); + } } }; -void G1StringDedup::unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, bool allow_resize_and_rehash) { +void G1StringDedup::unlink_or_oops_do(BoolObjectClosure* is_alive, + OopClosure* keep_alive, + bool allow_resize_and_rehash, + G1GCPhaseTimes* phase_times) { assert(is_enabled(), "String deduplication not enabled"); - G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy(); - g1p->phase_times()->note_string_dedup_fixup_start(); - double fixup_start = os::elapsedTime(); - G1StringDedupUnlinkOrOopsDoTask task(is_alive, keep_alive, allow_resize_and_rehash); + G1StringDedupUnlinkOrOopsDoTask task(is_alive, keep_alive, allow_resize_and_rehash, phase_times); G1CollectedHeap* g1h = G1CollectedHeap::heap(); g1h->set_par_threads(); g1h->workers()->run_task(&task); g1h->set_par_threads(0); - - double fixup_time_ms = (os::elapsedTime() - fixup_start) * 1000.0; - g1p->phase_times()->record_string_dedup_fixup_time(fixup_time_ms); - g1p->phase_times()->note_string_dedup_fixup_end(); } void G1StringDedup::threads_do(ThreadClosure* tc) { diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1StringDedup.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1StringDedup.hpp index 80ee1fd02ad..71c75bc2bbf 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1StringDedup.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1StringDedup.hpp @@ -91,6 +91,7 @@ class BoolObjectClosure; class ThreadClosure; class outputStream; class G1StringDedupTable; +class G1GCPhaseTimes; // // Main interface for interacting with string deduplication. @@ -131,7 +132,7 @@ public: static void oops_do(OopClosure* keep_alive); static void unlink(BoolObjectClosure* is_alive); static void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, - bool allow_resize_and_rehash = true); + bool allow_resize_and_rehash, G1GCPhaseTimes* phase_times = NULL); static void threads_do(ThreadClosure* tc); static void print_worker_threads_on(outputStream* st); From bcf9ea6cbf346719b6aa4eabfc763c952de91f19 Mon Sep 17 00:00:00 2001 From: David Lindholm Date: Thu, 12 Mar 2015 14:09:36 +0100 Subject: [PATCH 024/362] 8073463: G1 does not mangle freed heap regions Reviewed-by: mgerdin, jwilhelm --- .../concurrentMarkSweep/compactibleFreeListSpace.hpp | 4 ++++ .../src/share/vm/gc_implementation/g1/heapRegion.cpp | 10 ++++++++++ .../src/share/vm/gc_implementation/g1/heapRegion.hpp | 3 +++ hotspot/src/share/vm/memory/space.cpp | 9 --------- hotspot/src/share/vm/memory/space.hpp | 11 ++++------- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp index b33bdc71440..72eecc19fbc 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp @@ -396,6 +396,10 @@ class CompactibleFreeListSpace: public CompactibleSpace { // Resizing support void set_end(HeapWord* value); // override + // Never mangle CompactibleFreeListSpace + void mangle_unused_area() {} + void mangle_unused_area_complete() {} + // Mutual exclusion support Mutex* freelistLock() const { return &_freelistLock; } diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp index 2eb23388ef5..1ec43eae39c 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp @@ -934,6 +934,16 @@ void G1OffsetTableContigSpace::set_end(HeapWord* new_end) { _offsets.resize(new_end - bottom()); } +#ifndef PRODUCT +void G1OffsetTableContigSpace::mangle_unused_area() { + mangle_unused_area_complete(); +} + +void G1OffsetTableContigSpace::mangle_unused_area_complete() { + SpaceMangler::mangle_region(MemRegion(top(), end())); +} +#endif + void G1OffsetTableContigSpace::print() const { print_short(); gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp index 1d78eae7adf..93a149bdab1 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp @@ -155,6 +155,9 @@ class G1OffsetTableContigSpace: public CompactibleSpace { void set_bottom(HeapWord* value); void set_end(HeapWord* value); + void mangle_unused_area() PRODUCT_RETURN; + void mangle_unused_area_complete() PRODUCT_RETURN; + HeapWord* scan_top() const; void record_timestamp(); void reset_gc_time_stamp() { _gc_time_stamp = 0; } diff --git a/hotspot/src/share/vm/memory/space.cpp b/hotspot/src/share/vm/memory/space.cpp index 288637750be..9211b051e76 100644 --- a/hotspot/src/share/vm/memory/space.cpp +++ b/hotspot/src/share/vm/memory/space.cpp @@ -353,15 +353,6 @@ void ContiguousSpace::mangle_unused_area() { void ContiguousSpace::mangle_unused_area_complete() { mangler()->mangle_unused_area_complete(); } -void ContiguousSpace::mangle_region(MemRegion mr) { - // Although this method uses SpaceMangler::mangle_region() which - // is not specific to a space, the when the ContiguousSpace version - // is called, it is always with regard to a space and this - // bounds checking is appropriate. - MemRegion space_mr(bottom(), end()); - assert(space_mr.contains(mr), "Mangling outside space"); - SpaceMangler::mangle_region(mr); -} #endif // NOT_PRODUCT void CompactibleSpace::initialize(MemRegion mr, diff --git a/hotspot/src/share/vm/memory/space.hpp b/hotspot/src/share/vm/memory/space.hpp index 4eb7669ac23..f5649764ffa 100644 --- a/hotspot/src/share/vm/memory/space.hpp +++ b/hotspot/src/share/vm/memory/space.hpp @@ -128,11 +128,10 @@ class Space: public CHeapObj { // For detecting GC bugs. Should only be called at GC boundaries, since // some unused space may be used as scratch space during GC's. - // Default implementation does nothing. We also call this when expanding - // a space to satisfy an allocation request. See bug #4668531 - virtual void mangle_unused_area() {} - virtual void mangle_unused_area_complete() {} - virtual void mangle_region(MemRegion mr) {} + // We also call this when expanding a space to satisfy an allocation + // request. See bug #4668531 + virtual void mangle_unused_area() = 0; + virtual void mangle_unused_area_complete() = 0; // Testers bool is_empty() const { return used() == 0; } @@ -559,8 +558,6 @@ class ContiguousSpace: public CompactibleSpace { void mangle_unused_area() PRODUCT_RETURN; // Mangle [top, end) void mangle_unused_area_complete() PRODUCT_RETURN; - // Mangle the given MemRegion. - void mangle_region(MemRegion mr) PRODUCT_RETURN; // Do some sparse checking on the area that should have been mangled. void check_mangled_unused_area(HeapWord* limit) PRODUCT_RETURN; From 41455f243710abd2199d1d9e21f41c15dc0c4e00 Mon Sep 17 00:00:00 2001 From: Michail Chernov Date: Fri, 13 Mar 2015 17:47:34 +0400 Subject: [PATCH 025/362] 8026047: [TESTBUG] add regression test for DisableExplicitGC flag Reviewed-by: jwilhelm, brutisso --- hotspot/test/gc/TestDisableExplicitGC.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 hotspot/test/gc/TestDisableExplicitGC.java diff --git a/hotspot/test/gc/TestDisableExplicitGC.java b/hotspot/test/gc/TestDisableExplicitGC.java new file mode 100644 index 00000000000..45619568ab5 --- /dev/null +++ b/hotspot/test/gc/TestDisableExplicitGC.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test TestDisableExplicitGC + * @requires vm.opt.DisableExplicitGC == null + * @summary Verify GC behavior with DisableExplicitGC flag. + * @library /testlibrary + * @run main/othervm -XX:+PrintGCDetails TestDisableExplicitGC + * @run main/othervm/fail -XX:+DisableExplicitGC -XX:+PrintGCDetails TestDisableExplicitGC + * @run main/othervm -XX:-DisableExplicitGC -XX:+PrintGCDetails TestDisableExplicitGC + */ +import java.lang.management.GarbageCollectorMXBean; +import java.util.List; +import static com.oracle.java.testlibrary.Asserts.*; + +public class TestDisableExplicitGC { + + public static void main(String[] args) throws InterruptedException { + List list = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans(); + long collectionCountBefore = getCollectionCount(list); + System.gc(); + long collectionCountAfter = getCollectionCount(list); + assertLT(collectionCountBefore, collectionCountAfter); + } + + private static long getCollectionCount(List list) { + int collectionCount = 0; + for (GarbageCollectorMXBean gcMXBean : list) { + collectionCount += gcMXBean.getCollectionCount(); + } + return collectionCount; + } +} From 7e86840f64daaffa6d0988c875deef8b79f08da9 Mon Sep 17 00:00:00 2001 From: Jesper Wilhelmsson Date: Thu, 5 Mar 2015 23:47:26 +0100 Subject: [PATCH 026/362] 8057632: Remove auxiliary code used to handle the generations array Removed next_gen(), prev_gen(), and get_gen(). Reviewed-by: kbarrett, tschatzl --- .../compactibleFreeListSpace.cpp | 5 +- .../concurrentMarkSweepGeneration.cpp | 13 ++--- .../parNew/parNewGeneration.cpp | 47 +++++++++---------- .../parNew/parNewGeneration.hpp | 6 +-- .../src/share/vm/memory/collectorPolicy.cpp | 22 +++++---- .../src/share/vm/memory/defNewGeneration.cpp | 29 ++++++------ .../src/share/vm/memory/defNewGeneration.hpp | 4 +- .../src/share/vm/memory/genCollectedHeap.cpp | 17 ++++--- .../src/share/vm/memory/genCollectedHeap.hpp | 23 +-------- hotspot/src/share/vm/memory/genMarkSweep.cpp | 29 +++++------- hotspot/src/share/vm/memory/generation.cpp | 5 +- hotspot/src/share/vm/memory/space.cpp | 2 +- hotspot/src/share/vm/runtime/vmStructs.cpp | 2 +- .../src/share/vm/services/memoryService.cpp | 6 +-- .../src/share/vm/services/memoryService.hpp | 9 +--- 15 files changed, 92 insertions(+), 127 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp index 2264559e3b3..51e9a9f549c 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -186,7 +186,7 @@ HeapWord* CompactibleFreeListSpace::forward(oop q, size_t size, cp->space->set_compaction_top(compact_top); cp->space = cp->space->next_compaction_space(); if (cp->space == NULL) { - cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen); + cp->gen = GenCollectedHeap::heap()->young_gen(); assert(cp->gen != NULL, "compaction must succeed"); cp->space = cp->gen->first_compaction_space(); assert(cp->space != NULL, "generation must have a first compaction space"); @@ -900,7 +900,6 @@ void CompactibleFreeListSpace::object_iterate_mem(MemRegion mr, } } - // Callers of this iterator beware: The closure application should // be robust in the face of uninitialized objects and should (always) // return a correct size so that the next addr + size below gives us a diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp index c89cbedda29..219763410d5 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @@ -369,7 +369,7 @@ void CMSStats::adjust_cms_free_adjustment_factor(bool fail, size_t free) { double CMSStats::time_until_cms_gen_full() const { size_t cms_free = _cms_gen->cmsSpace()->free(); GenCollectedHeap* gch = GenCollectedHeap::heap(); - size_t expected_promotion = MIN2(gch->get_gen(0)->capacity(), + size_t expected_promotion = MIN2(gch->young_gen()->capacity(), (size_t) _cms_gen->gc_stats()->avg_promoted()->padded_average()); if (cms_free > expected_promotion) { // Start a cms collection if there isn't enough space to promote @@ -626,8 +626,8 @@ CMSCollector::CMSCollector(ConcurrentMarkSweepGeneration* cmsGen, // Support for parallelizing young gen rescan GenCollectedHeap* gch = GenCollectedHeap::heap(); - assert(gch->prev_gen(_cmsGen)->kind() == Generation::ParNew, "CMS can only be used with ParNew"); - _young_gen = (ParNewGeneration*)gch->prev_gen(_cmsGen); + assert(gch->young_gen()->kind() == Generation::ParNew, "CMS can only be used with ParNew"); + _young_gen = (ParNewGeneration*)gch->young_gen(); if (gch->supports_inline_contig_alloc()) { _top_addr = gch->top_addr(); _end_addr = gch->end_addr(); @@ -869,7 +869,7 @@ void ConcurrentMarkSweepGeneration::compute_new_size_free_list() { if (prev_level >= 0) { size_t prev_size = 0; GenCollectedHeap* gch = GenCollectedHeap::heap(); - Generation* prev_gen = gch->get_gen(prev_level); + Generation* prev_gen = gch->young_gen(); prev_size = prev_gen->capacity(); gclog_or_tty->print_cr(" Younger gen size "SIZE_FORMAT, prev_size/1000); @@ -1049,11 +1049,8 @@ oop ConcurrentMarkSweepGeneration::promote(oop obj, size_t obj_size) { // expand and retry size_t s = _cmsSpace->expansionSpaceRequired(obj_size); // HeapWords expand_for_gc_cause(s*HeapWordSize, MinHeapDeltaBytes, CMSExpansionCause::_satisfy_promotion); - // Since there's currently no next generation, we don't try to promote + // Since this is the old generation, we don't try to promote // into a more senior generation. - assert(next_gen() == NULL, "assumption, based upon which no attempt " - "is made to pass on a possibly failing " - "promotion to next generation"); res = _cmsSpace->promote(obj, obj_size); } if (res != NULL) { diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index a54864db074..1b9192962f8 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -325,7 +325,7 @@ public: private: ParallelTaskTerminator& _term; ParNewGeneration& _gen; - Generation& _next_gen; + Generation& _old_gen; public: bool is_valid(int id) const { return id < length(); } ParallelTaskTerminator* terminator() { return &_term; } @@ -338,7 +338,7 @@ ParScanThreadStateSet::ParScanThreadStateSet( Stack* overflow_stacks, size_t desired_plab_sz, ParallelTaskTerminator& term) : ResourceArray(sizeof(ParScanThreadState), num_threads), - _gen(gen), _next_gen(old_gen), _term(term) + _gen(gen), _old_gen(old_gen), _term(term) { assert(num_threads > 0, "sanity check!"); assert(ParGCUseLocalOverflow == (overflow_stacks != NULL), @@ -471,8 +471,8 @@ void ParScanThreadStateSet::flush() _gen.age_table()->merge(local_table); // Inform old gen that we're done. - _next_gen.par_promote_alloc_done(i); - _next_gen.par_oop_since_save_marks_iterate_done(i); + _old_gen.par_promote_alloc_done(i); + _old_gen.par_oop_since_save_marks_iterate_done(i); } if (UseConcMarkSweepGC) { @@ -574,10 +574,10 @@ void ParEvacuateFollowersClosure::do_void() { par_scan_state()->end_term_time(); } -ParNewGenTask::ParNewGenTask(ParNewGeneration* gen, Generation* next_gen, - HeapWord* young_old_boundary, ParScanThreadStateSet* state_set) : +ParNewGenTask::ParNewGenTask(ParNewGeneration* gen, Generation* old_gen, + HeapWord* young_old_boundary, ParScanThreadStateSet* state_set) : AbstractGangTask("ParNewGeneration collection"), - _gen(gen), _next_gen(next_gen), + _gen(gen), _old_gen(old_gen), _young_old_boundary(young_old_boundary), _state_set(state_set) {} @@ -601,8 +601,6 @@ void ParNewGenTask::work(uint worker_id) { // We would need multiple old-gen queues otherwise. assert(gch->n_gens() == 2, "Par young collection currently only works with one older gen."); - Generation* old_gen = gch->next_gen(_gen); - ParScanThreadState& par_scan_state = _state_set->thread_state(worker_id); assert(_state_set->is_valid(worker_id), "Should not have been called"); @@ -763,8 +761,9 @@ void ScanClosureWithParBarrier::do_oop(narrowOop* p) { ScanClosureWithParBarrier class ParNewRefProcTaskProxy: public AbstractGangTask { typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; public: - ParNewRefProcTaskProxy(ProcessTask& task, ParNewGeneration& gen, - Generation& next_gen, + ParNewRefProcTaskProxy(ProcessTask& task, + ParNewGeneration& gen, + Generation& old_gen, HeapWord* young_old_boundary, ParScanThreadStateSet& state_set); @@ -776,20 +775,20 @@ private: private: ParNewGeneration& _gen; ProcessTask& _task; - Generation& _next_gen; + Generation& _old_gen; HeapWord* _young_old_boundary; ParScanThreadStateSet& _state_set; }; -ParNewRefProcTaskProxy::ParNewRefProcTaskProxy( - ProcessTask& task, ParNewGeneration& gen, - Generation& next_gen, - HeapWord* young_old_boundary, - ParScanThreadStateSet& state_set) +ParNewRefProcTaskProxy::ParNewRefProcTaskProxy(ProcessTask& task, + ParNewGeneration& gen, + Generation& old_gen, + HeapWord* young_old_boundary, + ParScanThreadStateSet& state_set) : AbstractGangTask("ParNewGeneration parallel reference processing"), _gen(gen), _task(task), - _next_gen(next_gen), + _old_gen(old_gen), _young_old_boundary(young_old_boundary), _state_set(state_set) { @@ -893,7 +892,7 @@ void ParNewGeneration::handle_promotion_failed(GenCollectedHeap* gch, ParScanThr from()->set_next_compaction_space(to()); gch->set_incremental_collection_failed(); // Inform the next generation that a promotion failure occurred. - _next_gen->promotion_failure_occurred(); + _old_gen->promotion_failure_occurred(); // Trace promotion failure in the parallel GC threads thread_state_set.trace_promotion_failed(gc_tracer()); @@ -927,7 +926,7 @@ void ParNewGeneration::collect(bool full, workers->set_active_workers(active_workers); assert(gch->n_gens() == 2, "Par collection currently only works with single older gen."); - _next_gen = gch->next_gen(this); + _old_gen = gch->old_gen(); // If the next generation is too full to accommodate worst-case promotion // from this generation, pass on collection; let the next generation @@ -968,10 +967,10 @@ void ParNewGeneration::collect(bool full, // because only those workers go through the termination protocol. ParallelTaskTerminator _term(n_workers, task_queues()); ParScanThreadStateSet thread_state_set(workers->active_workers(), - *to(), *this, *_next_gen, *task_queues(), + *to(), *this, *_old_gen, *task_queues(), _overflow_stacks, desired_plab_sz(), _term); - ParNewGenTask tsk(this, _next_gen, reserved().end(), &thread_state_set); + ParNewGenTask tsk(this, _old_gen, reserved().end(), &thread_state_set); gch->set_par_threads(n_workers); gch->rem_set()->prepare_for_younger_refs_iterate(true); // It turns out that even when we're using 1 thread, doing the work in a @@ -1191,8 +1190,8 @@ oop ParNewGeneration::copy_to_survivor_space( } if (!_promotion_failed) { - new_obj = _next_gen->par_promote(par_scan_state->thread_num(), - old, m, sz); + new_obj = _old_gen->par_promote(par_scan_state->thread_num(), + old, m, sz); } if (new_obj == NULL) { diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp index ef0b0581765..f14f6a6d354 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -233,13 +233,13 @@ class ParScanThreadState { class ParNewGenTask: public AbstractGangTask { private: ParNewGeneration* _gen; - Generation* _next_gen; + Generation* _old_gen; HeapWord* _young_old_boundary; class ParScanThreadStateSet* _state_set; public: ParNewGenTask(ParNewGeneration* gen, - Generation* next_gen, + Generation* old_gen, HeapWord* young_old_boundary, ParScanThreadStateSet* state_set); diff --git a/hotspot/src/share/vm/memory/collectorPolicy.cpp b/hotspot/src/share/vm/memory/collectorPolicy.cpp index 28ef44f8f42..216e799d9ae 100644 --- a/hotspot/src/share/vm/memory/collectorPolicy.cpp +++ b/hotspot/src/share/vm/memory/collectorPolicy.cpp @@ -601,7 +601,7 @@ HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size, HandleMark hm; // Discard any handles allocated in each iteration. // First allocation attempt is lock-free. - Generation *young = gch->get_gen(0); + Generation *young = gch->young_gen(); assert(young->supports_inline_contig_alloc(), "Otherwise, must do alloc within heap lock"); if (young->should_allocate(size, is_tlab)) { @@ -615,8 +615,8 @@ HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size, { MutexLocker ml(Heap_lock); if (PrintGC && Verbose) { - gclog_or_tty->print_cr("TwoGenerationCollectorPolicy::mem_allocate_work:" - " attempting locked slow path allocation"); + gclog_or_tty->print_cr("GenCollectorPolicy::mem_allocate_work:" + " attempting locked slow path allocation"); } // Note that only large objects get a shot at being // allocated in later generations. @@ -705,7 +705,7 @@ HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size, // Give a warning if we seem to be looping forever. if ((QueuedAllocationWarningCount > 0) && (try_count % QueuedAllocationWarningCount == 0)) { - warning("TwoGenerationCollectorPolicy::mem_allocate_work retries %d times \n\t" + warning("GenCollectorPolicy::mem_allocate_work retries %d times \n\t" " size=" SIZE_FORMAT " %s", try_count, size, is_tlab ? "(TLAB)" : ""); } } @@ -715,10 +715,14 @@ HeapWord* GenCollectorPolicy::expand_heap_and_allocate(size_t size, bool is_tlab) { GenCollectedHeap *gch = GenCollectedHeap::heap(); HeapWord* result = NULL; - for (int i = number_of_generations() - 1; i >= 0 && result == NULL; i--) { - Generation *gen = gch->get_gen(i); - if (gen->should_allocate(size, is_tlab)) { - result = gen->expand_and_allocate(size, is_tlab); + Generation *old = gch->old_gen(); + if (old->should_allocate(size, is_tlab)) { + result = old->expand_and_allocate(size, is_tlab); + } + if (result == NULL) { + Generation *young = gch->young_gen(); + if (young->should_allocate(size, is_tlab)) { + result = young->expand_and_allocate(size, is_tlab); } } assert(result == NULL || gch->is_in_reserved(result), "result not in heap"); @@ -891,7 +895,7 @@ MetaWord* CollectorPolicy::satisfy_failed_metadata_allocation( bool GenCollectorPolicy::should_try_older_generation_allocation( size_t word_size) const { GenCollectedHeap* gch = GenCollectedHeap::heap(); - size_t young_capacity = gch->get_gen(0)->capacity_before_gc(); + size_t young_capacity = gch->young_gen()->capacity_before_gc(); return (word_size > heap_word_size(young_capacity)) || GC_locker::is_active_and_needs_gc() || gch->incremental_collection_failed(); diff --git a/hotspot/src/share/vm/memory/defNewGeneration.cpp b/hotspot/src/share/vm/memory/defNewGeneration.cpp index 053fe03b15d..43aceeb6942 100644 --- a/hotspot/src/share/vm/memory/defNewGeneration.cpp +++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp @@ -226,7 +226,7 @@ DefNewGeneration::DefNewGeneration(ReservedSpace rs, compute_space_boundaries(0, SpaceDecorator::Clear, SpaceDecorator::Mangle); update_counters(); - _next_gen = NULL; + _old_gen = NULL; _tenuring_threshold = MaxTenuringThreshold; _pretenure_size_threshold_words = PretenureSizeThreshold >> LogHeapWordSize; @@ -383,8 +383,8 @@ void DefNewGeneration::compute_new_size() { assert(next_level < gch->_n_gens, "DefNewGeneration cannot be an oldest gen"); - Generation* next_gen = gch->get_gen(next_level); - size_t old_size = next_gen->capacity(); + Generation* old_gen = gch->old_gen(); + size_t old_size = old_gen->capacity(); size_t new_size_before = _virtual_space.committed_size(); size_t min_new_size = spec()->init_size(); size_t max_new_size = reserved().byte_size(); @@ -568,7 +568,7 @@ void DefNewGeneration::collect(bool full, DefNewTracer gc_tracer; gc_tracer.report_gc_start(gch->gc_cause(), _gc_timer->gc_start()); - _next_gen = gch->next_gen(this); + _old_gen = gch->old_gen(); // If the next generation is too full to accommodate promotion // from this generation, pass on collection; let the next generation @@ -688,7 +688,7 @@ void DefNewGeneration::collect(bool full, gch->set_incremental_collection_failed(); // Inform the next generation that a promotion failure occurred. - _next_gen->promotion_failure_occurred(); + _old_gen->promotion_failure_occurred(); gc_tracer.report_promotion_failed(_promotion_failed_info); // Reset the PromotionFailureALot counters. @@ -793,7 +793,7 @@ oop DefNewGeneration::copy_to_survivor_space(oop old) { // Otherwise try allocating obj tenured if (obj == NULL) { - obj = _next_gen->promote(old, s); + obj = _old_gen->promote(old, s); if (obj == NULL) { handle_promotion_failure(old); return old; @@ -898,11 +898,11 @@ bool DefNewGeneration::collection_attempt_is_safe() { } return false; } - if (_next_gen == NULL) { + if (_old_gen == NULL) { GenCollectedHeap* gch = GenCollectedHeap::heap(); - _next_gen = gch->next_gen(this); + _old_gen = gch->old_gen(); } - return _next_gen->promotion_attempt_is_safe(used()); + return _old_gen->promotion_attempt_is_safe(used()); } void DefNewGeneration::gc_epilogue(bool full) { @@ -1022,8 +1022,7 @@ CompactibleSpace* DefNewGeneration::first_compaction_space() const { return eden(); } -HeapWord* DefNewGeneration::allocate(size_t word_size, - bool is_tlab) { +HeapWord* DefNewGeneration::allocate(size_t word_size, bool is_tlab) { // This is the slow-path allocation for the DefNewGeneration. // Most allocations are fast-path in compiled code. // We try to allocate from the eden. If that works, we are happy. @@ -1031,8 +1030,8 @@ HeapWord* DefNewGeneration::allocate(size_t word_size, // have to use it here, as well. HeapWord* result = eden()->par_allocate(word_size); if (result != NULL) { - if (CMSEdenChunksRecordAlways && _next_gen != NULL) { - _next_gen->sample_eden_chunk(); + if (CMSEdenChunksRecordAlways && _old_gen != NULL) { + _old_gen->sample_eden_chunk(); } } else { // If the eden is full and the last collection bailed out, we are running @@ -1047,8 +1046,8 @@ HeapWord* DefNewGeneration::allocate(size_t word_size, HeapWord* DefNewGeneration::par_allocate(size_t word_size, bool is_tlab) { HeapWord* res = eden()->par_allocate(word_size); - if (CMSEdenChunksRecordAlways && _next_gen != NULL) { - _next_gen->sample_eden_chunk(); + if (CMSEdenChunksRecordAlways && _old_gen != NULL) { + _old_gen->sample_eden_chunk(); } return res; } diff --git a/hotspot/src/share/vm/memory/defNewGeneration.hpp b/hotspot/src/share/vm/memory/defNewGeneration.hpp index 105c029be14..4e7899eb229 100644 --- a/hotspot/src/share/vm/memory/defNewGeneration.hpp +++ b/hotspot/src/share/vm/memory/defNewGeneration.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -42,7 +42,7 @@ class DefNewGeneration: public Generation { friend class VMStructs; protected: - Generation* _next_gen; + Generation* _old_gen; uint _tenuring_threshold; // Tenuring threshold for next collection. ageTable _age_table; // Size of object to pretenure in words; command line provides bytes diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.cpp b/hotspot/src/share/vm/memory/genCollectedHeap.cpp index 58a492c752e..20d9afe5036 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp @@ -177,18 +177,17 @@ void GenCollectedHeap::post_initialize() { SharedHeap::post_initialize(); GenCollectorPolicy *policy = (GenCollectorPolicy *)collector_policy(); guarantee(policy->is_generation_policy(), "Illegal policy type"); - assert((get_gen(0)->kind() == Generation::DefNew) || - (get_gen(0)->kind() == Generation::ParNew), + assert((_young_gen->kind() == Generation::DefNew) || + (_young_gen->kind() == Generation::ParNew), "Wrong youngest generation type"); - DefNewGeneration* def_new_gen = (DefNewGeneration*)get_gen(0); + DefNewGeneration* def_new_gen = (DefNewGeneration*)_young_gen; - Generation* old_gen = get_gen(1); - assert(old_gen->kind() == Generation::ConcurrentMarkSweep || - old_gen->kind() == Generation::MarkSweepCompact, + assert(_old_gen->kind() == Generation::ConcurrentMarkSweep || + _old_gen->kind() == Generation::MarkSweepCompact, "Wrong generation kind"); policy->initialize_size_policy(def_new_gen->eden()->capacity(), - old_gen->capacity(), + _old_gen->capacity(), def_new_gen->from()->capacity()); policy->initialize_gc_policy_counters(); } @@ -1113,10 +1112,10 @@ void GenCollectedHeap::print_on_error(outputStream* st) const { void GenCollectedHeap::print_tracing_info() const { if (TraceYoungGenTime) { - get_gen(0)->print_summary_info(); + _young_gen->print_summary_info(); } if (TraceOldGenTime) { - get_gen(1)->print_summary_info(); + _old_gen->print_summary_info(); } } diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.hpp b/hotspot/src/share/vm/memory/genCollectedHeap.hpp index 7de4a46517c..e9b3d744a32 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp @@ -373,27 +373,6 @@ public: // collection. virtual bool is_maximal_no_gc() const; - // Return the generation before "gen". - Generation* prev_gen(Generation* gen) const { - guarantee(gen->level() == 1, "Out of bounds"); - return _young_gen; - } - - // Return the generation after "gen". - Generation* next_gen(Generation* gen) const { - guarantee(gen->level() == 0, "Out of bounds"); - return _old_gen; - } - - Generation* get_gen(int i) const { - guarantee(i == 0 || i == 1, "Out of bounds"); - if (i == 0) { - return _young_gen; - } else { - return _old_gen; - } - } - int n_gens() const { assert(_n_gens == gen_policy()->number_of_generations(), "Sanity"); return _n_gens; @@ -486,7 +465,7 @@ public: assert(heap()->collector_policy()->is_generation_policy(), "the following definition may not be suitable for an n(>2)-generation system"); return incremental_collection_failed() || - (consult_young && !get_gen(0)->collection_attempt_is_safe()); + (consult_young && !_young_gen->collection_attempt_is_safe()); } // If a generation bails out of an incremental collection, diff --git a/hotspot/src/share/vm/memory/genMarkSweep.cpp b/hotspot/src/share/vm/memory/genMarkSweep.cpp index a85ddf01aae..32a59301f79 100644 --- a/hotspot/src/share/vm/memory/genMarkSweep.cpp +++ b/hotspot/src/share/vm/memory/genMarkSweep.cpp @@ -109,20 +109,16 @@ void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, bool c deallocate_stacks(); - // If compaction completely evacuated all generations younger than this - // one, then we can clear the card table. Otherwise, we must invalidate + // If compaction completely evacuated the young generation then we + // can clear the card table. Otherwise, we must invalidate // it (consider all cards dirty). In the future, we might consider doing // compaction within generations only, and doing card-table sliding. - bool all_empty = true; - for (int i = 0; all_empty && i < level; i++) { - Generation* g = gch->get_gen(i); - all_empty = all_empty && gch->get_gen(i)->used() == 0; - } GenRemSet* rs = gch->rem_set(); - Generation* old_gen = gch->get_gen(level); + Generation* old_gen = gch->old_gen(); + // Clear/invalidate below make use of the "prev_used_regions" saved earlier. - if (all_empty) { - // We've evacuated all generations below us. + if (gch->young_gen()->used() == 0) { + // We've evacuated the young generation. rs->clear_into_younger(old_gen); } else { // Invalidate the cards corresponding to the currently used @@ -157,9 +153,8 @@ void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, bool c void GenMarkSweep::allocate_stacks() { GenCollectedHeap* gch = GenCollectedHeap::heap(); - // Scratch request on behalf of oldest generation; will do no - // allocation. - ScratchBlock* scratch = gch->gather_scratch(gch->get_gen(gch->_n_gens-1), 0); + // Scratch request on behalf of old generation; will do no allocation. + ScratchBlock* scratch = gch->gather_scratch(gch->old_gen(), 0); // $$$ To cut a corner, we'll only use the first scratch block, and then // revert to malloc. @@ -188,7 +183,7 @@ void GenMarkSweep::deallocate_stacks() { } void GenMarkSweep::mark_sweep_phase1(int level, - bool clear_all_softrefs) { + bool clear_all_softrefs) { // Recursively traverse all live objects and mark them GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id()); trace(" 1"); @@ -199,7 +194,8 @@ void GenMarkSweep::mark_sweep_phase1(int level, // use OopsInGenClosure constructor which takes a generation, // as the Universe has not been created when the static constructors // are run. - follow_root_closure.set_orig_generation(gch->get_gen(level)); + assert(level == 1, "We don't use mark-sweep on young generations"); + follow_root_closure.set_orig_generation(gch->old_gen()); // Need new claim bits before marking starts. ClassLoaderDataGraph::clear_claimed_marks(); @@ -287,7 +283,8 @@ void GenMarkSweep::mark_sweep_phase3(int level) { // use OopsInGenClosure constructor which takes a generation, // as the Universe has not been created when the static constructors // are run. - adjust_pointer_closure.set_orig_generation(gch->get_gen(level)); + assert(level == 1, "We don't use mark-sweep on young generations."); + adjust_pointer_closure.set_orig_generation(gch->old_gen()); gch->gen_process_roots(level, false, // Younger gens are not roots. diff --git a/hotspot/src/share/vm/memory/generation.cpp b/hotspot/src/share/vm/memory/generation.cpp index b93d1422353..6bed336c174 100644 --- a/hotspot/src/share/vm/memory/generation.cpp +++ b/hotspot/src/share/vm/memory/generation.cpp @@ -153,9 +153,8 @@ bool Generation::is_in(const void* p) const { Generation* Generation::next_gen() const { GenCollectedHeap* gch = GenCollectedHeap::heap(); - int next = level() + 1; - if (next < gch->_n_gens) { - return gch->get_gen(next); + if (level() == 0) { + return gch->old_gen(); } else { return NULL; } diff --git a/hotspot/src/share/vm/memory/space.cpp b/hotspot/src/share/vm/memory/space.cpp index 9211b051e76..a7ea1b648f0 100644 --- a/hotspot/src/share/vm/memory/space.cpp +++ b/hotspot/src/share/vm/memory/space.cpp @@ -379,7 +379,7 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size, cp->space->set_compaction_top(compact_top); cp->space = cp->space->next_compaction_space(); if (cp->space == NULL) { - cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen); + cp->gen = GenCollectedHeap::heap()->young_gen(); assert(cp->gen != NULL, "compaction must succeed"); cp->space = cp->gen->first_compaction_space(); assert(cp->space != NULL, "generation must have a first compaction space"); diff --git a/hotspot/src/share/vm/runtime/vmStructs.cpp b/hotspot/src/share/vm/runtime/vmStructs.cpp index 631e5308a08..7357dc8c516 100644 --- a/hotspot/src/share/vm/runtime/vmStructs.cpp +++ b/hotspot/src/share/vm/runtime/vmStructs.cpp @@ -536,7 +536,7 @@ typedef CompactHashtable SymbolCompactHashTable; nonstatic_field(ContiguousSpace, _concurrent_iteration_safe_limit, HeapWord*) \ nonstatic_field(ContiguousSpace, _saved_mark_word, HeapWord*) \ \ - nonstatic_field(DefNewGeneration, _next_gen, Generation*) \ + nonstatic_field(DefNewGeneration, _old_gen, Generation*) \ nonstatic_field(DefNewGeneration, _tenuring_threshold, uint) \ nonstatic_field(DefNewGeneration, _age_table, ageTable) \ nonstatic_field(DefNewGeneration, _eden_space, ContiguousSpace*) \ diff --git a/hotspot/src/share/vm/services/memoryService.cpp b/hotspot/src/share/vm/services/memoryService.cpp index c2ad06e5578..794f4621ca5 100644 --- a/hotspot/src/share/vm/services/memoryService.cpp +++ b/hotspot/src/share/vm/services/memoryService.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, 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 @@ -160,8 +160,8 @@ void MemoryService::add_gen_collected_heap_info(GenCollectedHeap* heap) { _managers_list->append(_minor_gc_manager); _managers_list->append(_major_gc_manager); - add_generation_memory_pool(heap->get_gen(minor), _major_gc_manager, _minor_gc_manager); - add_generation_memory_pool(heap->get_gen(major), _major_gc_manager); + add_generation_memory_pool(heap->young_gen(), _major_gc_manager, _minor_gc_manager); + add_generation_memory_pool(heap->old_gen(), _major_gc_manager); } #if INCLUDE_ALL_GCS diff --git a/hotspot/src/share/vm/services/memoryService.hpp b/hotspot/src/share/vm/services/memoryService.hpp index ca2210e7796..e24cce73c57 100644 --- a/hotspot/src/share/vm/services/memoryService.hpp +++ b/hotspot/src/share/vm/services/memoryService.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, 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 @@ -57,13 +57,6 @@ private: init_code_heap_pools_size = 9 }; - // index for minor and major generations - enum { - minor = 0, - major = 1, - n_gens = 2 - }; - static GrowableArray* _pools_list; static GrowableArray* _managers_list; From 9272128a461cb877be76ab5218c00e17e4a70c25 Mon Sep 17 00:00:00 2001 From: Andrey Zakharov Date: Mon, 16 Mar 2015 17:51:28 +0300 Subject: [PATCH 027/362] 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before Added WhiteBox methods to count regions and exact aux data sizes Reviewed-by: tschatzl, jwilhelm, mgerdin --- .../gc_implementation/g1/g1CollectedHeap.hpp | 4 + .../g1/g1RegionToSpaceMapper.hpp | 5 +- .../g1/heapRegionManager.cpp | 20 ++- .../g1/heapRegionManager.hpp | 5 +- hotspot/src/share/vm/prims/whitebox.cpp | 17 ++ .../test/gc/g1/TestShrinkAuxiliaryData.java | 162 ++++++++++++------ .../test/gc/g1/TestShrinkAuxiliaryData00.java | 10 +- .../test/gc/g1/TestShrinkAuxiliaryData05.java | 9 +- .../test/gc/g1/TestShrinkAuxiliaryData10.java | 7 +- .../test/gc/g1/TestShrinkAuxiliaryData15.java | 7 +- .../test/gc/g1/TestShrinkAuxiliaryData20.java | 7 +- .../test/gc/g1/TestShrinkAuxiliaryData25.java | 7 +- .../test/gc/g1/TestShrinkAuxiliaryData30.java | 7 +- 13 files changed, 192 insertions(+), 75 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp index edf78a141b7..3d83853698a 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @@ -1118,6 +1118,10 @@ public: // The number of regions that are completely free. uint num_free_regions() const { return _hrm.num_free_regions(); } + MemoryUsage get_auxiliary_data_memory_usage() const { + return _hrm.get_auxiliary_data_memory_usage(); + } + // The number of regions that are not completely free. uint num_used_regions() const { return num_regions() - num_free_regions(); } diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1RegionToSpaceMapper.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1RegionToSpaceMapper.hpp index 6b34206495e..e46877785d7 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1RegionToSpaceMapper.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1RegionToSpaceMapper.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -57,6 +57,9 @@ class G1RegionToSpaceMapper : public CHeapObj { public: MemRegion reserved() { return _storage.reserved(); } + size_t reserved_size() { return _storage.reserved_size(); } + size_t committed_size() { return _storage.committed_size(); } + void set_mapping_changed_listener(G1MappingChangedListener* listener) { _listener = listener; } virtual ~G1RegionToSpaceMapper() { diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.cpp index a1156d8913e..419fe25c2ec 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -145,6 +145,24 @@ void HeapRegionManager::make_regions_available(uint start, uint num_regions) { } } +MemoryUsage HeapRegionManager::get_auxiliary_data_memory_usage() const { + size_t used_sz = + _prev_bitmap_mapper->committed_size() + + _next_bitmap_mapper->committed_size() + + _bot_mapper->committed_size() + + _cardtable_mapper->committed_size() + + _card_counts_mapper->committed_size(); + + size_t committed_sz = + _prev_bitmap_mapper->reserved_size() + + _next_bitmap_mapper->reserved_size() + + _bot_mapper->reserved_size() + + _cardtable_mapper->reserved_size() + + _card_counts_mapper->reserved_size(); + + return MemoryUsage(0, used_sz, committed_sz, committed_sz); +} + uint HeapRegionManager::expand_by(uint num_regions) { return expand_at(0, num_regions); } diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.hpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.hpp index 10fc349bb1f..1ac538608d3 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -28,6 +28,7 @@ #include "gc_implementation/g1/g1BiasedArray.hpp" #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp" #include "gc_implementation/g1/heapRegionSet.hpp" +#include "services/memoryUsage.hpp" class HeapRegion; class HeapRegionClosure; @@ -196,6 +197,8 @@ public: // Return the maximum number of regions in the heap. uint max_length() const { return (uint)_regions.length(); } + MemoryUsage get_auxiliary_data_memory_usage() const; + MemRegion reserved() const { return MemRegion(heap_bottom(), heap_end()); } // Expand the sequence to reflect that the heap has grown. Either create new diff --git a/hotspot/src/share/vm/prims/whitebox.cpp b/hotspot/src/share/vm/prims/whitebox.cpp index d469831b37e..3b8ad5e03ab 100644 --- a/hotspot/src/share/vm/prims/whitebox.cpp +++ b/hotspot/src/share/vm/prims/whitebox.cpp @@ -295,6 +295,12 @@ WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) return hr->is_humongous(); WB_END +WB_ENTRY(jlong, WB_G1NumMaxRegions(JNIEnv* env, jobject o)) + G1CollectedHeap* g1 = G1CollectedHeap::heap(); + size_t nr = g1->max_regions(); + return (jlong)nr; +WB_END + WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o)) G1CollectedHeap* g1 = G1CollectedHeap::heap(); size_t nr = g1->num_free_regions(); @@ -318,6 +324,14 @@ WB_END WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o)) return (jint)HeapRegion::GrainBytes; WB_END + +WB_ENTRY(jobject, WB_G1AuxiliaryMemoryUsage(JNIEnv* env)) + ResourceMark rm(THREAD); + G1CollectedHeap* g1h = G1CollectedHeap::heap(); + MemoryUsage usage = g1h->get_auxiliary_data_memory_usage(); + Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); + return JNIHandles::make_local(env, h()); +WB_END #endif // INCLUDE_ALL_GCS #if INCLUDE_NMT @@ -1240,9 +1254,12 @@ static JNINativeMethod methods[] = { #if INCLUDE_ALL_GCS {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, + {CC"g1NumMaxRegions", CC"()J", (void*)&WB_G1NumMaxRegions }, {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, {CC"g1StartConcMarkCycle", CC"()Z", (void*)&WB_G1StartMarkCycle }, + {CC"g1AuxiliaryMemoryUsage", CC"()Ljava/lang/management/MemoryUsage;", + (void*)&WB_G1AuxiliaryMemoryUsage }, #endif // INCLUDE_ALL_GCS #if INCLUDE_NMT {CC"NMTMalloc", CC"(J)J", (void*)&WB_NMTMalloc }, diff --git a/hotspot/test/gc/g1/TestShrinkAuxiliaryData.java b/hotspot/test/gc/g1/TestShrinkAuxiliaryData.java index 7ee231674d6..3145eb63854 100644 --- a/hotspot/test/gc/g1/TestShrinkAuxiliaryData.java +++ b/hotspot/test/gc/g1/TestShrinkAuxiliaryData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -21,7 +21,7 @@ * questions. */ -import static com.oracle.java.testlibrary.Asserts.assertLessThanOrEqual; +import com.oracle.java.testlibrary.Asserts; import com.oracle.java.testlibrary.OutputAnalyzer; import com.oracle.java.testlibrary.Platform; import com.oracle.java.testlibrary.ProcessTools; @@ -36,23 +36,29 @@ import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import sun.misc.Unsafe; +import sun.misc.Unsafe; // for ADDRESS_SIZE +import sun.hotspot.WhiteBox; public class TestShrinkAuxiliaryData { + private static final int REGION_SIZE = 1024 * 1024; + private final static String[] initialOpts = new String[]{ "-XX:MinHeapFreeRatio=10", "-XX:MaxHeapFreeRatio=11", "-XX:+UseG1GC", - "-XX:G1HeapRegionSize=1m", + "-XX:G1HeapRegionSize=" + REGION_SIZE, "-XX:-ExplicitGCInvokesConcurrent", - "-XX:+PrintGCDetails" + "-XX:+PrintGCDetails", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+WhiteBoxAPI", + "-Xbootclasspath/a:.", }; - private final int RSetCacheSize; + private final int hotCardTableSize; - protected TestShrinkAuxiliaryData(int RSetCacheSize) { - this.RSetCacheSize = RSetCacheSize; + protected TestShrinkAuxiliaryData(int hotCardTableSize) { + this.hotCardTableSize = hotCardTableSize; } protected void test() throws Exception { @@ -60,16 +66,16 @@ public class TestShrinkAuxiliaryData { Collections.addAll(vmOpts, initialOpts); int maxCacheSize = Math.max(0, Math.min(31, getMaxCacheSize())); - if (maxCacheSize < RSetCacheSize) { + if (maxCacheSize < hotCardTableSize) { System.out.format("Skiping test for %d cache size due max cache size %d", - RSetCacheSize, maxCacheSize + hotCardTableSize, maxCacheSize ); return; } printTestInfo(maxCacheSize); - vmOpts.add("-XX:G1ConcRSLogCacheSize=" + RSetCacheSize); + vmOpts.add("-XX:G1ConcRSLogCacheSize=" + hotCardTableSize); vmOpts.addAll(Arrays.asList(Utils.getTestJavaOpts())); // for 32 bits ObjectAlignmentInBytes is not a option @@ -92,11 +98,13 @@ public class TestShrinkAuxiliaryData { private void performTest(List opts) throws Exception { ProcessBuilder pb - = ProcessTools.createJavaProcessBuilder( - opts.toArray(new String[opts.size()]) - ); + = ProcessTools.createJavaProcessBuilder( + opts.toArray(new String[opts.size()]) + ); OutputAnalyzer output = new OutputAnalyzer(pb.start()); + System.out.println(output.getStdout()); + System.err.println(output.getStderr()); output.shouldHaveExitValue(0); } @@ -107,12 +115,13 @@ public class TestShrinkAuxiliaryData { formatSymbols.setGroupingSeparator(' '); grouped.setDecimalFormatSymbols(formatSymbols); - System.out.format("Test will use %s bytes of memory of %s available%n" + System.out.format( + "Test will use %s bytes of memory of %s available%n" + "Available memory is %s with %d bytes pointer size - can save %s pointers%n" + "Max cache size: 2^%d = %s elements%n", grouped.format(ShrinkAuxiliaryDataTest.getMemoryUsedByTest()), - grouped.format(Runtime.getRuntime().freeMemory()), - grouped.format(Runtime.getRuntime().freeMemory() + grouped.format(Runtime.getRuntime().maxMemory()), + grouped.format(Runtime.getRuntime().maxMemory() - ShrinkAuxiliaryDataTest.getMemoryUsedByTest()), Unsafe.ADDRESS_SIZE, grouped.format((Runtime.getRuntime().freeMemory() @@ -135,6 +144,7 @@ public class TestShrinkAuxiliaryData { if (availableMemory <= 0) { return 0; } + long availablePointersCount = availableMemory / Unsafe.ADDRESS_SIZE; return (63 - (int) Long.numberOfLeadingZeros(availablePointersCount)); } @@ -142,17 +152,48 @@ public class TestShrinkAuxiliaryData { static class ShrinkAuxiliaryDataTest { public static void main(String[] args) throws IOException { - int iterateCount = DEFAULT_ITERATION_COUNT; - if (args.length > 0) { - try { - iterateCount = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - //num_iterate remains default - } + ShrinkAuxiliaryDataTest testCase = new ShrinkAuxiliaryDataTest(); + + if (!testCase.checkEnvApplicability()) { + return; } - new ShrinkAuxiliaryDataTest().test(iterateCount); + testCase.test(); + } + + /** + * Checks is this environment suitable to run this test + * - memory is enough to decommit (page size is not big) + * - RSet cache size is not too big + * + * @return true if test could run, false if test should be skipped + */ + protected boolean checkEnvApplicability() { + + int pageSize = WhiteBox.getWhiteBox().getVMPageSize(); + System.out.println( "Page size = " + pageSize + + " region size = " + REGION_SIZE + + " aux data ~= " + (REGION_SIZE * 3 / 100)); + // If auxdata size will be less than page size it wouldn't decommit. + // Auxiliary data size is about ~3.6% of heap size. + if (pageSize >= REGION_SIZE * 3 / 100) { + System.out.format("Skipping test for too large page size = %d", + pageSize + ); + return false; + } + + if (REGION_SIZE * REGIONS_TO_ALLOCATE > Runtime.getRuntime().maxMemory()) { + System.out.format("Skipping test for too low available memory. " + + "Need %d, available %d", + REGION_SIZE * REGIONS_TO_ALLOCATE, + Runtime.getRuntime().maxMemory() + ); + return false; + } + + return true; } class GarbageObject { @@ -177,41 +218,54 @@ public class TestShrinkAuxiliaryData { private final List garbage = new ArrayList(); - public void test(int num_iterate) throws IOException { + public void test() throws IOException { + + MemoryUsage muFull, muFree, muAuxDataFull, muAuxDataFree; + float auxFull, auxFree; allocate(); link(); mutate(); + + muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); + long numUsedRegions = WhiteBox.getWhiteBox().g1NumMaxRegions() + - WhiteBox.getWhiteBox().g1NumFreeRegions(); + muAuxDataFull = WhiteBox.getWhiteBox().g1AuxiliaryMemoryUsage(); + auxFull = (float)muAuxDataFull.getUsed() / numUsedRegions; + + System.out.format("Full aux data ratio= %f, regions max= %d, used= %d\n", + auxFull, WhiteBox.getWhiteBox().g1NumMaxRegions(), numUsedRegions + ); + deallocate(); - - MemoryUsage muBeforeHeap - = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); - MemoryUsage muBeforeNonHeap - = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage(); - - for (int i = 0; i < num_iterate; i++) { - allocate(); - link(); - mutate(); - deallocate(); - } - System.gc(); - MemoryUsage muAfterHeap - = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); - MemoryUsage muAfterNonHeap - = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage(); - assertLessThanOrEqual(muAfterHeap.getCommitted(), muBeforeHeap.getCommitted(), - String.format("heap decommit failed - after > before: %d > %d", - muAfterHeap.getCommitted(), muBeforeHeap.getCommitted() + muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); + muAuxDataFree = WhiteBox.getWhiteBox().g1AuxiliaryMemoryUsage(); + + numUsedRegions = WhiteBox.getWhiteBox().g1NumMaxRegions() + - WhiteBox.getWhiteBox().g1NumFreeRegions(); + auxFree = (float)muAuxDataFree.getUsed() / numUsedRegions; + + System.out.format("Free aux data ratio= %f, regions max= %d, used= %d\n", + auxFree, WhiteBox.getWhiteBox().g1NumMaxRegions(), numUsedRegions + ); + + Asserts.assertLessThanOrEqual(muFree.getCommitted(), muFull.getCommitted(), + String.format("heap decommit failed - full > free: %d > %d", + muFree.getCommitted(), muFull.getCommitted() ) ); - if (muAfterHeap.getCommitted() < muBeforeHeap.getCommitted()) { - assertLessThanOrEqual(muAfterNonHeap.getCommitted(), muBeforeNonHeap.getCommitted(), - String.format("non-heap decommit failed - after > before: %d > %d", - muAfterNonHeap.getCommitted(), muBeforeNonHeap.getCommitted() + System.out.format("State used committed\n"); + System.out.format("Full aux data: %10d %10d\n", muAuxDataFull.getUsed(), muAuxDataFull.getCommitted()); + System.out.format("Free aux data: %10d %10d\n", muAuxDataFree.getUsed(), muAuxDataFree.getCommitted()); + + // if decommited check that aux data has same ratio + if (muFree.getCommitted() < muFull.getCommitted()) { + Asserts.assertLessThanOrEqual(auxFree, auxFull, + String.format("auxiliary data decommit failed - full > free: %f > %f", + auxFree, auxFull ) ); } @@ -238,8 +292,7 @@ public class TestShrinkAuxiliaryData { for (int i = 0; i < NUM_LINKS; i++) { int regionToLink; do { - regionToLink = (int) (Math.random() - * REGIONS_TO_ALLOCATE); + regionToLink = (int) (Math.random() * REGIONS_TO_ALLOCATE); } while (regionToLink == regionNumber); // get random garbage object from random region @@ -265,11 +318,8 @@ public class TestShrinkAuxiliaryData { return REGIONS_TO_ALLOCATE * REGION_SIZE; } - private static final int REGION_SIZE = 1024 * 1024; - private static final int DEFAULT_ITERATION_COUNT = 1; // iterate main scenario - private static final int REGIONS_TO_ALLOCATE = 5; + private static final int REGIONS_TO_ALLOCATE = 100; private static final int NUM_OBJECTS_PER_REGION = 10; private static final int NUM_LINKS = 20; // how many links create for each object - } } diff --git a/hotspot/test/gc/g1/TestShrinkAuxiliaryData00.java b/hotspot/test/gc/g1/TestShrinkAuxiliaryData00.java index 7d36e821048..9fb54377274 100644 --- a/hotspot/test/gc/g1/TestShrinkAuxiliaryData00.java +++ b/hotspot/test/gc/g1/TestShrinkAuxiliaryData00.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -23,11 +23,15 @@ /** * @test TestShrinkAuxiliaryData00 - * @bug 8038423 + * @bug 8038423 8061715 * @summary Checks that decommitment occurs for JVM with different * G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values + * @requires vm.gc=="G1" | vm.gc=="null" * @library /testlibrary /../../test/lib - * @build TestShrinkAuxiliaryData TestShrinkAuxiliaryData00 + * @build com.oracle.java.testlibrary.* sun.hotspot.WhiteBox + * TestShrinkAuxiliaryData TestShrinkAuxiliaryData00 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission * @run driver/timeout=720 TestShrinkAuxiliaryData00 */ public class TestShrinkAuxiliaryData00 { diff --git a/hotspot/test/gc/g1/TestShrinkAuxiliaryData05.java b/hotspot/test/gc/g1/TestShrinkAuxiliaryData05.java index 403b7bfe5aa..8ffc4fb201a 100644 --- a/hotspot/test/gc/g1/TestShrinkAuxiliaryData05.java +++ b/hotspot/test/gc/g1/TestShrinkAuxiliaryData05.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -23,12 +23,15 @@ /** * @test TestShrinkAuxiliaryData05 - * @bug 8038423 + * @bug 8038423 8061715 * @summary Checks that decommitment occurs for JVM with different * G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values * @requires vm.gc=="G1" | vm.gc=="null" * @library /testlibrary /../../test/lib - * @build TestShrinkAuxiliaryData TestShrinkAuxiliaryData05 + * @build com.oracle.java.testlibrary.* sun.hotspot.WhiteBox + * TestShrinkAuxiliaryData TestShrinkAuxiliaryData05 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission * @run driver/timeout=720 TestShrinkAuxiliaryData05 */ public class TestShrinkAuxiliaryData05 { diff --git a/hotspot/test/gc/g1/TestShrinkAuxiliaryData10.java b/hotspot/test/gc/g1/TestShrinkAuxiliaryData10.java index ad2ab4155b8..c66b243d565 100644 --- a/hotspot/test/gc/g1/TestShrinkAuxiliaryData10.java +++ b/hotspot/test/gc/g1/TestShrinkAuxiliaryData10.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -23,12 +23,15 @@ /** * @test TestShrinkAuxiliaryData10 - * @bug 8038423 + * @bug 8038423 8061715 * @summary Checks that decommitment occurs for JVM with different * G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values * @requires vm.gc=="G1" | vm.gc=="null" * @library /testlibrary /../../test/lib + * @build com.oracle.java.testlibrary.* sun.hotspot.WhiteBox * @build TestShrinkAuxiliaryData TestShrinkAuxiliaryData10 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission * @run driver/timeout=720 TestShrinkAuxiliaryData10 */ public class TestShrinkAuxiliaryData10 { diff --git a/hotspot/test/gc/g1/TestShrinkAuxiliaryData15.java b/hotspot/test/gc/g1/TestShrinkAuxiliaryData15.java index 76d54ae67e9..1889636a4f7 100644 --- a/hotspot/test/gc/g1/TestShrinkAuxiliaryData15.java +++ b/hotspot/test/gc/g1/TestShrinkAuxiliaryData15.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -23,12 +23,15 @@ /** * @test TestShrinkAuxiliaryData15 - * @bug 8038423 + * @bug 8038423 8061715 * @summary Checks that decommitment occurs for JVM with different * G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values * @requires vm.gc=="G1" | vm.gc=="null" * @library /testlibrary /../../test/lib + * @build com.oracle.java.testlibrary.* sun.hotspot.WhiteBox * @build TestShrinkAuxiliaryData TestShrinkAuxiliaryData15 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission * @run driver/timeout=720 TestShrinkAuxiliaryData15 */ public class TestShrinkAuxiliaryData15 { diff --git a/hotspot/test/gc/g1/TestShrinkAuxiliaryData20.java b/hotspot/test/gc/g1/TestShrinkAuxiliaryData20.java index 43c349e6c63..de59f1204f8 100644 --- a/hotspot/test/gc/g1/TestShrinkAuxiliaryData20.java +++ b/hotspot/test/gc/g1/TestShrinkAuxiliaryData20.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -23,12 +23,15 @@ /** * @test TestShrinkAuxiliaryData20 - * @bug 8038423 + * @bug 8038423 8061715 * @summary Checks that decommitment occurs for JVM with different * G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values * @requires vm.gc=="G1" | vm.gc=="null" * @library /testlibrary /../../test/lib + * @build com.oracle.java.testlibrary.* sun.hotspot.WhiteBox * @build TestShrinkAuxiliaryData TestShrinkAuxiliaryData20 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission * @run driver/timeout=720 TestShrinkAuxiliaryData20 */ public class TestShrinkAuxiliaryData20 { diff --git a/hotspot/test/gc/g1/TestShrinkAuxiliaryData25.java b/hotspot/test/gc/g1/TestShrinkAuxiliaryData25.java index e86d75a20ee..530fd790f07 100644 --- a/hotspot/test/gc/g1/TestShrinkAuxiliaryData25.java +++ b/hotspot/test/gc/g1/TestShrinkAuxiliaryData25.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -23,12 +23,15 @@ /** * @test TestShrinkAuxiliaryData25 - * @bug 8038423 + * @bug 8038423 8061715 * @summary Checks that decommitment occurs for JVM with different * G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values * @requires vm.gc=="G1" | vm.gc=="null" * @library /testlibrary /../../test/lib + * @build com.oracle.java.testlibrary.* sun.hotspot.WhiteBox * @build TestShrinkAuxiliaryData TestShrinkAuxiliaryData25 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission * @run driver/timeout=720 TestShrinkAuxiliaryData25 */ public class TestShrinkAuxiliaryData25 { diff --git a/hotspot/test/gc/g1/TestShrinkAuxiliaryData30.java b/hotspot/test/gc/g1/TestShrinkAuxiliaryData30.java index 08904841ad9..76bbd795951 100644 --- a/hotspot/test/gc/g1/TestShrinkAuxiliaryData30.java +++ b/hotspot/test/gc/g1/TestShrinkAuxiliaryData30.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -23,12 +23,15 @@ /** * @test TestShrinkAuxiliaryData30 - * @bug 8038423 + * @bug 8038423 8061715 * @summary Checks that decommitment occurs for JVM with different * G1ConcRSLogCacheSize and ObjectAlignmentInBytes options values * @requires vm.gc=="G1" | vm.gc=="null" * @library /testlibrary /../../test/lib + * @build com.oracle.java.testlibrary.* sun.hotspot.WhiteBox * @build TestShrinkAuxiliaryData TestShrinkAuxiliaryData30 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission * @run driver/timeout=720 TestShrinkAuxiliaryData30 */ public class TestShrinkAuxiliaryData30 { From 426a345fec15d7a44d20020b2391e86c06785073 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Tue, 17 Mar 2015 13:23:49 +0100 Subject: [PATCH 028/362] 8075242: Remove SpecializationStats Reviewed-by: brutisso, mgerdin --- .../concurrentMarkSweepGeneration.cpp | 4 - .../gc_implementation/g1/g1CollectedHeap.cpp | 5 - .../parNew/parNewGeneration.cpp | 4 - .../src/share/vm/memory/defNewGeneration.cpp | 3 - .../vm/memory/specialized_oop_closures.cpp | 115 ------------------ .../vm/memory/specialized_oop_closures.hpp | 88 +------------- .../src/share/vm/memory/tenuredGeneration.cpp | 3 - .../vm/oops/instanceClassLoaderKlass.cpp | 4 - hotspot/src/share/vm/oops/instanceKlass.cpp | 7 -- .../src/share/vm/oops/instanceMirrorKlass.cpp | 6 - .../src/share/vm/oops/instanceRefKlass.cpp | 9 -- hotspot/src/share/vm/oops/objArrayKlass.cpp | 3 - hotspot/src/share/vm/oops/objArrayOop.cpp | 1 - hotspot/src/share/vm/oops/oop.inline.hpp | 3 - 14 files changed, 2 insertions(+), 253 deletions(-) delete mode 100644 hotspot/src/share/vm/memory/specialized_oop_closures.cpp diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp index 219763410d5..f48a34c1748 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @@ -2997,7 +2997,6 @@ void CMSCollector::checkpointRootsInitial() { report_heap_summary(GCWhen::BeforeGC); ReferenceProcessor* rp = ref_processor(); - SpecializationStats::clear(); assert(_restart_addr == NULL, "Control point invariant"); { // acquire locks for subsequent manipulations @@ -3008,7 +3007,6 @@ void CMSCollector::checkpointRootsInitial() { rp->enable_discovery(); _collectorState = Marking; } - SpecializationStats::print(); } void CMSCollector::checkpointRootsInitialWork() { @@ -4326,7 +4324,6 @@ void CMSCollector::checkpointRootsFinal() { verify_work_stacks_empty(); verify_overflow_empty(); - SpecializationStats::clear(); if (PrintGCDetails) { gclog_or_tty->print("[YG occupancy: "SIZE_FORMAT" K ("SIZE_FORMAT" K)]", _young_gen->used() / K, @@ -4357,7 +4354,6 @@ void CMSCollector::checkpointRootsFinal() { } verify_work_stacks_empty(); verify_overflow_empty(); - SpecializationStats::print(); } void CMSCollector::checkpointRootsFinalWork() { diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index 0179bb4aa1a..ed964c52e8c 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -2026,10 +2026,6 @@ jint G1CollectedHeap::initialize() { Shared_DirtyCardQ_lock, &JavaThread::dirty_card_queue_set()); - // In case we're keeping closure specialization stats, initialize those - // counts and that mechanism. - SpecializationStats::clear(); - // Here we allocate the dummy HeapRegion that is required by the // G1AllocRegion class. HeapRegion* dummy_region = _hrm.get_dummy_region(); @@ -3321,7 +3317,6 @@ void G1CollectedHeap::print_tracing_info() const { concurrent_mark()->print_summary_info(); } g1_policy()->print_yg_surv_rate_info(); - SpecializationStats::print(); } #ifndef PRODUCT diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index 1b9192962f8..9ffe68a1b58 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -951,8 +951,6 @@ void ParNewGeneration::collect(bool full, // Capture heap used before collection (for printing). size_t gch_prev_used = gch->used(); - SpecializationStats::clear(); - age_table()->clear(); to()->clear(SpaceDecorator::Mangle); @@ -1072,8 +1070,6 @@ void ParNewGeneration::collect(bool full, jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; update_time_of_last_gc(now); - SpecializationStats::print(); - rp->set_enqueuing_is_done(true); if (rp->processing_is_mt()) { ParNewRefProcTaskExecutor task_executor(*this, thread_state_set); diff --git a/hotspot/src/share/vm/memory/defNewGeneration.cpp b/hotspot/src/share/vm/memory/defNewGeneration.cpp index 43aceeb6942..1f3fbe687e8 100644 --- a/hotspot/src/share/vm/memory/defNewGeneration.cpp +++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp @@ -590,8 +590,6 @@ void DefNewGeneration::collect(bool full, gch->trace_heap_before_gc(&gc_tracer); - SpecializationStats::clear(); - // These can be shared for all code paths IsAliveClosure is_alive(this); ScanWeakRefClosure scan_weak_ref(this); @@ -700,7 +698,6 @@ void DefNewGeneration::collect(bool full, // set new iteration safe limit for the survivor spaces from()->set_concurrent_iteration_safe_limit(from()->top()); to()->set_concurrent_iteration_safe_limit(to()->top()); - SpecializationStats::print(); // We need to use a monotonically non-decreasing time in ms // or we will see time-warp warnings and os::javaTimeMillis() diff --git a/hotspot/src/share/vm/memory/specialized_oop_closures.cpp b/hotspot/src/share/vm/memory/specialized_oop_closures.cpp deleted file mode 100644 index 467eba1ef6a..00000000000 --- a/hotspot/src/share/vm/memory/specialized_oop_closures.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2001, 2010, 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. - * - * 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. - * - */ - -#include "precompiled.hpp" -#include "memory/specialized_oop_closures.hpp" -#include "utilities/ostream.hpp" - -// For keeping stats on effectiveness. -#ifndef PRODUCT -#if ENABLE_SPECIALIZATION_STATS - -int SpecializationStats::_numCallsAll; - -int SpecializationStats::_numCallsTotal[NUM_Kinds]; -int SpecializationStats::_numCalls_nv[NUM_Kinds]; - -int SpecializationStats::_numDoOopCallsTotal[NUM_Kinds]; -int SpecializationStats::_numDoOopCalls_nv[NUM_Kinds]; - -void SpecializationStats::clear() { - _numCallsAll = 0; - for (int k = ik; k < NUM_Kinds; k++) { - _numCallsTotal[k] = 0; - _numCalls_nv[k] = 0; - - _numDoOopCallsTotal[k] = 0; - _numDoOopCalls_nv[k] = 0; - } -} - -void SpecializationStats::print() { - const char* header_format = " %20s %10s %11s %10s"; - const char* line_format = " %20s %10d %11d %9.2f%%"; - int all_numCallsTotal = - _numCallsTotal[ik] + _numCallsTotal[irk] + _numCallsTotal[oa]; - int all_numCalls_nv = - _numCalls_nv[ik] + _numCalls_nv[irk] + _numCalls_nv[oa]; - gclog_or_tty->print_cr("\nOf %d oop_oop_iterate calls %d (%6.3f%%) are in (ik, irk, oa).", - _numCallsAll, all_numCallsTotal, - 100.0 * (float)all_numCallsTotal / (float)_numCallsAll); - // irk calls are double-counted. - int real_ik_numCallsTotal = _numCallsTotal[ik] - _numCallsTotal[irk]; - int real_ik_numCalls_nv = _numCalls_nv[ik] - _numCalls_nv[irk]; - gclog_or_tty->print_cr(""); - gclog_or_tty->print_cr(header_format, "oop_oop_iterate:", "calls", "non-virtual", "pct"); - gclog_or_tty->print_cr(header_format, - "----------", - "----------", - "-----------", - "----------"); - gclog_or_tty->print_cr(line_format, "all", - all_numCallsTotal, - all_numCalls_nv, - 100.0 * (float)all_numCalls_nv / (float)all_numCallsTotal); - gclog_or_tty->print_cr(line_format, "ik", - real_ik_numCallsTotal, real_ik_numCalls_nv, - 100.0 * (float)real_ik_numCalls_nv / - (float)real_ik_numCallsTotal); - gclog_or_tty->print_cr(line_format, "irk", - _numCallsTotal[irk], _numCalls_nv[irk], - 100.0 * (float)_numCalls_nv[irk] / (float)_numCallsTotal[irk]); - gclog_or_tty->print_cr(line_format, "oa", - _numCallsTotal[oa], _numCalls_nv[oa], - 100.0 * (float)_numCalls_nv[oa] / (float)_numCallsTotal[oa]); - - - gclog_or_tty->print_cr(""); - gclog_or_tty->print_cr(header_format, "do_oop:", "calls", "non-virtual", "pct"); - gclog_or_tty->print_cr(header_format, - "----------", - "----------", - "-----------", - "----------"); - int all_numDoOopCallsTotal = - _numDoOopCallsTotal[ik] + _numDoOopCallsTotal[irk] + _numDoOopCallsTotal[oa]; - int all_numDoOopCalls_nv = - _numDoOopCalls_nv[ik] + _numDoOopCalls_nv[irk] + _numDoOopCalls_nv[oa]; - gclog_or_tty->print_cr(line_format, "all", - all_numDoOopCallsTotal, all_numDoOopCalls_nv, - 100.0 * (float)all_numDoOopCalls_nv / - (float)all_numDoOopCallsTotal); - const char* kind_names[] = { "ik", "irk", "oa" }; - for (int k = ik; k < NUM_Kinds; k++) { - gclog_or_tty->print_cr(line_format, kind_names[k], - _numDoOopCallsTotal[k], _numDoOopCalls_nv[k], - (_numDoOopCallsTotal[k] > 0 ? - 100.0 * (float)_numDoOopCalls_nv[k] / - (float)_numDoOopCallsTotal[k] - : 0.0)); - } -} - -#endif // ENABLE_SPECIALIZATION_STATS -#endif // !PRODUCT diff --git a/hotspot/src/share/vm/memory/specialized_oop_closures.hpp b/hotspot/src/share/vm/memory/specialized_oop_closures.hpp index b4e2fa33a22..4fbd0b11935 100644 --- a/hotspot/src/share/vm/memory/specialized_oop_closures.hpp +++ b/hotspot/src/share/vm/memory/specialized_oop_closures.hpp @@ -60,10 +60,10 @@ class NoHeaderExtendedOopClosure; // This macro applies an argument macro to all OopClosures for which we // want specialized bodies of "oop_oop_iterate". The arguments to "f" are: // "f(closureType, non_virtual)" -// where "closureType" is the name of the particular subclass of OopClosure, +// where "closureType" is the name of the particular subclass of ExtendedOopClosure, // and "non_virtual" will be the string "_nv" if the closure type should // have its "do_oop" method invoked non-virtually, or else the -// string "_v". ("OopClosure" itself will be the only class in the latter +// string "_v". ("ExtendedOopClosure" itself will be the only class in the latter // category.) // This is split into several because of a Visual C++ 6.0 compiler bug @@ -174,93 +174,9 @@ class NoHeaderExtendedOopClosure; // We separate these out, because sometime the general one has // a different definition from the specialized ones, and sometimes it // doesn't. -// NOTE: One of the valid criticisms of this -// specialize-oop_oop_iterate-for-specific-closures idiom is that it is -// easy to have a silent performance bug: if you fail to de-virtualize, -// things still work, just slower. The "SpecializationStats" mode is -// intended to at least make such a failure easy to detect. -// *Not* using the ALL_SINCE_SAVE_MARKS_CLOSURES(f) macro defined -// below means that *only* closures for which oop_oop_iterate specializations -// exist above may be applied to "oops_since_save_marks". That is, -// this form of the performance bug is caught statically. When you add -// a definition for the general type, this property goes away. -// Make sure you test with SpecializationStats to find such bugs -// when introducing a new closure where you don't want virtual dispatch. #define ALL_SINCE_SAVE_MARKS_CLOSURES(f) \ f(OopsInGenClosure,_v) \ SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) -// For keeping stats on effectiveness. -#define ENABLE_SPECIALIZATION_STATS 0 - - -class SpecializationStats { -public: - enum Kind { - ik, // InstanceKlass - irk, // InstanceRefKlass - oa, // ObjArrayKlass - NUM_Kinds - }; - -#if ENABLE_SPECIALIZATION_STATS -private: - static bool _init; - static bool _wrapped; - static jint _numCallsAll; - - static jint _numCallsTotal[NUM_Kinds]; - static jint _numCalls_nv[NUM_Kinds]; - - static jint _numDoOopCallsTotal[NUM_Kinds]; - static jint _numDoOopCalls_nv[NUM_Kinds]; -public: -#endif - static void clear() PRODUCT_RETURN; - - static inline void record_call() PRODUCT_RETURN; - static inline void record_iterate_call_v(Kind k) PRODUCT_RETURN; - static inline void record_iterate_call_nv(Kind k) PRODUCT_RETURN; - static inline void record_do_oop_call_v(Kind k) PRODUCT_RETURN; - static inline void record_do_oop_call_nv(Kind k) PRODUCT_RETURN; - - static void print() PRODUCT_RETURN; -}; - -#ifndef PRODUCT -#if ENABLE_SPECIALIZATION_STATS - -inline void SpecializationStats::record_call() { - Atomic::inc(&_numCallsAll); -} -inline void SpecializationStats::record_iterate_call_v(Kind k) { - Atomic::inc(&_numCallsTotal[k]); -} -inline void SpecializationStats::record_iterate_call_nv(Kind k) { - Atomic::inc(&_numCallsTotal[k]); - Atomic::inc(&_numCalls_nv[k]); -} - -inline void SpecializationStats::record_do_oop_call_v(Kind k) { - Atomic::inc(&_numDoOopCallsTotal[k]); -} -inline void SpecializationStats::record_do_oop_call_nv(Kind k) { - Atomic::inc(&_numDoOopCallsTotal[k]); - Atomic::inc(&_numDoOopCalls_nv[k]); -} - -#else // !ENABLE_SPECIALIZATION_STATS - -inline void SpecializationStats::record_call() {} -inline void SpecializationStats::record_iterate_call_v(Kind k) {} -inline void SpecializationStats::record_iterate_call_nv(Kind k) {} -inline void SpecializationStats::record_do_oop_call_v(Kind k) {} -inline void SpecializationStats::record_do_oop_call_nv(Kind k) {} -inline void SpecializationStats::clear() {} -inline void SpecializationStats::print() {} - -#endif // ENABLE_SPECIALIZATION_STATS -#endif // !PRODUCT - #endif // SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP diff --git a/hotspot/src/share/vm/memory/tenuredGeneration.cpp b/hotspot/src/share/vm/memory/tenuredGeneration.cpp index fff78747791..e300ee43eea 100644 --- a/hotspot/src/share/vm/memory/tenuredGeneration.cpp +++ b/hotspot/src/share/vm/memory/tenuredGeneration.cpp @@ -178,7 +178,6 @@ void TenuredGeneration::collect(bool full, bool is_tlab) { GenCollectedHeap* gch = GenCollectedHeap::heap(); - SpecializationStats::clear(); // Temporarily expand the span of our ref processor, so // refs discovery is over the entire heap, not just this generation ReferenceProcessorSpanMutator @@ -195,8 +194,6 @@ void TenuredGeneration::collect(bool full, gc_timer->register_gc_end(); gc_tracer->report_gc_end(gc_timer->gc_end(), gc_timer->time_partitions()); - - SpecializationStats::print(); } HeapWord* diff --git a/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp b/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp index 181db6e675a..209113db164 100644 --- a/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp @@ -54,7 +54,6 @@ int InstanceClassLoaderKlass:: \ oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ /* Get size before changing pointers */ \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk);\ int size = InstanceKlass::oop_oop_iterate##nv_suffix(obj, closure); \ \ if_do_metadata_checked(closure, nv_suffix) { \ @@ -74,7 +73,6 @@ oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { int InstanceClassLoaderKlass:: \ oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) { \ /* Get size before changing pointers */ \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk);\ int size = InstanceKlass::oop_oop_iterate_backwards##nv_suffix(obj, closure); \ return size; \ } @@ -87,8 +85,6 @@ int InstanceClassLoaderKlass:: oop_oop_iterate##nv_suffix##_m(oop obj, \ OopClosureType* closure, \ MemRegion mr) { \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk);\ - \ int size = InstanceKlass::oop_oop_iterate##nv_suffix##_m(obj, closure, mr); \ \ if_do_metadata_checked(closure, nv_suffix) { \ diff --git a/hotspot/src/share/vm/oops/instanceKlass.cpp b/hotspot/src/share/vm/oops/instanceKlass.cpp index 91843cdb2f5..a539bb7e7f1 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceKlass.cpp @@ -2209,15 +2209,12 @@ void InstanceKlass::oop_follow_contents(ParCompactionManager* cm, #define InstanceKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ \ int InstanceKlass::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ /* header */ \ if_do_metadata_checked(closure, nv_suffix) { \ closure->do_klass##nv_suffix(obj->klass()); \ } \ InstanceKlass_OOP_MAP_ITERATE( \ obj, \ - SpecializationStats:: \ - record_do_oop_call##nv_suffix(SpecializationStats::ik); \ (closure)->do_oop##nv_suffix(p), \ assert_is_in_closed_subset) \ return size_helper(); \ @@ -2228,14 +2225,11 @@ int InstanceKlass::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) \ int InstanceKlass::oop_oop_iterate_backwards##nv_suffix(oop obj, \ OopClosureType* closure) { \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik); \ - \ assert_should_ignore_metadata(closure, nv_suffix); \ \ /* instance variables */ \ InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ obj, \ - SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::ik);\ (closure)->do_oop##nv_suffix(p), \ assert_is_in_closed_subset) \ return size_helper(); \ @@ -2247,7 +2241,6 @@ int InstanceKlass::oop_oop_iterate_backwards##nv_suffix(oop obj, int InstanceKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \ OopClosureType* closure, \ MemRegion mr) { \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ if_do_metadata_checked(closure, nv_suffix) { \ if (mr.contains(obj)) { \ closure->do_klass##nv_suffix(obj->klass()); \ diff --git a/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp b/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp index 09a73f79de5..694b0f4ccad 100644 --- a/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp @@ -250,8 +250,6 @@ int InstanceMirrorKlass::oop_adjust_pointers(oop obj) { int InstanceMirrorKlass:: \ oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ /* Get size before changing pointers */ \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk); \ - \ InstanceKlass::oop_oop_iterate##nv_suffix(obj, closure); \ \ if_do_metadata_checked(closure, nv_suffix) { \ @@ -275,8 +273,6 @@ oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { int InstanceMirrorKlass:: \ oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) { \ /* Get size before changing pointers */ \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk); \ - \ InstanceKlass::oop_oop_iterate_backwards##nv_suffix(obj, closure); \ \ if (UseCompressedOops) { \ @@ -294,8 +290,6 @@ int InstanceMirrorKlass:: oop_oop_iterate##nv_suffix##_m(oop obj, \ OopClosureType* closure, \ MemRegion mr) { \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk); \ - \ InstanceKlass::oop_oop_iterate##nv_suffix##_m(obj, closure, mr); \ \ if_do_metadata_checked(closure, nv_suffix) { \ diff --git a/hotspot/src/share/vm/oops/instanceRefKlass.cpp b/hotspot/src/share/vm/oops/instanceRefKlass.cpp index a149893148c..af960aab651 100644 --- a/hotspot/src/share/vm/oops/instanceRefKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceRefKlass.cpp @@ -260,7 +260,6 @@ int InstanceRefKlass::oop_adjust_pointers(oop obj) { return size; \ } else if (contains(referent_addr)) { \ /* treat referent as normal oop */ \ - SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::irk);\ closure->do_oop##nv_suffix(referent_addr); \ } \ } \ @@ -276,7 +275,6 @@ int InstanceRefKlass::oop_adjust_pointers(oop obj) { INTPTR_FORMAT, disc_addr); \ } \ ) \ - SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::irk);\ closure->do_oop##nv_suffix(disc_addr); \ } \ } else { \ @@ -293,7 +291,6 @@ int InstanceRefKlass::oop_adjust_pointers(oop obj) { } \ /* treat next as normal oop */ \ if (contains(next_addr)) { \ - SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::irk); \ closure->do_oop##nv_suffix(next_addr); \ } \ return size; \ @@ -309,8 +306,6 @@ template bool contains(T *t) { return true; } int InstanceRefKlass:: \ oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ /* Get size before changing pointers */ \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk);\ - \ int size = InstanceKlass::oop_oop_iterate##nv_suffix(obj, closure); \ \ if (UseCompressedOops) { \ @@ -326,8 +321,6 @@ oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { int InstanceRefKlass:: \ oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) { \ /* Get size before changing pointers */ \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk);\ - \ int size = InstanceKlass::oop_oop_iterate_backwards##nv_suffix(obj, closure); \ \ if (UseCompressedOops) { \ @@ -345,8 +338,6 @@ int InstanceRefKlass:: oop_oop_iterate##nv_suffix##_m(oop obj, \ OopClosureType* closure, \ MemRegion mr) { \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk);\ - \ int size = InstanceKlass::oop_oop_iterate##nv_suffix##_m(obj, closure, mr); \ if (UseCompressedOops) { \ InstanceRefKlass_SPECIALIZED_OOP_ITERATE(narrowOop, nv_suffix, mr.contains); \ diff --git a/hotspot/src/share/vm/oops/objArrayKlass.cpp b/hotspot/src/share/vm/oops/objArrayKlass.cpp index 002196fe0b1..84990ebe967 100644 --- a/hotspot/src/share/vm/oops/objArrayKlass.cpp +++ b/hotspot/src/share/vm/oops/objArrayKlass.cpp @@ -479,7 +479,6 @@ void ObjArrayKlass::oop_follow_contents(ParCompactionManager* cm, \ int ObjArrayKlass::oop_oop_iterate##nv_suffix(oop obj, \ OopClosureType* closure) { \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \ assert (obj->is_array(), "obj must be array"); \ objArrayOop a = objArrayOop(obj); \ /* Get size before changing pointers. */ \ @@ -497,7 +496,6 @@ int ObjArrayKlass::oop_oop_iterate##nv_suffix(oop obj, int ObjArrayKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \ OopClosureType* closure, \ MemRegion mr) { \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \ assert(obj->is_array(), "obj must be array"); \ objArrayOop a = objArrayOop(obj); \ /* Get size before changing pointers. */ \ @@ -519,7 +517,6 @@ int ObjArrayKlass::oop_oop_iterate##nv_suffix##_m(oop obj, int ObjArrayKlass::oop_oop_iterate_range##nv_suffix(oop obj, \ OopClosureType* closure, \ int start, int end) { \ - SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \ assert(obj->is_array(), "obj must be array"); \ objArrayOop a = objArrayOop(obj); \ /* Get size before changing pointers. */ \ diff --git a/hotspot/src/share/vm/oops/objArrayOop.cpp b/hotspot/src/share/vm/oops/objArrayOop.cpp index 2d91b46a680..90dcce5cb7a 100644 --- a/hotspot/src/share/vm/oops/objArrayOop.cpp +++ b/hotspot/src/share/vm/oops/objArrayOop.cpp @@ -46,7 +46,6 @@ oop objArrayOopDesc::atomic_compare_exchange_oop(int index, oop exchange_value, #define ObjArrayOop_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ \ int objArrayOopDesc::oop_iterate_range(OopClosureType* blk, int start, int end) { \ - SpecializationStats::record_call(); \ return ((ObjArrayKlass*)klass())->oop_oop_iterate_range##nv_suffix(this, blk, start, end); \ } diff --git a/hotspot/src/share/vm/oops/oop.inline.hpp b/hotspot/src/share/vm/oops/oop.inline.hpp index 8c9949d1bd6..8adee1393e8 100644 --- a/hotspot/src/share/vm/oops/oop.inline.hpp +++ b/hotspot/src/share/vm/oops/oop.inline.hpp @@ -692,12 +692,10 @@ inline int oopDesc::adjust_pointers() { #define OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ \ inline int oopDesc::oop_iterate(OopClosureType* blk) { \ - SpecializationStats::record_call(); \ return klass()->oop_oop_iterate##nv_suffix(this, blk); \ } \ \ inline int oopDesc::oop_iterate(OopClosureType* blk, MemRegion mr) { \ - SpecializationStats::record_call(); \ return klass()->oop_oop_iterate##nv_suffix##_m(this, blk, mr); \ } @@ -721,7 +719,6 @@ ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_ITERATE_DEFN) #define OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \ \ inline int oopDesc::oop_iterate_backwards(OopClosureType* blk) { \ - SpecializationStats::record_call(); \ return klass()->oop_oop_iterate_backwards##nv_suffix(this, blk); \ } From 366bf9ff0978f654f3e866e749e3360c187f9b32 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Tue, 17 Mar 2015 14:18:52 +0100 Subject: [PATCH 029/362] 8075247: Cleanup specialized_oop_closures.hpp Reviewed-by: mgerdin, brutisso, tschatzl --- .../vm/gc_implementation/g1/g1OopClosures.hpp | 12 +++++ .../g1/g1_specialized_oop_closures.hpp | 47 +++++-------------- .../vm/gc_implementation/g1/heapRegion.hpp | 1 - .../vm/memory/specialized_oop_closures.hpp | 27 ++++------- .../vm/oops/instanceClassLoaderKlass.cpp | 1 + .../vm/oops/instanceClassLoaderKlass.hpp | 1 + hotspot/src/share/vm/oops/instanceKlass.cpp | 1 + hotspot/src/share/vm/oops/instanceKlass.hpp | 1 + .../src/share/vm/oops/instanceMirrorKlass.cpp | 1 + .../src/share/vm/oops/instanceMirrorKlass.hpp | 1 + .../src/share/vm/oops/instanceRefKlass.cpp | 1 + .../src/share/vm/oops/instanceRefKlass.hpp | 1 + hotspot/src/share/vm/oops/objArrayKlass.cpp | 1 + hotspot/src/share/vm/oops/objArrayOop.cpp | 1 + hotspot/src/share/vm/oops/objArrayOop.hpp | 1 + .../src/share/vm/precompiled/precompiled.hpp | 2 - 16 files changed, 43 insertions(+), 57 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1OopClosures.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1OopClosures.hpp index 4f6e655b511..44a6c1220d2 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1OopClosures.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1OopClosures.hpp @@ -109,6 +109,18 @@ protected: template void do_klass_barrier(T* p, oop new_obj); }; +enum G1Barrier { + G1BarrierNone, + G1BarrierEvac, + G1BarrierKlass +}; + +enum G1Mark { + G1MarkNone, + G1MarkFromRoot, + G1MarkPromotedFromRoot +}; + template class G1ParCopyClosure : public G1ParCopyHelper { private: diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1_specialized_oop_closures.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1_specialized_oop_closures.hpp index 309392cc0ce..f3c49d7fc15 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1_specialized_oop_closures.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1_specialized_oop_closures.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -30,23 +30,8 @@ // non-virtually, using a mechanism defined in this file. Extend these // macros in the obvious way to add specializations for new closures. -enum G1Barrier { - G1BarrierNone, - G1BarrierEvac, - G1BarrierKlass -}; - -enum G1Mark { - G1MarkNone, - G1MarkFromRoot, - G1MarkPromotedFromRoot -}; - // Forward declarations. -template -class G1ParCopyClosure; - class G1ParScanClosure; class G1ParPushHeapRSClosure; @@ -61,26 +46,16 @@ class G1TriggerClosure; class G1InvokeIfNotTriggeredClosure; class G1UpdateRSOrPushRefOopClosure; -#ifdef FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES -#error "FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES already defined." -#endif - -#define FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) \ - f(G1ParScanClosure,_nv) \ - f(G1ParPushHeapRSClosure,_nv) \ - f(FilterIntoCSClosure,_nv) \ - f(FilterOutOfRegionClosure,_nv) \ - f(G1CMOopClosure,_nv) \ - f(G1RootRegionScanClosure,_nv) \ - f(G1Mux2Closure,_nv) \ - f(G1TriggerClosure,_nv) \ - f(G1InvokeIfNotTriggeredClosure,_nv) \ +#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_G1(f) \ + f(G1ParScanClosure,_nv) \ + f(G1ParPushHeapRSClosure,_nv) \ + f(FilterIntoCSClosure,_nv) \ + f(FilterOutOfRegionClosure,_nv) \ + f(G1CMOopClosure,_nv) \ + f(G1RootRegionScanClosure,_nv) \ + f(G1Mux2Closure,_nv) \ + f(G1TriggerClosure,_nv) \ + f(G1InvokeIfNotTriggeredClosure,_nv) \ f(G1UpdateRSOrPushRefOopClosure,_nv) -#ifdef FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES -#error "FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES already defined." -#endif - -#define FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) - #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1_SPECIALIZED_OOP_CLOSURES_HPP diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp index 93a149bdab1..ec5fb14e116 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp @@ -27,7 +27,6 @@ #include "gc_implementation/g1/g1AllocationContext.hpp" #include "gc_implementation/g1/g1BlockOffsetTable.hpp" -#include "gc_implementation/g1/g1_specialized_oop_closures.hpp" #include "gc_implementation/g1/heapRegionType.hpp" #include "gc_implementation/g1/survRateGroup.hpp" #include "gc_implementation/shared/ageTable.hpp" diff --git a/hotspot/src/share/vm/memory/specialized_oop_closures.hpp b/hotspot/src/share/vm/memory/specialized_oop_closures.hpp index 4fbd0b11935..5373ad8dcf3 100644 --- a/hotspot/src/share/vm/memory/specialized_oop_closures.hpp +++ b/hotspot/src/share/vm/memory/specialized_oop_closures.hpp @@ -69,12 +69,6 @@ class NoHeaderExtendedOopClosure; // This is split into several because of a Visual C++ 6.0 compiler bug // where very long macros cause the compiler to crash -// Some other heap might define further specialized closures. -#ifndef FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES -#define FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) \ - /* None */ -#endif - #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \ f(ScanClosure,_nv) \ f(FastScanClosure,_nv) \ @@ -94,7 +88,7 @@ class NoHeaderExtendedOopClosure; SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f) #if INCLUDE_ALL_GCS -#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) \ +#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_CMS(f) \ f(MarkRefsIntoAndScanClosure,_nv) \ f(Par_MarkRefsIntoAndScanClosure,_nv) \ f(PushAndMarkClosure,_nv) \ @@ -102,8 +96,13 @@ class NoHeaderExtendedOopClosure; f(PushOrMarkClosure,_nv) \ f(Par_PushOrMarkClosure,_nv) \ f(CMSKeepAliveClosure,_nv) \ - f(CMSInnerParMarkAndPushClosure,_nv) \ - FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) + f(CMSInnerParMarkAndPushClosure,_nv) +#endif + +#if INCLUDE_ALL_GCS +#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) \ + SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_CMS(f) \ + SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_G1(f) #else // INCLUDE_ALL_GCS #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) #endif // INCLUDE_ALL_GCS @@ -144,13 +143,6 @@ class NoHeaderExtendedOopClosure; // The "root_class" is the most general class to define; this may be // "OopClosure" in some applications and "OopsInGenClosure" in others. - -// Some other heap might define further specialized closures. -#ifndef FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES -#define FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \ - /* None */ -#endif - #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \ f(ScanClosure,_nv) \ f(FastScanClosure,_nv) @@ -158,8 +150,7 @@ class NoHeaderExtendedOopClosure; #if INCLUDE_ALL_GCS #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) \ f(ParScanWithBarrierClosure,_nv) \ - f(ParScanWithoutBarrierClosure,_nv) \ - FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) + f(ParScanWithoutBarrierClosure,_nv) #else // INCLUDE_ALL_GCS #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) #endif // INCLUDE_ALL_GCS diff --git a/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp b/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp index 209113db164..f49e376cbfc 100644 --- a/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp @@ -30,6 +30,7 @@ #include "memory/genOopClosures.inline.hpp" #include "memory/iterator.inline.hpp" #include "memory/oopFactory.hpp" +#include "memory/specialized_oop_closures.hpp" #include "oops/instanceKlass.hpp" #include "oops/instanceClassLoaderKlass.hpp" #include "oops/instanceMirrorKlass.hpp" diff --git a/hotspot/src/share/vm/oops/instanceClassLoaderKlass.hpp b/hotspot/src/share/vm/oops/instanceClassLoaderKlass.hpp index 309ebf96c19..2cec4827ddf 100644 --- a/hotspot/src/share/vm/oops/instanceClassLoaderKlass.hpp +++ b/hotspot/src/share/vm/oops/instanceClassLoaderKlass.hpp @@ -25,6 +25,7 @@ #ifndef SHARE_VM_OOPS_INSTANCECLASSLOADERKLASS_HPP #define SHARE_VM_OOPS_INSTANCECLASSLOADERKLASS_HPP +#include "memory/specialized_oop_closures.hpp" #include "oops/instanceKlass.hpp" #include "utilities/macros.hpp" diff --git a/hotspot/src/share/vm/oops/instanceKlass.cpp b/hotspot/src/share/vm/oops/instanceKlass.cpp index a539bb7e7f1..607ae834600 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceKlass.cpp @@ -38,6 +38,7 @@ #include "memory/iterator.inline.hpp" #include "memory/metadataFactory.hpp" #include "memory/oopFactory.hpp" +#include "memory/specialized_oop_closures.hpp" #include "oops/fieldStreams.hpp" #include "oops/instanceClassLoaderKlass.hpp" #include "oops/instanceKlass.hpp" diff --git a/hotspot/src/share/vm/oops/instanceKlass.hpp b/hotspot/src/share/vm/oops/instanceKlass.hpp index 507454e18b9..f163ed248dc 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.hpp +++ b/hotspot/src/share/vm/oops/instanceKlass.hpp @@ -27,6 +27,7 @@ #include "classfile/classLoaderData.hpp" #include "memory/referenceType.hpp" +#include "memory/specialized_oop_closures.hpp" #include "oops/annotations.hpp" #include "oops/constMethod.hpp" #include "oops/fieldInfo.hpp" diff --git a/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp b/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp index 694b0f4ccad..73d6e439d6d 100644 --- a/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp @@ -30,6 +30,7 @@ #include "memory/genOopClosures.inline.hpp" #include "memory/iterator.inline.hpp" #include "memory/oopFactory.hpp" +#include "memory/specialized_oop_closures.hpp" #include "oops/instanceKlass.hpp" #include "oops/instanceMirrorKlass.hpp" #include "oops/instanceOop.hpp" diff --git a/hotspot/src/share/vm/oops/instanceMirrorKlass.hpp b/hotspot/src/share/vm/oops/instanceMirrorKlass.hpp index b861639ee0f..368b41de9b4 100644 --- a/hotspot/src/share/vm/oops/instanceMirrorKlass.hpp +++ b/hotspot/src/share/vm/oops/instanceMirrorKlass.hpp @@ -26,6 +26,7 @@ #define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_HPP #include "classfile/systemDictionary.hpp" +#include "memory/specialized_oop_closures.hpp" #include "oops/instanceKlass.hpp" #include "runtime/handles.hpp" #include "utilities/macros.hpp" diff --git a/hotspot/src/share/vm/oops/instanceRefKlass.cpp b/hotspot/src/share/vm/oops/instanceRefKlass.cpp index af960aab651..12804db3508 100644 --- a/hotspot/src/share/vm/oops/instanceRefKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceRefKlass.cpp @@ -30,6 +30,7 @@ #include "gc_interface/collectedHeap.inline.hpp" #include "memory/genCollectedHeap.hpp" #include "memory/genOopClosures.inline.hpp" +#include "memory/specialized_oop_closures.hpp" #include "oops/instanceRefKlass.hpp" #include "oops/oop.inline.hpp" #include "utilities/preserveException.hpp" diff --git a/hotspot/src/share/vm/oops/instanceRefKlass.hpp b/hotspot/src/share/vm/oops/instanceRefKlass.hpp index 3140977b471..2f5b459d800 100644 --- a/hotspot/src/share/vm/oops/instanceRefKlass.hpp +++ b/hotspot/src/share/vm/oops/instanceRefKlass.hpp @@ -25,6 +25,7 @@ #ifndef SHARE_VM_OOPS_INSTANCEREFKLASS_HPP #define SHARE_VM_OOPS_INSTANCEREFKLASS_HPP +#include "memory/specialized_oop_closures.hpp" #include "oops/instanceKlass.hpp" #include "utilities/macros.hpp" diff --git a/hotspot/src/share/vm/oops/objArrayKlass.cpp b/hotspot/src/share/vm/oops/objArrayKlass.cpp index 84990ebe967..8c2670c5214 100644 --- a/hotspot/src/share/vm/oops/objArrayKlass.cpp +++ b/hotspot/src/share/vm/oops/objArrayKlass.cpp @@ -32,6 +32,7 @@ #include "memory/iterator.inline.hpp" #include "memory/metadataFactory.hpp" #include "memory/resourceArea.hpp" +#include "memory/specialized_oop_closures.hpp" #include "memory/universe.inline.hpp" #include "oops/instanceKlass.hpp" #include "oops/klass.inline.hpp" diff --git a/hotspot/src/share/vm/oops/objArrayOop.cpp b/hotspot/src/share/vm/oops/objArrayOop.cpp index 90dcce5cb7a..a0265ee5cba 100644 --- a/hotspot/src/share/vm/oops/objArrayOop.cpp +++ b/hotspot/src/share/vm/oops/objArrayOop.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "memory/specialized_oop_closures.hpp" #include "oops/objArrayKlass.hpp" #include "oops/objArrayOop.hpp" #include "oops/oop.inline.hpp" diff --git a/hotspot/src/share/vm/oops/objArrayOop.hpp b/hotspot/src/share/vm/oops/objArrayOop.hpp index 3b32e5bafc2..5ffc0d7aab9 100644 --- a/hotspot/src/share/vm/oops/objArrayOop.hpp +++ b/hotspot/src/share/vm/oops/objArrayOop.hpp @@ -25,6 +25,7 @@ #ifndef SHARE_VM_OOPS_OBJARRAYOOP_HPP #define SHARE_VM_OOPS_OBJARRAYOOP_HPP +#include "memory/specialized_oop_closures.hpp" #include "oops/arrayOop.hpp" // An objArrayOop is an array containing oops. diff --git a/hotspot/src/share/vm/precompiled/precompiled.hpp b/hotspot/src/share/vm/precompiled/precompiled.hpp index 400ad459a40..a2ae0465c3d 100644 --- a/hotspot/src/share/vm/precompiled/precompiled.hpp +++ b/hotspot/src/share/vm/precompiled/precompiled.hpp @@ -136,7 +136,6 @@ # include "memory/sharedHeap.hpp" # include "memory/space.hpp" # include "memory/space.inline.hpp" -# include "memory/specialized_oop_closures.hpp" # include "memory/threadLocalAllocBuffer.hpp" # include "memory/threadLocalAllocBuffer.inline.hpp" # include "memory/universe.hpp" @@ -310,7 +309,6 @@ # include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" # include "gc_implementation/g1/g1OopClosures.hpp" # include "gc_implementation/g1/g1_globals.hpp" -# include "gc_implementation/g1/g1_specialized_oop_closures.hpp" # include "gc_implementation/g1/ptrQueue.hpp" # include "gc_implementation/g1/satbQueue.hpp" # include "gc_implementation/parNew/parOopClosures.hpp" From 28adfbf0bed68f397836151e5caa8fc6d4c5bcbf Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Tue, 17 Mar 2015 15:53:55 +0100 Subject: [PATCH 030/362] 8075249: Cleanup forward_to_atomic and ClaimedForwardPtr Reviewed-by: kbarrett, brutisso --- .../g1/g1ParScanThreadState.cpp | 4 ++- .../parNew/parNewGeneration.cpp | 9 +------ .../parNew/parNewGeneration.hpp | 2 -- hotspot/src/share/vm/oops/oop.inline.hpp | 24 +++++++++++++++++ hotspot/src/share/vm/oops/oop.pcgc.inline.hpp | 26 +------------------ 5 files changed, 29 insertions(+), 36 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp index 8849d42dd78..2ec726e744e 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -226,6 +226,8 @@ oop G1ParScanThreadState::copy_to_survivor_space(InCSetState const state, } assert(obj_ptr != NULL, "when we get here, allocation should have succeeded"); + assert(_g1h->is_in_reserved(obj_ptr), "Allocated memory should be in the heap"); + #ifndef PRODUCT // Should this evacuation fail? if (_g1h->evacuation_should_fail()) { diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index 9ffe68a1b58..9df8c4e8c1c 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -1122,14 +1122,6 @@ oop ParNewGeneration::real_forwardee_slow(oop obj) { return forward_ptr; } -#ifdef ASSERT -bool ParNewGeneration::is_legal_forward_ptr(oop p) { - return - (p == ClaimedForwardPtr) - || Universe::heap()->is_in_reserved(p); -} -#endif - void ParNewGeneration::preserve_mark_if_necessary(oop obj, markOop m) { if (m->must_be_preserved_for_promotion_failure(obj)) { // We should really have separate per-worker stacks, rather @@ -1204,6 +1196,7 @@ oop ParNewGeneration::copy_to_survivor_space( } else { // Is in to-space; do copying ourselves. Copy::aligned_disjoint_words((HeapWord*)old, (HeapWord*)new_obj, sz); + assert(Universe::heap()->is_in_reserved(new_obj), "illegal forwarding pointer value."); forward_ptr = old->forward_to_atomic(new_obj); // Restore the mark word copied above. new_obj->set_mark(m); diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp index f14f6a6d354..aa97271ac85 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp @@ -419,8 +419,6 @@ class ParNewGeneration: public DefNewGeneration { } static oop real_forwardee(oop obj); - - DEBUG_ONLY(static bool is_legal_forward_ptr(oop p);) }; #endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP diff --git a/hotspot/src/share/vm/oops/oop.inline.hpp b/hotspot/src/share/vm/oops/oop.inline.hpp index 8adee1393e8..dfc5ac385aa 100644 --- a/hotspot/src/share/vm/oops/oop.inline.hpp +++ b/hotspot/src/share/vm/oops/oop.inline.hpp @@ -630,6 +630,30 @@ inline bool oopDesc::cas_forward_to(oop p, markOop compare) { return cas_set_mark(m, compare) == compare; } +#if INCLUDE_ALL_GCS +inline oop oopDesc::forward_to_atomic(oop p) { + markOop oldMark = mark(); + markOop forwardPtrMark = markOopDesc::encode_pointer_as_mark(p); + markOop curMark; + + assert(forwardPtrMark->decode_pointer() == p, "encoding must be reversable"); + assert(sizeof(markOop) == sizeof(intptr_t), "CAS below requires this."); + + while (!oldMark->is_marked()) { + curMark = (markOop)Atomic::cmpxchg_ptr(forwardPtrMark, &_mark, oldMark); + assert(is_forwarded(), "object should have been forwarded"); + if (curMark == oldMark) { + return NULL; + } + // If the CAS was unsuccessful then curMark->is_marked() + // should return true as another thread has CAS'd in another + // forwarding pointer. + oldMark = curMark; + } + return forwardee(); +} +#endif + // Note that the forwardee is not the same thing as the displaced_mark. // The forwardee is used when copying during scavenge and mark-sweep. // It does need to clear the low two locking- and GC-related bits. diff --git a/hotspot/src/share/vm/oops/oop.pcgc.inline.hpp b/hotspot/src/share/vm/oops/oop.pcgc.inline.hpp index a361e3bcc77..930a770f63b 100644 --- a/hotspot/src/share/vm/oops/oop.pcgc.inline.hpp +++ b/hotspot/src/share/vm/oops/oop.pcgc.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -54,28 +54,4 @@ inline void oopDesc::follow_contents(ParCompactionManager* cm) { klass()->oop_follow_contents(cm, this); } -inline oop oopDesc::forward_to_atomic(oop p) { - assert(ParNewGeneration::is_legal_forward_ptr(p), - "illegal forwarding pointer value."); - markOop oldMark = mark(); - markOop forwardPtrMark = markOopDesc::encode_pointer_as_mark(p); - markOop curMark; - - assert(forwardPtrMark->decode_pointer() == p, "encoding must be reversable"); - assert(sizeof(markOop) == sizeof(intptr_t), "CAS below requires this."); - - while (!oldMark->is_marked()) { - curMark = (markOop)Atomic::cmpxchg_ptr(forwardPtrMark, &_mark, oldMark); - assert(is_forwarded(), "object should have been forwarded"); - if (curMark == oldMark) { - return NULL; - } - // If the CAS was unsuccessful then curMark->is_marked() - // should return true as another thread has CAS'd in another - // forwarding pointer. - oldMark = curMark; - } - return forwardee(); -} - #endif // SHARE_VM_OOPS_OOP_PCGC_INLINE_HPP From 207fadd39e3301cb169b3ae5c400a670f34db23e Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Wed, 18 Mar 2015 10:51:00 +0100 Subject: [PATCH 031/362] 8075416: Cleanup GC include dependencies in memoryPool.hpp Reviewed-by: ehelin, mgerdin --- .../parNew/parNewGeneration.cpp | 1 + hotspot/src/share/vm/memory/cardTableRS.cpp | 2 +- .../share/vm/services/lowMemoryDetector.hpp | 1 + hotspot/src/share/vm/services/memoryPool.cpp | 27 ++++++++++++++++++- hotspot/src/share/vm/services/memoryPool.hpp | 22 +++++---------- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index 9df8c4e8c1c..1712e4edc94 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp" #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp" #include "gc_implementation/parNew/parNewGeneration.hpp" #include "gc_implementation/parNew/parOopClosures.inline.hpp" diff --git a/hotspot/src/share/vm/memory/cardTableRS.cpp b/hotspot/src/share/vm/memory/cardTableRS.cpp index 45e20deec48..be98f7a70a7 100644 --- a/hotspot/src/share/vm/memory/cardTableRS.cpp +++ b/hotspot/src/share/vm/memory/cardTableRS.cpp @@ -27,7 +27,7 @@ #include "memory/cardTableRS.hpp" #include "memory/genCollectedHeap.hpp" #include "memory/generation.hpp" -#include "memory/space.hpp" +#include "memory/space.inline.hpp" #include "oops/oop.inline.hpp" #include "runtime/atomic.inline.hpp" #include "runtime/java.hpp" diff --git a/hotspot/src/share/vm/services/lowMemoryDetector.hpp b/hotspot/src/share/vm/services/lowMemoryDetector.hpp index 3dda4f1ba5a..16c306f5301 100644 --- a/hotspot/src/share/vm/services/lowMemoryDetector.hpp +++ b/hotspot/src/share/vm/services/lowMemoryDetector.hpp @@ -28,6 +28,7 @@ #include "memory/allocation.hpp" #include "services/memoryPool.hpp" #include "services/memoryService.hpp" +#include "services/memoryUsage.hpp" // Low Memory Detection Support // Two memory alarms in the JDK (we called them sensors). diff --git a/hotspot/src/share/vm/services/memoryPool.cpp b/hotspot/src/share/vm/services/memoryPool.cpp index 2d686cbdc9a..e9bc4d0542b 100644 --- a/hotspot/src/share/vm/services/memoryPool.cpp +++ b/hotspot/src/share/vm/services/memoryPool.cpp @@ -25,7 +25,9 @@ #include "precompiled.hpp" #include "classfile/systemDictionary.hpp" #include "classfile/vmSymbols.hpp" +#include "memory/defNewGeneration.hpp" #include "memory/metaspace.hpp" +#include "memory/space.hpp" #include "oops/oop.inline.hpp" #include "runtime/handles.inline.hpp" #include "runtime/javaCalls.hpp" @@ -34,8 +36,11 @@ #include "services/management.hpp" #include "services/memoryManager.hpp" #include "services/memoryPool.hpp" -#include "utilities/macros.hpp" #include "utilities/globalDefinitions.hpp" +#include "utilities/macros.hpp" +#if INCLUDE_ALL_GCS +#include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp" +#endif MemoryPool::MemoryPool(const char* name, PoolType type, @@ -187,6 +192,10 @@ ContiguousSpacePool::ContiguousSpacePool(ContiguousSpace* space, support_usage_threshold), _space(space) { } +size_t ContiguousSpacePool::used_in_bytes() { + return space()->used(); +} + MemoryUsage ContiguousSpacePool::get_memory_usage() { size_t maxSize = (available_for_allocation() ? max_size() : 0); size_t used = used_in_bytes(); @@ -204,6 +213,14 @@ SurvivorContiguousSpacePool::SurvivorContiguousSpacePool(DefNewGeneration* gen, support_usage_threshold), _gen(gen) { } +size_t SurvivorContiguousSpacePool::used_in_bytes() { + return _gen->from()->used(); +} + +size_t SurvivorContiguousSpacePool::committed_in_bytes() { + return _gen->from()->capacity(); +} + MemoryUsage SurvivorContiguousSpacePool::get_memory_usage() { size_t maxSize = (available_for_allocation() ? max_size() : 0); size_t used = used_in_bytes(); @@ -222,6 +239,10 @@ CompactibleFreeListSpacePool::CompactibleFreeListSpacePool(CompactibleFreeListSp support_usage_threshold), _space(space) { } +size_t CompactibleFreeListSpacePool::used_in_bytes() { + return _space->used(); +} + MemoryUsage CompactibleFreeListSpacePool::get_memory_usage() { size_t maxSize = (available_for_allocation() ? max_size() : 0); size_t used = used_in_bytes(); @@ -239,6 +260,10 @@ GenerationPool::GenerationPool(Generation* gen, support_usage_threshold), _gen(gen) { } +size_t GenerationPool::used_in_bytes() { + return _gen->used(); +} + MemoryUsage GenerationPool::get_memory_usage() { size_t used = used_in_bytes(); size_t committed = _gen->capacity(); diff --git a/hotspot/src/share/vm/services/memoryPool.hpp b/hotspot/src/share/vm/services/memoryPool.hpp index 007366e0bd6..f9b7a0a4080 100644 --- a/hotspot/src/share/vm/services/memoryPool.hpp +++ b/hotspot/src/share/vm/services/memoryPool.hpp @@ -25,15 +25,9 @@ #ifndef SHARE_VM_SERVICES_MEMORYPOOL_HPP #define SHARE_VM_SERVICES_MEMORYPOOL_HPP -#include "gc_implementation/shared/mutableSpace.hpp" -#include "memory/defNewGeneration.hpp" #include "memory/heap.hpp" -#include "memory/space.hpp" #include "services/memoryUsage.hpp" #include "utilities/macros.hpp" -#if INCLUDE_ALL_GCS -#include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp" -#endif // INCLUDE_ALL_GCS // A memory pool represents the memory area that the VM manages. // The Java virtual machine has at least one memory pool @@ -43,6 +37,8 @@ // both heap and non-heap memory. // Forward declaration +class CompactibleFreeListSpace; +class ContiguousSpace; class MemoryManager; class SensorInfo; class Generation; @@ -162,7 +158,7 @@ public: ContiguousSpace* space() { return _space; } MemoryUsage get_memory_usage(); - size_t used_in_bytes() { return space()->used(); } + size_t used_in_bytes(); }; class SurvivorContiguousSpacePool : public CollectedMemoryPool { @@ -178,12 +174,8 @@ public: MemoryUsage get_memory_usage(); - size_t used_in_bytes() { - return _gen->from()->used(); - } - size_t committed_in_bytes() { - return _gen->from()->capacity(); - } + size_t used_in_bytes(); + size_t committed_in_bytes(); }; #if INCLUDE_ALL_GCS @@ -198,7 +190,7 @@ public: bool support_usage_threshold); MemoryUsage get_memory_usage(); - size_t used_in_bytes() { return _space->used(); } + size_t used_in_bytes(); }; #endif // INCLUDE_ALL_GCS @@ -210,7 +202,7 @@ public: GenerationPool(Generation* gen, const char* name, PoolType type, bool support_usage_threshold); MemoryUsage get_memory_usage(); - size_t used_in_bytes() { return _gen->used(); } + size_t used_in_bytes(); }; class CodeHeapPool: public MemoryPool { From f5292016eeaa1bf5065f28a21144d9b5231529da Mon Sep 17 00:00:00 2001 From: Mikael Gerdin Date: Mon, 1 Dec 2014 15:24:56 +0100 Subject: [PATCH 032/362] 8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap Create a G1RootProcessor and move SharedHeap root processing to GenCollectedHeap Reviewed-by: brutisso, tschatzl, ehelin --- .../concurrentMarkSweepGeneration.cpp | 22 +- .../gc_implementation/g1/g1CollectedHeap.cpp | 210 ++----------- .../gc_implementation/g1/g1CollectedHeap.hpp | 41 +-- .../vm/gc_implementation/g1/g1MarkSweep.cpp | 37 ++- .../vm/gc_implementation/g1/g1RemSet.cpp | 2 - .../vm/gc_implementation/g1/g1RemSet.hpp | 1 - .../gc_implementation/g1/g1RootProcessor.cpp | 290 ++++++++++++++++++ .../gc_implementation/g1/g1RootProcessor.hpp | 116 +++++++ .../parNew/parNewGeneration.cpp | 2 +- .../src/share/vm/memory/defNewGeneration.cpp | 2 +- .../src/share/vm/memory/genCollectedHeap.cpp | 199 ++++++++---- .../src/share/vm/memory/genCollectedHeap.hpp | 22 +- hotspot/src/share/vm/memory/genMarkSweep.cpp | 4 +- hotspot/src/share/vm/memory/sharedHeap.cpp | 215 +------------ hotspot/src/share/vm/memory/sharedHeap.hpp | 78 +---- 15 files changed, 645 insertions(+), 596 deletions(-) create mode 100644 hotspot/src/share/vm/gc_implementation/g1/g1RootProcessor.cpp create mode 100644 hotspot/src/share/vm/gc_implementation/g1/g1RootProcessor.hpp diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp index f48a34c1748..e273c205a37 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @@ -506,7 +506,7 @@ CMSCollector::CMSCollector(ConcurrentMarkSweepGeneration* cmsGen, _collector_policy(cp), _should_unload_classes(CMSClassUnloadingEnabled), _concurrent_cycles_since_last_unload(0), - _roots_scanning_options(SharedHeap::SO_None), + _roots_scanning_options(GenCollectedHeap::SO_None), _inter_sweep_estimate(CMS_SweepWeight, CMS_SweepPadding), _intra_sweep_estimate(CMS_SweepWeight, CMS_SweepPadding), _gc_tracer_cm(new (ResourceObj::C_HEAP, mtGC) CMSTracer()), @@ -2496,7 +2496,7 @@ void CMSCollector::verify_after_remark_work_1() { gch->gen_process_roots(_cmsGen->level(), true, // younger gens are roots true, // activate StrongRootsScope - SharedHeap::ScanningOption(roots_scanning_options()), + GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), ¬Older, NULL, @@ -2564,7 +2564,7 @@ void CMSCollector::verify_after_remark_work_2() { gch->gen_process_roots(_cmsGen->level(), true, // younger gens are roots true, // activate StrongRootsScope - SharedHeap::ScanningOption(roots_scanning_options()), + GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), ¬Older, NULL, @@ -2748,7 +2748,7 @@ bool ConcurrentMarkSweepGeneration::is_too_full() const { void CMSCollector::setup_cms_unloading_and_verification_state() { const bool should_verify = VerifyBeforeGC || VerifyAfterGC || VerifyDuringGC || VerifyBeforeExit; - const int rso = SharedHeap::SO_AllCodeCache; + const int rso = GenCollectedHeap::SO_AllCodeCache; // We set the proper root for this CMS cycle here. if (should_unload_classes()) { // Should unload classes this cycle @@ -3087,7 +3087,7 @@ void CMSCollector::checkpointRootsInitialWork() { gch->gen_process_roots(_cmsGen->level(), true, // younger gens are roots true, // activate StrongRootsScope - SharedHeap::ScanningOption(roots_scanning_options()), + GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), ¬Older, NULL, @@ -4521,13 +4521,13 @@ void CMSParInitialMarkTask::work(uint worker_id) { gch->gen_process_roots(_collector->_cmsGen->level(), false, // yg was scanned above false, // this is parallel code - SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), + GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), _collector->should_unload_classes(), &par_mri_cl, NULL, &cld_closure); assert(_collector->should_unload_classes() - || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), + || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache), "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); _timer.stop(); if (PrintCMSStatistics != 0) { @@ -4657,14 +4657,14 @@ void CMSParRemarkTask::work(uint worker_id) { gch->gen_process_roots(_collector->_cmsGen->level(), false, // yg was scanned above false, // this is parallel code - SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), + GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), _collector->should_unload_classes(), &par_mrias_cl, NULL, NULL); // The dirty klasses will be handled below assert(_collector->should_unload_classes() - || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), + || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache), "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); _timer.stop(); if (PrintCMSStatistics != 0) { @@ -5248,14 +5248,14 @@ void CMSCollector::do_remark_non_parallel() { gch->gen_process_roots(_cmsGen->level(), true, // younger gens as roots false, // use the local StrongRootsScope - SharedHeap::ScanningOption(roots_scanning_options()), + GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), &mrias_cl, NULL, NULL); // The dirty klasses will be handled below assert(should_unload_classes() - || (roots_scanning_options() & SharedHeap::SO_AllCodeCache), + || (roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache), "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); } diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index ed964c52e8c..18b2770207b 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -48,6 +48,7 @@ #include "gc_implementation/g1/g1ParScanThreadState.inline.hpp" #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp" #include "gc_implementation/g1/g1RemSet.inline.hpp" +#include "gc_implementation/g1/g1RootProcessor.hpp" #include "gc_implementation/g1/g1StringDedup.hpp" #include "gc_implementation/g1/g1YCTypes.hpp" #include "gc_implementation/g1/heapRegion.inline.hpp" @@ -89,18 +90,6 @@ size_t G1CollectedHeap::_humongous_object_threshold_in_words = 0; // apply to TLAB allocation, which is not part of this interface: it // is done by clients of this interface.) -// Notes on implementation of parallelism in different tasks. -// -// G1ParVerifyTask uses heap_region_par_iterate() for parallelism. -// The number of GC workers is passed to heap_region_par_iterate(). -// It does use run_task() which sets _n_workers in the task. -// G1ParTask executes g1_process_roots() -> -// SharedHeap::process_roots() which calls eventually to -// CardTableModRefBS::par_non_clean_card_iterate_work() which uses -// SequentialSubTasksDone. SharedHeap::process_roots() also -// directly uses SubTasksDone (_process_strong_tasks field in SharedHeap). -// - // Local to this file. class RefineCardTableEntryClosure: public CardTableEntryClosure { @@ -1767,7 +1756,6 @@ G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* policy_) : _is_alive_closure_stw(this), _ref_processor_cm(NULL), _ref_processor_stw(NULL), - _process_strong_tasks(new SubTasksDone(G1H_PS_NumElements)), _bot_shared(NULL), _evac_failure_scan_stack(NULL), _mark_in_progress(false), @@ -1801,9 +1789,6 @@ G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* policy_) : _gc_tracer_cm(new (ResourceObj::C_HEAP, mtGC) G1OldTracer()) { _g1h = this; - if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) { - vm_exit_during_initialization("Failed necessary allocation."); - } _allocator = G1Allocator::create_allocator(_g1h); _humongous_object_threshold_in_words = HeapRegion::GrainWords / 2; @@ -3107,11 +3092,12 @@ void G1CollectedHeap::verify(bool silent, VerifyOption vo) { G1VerifyCodeRootOopClosure codeRootsCl(this, &rootsCl, vo); G1VerifyCodeRootBlobClosure blobsCl(&codeRootsCl); - process_all_roots(true, // activate StrongRootsScope - SO_AllCodeCache, // roots scanning options - &rootsCl, - &cldCl, - &blobsCl); + { + G1RootProcessor root_processor(this); + root_processor.process_all_roots(&rootsCl, + &cldCl, + &blobsCl); + } bool failures = rootsCl.failures() || codeRootsCl.failures(); @@ -4360,60 +4346,11 @@ class G1KlassScanClosure : public KlassClosure { } }; -class G1CodeBlobClosure : public CodeBlobClosure { - class HeapRegionGatheringOopClosure : public OopClosure { - G1CollectedHeap* _g1h; - OopClosure* _work; - nmethod* _nm; - - template - void do_oop_work(T* p) { - _work->do_oop(p); - T oop_or_narrowoop = oopDesc::load_heap_oop(p); - if (!oopDesc::is_null(oop_or_narrowoop)) { - oop o = oopDesc::decode_heap_oop_not_null(oop_or_narrowoop); - HeapRegion* hr = _g1h->heap_region_containing_raw(o); - assert(!_g1h->obj_in_cs(o) || hr->rem_set()->strong_code_roots_list_contains(_nm), "if o still in CS then evacuation failed and nm must already be in the remset"); - hr->add_strong_code_root(_nm); - } - } - - public: - HeapRegionGatheringOopClosure(OopClosure* oc) : _g1h(G1CollectedHeap::heap()), _work(oc), _nm(NULL) {} - - void do_oop(oop* o) { - do_oop_work(o); - } - - void do_oop(narrowOop* o) { - do_oop_work(o); - } - - void set_nm(nmethod* nm) { - _nm = nm; - } - }; - - HeapRegionGatheringOopClosure _oc; -public: - G1CodeBlobClosure(OopClosure* oc) : _oc(oc) {} - - void do_code_blob(CodeBlob* cb) { - nmethod* nm = cb->as_nmethod_or_null(); - if (nm != NULL) { - if (!nm->test_set_oops_do_mark()) { - _oc.set_nm(nm); - nm->oops_do(&_oc); - nm->fix_oop_relocations(); - } - } - } -}; - class G1ParTask : public AbstractGangTask { protected: G1CollectedHeap* _g1h; RefToScanQueueSet *_queues; + G1RootProcessor* _root_processor; ParallelTaskTerminator _terminator; uint _n_workers; @@ -4421,10 +4358,11 @@ protected: Mutex* stats_lock() { return &_stats_lock; } public: - G1ParTask(G1CollectedHeap* g1h, RefToScanQueueSet *task_queues) + G1ParTask(G1CollectedHeap* g1h, RefToScanQueueSet *task_queues, G1RootProcessor* root_processor) : AbstractGangTask("G1 collection"), _g1h(g1h), _queues(task_queues), + _root_processor(root_processor), _terminator(0, _queues), _stats_lock(Mutex::leaf, "parallel G1 stats lock", true) {} @@ -4438,13 +4376,7 @@ public: ParallelTaskTerminator* terminator() { return &_terminator; } virtual void set_for_termination(int active_workers) { - // This task calls set_n_termination() in par_non_clean_card_iterate_work() - // in the young space (_par_seq_tasks) in the G1 heap - // for SequentialSubTasksDone. - // This task also uses SubTasksDone in SharedHeap and G1CollectedHeap - // both of which need setting by set_n_termination(). - _g1h->SharedHeap::set_n_termination(active_workers); - _g1h->set_n_termination(active_workers); + _root_processor->set_num_workers(active_workers); terminator()->reset_for_reuse(active_workers); _n_workers = active_workers; } @@ -4513,24 +4445,21 @@ public: false, // Process all klasses. true); // Need to claim CLDs. - G1CodeBlobClosure scan_only_code_cl(&scan_only_root_cl); - G1CodeBlobClosure scan_mark_code_cl(&scan_mark_root_cl); - // IM Weak code roots are handled later. - OopClosure* strong_root_cl; OopClosure* weak_root_cl; CLDClosure* strong_cld_cl; CLDClosure* weak_cld_cl; - CodeBlobClosure* strong_code_cl; + + bool trace_metadata = false; if (_g1h->g1_policy()->during_initial_mark_pause()) { // We also need to mark copied objects. strong_root_cl = &scan_mark_root_cl; strong_cld_cl = &scan_mark_cld_cl; - strong_code_cl = &scan_mark_code_cl; if (ClassUnloadingWithConcurrentMark) { weak_root_cl = &scan_mark_weak_root_cl; weak_cld_cl = &scan_mark_weak_cld_cl; + trace_metadata = true; } else { weak_root_cl = &scan_mark_root_cl; weak_cld_cl = &scan_mark_cld_cl; @@ -4540,21 +4469,21 @@ public: weak_root_cl = &scan_only_root_cl; strong_cld_cl = &scan_only_cld_cl; weak_cld_cl = &scan_only_cld_cl; - strong_code_cl = &scan_only_code_cl; } - - G1ParPushHeapRSClosure push_heap_rs_cl(_g1h, &pss); - pss.start_strong_roots(); - _g1h->g1_process_roots(strong_root_cl, - weak_root_cl, - &push_heap_rs_cl, - strong_cld_cl, - weak_cld_cl, - strong_code_cl, - worker_id); + _root_processor->evacuate_roots(strong_root_cl, + weak_root_cl, + strong_cld_cl, + weak_cld_cl, + trace_metadata, + worker_id); + + G1ParPushHeapRSClosure push_heap_rs_cl(_g1h, &pss); + _root_processor->scan_remembered_sets(&push_heap_rs_cl, + weak_root_cl, + worker_id); pss.end_strong_roots(); { @@ -4585,87 +4514,6 @@ public: } }; -// *** Common G1 Evacuation Stuff - -// This method is run in a GC worker. - -void -G1CollectedHeap:: -g1_process_roots(OopClosure* scan_non_heap_roots, - OopClosure* scan_non_heap_weak_roots, - G1ParPushHeapRSClosure* scan_rs, - CLDClosure* scan_strong_clds, - CLDClosure* scan_weak_clds, - CodeBlobClosure* scan_strong_code, - uint worker_i) { - - // First scan the shared roots. - double ext_roots_start = os::elapsedTime(); - double closure_app_time_sec = 0.0; - - bool during_im = _g1h->g1_policy()->during_initial_mark_pause(); - bool trace_metadata = during_im && ClassUnloadingWithConcurrentMark; - - BufferingOopClosure buf_scan_non_heap_roots(scan_non_heap_roots); - BufferingOopClosure buf_scan_non_heap_weak_roots(scan_non_heap_weak_roots); - - process_roots(false, // no scoping; this is parallel code - SharedHeap::SO_None, - &buf_scan_non_heap_roots, - &buf_scan_non_heap_weak_roots, - scan_strong_clds, - // Unloading Initial Marks handle the weak CLDs separately. - (trace_metadata ? NULL : scan_weak_clds), - scan_strong_code); - - // Now the CM ref_processor roots. - if (!_process_strong_tasks->is_task_claimed(G1H_PS_refProcessor_oops_do)) { - // We need to treat the discovered reference lists of the - // concurrent mark ref processor as roots and keep entries - // (which are added by the marking threads) on them live - // until they can be processed at the end of marking. - ref_processor_cm()->weak_oops_do(&buf_scan_non_heap_roots); - } - - if (trace_metadata) { - // Barrier to make sure all workers passed - // the strong CLD and strong nmethods phases. - active_strong_roots_scope()->wait_until_all_workers_done_with_threads(n_par_threads()); - - // Now take the complement of the strong CLDs. - ClassLoaderDataGraph::roots_cld_do(NULL, scan_weak_clds); - } - - // Finish up any enqueued closure apps (attributed as object copy time). - buf_scan_non_heap_roots.done(); - buf_scan_non_heap_weak_roots.done(); - - double obj_copy_time_sec = buf_scan_non_heap_roots.closure_app_seconds() - + buf_scan_non_heap_weak_roots.closure_app_seconds(); - - g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, obj_copy_time_sec); - - double ext_root_time_sec = os::elapsedTime() - ext_roots_start - obj_copy_time_sec; - g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::ExtRootScan, worker_i, ext_root_time_sec); - - // During conc marking we have to filter the per-thread SATB buffers - // to make sure we remove any oops into the CSet (which will show up - // as implicitly live). - { - G1GCParPhaseTimesTracker x(g1_policy()->phase_times(), G1GCPhaseTimes::SATBFiltering, worker_i); - if (!_process_strong_tasks->is_task_claimed(G1H_PS_filter_satb_buffers) && mark_in_progress()) { - JavaThread::satb_mark_queue_set().filter_thread_buffers(); - } - } - - // Now scan the complement of the collection set. - G1CodeBlobClosure scavenge_cs_nmethods(scan_non_heap_weak_roots); - - g1_rem_set()->oops_into_collection_set_do(scan_rs, &scavenge_cs_nmethods, worker_i); - - _process_strong_tasks->all_tasks_completed(); -} - class G1StringSymbolTableUnlinkTask : public AbstractGangTask { private: BoolObjectClosure* _is_alive; @@ -5612,7 +5460,6 @@ void G1CollectedHeap::evacuate_collection_set(EvacuationInfo& evacuation_info) { workers()->set_active_workers(n_workers); set_par_threads(n_workers); - G1ParTask g1_par_task(this, _task_queues); init_for_evac_failure(NULL); @@ -5621,7 +5468,8 @@ void G1CollectedHeap::evacuate_collection_set(EvacuationInfo& evacuation_info) { double end_par_time_sec; { - StrongRootsScope srs(this); + G1RootProcessor root_processor(this); + G1ParTask g1_par_task(this, _task_queues, &root_processor); // InitialMark needs claim bits to keep track of the marked-through CLDs. if (g1_policy()->during_initial_mark_pause()) { ClassLoaderDataGraph::clear_claimed_marks(); @@ -5637,9 +5485,9 @@ void G1CollectedHeap::evacuate_collection_set(EvacuationInfo& evacuation_info) { end_par_time_sec = os::elapsedTime(); // Closing the inner scope will execute the destructor - // for the StrongRootsScope object. We record the current + // for the G1RootProcessor object. We record the current // elapsed time before closing the scope so that time - // taken for the SRS destructor is NOT included in the + // taken for the destructor is NOT included in the // reported parallel time. } diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp index 3d83853698a..91b47100797 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @@ -780,22 +780,6 @@ protected: // statistics or updating free lists. void abandon_collection_set(HeapRegion* cs_head); - // Applies "scan_non_heap_roots" to roots outside the heap, - // "scan_rs" to roots inside the heap (having done "set_region" to - // indicate the region in which the root resides), - // and does "scan_metadata" If "scan_rs" is - // NULL, then this step is skipped. The "worker_i" - // param is for use with parallel roots processing, and should be - // the "i" of the calling parallel worker thread's work(i) function. - // In the sequential case this param will be ignored. - void g1_process_roots(OopClosure* scan_non_heap_roots, - OopClosure* scan_non_heap_weak_roots, - G1ParPushHeapRSClosure* scan_rs, - CLDClosure* scan_strong_clds, - CLDClosure* scan_weak_clds, - CodeBlobClosure* scan_strong_code, - uint worker_i); - // The concurrent marker (and the thread it runs in.) ConcurrentMark* _cm; ConcurrentMarkThread* _cmThread; @@ -982,21 +966,10 @@ protected: // of G1CollectedHeap::_gc_time_stamp. uint* _worker_cset_start_region_time_stamp; - enum G1H_process_roots_tasks { - G1H_PS_filter_satb_buffers, - G1H_PS_refProcessor_oops_do, - // Leave this one last. - G1H_PS_NumElements - }; - - SubTasksDone* _process_strong_tasks; - volatile bool _free_regions_coming; public: - SubTasksDone* process_strong_tasks() { return _process_strong_tasks; } - void set_refine_cte_cl_concurrency(bool concurrent); RefToScanQueue *task_queue(int i) const; @@ -1029,21 +1002,11 @@ public: // Initialize weak reference processing. virtual void ref_processing_init(); - void set_par_threads(uint t) { - SharedHeap::set_par_threads(t); - // Done in SharedHeap but oddly there are - // two _process_strong_tasks's in a G1CollectedHeap - // so do it here too. - _process_strong_tasks->set_n_threads(t); - } - + // Explicitly import set_par_threads into this scope + using SharedHeap::set_par_threads; // Set _n_par_threads according to a policy TBD. void set_par_threads(); - void set_n_termination(int t) { - _process_strong_tasks->set_n_threads(t); - } - virtual CollectedHeap::Name kind() const { return CollectedHeap::G1CollectedHeap; } diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp index 7ea825d9db2..29020bc8782 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp @@ -31,6 +31,7 @@ #include "code/icBuffer.hpp" #include "gc_implementation/g1/g1Log.hpp" #include "gc_implementation/g1/g1MarkSweep.hpp" +#include "gc_implementation/g1/g1RootProcessor.hpp" #include "gc_implementation/g1/g1StringDedup.hpp" #include "gc_implementation/shared/gcHeapSummary.hpp" #include "gc_implementation/shared/gcTimer.hpp" @@ -125,21 +126,22 @@ void G1MarkSweep::mark_sweep_phase1(bool& marked_for_unloading, GCTraceTime tm("phase 1", G1Log::fine() && Verbose, true, gc_timer(), gc_tracer()->gc_id()); GenMarkSweep::trace(" 1"); - SharedHeap* sh = SharedHeap::heap(); + G1CollectedHeap* g1h = G1CollectedHeap::heap(); // Need cleared claim bits for the roots processing ClassLoaderDataGraph::clear_claimed_marks(); MarkingCodeBlobClosure follow_code_closure(&GenMarkSweep::follow_root_closure, !CodeBlobToOopClosure::FixRelocations); - sh->process_strong_roots(true, // activate StrongRootsScope - SharedHeap::SO_None, - &GenMarkSweep::follow_root_closure, - &GenMarkSweep::follow_cld_closure, - &follow_code_closure); + { + G1RootProcessor root_processor(g1h); + root_processor.process_strong_roots(&GenMarkSweep::follow_root_closure, + &GenMarkSweep::follow_cld_closure, + &follow_code_closure); + } // Process reference objects found during marking ReferenceProcessor* rp = GenMarkSweep::ref_processor(); - assert(rp == G1CollectedHeap::heap()->ref_processor_stw(), "Sanity"); + assert(rp == g1h->ref_processor_stw(), "Sanity"); rp->setup_policy(clear_all_softrefs); const ReferenceProcessorStats& stats = @@ -225,6 +227,12 @@ class G1AdjustPointersClosure: public HeapRegionClosure { } }; +class G1AlwaysTrueClosure: public BoolObjectClosure { +public: + bool do_object_b(oop p) { return true; } +}; +static G1AlwaysTrueClosure always_true; + void G1MarkSweep::mark_sweep_phase3() { G1CollectedHeap* g1h = G1CollectedHeap::heap(); @@ -232,24 +240,23 @@ void G1MarkSweep::mark_sweep_phase3() { GCTraceTime tm("phase 3", G1Log::fine() && Verbose, true, gc_timer(), gc_tracer()->gc_id()); GenMarkSweep::trace("3"); - SharedHeap* sh = SharedHeap::heap(); - // Need cleared claim bits for the roots processing ClassLoaderDataGraph::clear_claimed_marks(); CodeBlobToOopClosure adjust_code_closure(&GenMarkSweep::adjust_pointer_closure, CodeBlobToOopClosure::FixRelocations); - sh->process_all_roots(true, // activate StrongRootsScope - SharedHeap::SO_AllCodeCache, - &GenMarkSweep::adjust_pointer_closure, - &GenMarkSweep::adjust_cld_closure, - &adjust_code_closure); + { + G1RootProcessor root_processor(g1h); + root_processor.process_all_roots(&GenMarkSweep::adjust_pointer_closure, + &GenMarkSweep::adjust_cld_closure, + &adjust_code_closure); + } assert(GenMarkSweep::ref_processor() == g1h->ref_processor_stw(), "Sanity"); g1h->ref_processor_stw()->weak_oops_do(&GenMarkSweep::adjust_pointer_closure); // Now adjust pointers in remaining weak roots. (All of which should // have been cleared if they pointed to non-surviving objects.) - sh->process_weak_roots(&GenMarkSweep::adjust_pointer_closure); + JNIHandles::weak_oops_do(&always_true, &GenMarkSweep::adjust_pointer_closure); if (G1StringDedup::is_enabled()) { G1StringDedup::oops_do(&GenMarkSweep::adjust_pointer_closure); diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp index e26daa7601d..fe28cc28c55 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp @@ -79,7 +79,6 @@ G1RemSet::G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs) _cards_scanned(NULL), _total_cards_scanned(0), _prev_period_summary() { - _seq_task = new SubTasksDone(NumSeqTasks); _cset_rs_update_cl = NEW_C_HEAP_ARRAY(G1ParPushHeapRSClosure*, n_workers(), mtGC); for (uint i = 0; i < n_workers(); i++) { _cset_rs_update_cl[i] = NULL; @@ -90,7 +89,6 @@ G1RemSet::G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs) } G1RemSet::~G1RemSet() { - delete _seq_task; for (uint i = 0; i < n_workers(); i++) { assert(_cset_rs_update_cl[i] == NULL, "it should be"); } diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.hpp index fb9d348789e..77eed43ac87 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.hpp @@ -58,7 +58,6 @@ protected: }; CardTableModRefBS* _ct_bs; - SubTasksDone* _seq_task; G1CollectorPolicy* _g1p; ConcurrentG1Refine* _cg1r; diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1RootProcessor.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1RootProcessor.cpp new file mode 100644 index 00000000000..37d9dd7cad6 --- /dev/null +++ b/hotspot/src/share/vm/gc_implementation/g1/g1RootProcessor.cpp @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + * + */ + +#include "precompiled.hpp" + +#include "classfile/stringTable.hpp" +#include "classfile/systemDictionary.hpp" +#include "code/codeCache.hpp" +#include "gc_implementation/g1/bufferingOopClosure.hpp" +#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" +#include "gc_implementation/g1/g1CollectorPolicy.hpp" +#include "gc_implementation/g1/g1GCPhaseTimes.hpp" +#include "gc_implementation/g1/g1RemSet.inline.hpp" +#include "gc_implementation/g1/g1RootProcessor.hpp" +#include "memory/allocation.inline.hpp" +#include "runtime/fprofiler.hpp" +#include "runtime/mutex.hpp" +#include "services/management.hpp" + +class G1CodeBlobClosure : public CodeBlobClosure { + class HeapRegionGatheringOopClosure : public OopClosure { + G1CollectedHeap* _g1h; + OopClosure* _work; + nmethod* _nm; + + template + void do_oop_work(T* p) { + _work->do_oop(p); + T oop_or_narrowoop = oopDesc::load_heap_oop(p); + if (!oopDesc::is_null(oop_or_narrowoop)) { + oop o = oopDesc::decode_heap_oop_not_null(oop_or_narrowoop); + HeapRegion* hr = _g1h->heap_region_containing_raw(o); + assert(!_g1h->obj_in_cs(o) || hr->rem_set()->strong_code_roots_list_contains(_nm), "if o still in CS then evacuation failed and nm must already be in the remset"); + hr->add_strong_code_root(_nm); + } + } + + public: + HeapRegionGatheringOopClosure(OopClosure* oc) : _g1h(G1CollectedHeap::heap()), _work(oc), _nm(NULL) {} + + void do_oop(oop* o) { + do_oop_work(o); + } + + void do_oop(narrowOop* o) { + do_oop_work(o); + } + + void set_nm(nmethod* nm) { + _nm = nm; + } + }; + + HeapRegionGatheringOopClosure _oc; +public: + G1CodeBlobClosure(OopClosure* oc) : _oc(oc) {} + + void do_code_blob(CodeBlob* cb) { + nmethod* nm = cb->as_nmethod_or_null(); + if (nm != NULL) { + if (!nm->test_set_oops_do_mark()) { + _oc.set_nm(nm); + nm->oops_do(&_oc); + nm->fix_oop_relocations(); + } + } + } +}; + + +void G1RootProcessor::worker_has_discovered_all_strong_classes() { + uint n_workers = _g1h->n_par_threads(); + assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading"); + + uint new_value = (uint)Atomic::add(1, &_n_workers_discovered_strong_classes); + if (new_value == n_workers) { + // This thread is last. Notify the others. + MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag); + _lock.notify_all(); + } +} + +void G1RootProcessor::wait_until_all_strong_classes_discovered() { + uint n_workers = _g1h->n_par_threads(); + assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading"); + + if ((uint)_n_workers_discovered_strong_classes != n_workers) { + MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag); + while ((uint)_n_workers_discovered_strong_classes != n_workers) { + _lock.wait(Mutex::_no_safepoint_check_flag, 0, false); + } + } +} + +G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h) : + _g1h(g1h), + _process_strong_tasks(new SubTasksDone(G1RP_PS_NumElements)), + _srs(g1h), + _lock(Mutex::leaf, "G1 Root Scanning barrier lock", false, Monitor::_safepoint_check_never), + _n_workers_discovered_strong_classes(0) {} + +void G1RootProcessor::evacuate_roots(OopClosure* scan_non_heap_roots, + OopClosure* scan_non_heap_weak_roots, + CLDClosure* scan_strong_clds, + CLDClosure* scan_weak_clds, + bool trace_metadata, + uint worker_i) { + // First scan the shared roots. + double ext_roots_start = os::elapsedTime(); + + BufferingOopClosure buf_scan_non_heap_roots(scan_non_heap_roots); + BufferingOopClosure buf_scan_non_heap_weak_roots(scan_non_heap_weak_roots); + + OopClosure* const weak_roots = &buf_scan_non_heap_weak_roots; + OopClosure* const strong_roots = &buf_scan_non_heap_roots; + + // CodeBlobClosures are not interoperable with BufferingOopClosures + G1CodeBlobClosure root_code_blobs(scan_non_heap_roots); + + process_java_roots(strong_roots, + trace_metadata ? scan_strong_clds : NULL, + scan_strong_clds, + trace_metadata ? NULL : scan_weak_clds, + &root_code_blobs); + + // This is the point where this worker thread will not find more strong CLDs/nmethods. + // Report this so G1 can synchronize the strong and weak CLDs/nmethods processing. + if (trace_metadata) { + worker_has_discovered_all_strong_classes(); + } + + process_vm_roots(strong_roots, weak_roots); + + // Now the CM ref_processor roots. + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_refProcessor_oops_do)) { + // We need to treat the discovered reference lists of the + // concurrent mark ref processor as roots and keep entries + // (which are added by the marking threads) on them live + // until they can be processed at the end of marking. + _g1h->ref_processor_cm()->weak_oops_do(&buf_scan_non_heap_roots); + } + + if (trace_metadata) { + // Barrier to make sure all workers passed + // the strong CLD and strong nmethods phases. + wait_until_all_strong_classes_discovered(); + + // Now take the complement of the strong CLDs. + ClassLoaderDataGraph::roots_cld_do(NULL, scan_weak_clds); + } + + // Finish up any enqueued closure apps (attributed as object copy time). + buf_scan_non_heap_roots.done(); + buf_scan_non_heap_weak_roots.done(); + + double obj_copy_time_sec = buf_scan_non_heap_roots.closure_app_seconds() + + buf_scan_non_heap_weak_roots.closure_app_seconds(); + + G1GCPhaseTimes* phase_times = _g1h->g1_policy()->phase_times(); + phase_times->record_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, obj_copy_time_sec); + + double ext_root_time_sec = os::elapsedTime() - ext_roots_start - obj_copy_time_sec; + + phase_times->record_time_secs(G1GCPhaseTimes::ExtRootScan, worker_i, ext_root_time_sec); + + // During conc marking we have to filter the per-thread SATB buffers + // to make sure we remove any oops into the CSet (which will show up + // as implicitly live). + { + G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::SATBFiltering, worker_i); + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_filter_satb_buffers) && _g1h->mark_in_progress()) { + JavaThread::satb_mark_queue_set().filter_thread_buffers(); + } + } + + _process_strong_tasks->all_tasks_completed(); +} + +void G1RootProcessor::process_strong_roots(OopClosure* oops, + CLDClosure* clds, + CodeBlobClosure* blobs) { + + process_java_roots(oops, clds, clds, NULL, blobs); + process_vm_roots(oops, NULL); + + _process_strong_tasks->all_tasks_completed(); +} + +void G1RootProcessor::process_all_roots(OopClosure* oops, + CLDClosure* clds, + CodeBlobClosure* blobs) { + + process_java_roots(oops, NULL, clds, clds, NULL); + process_vm_roots(oops, oops); + + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_CodeCache_oops_do)) { + CodeCache::blobs_do(blobs); + } + + _process_strong_tasks->all_tasks_completed(); +} + +void G1RootProcessor::process_java_roots(OopClosure* strong_roots, + CLDClosure* thread_stack_clds, + CLDClosure* strong_clds, + CLDClosure* weak_clds, + CodeBlobClosure* strong_code) { + assert(thread_stack_clds == NULL || weak_clds == NULL, "There is overlap between those, only one may be set"); + // Iterating over the CLDG and the Threads are done early to allow us to + // first process the strong CLDs and nmethods and then, after a barrier, + // let the thread process the weak CLDs and nmethods. + + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_ClassLoaderDataGraph_oops_do)) { + ClassLoaderDataGraph::roots_cld_do(strong_clds, weak_clds); + } + + Threads::possibly_parallel_oops_do(strong_roots, thread_stack_clds, strong_code); +} + +void G1RootProcessor::process_vm_roots(OopClosure* strong_roots, + OopClosure* weak_roots) { + + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_Universe_oops_do)) { + Universe::oops_do(strong_roots); + } + + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_JNIHandles_oops_do)) { + JNIHandles::oops_do(strong_roots); + } + + if (!_process_strong_tasks-> is_task_claimed(G1RP_PS_ObjectSynchronizer_oops_do)) { + ObjectSynchronizer::oops_do(strong_roots); + } + + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_FlatProfiler_oops_do)) { + FlatProfiler::oops_do(strong_roots); + } + + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_Management_oops_do)) { + Management::oops_do(strong_roots); + } + + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_jvmti_oops_do)) { + JvmtiExport::oops_do(strong_roots); + } + + if (!_process_strong_tasks->is_task_claimed(G1RP_PS_SystemDictionary_oops_do)) { + SystemDictionary::roots_oops_do(strong_roots, weak_roots); + } + + // All threads execute the following. A specific chunk of buckets + // from the StringTable are the individual tasks. + if (weak_roots != NULL) { + StringTable::possibly_parallel_oops_do(weak_roots); + } +} + +void G1RootProcessor::scan_remembered_sets(G1ParPushHeapRSClosure* scan_rs, + OopClosure* scan_non_heap_weak_roots, + uint worker_i) { + // Now scan the complement of the collection set. + G1CodeBlobClosure scavenge_cs_nmethods(scan_non_heap_weak_roots); + + _g1h->g1_rem_set()->oops_into_collection_set_do(scan_rs, &scavenge_cs_nmethods, worker_i); +} + +void G1RootProcessor::set_num_workers(int active_workers) { + _process_strong_tasks->set_n_threads(active_workers); +} diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1RootProcessor.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1RootProcessor.hpp new file mode 100644 index 00000000000..47c484b5294 --- /dev/null +++ b/hotspot/src/share/vm/gc_implementation/g1/g1RootProcessor.hpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + * + */ + +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_ROOTPROCESSOR_HPP +#define SHARE_VM_GC_IMPLEMENTATION_G1_ROOTPROCESSOR_HPP + +#include "memory/allocation.hpp" +#include "memory/sharedHeap.hpp" +#include "runtime/mutex.hpp" + +class CLDClosure; +class CodeBlobClosure; +class G1CollectedHeap; +class G1ParPushHeapRSClosure; +class Monitor; +class OopClosure; +class SubTasksDone; + +// Scoped object to assist in applying oop, CLD and code blob closures to +// root locations. Handles claiming of different root scanning tasks +// and takes care of global state for root scanning via a StrongRootsScope. +// In the parallel case there is a shared G1RootProcessor object where all +// worker thread call the process_roots methods. +class G1RootProcessor : public StackObj { + G1CollectedHeap* _g1h; + SubTasksDone* _process_strong_tasks; + SharedHeap::StrongRootsScope _srs; + + // Used to implement the Thread work barrier. + Monitor _lock; + volatile jint _n_workers_discovered_strong_classes; + + enum G1H_process_roots_tasks { + G1RP_PS_Universe_oops_do, + G1RP_PS_JNIHandles_oops_do, + G1RP_PS_ObjectSynchronizer_oops_do, + G1RP_PS_FlatProfiler_oops_do, + G1RP_PS_Management_oops_do, + G1RP_PS_SystemDictionary_oops_do, + G1RP_PS_ClassLoaderDataGraph_oops_do, + G1RP_PS_jvmti_oops_do, + G1RP_PS_CodeCache_oops_do, + G1RP_PS_filter_satb_buffers, + G1RP_PS_refProcessor_oops_do, + // Leave this one last. + G1RP_PS_NumElements + }; + + void worker_has_discovered_all_strong_classes(); + void wait_until_all_strong_classes_discovered(); + + void process_java_roots(OopClosure* scan_non_heap_roots, + CLDClosure* thread_stack_clds, + CLDClosure* scan_strong_clds, + CLDClosure* scan_weak_clds, + CodeBlobClosure* scan_strong_code); + + void process_vm_roots(OopClosure* scan_non_heap_roots, + OopClosure* scan_non_heap_weak_roots); + +public: + G1RootProcessor(G1CollectedHeap* g1h); + + // Apply closures to the strongly and weakly reachable roots in the system + // in a single pass. + // Record and report timing measurements for sub phases using the worker_i + void evacuate_roots(OopClosure* scan_non_heap_roots, + OopClosure* scan_non_heap_weak_roots, + CLDClosure* scan_strong_clds, + CLDClosure* scan_weak_clds, + bool trace_metadata, + uint worker_i); + + // Apply oops, clds and blobs to all strongly reachable roots in the system + void process_strong_roots(OopClosure* oops, + CLDClosure* clds, + CodeBlobClosure* blobs); + + // Apply oops, clds and blobs to strongly and weakly reachable roots in the system + void process_all_roots(OopClosure* oops, + CLDClosure* clds, + CodeBlobClosure* blobs); + + // Apply scan_rs to all locations in the union of the remembered sets for all + // regions in the collection set + // (having done "set_region" to indicate the region in which the root resides), + void scan_remembered_sets(G1ParPushHeapRSClosure* scan_rs, + OopClosure* scan_non_heap_weak_roots, + uint worker_i); + + // Inform the root processor about the number of worker threads + void set_num_workers(int active_workers); +}; + +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_ROOTPROCESSOR_HPP diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index 1712e4edc94..11465b12ef3 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -618,7 +618,7 @@ void ParNewGenTask::work(uint worker_id) { true, // Process younger gens, if any, // as strong roots. false, // no scope; this is parallel code - SharedHeap::SO_ScavengeCodeCache, + GenCollectedHeap::SO_ScavengeCodeCache, GenCollectedHeap::StrongAndWeakRoots, &par_scan_state.to_space_root_closure(), &par_scan_state.older_gen_closure(), diff --git a/hotspot/src/share/vm/memory/defNewGeneration.cpp b/hotspot/src/share/vm/memory/defNewGeneration.cpp index 1f3fbe687e8..0f5b2236555 100644 --- a/hotspot/src/share/vm/memory/defNewGeneration.cpp +++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp @@ -626,7 +626,7 @@ void DefNewGeneration::collect(bool full, true, // Process younger gens, if any, // as strong roots. true, // activate StrongRootsScope - SharedHeap::SO_ScavengeCodeCache, + GenCollectedHeap::SO_ScavengeCodeCache, GenCollectedHeap::StrongAndWeakRoots, &fsc_with_no_gc_barrier, &fsc_with_gc_barrier, diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.cpp b/hotspot/src/share/vm/memory/genCollectedHeap.cpp index 20d9afe5036..704291f0d94 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp @@ -26,6 +26,7 @@ #include "classfile/symbolTable.hpp" #include "classfile/systemDictionary.hpp" #include "classfile/vmSymbols.hpp" +#include "code/codeCache.hpp" #include "code/icBuffer.hpp" #include "gc_implementation/shared/collectorCounters.hpp" #include "gc_implementation/shared/gcTrace.hpp" @@ -47,6 +48,7 @@ #include "runtime/handles.inline.hpp" #include "runtime/java.hpp" #include "runtime/vmThread.hpp" +#include "services/management.hpp" #include "services/memoryService.hpp" #include "utilities/vmError.hpp" #include "utilities/workgroup.hpp" @@ -61,7 +63,15 @@ NOT_PRODUCT(size_t GenCollectedHeap::_skip_header_HeapWords = 0;) // The set of potentially parallel tasks in root scanning. enum GCH_strong_roots_tasks { - // We probably want to parallelize both of these internally, but for now... + GCH_PS_Universe_oops_do, + GCH_PS_JNIHandles_oops_do, + GCH_PS_ObjectSynchronizer_oops_do, + GCH_PS_FlatProfiler_oops_do, + GCH_PS_Management_oops_do, + GCH_PS_SystemDictionary_oops_do, + GCH_PS_ClassLoaderDataGraph_oops_do, + GCH_PS_jvmti_oops_do, + GCH_PS_CodeCache_oops_do, GCH_PS_younger_gens, // Leave this one last. GCH_PS_NumElements @@ -71,13 +81,9 @@ GenCollectedHeap::GenCollectedHeap(GenCollectorPolicy *policy) : SharedHeap(policy), _rem_set(NULL), _gen_policy(policy), - _gen_process_roots_tasks(new SubTasksDone(GCH_PS_NumElements)), + _process_strong_tasks(new SubTasksDone(GCH_PS_NumElements)), _full_collections_completed(0) { - if (_gen_process_roots_tasks == NULL || - !_gen_process_roots_tasks->valid()) { - vm_exit_during_initialization("Failed necessary allocation."); - } assert(policy != NULL, "Sanity check"); } @@ -569,29 +575,137 @@ HeapWord* GenCollectedHeap::satisfy_failed_allocation(size_t size, bool is_tlab) void GenCollectedHeap::set_par_threads(uint t) { SharedHeap::set_par_threads(t); - _gen_process_roots_tasks->set_n_threads(t); + set_n_termination(t); } -void GenCollectedHeap:: -gen_process_roots(int level, - bool younger_gens_as_roots, - bool activate_scope, - SharedHeap::ScanningOption so, - OopsInGenClosure* not_older_gens, - OopsInGenClosure* weak_roots, - OopsInGenClosure* older_gens, - CLDClosure* cld_closure, - CLDClosure* weak_cld_closure, - CodeBlobClosure* code_closure) { +void GenCollectedHeap::set_n_termination(uint t) { + _process_strong_tasks->set_n_threads(t); +} + +#ifdef ASSERT +class AssertNonScavengableClosure: public OopClosure { +public: + virtual void do_oop(oop* p) { + assert(!Universe::heap()->is_in_partial_collection(*p), + "Referent should not be scavengable."); } + virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } +}; +static AssertNonScavengableClosure assert_is_non_scavengable_closure; +#endif + +void GenCollectedHeap::process_roots(bool activate_scope, + ScanningOption so, + OopClosure* strong_roots, + OopClosure* weak_roots, + CLDClosure* strong_cld_closure, + CLDClosure* weak_cld_closure, + CodeBlobClosure* code_roots) { + StrongRootsScope srs(this, activate_scope); // General roots. - SharedHeap::process_roots(activate_scope, so, - not_older_gens, weak_roots, - cld_closure, weak_cld_closure, - code_closure); + assert(_strong_roots_parity != 0, "must have called prologue code"); + assert(code_roots != NULL, "code root closure should always be set"); + // _n_termination for _process_strong_tasks should be set up stream + // in a method not running in a GC worker. Otherwise the GC worker + // could be trying to change the termination condition while the task + // is executing in another GC worker. + + if (!_process_strong_tasks->is_task_claimed(GCH_PS_ClassLoaderDataGraph_oops_do)) { + ClassLoaderDataGraph::roots_cld_do(strong_cld_closure, weak_cld_closure); + } + + // Some CLDs contained in the thread frames should be considered strong. + // Don't process them if they will be processed during the ClassLoaderDataGraph phase. + CLDClosure* roots_from_clds_p = (strong_cld_closure != weak_cld_closure) ? strong_cld_closure : NULL; + // Only process code roots from thread stacks if we aren't visiting the entire CodeCache anyway + CodeBlobClosure* roots_from_code_p = (so & SO_AllCodeCache) ? NULL : code_roots; + + Threads::possibly_parallel_oops_do(strong_roots, roots_from_clds_p, roots_from_code_p); + + if (!_process_strong_tasks->is_task_claimed(GCH_PS_Universe_oops_do)) { + Universe::oops_do(strong_roots); + } + // Global (strong) JNI handles + if (!_process_strong_tasks->is_task_claimed(GCH_PS_JNIHandles_oops_do)) { + JNIHandles::oops_do(strong_roots); + } + + if (!_process_strong_tasks->is_task_claimed(GCH_PS_ObjectSynchronizer_oops_do)) { + ObjectSynchronizer::oops_do(strong_roots); + } + if (!_process_strong_tasks->is_task_claimed(GCH_PS_FlatProfiler_oops_do)) { + FlatProfiler::oops_do(strong_roots); + } + if (!_process_strong_tasks->is_task_claimed(GCH_PS_Management_oops_do)) { + Management::oops_do(strong_roots); + } + if (!_process_strong_tasks->is_task_claimed(GCH_PS_jvmti_oops_do)) { + JvmtiExport::oops_do(strong_roots); + } + + if (!_process_strong_tasks->is_task_claimed(GCH_PS_SystemDictionary_oops_do)) { + SystemDictionary::roots_oops_do(strong_roots, weak_roots); + } + + // All threads execute the following. A specific chunk of buckets + // from the StringTable are the individual tasks. + if (weak_roots != NULL) { + if (CollectedHeap::use_parallel_gc_threads()) { + StringTable::possibly_parallel_oops_do(weak_roots); + } else { + StringTable::oops_do(weak_roots); + } + } + + if (!_process_strong_tasks->is_task_claimed(GCH_PS_CodeCache_oops_do)) { + if (so & SO_ScavengeCodeCache) { + assert(code_roots != NULL, "must supply closure for code cache"); + + // We only visit parts of the CodeCache when scavenging. + CodeCache::scavenge_root_nmethods_do(code_roots); + } + if (so & SO_AllCodeCache) { + assert(code_roots != NULL, "must supply closure for code cache"); + + // CMSCollector uses this to do intermediate-strength collections. + // We scan the entire code cache, since CodeCache::do_unloading is not called. + CodeCache::blobs_do(code_roots); + } + // Verify that the code cache contents are not subject to + // movement by a scavenging collection. + DEBUG_ONLY(CodeBlobToOopClosure assert_code_is_non_scavengable(&assert_is_non_scavengable_closure, !CodeBlobToOopClosure::FixRelocations)); + DEBUG_ONLY(CodeCache::asserted_non_scavengable_nmethods_do(&assert_code_is_non_scavengable)); + } + +} + +void GenCollectedHeap::gen_process_roots(int level, + bool younger_gens_as_roots, + bool activate_scope, + ScanningOption so, + bool only_strong_roots, + OopsInGenClosure* not_older_gens, + OopsInGenClosure* older_gens, + CLDClosure* cld_closure) { + const bool is_adjust_phase = !only_strong_roots && !younger_gens_as_roots; + + bool is_moving_collection = false; + if (level == 0 || is_adjust_phase) { + // young collections are always moving + is_moving_collection = true; + } + + MarkingCodeBlobClosure mark_code_closure(not_older_gens, is_moving_collection); + OopsInGenClosure* weak_roots = only_strong_roots ? NULL : not_older_gens; + CLDClosure* weak_cld_closure = only_strong_roots ? NULL : cld_closure; + + process_roots(activate_scope, so, + not_older_gens, weak_roots, + cld_closure, weak_cld_closure, + &mark_code_closure); if (younger_gens_as_roots) { - if (!_gen_process_roots_tasks->is_task_claimed(GCH_PS_younger_gens)) { + if (!_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) { if (level == 1) { not_older_gens->set_generation(_young_gen); _young_gen->oop_iterate(not_older_gens); @@ -607,43 +721,18 @@ gen_process_roots(int level, older_gens->reset_generation(); } - _gen_process_roots_tasks->all_tasks_completed(); + _process_strong_tasks->all_tasks_completed(); } -void GenCollectedHeap:: -gen_process_roots(int level, - bool younger_gens_as_roots, - bool activate_scope, - SharedHeap::ScanningOption so, - bool only_strong_roots, - OopsInGenClosure* not_older_gens, - OopsInGenClosure* older_gens, - CLDClosure* cld_closure) { - const bool is_adjust_phase = !only_strong_roots && !younger_gens_as_roots; - - bool is_moving_collection = false; - if (level == 0 || is_adjust_phase) { - // young collections are always moving - is_moving_collection = true; - } - - MarkingCodeBlobClosure mark_code_closure(not_older_gens, is_moving_collection); - CodeBlobClosure* code_closure = &mark_code_closure; - - gen_process_roots(level, - younger_gens_as_roots, - activate_scope, so, - not_older_gens, only_strong_roots ? NULL : not_older_gens, - older_gens, - cld_closure, only_strong_roots ? NULL : cld_closure, - code_closure); - -} +class AlwaysTrueClosure: public BoolObjectClosure { +public: + bool do_object_b(oop p) { return true; } +}; +static AlwaysTrueClosure always_true; void GenCollectedHeap::gen_process_weak_roots(OopClosure* root_closure) { - SharedHeap::process_weak_roots(root_closure); - // "Local" "weak" refs + JNIHandles::weak_oops_do(&always_true, root_closure); _young_gen->ref_processor()->weak_oops_do(root_closure); _old_gen->ref_processor()->weak_oops_do(root_closure); } diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.hpp b/hotspot/src/share/vm/memory/genCollectedHeap.hpp index e9b3d744a32..d6193770905 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp @@ -85,8 +85,7 @@ public: // Data structure for claiming the (potentially) parallel tasks in // (gen-specific) roots processing. - SubTasksDone* _gen_process_roots_tasks; - SubTasksDone* gen_process_roots_tasks() { return _gen_process_roots_tasks; } + SubTasksDone* _process_strong_tasks; // Collects the given generation. void collect_generation(Generation* gen, bool full, size_t size, bool is_tlab, @@ -387,6 +386,7 @@ public: static GenCollectedHeap* heap(); void set_par_threads(uint t); + void set_n_termination(uint t); // Invoke the "do_oop" method of one of the closures "not_older_gens" // or "older_gens" on root locations for the generation at @@ -400,11 +400,25 @@ public: // The "so" argument determines which of the roots // the closure is applied to: // "SO_None" does none; + enum ScanningOption { + SO_None = 0x0, + SO_AllCodeCache = 0x8, + SO_ScavengeCodeCache = 0x10 + }; + private: + void process_roots(bool activate_scope, + ScanningOption so, + OopClosure* strong_roots, + OopClosure* weak_roots, + CLDClosure* strong_cld_closure, + CLDClosure* weak_cld_closure, + CodeBlobClosure* code_roots); + void gen_process_roots(int level, bool younger_gens_as_roots, bool activate_scope, - SharedHeap::ScanningOption so, + ScanningOption so, OopsInGenClosure* not_older_gens, OopsInGenClosure* weak_roots, OopsInGenClosure* older_gens, @@ -419,7 +433,7 @@ public: void gen_process_roots(int level, bool younger_gens_as_roots, bool activate_scope, - SharedHeap::ScanningOption so, + ScanningOption so, bool only_strong_roots, OopsInGenClosure* not_older_gens, OopsInGenClosure* older_gens, diff --git a/hotspot/src/share/vm/memory/genMarkSweep.cpp b/hotspot/src/share/vm/memory/genMarkSweep.cpp index 32a59301f79..eac303540f2 100644 --- a/hotspot/src/share/vm/memory/genMarkSweep.cpp +++ b/hotspot/src/share/vm/memory/genMarkSweep.cpp @@ -203,7 +203,7 @@ void GenMarkSweep::mark_sweep_phase1(int level, gch->gen_process_roots(level, false, // Younger gens are not roots. true, // activate StrongRootsScope - SharedHeap::SO_None, + GenCollectedHeap::SO_None, GenCollectedHeap::StrongRootsOnly, &follow_root_closure, &follow_root_closure, @@ -289,7 +289,7 @@ void GenMarkSweep::mark_sweep_phase3(int level) { gch->gen_process_roots(level, false, // Younger gens are not roots. true, // activate StrongRootsScope - SharedHeap::SO_AllCodeCache, + GenCollectedHeap::SO_AllCodeCache, GenCollectedHeap::StrongAndWeakRoots, &adjust_pointer_closure, &adjust_pointer_closure, diff --git a/hotspot/src/share/vm/memory/sharedHeap.cpp b/hotspot/src/share/vm/memory/sharedHeap.cpp index d6617af237e..27672c8168d 100644 --- a/hotspot/src/share/vm/memory/sharedHeap.cpp +++ b/hotspot/src/share/vm/memory/sharedHeap.cpp @@ -32,7 +32,6 @@ #include "runtime/atomic.inline.hpp" #include "runtime/fprofiler.hpp" #include "runtime/java.hpp" -#include "services/management.hpp" #include "utilities/copy.hpp" #include "utilities/workgroup.hpp" @@ -40,32 +39,12 @@ PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC SharedHeap* SharedHeap::_sh; -// The set of potentially parallel tasks in root scanning. -enum SH_process_roots_tasks { - SH_PS_Universe_oops_do, - SH_PS_JNIHandles_oops_do, - SH_PS_ObjectSynchronizer_oops_do, - SH_PS_FlatProfiler_oops_do, - SH_PS_Management_oops_do, - SH_PS_SystemDictionary_oops_do, - SH_PS_ClassLoaderDataGraph_oops_do, - SH_PS_jvmti_oops_do, - SH_PS_CodeCache_oops_do, - // Leave this one last. - SH_PS_NumElements -}; - SharedHeap::SharedHeap(CollectorPolicy* policy_) : CollectedHeap(), _collector_policy(policy_), - _strong_roots_scope(NULL), _strong_roots_parity(0), - _process_strong_tasks(new SubTasksDone(SH_PS_NumElements)), _workers(NULL) { - if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) { - vm_exit_during_initialization("Failed necessary allocation."); - } _sh = this; // ch is static, should be set only once. if (UseConcMarkSweepGC || UseG1GC) { _workers = new FlexibleWorkGang("GC Thread", ParallelGCThreads, @@ -79,14 +58,6 @@ SharedHeap::SharedHeap(CollectorPolicy* policy_) : } } -int SharedHeap::n_termination() { - return _process_strong_tasks->n_threads(); -} - -void SharedHeap::set_n_termination(int t) { - _process_strong_tasks->set_n_threads(t); -} - bool SharedHeap::heap_lock_held_for_gc() { Thread* t = Thread::current(); return Heap_lock->owned_by_self() @@ -97,31 +68,6 @@ bool SharedHeap::heap_lock_held_for_gc() { void SharedHeap::set_par_threads(uint t) { assert(t == 0 || !UseSerialGC, "Cannot have parallel threads"); _n_par_threads = t; - _process_strong_tasks->set_n_threads(t); -} - -#ifdef ASSERT -class AssertNonScavengableClosure: public OopClosure { -public: - virtual void do_oop(oop* p) { - assert(!Universe::heap()->is_in_partial_collection(*p), - "Referent should not be scavengable."); } - virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } -}; -static AssertNonScavengableClosure assert_is_non_scavengable_closure; -#endif - -SharedHeap::StrongRootsScope* SharedHeap::active_strong_roots_scope() const { - return _strong_roots_scope; -} -void SharedHeap::register_strong_roots_scope(SharedHeap::StrongRootsScope* scope) { - assert(_strong_roots_scope == NULL, "Should only have one StrongRootsScope active"); - assert(scope != NULL, "Illegal argument"); - _strong_roots_scope = scope; -} -void SharedHeap::unregister_strong_roots_scope(SharedHeap::StrongRootsScope* scope) { - assert(_strong_roots_scope == scope, "Wrong scope unregistered"); - _strong_roots_scope = NULL; } void SharedHeap::change_strong_roots_parity() { @@ -135,174 +81,15 @@ void SharedHeap::change_strong_roots_parity() { } SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* heap, bool activate) - : MarkScope(activate), _sh(heap), _n_workers_done_with_threads(0) + : MarkScope(activate), _sh(heap) { if (_active) { - _sh->register_strong_roots_scope(this); _sh->change_strong_roots_parity(); // Zero the claimed high water mark in the StringTable StringTable::clear_parallel_claimed_index(); } } -SharedHeap::StrongRootsScope::~StrongRootsScope() { - if (_active) { - _sh->unregister_strong_roots_scope(this); - } -} - -Monitor* SharedHeap::StrongRootsScope::_lock = new Monitor(Mutex::leaf, "StrongRootsScope lock", false, Monitor::_safepoint_check_never); - -void SharedHeap::StrongRootsScope::mark_worker_done_with_threads(uint n_workers) { - // The Thread work barrier is only needed by G1 Class Unloading. - // No need to use the barrier if this is single-threaded code. - if (UseG1GC && ClassUnloadingWithConcurrentMark && n_workers > 0) { - uint new_value = (uint)Atomic::add(1, &_n_workers_done_with_threads); - if (new_value == n_workers) { - // This thread is last. Notify the others. - MonitorLockerEx ml(_lock, Mutex::_no_safepoint_check_flag); - _lock->notify_all(); - } - } -} - -void SharedHeap::StrongRootsScope::wait_until_all_workers_done_with_threads(uint n_workers) { - assert(UseG1GC, "Currently only used by G1"); - assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading"); - - // No need to use the barrier if this is single-threaded code. - if (n_workers > 0 && (uint)_n_workers_done_with_threads != n_workers) { - MonitorLockerEx ml(_lock, Mutex::_no_safepoint_check_flag); - while ((uint)_n_workers_done_with_threads != n_workers) { - _lock->wait(Mutex::_no_safepoint_check_flag, 0, false); - } - } -} - -void SharedHeap::process_roots(bool activate_scope, - ScanningOption so, - OopClosure* strong_roots, - OopClosure* weak_roots, - CLDClosure* strong_cld_closure, - CLDClosure* weak_cld_closure, - CodeBlobClosure* code_roots) { - StrongRootsScope srs(this, activate_scope); - - // General roots. - assert(_strong_roots_parity != 0, "must have called prologue code"); - assert(code_roots != NULL, "code root closure should always be set"); - // _n_termination for _process_strong_tasks should be set up stream - // in a method not running in a GC worker. Otherwise the GC worker - // could be trying to change the termination condition while the task - // is executing in another GC worker. - - // Iterating over the CLDG and the Threads are done early to allow G1 to - // first process the strong CLDs and nmethods and then, after a barrier, - // let the thread process the weak CLDs and nmethods. - - if (!_process_strong_tasks->is_task_claimed(SH_PS_ClassLoaderDataGraph_oops_do)) { - ClassLoaderDataGraph::roots_cld_do(strong_cld_closure, weak_cld_closure); - } - - // Some CLDs contained in the thread frames should be considered strong. - // Don't process them if they will be processed during the ClassLoaderDataGraph phase. - CLDClosure* roots_from_clds_p = (strong_cld_closure != weak_cld_closure) ? strong_cld_closure : NULL; - // Only process code roots from thread stacks if we aren't visiting the entire CodeCache anyway - CodeBlobClosure* roots_from_code_p = (so & SO_AllCodeCache) ? NULL : code_roots; - - Threads::possibly_parallel_oops_do(strong_roots, roots_from_clds_p, roots_from_code_p); - - // This is the point where this worker thread will not find more strong CLDs/nmethods. - // Report this so G1 can synchronize the strong and weak CLDs/nmethods processing. - active_strong_roots_scope()->mark_worker_done_with_threads(n_par_threads()); - - if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) { - Universe::oops_do(strong_roots); - } - // Global (strong) JNI handles - if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do)) - JNIHandles::oops_do(strong_roots); - - if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do)) - ObjectSynchronizer::oops_do(strong_roots); - if (!_process_strong_tasks->is_task_claimed(SH_PS_FlatProfiler_oops_do)) - FlatProfiler::oops_do(strong_roots); - if (!_process_strong_tasks->is_task_claimed(SH_PS_Management_oops_do)) - Management::oops_do(strong_roots); - if (!_process_strong_tasks->is_task_claimed(SH_PS_jvmti_oops_do)) - JvmtiExport::oops_do(strong_roots); - - if (!_process_strong_tasks->is_task_claimed(SH_PS_SystemDictionary_oops_do)) { - SystemDictionary::roots_oops_do(strong_roots, weak_roots); - } - - // All threads execute the following. A specific chunk of buckets - // from the StringTable are the individual tasks. - if (weak_roots != NULL) { - if (CollectedHeap::use_parallel_gc_threads()) { - StringTable::possibly_parallel_oops_do(weak_roots); - } else { - StringTable::oops_do(weak_roots); - } - } - - if (!_process_strong_tasks->is_task_claimed(SH_PS_CodeCache_oops_do)) { - if (so & SO_ScavengeCodeCache) { - assert(code_roots != NULL, "must supply closure for code cache"); - - // We only visit parts of the CodeCache when scavenging. - CodeCache::scavenge_root_nmethods_do(code_roots); - } - if (so & SO_AllCodeCache) { - assert(code_roots != NULL, "must supply closure for code cache"); - - // CMSCollector uses this to do intermediate-strength collections. - // We scan the entire code cache, since CodeCache::do_unloading is not called. - CodeCache::blobs_do(code_roots); - } - // Verify that the code cache contents are not subject to - // movement by a scavenging collection. - DEBUG_ONLY(CodeBlobToOopClosure assert_code_is_non_scavengable(&assert_is_non_scavengable_closure, !CodeBlobToOopClosure::FixRelocations)); - DEBUG_ONLY(CodeCache::asserted_non_scavengable_nmethods_do(&assert_code_is_non_scavengable)); - } - - _process_strong_tasks->all_tasks_completed(); -} - -void SharedHeap::process_all_roots(bool activate_scope, - ScanningOption so, - OopClosure* roots, - CLDClosure* cld_closure, - CodeBlobClosure* code_closure) { - process_roots(activate_scope, so, - roots, roots, - cld_closure, cld_closure, - code_closure); -} - -void SharedHeap::process_strong_roots(bool activate_scope, - ScanningOption so, - OopClosure* roots, - CLDClosure* cld_closure, - CodeBlobClosure* code_closure) { - process_roots(activate_scope, so, - roots, NULL, - cld_closure, NULL, - code_closure); -} - - -class AlwaysTrueClosure: public BoolObjectClosure { -public: - bool do_object_b(oop p) { return true; } -}; -static AlwaysTrueClosure always_true; - -void SharedHeap::process_weak_roots(OopClosure* root_closure) { - // Global (weak) JNI handles - JNIHandles::weak_oops_do(&always_true, root_closure); -} - void SharedHeap::set_barrier_set(BarrierSet* bs) { _barrier_set = bs; // Cached barrier set for fast access in oops diff --git a/hotspot/src/share/vm/memory/sharedHeap.hpp b/hotspot/src/share/vm/memory/sharedHeap.hpp index 91735f1cdaa..80717520249 100644 --- a/hotspot/src/share/vm/memory/sharedHeap.hpp +++ b/hotspot/src/share/vm/memory/sharedHeap.hpp @@ -61,18 +61,18 @@ class KlassClosure; // counts the number of tasks that have been done and then reset // the SubTasksDone so that it can be used again. When the number of // tasks is set to the number of GC workers, then _n_threads must -// be set to the number of active GC workers. G1CollectedHeap, -// HRInto_G1RemSet, GenCollectedHeap and SharedHeap have SubTasksDone. -// This seems too many. +// be set to the number of active GC workers. G1RootProcessor and +// GenCollectedHeap have SubTasksDone. // 3) SequentialSubTasksDone has an _n_threads that is used in // a way similar to SubTasksDone and has the same dependency on the // number of active GC workers. CompactibleFreeListSpace and Space // have SequentialSubTasksDone's. -// Example of using SubTasksDone and SequentialSubTasksDone -// G1CollectedHeap::g1_process_roots() -// to SharedHeap::process_roots() and uses -// SubTasksDone* _process_strong_tasks to claim tasks. -// process_roots() calls +// +// Examples of using SubTasksDone and SequentialSubTasksDone: +// G1RootProcessor and GenCollectedHeap::process_roots() use +// SubTasksDone* _process_strong_tasks to claim tasks for workers +// +// GenCollectedHeap::gen_process_roots() calls // rem_set()->younger_refs_iterate() // to scan the card table and which eventually calls down into // CardTableModRefBS::par_non_clean_card_iterate_work(). This method @@ -104,10 +104,6 @@ class SharedHeap : public CollectedHeap { friend class VM_GC_Operation; friend class VM_CGC_Operation; -private: - // For claiming strong_roots tasks. - SubTasksDone* _process_strong_tasks; - protected: // There should be only a single instance of "SharedHeap" in a program. // This is enforced with the protected constructor below, which will also @@ -140,7 +136,6 @@ public: static SharedHeap* heap() { return _sh; } void set_barrier_set(BarrierSet* bs); - SubTasksDone* process_strong_tasks() { return _process_strong_tasks; } // Does operations required after initialization has been done. virtual void post_initialize(); @@ -193,69 +188,19 @@ public: // strong_roots_prologue calls change_strong_roots_parity, if // parallel tasks are enabled. class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope { - // Used to implement the Thread work barrier. - static Monitor* _lock; - SharedHeap* _sh; - volatile jint _n_workers_done_with_threads; public: StrongRootsScope(SharedHeap* heap, bool activate = true); - ~StrongRootsScope(); - - // Mark that this thread is done with the Threads work. - void mark_worker_done_with_threads(uint n_workers); - // Wait until all n_workers are done with the Threads work. - void wait_until_all_workers_done_with_threads(uint n_workers); }; friend class StrongRootsScope; - // The current active StrongRootScope - StrongRootsScope* _strong_roots_scope; - - StrongRootsScope* active_strong_roots_scope() const; - private: - void register_strong_roots_scope(StrongRootsScope* scope); - void unregister_strong_roots_scope(StrongRootsScope* scope); void change_strong_roots_parity(); public: - enum ScanningOption { - SO_None = 0x0, - SO_AllCodeCache = 0x8, - SO_ScavengeCodeCache = 0x10 - }; - FlexibleWorkGang* workers() const { return _workers; } - // Invoke the "do_oop" method the closure "roots" on all root locations. - // The "so" argument determines which roots the closure is applied to: - // "SO_None" does none; - // "SO_AllCodeCache" applies the closure to all elements of the CodeCache. - // "SO_ScavengeCodeCache" applies the closure to elements on the scavenge root list in the CodeCache. - void process_roots(bool activate_scope, - ScanningOption so, - OopClosure* strong_roots, - OopClosure* weak_roots, - CLDClosure* strong_cld_closure, - CLDClosure* weak_cld_closure, - CodeBlobClosure* code_roots); - void process_all_roots(bool activate_scope, - ScanningOption so, - OopClosure* roots, - CLDClosure* cld_closure, - CodeBlobClosure* code_roots); - void process_strong_roots(bool activate_scope, - ScanningOption so, - OopClosure* roots, - CLDClosure* cld_closure, - CodeBlobClosure* code_roots); - - - // Apply "root_closure" to the JNI weak roots.. - void process_weak_roots(OopClosure* root_closure); - // The functions below are helper functions that a subclass of // "SharedHeap" can use in the implementation of its virtual // functions. @@ -270,9 +215,6 @@ public: // (such as process roots) subsequently. virtual void set_par_threads(uint t); - int n_termination(); - void set_n_termination(int t); - // // New methods from CollectedHeap // @@ -284,8 +226,4 @@ public: size_t capacity); }; -inline SharedHeap::ScanningOption operator|(SharedHeap::ScanningOption so0, SharedHeap::ScanningOption so1) { - return static_cast(static_cast(so0) | static_cast(so1)); -} - #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP From 4f7ab1448ede16e73d54299b58a4f05a7661fa3a Mon Sep 17 00:00:00 2001 From: Karen Kinnear Date: Fri, 19 Dec 2014 11:48:50 -0800 Subject: [PATCH 033/362] 8065366: Better private method resolution Reviewed-by: hseigel, lfoltan, coleenp, ahgross --- .../src/share/vm/classfile/defaultMethods.cpp | 9 +++-- hotspot/src/share/vm/oops/klassVtable.cpp | 33 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/hotspot/src/share/vm/classfile/defaultMethods.cpp b/hotspot/src/share/vm/classfile/defaultMethods.cpp index 5cc8a6844ae..fdd2170faaa 100644 --- a/hotspot/src/share/vm/classfile/defaultMethods.cpp +++ b/hotspot/src/share/vm/classfile/defaultMethods.cpp @@ -731,10 +731,12 @@ class FindMethodsByErasedSig : public HierarchyVisitor { Method* m = iklass->find_method(_method_name, _method_signature); // private interface methods are not candidates for default methods // invokespecial to private interface methods doesn't use default method logic + // private class methods are not candidates for default methods, + // private methods do not override default methods, so need to perform + // default method inheritance without including private methods // The overpasses are your supertypes' errors, we do not include them // future: take access controls into account for superclass methods - if (m != NULL && !m->is_static() && !m->is_overpass() && - (!iklass->is_interface() || m->is_public())) { + if (m != NULL && !m->is_static() && !m->is_overpass() && !m->is_private()) { if (_family == NULL) { _family = new StatefulMethodFamily(); } @@ -745,6 +747,9 @@ class FindMethodsByErasedSig : public HierarchyVisitor { } else { // This is the rule that methods in classes "win" (bad word) over // methods in interfaces. This works because of single inheritance + // private methods in classes do not "win", they will be found + // first on searching, but overriding for invokevirtual needs + // to find default method candidates for the same signature _family->set_target_if_empty(m); } } diff --git a/hotspot/src/share/vm/oops/klassVtable.cpp b/hotspot/src/share/vm/oops/klassVtable.cpp index 5cfa70a73ae..3d9e0553429 100644 --- a/hotspot/src/share/vm/oops/klassVtable.cpp +++ b/hotspot/src/share/vm/oops/klassVtable.cpp @@ -404,13 +404,15 @@ bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle tar // get super_klass for method_holder for the found method InstanceKlass* super_klass = super_method->method_holder(); - if (is_default + // private methods are also never overridden + if (!super_method->is_private() && + (is_default || ((super_klass->is_override(super_method, target_loader, target_classname, THREAD)) || ((klass->major_version() >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) && ((super_klass = find_transitive_override(super_klass, target_method, i, target_loader, target_classname, THREAD)) - != (InstanceKlass*)NULL)))) + != (InstanceKlass*)NULL))))) { // Package private methods always need a new entry to root their own // overriding. They may also override other methods. @@ -692,9 +694,15 @@ bool klassVtable::is_miranda_entry_at(int i) { // check if a method is a miranda method, given a class's methods table, // its default_method table and its super // Miranda methods are calculated twice: -// first: before vtable size calculation: including abstract and default +// first: before vtable size calculation: including abstract and superinterface default +// We include potential default methods to give them space in the vtable. +// During the first run, the default_methods list is empty // This is seen by default method creation -// Second: recalculated during vtable initialization: only abstract +// Second: recalculated during vtable initialization: only include abstract methods. +// During the second run, default_methods is set up, so concrete methods from +// superinterfaces with matching names/signatures to default_methods are already +// in the default_methods list and do not need to be appended to the vtable +// as mirandas // This is seen by link resolution and selection. // "miranda" means not static, not defined by this class. // private methods in interfaces do not belong in the miranda list. @@ -709,8 +717,9 @@ bool klassVtable::is_miranda(Method* m, Array* class_methods, } Symbol* name = m->name(); Symbol* signature = m->signature(); + Method* mo; - if (InstanceKlass::find_instance_method(class_methods, name, signature) == NULL) { + if ((mo = InstanceKlass::find_instance_method(class_methods, name, signature)) == NULL) { // did not find it in the method table of the current class if ((default_methods == NULL) || InstanceKlass::find_method(default_methods, name, signature) == NULL) { @@ -719,7 +728,7 @@ bool klassVtable::is_miranda(Method* m, Array* class_methods, return true; } - Method* mo = InstanceKlass::cast(super)->lookup_method(name, signature); + mo = InstanceKlass::cast(super)->lookup_method(name, signature); while (mo != NULL && mo->access_flags().is_static() && mo->method_holder() != NULL && mo->method_holder()->super() != NULL) @@ -731,6 +740,18 @@ bool klassVtable::is_miranda(Method* m, Array* class_methods, return true; } } + } else { + // if the local class has a private method, the miranda will not + // override it, so a vtable slot is needed + if (mo->access_flags().is_private()) { + + // Second round, weed out any superinterface methods that turned + // into default methods, i.e. were concrete not abstract in the end + if ((default_methods == NULL) || + InstanceKlass::find_method(default_methods, name, signature) == NULL) { + return true; + } + } } return false; From 10a50a853f96778a3ea7ba748bd04135ad1bc28c Mon Sep 17 00:00:00 2001 From: Kim Barrett Date: Mon, 9 Feb 2015 13:30:30 -0500 Subject: [PATCH 034/362] 8071931: Return of the phantom menace Reviewed-by: mchung, dfuchs, ahgross, brutisso --- hotspot/src/share/vm/memory/referenceProcessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotspot/src/share/vm/memory/referenceProcessor.cpp b/hotspot/src/share/vm/memory/referenceProcessor.cpp index 8943a5e675f..6917b2e5f9c 100644 --- a/hotspot/src/share/vm/memory/referenceProcessor.cpp +++ b/hotspot/src/share/vm/memory/referenceProcessor.cpp @@ -250,7 +250,7 @@ ReferenceProcessorStats ReferenceProcessor::process_discovered_references( // Cleaner references to be temporary, and don't want to deal with // possible incompatibilities arising from making it more visible. phantom_count += - process_discovered_reflist(_discoveredCleanerRefs, NULL, false, + process_discovered_reflist(_discoveredCleanerRefs, NULL, true, is_alive, keep_alive, complete_gc, task_executor); } From a7edf52a02b019c20111dddc10d16f3e6b9d3203 Mon Sep 17 00:00:00 2001 From: Goetz Lindenmaier Date: Mon, 16 Feb 2015 14:07:36 +0100 Subject: [PATCH 035/362] 8073315: Enable gcc -Wtype-limits and fix upcoming issues Relevant fixes in blockOffsetTable.cpp, os_linux.cpp, parCardTableModRefBS.cpp. Reviewed-by: jwilhelm, kbarrett, simonis --- hotspot/make/linux/makefiles/gcc.make | 5 ++++ hotspot/src/os/linux/vm/os_linux.cpp | 24 ++++++++++--------- hotspot/src/share/vm/asm/codeBuffer.cpp | 5 +--- .../share/vm/classfile/systemDictionary.cpp | 2 -- .../gc_implementation/g1/concurrentMark.cpp | 3 ++- .../gc_implementation/g1/concurrentMark.hpp | 4 ++-- .../vm/gc_implementation/g1/g1CardCounts.hpp | 6 ++--- .../gc_implementation/g1/g1CollectedHeap.cpp | 2 +- .../vm/gc_implementation/g1/heapRegion.cpp | 5 ++-- .../g1/heapRegionManager.cpp | 4 ++-- .../gc_implementation/g1/heapRegionRemSet.cpp | 4 ++-- .../vm/gc_implementation/g1/heapRegionSet.cpp | 4 ++-- .../vm/gc_implementation/g1/ptrQueue.cpp | 7 +++--- .../parNew/parCardTableModRefBS.cpp | 10 ++++---- .../vm/gc_implementation/shared/gcUtil.hpp | 4 ++-- .../vm/gc_implementation/shared/liveRange.hpp | 3 +-- .../gc_implementation/shared/mutableSpace.cpp | 5 ++-- hotspot/src/share/vm/memory/allocation.cpp | 1 - .../src/share/vm/memory/blockOffsetTable.cpp | 5 ++-- hotspot/src/share/vm/memory/heap.cpp | 6 ++--- .../share/vm/memory/referenceProcessor.cpp | 6 ++--- hotspot/src/share/vm/opto/chaitin.cpp | 2 +- hotspot/src/share/vm/opto/graphKit.cpp | 7 +----- .../share/vm/prims/jvmtiRedefineClasses.cpp | 9 ++----- hotspot/src/share/vm/runtime/virtualspace.cpp | 13 +++++----- hotspot/src/share/vm/utilities/bitMap.cpp | 4 +--- hotspot/src/share/vm/utilities/workgroup.cpp | 4 ++-- .../share/vm/utilities/yieldingWorkgroup.cpp | 3 +-- 28 files changed, 71 insertions(+), 86 deletions(-) diff --git a/hotspot/make/linux/makefiles/gcc.make b/hotspot/make/linux/makefiles/gcc.make index d9007afe655..c1d59e990a0 100644 --- a/hotspot/make/linux/makefiles/gcc.make +++ b/hotspot/make/linux/makefiles/gcc.make @@ -214,6 +214,11 @@ ifeq ($(USE_CLANG),) # conversions which might affect the values. Only enable it in earlier versions. ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" WARNING_FLAGS += -Wconversion + endif + ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 8 \) \))" "1" + # This flag is only known since GCC 4.3. Gcc 4.8 contains a fix so that with templates no + # warnings are issued: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856 + WARNING_FLAGS += -Wtype-limits endif endif diff --git a/hotspot/src/os/linux/vm/os_linux.cpp b/hotspot/src/os/linux/vm/os_linux.cpp index a2a807aa003..c3403d49e4d 100644 --- a/hotspot/src/os/linux/vm/os_linux.cpp +++ b/hotspot/src/os/linux/vm/os_linux.cpp @@ -3732,14 +3732,14 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { // Does this overlap the block we wanted? Give back the overlapped // parts and try again. - size_t top_overlap = requested_addr + (bytes + gap) - base[i]; - if (top_overlap >= 0 && top_overlap < bytes) { + ptrdiff_t top_overlap = requested_addr + (bytes + gap) - base[i]; + if (top_overlap >= 0 && (size_t)top_overlap < bytes) { unmap_memory(base[i], top_overlap); base[i] += top_overlap; size[i] = bytes - top_overlap; } else { - size_t bottom_overlap = base[i] + bytes - requested_addr; - if (bottom_overlap >= 0 && bottom_overlap < bytes) { + ptrdiff_t bottom_overlap = base[i] + bytes - requested_addr; + if (bottom_overlap >= 0 && (size_t)bottom_overlap < bytes) { unmap_memory(requested_addr, bottom_overlap); size[i] = bytes - bottom_overlap; } else { @@ -6003,11 +6003,11 @@ int os::get_core_path(char* buffer, size_t bufferSize) { } if (strlen(core_pattern) == 0) { - return 0; + return -1; } char *pid_pos = strstr(core_pattern, "%p"); - size_t written; + int written; if (core_pattern[0] == '/') { written = jio_snprintf(buffer, bufferSize, core_pattern); @@ -6016,8 +6016,7 @@ int os::get_core_path(char* buffer, size_t bufferSize) { const char* p = get_current_directory(cwd, PATH_MAX); if (p == NULL) { - assert(p != NULL, "failed to get current directory"); - return 0; + return -1; } if (core_pattern[0] == '|') { @@ -6029,8 +6028,11 @@ int os::get_core_path(char* buffer, size_t bufferSize) { } } - if ((written >= 0) && (written < bufferSize) - && (pid_pos == NULL) && (core_pattern[0] != '|')) { + if (written < 0) { + return -1; + } + + if (((size_t)written < bufferSize) && (pid_pos == NULL) && (core_pattern[0] != '|')) { int core_uses_pid_file = ::open("/proc/sys/kernel/core_uses_pid", O_RDONLY); if (core_uses_pid_file != -1) { @@ -6038,7 +6040,7 @@ int os::get_core_path(char* buffer, size_t bufferSize) { ssize_t ret = ::read(core_uses_pid_file, &core_uses_pid, 1); ::close(core_uses_pid_file); - if (core_uses_pid == '1'){ + if (core_uses_pid == '1') { jio_snprintf(buffer + written, bufferSize - written, ".%d", current_process_id()); } diff --git a/hotspot/src/share/vm/asm/codeBuffer.cpp b/hotspot/src/share/vm/asm/codeBuffer.cpp index 4567735fbd6..974a48156f8 100644 --- a/hotspot/src/share/vm/asm/codeBuffer.cpp +++ b/hotspot/src/share/vm/asm/codeBuffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -926,9 +926,6 @@ void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) { void CodeBuffer::take_over_code_from(CodeBuffer* cb) { // Must already have disposed of the old blob somehow. assert(blob() == NULL, "must be empty"); -#ifdef ASSERT - -#endif // Take the new blob away from cb. set_blob(cb->blob()); // Take over all the section pointers. diff --git a/hotspot/src/share/vm/classfile/systemDictionary.cpp b/hotspot/src/share/vm/classfile/systemDictionary.cpp index 72da0bb7089..8c76d2a47f5 100644 --- a/hotspot/src/share/vm/classfile/systemDictionary.cpp +++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp @@ -1368,8 +1368,6 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { ClassLoaderData* loader_data = k->class_loader_data(); Handle class_loader_h(THREAD, loader_data->class_loader()); - for (uintx it = 0; it < GCExpandToAllocateDelayMillis; it++){} - // for bootstrap and other parallel classloaders don't acquire lock, // use placeholder token // If a parallelCapable class loader calls define_instance_class instead of diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp index 6d7197c060a..650967e48de 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp @@ -2170,12 +2170,13 @@ void ConcurrentMark::completeCleanup() { g1h->secondary_free_list_add(&tmp_free_list); SecondaryFreeList_lock->notify_all(); } - +#ifndef PRODUCT if (G1StressConcRegionFreeing) { for (uintx i = 0; i < G1StressConcRegionFreeingDelayMillis; ++i) { os::sleep(Thread::current(), (jlong) 1, false); } } +#endif } } assert(tmp_free_list.is_empty(), "post-condition"); diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp index 03b98366f36..c8783171096 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp @@ -853,7 +853,7 @@ public: // Returns the card bitmap for a given task or worker id. BitMap* count_card_bitmap_for(uint worker_id) { - assert(0 <= worker_id && worker_id < _max_worker_id, "oob"); + assert(worker_id < _max_worker_id, "oob"); assert(_count_card_bitmaps != NULL, "uninitialized"); BitMap* task_card_bm = &_count_card_bitmaps[worker_id]; assert(task_card_bm->size() == _card_bm.size(), "size mismatch"); @@ -863,7 +863,7 @@ public: // Returns the array containing the marked bytes for each region, // for the given worker or task id. size_t* count_marked_bytes_array_for(uint worker_id) { - assert(0 <= worker_id && worker_id < _max_worker_id, "oob"); + assert(worker_id < _max_worker_id, "oob"); assert(_count_marked_bytes != NULL, "uninitialized"); size_t* marked_bytes_array = _count_marked_bytes[worker_id]; assert(marked_bytes_array != NULL, "uninitialized"); diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp index 7dcad458b9d..6922818a790 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -84,13 +84,13 @@ class G1CardCounts: public CHeapObj { "_ct_bot: " PTR_FORMAT, p2i(card_ptr), p2i(_ct_bot))); size_t card_num = pointer_delta(card_ptr, _ct_bot, sizeof(jbyte)); - assert(card_num >= 0 && card_num < _reserved_max_card_num, + assert(card_num < _reserved_max_card_num, err_msg("card pointer out of range: " PTR_FORMAT, p2i(card_ptr))); return card_num; } jbyte* card_num_2_ptr(size_t card_num) { - assert(card_num >= 0 && card_num < _reserved_max_card_num, + assert(card_num < _reserved_max_card_num, err_msg("card num out of range: "SIZE_FORMAT, card_num)); return (jbyte*) (_ct_bot + card_num); } diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index 18deaa19b1b..70ad26e7f09 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -5425,7 +5425,7 @@ public: // limit is set using max_num_q() - which was set using ParallelGCThreads. // So this must be true - but assert just in case someone decides to // change the worker ids. - assert(0 <= worker_id && worker_id < limit, "sanity"); + assert(worker_id < limit, "sanity"); assert(!rp->discovery_is_atomic(), "check this code"); // Select discovered lists [i, i+stride, i+2*stride,...,limit) diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp index 2eb23388ef5..77d8397ba91 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp @@ -324,9 +324,8 @@ void HeapRegion::note_self_forwarding_removal_start(bool during_initial_mark, void HeapRegion::note_self_forwarding_removal_end(bool during_initial_mark, bool during_conc_mark, size_t marked_bytes) { - assert(0 <= marked_bytes && marked_bytes <= used(), - err_msg("marked: "SIZE_FORMAT" used: "SIZE_FORMAT, - marked_bytes, used())); + assert(marked_bytes <= used(), + err_msg("marked: "SIZE_FORMAT" used: "SIZE_FORMAT, marked_bytes, used())); _prev_top_at_mark_start = top(); _prev_marked_bytes = marked_bytes; } diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.cpp index a1156d8913e..38a41dc27d7 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -270,7 +270,7 @@ void HeapRegionManager::par_iterate(HeapRegionClosure* blk, uint worker_id, Heap const uint n_regions = hrclaimer->n_regions(); for (uint count = 0; count < n_regions; count++) { const uint index = (start_index + count) % n_regions; - assert(0 <= index && index < n_regions, "sanity"); + assert(index < n_regions, "sanity"); // Skip over unavailable regions if (!is_available(index)) { continue; diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp index f092f3ec9c2..835b8e2edd8 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -541,7 +541,7 @@ void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, uint tid) { PerRegionTable* OtherRegionsTable::find_region_table(size_t ind, HeapRegion* hr) const { - assert(0 <= ind && ind < _max_fine_entries, "Preconditions."); + assert(ind < _max_fine_entries, "Preconditions."); PerRegionTable* prt = _fine_grain_regions[ind]; while (prt != NULL && prt->hr() != hr) { prt = prt->collision_list_next(); diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp index b1724dcdcd3..37a85aa0def 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -57,7 +57,7 @@ void HeapRegionSetBase::verify() { check_mt_safety(); guarantee(( is_empty() && length() == 0 && total_capacity_bytes() == 0) || - (!is_empty() && length() >= 0 && total_capacity_bytes() >= 0), + (!is_empty() && length() > 0 && total_capacity_bytes() > 0) , hrs_ext_msg(this, "invariant")); } diff --git a/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp b/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp index f7202ab2c2a..aae06af1622 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -58,7 +58,7 @@ void PtrQueue::flush_impl() { void PtrQueue::enqueue_known_active(void* ptr) { - assert(0 <= _index && _index <= _sz, "Invariant."); + assert(_index <= _sz, "Invariant."); assert(_index == 0 || _buf != NULL, "invariant"); while (_index == 0) { @@ -68,7 +68,7 @@ void PtrQueue::enqueue_known_active(void* ptr) { assert(_index > 0, "postcondition"); _index -= oopSize; _buf[byte_index_to_index((int)_index)] = ptr; - assert(0 <= _index && _index <= _sz, "Invariant."); + assert(_index <= _sz, "Invariant."); } void PtrQueue::locking_enqueue_completed_buffer(void** buf) { @@ -194,7 +194,6 @@ void PtrQueue::handle_zero_index() { _buf = qset()->allocate_buffer(); _sz = qset()->buffer_size(); _index = _sz; - assert(0 <= _index && _index <= _sz, "Invariant."); } bool PtrQueueSet::process_or_enqueue_complete_buffer(void** buf) { diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp index c0674f38f35..efe7e399209 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2015, 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 @@ -195,8 +195,9 @@ process_chunk_boundaries(Space* sp, // our closures depend on this property and do not protect against // double scans. - uintptr_t cur_chunk_index = addr_to_chunk_index(chunk_mr.start()); - cur_chunk_index = cur_chunk_index - lowest_non_clean_base_chunk_index; + uintptr_t start_chunk_index = addr_to_chunk_index(chunk_mr.start()); + assert(start_chunk_index >= lowest_non_clean_base_chunk_index, "Bounds error."); + uintptr_t cur_chunk_index = start_chunk_index - lowest_non_clean_base_chunk_index; NOISY(tty->print_cr("===========================================================================");) NOISY(tty->print_cr(" process_chunk_boundary: Called with [" PTR_FORMAT "," PTR_FORMAT ")", @@ -242,8 +243,7 @@ process_chunk_boundaries(Space* sp, if (first_dirty_card != NULL) { NOISY(tty->print_cr(" LNC: Found a dirty card at " PTR_FORMAT " in current chunk", first_dirty_card);) - assert(0 <= cur_chunk_index && cur_chunk_index < lowest_non_clean_chunk_size, - "Bounds error."); + assert(cur_chunk_index < lowest_non_clean_chunk_size, "Bounds error."); assert(lowest_non_clean[cur_chunk_index] == NULL, "Write exactly once : value should be stable hereafter for this round"); lowest_non_clean[cur_chunk_index] = first_dirty_card; diff --git a/hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp b/hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp index f1292ebcd7d..07cdff63d2f 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp +++ b/hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -103,7 +103,7 @@ class AdaptiveWeightedAverage : public CHeapObj { static inline float exp_avg(float avg, float sample, unsigned int weight) { - assert(0 <= weight && weight <= 100, "weight must be a percent"); + assert(weight <= 100, "weight must be a percent"); return (100.0F - weight) * avg / 100.0F + weight * sample / 100.0F; } static inline size_t exp_avg(size_t avg, size_t sample, diff --git a/hotspot/src/share/vm/gc_implementation/shared/liveRange.hpp b/hotspot/src/share/vm/gc_implementation/shared/liveRange.hpp index 1cf300a620a..7894183ac28 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/liveRange.hpp +++ b/hotspot/src/share/vm/gc_implementation/shared/liveRange.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -42,7 +42,6 @@ public: MemRegion::set_end(e); } void set_word_size(size_t ws) { - assert(ws >= 0, "should be a non-zero range"); MemRegion::set_word_size(ws); } diff --git a/hotspot/src/share/vm/gc_implementation/shared/mutableSpace.cpp b/hotspot/src/share/vm/gc_implementation/shared/mutableSpace.cpp index a87a2494a0b..e2e4a6b8e04 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/mutableSpace.cpp +++ b/hotspot/src/share/vm/gc_implementation/shared/mutableSpace.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -36,8 +36,7 @@ PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC MutableSpace::MutableSpace(size_t alignment): ImmutableSpace(), _top(NULL), _alignment(alignment) { - assert(MutableSpace::alignment() >= 0 && - MutableSpace::alignment() % os::vm_page_size() == 0, + assert(MutableSpace::alignment() % os::vm_page_size() == 0, "Space should be aligned"); _mangler = new MutableSpaceMangler(this); } diff --git a/hotspot/src/share/vm/memory/allocation.cpp b/hotspot/src/share/vm/memory/allocation.cpp index 4e2056861f6..56734768eed 100644 --- a/hotspot/src/share/vm/memory/allocation.cpp +++ b/hotspot/src/share/vm/memory/allocation.cpp @@ -562,7 +562,6 @@ void* Arena::grow(size_t x, AllocFailType alloc_failmode) { // Reallocate storage in Arena. void *Arena::Arealloc(void* old_ptr, size_t old_size, size_t new_size, AllocFailType alloc_failmode) { - assert(new_size >= 0, "bad size"); if (new_size == 0) return NULL; #ifdef ASSERT if (UseMallocOnly) { diff --git a/hotspot/src/share/vm/memory/blockOffsetTable.cpp b/hotspot/src/share/vm/memory/blockOffsetTable.cpp index d64aff67dd7..b02d4d12c00 100644 --- a/hotspot/src/share/vm/memory/blockOffsetTable.cpp +++ b/hotspot/src/share/vm/memory/blockOffsetTable.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, 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 @@ -792,6 +792,5 @@ void BlockOffsetArrayContigSpace::zero_bottom_entry() { } size_t BlockOffsetArrayContigSpace::last_active_index() const { - size_t result = _next_offset_index - 1; - return result >= 0 ? result : 0; + return _next_offset_index == 0 ? 0 : _next_offset_index - 1; } diff --git a/hotspot/src/share/vm/memory/heap.cpp b/hotspot/src/share/vm/memory/heap.cpp index 67cc03378a3..2c4a661e359 100644 --- a/hotspot/src/share/vm/memory/heap.cpp +++ b/hotspot/src/share/vm/memory/heap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -52,7 +52,7 @@ CodeHeap::CodeHeap(const char* name, const int code_blob_type) void CodeHeap::mark_segmap_as_free(size_t beg, size_t end) { - assert(0 <= beg && beg < _number_of_committed_segments, "interval begin out of bounds"); + assert( beg < _number_of_committed_segments, "interval begin out of bounds"); assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds"); // setup _segmap pointers for faster indexing address p = (address)_segmap.low() + beg; @@ -63,7 +63,7 @@ void CodeHeap::mark_segmap_as_free(size_t beg, size_t end) { void CodeHeap::mark_segmap_as_used(size_t beg, size_t end) { - assert(0 <= beg && beg < _number_of_committed_segments, "interval begin out of bounds"); + assert( beg < _number_of_committed_segments, "interval begin out of bounds"); assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds"); // setup _segmap pointers for faster indexing address p = (address)_segmap.low() + beg; diff --git a/hotspot/src/share/vm/memory/referenceProcessor.cpp b/hotspot/src/share/vm/memory/referenceProcessor.cpp index 9fe08b5d3be..1a011ce1e91 100644 --- a/hotspot/src/share/vm/memory/referenceProcessor.cpp +++ b/hotspot/src/share/vm/memory/referenceProcessor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -987,7 +987,7 @@ inline DiscoveredList* ReferenceProcessor::get_discovered_list(ReferenceType rt) id = next_id(); } } - assert(0 <= id && id < _max_num_q, "Id is out-of-bounds (call Freud?)"); + assert(id < _max_num_q, "Id is out-of-bounds (call Freud?)"); // Get the discovered queue to which we will add DiscoveredList* list = NULL; @@ -1345,7 +1345,7 @@ ReferenceProcessor::preclean_discovered_reflist(DiscoveredList& refs_list, } const char* ReferenceProcessor::list_name(uint i) { - assert(i >= 0 && i <= _max_num_q * number_of_subclasses_of_ref(), + assert(i <= _max_num_q * number_of_subclasses_of_ref(), "Out of bounds index"); int j = i / _max_num_q; diff --git a/hotspot/src/share/vm/opto/chaitin.cpp b/hotspot/src/share/vm/opto/chaitin.cpp index 7b1290dd36a..d60790276fa 100644 --- a/hotspot/src/share/vm/opto/chaitin.cpp +++ b/hotspot/src/share/vm/opto/chaitin.cpp @@ -602,7 +602,7 @@ void PhaseChaitin::Register_Allocate() { // This frame must preserve the required fp alignment _framesize = round_to(_framesize, Matcher::stack_alignment_in_slots()); - assert( _framesize >= 0 && _framesize <= 1000000, "sanity check" ); + assert(_framesize <= 1000000, "sanity check"); #ifndef PRODUCT _total_framesize += _framesize; if ((int)_framesize > _max_framesize) { diff --git a/hotspot/src/share/vm/opto/graphKit.cpp b/hotspot/src/share/vm/opto/graphKit.cpp index 5a90b50f71b..ad7ffefd275 100644 --- a/hotspot/src/share/vm/opto/graphKit.cpp +++ b/hotspot/src/share/vm/opto/graphKit.cpp @@ -3027,12 +3027,7 @@ Node* GraphKit::gen_checkcast(Node *obj, Node* superklass, // We may not have profiling here or it may not help us. If we have // a speculative type use it to perform an exact cast. ciKlass* spec_obj_type = obj_type->speculative_type(); - if (spec_obj_type != NULL || - (data != NULL && - // Counter has never been decremented (due to cast failure). - // ...This is a reasonable thing to expect. It is true of - // all casts inserted by javac to implement generic types. - data->as_CounterData()->count() >= 0)) { + if (spec_obj_type != NULL || data != NULL) { cast_obj = maybe_cast_profiled_receiver(not_null_obj, tk->klass(), spec_obj_type, safe_for_replace); if (cast_obj != NULL) { if (failure_control != NULL) // failure is now impossible diff --git a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp index b5e5f64806f..48bbcb6dd21 100644 --- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp +++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp @@ -2902,18 +2902,13 @@ void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table( // } assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type"); - // The Linux compiler does not like frame_type to be u1 or u2. It - // issues the following warning for the first if-statement below: - // - // "warning: comparison is always true due to limited range of data type" - // - u4 frame_type = *stackmap_p; + u1 frame_type = *stackmap_p; stackmap_p++; // same_frame { // u1 frame_type = SAME; /* 0-63 */ // } - if (frame_type >= 0 && frame_type <= 63) { + if (frame_type <= 63) { // nothing more to do for same_frame } diff --git a/hotspot/src/share/vm/runtime/virtualspace.cpp b/hotspot/src/share/vm/runtime/virtualspace.cpp index fe3219f1a8b..d8d09df2715 100644 --- a/hotspot/src/share/vm/runtime/virtualspace.cpp +++ b/hotspot/src/share/vm/runtime/virtualspace.cpp @@ -519,12 +519,13 @@ void ReservedHeapSpace::initialize_compressed_heap(const size_t size, size_t ali // Calc address range within we try to attach (range of possible start addresses). char *const highest_start = (char *)align_ptr_down(zerobased_max - size, attach_point_alignment); - // SS10 and SS12u1 cannot compile "(char *)UnscaledOopHeapMax - size" on solaris sparc 32-bit: - // "Cannot use int to initialize char*." Introduce aux variable. - char *unscaled_end = (char *)UnscaledOopHeapMax; - unscaled_end -= size; - char *lowest_start = (size < UnscaledOopHeapMax) ? - MAX2(unscaled_end, aligned_heap_base_min_address) : aligned_heap_base_min_address; + // Need to be careful about size being guaranteed to be less + // than UnscaledOopHeapMax due to type constraints. + char *lowest_start = aligned_heap_base_min_address; + uint64_t unscaled_end = UnscaledOopHeapMax - size; + if (unscaled_end < UnscaledOopHeapMax) { // unscaled_end wrapped if size is large + lowest_start = MAX2(lowest_start, (char*)unscaled_end); + } lowest_start = (char *)align_ptr_up(lowest_start, attach_point_alignment); try_reserve_range(highest_start, lowest_start, attach_point_alignment, aligned_heap_base_min_address, zerobased_max, size, alignment, large); diff --git a/hotspot/src/share/vm/utilities/bitMap.cpp b/hotspot/src/share/vm/utilities/bitMap.cpp index 3ebd7391e88..9ffc0bc100e 100644 --- a/hotspot/src/share/vm/utilities/bitMap.cpp +++ b/hotspot/src/share/vm/utilities/bitMap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -33,7 +33,6 @@ BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) : _map(map), _size(size_in_bits), _map_allocator(false) { assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption."); - assert(size_in_bits >= 0, "just checking"); } @@ -45,7 +44,6 @@ BitMap::BitMap(idx_t size_in_bits, bool in_resource_area) : } void BitMap::resize(idx_t size_in_bits, bool in_resource_area) { - assert(size_in_bits >= 0, "just checking"); idx_t old_size_in_words = size_in_words(); bm_word_t* old_map = map(); diff --git a/hotspot/src/share/vm/utilities/workgroup.cpp b/hotspot/src/share/vm/utilities/workgroup.cpp index dc260422adf..280d0bc947d 100644 --- a/hotspot/src/share/vm/utilities/workgroup.cpp +++ b/hotspot/src/share/vm/utilities/workgroup.cpp @@ -124,7 +124,7 @@ GangWorker* AbstractWorkGang::gang_worker(uint i) const { // Array index bounds checking. GangWorker* result = NULL; assert(gang_workers() != NULL, "No workers for indexing"); - assert(((i >= 0) && (i < total_workers())), "Worker index out of bounds"); + assert(i < total_workers(), "Worker index out of bounds"); result = _gang_workers[i]; assert(result != NULL, "Indexing to null worker"); return result; @@ -463,7 +463,7 @@ void SubTasksDone::clear() { } bool SubTasksDone::is_task_claimed(uint t) { - assert(0 <= t && t < _n_tasks, "bad task id."); + assert(t < _n_tasks, "bad task id."); uint old = _tasks[t]; if (old == 0) { old = Atomic::cmpxchg(1, &_tasks[t], 0); diff --git a/hotspot/src/share/vm/utilities/yieldingWorkgroup.cpp b/hotspot/src/share/vm/utilities/yieldingWorkgroup.cpp index fdbb0befbfc..1ea33e643d0 100644 --- a/hotspot/src/share/vm/utilities/yieldingWorkgroup.cpp +++ b/hotspot/src/share/vm/utilities/yieldingWorkgroup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -120,7 +120,6 @@ void YieldingFlexibleWorkGang::start_task(YieldingFlexibleGangTask* new_task) { _sequence_number++; uint requested_size = new_task->requested_size(); - assert(requested_size >= 0, "Should be non-negative"); if (requested_size != 0) { _active_workers = MIN2(requested_size, total_workers()); } else { From af874b5889ad633f93b04d6b5e9eb2dbbb654831 Mon Sep 17 00:00:00 2001 From: Peter Brunet Date: Fri, 27 Mar 2015 15:48:08 -0500 Subject: [PATCH 036/362] 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831 Move files from open to closed Reviewed-by: prr, mchung, erikj, ihse, serb, bpatel --- make/Images.gmk | 6 +++- make/Javadoc.gmk | 56 ++++++++++++++++++++++++++++++++++- make/Main.gmk | 3 ++ make/common/NON_CORE_PKGS.gmk | 7 +++-- modules.xml | 9 ++++-- 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/make/Images.gmk b/make/Images.gmk index 3a8171416c7..c454b0e5a8a 100644 --- a/make/Images.gmk +++ b/make/Images.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2014, 2015 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 @@ -57,6 +57,10 @@ ifeq ($(OPENJDK_TARGET_OS), solaris) PROVIDER_MODULES += jdk.crypto.ucrypto endif +ifeq ($(OPENJDK_TARGET_OS), windows) + MAIN_MODULES += jdk.accessibility +endif + ifeq ($(OPENJDK_TARGET_OS), macosx) MAIN_MODULES += jdk.deploy.osx endif diff --git a/make/Javadoc.gmk b/make/Javadoc.gmk index 2a7a59ea83e..4569ed84272 100644 --- a/make/Javadoc.gmk +++ b/make/Javadoc.gmk @@ -1,4 +1,4 @@ -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -81,6 +81,8 @@ NASHORNAPI_FIRST_COPYRIGHT_YEAR = 2014 JNLP_FIRST_COPYRIGHT_YEAR = 1998 PLUGIN2_FIRST_COPYRIGHT_YEAR = 2007 JDKNET_FIRST_COPYRIGHT_YEAR = 2014 +JACCESSAPI_FIRST_COPYRIGHT_YEAR = 2002 + # Oracle name FULL_COMPANY_NAME = Oracle and/or its affiliates @@ -1231,6 +1233,58 @@ $(SCTPAPI_PACKAGES_FILE): $(call PackageDependencies,$(SCTPAPI_PKGS)) $(prep-target) $(call PackageFilter,$(SCTPAPI_PKGS)) +############################################################# +# +# jaccessdocs - Java Accessibility Utilities +# + +ALL_OTHER_TARGETS += jaccessdocs + +JACCESSAPI_DOCDIR := $(JRE_API_DOCSDIR)/accessibility/jaccess/spec +JACCESSAPI2COREAPI := ../../../$(JDKJRE2COREAPI) +JACCESSAPI_DOCTITLE := JACCESS API +JACCESSAPI_WINDOWTITLE := JACCESS API +JACCESSAPI_HEADER := JACCESS API +JACCESSAPI_BOTTOM := $(call CommonBottom,$(JACCESSAPI_FIRST_COPYRIGHT_YEAR)) +# JACCESSAPI_PKGS is located in NON_CORE_PKGS.gmk + +JACCESSAPI_INDEX_HTML = $(JACCESSAPI_DOCDIR)/index.html +JACCESSAPI_OPTIONS_FILE = $(DOCSTMPDIR)/jaccess.options +JACCESSAPI_PACKAGES_FILE = $(DOCSTMPDIR)/jaccess.packages + +jaccessdocs: $(JACCESSAPI_INDEX_HTML) + +# Set relative location to core api document root +$(JACCESSAPI_INDEX_HTML): GET2DOCSDIR=$(JACCESSAPI2COREAPI)/.. + +# Run javadoc if the index file is out of date or missing +$(JACCESSAPI_INDEX_HTML): $(JACCESSAPI_OPTIONS_FILE) $(JACCESSAPI_PACKAGES_FILE) $(COREAPI_INDEX_FILE) + $(prep-javadoc) + $(call JavadocSummary,$(JACCESSAPI_OPTIONS_FILE),$(JACCESSAPI_PACKAGES_FILE)) + $(JAVADOC_CMD) -d $(@D) \ + @$(JACCESSAPI_OPTIONS_FILE) @$(JACCESSAPI_PACKAGES_FILE) + +# Create file with javadoc options in it +$(JACCESSAPI_OPTIONS_FILE): + $(prep-target) + @($(call COMMON_JAVADOCFLAGS) ; \ + $(call COMMON_JAVADOCTAGS) ; \ + $(call OptionOnly,-Xdoclint:all) ; \ + $(call OptionPair,-sourcepath,$(RELEASEDOCS_SOURCEPATH)) ; \ + $(call OptionPair,-encoding,ascii) ; \ + $(call OptionOnly,-nodeprecatedlist) ; \ + $(call OptionPair,-doctitle,$(JACCESSAPI_DOCTITLE)) ; \ + $(call OptionPair,-windowtitle,$(JACCESSAPI_WINDOWTITLE) $(DRAFT_WINTITLE)); \ + $(call OptionPair,-header,$(JACCESSAPI_HEADER)$(DRAFT_HEADER)) ; \ + $(call OptionPair,-bottom,$(JACCESSAPI_BOTTOM)$(DRAFT_BOTTOM)) ; \ + $(call OptionTrip,-linkoffline,$(JACCESSAPI2COREAPI),$(COREAPI_DOCSDIR)/); \ + ) >> $@ + +# Create a file with the package names in it +$(JACCESSAPI_PACKAGES_FILE): $(call PackageDependencies,$(JACCESSAPI_PKGS)) + $(prep-target) + $(call PackageFilter,$(JACCESSAPI_PKGS)) + ############################################################# # # jdk.net docs diff --git a/make/Main.gmk b/make/Main.gmk index 5a4e0d5c23a..31e2fa69c3e 100644 --- a/make/Main.gmk +++ b/make/Main.gmk @@ -386,6 +386,9 @@ else # links against libosxapp. jdk.deploy.osx-libs: java.desktop-libs + # jdk.accessibility depends on java.desktop + jdk.accessibility-libs: java.desktop-libs + # This dependency needs to be explicitly declared. jdk.jdi-gensrc generates a # header file used by jdk.jdwp.agent-libs. The jdk.jdwp.agent-gensrc is a # virtual target. diff --git a/make/common/NON_CORE_PKGS.gmk b/make/common/NON_CORE_PKGS.gmk index cb3887a9d00..5127743ccf5 100644 --- a/make/common/NON_CORE_PKGS.gmk +++ b/make/common/NON_CORE_PKGS.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2002, 2015, 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 @@ -99,6 +99,8 @@ JDK_PKGS = jdk \ jdk.net \ jdk.management.cmm +JACCESSAPI_PKGS = com.sun.java.accessibility.util + # non-core packages in rt.jar NON_CORE_PKGS = $(DOMAPI_PKGS) \ $(MGMT_PKGS) \ @@ -110,4 +112,5 @@ NON_CORE_PKGS = $(DOMAPI_PKGS) \ $(SMARTCARDIO_PKGS) \ $(SCTPAPI_PKGS) \ $(APPLE_EXT_PKGS) \ - $(JDK_PKGS) + $(JDK_PKGS) \ + $(JACCESSAPI_PKGS) diff --git a/modules.xml b/modules.xml index 389112a748c..a98218f1a2c 100644 --- a/modules.xml +++ b/modules.xml @@ -2,7 +2,7 @@ Date: Fri, 13 Mar 2015 15:16:07 -0400 Subject: [PATCH 064/362] 8074717: Merge interp_masm files for x86 _32 and _64 Merge interp_masm_x86 files into one. Reviewed-by: sspitsyn, hseigel, mockner --- hotspot/src/cpu/x86/vm/interp_masm_x86.cpp | 1649 ++++++++++++++++- hotspot/src/cpu/x86/vm/interp_masm_x86.hpp | 256 ++- hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp | 1444 --------------- hotspot/src/cpu/x86/vm/interp_masm_x86_32.hpp | 223 --- hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp | 1507 --------------- hotspot/src/cpu/x86/vm/interp_masm_x86_64.hpp | 240 --- 6 files changed, 1897 insertions(+), 3422 deletions(-) delete mode 100644 hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp delete mode 100644 hotspot/src/cpu/x86/vm/interp_masm_x86_32.hpp delete mode 100644 hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp delete mode 100644 hotspot/src/cpu/x86/vm/interp_masm_x86_64.hpp diff --git a/hotspot/src/cpu/x86/vm/interp_masm_x86.cpp b/hotspot/src/cpu/x86/vm/interp_masm_x86.cpp index 34d0d8061d0..e9e238001aa 100644 --- a/hotspot/src/cpu/x86/vm/interp_masm_x86.cpp +++ b/hotspot/src/cpu/x86/vm/interp_masm_x86.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -25,7 +25,20 @@ #include "precompiled.hpp" #include "interp_masm_x86.hpp" #include "interpreter/interpreter.hpp" +#include "interpreter/interpreterRuntime.hpp" +#include "oops/arrayOop.hpp" +#include "oops/markOop.hpp" #include "oops/methodData.hpp" +#include "oops/method.hpp" +#include "prims/jvmtiExport.hpp" +#include "prims/jvmtiRedefineClassesTrace.hpp" +#include "prims/jvmtiThreadState.hpp" +#include "runtime/basicLock.hpp" +#include "runtime/biasedLocking.hpp" +#include "runtime/sharedRuntime.hpp" +#include "runtime/thread.inline.hpp" + +// Implementation of InterpreterMacroAssembler #ifndef CC_INTERP void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) { @@ -227,3 +240,1637 @@ void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register t } } #endif + +#ifdef CC_INTERP +void InterpreterMacroAssembler::get_method(Register reg) { + movptr(reg, Address(rbp, -(sizeof(BytecodeInterpreter) + 2 * wordSize))); + movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method))); +} +#endif // CC_INTERP + +#ifndef CC_INTERP +void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point, + int number_of_arguments) { + // interpreter specific + // + // Note: No need to save/restore bcp & locals registers + // since these are callee saved registers and no blocking/ + // GC can happen in leaf calls. + // Further Note: DO NOT save/restore bcp/locals. If a caller has + // already saved them so that it can use rsi/rdi as temporaries + // then a save/restore here will DESTROY the copy the caller + // saved! There used to be a save_bcp() that only happened in + // the ASSERT path (no restore_bcp). Which caused bizarre failures + // when jvm built with ASSERTs. +#ifdef ASSERT + { + Label L; + cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); + jcc(Assembler::equal, L); + stop("InterpreterMacroAssembler::call_VM_leaf_base:" + " last_sp != NULL"); + bind(L); + } +#endif + // super call + MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments); + // interpreter specific + // LP64: Used to ASSERT that r13/r14 were equal to frame's bcp/locals + // but since they may not have been saved (and we don't want to + // save them here (see note above) the assert is invalid. +} + +void InterpreterMacroAssembler::call_VM_base(Register oop_result, + Register java_thread, + Register last_java_sp, + address entry_point, + int number_of_arguments, + bool check_exceptions) { + // interpreter specific + // + // Note: Could avoid restoring locals ptr (callee saved) - however doesn't + // really make a difference for these runtime calls, since they are + // slow anyway. Btw., bcp must be saved/restored since it may change + // due to GC. + NOT_LP64(assert(java_thread == noreg , "not expecting a precomputed java thread");) + save_bcp(); +#ifdef ASSERT + { + Label L; + cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); + jcc(Assembler::equal, L); + stop("InterpreterMacroAssembler::call_VM_leaf_base:" + " last_sp != NULL"); + bind(L); + } +#endif /* ASSERT */ + // super call + MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp, + entry_point, number_of_arguments, + check_exceptions); + // interpreter specific + restore_bcp(); + restore_locals(); +} + +void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) { + if (JvmtiExport::can_pop_frame()) { + Label L; + // Initiate popframe handling only if it is not already being + // processed. If the flag has the popframe_processing bit set, it + // means that this code is called *during* popframe handling - we + // don't want to reenter. + // This method is only called just after the call into the vm in + // call_VM_base, so the arg registers are available. + Register pop_cond = NOT_LP64(java_thread) // Not clear if any other register is available on 32 bit + LP64_ONLY(c_rarg0); + movl(pop_cond, Address(java_thread, JavaThread::popframe_condition_offset())); + testl(pop_cond, JavaThread::popframe_pending_bit); + jcc(Assembler::zero, L); + testl(pop_cond, JavaThread::popframe_processing_bit); + jcc(Assembler::notZero, L); + // Call Interpreter::remove_activation_preserving_args_entry() to get the + // address of the same-named entrypoint in the generated interpreter code. + call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); + jmp(rax); + bind(L); + NOT_LP64(get_thread(java_thread);) + } +} + +void InterpreterMacroAssembler::load_earlyret_value(TosState state) { + Register thread = LP64_ONLY(r15_thread) NOT_LP64(rcx); + NOT_LP64(get_thread(thread);) + movptr(rcx, Address(thread, JavaThread::jvmti_thread_state_offset())); + const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset()); + const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset()); + const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset()); +#ifdef _LP64 + switch (state) { + case atos: movptr(rax, oop_addr); + movptr(oop_addr, (int32_t)NULL_WORD); + verify_oop(rax, state); break; + case ltos: movptr(rax, val_addr); break; + case btos: // fall through + case ctos: // fall through + case stos: // fall through + case itos: movl(rax, val_addr); break; + case ftos: movflt(xmm0, val_addr); break; + case dtos: movdbl(xmm0, val_addr); break; + case vtos: /* nothing to do */ break; + default : ShouldNotReachHere(); + } + // Clean up tos value in the thread object + movl(tos_addr, (int) ilgl); + movl(val_addr, (int32_t) NULL_WORD); +#else + const Address val_addr1(rcx, JvmtiThreadState::earlyret_value_offset() + + in_ByteSize(wordSize)); + switch (state) { + case atos: movptr(rax, oop_addr); + movptr(oop_addr, NULL_WORD); + verify_oop(rax, state); break; + case ltos: + movl(rdx, val_addr1); // fall through + case btos: // fall through + case ctos: // fall through + case stos: // fall through + case itos: movl(rax, val_addr); break; + case ftos: fld_s(val_addr); break; + case dtos: fld_d(val_addr); break; + case vtos: /* nothing to do */ break; + default : ShouldNotReachHere(); + } +#endif // _LP64 + // Clean up tos value in the thread object + movl(tos_addr, (int32_t) ilgl); + movptr(val_addr, NULL_WORD); + NOT_LP64(movptr(val_addr1, NULL_WORD);) +} + + +void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) { + if (JvmtiExport::can_force_early_return()) { + Label L; + Register tmp = LP64_ONLY(c_rarg0) NOT_LP64(java_thread); + Register rthread = LP64_ONLY(r15_thread) NOT_LP64(java_thread); + + movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset())); + testptr(tmp, tmp); + jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit; + + // Initiate earlyret handling only if it is not already being processed. + // If the flag has the earlyret_processing bit set, it means that this code + // is called *during* earlyret handling - we don't want to reenter. + movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset())); + cmpl(tmp, JvmtiThreadState::earlyret_pending); + jcc(Assembler::notEqual, L); + + // Call Interpreter::remove_activation_early_entry() to get the address of the + // same-named entrypoint in the generated interpreter code. + NOT_LP64(get_thread(java_thread);) + movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset())); +#ifdef _LP64 + movl(tmp, Address(tmp, JvmtiThreadState::earlyret_tos_offset())); + call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), tmp); +#else + pushl(Address(tmp, JvmtiThreadState::earlyret_tos_offset())); + call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), 1); +#endif // _LP64 + jmp(rax); + bind(L); + NOT_LP64(get_thread(java_thread);) + } +} + +void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) { + assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode"); + load_unsigned_short(reg, Address(_bcp_register, bcp_offset)); + bswapl(reg); + shrl(reg, 16); +} + +void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index, + int bcp_offset, + size_t index_size) { + assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); + if (index_size == sizeof(u2)) { + load_unsigned_short(index, Address(_bcp_register, bcp_offset)); + } else if (index_size == sizeof(u4)) { + movl(index, Address(_bcp_register, bcp_offset)); + // Check if the secondary index definition is still ~x, otherwise + // we have to change the following assembler code to calculate the + // plain index. + assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line"); + notl(index); // convert to plain index + } else if (index_size == sizeof(u1)) { + load_unsigned_byte(index, Address(_bcp_register, bcp_offset)); + } else { + ShouldNotReachHere(); + } +} + +void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, + Register index, + int bcp_offset, + size_t index_size) { + assert_different_registers(cache, index); + get_cache_index_at_bcp(index, bcp_offset, index_size); + movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); + assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below"); + // convert from field index to ConstantPoolCacheEntry index + assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line"); + shll(index, 2); +} + +void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache, + Register index, + Register bytecode, + int byte_no, + int bcp_offset, + size_t index_size) { + get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size); + // We use a 32-bit load here since the layout of 64-bit words on + // little-endian machines allow us that. + movl(bytecode, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset())); + const int shift_count = (1 + byte_no) * BitsPerByte; + assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) || + (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift), + "correct shift count"); + shrl(bytecode, shift_count); + assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask"); + andl(bytecode, ConstantPoolCacheEntry::bytecode_1_mask); +} + +void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, + Register tmp, + int bcp_offset, + size_t index_size) { + assert(cache != tmp, "must use different register"); + get_cache_index_at_bcp(tmp, bcp_offset, index_size); + assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below"); + // convert from field index to ConstantPoolCacheEntry index + // and from word offset to byte offset + assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line"); + shll(tmp, 2 + LogBytesPerWord); + movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); + // skip past the header + addptr(cache, in_bytes(ConstantPoolCache::base_offset())); + addptr(cache, tmp); // construct pointer to cache entry +} + +// Load object from cpool->resolved_references(index) +void InterpreterMacroAssembler::load_resolved_reference_at_index( + Register result, Register index) { + assert_different_registers(result, index); + // convert from field index to resolved_references() index and from + // word index to byte offset. Since this is a java object, it can be compressed + Register tmp = index; // reuse + shll(tmp, LogBytesPerHeapOop); + + get_constant_pool(result); + // load pointer for resolved_references[] objArray + movptr(result, Address(result, ConstantPool::resolved_references_offset_in_bytes())); + // JNIHandles::resolve(obj); + movptr(result, Address(result, 0)); + // Add in the index + addptr(result, tmp); + load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT))); +} + + +// Generate a subtype check: branch to ok_is_subtype if sub_klass is a +// subtype of super_klass. +// +// Args: +// rax: superklass +// Rsub_klass: subklass +// +// Kills: +// rcx, rdi +void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, + Label& ok_is_subtype) { + assert(Rsub_klass != rax, "rax holds superklass"); + LP64_ONLY(assert(Rsub_klass != r14, "r14 holds locals");) + LP64_ONLY(assert(Rsub_klass != r13, "r13 holds bcp");) + assert(Rsub_klass != rcx, "rcx holds 2ndary super array length"); + assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr"); + + // Profile the not-null value's klass. + profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi + + // Do the check. + check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx + + // Profile the failure of the check. + profile_typecheck_failed(rcx); // blows rcx +} + + +#ifndef _LP64 +void InterpreterMacroAssembler::f2ieee() { + if (IEEEPrecision) { + fstp_s(Address(rsp, 0)); + fld_s(Address(rsp, 0)); + } +} + + +void InterpreterMacroAssembler::d2ieee() { + if (IEEEPrecision) { + fstp_d(Address(rsp, 0)); + fld_d(Address(rsp, 0)); + } +} +#endif // _LP64 + +// Java Expression Stack + +void InterpreterMacroAssembler::pop_ptr(Register r) { + pop(r); +} + +void InterpreterMacroAssembler::push_ptr(Register r) { + push(r); +} + +void InterpreterMacroAssembler::push_i(Register r) { + push(r); +} + +#ifdef _LP64 +void InterpreterMacroAssembler::pop_i(Register r) { + // XXX can't use pop currently, upper half non clean + movl(r, Address(rsp, 0)); + addptr(rsp, wordSize); +} + +void InterpreterMacroAssembler::pop_l(Register r) { + movq(r, Address(rsp, 0)); + addptr(rsp, 2 * Interpreter::stackElementSize); +} + +void InterpreterMacroAssembler::pop_f(XMMRegister r) { + movflt(r, Address(rsp, 0)); + addptr(rsp, wordSize); +} + +void InterpreterMacroAssembler::pop_d(XMMRegister r) { + movdbl(r, Address(rsp, 0)); + addptr(rsp, 2 * Interpreter::stackElementSize); +} + +void InterpreterMacroAssembler::push_l(Register r) { + subptr(rsp, 2 * wordSize); + movq(Address(rsp, 0), r); +} + +void InterpreterMacroAssembler::push_f(XMMRegister r) { + subptr(rsp, wordSize); + movflt(Address(rsp, 0), r); +} + +void InterpreterMacroAssembler::push_d(XMMRegister r) { + subptr(rsp, 2 * wordSize); + movdbl(Address(rsp, 0), r); +} + +void InterpreterMacroAssembler::pop(TosState state) { + switch (state) { + case atos: pop_ptr(); break; + case btos: + case ctos: + case stos: + case itos: pop_i(); break; + case ltos: pop_l(); break; + case ftos: pop_f(); break; + case dtos: pop_d(); break; + case vtos: /* nothing to do */ break; + default: ShouldNotReachHere(); + } + verify_oop(rax, state); +} + +void InterpreterMacroAssembler::push(TosState state) { + verify_oop(rax, state); + switch (state) { + case atos: push_ptr(); break; + case btos: + case ctos: + case stos: + case itos: push_i(); break; + case ltos: push_l(); break; + case ftos: push_f(); break; + case dtos: push_d(); break; + case vtos: /* nothing to do */ break; + default : ShouldNotReachHere(); + } +} +#else +void InterpreterMacroAssembler::pop_i(Register r) { + pop(r); +} + +void InterpreterMacroAssembler::pop_l(Register lo, Register hi) { + pop(lo); + pop(hi); +} + +void InterpreterMacroAssembler::pop_f() { + fld_s(Address(rsp, 0)); + addptr(rsp, 1 * wordSize); +} + +void InterpreterMacroAssembler::pop_d() { + fld_d(Address(rsp, 0)); + addptr(rsp, 2 * wordSize); +} + + +void InterpreterMacroAssembler::pop(TosState state) { + switch (state) { + case atos: pop_ptr(rax); break; + case btos: // fall through + case ctos: // fall through + case stos: // fall through + case itos: pop_i(rax); break; + case ltos: pop_l(rax, rdx); break; + case ftos: pop_f(); break; + case dtos: pop_d(); break; + case vtos: /* nothing to do */ break; + default : ShouldNotReachHere(); + } + verify_oop(rax, state); +} + + +void InterpreterMacroAssembler::push_l(Register lo, Register hi) { + push(hi); + push(lo); +} + +void InterpreterMacroAssembler::push_f() { + // Do not schedule for no AGI! Never write beyond rsp! + subptr(rsp, 1 * wordSize); + fstp_s(Address(rsp, 0)); +} + +void InterpreterMacroAssembler::push_d(Register r) { + // Do not schedule for no AGI! Never write beyond rsp! + subptr(rsp, 2 * wordSize); + fstp_d(Address(rsp, 0)); +} + + +void InterpreterMacroAssembler::push(TosState state) { + verify_oop(rax, state); + switch (state) { + case atos: push_ptr(rax); break; + case btos: // fall through + case ctos: // fall through + case stos: // fall through + case itos: push_i(rax); break; + case ltos: push_l(rax, rdx); break; + case ftos: push_f(); break; + case dtos: push_d(rax); break; + case vtos: /* nothing to do */ break; + default : ShouldNotReachHere(); + } +} +#endif // _LP64 + + +// Helpers for swap and dup +void InterpreterMacroAssembler::load_ptr(int n, Register val) { + movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n))); +} + +void InterpreterMacroAssembler::store_ptr(int n, Register val) { + movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val); +} + + +void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() { + // set sender sp + lea(_bcp_register, Address(rsp, wordSize)); + // record last_sp + movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), _bcp_register); +} + + +// Jump to from_interpreted entry of a call unless single stepping is possible +// in this thread in which case we must call the i2i entry +void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) { + prepare_to_jump_from_interpreted(); + + if (JvmtiExport::can_post_interpreter_events()) { + Label run_compiled_code; + // JVMTI events, such as single-stepping, are implemented partly by avoiding running + // compiled code in threads for which the event is enabled. Check here for + // interp_only_mode if these events CAN be enabled. + // interp_only is an int, on little endian it is sufficient to test the byte only + // Is a cmpl faster? + LP64_ONLY(temp = r15_thread;) + NOT_LP64(get_thread(temp);) + cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0); + jccb(Assembler::zero, run_compiled_code); + jmp(Address(method, Method::interpreter_entry_offset())); + bind(run_compiled_code); + } + + jmp(Address(method, Method::from_interpreted_offset())); +} + +// The following two routines provide a hook so that an implementation +// can schedule the dispatch in two parts. x86 does not do this. +void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) { + // Nothing x86 specific to be done here +} + +void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) { + dispatch_next(state, step); +} + +void InterpreterMacroAssembler::dispatch_base(TosState state, + address* table, + bool verifyoop) { + verify_FPU(1, state); + if (VerifyActivationFrameSize) { + Label L; + mov(rcx, rbp); + subptr(rcx, rsp); + int32_t min_frame_size = + (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * + wordSize; + cmpptr(rcx, (int32_t)min_frame_size); + jcc(Assembler::greaterEqual, L); + stop("broken stack frame"); + bind(L); + } + if (verifyoop) { + verify_oop(rax, state); + } +#ifdef _LP64 + lea(rscratch1, ExternalAddress((address)table)); + jmp(Address(rscratch1, rbx, Address::times_8)); +#else + Address index(noreg, rbx, Address::times_ptr); + ExternalAddress tbl((address)table); + ArrayAddress dispatch(tbl, index); + jump(dispatch); +#endif // _LP64 +} + +void InterpreterMacroAssembler::dispatch_only(TosState state) { + dispatch_base(state, Interpreter::dispatch_table(state)); +} + +void InterpreterMacroAssembler::dispatch_only_normal(TosState state) { + dispatch_base(state, Interpreter::normal_table(state)); +} + +void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) { + dispatch_base(state, Interpreter::normal_table(state), false); +} + + +void InterpreterMacroAssembler::dispatch_next(TosState state, int step) { + // load next bytecode (load before advancing _bcp_register to prevent AGI) + load_unsigned_byte(rbx, Address(_bcp_register, step)); + // advance _bcp_register + increment(_bcp_register, step); + dispatch_base(state, Interpreter::dispatch_table(state)); +} + +void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { + // load current bytecode + load_unsigned_byte(rbx, Address(_bcp_register, 0)); + dispatch_base(state, table); +} + +// remove activation +// +// Unlock the receiver if this is a synchronized method. +// Unlock any Java monitors from syncronized blocks. +// Remove the activation from the stack. +// +// If there are locked Java monitors +// If throw_monitor_exception +// throws IllegalMonitorStateException +// Else if install_monitor_exception +// installs IllegalMonitorStateException +// Else +// no error processing +void InterpreterMacroAssembler::remove_activation( + TosState state, + Register ret_addr, + bool throw_monitor_exception, + bool install_monitor_exception, + bool notify_jvmdi) { + // Note: Registers rdx xmm0 may be in use for the + // result check if synchronized method + Label unlocked, unlock, no_unlock; + + const Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx); + const Register robj = LP64_ONLY(c_rarg1) NOT_LP64(rdx); + const Register rmon = LP64_ONLY(c_rarg1) NOT_LP64(rcx); + // monitor pointers need different register + // because rdx may have the result in it + NOT_LP64(get_thread(rcx);) + + // get the value of _do_not_unlock_if_synchronized into rdx + const Address do_not_unlock_if_synchronized(rthread, + in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); + movbool(rbx, do_not_unlock_if_synchronized); + movbool(do_not_unlock_if_synchronized, false); // reset the flag + + // get method access flags + movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); + movl(rcx, Address(rcx, Method::access_flags_offset())); + testl(rcx, JVM_ACC_SYNCHRONIZED); + jcc(Assembler::zero, unlocked); + + // Don't unlock anything if the _do_not_unlock_if_synchronized flag + // is set. + testbool(rbx); + jcc(Assembler::notZero, no_unlock); + + // unlock monitor + push(state); // save result + + // BasicObjectLock will be first in list, since this is a + // synchronized method. However, need to check that the object has + // not been unlocked by an explicit monitorexit bytecode. + const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * + wordSize - (int) sizeof(BasicObjectLock)); + // We use c_rarg1/rdx so that if we go slow path it will be the correct + // register for unlock_object to pass to VM directly + lea(robj, monitor); // address of first monitor + + movptr(rax, Address(robj, BasicObjectLock::obj_offset_in_bytes())); + testptr(rax, rax); + jcc(Assembler::notZero, unlock); + + pop(state); + if (throw_monitor_exception) { + // Entry already unlocked, need to throw exception + NOT_LP64(empty_FPU_stack();) // remove possible return value from FPU-stack, otherwise stack could overflow + call_VM(noreg, CAST_FROM_FN_PTR(address, + InterpreterRuntime::throw_illegal_monitor_state_exception)); + should_not_reach_here(); + } else { + // Monitor already unlocked during a stack unroll. If requested, + // install an illegal_monitor_state_exception. Continue with + // stack unrolling. + if (install_monitor_exception) { + NOT_LP64(empty_FPU_stack();) + call_VM(noreg, CAST_FROM_FN_PTR(address, + InterpreterRuntime::new_illegal_monitor_state_exception)); + } + jmp(unlocked); + } + + bind(unlock); + unlock_object(robj); + pop(state); + + // Check that for block-structured locking (i.e., that all locked + // objects has been unlocked) + bind(unlocked); + + // rax, rdx: Might contain return value + + // Check that all monitors are unlocked + { + Label loop, exception, entry, restart; + const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; + const Address monitor_block_top( + rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); + const Address monitor_block_bot( + rbp, frame::interpreter_frame_initial_sp_offset * wordSize); + + bind(restart); + // We use c_rarg1 so that if we go slow path it will be the correct + // register for unlock_object to pass to VM directly + movptr(rmon, monitor_block_top); // points to current entry, starting + // with top-most entry + lea(rbx, monitor_block_bot); // points to word before bottom of + // monitor block + jmp(entry); + + // Entry already locked, need to throw exception + bind(exception); + + if (throw_monitor_exception) { + // Throw exception + NOT_LP64(empty_FPU_stack();) + MacroAssembler::call_VM(noreg, + CAST_FROM_FN_PTR(address, InterpreterRuntime:: + throw_illegal_monitor_state_exception)); + should_not_reach_here(); + } else { + // Stack unrolling. Unlock object and install illegal_monitor_exception. + // Unlock does not block, so don't have to worry about the frame. + // We don't have to preserve c_rarg1 since we are going to throw an exception. + + push(state); + mov(robj, rmon); // nop if robj and rmon are the same + unlock_object(robj); + pop(state); + + if (install_monitor_exception) { + NOT_LP64(empty_FPU_stack();) + call_VM(noreg, CAST_FROM_FN_PTR(address, + InterpreterRuntime:: + new_illegal_monitor_state_exception)); + } + + jmp(restart); + } + + bind(loop); + // check if current entry is used + cmpptr(Address(rmon, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL); + jcc(Assembler::notEqual, exception); + + addptr(rmon, entry_size); // otherwise advance to next entry + bind(entry); + cmpptr(rmon, rbx); // check if bottom reached + jcc(Assembler::notEqual, loop); // if not at bottom then check this entry + } + + bind(no_unlock); + + // jvmti support + if (notify_jvmdi) { + notify_method_exit(state, NotifyJVMTI); // preserve TOSCA + } else { + notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA + } + + // remove activation + // get sender sp + movptr(rbx, + Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); + leave(); // remove frame anchor + pop(ret_addr); // get return address + mov(rsp, rbx); // set sp to sender sp +#ifndef _LP64 + if (UseSSE) { + // float and double are returned in xmm register in SSE-mode + if (state == ftos && UseSSE >= 1) { + subptr(rsp, wordSize); + fstp_s(Address(rsp, 0)); + movflt(xmm0, Address(rsp, 0)); + addptr(rsp, wordSize); + } else if (state == dtos && UseSSE >= 2) { + subptr(rsp, 2*wordSize); + fstp_d(Address(rsp, 0)); + movdbl(xmm0, Address(rsp, 0)); + addptr(rsp, 2*wordSize); + } + } +#endif // _LP64 +} +#endif // !CC_INTERP + +void InterpreterMacroAssembler::get_method_counters(Register method, + Register mcs, Label& skip) { + Label has_counters; + movptr(mcs, Address(method, Method::method_counters_offset())); + testptr(mcs, mcs); + jcc(Assembler::notZero, has_counters); + call_VM(noreg, CAST_FROM_FN_PTR(address, + InterpreterRuntime::build_method_counters), method); + movptr(mcs, Address(method,Method::method_counters_offset())); + testptr(mcs, mcs); + jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory + bind(has_counters); +} + + +// Lock object +// +// Args: +// rdx, c_rarg1: BasicObjectLock to be used for locking +// +// Kills: +// rax +// rscratch1 (scratch regs) +void InterpreterMacroAssembler::lock_object(Register lock_reg) { + assert(lock_reg == LP64_ONLY(c_rarg1) NOT_LP64(rdx), + "The argument is only for looks. It must be c_rarg1"); + + if (UseHeavyMonitors) { + call_VM(noreg, + CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), + lock_reg); + } else { + Label done; + + const Register swap_reg = rax; // Must use rax for cmpxchg instruction + const Register obj_reg = LP64_ONLY(c_rarg3) NOT_LP64(rcx); // Will contain the oop + + const int obj_offset = BasicObjectLock::obj_offset_in_bytes(); + const int lock_offset = BasicObjectLock::lock_offset_in_bytes (); + const int mark_offset = lock_offset + + BasicLock::displaced_header_offset_in_bytes(); + + Label slow_case; + + // Load object pointer into obj_reg + movptr(obj_reg, Address(lock_reg, obj_offset)); + + if (UseBiasedLocking) { + biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, done, &slow_case); + } + + // Load immediate 1 into swap_reg %rax + movl(swap_reg, (int32_t)1); + + // Load (object->mark() | 1) into swap_reg %rax + orptr(swap_reg, Address(obj_reg, 0)); + + // Save (object->mark() | 1) into BasicLock's displaced header + movptr(Address(lock_reg, mark_offset), swap_reg); + + assert(lock_offset == 0, + "displached header must be first word in BasicObjectLock"); + + if (os::is_MP()) lock(); + cmpxchgptr(lock_reg, Address(obj_reg, 0)); + if (PrintBiasedLockingStatistics) { + cond_inc32(Assembler::zero, + ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); + } + jcc(Assembler::zero, done); + + const int zero_bits = LP64_ONLY(7) NOT_LP64(3); + + // Test if the oopMark is an obvious stack pointer, i.e., + // 1) (mark & zero_bits) == 0, and + // 2) rsp <= mark < mark + os::pagesize() + // + // These 3 tests can be done by evaluating the following + // expression: ((mark - rsp) & (zero_bits - os::vm_page_size())), + // assuming both stack pointer and pagesize have their + // least significant bits clear. + // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg + subptr(swap_reg, rsp); + andptr(swap_reg, zero_bits - os::vm_page_size()); + + // Save the test result, for recursive case, the result is zero + movptr(Address(lock_reg, mark_offset), swap_reg); + + if (PrintBiasedLockingStatistics) { + cond_inc32(Assembler::zero, + ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); + } + jcc(Assembler::zero, done); + + bind(slow_case); + + // Call the runtime routine for slow case + call_VM(noreg, + CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), + lock_reg); + + bind(done); + } +} + + +// Unlocks an object. Used in monitorexit bytecode and +// remove_activation. Throws an IllegalMonitorException if object is +// not locked by current thread. +// +// Args: +// rdx, c_rarg1: BasicObjectLock for lock +// +// Kills: +// rax +// c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs) +// rscratch1, rscratch2 (scratch regs) +// rax, rbx, rcx, rdx +void InterpreterMacroAssembler::unlock_object(Register lock_reg) { + assert(lock_reg == LP64_ONLY(c_rarg1) NOT_LP64(rdx), + "The argument is only for looks. It must be c_rarg1"); + + if (UseHeavyMonitors) { + call_VM(noreg, + CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), + lock_reg); + } else { + Label done; + + const Register swap_reg = rax; // Must use rax for cmpxchg instruction + const Register header_reg = LP64_ONLY(c_rarg2) NOT_LP64(rbx); // Will contain the old oopMark + const Register obj_reg = LP64_ONLY(c_rarg3) NOT_LP64(rcx); // Will contain the oop + + save_bcp(); // Save in case of exception + + // Convert from BasicObjectLock structure to object and BasicLock + // structure Store the BasicLock address into %rax + lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes())); + + // Load oop into obj_reg(%c_rarg3) + movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes())); + + // Free entry + movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); + + if (UseBiasedLocking) { + biased_locking_exit(obj_reg, header_reg, done); + } + + // Load the old header from BasicLock structure + movptr(header_reg, Address(swap_reg, + BasicLock::displaced_header_offset_in_bytes())); + + // Test for recursion + testptr(header_reg, header_reg); + + // zero for recursive case + jcc(Assembler::zero, done); + + // Atomic swap back the old header + if (os::is_MP()) lock(); + cmpxchgptr(header_reg, Address(obj_reg, 0)); + + // zero for recursive case + jcc(Assembler::zero, done); + + // Call the runtime routine for slow case. + movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), + obj_reg); // restore obj + call_VM(noreg, + CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), + lock_reg); + + bind(done); + + restore_bcp(); + } +} +#ifndef CC_INTERP +void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, + Label& zero_continue) { + assert(ProfileInterpreter, "must be profiling interpreter"); + movptr(mdp, Address(rbp, frame::interpreter_frame_mdp_offset * wordSize)); + testptr(mdp, mdp); + jcc(Assembler::zero, zero_continue); +} + + +// Set the method data pointer for the current bcp. +void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { + assert(ProfileInterpreter, "must be profiling interpreter"); + Label set_mdp; + push(rax); + push(rbx); + + get_method(rbx); + // Test MDO to avoid the call if it is NULL. + movptr(rax, Address(rbx, in_bytes(Method::method_data_offset()))); + testptr(rax, rax); + jcc(Assembler::zero, set_mdp); + // rbx: method + // _bcp_register: bcp + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, _bcp_register); + // rax: mdi + // mdo is guaranteed to be non-zero here, we checked for it before the call. + movptr(rbx, Address(rbx, in_bytes(Method::method_data_offset()))); + addptr(rbx, in_bytes(MethodData::data_offset())); + addptr(rax, rbx); + bind(set_mdp); + movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), rax); + pop(rbx); + pop(rax); +} + +void InterpreterMacroAssembler::verify_method_data_pointer() { + assert(ProfileInterpreter, "must be profiling interpreter"); +#ifdef ASSERT + Label verify_continue; + push(rax); + push(rbx); + Register arg3_reg = LP64_ONLY(c_rarg3) NOT_LP64(rcx); + Register arg2_reg = LP64_ONLY(c_rarg2) NOT_LP64(rdx); + push(arg3_reg); + push(arg2_reg); + test_method_data_pointer(arg3_reg, verify_continue); // If mdp is zero, continue + get_method(rbx); + + // If the mdp is valid, it will point to a DataLayout header which is + // consistent with the bcp. The converse is highly probable also. + load_unsigned_short(arg2_reg, + Address(arg3_reg, in_bytes(DataLayout::bci_offset()))); + addptr(arg2_reg, Address(rbx, Method::const_offset())); + lea(arg2_reg, Address(arg2_reg, ConstMethod::codes_offset())); + cmpptr(arg2_reg, _bcp_register); + jcc(Assembler::equal, verify_continue); + // rbx: method + // _bcp_register: bcp + // c_rarg3: mdp + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), + rbx, _bcp_register, arg3_reg); + bind(verify_continue); + pop(arg2_reg); + pop(arg3_reg); + pop(rbx); + pop(rax); +#endif // ASSERT +} + + +void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, + int constant, + Register value) { + assert(ProfileInterpreter, "must be profiling interpreter"); + Address data(mdp_in, constant); + movptr(data, value); +} + + +void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, + int constant, + bool decrement) { + // Counter address + Address data(mdp_in, constant); + + increment_mdp_data_at(data, decrement); +} + +void InterpreterMacroAssembler::increment_mdp_data_at(Address data, + bool decrement) { + assert(ProfileInterpreter, "must be profiling interpreter"); + // %%% this does 64bit counters at best it is wasting space + // at worst it is a rare bug when counters overflow + + if (decrement) { + // Decrement the register. Set condition codes. + addptr(data, (int32_t) -DataLayout::counter_increment); + // If the decrement causes the counter to overflow, stay negative + Label L; + jcc(Assembler::negative, L); + addptr(data, (int32_t) DataLayout::counter_increment); + bind(L); + } else { + assert(DataLayout::counter_increment == 1, + "flow-free idiom only works with 1"); + // Increment the register. Set carry flag. + addptr(data, DataLayout::counter_increment); + // If the increment causes the counter to overflow, pull back by 1. + sbbptr(data, (int32_t)0); + } +} + + +void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, + Register reg, + int constant, + bool decrement) { + Address data(mdp_in, reg, Address::times_1, constant); + + increment_mdp_data_at(data, decrement); +} + +void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, + int flag_byte_constant) { + assert(ProfileInterpreter, "must be profiling interpreter"); + int header_offset = in_bytes(DataLayout::header_offset()); + int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant); + // Set the flag + orl(Address(mdp_in, header_offset), header_bits); +} + + + +void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in, + int offset, + Register value, + Register test_value_out, + Label& not_equal_continue) { + assert(ProfileInterpreter, "must be profiling interpreter"); + if (test_value_out == noreg) { + cmpptr(value, Address(mdp_in, offset)); + } else { + // Put the test value into a register, so caller can use it: + movptr(test_value_out, Address(mdp_in, offset)); + cmpptr(test_value_out, value); + } + jcc(Assembler::notEqual, not_equal_continue); +} + + +void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, + int offset_of_disp) { + assert(ProfileInterpreter, "must be profiling interpreter"); + Address disp_address(mdp_in, offset_of_disp); + addptr(mdp_in, disp_address); + movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); +} + + +void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, + Register reg, + int offset_of_disp) { + assert(ProfileInterpreter, "must be profiling interpreter"); + Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp); + addptr(mdp_in, disp_address); + movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); +} + + +void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, + int constant) { + assert(ProfileInterpreter, "must be profiling interpreter"); + addptr(mdp_in, constant); + movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); +} + + +void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) { + assert(ProfileInterpreter, "must be profiling interpreter"); + push(return_bci); // save/restore across call_VM + call_VM(noreg, + CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), + return_bci); + pop(return_bci); +} + + +void InterpreterMacroAssembler::profile_taken_branch(Register mdp, + Register bumped_count) { + if (ProfileInterpreter) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + // Otherwise, assign to mdp + test_method_data_pointer(mdp, profile_continue); + + // We are taking a branch. Increment the taken count. + // We inline increment_mdp_data_at to return bumped_count in a register + //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); + Address data(mdp, in_bytes(JumpData::taken_offset())); + movptr(bumped_count, data); + assert(DataLayout::counter_increment == 1, + "flow-free idiom only works with 1"); + addptr(bumped_count, DataLayout::counter_increment); + sbbptr(bumped_count, 0); + movptr(data, bumped_count); // Store back out + + // The method data pointer needs to be updated to reflect the new target. + update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset())); + bind(profile_continue); + } +} + + +void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) { + if (ProfileInterpreter) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + // We are taking a branch. Increment the not taken count. + increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset())); + + // The method data pointer needs to be updated to correspond to + // the next bytecode + update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size())); + bind(profile_continue); + } +} + +void InterpreterMacroAssembler::profile_call(Register mdp) { + if (ProfileInterpreter) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + // We are making a call. Increment the count. + increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); + + // The method data pointer needs to be updated to reflect the new target. + update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size())); + bind(profile_continue); + } +} + + +void InterpreterMacroAssembler::profile_final_call(Register mdp) { + if (ProfileInterpreter) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + // We are making a call. Increment the count. + increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); + + // The method data pointer needs to be updated to reflect the new target. + update_mdp_by_constant(mdp, + in_bytes(VirtualCallData:: + virtual_call_data_size())); + bind(profile_continue); + } +} + + +void InterpreterMacroAssembler::profile_virtual_call(Register receiver, + Register mdp, + Register reg2, + bool receiver_can_be_null) { + if (ProfileInterpreter) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + Label skip_receiver_profile; + if (receiver_can_be_null) { + Label not_null; + testptr(receiver, receiver); + jccb(Assembler::notZero, not_null); + // We are making a call. Increment the count for null receiver. + increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); + jmp(skip_receiver_profile); + bind(not_null); + } + + // Record the receiver type. + record_klass_in_profile(receiver, mdp, reg2, true); + bind(skip_receiver_profile); + + // The method data pointer needs to be updated to reflect the new target. + update_mdp_by_constant(mdp, + in_bytes(VirtualCallData:: + virtual_call_data_size())); + bind(profile_continue); + } +} + +// This routine creates a state machine for updating the multi-row +// type profile at a virtual call site (or other type-sensitive bytecode). +// The machine visits each row (of receiver/count) until the receiver type +// is found, or until it runs out of rows. At the same time, it remembers +// the location of the first empty row. (An empty row records null for its +// receiver, and can be allocated for a newly-observed receiver type.) +// Because there are two degrees of freedom in the state, a simple linear +// search will not work; it must be a decision tree. Hence this helper +// function is recursive, to generate the required tree structured code. +// It's the interpreter, so we are trading off code space for speed. +// See below for example code. +void InterpreterMacroAssembler::record_klass_in_profile_helper( + Register receiver, Register mdp, + Register reg2, int start_row, + Label& done, bool is_virtual_call) { + if (TypeProfileWidth == 0) { + if (is_virtual_call) { + increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); + } + return; + } + + int last_row = VirtualCallData::row_limit() - 1; + assert(start_row <= last_row, "must be work left to do"); + // Test this row for both the receiver and for null. + // Take any of three different outcomes: + // 1. found receiver => increment count and goto done + // 2. found null => keep looking for case 1, maybe allocate this cell + // 3. found something else => keep looking for cases 1 and 2 + // Case 3 is handled by a recursive call. + for (int row = start_row; row <= last_row; row++) { + Label next_test; + bool test_for_null_also = (row == start_row); + + // See if the receiver is receiver[n]. + int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row)); + test_mdp_data_at(mdp, recvr_offset, receiver, + (test_for_null_also ? reg2 : noreg), + next_test); + // (Reg2 now contains the receiver from the CallData.) + + // The receiver is receiver[n]. Increment count[n]. + int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row)); + increment_mdp_data_at(mdp, count_offset); + jmp(done); + bind(next_test); + + if (test_for_null_also) { + Label found_null; + // Failed the equality check on receiver[n]... Test for null. + testptr(reg2, reg2); + if (start_row == last_row) { + // The only thing left to do is handle the null case. + if (is_virtual_call) { + jccb(Assembler::zero, found_null); + // Receiver did not match any saved receiver and there is no empty row for it. + // Increment total counter to indicate polymorphic case. + increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); + jmp(done); + bind(found_null); + } else { + jcc(Assembler::notZero, done); + } + break; + } + // Since null is rare, make it be the branch-taken case. + jcc(Assembler::zero, found_null); + + // Put all the "Case 3" tests here. + record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call); + + // Found a null. Keep searching for a matching receiver, + // but remember that this is an empty (unused) slot. + bind(found_null); + } + } + + // In the fall-through case, we found no matching receiver, but we + // observed the receiver[start_row] is NULL. + + // Fill in the receiver field and increment the count. + int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row)); + set_mdp_data_at(mdp, recvr_offset, receiver); + int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row)); + movl(reg2, DataLayout::counter_increment); + set_mdp_data_at(mdp, count_offset, reg2); + if (start_row > 0) { + jmp(done); + } +} + +// Example state machine code for three profile rows: +// // main copy of decision tree, rooted at row[1] +// if (row[0].rec == rec) { row[0].incr(); goto done; } +// if (row[0].rec != NULL) { +// // inner copy of decision tree, rooted at row[1] +// if (row[1].rec == rec) { row[1].incr(); goto done; } +// if (row[1].rec != NULL) { +// // degenerate decision tree, rooted at row[2] +// if (row[2].rec == rec) { row[2].incr(); goto done; } +// if (row[2].rec != NULL) { count.incr(); goto done; } // overflow +// row[2].init(rec); goto done; +// } else { +// // remember row[1] is empty +// if (row[2].rec == rec) { row[2].incr(); goto done; } +// row[1].init(rec); goto done; +// } +// } else { +// // remember row[0] is empty +// if (row[1].rec == rec) { row[1].incr(); goto done; } +// if (row[2].rec == rec) { row[2].incr(); goto done; } +// row[0].init(rec); goto done; +// } +// done: + +void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, + Register mdp, Register reg2, + bool is_virtual_call) { + assert(ProfileInterpreter, "must be profiling"); + Label done; + + record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call); + + bind (done); +} + +void InterpreterMacroAssembler::profile_ret(Register return_bci, + Register mdp) { + if (ProfileInterpreter) { + Label profile_continue; + uint row; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + // Update the total ret count. + increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); + + for (row = 0; row < RetData::row_limit(); row++) { + Label next_test; + + // See if return_bci is equal to bci[n]: + test_mdp_data_at(mdp, + in_bytes(RetData::bci_offset(row)), + return_bci, noreg, + next_test); + + // return_bci is equal to bci[n]. Increment the count. + increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row))); + + // The method data pointer needs to be updated to reflect the new target. + update_mdp_by_offset(mdp, + in_bytes(RetData::bci_displacement_offset(row))); + jmp(profile_continue); + bind(next_test); + } + + update_mdp_for_ret(return_bci); + + bind(profile_continue); + } +} + + +void InterpreterMacroAssembler::profile_null_seen(Register mdp) { + if (ProfileInterpreter) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + set_mdp_flag_at(mdp, BitData::null_seen_byte_constant()); + + // The method data pointer needs to be updated. + int mdp_delta = in_bytes(BitData::bit_data_size()); + if (TypeProfileCasts) { + mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); + } + update_mdp_by_constant(mdp, mdp_delta); + + bind(profile_continue); + } +} + + +void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) { + if (ProfileInterpreter && TypeProfileCasts) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + int count_offset = in_bytes(CounterData::count_offset()); + // Back up the address, since we have already bumped the mdp. + count_offset -= in_bytes(VirtualCallData::virtual_call_data_size()); + + // *Decrement* the counter. We expect to see zero or small negatives. + increment_mdp_data_at(mdp, count_offset, true); + + bind (profile_continue); + } +} + + +void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) { + if (ProfileInterpreter) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + // The method data pointer needs to be updated. + int mdp_delta = in_bytes(BitData::bit_data_size()); + if (TypeProfileCasts) { + mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); + + // Record the object type. + record_klass_in_profile(klass, mdp, reg2, false); + NOT_LP64(assert(reg2 == rdi, "we know how to fix this blown reg");) + NOT_LP64(restore_locals();) // Restore EDI + } + update_mdp_by_constant(mdp, mdp_delta); + + bind(profile_continue); + } +} + + +void InterpreterMacroAssembler::profile_switch_default(Register mdp) { + if (ProfileInterpreter) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + // Update the default case count + increment_mdp_data_at(mdp, + in_bytes(MultiBranchData::default_count_offset())); + + // The method data pointer needs to be updated. + update_mdp_by_offset(mdp, + in_bytes(MultiBranchData:: + default_displacement_offset())); + + bind(profile_continue); + } +} + + +void InterpreterMacroAssembler::profile_switch_case(Register index, + Register mdp, + Register reg2) { + if (ProfileInterpreter) { + Label profile_continue; + + // If no method data exists, go to profile_continue. + test_method_data_pointer(mdp, profile_continue); + + // Build the base (index * per_case_size_in_bytes()) + + // case_array_offset_in_bytes() + movl(reg2, in_bytes(MultiBranchData::per_case_size())); + imulptr(index, reg2); // XXX l ? + addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ? + + // Update the case count + increment_mdp_data_at(mdp, + index, + in_bytes(MultiBranchData::relative_count_offset())); + + // The method data pointer needs to be updated. + update_mdp_by_offset(mdp, + index, + in_bytes(MultiBranchData:: + relative_displacement_offset())); + + bind(profile_continue); + } +} + + + +void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) { + if (state == atos) { + MacroAssembler::verify_oop(reg); + } +} + +void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { +#ifndef _LP64 + if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth); +#endif +} + +// Jump if ((*counter_addr += increment) & mask) satisfies the condition. +void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, + int increment, Address mask, + Register scratch, bool preloaded, + Condition cond, Label* where) { + if (!preloaded) { + movl(scratch, counter_addr); + } + incrementl(scratch, increment); + movl(counter_addr, scratch); + andl(scratch, mask); + jcc(cond, *where); +} +#endif // CC_INTERP + +void InterpreterMacroAssembler::notify_method_entry() { + // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to + // track stack depth. If it is possible to enter interp_only_mode we add + // the code to check if the event should be sent. + Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx); + Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rbx); + if (JvmtiExport::can_post_interpreter_events()) { + Label L; + NOT_LP64(get_thread(rthread);) + movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset())); + testl(rdx, rdx); + jcc(Assembler::zero, L); + call_VM(noreg, CAST_FROM_FN_PTR(address, + InterpreterRuntime::post_method_entry)); + bind(L); + } + + { + SkipIfEqual skip(this, &DTraceMethodProbes, false); + NOT_LP64(get_thread(rthread);) + get_method(rarg); + call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), + rthread, rarg); + } + + // RedefineClasses() tracing support for obsolete method entry + if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) { + NOT_LP64(get_thread(rthread);) + get_method(rarg); + call_VM_leaf( + CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry), + rthread, rarg); + } +} + + +void InterpreterMacroAssembler::notify_method_exit( + TosState state, NotifyMethodExitMode mode) { + // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to + // track stack depth. If it is possible to enter interp_only_mode we add + // the code to check if the event should be sent. + Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx); + Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rbx); + if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { + Label L; + // Note: frame::interpreter_frame_result has a dependency on how the + // method result is saved across the call to post_method_exit. If this + // is changed then the interpreter_frame_result implementation will + // need to be updated too. + + // For c++ interpreter the result is always stored at a known location in the frame + // template interpreter will leave it on the top of the stack. + NOT_CC_INTERP(push(state);) + NOT_LP64(get_thread(rthread);) + movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset())); + testl(rdx, rdx); + jcc(Assembler::zero, L); + call_VM(noreg, + CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit)); + bind(L); + NOT_CC_INTERP(pop(state)); + } + + { + SkipIfEqual skip(this, &DTraceMethodProbes, false); + NOT_CC_INTERP(push(state)); + NOT_LP64(get_thread(rthread);) + get_method(rarg); + call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), + rthread, rarg); + NOT_CC_INTERP(pop(state)); + } +} diff --git a/hotspot/src/cpu/x86/vm/interp_masm_x86.hpp b/hotspot/src/cpu/x86/vm/interp_masm_x86.hpp index 2ac4d026654..a03f70d8bc3 100644 --- a/hotspot/src/cpu/x86/vm/interp_masm_x86.hpp +++ b/hotspot/src/cpu/x86/vm/interp_masm_x86.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -35,12 +35,254 @@ class InterpreterMacroAssembler: public MacroAssembler { -#ifdef TARGET_ARCH_MODEL_x86_32 -# include "interp_masm_x86_32.hpp" -#endif -#ifdef TARGET_ARCH_MODEL_x86_64 -# include "interp_masm_x86_64.hpp" -#endif +#ifndef CC_INTERP + protected: + // Interpreter specific version of call_VM_base + virtual void call_VM_leaf_base(address entry_point, + int number_of_arguments); + + virtual void call_VM_base(Register oop_result, + Register java_thread, + Register last_java_sp, + address entry_point, + int number_of_arguments, + bool check_exceptions); + + virtual void check_and_handle_popframe(Register java_thread); + virtual void check_and_handle_earlyret(Register java_thread); + + // base routine for all dispatches + void dispatch_base(TosState state, address* table, bool verifyoop = true); +#endif // CC_INTERP + + public: + InterpreterMacroAssembler(CodeBuffer* code) : MacroAssembler(code), + _locals_register(LP64_ONLY(r14) NOT_LP64(rdi)), + _bcp_register(LP64_ONLY(r13) NOT_LP64(rsi)) {} + + void load_earlyret_value(TosState state); + +#ifdef CC_INTERP + void save_bcp() { /* not needed in c++ interpreter and harmless */ } + void restore_bcp() { /* not needed in c++ interpreter and harmless */ } + + // Helpers for runtime call arguments/results + void get_method(Register reg); + +#else + + // Interpreter-specific registers + void save_bcp() { + movptr(Address(rbp, frame::interpreter_frame_bcp_offset * wordSize), _bcp_register); + } + + void restore_bcp() { + movptr(_bcp_register, Address(rbp, frame::interpreter_frame_bcp_offset * wordSize)); + } + + void restore_locals() { + movptr(_locals_register, Address(rbp, frame::interpreter_frame_locals_offset * wordSize)); + } + + // Helpers for runtime call arguments/results + void get_method(Register reg) { + movptr(reg, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); + } + + void get_const(Register reg) { + get_method(reg); + movptr(reg, Address(reg, Method::const_offset())); + } + + void get_constant_pool(Register reg) { + get_const(reg); + movptr(reg, Address(reg, ConstMethod::constants_offset())); + } + + void get_constant_pool_cache(Register reg) { + get_constant_pool(reg); + movptr(reg, Address(reg, ConstantPool::cache_offset_in_bytes())); + } + + void get_cpool_and_tags(Register cpool, Register tags) { + get_constant_pool(cpool); + movptr(tags, Address(cpool, ConstantPool::tags_offset_in_bytes())); + } + + void get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset); + void get_cache_and_index_at_bcp(Register cache, + Register index, + int bcp_offset, + size_t index_size = sizeof(u2)); + void get_cache_and_index_and_bytecode_at_bcp(Register cache, + Register index, + Register bytecode, + int byte_no, + int bcp_offset, + size_t index_size = sizeof(u2)); + void get_cache_entry_pointer_at_bcp(Register cache, + Register tmp, + int bcp_offset, + size_t index_size = sizeof(u2)); + void get_cache_index_at_bcp(Register index, + int bcp_offset, + size_t index_size = sizeof(u2)); + + // load cpool->resolved_references(index); + void load_resolved_reference_at_index(Register result, Register index); + + NOT_LP64(void f2ieee();) // truncate ftos to 32bits + NOT_LP64(void d2ieee();) // truncate dtos to 64bits + + // Expression stack + void pop_ptr(Register r = rax); + void pop_i(Register r = rax); + void push_ptr(Register r = rax); + void push_i(Register r = rax); + +#ifdef _LP64 + void pop_l(Register r = rax); + void pop_f(XMMRegister r = xmm0); + void pop_d(XMMRegister r = xmm0); + void push_l(Register r = rax); + void push_f(XMMRegister r = xmm0); + void push_d(XMMRegister r = xmm0); +#else + void pop_l(Register lo = rax, Register hi = rdx); + void pop_f(); + void pop_d(); + + void push_l(Register lo = rax, Register hi = rdx); + void push_d(Register r = rax); + void push_f(); +#endif // _LP64 + + void pop(Register r) { ((MacroAssembler*)this)->pop(r); } + void push(Register r) { ((MacroAssembler*)this)->push(r); } + void push(int32_t imm ) { ((MacroAssembler*)this)->push(imm); } + + void pop(TosState state); // transition vtos -> state + void push(TosState state); // transition state -> vtos + + // These are dummies to prevent surprise implicit conversions to Register + void pop(void* v); // Add unimplemented ambiguous method + void push(void* v); // Add unimplemented ambiguous method + + void empty_expression_stack() { + movptr(rsp, Address(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize)); + // NULL last_sp until next java call + movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); + } + + // Helpers for swap and dup + void load_ptr(int n, Register val); + void store_ptr(int n, Register val); + + // Generate a subtype check: branch to ok_is_subtype if sub_klass is + // a subtype of super_klass. + void gen_subtype_check( Register sub_klass, Label &ok_is_subtype ); + + // Dispatching + void dispatch_prolog(TosState state, int step = 0); + void dispatch_epilog(TosState state, int step = 0); + // dispatch via rbx (assume rbx is loaded already) + void dispatch_only(TosState state); + // dispatch normal table via rbx (assume rbx is loaded already) + void dispatch_only_normal(TosState state); + void dispatch_only_noverify(TosState state); + // load rbx from [_bcp_register + step] and dispatch via rbx + void dispatch_next(TosState state, int step = 0); + // load rbx from [_bcp_register] and dispatch via rbx and table + void dispatch_via (TosState state, address* table); + + // jump to an invoked target + void prepare_to_jump_from_interpreted(); + void jump_from_interpreted(Register method, Register temp); + + // Returning from interpreted functions + // + // Removes the current activation (incl. unlocking of monitors) + // and sets up the return address. This code is also used for + // exception unwindwing. In that case, we do not want to throw + // IllegalMonitorStateExceptions, since that might get us into an + // infinite rethrow exception loop. + // Additionally this code is used for popFrame and earlyReturn. + // In popFrame case we want to skip throwing an exception, + // installing an exception, and notifying jvmdi. + // In earlyReturn case we only want to skip throwing an exception + // and installing an exception. + void remove_activation(TosState state, Register ret_addr, + bool throw_monitor_exception = true, + bool install_monitor_exception = true, + bool notify_jvmdi = true); +#endif // CC_INTERP + void get_method_counters(Register method, Register mcs, Label& skip); + + // Object locking + void lock_object (Register lock_reg); + void unlock_object(Register lock_reg); + +#ifndef CC_INTERP + + // Interpreter profiling operations + void set_method_data_pointer_for_bcp(); + void test_method_data_pointer(Register mdp, Label& zero_continue); + void verify_method_data_pointer(); + + void set_mdp_data_at(Register mdp_in, int constant, Register value); + void increment_mdp_data_at(Address data, bool decrement = false); + void increment_mdp_data_at(Register mdp_in, int constant, + bool decrement = false); + void increment_mdp_data_at(Register mdp_in, Register reg, int constant, + bool decrement = false); + void increment_mask_and_jump(Address counter_addr, + int increment, Address mask, + Register scratch, bool preloaded, + Condition cond, Label* where); + void set_mdp_flag_at(Register mdp_in, int flag_constant); + void test_mdp_data_at(Register mdp_in, int offset, Register value, + Register test_value_out, + Label& not_equal_continue); + + void record_klass_in_profile(Register receiver, Register mdp, + Register reg2, bool is_virtual_call); + void record_klass_in_profile_helper(Register receiver, Register mdp, + Register reg2, int start_row, + Label& done, bool is_virtual_call); + + void update_mdp_by_offset(Register mdp_in, int offset_of_offset); + void update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp); + void update_mdp_by_constant(Register mdp_in, int constant); + void update_mdp_for_ret(Register return_bci); + + void profile_taken_branch(Register mdp, Register bumped_count); + void profile_not_taken_branch(Register mdp); + void profile_call(Register mdp); + void profile_final_call(Register mdp); + void profile_virtual_call(Register receiver, Register mdp, + Register scratch2, + bool receiver_can_be_null = false); + void profile_ret(Register return_bci, Register mdp); + void profile_null_seen(Register mdp); + void profile_typecheck(Register mdp, Register klass, Register scratch); + void profile_typecheck_failed(Register mdp); + void profile_switch_default(Register mdp); + void profile_switch_case(Register index_in_scratch, Register mdp, + Register scratch2); + + // Debugging + // only if +VerifyOops && state == atos + void verify_oop(Register reg, TosState state = atos); + // only if +VerifyFPU && (state == ftos || state == dtos) + void verify_FPU(int stack_depth, TosState state = ftos); + +#endif // !CC_INTERP + + typedef enum { NotifyJVMTI, SkipNotifyJVMTI } NotifyMethodExitMode; + + // support for jvmti/dtrace + void notify_method_entry(); + void notify_method_exit(TosState state, NotifyMethodExitMode mode); private: diff --git a/hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp b/hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp deleted file mode 100644 index 9aa4587f793..00000000000 --- a/hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp +++ /dev/null @@ -1,1444 +0,0 @@ -/* - * Copyright (c) 1997, 2014, 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. - * - * 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. - * - */ - -#include "precompiled.hpp" -#include "interp_masm_x86.hpp" -#include "interpreter/interpreter.hpp" -#include "interpreter/interpreterRuntime.hpp" -#include "oops/arrayOop.hpp" -#include "oops/markOop.hpp" -#include "oops/methodData.hpp" -#include "oops/method.hpp" -#include "prims/jvmtiExport.hpp" -#include "prims/jvmtiRedefineClassesTrace.hpp" -#include "prims/jvmtiThreadState.hpp" -#include "runtime/basicLock.hpp" -#include "runtime/biasedLocking.hpp" -#include "runtime/sharedRuntime.hpp" -#include "runtime/thread.inline.hpp" - - -// Implementation of InterpreterMacroAssembler -#ifdef CC_INTERP -void InterpreterMacroAssembler::get_method(Register reg) { - movptr(reg, Address(rbp, -(sizeof(BytecodeInterpreter) + 2 * wordSize))); - movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method))); -} -#endif // CC_INTERP - - -#ifndef CC_INTERP -void InterpreterMacroAssembler::call_VM_leaf_base( - address entry_point, - int number_of_arguments -) { - // interpreter specific - // - // Note: No need to save/restore bcp & locals (rsi & rdi) pointer - // since these are callee saved registers and no blocking/ - // GC can happen in leaf calls. - // Further Note: DO NOT save/restore bcp/locals. If a caller has - // already saved them so that it can use rsi/rdi as temporaries - // then a save/restore here will DESTROY the copy the caller - // saved! There used to be a save_bcp() that only happened in - // the ASSERT path (no restore_bcp). Which caused bizarre failures - // when jvm built with ASSERTs. -#ifdef ASSERT - { Label L; - cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); - jcc(Assembler::equal, L); - stop("InterpreterMacroAssembler::call_VM_leaf_base: last_sp != NULL"); - bind(L); - } -#endif - // super call - MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments); - // interpreter specific - - // Used to ASSERT that rsi/rdi were equal to frame's bcp/locals - // but since they may not have been saved (and we don't want to - // save them here (see note above) the assert is invalid. -} - - -void InterpreterMacroAssembler::call_VM_base( - Register oop_result, - Register java_thread, - Register last_java_sp, - address entry_point, - int number_of_arguments, - bool check_exceptions -) { -#ifdef ASSERT - { Label L; - cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); - jcc(Assembler::equal, L); - stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL"); - bind(L); - } -#endif /* ASSERT */ - // interpreter specific - // - // Note: Could avoid restoring locals ptr (callee saved) - however doesn't - // really make a difference for these runtime calls, since they are - // slow anyway. Btw., bcp must be saved/restored since it may change - // due to GC. - assert(java_thread == noreg , "not expecting a precomputed java thread"); - save_bcp(); - // super call - MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exceptions); - // interpreter specific - restore_bcp(); - restore_locals(); -} - - -void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) { - if (JvmtiExport::can_pop_frame()) { - Label L; - // Initiate popframe handling only if it is not already being processed. If the flag - // has the popframe_processing bit set, it means that this code is called *during* popframe - // handling - we don't want to reenter. - Register pop_cond = java_thread; // Not clear if any other register is available... - movl(pop_cond, Address(java_thread, JavaThread::popframe_condition_offset())); - testl(pop_cond, JavaThread::popframe_pending_bit); - jcc(Assembler::zero, L); - testl(pop_cond, JavaThread::popframe_processing_bit); - jcc(Assembler::notZero, L); - // Call Interpreter::remove_activation_preserving_args_entry() to get the - // address of the same-named entrypoint in the generated interpreter code. - call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); - jmp(rax); - bind(L); - get_thread(java_thread); - } -} - - -void InterpreterMacroAssembler::load_earlyret_value(TosState state) { - get_thread(rcx); - movl(rcx, Address(rcx, JavaThread::jvmti_thread_state_offset())); - const Address tos_addr (rcx, JvmtiThreadState::earlyret_tos_offset()); - const Address oop_addr (rcx, JvmtiThreadState::earlyret_oop_offset()); - const Address val_addr (rcx, JvmtiThreadState::earlyret_value_offset()); - const Address val_addr1(rcx, JvmtiThreadState::earlyret_value_offset() - + in_ByteSize(wordSize)); - switch (state) { - case atos: movptr(rax, oop_addr); - movptr(oop_addr, NULL_WORD); - verify_oop(rax, state); break; - case ltos: - movl(rdx, val_addr1); // fall through - case btos: // fall through - case ctos: // fall through - case stos: // fall through - case itos: movl(rax, val_addr); break; - case ftos: fld_s(val_addr); break; - case dtos: fld_d(val_addr); break; - case vtos: /* nothing to do */ break; - default : ShouldNotReachHere(); - } - // Clean up tos value in the thread object - movl(tos_addr, (int32_t) ilgl); - movptr(val_addr, NULL_WORD); - NOT_LP64(movptr(val_addr1, NULL_WORD)); -} - - -void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) { - if (JvmtiExport::can_force_early_return()) { - Label L; - Register tmp = java_thread; - movptr(tmp, Address(tmp, JavaThread::jvmti_thread_state_offset())); - testptr(tmp, tmp); - jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit; - - // Initiate earlyret handling only if it is not already being processed. - // If the flag has the earlyret_processing bit set, it means that this code - // is called *during* earlyret handling - we don't want to reenter. - movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset())); - cmpl(tmp, JvmtiThreadState::earlyret_pending); - jcc(Assembler::notEqual, L); - - // Call Interpreter::remove_activation_early_entry() to get the address of the - // same-named entrypoint in the generated interpreter code. - get_thread(java_thread); - movptr(tmp, Address(java_thread, JavaThread::jvmti_thread_state_offset())); - pushl(Address(tmp, JvmtiThreadState::earlyret_tos_offset())); - call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), 1); - jmp(rax); - bind(L); - get_thread(java_thread); - } -} - - -void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) { - assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode"); - load_unsigned_short(reg, Address(rsi, bcp_offset)); - bswapl(reg); - shrl(reg, 16); -} - - -void InterpreterMacroAssembler::get_cache_index_at_bcp(Register reg, int bcp_offset, size_t index_size) { - assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); - if (index_size == sizeof(u2)) { - load_unsigned_short(reg, Address(rsi, bcp_offset)); - } else if (index_size == sizeof(u4)) { - movl(reg, Address(rsi, bcp_offset)); - // Check if the secondary index definition is still ~x, otherwise - // we have to change the following assembler code to calculate the - // plain index. - assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line"); - notl(reg); // convert to plain index - } else if (index_size == sizeof(u1)) { - load_unsigned_byte(reg, Address(rsi, bcp_offset)); - } else { - ShouldNotReachHere(); - } -} - - -void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register index, - int bcp_offset, size_t index_size) { - assert_different_registers(cache, index); - get_cache_index_at_bcp(index, bcp_offset, index_size); - movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); - assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below"); - assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line"); - shlptr(index, 2); // convert from field index to ConstantPoolCacheEntry index -} - - -void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache, - Register index, - Register bytecode, - int byte_no, - int bcp_offset, - size_t index_size) { - get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size); - movptr(bytecode, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset())); - const int shift_count = (1 + byte_no) * BitsPerByte; - assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) || - (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift), - "correct shift count"); - shrptr(bytecode, shift_count); - assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask"); - andptr(bytecode, ConstantPoolCacheEntry::bytecode_1_mask); -} - - -void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, Register tmp, - int bcp_offset, size_t index_size) { - assert(cache != tmp, "must use different register"); - get_cache_index_at_bcp(tmp, bcp_offset, index_size); - assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below"); - // convert from field index to ConstantPoolCacheEntry index - // and from word offset to byte offset - assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line"); - shll(tmp, 2 + LogBytesPerWord); - movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); - // skip past the header - addptr(cache, in_bytes(ConstantPoolCache::base_offset())); - addptr(cache, tmp); // construct pointer to cache entry -} - -// Load object from cpool->resolved_references(index) -void InterpreterMacroAssembler::load_resolved_reference_at_index( - Register result, Register index) { - assert_different_registers(result, index); - // convert from field index to resolved_references() index and from - // word index to byte offset. Since this is a java object, it can be compressed - Register tmp = index; // reuse - shll(tmp, LogBytesPerHeapOop); - - get_constant_pool(result); - // load pointer for resolved_references[] objArray - movptr(result, Address(result, ConstantPool::resolved_references_offset_in_bytes())); - // JNIHandles::resolve(obj); - movptr(result, Address(result, 0)); - // Add in the index - addptr(result, tmp); - load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT))); -} - - // Generate a subtype check: branch to ok_is_subtype if sub_klass is - // a subtype of super_klass. EAX holds the super_klass. Blows ECX. - // Resets EDI to locals. Register sub_klass cannot be any of the above. -void InterpreterMacroAssembler::gen_subtype_check( Register Rsub_klass, Label &ok_is_subtype ) { - assert( Rsub_klass != rax, "rax, holds superklass" ); - assert( Rsub_klass != rcx, "used as a temp" ); - assert( Rsub_klass != rdi, "used as a temp, restored from locals" ); - - // Profile the not-null value's klass. - profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi - - // Do the check. - check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx - - // Profile the failure of the check. - profile_typecheck_failed(rcx); // blows rcx -} - -void InterpreterMacroAssembler::f2ieee() { - if (IEEEPrecision) { - fstp_s(Address(rsp, 0)); - fld_s(Address(rsp, 0)); - } -} - - -void InterpreterMacroAssembler::d2ieee() { - if (IEEEPrecision) { - fstp_d(Address(rsp, 0)); - fld_d(Address(rsp, 0)); - } -} - -// Java Expression Stack - -void InterpreterMacroAssembler::pop_ptr(Register r) { - pop(r); -} - -void InterpreterMacroAssembler::pop_i(Register r) { - pop(r); -} - -void InterpreterMacroAssembler::pop_l(Register lo, Register hi) { - pop(lo); - pop(hi); -} - -void InterpreterMacroAssembler::pop_f() { - fld_s(Address(rsp, 0)); - addptr(rsp, 1 * wordSize); -} - -void InterpreterMacroAssembler::pop_d() { - fld_d(Address(rsp, 0)); - addptr(rsp, 2 * wordSize); -} - - -void InterpreterMacroAssembler::pop(TosState state) { - switch (state) { - case atos: pop_ptr(rax); break; - case btos: // fall through - case ctos: // fall through - case stos: // fall through - case itos: pop_i(rax); break; - case ltos: pop_l(rax, rdx); break; - case ftos: pop_f(); break; - case dtos: pop_d(); break; - case vtos: /* nothing to do */ break; - default : ShouldNotReachHere(); - } - verify_oop(rax, state); -} - -void InterpreterMacroAssembler::push_ptr(Register r) { - push(r); -} - -void InterpreterMacroAssembler::push_i(Register r) { - push(r); -} - -void InterpreterMacroAssembler::push_l(Register lo, Register hi) { - push(hi); - push(lo); -} - -void InterpreterMacroAssembler::push_f() { - // Do not schedule for no AGI! Never write beyond rsp! - subptr(rsp, 1 * wordSize); - fstp_s(Address(rsp, 0)); -} - -void InterpreterMacroAssembler::push_d(Register r) { - // Do not schedule for no AGI! Never write beyond rsp! - subptr(rsp, 2 * wordSize); - fstp_d(Address(rsp, 0)); -} - - -void InterpreterMacroAssembler::push(TosState state) { - verify_oop(rax, state); - switch (state) { - case atos: push_ptr(rax); break; - case btos: // fall through - case ctos: // fall through - case stos: // fall through - case itos: push_i(rax); break; - case ltos: push_l(rax, rdx); break; - case ftos: push_f(); break; - case dtos: push_d(rax); break; - case vtos: /* nothing to do */ break; - default : ShouldNotReachHere(); - } -} - - -// Helpers for swap and dup -void InterpreterMacroAssembler::load_ptr(int n, Register val) { - movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n))); -} - -void InterpreterMacroAssembler::store_ptr(int n, Register val) { - movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val); -} - -void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() { - // set sender sp - lea(rsi, Address(rsp, wordSize)); - // record last_sp - movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), rsi); -} - - -// Jump to from_interpreted entry of a call unless single stepping is possible -// in this thread in which case we must call the i2i entry -void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) { - prepare_to_jump_from_interpreted(); - - if (JvmtiExport::can_post_interpreter_events()) { - Label run_compiled_code; - // JVMTI events, such as single-stepping, are implemented partly by avoiding running - // compiled code in threads for which the event is enabled. Check here for - // interp_only_mode if these events CAN be enabled. - get_thread(temp); - // interp_only is an int, on little endian it is sufficient to test the byte only - // Is a cmpl faster? - cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0); - jccb(Assembler::zero, run_compiled_code); - jmp(Address(method, Method::interpreter_entry_offset())); - bind(run_compiled_code); - } - - jmp(Address(method, Method::from_interpreted_offset())); - -} - - -// The following two routines provide a hook so that an implementation -// can schedule the dispatch in two parts. Intel does not do this. -void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) { - // Nothing Intel-specific to be done here. -} - -void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) { - dispatch_next(state, step); -} - -void InterpreterMacroAssembler::dispatch_base(TosState state, address* table, - bool verifyoop) { - verify_FPU(1, state); - if (VerifyActivationFrameSize) { - Label L; - mov(rcx, rbp); - subptr(rcx, rsp); - int min_frame_size = (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * wordSize; - cmpptr(rcx, min_frame_size); - jcc(Assembler::greaterEqual, L); - stop("broken stack frame"); - bind(L); - } - if (verifyoop) verify_oop(rax, state); - Address index(noreg, rbx, Address::times_ptr); - ExternalAddress tbl((address)table); - ArrayAddress dispatch(tbl, index); - jump(dispatch); -} - - -void InterpreterMacroAssembler::dispatch_only(TosState state) { - dispatch_base(state, Interpreter::dispatch_table(state)); -} - - -void InterpreterMacroAssembler::dispatch_only_normal(TosState state) { - dispatch_base(state, Interpreter::normal_table(state)); -} - -void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) { - dispatch_base(state, Interpreter::normal_table(state), false); -} - - -void InterpreterMacroAssembler::dispatch_next(TosState state, int step) { - // load next bytecode (load before advancing rsi to prevent AGI) - load_unsigned_byte(rbx, Address(rsi, step)); - // advance rsi - increment(rsi, step); - dispatch_base(state, Interpreter::dispatch_table(state)); -} - - -void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { - // load current bytecode - load_unsigned_byte(rbx, Address(rsi, 0)); - dispatch_base(state, table); -} - -// remove activation -// -// Unlock the receiver if this is a synchronized method. -// Unlock any Java monitors from syncronized blocks. -// Remove the activation from the stack. -// -// If there are locked Java monitors -// If throw_monitor_exception -// throws IllegalMonitorStateException -// Else if install_monitor_exception -// installs IllegalMonitorStateException -// Else -// no error processing -void InterpreterMacroAssembler::remove_activation(TosState state, Register ret_addr, - bool throw_monitor_exception, - bool install_monitor_exception, - bool notify_jvmdi) { - // Note: Registers rax, rdx and FPU ST(0) may be in use for the result - // check if synchronized method - Label unlocked, unlock, no_unlock; - - get_thread(rcx); - const Address do_not_unlock_if_synchronized(rcx, - in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); - - movbool(rbx, do_not_unlock_if_synchronized); - mov(rdi,rbx); - movbool(do_not_unlock_if_synchronized, false); // reset the flag - - movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); // get method access flags - movl(rcx, Address(rbx, Method::access_flags_offset())); - - testl(rcx, JVM_ACC_SYNCHRONIZED); - jcc(Assembler::zero, unlocked); - - // Don't unlock anything if the _do_not_unlock_if_synchronized flag - // is set. - mov(rcx,rdi); - testbool(rcx); - jcc(Assembler::notZero, no_unlock); - - // unlock monitor - push(state); // save result - - // BasicObjectLock will be first in list, since this is a synchronized method. However, need - // to check that the object has not been unlocked by an explicit monitorexit bytecode. - const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock)); - lea (rdx, monitor); // address of first monitor - - movptr (rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes())); - testptr(rax, rax); - jcc (Assembler::notZero, unlock); - - pop(state); - if (throw_monitor_exception) { - empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow - - // Entry already unlocked, need to throw exception - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); - should_not_reach_here(); - } else { - // Monitor already unlocked during a stack unroll. - // If requested, install an illegal_monitor_state_exception. - // Continue with stack unrolling. - if (install_monitor_exception) { - empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); - } - jmp(unlocked); - } - - bind(unlock); - unlock_object(rdx); - pop(state); - - // Check that for block-structured locking (i.e., that all locked objects has been unlocked) - bind(unlocked); - - // rax, rdx: Might contain return value - - // Check that all monitors are unlocked - { - Label loop, exception, entry, restart; - const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; - const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); - const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize); - - bind(restart); - movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry - lea(rbx, monitor_block_bot); // points to word before bottom of monitor block - jmp(entry); - - // Entry already locked, need to throw exception - bind(exception); - - if (throw_monitor_exception) { - empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow - - // Throw exception - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); - should_not_reach_here(); - } else { - // Stack unrolling. Unlock object and install illegal_monitor_exception - // Unlock does not block, so don't have to worry about the frame - - push(state); - mov(rdx, rcx); - unlock_object(rdx); - pop(state); - - if (install_monitor_exception) { - empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); - } - - jmp(restart); - } - - bind(loop); - cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); // check if current entry is used - jcc(Assembler::notEqual, exception); - - addptr(rcx, entry_size); // otherwise advance to next entry - bind(entry); - cmpptr(rcx, rbx); // check if bottom reached - jcc(Assembler::notEqual, loop); // if not at bottom then check this entry - } - - bind(no_unlock); - - // jvmti support - if (notify_jvmdi) { - notify_method_exit(state, NotifyJVMTI); // preserve TOSCA - } else { - notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA - } - - // remove activation - movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp - leave(); // remove frame anchor - pop(ret_addr); // get return address - mov(rsp, rbx); // set sp to sender sp - if (UseSSE) { - // float and double are returned in xmm register in SSE-mode - if (state == ftos && UseSSE >= 1) { - subptr(rsp, wordSize); - fstp_s(Address(rsp, 0)); - movflt(xmm0, Address(rsp, 0)); - addptr(rsp, wordSize); - } else if (state == dtos && UseSSE >= 2) { - subptr(rsp, 2*wordSize); - fstp_d(Address(rsp, 0)); - movdbl(xmm0, Address(rsp, 0)); - addptr(rsp, 2*wordSize); - } - } -} - -#endif /* !CC_INTERP */ - -void InterpreterMacroAssembler::get_method_counters(Register method, - Register mcs, Label& skip) { - Label has_counters; - movptr(mcs, Address(method, Method::method_counters_offset())); - testptr(mcs, mcs); - jcc(Assembler::notZero, has_counters); - call_VM(noreg, CAST_FROM_FN_PTR(address, - InterpreterRuntime::build_method_counters), method); - movptr(mcs, Address(method,Method::method_counters_offset())); - testptr(mcs, mcs); - jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory - bind(has_counters); -} - - -// Lock object -// -// Argument: rdx : Points to BasicObjectLock to be used for locking. Must -// be initialized with object to lock -void InterpreterMacroAssembler::lock_object(Register lock_reg) { - assert(lock_reg == rdx, "The argument is only for looks. It must be rdx"); - - if (UseHeavyMonitors) { - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg); - } else { - - Label done; - - const Register swap_reg = rax; // Must use rax, for cmpxchg instruction - const Register obj_reg = rcx; // Will contain the oop - - const int obj_offset = BasicObjectLock::obj_offset_in_bytes(); - const int lock_offset = BasicObjectLock::lock_offset_in_bytes (); - const int mark_offset = lock_offset + BasicLock::displaced_header_offset_in_bytes(); - - Label slow_case; - - // Load object pointer into obj_reg %rcx - movptr(obj_reg, Address(lock_reg, obj_offset)); - - if (UseBiasedLocking) { - // Note: we use noreg for the temporary register since it's hard - // to come up with a free register on all incoming code paths - biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case); - } - - // Load immediate 1 into swap_reg %rax, - movptr(swap_reg, (int32_t)1); - - // Load (object->mark() | 1) into swap_reg %rax, - orptr(swap_reg, Address(obj_reg, 0)); - - // Save (object->mark() | 1) into BasicLock's displaced header - movptr(Address(lock_reg, mark_offset), swap_reg); - - assert(lock_offset == 0, "displached header must be first word in BasicObjectLock"); - if (os::is_MP()) { - lock(); - } - cmpxchgptr(lock_reg, Address(obj_reg, 0)); - if (PrintBiasedLockingStatistics) { - cond_inc32(Assembler::zero, - ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); - } - jcc(Assembler::zero, done); - - // Test if the oopMark is an obvious stack pointer, i.e., - // 1) (mark & 3) == 0, and - // 2) rsp <= mark < mark + os::pagesize() - // - // These 3 tests can be done by evaluating the following - // expression: ((mark - rsp) & (3 - os::vm_page_size())), - // assuming both stack pointer and pagesize have their - // least significant 2 bits clear. - // NOTE: the oopMark is in swap_reg %rax, as the result of cmpxchg - subptr(swap_reg, rsp); - andptr(swap_reg, 3 - os::vm_page_size()); - - // Save the test result, for recursive case, the result is zero - movptr(Address(lock_reg, mark_offset), swap_reg); - - if (PrintBiasedLockingStatistics) { - cond_inc32(Assembler::zero, - ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); - } - jcc(Assembler::zero, done); - - bind(slow_case); - - // Call the runtime routine for slow case - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg); - - bind(done); - } -} - - -// Unlocks an object. Used in monitorexit bytecode and remove_activation. -// -// Argument: rdx : Points to BasicObjectLock structure for lock -// Throw an IllegalMonitorException if object is not locked by current thread -// -// Uses: rax, rbx, rcx, rdx -void InterpreterMacroAssembler::unlock_object(Register lock_reg) { - assert(lock_reg == rdx, "The argument is only for looks. It must be rdx"); - - if (UseHeavyMonitors) { - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); - } else { - Label done; - - const Register swap_reg = rax; // Must use rax, for cmpxchg instruction - const Register header_reg = rbx; // Will contain the old oopMark - const Register obj_reg = rcx; // Will contain the oop - - save_bcp(); // Save in case of exception - - // Convert from BasicObjectLock structure to object and BasicLock structure - // Store the BasicLock address into %rax, - lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes())); - - // Load oop into obj_reg(%rcx) - movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes ())); - - // Free entry - movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), NULL_WORD); - - if (UseBiasedLocking) { - biased_locking_exit(obj_reg, header_reg, done); - } - - // Load the old header from BasicLock structure - movptr(header_reg, Address(swap_reg, BasicLock::displaced_header_offset_in_bytes())); - - // Test for recursion - testptr(header_reg, header_reg); - - // zero for recursive case - jcc(Assembler::zero, done); - - // Atomic swap back the old header - if (os::is_MP()) lock(); - cmpxchgptr(header_reg, Address(obj_reg, 0)); - - // zero for recursive case - jcc(Assembler::zero, done); - - // Call the runtime routine for slow case. - movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); - - bind(done); - - restore_bcp(); - } -} - - -#ifndef CC_INTERP - -// Test ImethodDataPtr. If it is null, continue at the specified label -void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, Label& zero_continue) { - assert(ProfileInterpreter, "must be profiling interpreter"); - movptr(mdp, Address(rbp, frame::interpreter_frame_mdp_offset * wordSize)); - testptr(mdp, mdp); - jcc(Assembler::zero, zero_continue); -} - - -// Set the method data pointer for the current bcp. -void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { - assert(ProfileInterpreter, "must be profiling interpreter"); - Label set_mdp; - push(rax); - push(rbx); - - get_method(rbx); - // Test MDO to avoid the call if it is NULL. - movptr(rax, Address(rbx, in_bytes(Method::method_data_offset()))); - testptr(rax, rax); - jcc(Assembler::zero, set_mdp); - // rbx,: method - // rsi: bcp - call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, rsi); - // rax,: mdi - // mdo is guaranteed to be non-zero here, we checked for it before the call. - movptr(rbx, Address(rbx, in_bytes(Method::method_data_offset()))); - addptr(rbx, in_bytes(MethodData::data_offset())); - addptr(rax, rbx); - bind(set_mdp); - movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), rax); - pop(rbx); - pop(rax); -} - -void InterpreterMacroAssembler::verify_method_data_pointer() { - assert(ProfileInterpreter, "must be profiling interpreter"); -#ifdef ASSERT - Label verify_continue; - push(rax); - push(rbx); - push(rcx); - push(rdx); - test_method_data_pointer(rcx, verify_continue); // If mdp is zero, continue - get_method(rbx); - - // If the mdp is valid, it will point to a DataLayout header which is - // consistent with the bcp. The converse is highly probable also. - load_unsigned_short(rdx, Address(rcx, in_bytes(DataLayout::bci_offset()))); - addptr(rdx, Address(rbx, Method::const_offset())); - lea(rdx, Address(rdx, ConstMethod::codes_offset())); - cmpptr(rdx, rsi); - jcc(Assembler::equal, verify_continue); - // rbx,: method - // rsi: bcp - // rcx: mdp - call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), rbx, rsi, rcx); - bind(verify_continue); - pop(rdx); - pop(rcx); - pop(rbx); - pop(rax); -#endif // ASSERT -} - - -void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, int constant, Register value) { - // %%% this seems to be used to store counter data which is surely 32bits - // however 64bit side stores 64 bits which seems wrong - assert(ProfileInterpreter, "must be profiling interpreter"); - Address data(mdp_in, constant); - movptr(data, value); -} - - -void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, - int constant, - bool decrement) { - // Counter address - Address data(mdp_in, constant); - - increment_mdp_data_at(data, decrement); -} - - -void InterpreterMacroAssembler::increment_mdp_data_at(Address data, - bool decrement) { - - assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" ); - assert(ProfileInterpreter, "must be profiling interpreter"); - - // %%% 64bit treats this as 64 bit which seems unlikely - if (decrement) { - // Decrement the register. Set condition codes. - addl(data, -DataLayout::counter_increment); - // If the decrement causes the counter to overflow, stay negative - Label L; - jcc(Assembler::negative, L); - addl(data, DataLayout::counter_increment); - bind(L); - } else { - assert(DataLayout::counter_increment == 1, - "flow-free idiom only works with 1"); - // Increment the register. Set carry flag. - addl(data, DataLayout::counter_increment); - // If the increment causes the counter to overflow, pull back by 1. - sbbl(data, 0); - } -} - - -void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, - Register reg, - int constant, - bool decrement) { - Address data(mdp_in, reg, Address::times_1, constant); - - increment_mdp_data_at(data, decrement); -} - - -void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, int flag_byte_constant) { - assert(ProfileInterpreter, "must be profiling interpreter"); - int header_offset = in_bytes(DataLayout::header_offset()); - int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant); - // Set the flag - orl(Address(mdp_in, header_offset), header_bits); -} - - - -void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in, - int offset, - Register value, - Register test_value_out, - Label& not_equal_continue) { - assert(ProfileInterpreter, "must be profiling interpreter"); - if (test_value_out == noreg) { - cmpptr(value, Address(mdp_in, offset)); - } else { - // Put the test value into a register, so caller can use it: - movptr(test_value_out, Address(mdp_in, offset)); - cmpptr(test_value_out, value); - } - jcc(Assembler::notEqual, not_equal_continue); -} - - -void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, int offset_of_disp) { - assert(ProfileInterpreter, "must be profiling interpreter"); - Address disp_address(mdp_in, offset_of_disp); - addptr(mdp_in,disp_address); - movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); -} - - -void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp) { - assert(ProfileInterpreter, "must be profiling interpreter"); - Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp); - addptr(mdp_in, disp_address); - movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); -} - - -void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, int constant) { - assert(ProfileInterpreter, "must be profiling interpreter"); - addptr(mdp_in, constant); - movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); -} - - -void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) { - assert(ProfileInterpreter, "must be profiling interpreter"); - push(return_bci); // save/restore across call_VM - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci); - pop(return_bci); -} - - -void InterpreterMacroAssembler::profile_taken_branch(Register mdp, Register bumped_count) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - // Otherwise, assign to mdp - test_method_data_pointer(mdp, profile_continue); - - // We are taking a branch. Increment the taken count. - // We inline increment_mdp_data_at to return bumped_count in a register - //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); - Address data(mdp, in_bytes(JumpData::taken_offset())); - - // %%% 64bit treats these cells as 64 bit but they seem to be 32 bit - movl(bumped_count,data); - assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" ); - addl(bumped_count, DataLayout::counter_increment); - sbbl(bumped_count, 0); - movl(data,bumped_count); // Store back out - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset())); - bind (profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // We are taking a branch. Increment the not taken count. - increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset())); - - // The method data pointer needs to be updated to correspond to the next bytecode - update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size())); - bind (profile_continue); - } -} - -void InterpreterMacroAssembler::profile_call(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // We are making a call. Increment the count. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size())); - bind (profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_final_call(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // We are making a call. Increment the count. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size())); - bind (profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_virtual_call(Register receiver, Register mdp, - Register reg2, - bool receiver_can_be_null) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - Label skip_receiver_profile; - if (receiver_can_be_null) { - Label not_null; - testptr(receiver, receiver); - jccb(Assembler::notZero, not_null); - // We are making a call. Increment the count for null receiver. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - jmp(skip_receiver_profile); - bind(not_null); - } - - // Record the receiver type. - record_klass_in_profile(receiver, mdp, reg2, true); - bind(skip_receiver_profile); - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_constant(mdp, - in_bytes(VirtualCallData:: - virtual_call_data_size())); - bind(profile_continue); - } -} - - -void InterpreterMacroAssembler::record_klass_in_profile_helper( - Register receiver, Register mdp, - Register reg2, int start_row, - Label& done, bool is_virtual_call) { - if (TypeProfileWidth == 0) { - if (is_virtual_call) { - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - } - return; - } - - int last_row = VirtualCallData::row_limit() - 1; - assert(start_row <= last_row, "must be work left to do"); - // Test this row for both the receiver and for null. - // Take any of three different outcomes: - // 1. found receiver => increment count and goto done - // 2. found null => keep looking for case 1, maybe allocate this cell - // 3. found something else => keep looking for cases 1 and 2 - // Case 3 is handled by a recursive call. - for (int row = start_row; row <= last_row; row++) { - Label next_test; - bool test_for_null_also = (row == start_row); - - // See if the receiver is receiver[n]. - int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row)); - test_mdp_data_at(mdp, recvr_offset, receiver, - (test_for_null_also ? reg2 : noreg), - next_test); - // (Reg2 now contains the receiver from the CallData.) - - // The receiver is receiver[n]. Increment count[n]. - int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row)); - increment_mdp_data_at(mdp, count_offset); - jmp(done); - bind(next_test); - - if (row == start_row) { - Label found_null; - // Failed the equality check on receiver[n]... Test for null. - testptr(reg2, reg2); - if (start_row == last_row) { - // The only thing left to do is handle the null case. - if (is_virtual_call) { - jccb(Assembler::zero, found_null); - // Receiver did not match any saved receiver and there is no empty row for it. - // Increment total counter to indicate polymorphic case. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - jmp(done); - bind(found_null); - } else { - jcc(Assembler::notZero, done); - } - break; - } - // Since null is rare, make it be the branch-taken case. - jcc(Assembler::zero, found_null); - - // Put all the "Case 3" tests here. - record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call); - - // Found a null. Keep searching for a matching receiver, - // but remember that this is an empty (unused) slot. - bind(found_null); - } - } - - // In the fall-through case, we found no matching receiver, but we - // observed the receiver[start_row] is NULL. - - // Fill in the receiver field and increment the count. - int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row)); - set_mdp_data_at(mdp, recvr_offset, receiver); - int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row)); - movptr(reg2, (intptr_t)DataLayout::counter_increment); - set_mdp_data_at(mdp, count_offset, reg2); - if (start_row > 0) { - jmp(done); - } -} - -void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, - Register mdp, Register reg2, - bool is_virtual_call) { - assert(ProfileInterpreter, "must be profiling"); - Label done; - - record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call); - - bind (done); -} - -void InterpreterMacroAssembler::profile_ret(Register return_bci, Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - uint row; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // Update the total ret count. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - - for (row = 0; row < RetData::row_limit(); row++) { - Label next_test; - - // See if return_bci is equal to bci[n]: - test_mdp_data_at(mdp, in_bytes(RetData::bci_offset(row)), return_bci, - noreg, next_test); - - // return_bci is equal to bci[n]. Increment the count. - increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row))); - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_offset(mdp, in_bytes(RetData::bci_displacement_offset(row))); - jmp(profile_continue); - bind(next_test); - } - - update_mdp_for_ret(return_bci); - - bind (profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_null_seen(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - set_mdp_flag_at(mdp, BitData::null_seen_byte_constant()); - - // The method data pointer needs to be updated. - int mdp_delta = in_bytes(BitData::bit_data_size()); - if (TypeProfileCasts) { - mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); - } - update_mdp_by_constant(mdp, mdp_delta); - - bind (profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) { - if (ProfileInterpreter && TypeProfileCasts) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - int count_offset = in_bytes(CounterData::count_offset()); - // Back up the address, since we have already bumped the mdp. - count_offset -= in_bytes(VirtualCallData::virtual_call_data_size()); - - // *Decrement* the counter. We expect to see zero or small negatives. - increment_mdp_data_at(mdp, count_offset, true); - - bind (profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) -{ - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // The method data pointer needs to be updated. - int mdp_delta = in_bytes(BitData::bit_data_size()); - if (TypeProfileCasts) { - mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); - - // Record the object type. - record_klass_in_profile(klass, mdp, reg2, false); - assert(reg2 == rdi, "we know how to fix this blown reg"); - restore_locals(); // Restore EDI - } - update_mdp_by_constant(mdp, mdp_delta); - - bind(profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_switch_default(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // Update the default case count - increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset())); - - // The method data pointer needs to be updated. - update_mdp_by_offset(mdp, in_bytes(MultiBranchData::default_displacement_offset())); - - bind (profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_switch_case(Register index, Register mdp, Register reg2) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes() - movptr(reg2, (intptr_t)in_bytes(MultiBranchData::per_case_size())); - // index is positive and so should have correct value if this code were - // used on 64bits - imulptr(index, reg2); - addptr(index, in_bytes(MultiBranchData::case_array_offset())); - - // Update the case count - increment_mdp_data_at(mdp, index, in_bytes(MultiBranchData::relative_count_offset())); - - // The method data pointer needs to be updated. - update_mdp_by_offset(mdp, index, in_bytes(MultiBranchData::relative_displacement_offset())); - - bind (profile_continue); - } -} - -#endif // !CC_INTERP - - - -void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) { - if (state == atos) MacroAssembler::verify_oop(reg); -} - - -#ifndef CC_INTERP -void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { - if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth); -} - -// Jump if ((*counter_addr += increment) & mask) satisfies the condition. -void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, - int increment, Address mask, - Register scratch, bool preloaded, - Condition cond, Label* where) { - if (!preloaded) { - movl(scratch, counter_addr); - } - incrementl(scratch, increment); - movl(counter_addr, scratch); - andl(scratch, mask); - jcc(cond, *where); -} -#endif /* CC_INTERP */ - - -void InterpreterMacroAssembler::notify_method_entry() { - // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to - // track stack depth. If it is possible to enter interp_only_mode we add - // the code to check if the event should be sent. - if (JvmtiExport::can_post_interpreter_events()) { - Label L; - get_thread(rcx); - movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset())); - testl(rcx,rcx); - jcc(Assembler::zero, L); - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry)); - bind(L); - } - - { - SkipIfEqual skip_if(this, &DTraceMethodProbes, 0); - get_thread(rcx); - get_method(rbx); - call_VM_leaf( - CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), rcx, rbx); - } - - // RedefineClasses() tracing support for obsolete method entry - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) { - get_thread(rcx); - get_method(rbx); - call_VM_leaf( - CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry), - rcx, rbx); - } -} - - -void InterpreterMacroAssembler::notify_method_exit( - TosState state, NotifyMethodExitMode mode) { - // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to - // track stack depth. If it is possible to enter interp_only_mode we add - // the code to check if the event should be sent. - if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { - Label L; - // Note: frame::interpreter_frame_result has a dependency on how the - // method result is saved across the call to post_method_exit. If this - // is changed then the interpreter_frame_result implementation will - // need to be updated too. - - // For c++ interpreter the result is always stored at a known location in the frame - // template interpreter will leave it on the top of the stack. - NOT_CC_INTERP(push(state);) - get_thread(rcx); - movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset())); - testl(rcx,rcx); - jcc(Assembler::zero, L); - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit)); - bind(L); - NOT_CC_INTERP(pop(state);) - } - - { - SkipIfEqual skip_if(this, &DTraceMethodProbes, 0); - NOT_CC_INTERP(push(state)); - get_thread(rbx); - get_method(rcx); - call_VM_leaf( - CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), - rbx, rcx); - NOT_CC_INTERP(pop(state)); - } -} diff --git a/hotspot/src/cpu/x86/vm/interp_masm_x86_32.hpp b/hotspot/src/cpu/x86/vm/interp_masm_x86_32.hpp deleted file mode 100644 index 2cd8e162fde..00000000000 --- a/hotspot/src/cpu/x86/vm/interp_masm_x86_32.hpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 1997, 2014, 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. - * - * 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. - * - */ - -#ifndef CC_INTERP - protected: - // Interpreter specific version of call_VM_base - virtual void call_VM_leaf_base( - address entry_point, - int number_of_arguments - ); - - virtual void call_VM_base( - Register oop_result, - Register java_thread, - Register last_java_sp, - address entry_point, - int number_of_arguments, - bool check_exceptions - ); - - virtual void check_and_handle_popframe(Register java_thread); - virtual void check_and_handle_earlyret(Register java_thread); - - // base routine for all dispatches - void dispatch_base(TosState state, address* table, bool verifyoop = true); -#endif /* CC_INTERP */ - - public: - InterpreterMacroAssembler(CodeBuffer* code) : MacroAssembler(code), _locals_register(rdi), _bcp_register(rsi) {} - - void load_earlyret_value(TosState state); - - // Interpreter-specific registers -#ifdef CC_INTERP - void save_bcp() { /* not needed in c++ interpreter and harmless */ } - void restore_bcp() { /* not needed in c++ interpreter and harmless */ } - - // Helpers for runtime call arguments/results - void get_method(Register reg); - -#else - - void save_bcp() { movptr(Address(rbp, frame::interpreter_frame_bcp_offset * wordSize), rsi); } - void restore_bcp() { movptr(rsi, Address(rbp, frame::interpreter_frame_bcp_offset * wordSize)); } - void restore_locals() { movptr(rdi, Address(rbp, frame::interpreter_frame_locals_offset * wordSize)); } - - // Helpers for runtime call arguments/results - void get_method(Register reg) { movptr(reg, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); } - void get_const(Register reg) { get_method(reg); movptr(reg, Address(reg, Method::const_offset())); } - void get_constant_pool(Register reg) { get_const(reg); movptr(reg, Address(reg, ConstMethod::constants_offset())); } - void get_constant_pool_cache(Register reg) { get_constant_pool(reg); movptr(reg, Address(reg, ConstantPool::cache_offset_in_bytes())); } - void get_cpool_and_tags(Register cpool, Register tags) { get_constant_pool(cpool); movptr(tags, Address(cpool, ConstantPool::tags_offset_in_bytes())); - } - void get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset); - void get_cache_and_index_at_bcp(Register cache, Register index, int bcp_offset, size_t index_size = sizeof(u2)); - void get_cache_and_index_and_bytecode_at_bcp(Register cache, Register index, Register bytecode, int byte_no, int bcp_offset, size_t index_size = sizeof(u2)); - void get_cache_entry_pointer_at_bcp(Register cache, Register tmp, int bcp_offset, size_t index_size = sizeof(u2)); - void get_cache_index_at_bcp(Register index, int bcp_offset, size_t index_size = sizeof(u2)); - - // load cpool->resolved_references(index); - void load_resolved_reference_at_index(Register result, Register index); - - // Expression stack - void f2ieee(); // truncate ftos to 32bits - void d2ieee(); // truncate dtos to 64bits - - void pop_ptr(Register r = rax); - void pop_i(Register r = rax); - void pop_l(Register lo = rax, Register hi = rdx); - void pop_f(); - void pop_d(); - - void push_ptr(Register r = rax); - void push_i(Register r = rax); - void push_l(Register lo = rax, Register hi = rdx); - void push_d(Register r = rax); - void push_f(); - - void pop(TosState state); // transition vtos -> state - void push(TosState state); // transition state -> vtos - - void pop(Register r ) { ((MacroAssembler*)this)->pop(r); } - - void push(Register r ) { ((MacroAssembler*)this)->push(r); } - void push(int32_t imm ) { ((MacroAssembler*)this)->push(imm); } - - // These are dummies to prevent surprise implicit conversions to Register - void pop(void* v ); // Add unimplemented ambiguous method - void push(void* v ); // Add unimplemented ambiguous method - - void empty_expression_stack() { - movptr(rsp, Address(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize)); - // NULL last_sp until next java call - movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD); - } - - // Helpers for swap and dup - void load_ptr(int n, Register val); - void store_ptr(int n, Register val); - - // Generate a subtype check: branch to ok_is_subtype if sub_klass is - // a subtype of super_klass. EAX holds the super_klass. Blows ECX - // and EDI. Register sub_klass cannot be any of the above. - void gen_subtype_check( Register sub_klass, Label &ok_is_subtype ); - - // Dispatching - void dispatch_prolog(TosState state, int step = 0); - void dispatch_epilog(TosState state, int step = 0); - void dispatch_only(TosState state); // dispatch via rbx, (assume rbx, is loaded already) - void dispatch_only_normal(TosState state); // dispatch normal table via rbx, (assume rbx, is loaded already) - void dispatch_only_noverify(TosState state); - void dispatch_next(TosState state, int step = 0); // load rbx, from [esi + step] and dispatch via rbx, - void dispatch_via (TosState state, address* table); // load rbx, from [esi] and dispatch via rbx, and table - - - // jump to an invoked target - void prepare_to_jump_from_interpreted(); - void jump_from_interpreted(Register method, Register temp); - - // Returning from interpreted functions - // - // Removes the current activation (incl. unlocking of monitors) - // and sets up the return address. This code is also used for - // exception unwindwing. In that case, we do not want to throw - // IllegalMonitorStateExceptions, since that might get us into an - // infinite rethrow exception loop. - // Additionally this code is used for popFrame and earlyReturn. - // In popFrame case we want to skip throwing an exception, - // installing an exception, and notifying jvmdi. - // In earlyReturn case we only want to skip throwing an exception - // and installing an exception. - void remove_activation(TosState state, Register ret_addr, - bool throw_monitor_exception = true, - bool install_monitor_exception = true, - bool notify_jvmdi = true); -#endif /* !CC_INTERP */ - void get_method_counters(Register method, Register mcs, Label& skip); - - // Debugging - void verify_oop(Register reg, TosState state = atos); // only if +VerifyOops && state == atos -#ifndef CC_INTERP - void verify_FPU(int stack_depth, TosState state = ftos); // only if +VerifyFPU && (state == ftos || state == dtos) - -#endif /* !CC_INTERP */ - - // Object locking - void lock_object (Register lock_reg); - void unlock_object(Register lock_reg); - -#ifndef CC_INTERP - - // Interpreter profiling operations - void set_method_data_pointer_for_bcp(); - void test_method_data_pointer(Register mdp, Label& zero_continue); - void verify_method_data_pointer(); - - void set_mdp_data_at(Register mdp_in, int constant, Register value); - void increment_mdp_data_at(Address data, bool decrement = false); - void increment_mdp_data_at(Register mdp_in, int constant, - bool decrement = false); - void increment_mdp_data_at(Register mdp_in, Register reg, int constant, - bool decrement = false); - void increment_mask_and_jump(Address counter_addr, - int increment, Address mask, - Register scratch, bool preloaded, - Condition cond, Label* where); - void set_mdp_flag_at(Register mdp_in, int flag_constant); - void test_mdp_data_at(Register mdp_in, int offset, Register value, - Register test_value_out, - Label& not_equal_continue); - - void record_klass_in_profile(Register receiver, Register mdp, - Register reg2, bool is_virtual_call); - void record_klass_in_profile_helper(Register receiver, Register mdp, - Register reg2, int start_row, - Label& done, bool is_virtual_call); - - void update_mdp_by_offset(Register mdp_in, int offset_of_offset); - void update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp); - void update_mdp_by_constant(Register mdp_in, int constant); - void update_mdp_for_ret(Register return_bci); - - void profile_taken_branch(Register mdp, Register bumped_count); - void profile_not_taken_branch(Register mdp); - void profile_call(Register mdp); - void profile_final_call(Register mdp); - void profile_virtual_call(Register receiver, Register mdp, Register scratch2, - bool receiver_can_be_null = false); - void profile_ret(Register return_bci, Register mdp); - void profile_null_seen(Register mdp); - void profile_typecheck(Register mdp, Register klass, Register scratch); - void profile_typecheck_failed(Register mdp); - void profile_switch_default(Register mdp); - void profile_switch_case(Register index_in_scratch, Register mdp, Register scratch2); - -#endif /* !CC_INTERP */ - - typedef enum { NotifyJVMTI, SkipNotifyJVMTI } NotifyMethodExitMode; - - // support for jvmti - void notify_method_entry(); - void notify_method_exit(TosState state, NotifyMethodExitMode mode); diff --git a/hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp b/hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp deleted file mode 100644 index 76335ca9fcc..00000000000 --- a/hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp +++ /dev/null @@ -1,1507 +0,0 @@ -/* - * Copyright (c) 2003, 2014, 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. - * - * 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. - * - */ - -#include "precompiled.hpp" -#include "interp_masm_x86.hpp" -#include "interpreter/interpreter.hpp" -#include "interpreter/interpreterRuntime.hpp" -#include "oops/arrayOop.hpp" -#include "oops/markOop.hpp" -#include "oops/methodData.hpp" -#include "oops/method.hpp" -#include "prims/jvmtiExport.hpp" -#include "prims/jvmtiRedefineClassesTrace.hpp" -#include "prims/jvmtiThreadState.hpp" -#include "runtime/basicLock.hpp" -#include "runtime/biasedLocking.hpp" -#include "runtime/sharedRuntime.hpp" -#include "runtime/thread.inline.hpp" - - -// Implementation of InterpreterMacroAssembler - -#ifdef CC_INTERP -void InterpreterMacroAssembler::get_method(Register reg) { - movptr(reg, Address(rbp, -((int)sizeof(BytecodeInterpreter) + 2 * wordSize))); - movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method))); -} -#endif // CC_INTERP - -#ifndef CC_INTERP - -void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point, - int number_of_arguments) { - // interpreter specific - // - // Note: No need to save/restore bcp & locals (r13 & r14) pointer - // since these are callee saved registers and no blocking/ - // GC can happen in leaf calls. - // Further Note: DO NOT save/restore bcp/locals. If a caller has - // already saved them so that it can use esi/edi as temporaries - // then a save/restore here will DESTROY the copy the caller - // saved! There used to be a save_bcp() that only happened in - // the ASSERT path (no restore_bcp). Which caused bizarre failures - // when jvm built with ASSERTs. -#ifdef ASSERT - { - Label L; - cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); - jcc(Assembler::equal, L); - stop("InterpreterMacroAssembler::call_VM_leaf_base:" - " last_sp != NULL"); - bind(L); - } -#endif - // super call - MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments); - // interpreter specific - // Used to ASSERT that r13/r14 were equal to frame's bcp/locals - // but since they may not have been saved (and we don't want to - // save thme here (see note above) the assert is invalid. -} - -void InterpreterMacroAssembler::call_VM_base(Register oop_result, - Register java_thread, - Register last_java_sp, - address entry_point, - int number_of_arguments, - bool check_exceptions) { - // interpreter specific - // - // Note: Could avoid restoring locals ptr (callee saved) - however doesn't - // really make a difference for these runtime calls, since they are - // slow anyway. Btw., bcp must be saved/restored since it may change - // due to GC. - // assert(java_thread == noreg , "not expecting a precomputed java thread"); - save_bcp(); -#ifdef ASSERT - { - Label L; - cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); - jcc(Assembler::equal, L); - stop("InterpreterMacroAssembler::call_VM_leaf_base:" - " last_sp != NULL"); - bind(L); - } -#endif /* ASSERT */ - // super call - MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp, - entry_point, number_of_arguments, - check_exceptions); - // interpreter specific - restore_bcp(); - restore_locals(); -} - - -void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) { - if (JvmtiExport::can_pop_frame()) { - Label L; - // Initiate popframe handling only if it is not already being - // processed. If the flag has the popframe_processing bit set, it - // means that this code is called *during* popframe handling - we - // don't want to reenter. - // This method is only called just after the call into the vm in - // call_VM_base, so the arg registers are available. - movl(c_rarg0, Address(r15_thread, JavaThread::popframe_condition_offset())); - testl(c_rarg0, JavaThread::popframe_pending_bit); - jcc(Assembler::zero, L); - testl(c_rarg0, JavaThread::popframe_processing_bit); - jcc(Assembler::notZero, L); - // Call Interpreter::remove_activation_preserving_args_entry() to get the - // address of the same-named entrypoint in the generated interpreter code. - call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); - jmp(rax); - bind(L); - } -} - - -void InterpreterMacroAssembler::load_earlyret_value(TosState state) { - movptr(rcx, Address(r15_thread, JavaThread::jvmti_thread_state_offset())); - const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset()); - const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset()); - const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset()); - switch (state) { - case atos: movptr(rax, oop_addr); - movptr(oop_addr, (int32_t)NULL_WORD); - verify_oop(rax, state); break; - case ltos: movptr(rax, val_addr); break; - case btos: // fall through - case ctos: // fall through - case stos: // fall through - case itos: movl(rax, val_addr); break; - case ftos: movflt(xmm0, val_addr); break; - case dtos: movdbl(xmm0, val_addr); break; - case vtos: /* nothing to do */ break; - default : ShouldNotReachHere(); - } - // Clean up tos value in the thread object - movl(tos_addr, (int) ilgl); - movl(val_addr, (int32_t) NULL_WORD); -} - - -void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) { - if (JvmtiExport::can_force_early_return()) { - Label L; - movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset())); - testptr(c_rarg0, c_rarg0); - jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit; - - // Initiate earlyret handling only if it is not already being processed. - // If the flag has the earlyret_processing bit set, it means that this code - // is called *during* earlyret handling - we don't want to reenter. - movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_state_offset())); - cmpl(c_rarg0, JvmtiThreadState::earlyret_pending); - jcc(Assembler::notEqual, L); - - // Call Interpreter::remove_activation_early_entry() to get the address of the - // same-named entrypoint in the generated interpreter code. - movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset())); - movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_tos_offset())); - call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), c_rarg0); - jmp(rax); - bind(L); - } -} - - -void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp( - Register reg, - int bcp_offset) { - assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode"); - load_unsigned_short(reg, Address(r13, bcp_offset)); - bswapl(reg); - shrl(reg, 16); -} - - -void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index, - int bcp_offset, - size_t index_size) { - assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); - if (index_size == sizeof(u2)) { - load_unsigned_short(index, Address(r13, bcp_offset)); - } else if (index_size == sizeof(u4)) { - movl(index, Address(r13, bcp_offset)); - // Check if the secondary index definition is still ~x, otherwise - // we have to change the following assembler code to calculate the - // plain index. - assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line"); - notl(index); // convert to plain index - } else if (index_size == sizeof(u1)) { - load_unsigned_byte(index, Address(r13, bcp_offset)); - } else { - ShouldNotReachHere(); - } -} - - -void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, - Register index, - int bcp_offset, - size_t index_size) { - assert_different_registers(cache, index); - get_cache_index_at_bcp(index, bcp_offset, index_size); - movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); - assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below"); - // convert from field index to ConstantPoolCacheEntry index - assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line"); - shll(index, 2); -} - - -void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache, - Register index, - Register bytecode, - int byte_no, - int bcp_offset, - size_t index_size) { - get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size); - // We use a 32-bit load here since the layout of 64-bit words on - // little-endian machines allow us that. - movl(bytecode, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset())); - const int shift_count = (1 + byte_no) * BitsPerByte; - assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) || - (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift), - "correct shift count"); - shrl(bytecode, shift_count); - assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask"); - andl(bytecode, ConstantPoolCacheEntry::bytecode_1_mask); -} - - -void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, - Register tmp, - int bcp_offset, - size_t index_size) { - assert(cache != tmp, "must use different register"); - get_cache_index_at_bcp(tmp, bcp_offset, index_size); - assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below"); - // convert from field index to ConstantPoolCacheEntry index - // and from word offset to byte offset - assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line"); - shll(tmp, 2 + LogBytesPerWord); - movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); - // skip past the header - addptr(cache, in_bytes(ConstantPoolCache::base_offset())); - addptr(cache, tmp); // construct pointer to cache entry -} - -// Load object from cpool->resolved_references(index) -void InterpreterMacroAssembler::load_resolved_reference_at_index( - Register result, Register index) { - assert_different_registers(result, index); - // convert from field index to resolved_references() index and from - // word index to byte offset. Since this is a java object, it can be compressed - Register tmp = index; // reuse - shll(tmp, LogBytesPerHeapOop); - - get_constant_pool(result); - // load pointer for resolved_references[] objArray - movptr(result, Address(result, ConstantPool::resolved_references_offset_in_bytes())); - // JNIHandles::resolve(obj); - movptr(result, Address(result, 0)); - // Add in the index - addptr(result, tmp); - load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT))); -} - -// Generate a subtype check: branch to ok_is_subtype if sub_klass is a -// subtype of super_klass. -// -// Args: -// rax: superklass -// Rsub_klass: subklass -// -// Kills: -// rcx, rdi -void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, - Label& ok_is_subtype) { - assert(Rsub_klass != rax, "rax holds superklass"); - assert(Rsub_klass != r14, "r14 holds locals"); - assert(Rsub_klass != r13, "r13 holds bcp"); - assert(Rsub_klass != rcx, "rcx holds 2ndary super array length"); - assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr"); - - // Profile the not-null value's klass. - profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi - - // Do the check. - check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx - - // Profile the failure of the check. - profile_typecheck_failed(rcx); // blows rcx -} - - - -// Java Expression Stack - -void InterpreterMacroAssembler::pop_ptr(Register r) { - pop(r); -} - -void InterpreterMacroAssembler::pop_i(Register r) { - // XXX can't use pop currently, upper half non clean - movl(r, Address(rsp, 0)); - addptr(rsp, wordSize); -} - -void InterpreterMacroAssembler::pop_l(Register r) { - movq(r, Address(rsp, 0)); - addptr(rsp, 2 * Interpreter::stackElementSize); -} - -void InterpreterMacroAssembler::pop_f(XMMRegister r) { - movflt(r, Address(rsp, 0)); - addptr(rsp, wordSize); -} - -void InterpreterMacroAssembler::pop_d(XMMRegister r) { - movdbl(r, Address(rsp, 0)); - addptr(rsp, 2 * Interpreter::stackElementSize); -} - -void InterpreterMacroAssembler::push_ptr(Register r) { - push(r); -} - -void InterpreterMacroAssembler::push_i(Register r) { - push(r); -} - -void InterpreterMacroAssembler::push_l(Register r) { - subptr(rsp, 2 * wordSize); - movq(Address(rsp, 0), r); -} - -void InterpreterMacroAssembler::push_f(XMMRegister r) { - subptr(rsp, wordSize); - movflt(Address(rsp, 0), r); -} - -void InterpreterMacroAssembler::push_d(XMMRegister r) { - subptr(rsp, 2 * wordSize); - movdbl(Address(rsp, 0), r); -} - -void InterpreterMacroAssembler::pop(TosState state) { - switch (state) { - case atos: pop_ptr(); break; - case btos: - case ctos: - case stos: - case itos: pop_i(); break; - case ltos: pop_l(); break; - case ftos: pop_f(); break; - case dtos: pop_d(); break; - case vtos: /* nothing to do */ break; - default: ShouldNotReachHere(); - } - verify_oop(rax, state); -} - -void InterpreterMacroAssembler::push(TosState state) { - verify_oop(rax, state); - switch (state) { - case atos: push_ptr(); break; - case btos: - case ctos: - case stos: - case itos: push_i(); break; - case ltos: push_l(); break; - case ftos: push_f(); break; - case dtos: push_d(); break; - case vtos: /* nothing to do */ break; - default : ShouldNotReachHere(); - } -} - - -// Helpers for swap and dup -void InterpreterMacroAssembler::load_ptr(int n, Register val) { - movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n))); -} - -void InterpreterMacroAssembler::store_ptr(int n, Register val) { - movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val); -} - - -void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() { - // set sender sp - lea(r13, Address(rsp, wordSize)); - // record last_sp - movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), r13); -} - - -// Jump to from_interpreted entry of a call unless single stepping is possible -// in this thread in which case we must call the i2i entry -void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) { - prepare_to_jump_from_interpreted(); - - if (JvmtiExport::can_post_interpreter_events()) { - Label run_compiled_code; - // JVMTI events, such as single-stepping, are implemented partly by avoiding running - // compiled code in threads for which the event is enabled. Check here for - // interp_only_mode if these events CAN be enabled. - // interp_only is an int, on little endian it is sufficient to test the byte only - // Is a cmpl faster? - cmpb(Address(r15_thread, JavaThread::interp_only_mode_offset()), 0); - jccb(Assembler::zero, run_compiled_code); - jmp(Address(method, Method::interpreter_entry_offset())); - bind(run_compiled_code); - } - - jmp(Address(method, Method::from_interpreted_offset())); - -} - - -// The following two routines provide a hook so that an implementation -// can schedule the dispatch in two parts. amd64 does not do this. -void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) { - // Nothing amd64 specific to be done here -} - -void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) { - dispatch_next(state, step); -} - -void InterpreterMacroAssembler::dispatch_base(TosState state, - address* table, - bool verifyoop) { - verify_FPU(1, state); - if (VerifyActivationFrameSize) { - Label L; - mov(rcx, rbp); - subptr(rcx, rsp); - int32_t min_frame_size = - (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * - wordSize; - cmpptr(rcx, (int32_t)min_frame_size); - jcc(Assembler::greaterEqual, L); - stop("broken stack frame"); - bind(L); - } - if (verifyoop) { - verify_oop(rax, state); - } - lea(rscratch1, ExternalAddress((address)table)); - jmp(Address(rscratch1, rbx, Address::times_8)); -} - -void InterpreterMacroAssembler::dispatch_only(TosState state) { - dispatch_base(state, Interpreter::dispatch_table(state)); -} - -void InterpreterMacroAssembler::dispatch_only_normal(TosState state) { - dispatch_base(state, Interpreter::normal_table(state)); -} - -void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) { - dispatch_base(state, Interpreter::normal_table(state), false); -} - - -void InterpreterMacroAssembler::dispatch_next(TosState state, int step) { - // load next bytecode (load before advancing r13 to prevent AGI) - load_unsigned_byte(rbx, Address(r13, step)); - // advance r13 - increment(r13, step); - dispatch_base(state, Interpreter::dispatch_table(state)); -} - -void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { - // load current bytecode - load_unsigned_byte(rbx, Address(r13, 0)); - dispatch_base(state, table); -} - -// remove activation -// -// Unlock the receiver if this is a synchronized method. -// Unlock any Java monitors from syncronized blocks. -// Remove the activation from the stack. -// -// If there are locked Java monitors -// If throw_monitor_exception -// throws IllegalMonitorStateException -// Else if install_monitor_exception -// installs IllegalMonitorStateException -// Else -// no error processing -void InterpreterMacroAssembler::remove_activation( - TosState state, - Register ret_addr, - bool throw_monitor_exception, - bool install_monitor_exception, - bool notify_jvmdi) { - // Note: Registers rdx xmm0 may be in use for the - // result check if synchronized method - Label unlocked, unlock, no_unlock; - - // get the value of _do_not_unlock_if_synchronized into rdx - const Address do_not_unlock_if_synchronized(r15_thread, - in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); - movbool(rdx, do_not_unlock_if_synchronized); - movbool(do_not_unlock_if_synchronized, false); // reset the flag - - // get method access flags - movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); - movl(rcx, Address(rbx, Method::access_flags_offset())); - testl(rcx, JVM_ACC_SYNCHRONIZED); - jcc(Assembler::zero, unlocked); - - // Don't unlock anything if the _do_not_unlock_if_synchronized flag - // is set. - testbool(rdx); - jcc(Assembler::notZero, no_unlock); - - // unlock monitor - push(state); // save result - - // BasicObjectLock will be first in list, since this is a - // synchronized method. However, need to check that the object has - // not been unlocked by an explicit monitorexit bytecode. - const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * - wordSize - (int) sizeof(BasicObjectLock)); - // We use c_rarg1 so that if we go slow path it will be the correct - // register for unlock_object to pass to VM directly - lea(c_rarg1, monitor); // address of first monitor - - movptr(rax, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes())); - testptr(rax, rax); - jcc(Assembler::notZero, unlock); - - pop(state); - if (throw_monitor_exception) { - // Entry already unlocked, need to throw exception - call_VM(noreg, CAST_FROM_FN_PTR(address, - InterpreterRuntime::throw_illegal_monitor_state_exception)); - should_not_reach_here(); - } else { - // Monitor already unlocked during a stack unroll. If requested, - // install an illegal_monitor_state_exception. Continue with - // stack unrolling. - if (install_monitor_exception) { - call_VM(noreg, CAST_FROM_FN_PTR(address, - InterpreterRuntime::new_illegal_monitor_state_exception)); - } - jmp(unlocked); - } - - bind(unlock); - unlock_object(c_rarg1); - pop(state); - - // Check that for block-structured locking (i.e., that all locked - // objects has been unlocked) - bind(unlocked); - - // rax: Might contain return value - - // Check that all monitors are unlocked - { - Label loop, exception, entry, restart; - const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; - const Address monitor_block_top( - rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); - const Address monitor_block_bot( - rbp, frame::interpreter_frame_initial_sp_offset * wordSize); - - bind(restart); - // We use c_rarg1 so that if we go slow path it will be the correct - // register for unlock_object to pass to VM directly - movptr(c_rarg1, monitor_block_top); // points to current entry, starting - // with top-most entry - lea(rbx, monitor_block_bot); // points to word before bottom of - // monitor block - jmp(entry); - - // Entry already locked, need to throw exception - bind(exception); - - if (throw_monitor_exception) { - // Throw exception - MacroAssembler::call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime:: - throw_illegal_monitor_state_exception)); - should_not_reach_here(); - } else { - // Stack unrolling. Unlock object and install illegal_monitor_exception. - // Unlock does not block, so don't have to worry about the frame. - // We don't have to preserve c_rarg1 since we are going to throw an exception. - - push(state); - unlock_object(c_rarg1); - pop(state); - - if (install_monitor_exception) { - call_VM(noreg, CAST_FROM_FN_PTR(address, - InterpreterRuntime:: - new_illegal_monitor_state_exception)); - } - - jmp(restart); - } - - bind(loop); - // check if current entry is used - cmpptr(Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL); - jcc(Assembler::notEqual, exception); - - addptr(c_rarg1, entry_size); // otherwise advance to next entry - bind(entry); - cmpptr(c_rarg1, rbx); // check if bottom reached - jcc(Assembler::notEqual, loop); // if not at bottom then check this entry - } - - bind(no_unlock); - - // jvmti support - if (notify_jvmdi) { - notify_method_exit(state, NotifyJVMTI); // preserve TOSCA - } else { - notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA - } - - // remove activation - // get sender sp - movptr(rbx, - Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); - leave(); // remove frame anchor - pop(ret_addr); // get return address - mov(rsp, rbx); // set sp to sender sp -} - -#endif // C_INTERP - -void InterpreterMacroAssembler::get_method_counters(Register method, - Register mcs, Label& skip) { - Label has_counters; - movptr(mcs, Address(method, Method::method_counters_offset())); - testptr(mcs, mcs); - jcc(Assembler::notZero, has_counters); - call_VM(noreg, CAST_FROM_FN_PTR(address, - InterpreterRuntime::build_method_counters), method); - movptr(mcs, Address(method,Method::method_counters_offset())); - testptr(mcs, mcs); - jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory - bind(has_counters); -} - - -// Lock object -// -// Args: -// c_rarg1: BasicObjectLock to be used for locking -// -// Kills: -// rax -// c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs) -// rscratch1, rscratch2 (scratch regs) -void InterpreterMacroAssembler::lock_object(Register lock_reg) { - assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1"); - - if (UseHeavyMonitors) { - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), - lock_reg); - } else { - Label done; - - const Register swap_reg = rax; // Must use rax for cmpxchg instruction - const Register obj_reg = c_rarg3; // Will contain the oop - - const int obj_offset = BasicObjectLock::obj_offset_in_bytes(); - const int lock_offset = BasicObjectLock::lock_offset_in_bytes (); - const int mark_offset = lock_offset + - BasicLock::displaced_header_offset_in_bytes(); - - Label slow_case; - - // Load object pointer into obj_reg %c_rarg3 - movptr(obj_reg, Address(lock_reg, obj_offset)); - - if (UseBiasedLocking) { - biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, done, &slow_case); - } - - // Load immediate 1 into swap_reg %rax - movl(swap_reg, 1); - - // Load (object->mark() | 1) into swap_reg %rax - orptr(swap_reg, Address(obj_reg, 0)); - - // Save (object->mark() | 1) into BasicLock's displaced header - movptr(Address(lock_reg, mark_offset), swap_reg); - - assert(lock_offset == 0, - "displached header must be first word in BasicObjectLock"); - - if (os::is_MP()) lock(); - cmpxchgptr(lock_reg, Address(obj_reg, 0)); - if (PrintBiasedLockingStatistics) { - cond_inc32(Assembler::zero, - ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); - } - jcc(Assembler::zero, done); - - // Test if the oopMark is an obvious stack pointer, i.e., - // 1) (mark & 7) == 0, and - // 2) rsp <= mark < mark + os::pagesize() - // - // These 3 tests can be done by evaluating the following - // expression: ((mark - rsp) & (7 - os::vm_page_size())), - // assuming both stack pointer and pagesize have their - // least significant 3 bits clear. - // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg - subptr(swap_reg, rsp); - andptr(swap_reg, 7 - os::vm_page_size()); - - // Save the test result, for recursive case, the result is zero - movptr(Address(lock_reg, mark_offset), swap_reg); - - if (PrintBiasedLockingStatistics) { - cond_inc32(Assembler::zero, - ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); - } - jcc(Assembler::zero, done); - - bind(slow_case); - - // Call the runtime routine for slow case - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), - lock_reg); - - bind(done); - } -} - - -// Unlocks an object. Used in monitorexit bytecode and -// remove_activation. Throws an IllegalMonitorException if object is -// not locked by current thread. -// -// Args: -// c_rarg1: BasicObjectLock for lock -// -// Kills: -// rax -// c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs) -// rscratch1, rscratch2 (scratch regs) -void InterpreterMacroAssembler::unlock_object(Register lock_reg) { - assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1"); - - if (UseHeavyMonitors) { - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), - lock_reg); - } else { - Label done; - - const Register swap_reg = rax; // Must use rax for cmpxchg instruction - const Register header_reg = c_rarg2; // Will contain the old oopMark - const Register obj_reg = c_rarg3; // Will contain the oop - - save_bcp(); // Save in case of exception - - // Convert from BasicObjectLock structure to object and BasicLock - // structure Store the BasicLock address into %rax - lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes())); - - // Load oop into obj_reg(%c_rarg3) - movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes())); - - // Free entry - movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); - - if (UseBiasedLocking) { - biased_locking_exit(obj_reg, header_reg, done); - } - - // Load the old header from BasicLock structure - movptr(header_reg, Address(swap_reg, - BasicLock::displaced_header_offset_in_bytes())); - - // Test for recursion - testptr(header_reg, header_reg); - - // zero for recursive case - jcc(Assembler::zero, done); - - // Atomic swap back the old header - if (os::is_MP()) lock(); - cmpxchgptr(header_reg, Address(obj_reg, 0)); - - // zero for recursive case - jcc(Assembler::zero, done); - - // Call the runtime routine for slow case. - movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), - obj_reg); // restore obj - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), - lock_reg); - - bind(done); - - restore_bcp(); - } -} - -#ifndef CC_INTERP - -void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, - Label& zero_continue) { - assert(ProfileInterpreter, "must be profiling interpreter"); - movptr(mdp, Address(rbp, frame::interpreter_frame_mdp_offset * wordSize)); - testptr(mdp, mdp); - jcc(Assembler::zero, zero_continue); -} - - -// Set the method data pointer for the current bcp. -void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { - assert(ProfileInterpreter, "must be profiling interpreter"); - Label set_mdp; - push(rax); - push(rbx); - - get_method(rbx); - // Test MDO to avoid the call if it is NULL. - movptr(rax, Address(rbx, in_bytes(Method::method_data_offset()))); - testptr(rax, rax); - jcc(Assembler::zero, set_mdp); - // rbx: method - // r13: bcp - call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, r13); - // rax: mdi - // mdo is guaranteed to be non-zero here, we checked for it before the call. - movptr(rbx, Address(rbx, in_bytes(Method::method_data_offset()))); - addptr(rbx, in_bytes(MethodData::data_offset())); - addptr(rax, rbx); - bind(set_mdp); - movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), rax); - pop(rbx); - pop(rax); -} - -void InterpreterMacroAssembler::verify_method_data_pointer() { - assert(ProfileInterpreter, "must be profiling interpreter"); -#ifdef ASSERT - Label verify_continue; - push(rax); - push(rbx); - push(c_rarg3); - push(c_rarg2); - test_method_data_pointer(c_rarg3, verify_continue); // If mdp is zero, continue - get_method(rbx); - - // If the mdp is valid, it will point to a DataLayout header which is - // consistent with the bcp. The converse is highly probable also. - load_unsigned_short(c_rarg2, - Address(c_rarg3, in_bytes(DataLayout::bci_offset()))); - addptr(c_rarg2, Address(rbx, Method::const_offset())); - lea(c_rarg2, Address(c_rarg2, ConstMethod::codes_offset())); - cmpptr(c_rarg2, r13); - jcc(Assembler::equal, verify_continue); - // rbx: method - // r13: bcp - // c_rarg3: mdp - call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), - rbx, r13, c_rarg3); - bind(verify_continue); - pop(c_rarg2); - pop(c_rarg3); - pop(rbx); - pop(rax); -#endif // ASSERT -} - - -void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, - int constant, - Register value) { - assert(ProfileInterpreter, "must be profiling interpreter"); - Address data(mdp_in, constant); - movptr(data, value); -} - - -void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, - int constant, - bool decrement) { - // Counter address - Address data(mdp_in, constant); - - increment_mdp_data_at(data, decrement); -} - -void InterpreterMacroAssembler::increment_mdp_data_at(Address data, - bool decrement) { - assert(ProfileInterpreter, "must be profiling interpreter"); - // %%% this does 64bit counters at best it is wasting space - // at worst it is a rare bug when counters overflow - - if (decrement) { - // Decrement the register. Set condition codes. - addptr(data, (int32_t) -DataLayout::counter_increment); - // If the decrement causes the counter to overflow, stay negative - Label L; - jcc(Assembler::negative, L); - addptr(data, (int32_t) DataLayout::counter_increment); - bind(L); - } else { - assert(DataLayout::counter_increment == 1, - "flow-free idiom only works with 1"); - // Increment the register. Set carry flag. - addptr(data, DataLayout::counter_increment); - // If the increment causes the counter to overflow, pull back by 1. - sbbptr(data, (int32_t)0); - } -} - - -void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, - Register reg, - int constant, - bool decrement) { - Address data(mdp_in, reg, Address::times_1, constant); - - increment_mdp_data_at(data, decrement); -} - -void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, - int flag_byte_constant) { - assert(ProfileInterpreter, "must be profiling interpreter"); - int header_offset = in_bytes(DataLayout::header_offset()); - int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant); - // Set the flag - orl(Address(mdp_in, header_offset), header_bits); -} - - - -void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in, - int offset, - Register value, - Register test_value_out, - Label& not_equal_continue) { - assert(ProfileInterpreter, "must be profiling interpreter"); - if (test_value_out == noreg) { - cmpptr(value, Address(mdp_in, offset)); - } else { - // Put the test value into a register, so caller can use it: - movptr(test_value_out, Address(mdp_in, offset)); - cmpptr(test_value_out, value); - } - jcc(Assembler::notEqual, not_equal_continue); -} - - -void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, - int offset_of_disp) { - assert(ProfileInterpreter, "must be profiling interpreter"); - Address disp_address(mdp_in, offset_of_disp); - addptr(mdp_in, disp_address); - movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); -} - - -void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, - Register reg, - int offset_of_disp) { - assert(ProfileInterpreter, "must be profiling interpreter"); - Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp); - addptr(mdp_in, disp_address); - movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); -} - - -void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, - int constant) { - assert(ProfileInterpreter, "must be profiling interpreter"); - addptr(mdp_in, constant); - movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); -} - - -void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) { - assert(ProfileInterpreter, "must be profiling interpreter"); - push(return_bci); // save/restore across call_VM - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), - return_bci); - pop(return_bci); -} - - -void InterpreterMacroAssembler::profile_taken_branch(Register mdp, - Register bumped_count) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - // Otherwise, assign to mdp - test_method_data_pointer(mdp, profile_continue); - - // We are taking a branch. Increment the taken count. - // We inline increment_mdp_data_at to return bumped_count in a register - //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); - Address data(mdp, in_bytes(JumpData::taken_offset())); - movptr(bumped_count, data); - assert(DataLayout::counter_increment == 1, - "flow-free idiom only works with 1"); - addptr(bumped_count, DataLayout::counter_increment); - sbbptr(bumped_count, 0); - movptr(data, bumped_count); // Store back out - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset())); - bind(profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // We are taking a branch. Increment the not taken count. - increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset())); - - // The method data pointer needs to be updated to correspond to - // the next bytecode - update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size())); - bind(profile_continue); - } -} - -void InterpreterMacroAssembler::profile_call(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // We are making a call. Increment the count. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size())); - bind(profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_final_call(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // We are making a call. Increment the count. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_constant(mdp, - in_bytes(VirtualCallData:: - virtual_call_data_size())); - bind(profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_virtual_call(Register receiver, - Register mdp, - Register reg2, - bool receiver_can_be_null) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - Label skip_receiver_profile; - if (receiver_can_be_null) { - Label not_null; - testptr(receiver, receiver); - jccb(Assembler::notZero, not_null); - // We are making a call. Increment the count for null receiver. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - jmp(skip_receiver_profile); - bind(not_null); - } - - // Record the receiver type. - record_klass_in_profile(receiver, mdp, reg2, true); - bind(skip_receiver_profile); - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_constant(mdp, - in_bytes(VirtualCallData:: - virtual_call_data_size())); - bind(profile_continue); - } -} - -// This routine creates a state machine for updating the multi-row -// type profile at a virtual call site (or other type-sensitive bytecode). -// The machine visits each row (of receiver/count) until the receiver type -// is found, or until it runs out of rows. At the same time, it remembers -// the location of the first empty row. (An empty row records null for its -// receiver, and can be allocated for a newly-observed receiver type.) -// Because there are two degrees of freedom in the state, a simple linear -// search will not work; it must be a decision tree. Hence this helper -// function is recursive, to generate the required tree structured code. -// It's the interpreter, so we are trading off code space for speed. -// See below for example code. -void InterpreterMacroAssembler::record_klass_in_profile_helper( - Register receiver, Register mdp, - Register reg2, int start_row, - Label& done, bool is_virtual_call) { - if (TypeProfileWidth == 0) { - if (is_virtual_call) { - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - } - return; - } - - int last_row = VirtualCallData::row_limit() - 1; - assert(start_row <= last_row, "must be work left to do"); - // Test this row for both the receiver and for null. - // Take any of three different outcomes: - // 1. found receiver => increment count and goto done - // 2. found null => keep looking for case 1, maybe allocate this cell - // 3. found something else => keep looking for cases 1 and 2 - // Case 3 is handled by a recursive call. - for (int row = start_row; row <= last_row; row++) { - Label next_test; - bool test_for_null_also = (row == start_row); - - // See if the receiver is receiver[n]. - int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row)); - test_mdp_data_at(mdp, recvr_offset, receiver, - (test_for_null_also ? reg2 : noreg), - next_test); - // (Reg2 now contains the receiver from the CallData.) - - // The receiver is receiver[n]. Increment count[n]. - int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row)); - increment_mdp_data_at(mdp, count_offset); - jmp(done); - bind(next_test); - - if (test_for_null_also) { - Label found_null; - // Failed the equality check on receiver[n]... Test for null. - testptr(reg2, reg2); - if (start_row == last_row) { - // The only thing left to do is handle the null case. - if (is_virtual_call) { - jccb(Assembler::zero, found_null); - // Receiver did not match any saved receiver and there is no empty row for it. - // Increment total counter to indicate polymorphic case. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - jmp(done); - bind(found_null); - } else { - jcc(Assembler::notZero, done); - } - break; - } - // Since null is rare, make it be the branch-taken case. - jcc(Assembler::zero, found_null); - - // Put all the "Case 3" tests here. - record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call); - - // Found a null. Keep searching for a matching receiver, - // but remember that this is an empty (unused) slot. - bind(found_null); - } - } - - // In the fall-through case, we found no matching receiver, but we - // observed the receiver[start_row] is NULL. - - // Fill in the receiver field and increment the count. - int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row)); - set_mdp_data_at(mdp, recvr_offset, receiver); - int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row)); - movl(reg2, DataLayout::counter_increment); - set_mdp_data_at(mdp, count_offset, reg2); - if (start_row > 0) { - jmp(done); - } -} - -// Example state machine code for three profile rows: -// // main copy of decision tree, rooted at row[1] -// if (row[0].rec == rec) { row[0].incr(); goto done; } -// if (row[0].rec != NULL) { -// // inner copy of decision tree, rooted at row[1] -// if (row[1].rec == rec) { row[1].incr(); goto done; } -// if (row[1].rec != NULL) { -// // degenerate decision tree, rooted at row[2] -// if (row[2].rec == rec) { row[2].incr(); goto done; } -// if (row[2].rec != NULL) { count.incr(); goto done; } // overflow -// row[2].init(rec); goto done; -// } else { -// // remember row[1] is empty -// if (row[2].rec == rec) { row[2].incr(); goto done; } -// row[1].init(rec); goto done; -// } -// } else { -// // remember row[0] is empty -// if (row[1].rec == rec) { row[1].incr(); goto done; } -// if (row[2].rec == rec) { row[2].incr(); goto done; } -// row[0].init(rec); goto done; -// } -// done: - -void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, - Register mdp, Register reg2, - bool is_virtual_call) { - assert(ProfileInterpreter, "must be profiling"); - Label done; - - record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call); - - bind (done); -} - -void InterpreterMacroAssembler::profile_ret(Register return_bci, - Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - uint row; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // Update the total ret count. - increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); - - for (row = 0; row < RetData::row_limit(); row++) { - Label next_test; - - // See if return_bci is equal to bci[n]: - test_mdp_data_at(mdp, - in_bytes(RetData::bci_offset(row)), - return_bci, noreg, - next_test); - - // return_bci is equal to bci[n]. Increment the count. - increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row))); - - // The method data pointer needs to be updated to reflect the new target. - update_mdp_by_offset(mdp, - in_bytes(RetData::bci_displacement_offset(row))); - jmp(profile_continue); - bind(next_test); - } - - update_mdp_for_ret(return_bci); - - bind(profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_null_seen(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - set_mdp_flag_at(mdp, BitData::null_seen_byte_constant()); - - // The method data pointer needs to be updated. - int mdp_delta = in_bytes(BitData::bit_data_size()); - if (TypeProfileCasts) { - mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); - } - update_mdp_by_constant(mdp, mdp_delta); - - bind(profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) { - if (ProfileInterpreter && TypeProfileCasts) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - int count_offset = in_bytes(CounterData::count_offset()); - // Back up the address, since we have already bumped the mdp. - count_offset -= in_bytes(VirtualCallData::virtual_call_data_size()); - - // *Decrement* the counter. We expect to see zero or small negatives. - increment_mdp_data_at(mdp, count_offset, true); - - bind (profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // The method data pointer needs to be updated. - int mdp_delta = in_bytes(BitData::bit_data_size()); - if (TypeProfileCasts) { - mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); - - // Record the object type. - record_klass_in_profile(klass, mdp, reg2, false); - } - update_mdp_by_constant(mdp, mdp_delta); - - bind(profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_switch_default(Register mdp) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // Update the default case count - increment_mdp_data_at(mdp, - in_bytes(MultiBranchData::default_count_offset())); - - // The method data pointer needs to be updated. - update_mdp_by_offset(mdp, - in_bytes(MultiBranchData:: - default_displacement_offset())); - - bind(profile_continue); - } -} - - -void InterpreterMacroAssembler::profile_switch_case(Register index, - Register mdp, - Register reg2) { - if (ProfileInterpreter) { - Label profile_continue; - - // If no method data exists, go to profile_continue. - test_method_data_pointer(mdp, profile_continue); - - // Build the base (index * per_case_size_in_bytes()) + - // case_array_offset_in_bytes() - movl(reg2, in_bytes(MultiBranchData::per_case_size())); - imulptr(index, reg2); // XXX l ? - addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ? - - // Update the case count - increment_mdp_data_at(mdp, - index, - in_bytes(MultiBranchData::relative_count_offset())); - - // The method data pointer needs to be updated. - update_mdp_by_offset(mdp, - index, - in_bytes(MultiBranchData:: - relative_displacement_offset())); - - bind(profile_continue); - } -} - - - -void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) { - if (state == atos) { - MacroAssembler::verify_oop(reg); - } -} - -void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { -} - -// Jump if ((*counter_addr += increment) & mask) satisfies the condition. -void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, - int increment, Address mask, - Register scratch, bool preloaded, - Condition cond, Label* where) { - if (!preloaded) { - movl(scratch, counter_addr); - } - incrementl(scratch, increment); - movl(counter_addr, scratch); - andl(scratch, mask); - jcc(cond, *where); -} -#endif // !CC_INTERP - - -void InterpreterMacroAssembler::notify_method_entry() { - // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to - // track stack depth. If it is possible to enter interp_only_mode we add - // the code to check if the event should be sent. - if (JvmtiExport::can_post_interpreter_events()) { - Label L; - movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset())); - testl(rdx, rdx); - jcc(Assembler::zero, L); - call_VM(noreg, CAST_FROM_FN_PTR(address, - InterpreterRuntime::post_method_entry)); - bind(L); - } - - { - SkipIfEqual skip(this, &DTraceMethodProbes, false); - get_method(c_rarg1); - call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), - r15_thread, c_rarg1); - } - - // RedefineClasses() tracing support for obsolete method entry - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) { - get_method(c_rarg1); - call_VM_leaf( - CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry), - r15_thread, c_rarg1); - } -} - - -void InterpreterMacroAssembler::notify_method_exit( - TosState state, NotifyMethodExitMode mode) { - // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to - // track stack depth. If it is possible to enter interp_only_mode we add - // the code to check if the event should be sent. - if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { - Label L; - // Note: frame::interpreter_frame_result has a dependency on how the - // method result is saved across the call to post_method_exit. If this - // is changed then the interpreter_frame_result implementation will - // need to be updated too. - - // For c++ interpreter the result is always stored at a known location in the frame - // template interpreter will leave it on the top of the stack. - NOT_CC_INTERP(push(state);) - movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset())); - testl(rdx, rdx); - jcc(Assembler::zero, L); - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit)); - bind(L); - NOT_CC_INTERP(pop(state)); - } - - { - SkipIfEqual skip(this, &DTraceMethodProbes, false); - NOT_CC_INTERP(push(state)); - get_method(c_rarg1); - call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), - r15_thread, c_rarg1); - NOT_CC_INTERP(pop(state)); - } -} - diff --git a/hotspot/src/cpu/x86/vm/interp_masm_x86_64.hpp b/hotspot/src/cpu/x86/vm/interp_masm_x86_64.hpp deleted file mode 100644 index c4ed238bc20..00000000000 --- a/hotspot/src/cpu/x86/vm/interp_masm_x86_64.hpp +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2003, 2014, 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. - * - * 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. - * - */ - -#ifndef CC_INTERP - protected: - // Interpreter specific version of call_VM_base - virtual void call_VM_leaf_base(address entry_point, - int number_of_arguments); - - virtual void call_VM_base(Register oop_result, - Register java_thread, - Register last_java_sp, - address entry_point, - int number_of_arguments, - bool check_exceptions); - - virtual void check_and_handle_popframe(Register java_thread); - virtual void check_and_handle_earlyret(Register java_thread); - - // base routine for all dispatches - void dispatch_base(TosState state, address* table, bool verifyoop = true); -#endif // CC_INTERP - - public: - InterpreterMacroAssembler(CodeBuffer* code) : MacroAssembler(code), _locals_register(r14), _bcp_register(r13) {} - - void load_earlyret_value(TosState state); - -#ifdef CC_INTERP - void save_bcp() { /* not needed in c++ interpreter and harmless */ } - void restore_bcp() { /* not needed in c++ interpreter and harmless */ } - - // Helpers for runtime call arguments/results - void get_method(Register reg); - -#else - - // Interpreter-specific registers - void save_bcp() { - movptr(Address(rbp, frame::interpreter_frame_bcp_offset * wordSize), r13); - } - - void restore_bcp() { - movptr(r13, Address(rbp, frame::interpreter_frame_bcp_offset * wordSize)); - } - - void restore_locals() { - movptr(r14, Address(rbp, frame::interpreter_frame_locals_offset * wordSize)); - } - - // Helpers for runtime call arguments/results - void get_method(Register reg) { - movptr(reg, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); - } - - void get_const(Register reg) { - get_method(reg); - movptr(reg, Address(reg, Method::const_offset())); - } - - void get_constant_pool(Register reg) { - get_const(reg); - movptr(reg, Address(reg, ConstMethod::constants_offset())); - } - - void get_constant_pool_cache(Register reg) { - get_constant_pool(reg); - movptr(reg, Address(reg, ConstantPool::cache_offset_in_bytes())); - } - - void get_cpool_and_tags(Register cpool, Register tags) { - get_constant_pool(cpool); - movptr(tags, Address(cpool, ConstantPool::tags_offset_in_bytes())); - } - - void get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset); - void get_cache_and_index_at_bcp(Register cache, Register index, int bcp_offset, size_t index_size = sizeof(u2)); - void get_cache_and_index_and_bytecode_at_bcp(Register cache, Register index, Register bytecode, int byte_no, int bcp_offset, size_t index_size = sizeof(u2)); - void get_cache_entry_pointer_at_bcp(Register cache, Register tmp, int bcp_offset, size_t index_size = sizeof(u2)); - void get_cache_index_at_bcp(Register index, int bcp_offset, size_t index_size = sizeof(u2)); - - // load cpool->resolved_references(index); - void load_resolved_reference_at_index(Register result, Register index); - - void pop_ptr(Register r = rax); - void pop_i(Register r = rax); - void pop_l(Register r = rax); - void pop_f(XMMRegister r = xmm0); - void pop_d(XMMRegister r = xmm0); - void push_ptr(Register r = rax); - void push_i(Register r = rax); - void push_l(Register r = rax); - void push_f(XMMRegister r = xmm0); - void push_d(XMMRegister r = xmm0); - - void pop(Register r ) { ((MacroAssembler*)this)->pop(r); } - - void push(Register r ) { ((MacroAssembler*)this)->push(r); } - void push(int32_t imm ) { ((MacroAssembler*)this)->push(imm); } - - void pop(TosState state); // transition vtos -> state - void push(TosState state); // transition state -> vtos - - void empty_expression_stack() { - movptr(rsp, Address(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize)); - // NULL last_sp until next java call - movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); - } - - // Helpers for swap and dup - void load_ptr(int n, Register val); - void store_ptr(int n, Register val); - - // Generate a subtype check: branch to ok_is_subtype if sub_klass is - // a subtype of super_klass. - void gen_subtype_check( Register sub_klass, Label &ok_is_subtype ); - - // Dispatching - void dispatch_prolog(TosState state, int step = 0); - void dispatch_epilog(TosState state, int step = 0); - // dispatch via ebx (assume ebx is loaded already) - void dispatch_only(TosState state); - // dispatch normal table via ebx (assume ebx is loaded already) - void dispatch_only_normal(TosState state); - void dispatch_only_noverify(TosState state); - // load ebx from [esi + step] and dispatch via ebx - void dispatch_next(TosState state, int step = 0); - // load ebx from [esi] and dispatch via ebx and table - void dispatch_via (TosState state, address* table); - - // jump to an invoked target - void prepare_to_jump_from_interpreted(); - void jump_from_interpreted(Register method, Register temp); - - - // Returning from interpreted functions - // - // Removes the current activation (incl. unlocking of monitors) - // and sets up the return address. This code is also used for - // exception unwindwing. In that case, we do not want to throw - // IllegalMonitorStateExceptions, since that might get us into an - // infinite rethrow exception loop. - // Additionally this code is used for popFrame and earlyReturn. - // In popFrame case we want to skip throwing an exception, - // installing an exception, and notifying jvmdi. - // In earlyReturn case we only want to skip throwing an exception - // and installing an exception. - void remove_activation(TosState state, Register ret_addr, - bool throw_monitor_exception = true, - bool install_monitor_exception = true, - bool notify_jvmdi = true); -#endif // CC_INTERP - void get_method_counters(Register method, Register mcs, Label& skip); - - // Object locking - void lock_object (Register lock_reg); - void unlock_object(Register lock_reg); - -#ifndef CC_INTERP - - // Interpreter profiling operations - void set_method_data_pointer_for_bcp(); - void test_method_data_pointer(Register mdp, Label& zero_continue); - void verify_method_data_pointer(); - - void set_mdp_data_at(Register mdp_in, int constant, Register value); - void increment_mdp_data_at(Address data, bool decrement = false); - void increment_mdp_data_at(Register mdp_in, int constant, - bool decrement = false); - void increment_mdp_data_at(Register mdp_in, Register reg, int constant, - bool decrement = false); - void increment_mask_and_jump(Address counter_addr, - int increment, Address mask, - Register scratch, bool preloaded, - Condition cond, Label* where); - void set_mdp_flag_at(Register mdp_in, int flag_constant); - void test_mdp_data_at(Register mdp_in, int offset, Register value, - Register test_value_out, - Label& not_equal_continue); - - void record_klass_in_profile(Register receiver, Register mdp, - Register reg2, bool is_virtual_call); - void record_klass_in_profile_helper(Register receiver, Register mdp, - Register reg2, int start_row, - Label& done, bool is_virtual_call); - - void update_mdp_by_offset(Register mdp_in, int offset_of_offset); - void update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp); - void update_mdp_by_constant(Register mdp_in, int constant); - void update_mdp_for_ret(Register return_bci); - - void profile_taken_branch(Register mdp, Register bumped_count); - void profile_not_taken_branch(Register mdp); - void profile_call(Register mdp); - void profile_final_call(Register mdp); - void profile_virtual_call(Register receiver, Register mdp, - Register scratch2, - bool receiver_can_be_null = false); - void profile_ret(Register return_bci, Register mdp); - void profile_null_seen(Register mdp); - void profile_typecheck(Register mdp, Register klass, Register scratch); - void profile_typecheck_failed(Register mdp); - void profile_switch_default(Register mdp); - void profile_switch_case(Register index_in_scratch, Register mdp, - Register scratch2); - - // Debugging - // only if +VerifyOops && state == atos - void verify_oop(Register reg, TosState state = atos); - // only if +VerifyFPU && (state == ftos || state == dtos) - void verify_FPU(int stack_depth, TosState state = ftos); - -#endif // !CC_INTERP - - typedef enum { NotifyJVMTI, SkipNotifyJVMTI } NotifyMethodExitMode; - - // support for jvmti/dtrace - void notify_method_entry(); - void notify_method_exit(TosState state, NotifyMethodExitMode mode); From 41b79b9ad430ae6c43271b6b268b78ad1e816923 Mon Sep 17 00:00:00 2001 From: Zoltan Majo Date: Sat, 14 Mar 2015 11:21:04 +0100 Subject: [PATCH 065/362] 8074869: C2 code generator can replace -0.0f with +0.0f on Linux Instead of 'fpclass', use cast float->int and double->long to check if value is +0.0f and +0.0d, respectively. Reviewed-by: kvn, simonis, dlong --- hotspot/src/cpu/aarch64/vm/aarch64.ad | 12 ++-- hotspot/src/cpu/ppc/vm/ppc.ad | 6 +- hotspot/src/cpu/sparc/vm/sparc.ad | 10 +-- .../vm/utilities/globalDefinitions_gcc.hpp | 8 --- .../globalDefinitions_sparcWorks.hpp | 9 --- .../vm/utilities/globalDefinitions_xlc.hpp | 8 --- .../loopopts/ConstFPVectorization.java | 63 +++++++++++++++++++ 7 files changed, 75 insertions(+), 41 deletions(-) create mode 100644 hotspot/test/compiler/loopopts/ConstFPVectorization.java diff --git a/hotspot/src/cpu/aarch64/vm/aarch64.ad b/hotspot/src/cpu/aarch64/vm/aarch64.ad index 38e8e9ead46..d2a54458930 100644 --- a/hotspot/src/cpu/aarch64/vm/aarch64.ad +++ b/hotspot/src/cpu/aarch64/vm/aarch64.ad @@ -3735,12 +3735,12 @@ operand immD() interface(CONST_INTER); %} -// constant 'double +0.0'. +// Double Immediate: +0.0d operand immD0() %{ - predicate((n->getd() == 0) && - (fpclassify(n->getd()) == FP_ZERO) && (signbit(n->getd()) == 0)); + predicate(jlong_cast(n->getd()) == 0); match(ConD); + op_cost(0); format %{ %} interface(CONST_INTER); @@ -3765,12 +3765,12 @@ operand immF() interface(CONST_INTER); %} -// constant 'float +0.0'. +// Float Immediate: +0.0f. operand immF0() %{ - predicate((n->getf() == 0) && - (fpclassify(n->getf()) == FP_ZERO) && (signbit(n->getf()) == 0)); + predicate(jint_cast(n->getf()) == 0); match(ConF); + op_cost(0); format %{ %} interface(CONST_INTER); diff --git a/hotspot/src/cpu/ppc/vm/ppc.ad b/hotspot/src/cpu/ppc/vm/ppc.ad index 3808eabd27e..4c64d96a3e4 100644 --- a/hotspot/src/cpu/ppc/vm/ppc.ad +++ b/hotspot/src/cpu/ppc/vm/ppc.ad @@ -4416,11 +4416,11 @@ operand immF() %{ interface(CONST_INTER); %} -// constant 'float +0.0'. +// Float Immediate: +0.0f. operand immF_0() %{ - predicate((n->getf() == 0) && - (fpclassify(n->getf()) == FP_ZERO) && (signbit(n->getf()) == 0)); + predicate(jint_cast(n->getf()) == 0); match(ConF); + op_cost(0); format %{ %} interface(CONST_INTER); diff --git a/hotspot/src/cpu/sparc/vm/sparc.ad b/hotspot/src/cpu/sparc/vm/sparc.ad index c344c216b37..01e0c805b5f 100644 --- a/hotspot/src/cpu/sparc/vm/sparc.ad +++ b/hotspot/src/cpu/sparc/vm/sparc.ad @@ -3758,13 +3758,9 @@ operand immD() %{ interface(CONST_INTER); %} +// Double Immediate: +0.0d operand immD0() %{ -#ifdef _LP64 - // on 64-bit architectures this comparision is faster predicate(jlong_cast(n->getd()) == 0); -#else - predicate((n->getd() == 0) && (fpclass(n->getd()) == FP_PZERO)); -#endif match(ConD); op_cost(0); @@ -3781,9 +3777,9 @@ operand immF() %{ interface(CONST_INTER); %} -// Float Immediate: 0 +// Float Immediate: +0.0f operand immF0() %{ - predicate((n->getf() == 0) && (fpclass(n->getf()) == FP_PZERO)); + predicate(jint_cast(n->getf()) == 0); match(ConF); op_cost(0); diff --git a/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp b/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp index 8d78eef4f9b..dd9bb0df880 100644 --- a/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp +++ b/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp @@ -44,14 +44,6 @@ #endif // SOLARIS #include -#ifndef FP_PZERO -// Linux doesn't have positive/negative zero -#define FP_PZERO FP_ZERO -#endif -#if (!defined fpclass) && ((!defined SPARC) || (!defined SOLARIS)) -#define fpclass fpclassify -#endif - #include #include #include diff --git a/hotspot/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp b/hotspot/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp index b42a22e7004..a1a12a4361c 100644 --- a/hotspot/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp +++ b/hotspot/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp @@ -48,15 +48,6 @@ # include #endif # include -#ifdef LINUX -#ifndef FP_PZERO - // Linux doesn't have positive/negative zero - #define FP_PZERO FP_ZERO -#endif -#ifndef fpclass - #define fpclass fpclassify -#endif -#endif # include # include # include diff --git a/hotspot/src/share/vm/utilities/globalDefinitions_xlc.hpp b/hotspot/src/share/vm/utilities/globalDefinitions_xlc.hpp index 32094ab8635..948ee4843ba 100644 --- a/hotspot/src/share/vm/utilities/globalDefinitions_xlc.hpp +++ b/hotspot/src/share/vm/utilities/globalDefinitions_xlc.hpp @@ -41,14 +41,6 @@ #include #include -#ifndef FP_PZERO -// Linux doesn't have positive/negative zero -#define FP_PZERO FP_ZERO -#endif -#if (!defined fpclass) -#define fpclass fpclassify -#endif - #include #include #include diff --git a/hotspot/test/compiler/loopopts/ConstFPVectorization.java b/hotspot/test/compiler/loopopts/ConstFPVectorization.java new file mode 100644 index 00000000000..50cb0e614ec --- /dev/null +++ b/hotspot/test/compiler/loopopts/ConstFPVectorization.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + * + */ + +/** + * @test + * @bug 8074869 + * @summary C2 code generator can replace -0.0f with +0.0f on Linux + * @run main ConstFPVectorization 8 + * @author volker.simonis@gmail.com + * + */ + +public class ConstFPVectorization { + + static float[] f = new float[16]; + static double[] d = new double[16]; + + static void floatLoop(int count) { + for (int i = 0; i < count; i++) { + f[i] = -0.0f; + } + } + + static void doubleLoop(int count) { + for (int i = 0; i < count; i++) { + d[i] = -0.0d; + } + } + + public static void main(String args[]) { + for (int i = 0; i < 10_000; i++) { + floatLoop(Integer.parseInt(args[0])); + doubleLoop(Integer.parseInt(args[0])); + } + for (int i = 0; i < Integer.parseInt(args[0]); i++) { + if (Float.floatToRawIntBits(f[i]) != Float.floatToRawIntBits(-0.0f)) + throw new Error("Float error at index " + i); + if (Double.doubleToRawLongBits(d[i]) != Double.doubleToRawLongBits(-0.0d)) + throw new Error("Double error at index " + i); + } + } +} From 20be94ae55662f1458f36d10c33ede1e0268fed9 Mon Sep 17 00:00:00 2001 From: Katja Kantserova Date: Mon, 16 Mar 2015 09:32:34 +0100 Subject: [PATCH 066/362] 8073794: jdk/test/com/sun/jdi/BadHandshakeTest.java should retry if tcp port is taken Reviewed-by: jbachorik --- jdk/test/ProblemList.txt | 3 - jdk/test/com/sun/jdi/BadHandshakeTest.java | 81 +++++++++++++++------- 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/jdk/test/ProblemList.txt b/jdk/test/ProblemList.txt index b8bcd0e1dc9..95b60e73fb3 100644 --- a/jdk/test/ProblemList.txt +++ b/jdk/test/ProblemList.txt @@ -283,9 +283,6 @@ tools/launcher/FXLauncherTest.java linux-all # jdk_jdi -# 6983531 -com/sun/jdi/BadHandshakeTest.java linux-all,windows-all - # 8004127 com/sun/jdi/RedefineImplementor.sh generic-all diff --git a/jdk/test/com/sun/jdi/BadHandshakeTest.java b/jdk/test/com/sun/jdi/BadHandshakeTest.java index 87db9002ae9..2a1108f5910 100644 --- a/jdk/test/com/sun/jdi/BadHandshakeTest.java +++ b/jdk/test/com/sun/jdi/BadHandshakeTest.java @@ -21,22 +21,15 @@ * questions. */ -/* @test - * @bug 6306165 6432567 - * @summary Check that a bad handshake doesn't cause a debuggee to abort - * @library /lib/testlibrary - * - * @build jdk.testlibrary.* VMConnection BadHandshakeTest Exit0 - * @run driver BadHandshakeTest - * - */ import java.net.Socket; -import java.net.InetAddress; + import com.sun.jdi.Bootstrap; import com.sun.jdi.VirtualMachine; import com.sun.jdi.event.*; import com.sun.jdi.connect.Connector; import com.sun.jdi.connect.AttachingConnector; +import com.sun.jdi.connect.Connector.Argument; + import java.util.Map; import java.util.List; import java.util.Iterator; @@ -46,13 +39,22 @@ import java.util.concurrent.atomic.AtomicBoolean; import jdk.testlibrary.Utils; import jdk.testlibrary.ProcessTools; +/* @test + * @bug 6306165 6432567 + * @summary Check that a bad handshake doesn't cause a debuggee to abort + * @library /lib/testlibrary + * + * @build jdk.testlibrary.* VMConnection BadHandshakeTest Exit0 + * @run driver BadHandshakeTest + */ public class BadHandshakeTest { + /* * Find a connector by name */ private static Connector findConnector(String name) { - List connectors = Bootstrap.virtualMachineManager().allConnectors(); - Iterator iter = connectors.iterator(); + List connectors = Bootstrap.virtualMachineManager().allConnectors(); + Iterator iter = connectors.iterator(); while (iter.hasNext()) { Connector connector = (Connector)iter.next(); if (connector.name().equals(name)) { @@ -65,7 +67,7 @@ public class BadHandshakeTest { /* * Launch a server debuggee with the given address */ - private static Process launch(String address, String class_name) throws Exception { + private static LaunchResult launch(String address, String class_name) throws Exception { String[] args = VMConnection.insertDebuggeeVMOptions(new String[] { "-agentlib:jdwp=transport=dt_socket" + ",server=y" + ",suspend=y" + ",address=" + address, @@ -75,6 +77,7 @@ public class BadHandshakeTest { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); final AtomicBoolean success = new AtomicBoolean(); + final AtomicBoolean bindFailed = new AtomicBoolean(); Process p = ProcessTools.startProcess( class_name, pb, @@ -83,13 +86,17 @@ public class BadHandshakeTest { // Listening for transport dt_socket at address: xxxxx // which shows the debuggee is ready to accept connections. success.set(line.contains("Listening for transport dt_socket at address:")); + // If the first line contains 'Address already in use' + // that means the debuggee has failed to start due to busy port + bindFailed.set(line.contains("Address already in use")); return true; }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS ); - return success.get() ? p : null; + return new LaunchResult(success.get() ? p : null, + bindFailed.get()); } /* @@ -99,14 +106,20 @@ public class BadHandshakeTest { * - verify we saw no error */ public static void main(String args[]) throws Exception { - int port = Utils.getFreePort(); - - String address = String.valueOf(port); - - // launch the server debuggee - Process process = launch(address, "Exit0"); - if (process == null) { - throw new RuntimeException("Unable to start debugee"); + // Launch the server debuggee + int port = 0; + Process process = null; + while (process == null) { + port = Utils.getFreePort(); + String address = String.valueOf(port); + LaunchResult launchResult = launch(address, "Exit0"); + process = launchResult.getProcess(); + if (launchResult.isBindFailed()) { + System.out.println("Port " + port + " already in use. Trying to restart debuggee with a new one..."); + Thread.sleep(100); + } else if (process == null ) { + throw new RuntimeException("Unable to start debugee"); + } } // Connect to the debuggee and handshake with garbage @@ -119,9 +132,9 @@ public class BadHandshakeTest { s.getOutputStream().write("JDWP-".getBytes("UTF-8")); - // attach to server debuggee and resume it so it can exit + // Attach to server debuggee and resume it so it can exit AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach"); - Map conn_args = conn.defaultArguments(); + Map conn_args = conn.defaultArguments(); Connector.IntegerArgument port_arg = (Connector.IntegerArgument)conn_args.get("port"); port_arg.setValue(port); @@ -143,4 +156,24 @@ public class BadHandshakeTest { process.waitFor(); } + private static class LaunchResult { + + private final Process p; + private final boolean bindFailed; + + public LaunchResult(Process p, boolean bindFailed) { + this.p = p; + this.bindFailed = bindFailed; + } + + public Process getProcess() { + return p; + } + + public boolean isBindFailed() { + return bindFailed; + } + + } + } From ba1d121fe0ddc0f2b9f830bd9dcf872b3f05d331 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Thu, 26 Mar 2015 11:28:19 +0100 Subject: [PATCH 067/362] 8075957: Reduce calls to the GC specific object visitors in oopDesc Reviewed-by: brutisso, mgerdin, pliden --- .../gc_implementation/g1/g1CollectedHeap.cpp | 1 - .../vm/gc_implementation/g1/g1MarkSweep.cpp | 5 ++-- .../g1/g1ParScanThreadState.cpp | 1 - .../parNew/parNewGeneration.cpp | 1 - .../parallelScavenge/cardTableExtension.cpp | 7 +++-- .../parallelScavenge/pcTasks.cpp | 7 +++-- .../parallelScavenge/psCompactionManager.cpp | 12 ++++----- .../parallelScavenge/psCompactionManager.hpp | 6 ++++- .../psCompactionManager.inline.hpp | 17 +++++++++++- .../parallelScavenge/psMarkSweepDecorator.cpp | 6 ++--- .../parallelScavenge/psParallelCompact.cpp | 10 ++++--- .../parallelScavenge/psParallelCompact.hpp | 26 ------------------- .../parallelScavenge/psPromotionManager.cpp | 3 +-- .../parallelScavenge/psPromotionManager.hpp | 4 ++- .../psPromotionManager.inline.hpp | 7 +++-- .../parallelScavenge/psScavenge.cpp | 1 - .../parallelScavenge/psTasks.cpp | 1 - .../vm/gc_implementation/shared/markSweep.cpp | 10 ++++--- .../vm/gc_implementation/shared/markSweep.hpp | 6 +++++ .../shared/markSweep.inline.hpp | 12 +++++++-- hotspot/src/share/vm/memory/space.inline.hpp | 4 +-- .../vm/oops/instanceClassLoaderKlass.cpp | 3 +-- hotspot/src/share/vm/oops/instanceKlass.cpp | 1 - .../src/share/vm/oops/instanceMirrorKlass.cpp | 3 +-- .../src/share/vm/oops/instanceRefKlass.cpp | 3 +-- hotspot/src/share/vm/oops/objArrayKlass.cpp | 1 - 26 files changed, 82 insertions(+), 76 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index a9ef5dcad69..deb2e2af927 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -66,7 +66,6 @@ #include "memory/iterator.hpp" #include "memory/referenceProcessor.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #include "runtime/atomic.inline.hpp" #include "runtime/orderAccess.inline.hpp" #include "runtime/vmThread.hpp" diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp index 29020bc8782..38ec4a96c7e 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -33,6 +33,7 @@ #include "gc_implementation/g1/g1MarkSweep.hpp" #include "gc_implementation/g1/g1RootProcessor.hpp" #include "gc_implementation/g1/g1StringDedup.hpp" +#include "gc_implementation/shared/markSweep.inline.hpp" #include "gc_implementation/shared/gcHeapSummary.hpp" #include "gc_implementation/shared/gcTimer.hpp" #include "gc_implementation/shared/gcTrace.hpp" @@ -217,7 +218,7 @@ class G1AdjustPointersClosure: public HeapRegionClosure { // We must adjust the pointers on the single H object. oop obj = oop(r->bottom()); // point all the oops to the new location - obj->adjust_pointers(); + MarkSweep::adjust_pointers(obj); } } else { // This really ought to be "as_CompactibleSpace"... diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp index 2ec726e744e..6ffb5fe5902 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp @@ -27,7 +27,6 @@ #include "gc_implementation/g1/g1OopClosures.inline.hpp" #include "gc_implementation/g1/g1ParScanThreadState.inline.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #include "runtime/prefetch.inline.hpp" G1ParScanThreadState::G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp) diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index 11465b12ef3..f1be6547dd6 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -46,7 +46,6 @@ #include "memory/space.hpp" #include "oops/objArrayOop.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #include "runtime/atomic.inline.hpp" #include "runtime/handles.hpp" #include "runtime/handles.inline.hpp" diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp index 7448978578c..3523ff514d8 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp @@ -26,12 +26,11 @@ #include "gc_implementation/parallelScavenge/cardTableExtension.hpp" #include "gc_implementation/parallelScavenge/gcTaskManager.hpp" #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" -#include "gc_implementation/parallelScavenge/psPromotionManager.hpp" +#include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" #include "gc_implementation/parallelScavenge/psScavenge.hpp" #include "gc_implementation/parallelScavenge/psTasks.hpp" #include "gc_implementation/parallelScavenge/psYoungGen.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.psgc.inline.hpp" #include "runtime/prefetch.inline.hpp" // Checks an individual oop for missing precise marks. Mark @@ -291,7 +290,7 @@ void CardTableExtension::scavenge_contents_parallel(ObjectStartArray* start_arra Prefetch::write(p, interval); oop m = oop(p); assert(m->is_oop_or_null(), err_msg("Expected an oop or NULL for header field at " PTR_FORMAT, p2i(m))); - m->push_contents(pm); + pm->push_contents(m); p += m->size(); } pm->drain_stacks_cond_depth(); @@ -299,7 +298,7 @@ void CardTableExtension::scavenge_contents_parallel(ObjectStartArray* start_arra while (p < to) { oop m = oop(p); assert(m->is_oop_or_null(), err_msg("Expected an oop or NULL for header field at " PTR_FORMAT, p2i(m))); - m->push_contents(pm); + pm->push_contents(m); p += m->size(); } pm->drain_stacks_cond_depth(); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp index c277038c904..13ccf71c28c 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp @@ -27,6 +27,7 @@ #include "code/codeCache.hpp" #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" #include "gc_implementation/parallelScavenge/pcTasks.hpp" +#include "gc_implementation/parallelScavenge/psCompactionManager.inline.hpp" #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" #include "gc_implementation/shared/gcTimer.hpp" #include "gc_implementation/shared/gcTraceTime.hpp" @@ -34,7 +35,6 @@ #include "memory/universe.hpp" #include "oops/objArrayKlass.inline.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #include "prims/jvmtiExport.hpp" #include "runtime/fprofiler.hpp" #include "runtime/jniHandles.hpp" @@ -221,12 +221,11 @@ void StealMarkingTask::do_it(GCTaskManager* manager, uint which) { int random_seed = 17; do { while (ParCompactionManager::steal_objarray(which, &random_seed, task)) { - ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass(); - k->oop_follow_contents(cm, task.obj(), task.index()); + cm->follow_contents((objArrayOop)task.obj(), task.index()); cm->follow_marking_stacks(); } while (ParCompactionManager::steal(which, &random_seed, obj)) { - obj->follow_contents(cm); + cm->follow_contents(obj); cm->follow_marking_stacks(); } } while (!terminator()->offer_termination()); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.cpp index f838787bfdc..70b619f813d 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -28,12 +28,11 @@ #include "gc_implementation/parallelScavenge/objectStartArray.hpp" #include "gc_implementation/parallelScavenge/parMarkBitMap.hpp" #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" -#include "gc_implementation/parallelScavenge/psCompactionManager.hpp" +#include "gc_implementation/parallelScavenge/psCompactionManager.inline.hpp" #include "gc_implementation/parallelScavenge/psOldGen.hpp" #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" #include "oops/objArrayKlass.inline.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #include "runtime/atomic.inline.hpp" #include "utilities/stack.inline.hpp" @@ -180,17 +179,16 @@ void ParCompactionManager::follow_marking_stacks() { // Drain the overflow stack first, to allow stealing from the marking stack. oop obj; while (marking_stack()->pop_overflow(obj)) { - obj->follow_contents(this); + follow_contents(obj); } while (marking_stack()->pop_local(obj)) { - obj->follow_contents(this); + follow_contents(obj); } // Process ObjArrays one at a time to avoid marking stack bloat. ObjArrayTask task; if (_objarray_stack.pop_overflow(task) || _objarray_stack.pop_local(task)) { - ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass(); - k->oop_follow_contents(this, task.obj(), task.index()); + follow_contents((objArrayOop)task.obj(), task.index()); } } while (!marking_stacks_empty()); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.hpp index 7d7a9f495a1..4e5544da50d 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -196,6 +196,10 @@ private: // Process tasks remaining on any stack void drain_region_stacks(); + void follow_contents(oop obj); + void follow_contents(objArrayOop array, int index); + + void update_contents(oop obj); }; inline ParCompactionManager* ParCompactionManager::manager_array(int index) { diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.inline.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.inline.hpp index 6cf76353d9c..90c22306e7d 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.inline.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015 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 @@ -27,6 +27,8 @@ #include "gc_implementation/parallelScavenge/psCompactionManager.hpp" #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" +#include "oops/objArrayKlass.inline.hpp" +#include "oops/oop.pcgc.inline.hpp" void ParCompactionManager::push_objarray(oop obj, size_t index) { @@ -46,4 +48,17 @@ void ParCompactionManager::push_region(size_t index) region_stack()->push(index); } +inline void ParCompactionManager::follow_contents(oop obj) { + obj->follow_contents(this); +} + +inline void ParCompactionManager::follow_contents(objArrayOop obj, int index) { + ObjArrayKlass* k = (ObjArrayKlass*)obj->klass(); + k->oop_follow_contents(this, obj, index); +} + +inline void ParCompactionManager::update_contents(oop obj) { + obj->update_contents(this); +} + #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSCOMPACTIONMANAGER_INLINE_HPP diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweepDecorator.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweepDecorator.cpp index dc79821cb37..2cf025452b1 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweepDecorator.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweepDecorator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -303,7 +303,7 @@ void PSMarkSweepDecorator::adjust_pointers() { while (q < end) { // point all the oops to the new location - size_t size = oop(q)->adjust_pointers(); + size_t size = MarkSweep::adjust_pointers(oop(q)); q += size; } @@ -324,7 +324,7 @@ void PSMarkSweepDecorator::adjust_pointers() { if (oop(q)->is_gc_marked()) { // q is alive // point all the oops to the new location - size_t size = oop(q)->adjust_pointers(); + size_t size = MarkSweep::adjust_pointers(oop(q)); debug_only(prev_q = q); q += size; } else { diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp index 3e89b0a98e0..c262b0b5c95 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp @@ -50,7 +50,6 @@ #include "memory/referenceProcessor.hpp" #include "oops/methodData.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #include "runtime/atomic.inline.hpp" #include "runtime/fprofiler.hpp" #include "runtime/safepoint.hpp" @@ -2776,6 +2775,11 @@ void PSParallelCompact::verify_complete(SpaceId space_id) { } #endif // #ifdef ASSERT +inline void UpdateOnlyClosure::do_addr(HeapWord* addr) { + _start_array->allocate_block(addr); + compaction_manager()->update_contents(oop(addr)); +} + // Update interior oops in the ranges of regions [beg_region, end_region). void PSParallelCompact::update_and_deadwood_in_dense_prefix(ParCompactionManager* cm, @@ -2876,7 +2880,7 @@ void PSParallelCompact::update_deferred_objects(ParCompactionManager* cm, if (start_array != NULL) { start_array->allocate_block(addr); } - oop(addr)->update_contents(cm); + cm->update_contents(oop(addr)); assert(oop(addr)->is_oop_or_null(), err_msg("Expected an oop or NULL at " PTR_FORMAT, p2i(oop(addr)))); } } @@ -3360,7 +3364,7 @@ MoveAndUpdateClosure::do_addr(HeapWord* addr, size_t words) { } oop moved_oop = (oop) destination(); - moved_oop->update_contents(compaction_manager()); + compaction_manager()->update_contents(moved_oop); assert(moved_oop->is_oop_or_null(), err_msg("Expected an oop or NULL at " PTR_FORMAT, p2i(moved_oop))); update_state(words); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp index d402309851f..3e1f9198c57 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp @@ -1025,9 +1025,6 @@ class PSParallelCompact : AllStatic { bool maximum_heap_compaction, ParallelOldTracer *gc_tracer); - template - static inline void follow_root(ParCompactionManager* cm, T* p); - // Compute the dense prefix for the designated space. This is an experimental // implementation currently not used in production. static HeapWord* compute_dense_prefix_via_density(const SpaceId id, @@ -1335,23 +1332,6 @@ inline bool PSParallelCompact::is_marked(oop obj) { return mark_bitmap()->is_marked(obj); } -template -inline void PSParallelCompact::follow_root(ParCompactionManager* cm, T* p) { - assert(!Universe::heap()->is_in_reserved(p), - "roots shouldn't be things within the heap"); - - T heap_oop = oopDesc::load_heap_oop(p); - if (!oopDesc::is_null(heap_oop)) { - oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); - if (mark_bitmap()->is_unmarked(obj)) { - if (mark_obj(obj)) { - obj->follow_contents(cm); - } - } - } - cm->follow_marking_stacks(); -} - template inline void PSParallelCompact::mark_and_push(ParCompactionManager* cm, T* p) { T heap_oop = oopDesc::load_heap_oop(p); @@ -1524,12 +1504,6 @@ class UpdateOnlyClosure: public ParMarkBitMapClosure { inline void do_addr(HeapWord* addr); }; -inline void UpdateOnlyClosure::do_addr(HeapWord* addr) -{ - _start_array->allocate_block(addr); - oop(addr)->update_contents(compaction_manager()); -} - class FillClosure: public ParMarkBitMapClosure { public: diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp index 33d300fcbb7..cf79af15c4e 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp @@ -33,7 +33,6 @@ #include "memory/memRegion.hpp" #include "memory/padded.inline.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.psgc.inline.hpp" #include "utilities/stack.inline.hpp" PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC @@ -325,7 +324,7 @@ oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) { _promotion_failed_info.register_copy_failure(obj->size()); - obj->push_contents(this); + push_contents(obj); // Save the mark if needed PSScavenge::oop_promotion_failed(obj, obj_mark); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.hpp index b111ff2765a..d98ed220efd 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -212,6 +212,8 @@ class PSPromotionManager VALUE_OBJ_CLASS_SPEC { template inline void claim_or_forward_depth(T* p); TASKQUEUE_STATS_ONLY(inline void record_steal(StarTask& p);) + + void push_contents(oop obj); }; #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.inline.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.inline.hpp index 0ffe2df0788..cb6445fe13f 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.inline.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -91,6 +91,9 @@ inline void PSPromotionManager::promotion_trace_event(oop new_obj, oop old_obj, } } +inline void PSPromotionManager::push_contents(oop obj) { + obj->push_contents(this); +} // // This method is pretty bulky. It would be nice to split it up // into smaller submethods, but we need to be careful not to hurt @@ -227,7 +230,7 @@ oop PSPromotionManager::copy_to_survivor_space(oop o) { TASKQUEUE_STATS_ONLY(++_arrays_chunked; ++_masked_pushes); } else { // we'll just push its contents - new_obj->push_contents(this); + push_contents(new_obj); } } else { // We lost, someone else "owns" this object diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp index 3c0542f3b80..205170b8c65 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp @@ -46,7 +46,6 @@ #include "memory/referenceProcessor.hpp" #include "memory/resourceArea.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.psgc.inline.hpp" #include "runtime/biasedLocking.hpp" #include "runtime/fprofiler.hpp" #include "runtime/handles.inline.hpp" diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp index e944dfea010..5739331ab6a 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp @@ -35,7 +35,6 @@ #include "memory/iterator.hpp" #include "memory/universe.hpp" #include "oops/oop.inline.hpp" -#include "oops/oop.psgc.inline.hpp" #include "runtime/fprofiler.hpp" #include "runtime/thread.hpp" #include "runtime/vmThread.hpp" diff --git a/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp b/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp index 01e7e88f5b8..dadffdf01b5 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp +++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp @@ -64,18 +64,22 @@ void MarkSweep::follow_class_loader(ClassLoaderData* cld) { MarkSweep::follow_cld_closure.do_cld(cld); } +void MarkSweep::follow_array(objArrayOop array, int index) { + ObjArrayKlass* k = (ObjArrayKlass*)array->klass(); + k->oop_follow_contents(array, index); +} + void MarkSweep::follow_stack() { do { while (!_marking_stack.is_empty()) { oop obj = _marking_stack.pop(); assert (obj->is_gc_marked(), "p must be marked"); - obj->follow_contents(); + follow_object(obj); } // Process ObjArrays one at a time to avoid marking stack bloat. if (!_objarray_stack.is_empty()) { ObjArrayTask task = _objarray_stack.pop(); - ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass(); - k->oop_follow_contents(task.obj(), task.index()); + follow_array(objArrayOop(task.obj()), task.index()); } } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty()); } diff --git a/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp b/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp index 37928ea2ac6..724d212940c 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp +++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp @@ -160,10 +160,16 @@ class MarkSweep : AllStatic { static void follow_stack(); // Empty marking stack. + static void follow_object(oop obj); + + static void follow_array(objArrayOop array, int index); + static void follow_klass(Klass* klass); static void follow_class_loader(ClassLoaderData* cld); + static int adjust_pointers(oop obj); + static void preserve_mark(oop p, markOop mark); // Save the mark word so it can be restored later static void adjust_marks(); // Adjust the pointers in the preserved marks table diff --git a/hotspot/src/share/vm/gc_implementation/shared/markSweep.inline.hpp b/hotspot/src/share/vm/gc_implementation/shared/markSweep.inline.hpp index ebc89061a32..196dcad7a7f 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.inline.hpp +++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, 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 @@ -58,6 +58,10 @@ inline void MarkSweep::follow_klass(Klass* klass) { MarkSweep::mark_and_push(&op); } +inline void MarkSweep::follow_object(oop obj) { + obj->follow_contents(); +} + template inline void MarkSweep::follow_root(T* p) { assert(!Universe::heap()->is_in_reserved(p), "roots shouldn't be things within the heap"); @@ -66,7 +70,7 @@ template inline void MarkSweep::follow_root(T* p) { oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); if (!obj->mark()->is_marked()) { mark_object(obj); - obj->follow_contents(); + follow_object(obj); } } follow_stack(); @@ -90,6 +94,10 @@ void MarkSweep::push_objarray(oop obj, size_t index) { _objarray_stack.push(task); } +inline int MarkSweep::adjust_pointers(oop obj) { + return obj->adjust_pointers(); +} + template inline void MarkSweep::adjust_pointer(T* p) { T heap_oop = oopDesc::load_heap_oop(p); if (!oopDesc::is_null(heap_oop)) { diff --git a/hotspot/src/share/vm/memory/space.inline.hpp b/hotspot/src/share/vm/memory/space.inline.hpp index 6adfc5702a6..ccb81527586 100644 --- a/hotspot/src/share/vm/memory/space.inline.hpp +++ b/hotspot/src/share/vm/memory/space.inline.hpp @@ -214,7 +214,7 @@ inline void CompactibleSpace::scan_and_adjust_pointers(SpaceType* space) { assert(space->block_is_obj(q), "should be at block boundaries, and should be looking at objs"); // point all the oops to the new location - size_t size = oop(q)->adjust_pointers(); + size_t size = MarkSweep::adjust_pointers(oop(q)); size = space->adjust_obj_size(size); q += size; @@ -238,7 +238,7 @@ inline void CompactibleSpace::scan_and_adjust_pointers(SpaceType* space) { if (oop(q)->is_gc_marked()) { // q is alive // point all the oops to the new location - size_t size = oop(q)->adjust_pointers(); + size_t size = MarkSweep::adjust_pointers(oop(q)); size = space->adjust_obj_size(size); debug_only(prev_q = q); q += size; diff --git a/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp b/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp index f49e376cbfc..cf2eec97ee9 100644 --- a/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceClassLoaderKlass.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -42,7 +42,6 @@ #if INCLUDE_ALL_GCS #include "gc_implementation/parNew/parOopClosures.inline.hpp" #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #endif // INCLUDE_ALL_GCS // Macro to define InstanceClassLoaderKlass::oop_oop_iterate for virtual/nonvirtual for diff --git a/hotspot/src/share/vm/oops/instanceKlass.cpp b/hotspot/src/share/vm/oops/instanceKlass.cpp index 8d62afef112..f7ac70e3f45 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceKlass.cpp @@ -74,7 +74,6 @@ #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp" #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #endif // INCLUDE_ALL_GCS #ifdef COMPILER1 #include "c1/c1_Compiler.hpp" diff --git a/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp b/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp index 73d6e439d6d..191f1b85383 100644 --- a/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -47,7 +47,6 @@ #include "gc_implementation/parNew/parOopClosures.inline.hpp" #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #endif // INCLUDE_ALL_GCS int InstanceMirrorKlass::_offset_of_static_fields = 0; diff --git a/hotspot/src/share/vm/oops/instanceRefKlass.cpp b/hotspot/src/share/vm/oops/instanceRefKlass.cpp index 12804db3508..bf3cfa3dc8a 100644 --- a/hotspot/src/share/vm/oops/instanceRefKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceRefKlass.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -43,7 +43,6 @@ #include "gc_implementation/parNew/parOopClosures.inline.hpp" #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #endif // INCLUDE_ALL_GCS PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC diff --git a/hotspot/src/share/vm/oops/objArrayKlass.cpp b/hotspot/src/share/vm/oops/objArrayKlass.cpp index 8c2670c5214..ceaabf9d9b5 100644 --- a/hotspot/src/share/vm/oops/objArrayKlass.cpp +++ b/hotspot/src/share/vm/oops/objArrayKlass.cpp @@ -55,7 +55,6 @@ #include "gc_implementation/parallelScavenge/psCompactionManager.hpp" #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" -#include "oops/oop.pcgc.inline.hpp" #endif // INCLUDE_ALL_GCS ObjArrayKlass* ObjArrayKlass::allocate(ClassLoaderData* loader_data, int n, KlassHandle klass_handle, Symbol* name, TRAPS) { From 2c63bc9175ee033412babc014df472827aa91a66 Mon Sep 17 00:00:00 2001 From: Jesper Wilhelmsson Date: Mon, 16 Mar 2015 13:28:27 +0100 Subject: [PATCH 068/362] 8075635: Remove GenerationSpec array Replaced the array with explicit variables for young and old Reviewed-by: kbarrett, mgerdin --- .../jvm/hotspot/memory/GenCollectedHeap.java | 29 ++++++++----- .../cmsCollectorPolicy.cpp | 9 ++-- .../src/share/vm/memory/collectorPolicy.cpp | 10 ++--- .../src/share/vm/memory/collectorPolicy.hpp | 19 ++++++--- .../src/share/vm/memory/defNewGeneration.cpp | 2 +- .../src/share/vm/memory/genCollectedHeap.cpp | 42 +++++++------------ .../src/share/vm/memory/genCollectedHeap.hpp | 6 +-- hotspot/src/share/vm/memory/generation.cpp | 4 +- .../src/share/vm/memory/generationSpec.hpp | 18 +++----- hotspot/src/share/vm/runtime/vmStructs.cpp | 7 +++- .../src/share/vm/services/memoryService.cpp | 3 +- 11 files changed, 72 insertions(+), 77 deletions(-) diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/GenCollectedHeap.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/GenCollectedHeap.java index 26b107355b0..b39c4602043 100644 --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/GenCollectedHeap.java +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/GenCollectedHeap.java @@ -37,7 +37,9 @@ public class GenCollectedHeap extends SharedHeap { private static CIntegerField nGensField; private static AddressField youngGenField; private static AddressField oldGenField; - private static AddressField genSpecsField; + + private static AddressField youngGenSpecField; + private static AddressField oldGenSpecField; private static GenerationFactory genFactory; @@ -55,9 +57,12 @@ public class GenCollectedHeap extends SharedHeap { nGensField = type.getCIntegerField("_n_gens"); youngGenField = type.getAddressField("_young_gen"); oldGenField = type.getAddressField("_old_gen"); - genSpecsField = type.getAddressField("_gen_specs"); genFactory = new GenerationFactory(); + + Type collectorPolicyType = db.lookupType("GenCollectorPolicy"); + youngGenSpecField = collectorPolicyType.getAddressField("_young_gen_spec"); + oldGenSpecField = collectorPolicyType.getAddressField("_old_gen_spec"); } public GenCollectedHeap(Address addr) { @@ -115,21 +120,23 @@ public class GenCollectedHeap extends SharedHeap { /** Package-private access to GenerationSpecs */ GenerationSpec spec(int level) { if (Assert.ASSERTS_ENABLED) { - Assert.that((level >= 0) && (level < nGens()), "Index " + level + - " out of range (should be between 0 and " + nGens() + ")"); + Assert.that((level == 0) || (level == 1), "Index " + level + + " out of range (should be 0 or 1)"); } - if ((level < 0) || (level >= nGens())) { + if ((level != 0) && (level != 1)) { return null; } - Address ptrList = genSpecsField.getValue(addr); - if (ptrList == null) { - return null; + if (level == 0) { + return (GenerationSpec) + VMObjectFactory.newObject(GenerationSpec.class, + youngGenSpecField.getAddress()); + } else { + return (GenerationSpec) + VMObjectFactory.newObject(GenerationSpec.class, + oldGenSpecField.getAddress()); } - return (GenerationSpec) - VMObjectFactory.newObject(GenerationSpec.class, - ptrList.getAddressAt(level * VM.getVM().getAddressSize())); } public CollectedHeapName kind() { diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp index 0bc3a84dba4..a4960ad4f72 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2015, 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 @@ -52,9 +52,10 @@ void ConcurrentMarkSweepPolicy::initialize_alignments() { } void ConcurrentMarkSweepPolicy::initialize_generations() { - _generations = NEW_C_HEAP_ARRAY(GenerationSpecPtr, number_of_generations(), mtGC); - _generations[0] = new GenerationSpec(Generation::ParNew, _initial_young_size, _max_young_size); - _generations[1] = new GenerationSpec(Generation::ConcurrentMarkSweep, _initial_old_size, _max_old_size); + _young_gen_spec = new GenerationSpec(Generation::ParNew, _initial_young_size, + _max_young_size, _gen_alignment); + _old_gen_spec = new GenerationSpec(Generation::ConcurrentMarkSweep, + _initial_old_size, _max_old_size, _gen_alignment); } void ConcurrentMarkSweepPolicy::initialize_size_policy(size_t init_eden_size, diff --git a/hotspot/src/share/vm/memory/collectorPolicy.cpp b/hotspot/src/share/vm/memory/collectorPolicy.cpp index d20c2536e32..094e3c3e28e 100644 --- a/hotspot/src/share/vm/memory/collectorPolicy.cpp +++ b/hotspot/src/share/vm/memory/collectorPolicy.cpp @@ -190,11 +190,12 @@ GenCollectorPolicy::GenCollectorPolicy() : _min_young_size(0), _initial_young_size(0), _max_young_size(0), - _gen_alignment(0), _min_old_size(0), _initial_old_size(0), _max_old_size(0), - _generations(NULL) + _gen_alignment(0), + _young_gen_spec(NULL), + _old_gen_spec(NULL) {} size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) { @@ -912,9 +913,8 @@ void MarkSweepPolicy::initialize_alignments() { } void MarkSweepPolicy::initialize_generations() { - _generations = NEW_C_HEAP_ARRAY(GenerationSpecPtr, number_of_generations(), mtGC); - _generations[0] = new GenerationSpec(Generation::DefNew, _initial_young_size, _max_young_size); - _generations[1] = new GenerationSpec(Generation::MarkSweepCompact, _initial_old_size, _max_old_size); + _young_gen_spec = new GenerationSpec(Generation::DefNew, _initial_young_size, _max_young_size, _gen_alignment); + _old_gen_spec = new GenerationSpec(Generation::MarkSweepCompact, _initial_old_size, _max_old_size, _gen_alignment); } void MarkSweepPolicy::initialize_gc_policy_counters() { diff --git a/hotspot/src/share/vm/memory/collectorPolicy.hpp b/hotspot/src/share/vm/memory/collectorPolicy.hpp index 6f20be7f6dc..365a0ebe734 100644 --- a/hotspot/src/share/vm/memory/collectorPolicy.hpp +++ b/hotspot/src/share/vm/memory/collectorPolicy.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -208,7 +208,8 @@ class ClearedAllSoftRefs : public StackObj { }; class GenCollectorPolicy : public CollectorPolicy { -friend class TestGenCollectorPolicy; + friend class TestGenCollectorPolicy; + friend class VMStructs; protected: size_t _min_young_size; size_t _initial_young_size; @@ -221,7 +222,8 @@ friend class TestGenCollectorPolicy; // time. When using large pages they can differ. size_t _gen_alignment; - GenerationSpec **_generations; + GenerationSpec* _young_gen_spec; + GenerationSpec* _old_gen_spec; // Return true if an allocation should be attempted in the older generation // if it fails in the younger generation. Return false, otherwise. @@ -261,9 +263,14 @@ friend class TestGenCollectorPolicy; int number_of_generations() { return 2; } - virtual GenerationSpec **generations() { - assert(_generations != NULL, "Sanity check"); - return _generations; + GenerationSpec* young_gen_spec() const { + assert(_young_gen_spec != NULL, "_young_gen_spec should have been initialized"); + return _young_gen_spec; + } + + GenerationSpec* old_gen_spec() const { + assert(_old_gen_spec != NULL, "_old_gen_spec should have been initialized"); + return _old_gen_spec; } virtual GenCollectorPolicy* as_generation_policy() { return this; } diff --git a/hotspot/src/share/vm/memory/defNewGeneration.cpp b/hotspot/src/share/vm/memory/defNewGeneration.cpp index 0f5b2236555..c0eeb620010 100644 --- a/hotspot/src/share/vm/memory/defNewGeneration.cpp +++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp @@ -380,7 +380,7 @@ void DefNewGeneration::compute_new_size() { int next_level = level() + 1; GenCollectedHeap* gch = GenCollectedHeap::heap(); - assert(next_level < gch->_n_gens, + assert(next_level < gch->n_gens(), "DefNewGeneration cannot be an oldest gen"); Generation* old_gen = gch->old_gen(); diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.cpp b/hotspot/src/share/vm/memory/genCollectedHeap.cpp index 704291f0d94..64c37b3655c 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp @@ -90,7 +90,6 @@ GenCollectedHeap::GenCollectedHeap(GenCollectorPolicy *policy) : jint GenCollectedHeap::initialize() { CollectedHeap::pre_initialize(); - int i; _n_gens = gen_policy()->number_of_generations(); assert(_n_gens == 2, "There is no support for more than two generations"); @@ -101,16 +100,6 @@ jint GenCollectedHeap::initialize() { // HeapWordSize). guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize"); - // The heap must be at least as aligned as generations. - size_t gen_alignment = Generation::GenGrain; - - _gen_specs = gen_policy()->generations(); - - // Make sure the sizes are all aligned. - for (i = 0; i < _n_gens; i++) { - _gen_specs[i]->align(gen_alignment); - } - // Allocate space for the heap. char* heap_address; @@ -133,12 +122,12 @@ jint GenCollectedHeap::initialize() { _gch = this; - ReservedSpace young_rs = heap_rs.first_part(_gen_specs[0]->max_size(), false, false); - _young_gen = _gen_specs[0]->init(young_rs, 0, rem_set()); - heap_rs = heap_rs.last_part(_gen_specs[0]->max_size()); + ReservedSpace young_rs = heap_rs.first_part(gen_policy()->young_gen_spec()->max_size(), false, false); + _young_gen = gen_policy()->young_gen_spec()->init(young_rs, 0, rem_set()); + heap_rs = heap_rs.last_part(gen_policy()->young_gen_spec()->max_size()); - ReservedSpace old_rs = heap_rs.first_part(_gen_specs[1]->max_size(), false, false); - _old_gen = _gen_specs[1]->init(old_rs, 1, rem_set()); + ReservedSpace old_rs = heap_rs.first_part(gen_policy()->old_gen_spec()->max_size(), false, false); + _old_gen = gen_policy()->old_gen_spec()->init(old_rs, 1, rem_set()); clear_incremental_collection_failed(); #if INCLUDE_ALL_GCS @@ -155,21 +144,18 @@ jint GenCollectedHeap::initialize() { char* GenCollectedHeap::allocate(size_t alignment, ReservedSpace* heap_rs){ - const char overflow_msg[] = "The size of the object heap + VM data exceeds " - "the maximum representable size"; - // Now figure out the total size. - size_t total_reserved = 0; - const size_t pageSize = UseLargePages ? - os::large_page_size() : os::vm_page_size(); - + const size_t pageSize = UseLargePages ? os::large_page_size() : os::vm_page_size(); assert(alignment % pageSize == 0, "Must be"); - for (int i = 0; i < _n_gens; i++) { - total_reserved += _gen_specs[i]->max_size(); - if (total_reserved < _gen_specs[i]->max_size()) { - vm_exit_during_initialization(overflow_msg); - } + GenerationSpec* young_spec = gen_policy()->young_gen_spec(); + GenerationSpec* old_spec = gen_policy()->old_gen_spec(); + + // Check for overflow. + size_t total_reserved = young_spec->max_size() + old_spec->max_size(); + if (total_reserved < young_spec->max_size()) { + vm_exit_during_initialization("The size of the object heap + VM data exceeds " + "the maximum representable size"); } assert(total_reserved % alignment == 0, err_msg("Gen size; total_reserved=" SIZE_FORMAT ", alignment=" diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.hpp b/hotspot/src/share/vm/memory/genCollectedHeap.hpp index d6193770905..bcc20bcd2aa 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp @@ -67,8 +67,6 @@ public: Generation* _young_gen; Generation* _old_gen; - GenerationSpec** _gen_specs; - // The singleton Gen Remembered Set. GenRemSet* _rem_set; @@ -145,8 +143,8 @@ public: return CollectedHeap::GenCollectedHeap; } - Generation* young_gen() { return _young_gen; } - Generation* old_gen() { return _old_gen; } + Generation* young_gen() const { return _young_gen; } + Generation* old_gen() const { return _old_gen; } // The generational collector policy. GenCollectorPolicy* gen_policy() const { return _gen_policy; } diff --git a/hotspot/src/share/vm/memory/generation.cpp b/hotspot/src/share/vm/memory/generation.cpp index 6bed336c174..205cbce34a4 100644 --- a/hotspot/src/share/vm/memory/generation.cpp +++ b/hotspot/src/share/vm/memory/generation.cpp @@ -63,8 +63,8 @@ Generation::Generation(ReservedSpace rs, size_t initial_size, int level) : GenerationSpec* Generation::spec() { GenCollectedHeap* gch = GenCollectedHeap::heap(); - assert(0 <= level() && level() < gch->_n_gens, "Bad gen level"); - return gch->_gen_specs[level()]; + assert(level() == 0 || level() == 1, "Bad gen level"); + return level() == 0 ? gch->gen_policy()->young_gen_spec() : gch->gen_policy()->old_gen_spec(); } size_t Generation::max_capacity() const { diff --git a/hotspot/src/share/vm/memory/generationSpec.hpp b/hotspot/src/share/vm/memory/generationSpec.hpp index 58448a496af..5c0e57ed14b 100644 --- a/hotspot/src/share/vm/memory/generationSpec.hpp +++ b/hotspot/src/share/vm/memory/generationSpec.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -39,11 +39,11 @@ private: size_t _max_size; public: - GenerationSpec(Generation::Name name, size_t init_size, size_t max_size) { - _name = name; - _init_size = init_size; - _max_size = max_size; - } + GenerationSpec(Generation::Name name, size_t init_size, size_t max_size, size_t alignment) : + _name(name), + _init_size(align_size_up(init_size, alignment)), + _max_size(align_size_up(max_size, alignment)) + { } Generation* init(ReservedSpace rs, int level, GenRemSet* remset); @@ -53,12 +53,6 @@ public: void set_init_size(size_t size) { _init_size = size; } size_t max_size() const { return _max_size; } void set_max_size(size_t size) { _max_size = size; } - - // Alignment - void align(size_t alignment) { - set_init_size(align_size_up(init_size(), alignment)); - set_max_size(align_size_up(max_size(), alignment)); - } }; typedef GenerationSpec* GenerationSpecPtr; diff --git a/hotspot/src/share/vm/runtime/vmStructs.cpp b/hotspot/src/share/vm/runtime/vmStructs.cpp index 727d3ace8d2..8524679cbc3 100644 --- a/hotspot/src/share/vm/runtime/vmStructs.cpp +++ b/hotspot/src/share/vm/runtime/vmStructs.cpp @@ -527,11 +527,11 @@ typedef CompactHashtable SymbolCompactHashTable; nonstatic_field(CollectedHeap, _defer_initial_card_mark, bool) \ nonstatic_field(CollectedHeap, _is_gc_active, bool) \ nonstatic_field(CollectedHeap, _total_collections, unsigned int) \ + \ nonstatic_field(CompactibleSpace, _compaction_top, HeapWord*) \ nonstatic_field(CompactibleSpace, _first_dead, HeapWord*) \ nonstatic_field(CompactibleSpace, _end_of_live, HeapWord*) \ \ - \ nonstatic_field(ContiguousSpace, _top, HeapWord*) \ nonstatic_field(ContiguousSpace, _concurrent_iteration_safe_limit, HeapWord*) \ nonstatic_field(ContiguousSpace, _saved_mark_word, HeapWord*) \ @@ -559,7 +559,9 @@ typedef CompactHashtable SymbolCompactHashTable; nonstatic_field(GenCollectedHeap, _young_gen, Generation*) \ nonstatic_field(GenCollectedHeap, _old_gen, Generation*) \ nonstatic_field(GenCollectedHeap, _n_gens, int) \ - nonstatic_field(GenCollectedHeap, _gen_specs, GenerationSpec**) \ + \ + nonstatic_field(GenCollectorPolicy, _young_gen_spec, GenerationSpec*) \ + nonstatic_field(GenCollectorPolicy, _old_gen_spec, GenerationSpec*) \ \ nonstatic_field(HeapWord, i, char*) \ \ @@ -1505,6 +1507,7 @@ typedef CompactHashtable SymbolCompactHashTable; declare_type(DefNewGeneration, Generation) \ declare_type(CardGeneration, Generation) \ declare_type(TenuredGeneration, CardGeneration) \ + declare_toplevel_type(GenCollectorPolicy) \ declare_toplevel_type(Space) \ declare_toplevel_type(BitMap) \ declare_type(CompactibleSpace, Space) \ diff --git a/hotspot/src/share/vm/services/memoryService.cpp b/hotspot/src/share/vm/services/memoryService.cpp index 794f4621ca5..89e57affaa3 100644 --- a/hotspot/src/share/vm/services/memoryService.cpp +++ b/hotspot/src/share/vm/services/memoryService.cpp @@ -130,8 +130,7 @@ void MemoryService::add_gen_collected_heap_info(GenCollectedHeap* heap) { GenCollectorPolicy* gen_policy = policy->as_generation_policy(); if (gen_policy != NULL) { - GenerationSpec** specs = gen_policy->generations(); - Generation::Name kind = specs[0]->name(); + Generation::Name kind = gen_policy->young_gen_spec()->name(); switch (kind) { case Generation::DefNew: _minor_gc_manager = MemoryManager::get_copy_memory_manager(); From 012666647ca92109b394dd4b1973b79a69f2c7b5 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Mon, 16 Mar 2015 20:32:45 +0300 Subject: [PATCH 069/362] 8073008: press-and-hold input method for accented characters works incorrectly on OS X Reviewed-by: azvegint, alexp --- .../java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m index 34b997988b4..e7466fc5cba 100644 --- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m +++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @@ -311,7 +311,10 @@ AWT_ASSERT_APPKIT_THREAD; } - (BOOL) performKeyEquivalent: (NSEvent *) event { - [self deliverJavaKeyEventHelper: event]; + // if IM is active key events should be ignored + if (![self hasMarkedText] && !fInPressAndHold) { + [self deliverJavaKeyEventHelper: event]; + } // Workaround for 8020209: special case for "Cmd =" and "Cmd ." // because Cocoa calls performKeyEquivalent twice for these keystrokes From 72f3a466e0eab223530607d73d06749d5fb7ad40 Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Tue, 17 Mar 2015 14:38:22 +0400 Subject: [PATCH 070/362] 8040328: JSlider has wrong preferred size with Synth LAF Reviewed-by: alexsch, ant --- .../javax/swing/plaf/synth/SynthSliderUI.java | 6 +- .../swing/plaf/synth/8040328/bug8040328.java | 98 +++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 jdk/test/javax/swing/plaf/synth/8040328/bug8040328.java diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java index 2116e65a0f4..912f3f43e7f 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java @@ -308,14 +308,14 @@ public class SynthSliderUI extends BasicSliderUI public Dimension getPreferredSize(JComponent c) { recalculateIfInsetsChanged(); Dimension d = new Dimension(contentRect.width, contentRect.height); + Insets i = slider.getInsets(); if (slider.getOrientation() == JSlider.VERTICAL) { d.height = 200; + d.height += i.top + i.bottom; } else { d.width = 200; + d.width += i.left + i.right; } - Insets i = slider.getInsets(); - d.width += i.left + i.right; - d.height += i.top + i.bottom; return d; } diff --git a/jdk/test/javax/swing/plaf/synth/8040328/bug8040328.java b/jdk/test/javax/swing/plaf/synth/8040328/bug8040328.java new file mode 100644 index 00000000000..72a0e46885f --- /dev/null +++ b/jdk/test/javax/swing/plaf/synth/8040328/bug8040328.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* @test + @bug 8040328 + @summary JSlider has wrong preferred size with Synth LAF + @author Semyon Sadetsky +*/ + +import javax.swing.*; +import javax.swing.plaf.synth.SynthLookAndFeel; +import java.awt.*; +import java.io.ByteArrayInputStream; + +public class bug8040328 { + private static String synthXml = "" + + " " + + " " + + " " + + " " + + ""; + + public static void main(String[] args) throws Exception { + SynthLookAndFeel lookAndFeel = new SynthLookAndFeel(); + lookAndFeel.load(new ByteArrayInputStream(synthXml.getBytes("UTF8")), + bug8040328.class); + UIManager.setLookAndFeel(lookAndFeel); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + final JFrame frame = new JFrame(); + try { + frame.setUndecorated(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + test(frame); + } finally { + frame.dispose(); + } + } + }); + System.out.println("ok"); + } + + static void test(JFrame frame) { + JSlider hslider = new JSlider(JSlider.HORIZONTAL); + hslider.setBackground(Color.DARK_GRAY); + frame.getContentPane().add(hslider, BorderLayout.CENTER); + frame.getContentPane().setBackground(Color.CYAN); + frame.pack(); + Insets insets = hslider.getInsets(); + if (hslider.getWidth() != 200 + insets.left + insets.right) { + throw new RuntimeException( + "Horizontal slider width is wrong " + hslider.getWidth()); + } + if (hslider.getHeight() != hslider.getMinimumSize().height) { + throw new RuntimeException( + "Horizontal slider height is wrong " + hslider.getHeight()); + } + frame.getContentPane().remove(hslider); + + JSlider vslider = new JSlider(JSlider.VERTICAL); + frame.getContentPane().add(vslider); + frame.pack(); + insets = vslider.getInsets(); + if (vslider.getWidth() != vslider.getMinimumSize().width) { + throw new RuntimeException( + "Verical slider width is wrong " + vslider.getWidth()); + } + if (vslider.getHeight() != 200 + insets.top + insets.bottom) { + throw new RuntimeException( + "Verical slider height is wrong " + vslider.getHeight()); + } + } +} From fd46a24a3e4f2dc763bed06b524dbde5e3a97ce3 Mon Sep 17 00:00:00 2001 From: Bengt Rutisson Date: Fri, 27 Mar 2015 09:28:47 +0100 Subject: [PATCH 071/362] 8076076: Move SharedHeap::print_size_transition() into G1 code Reviewed-by: tschatzl, mgerdin --- .../vm/gc_implementation/g1/concurrentMark.cpp | 5 +---- .../gc_implementation/g1/g1CollectorPolicy.cpp | 18 ++++++++++++++---- .../gc_implementation/g1/g1CollectorPolicy.hpp | 2 ++ hotspot/src/share/vm/memory/sharedHeap.cpp | 14 -------------- hotspot/src/share/vm/memory/sharedHeap.hpp | 10 ---------- 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp index c91b5bcf09c..49116d28b37 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp @@ -2088,10 +2088,7 @@ void ConcurrentMark::cleanup() { _cleanup_times.add((end - start) * 1000.0); if (G1Log::fine()) { - g1h->print_size_transition(gclog_or_tty, - start_used_bytes, - g1h->used(), - g1h->capacity()); + g1h->g1_policy()->print_heap_transition(start_used_bytes); } // Clean up will have freed any regions completely full of garbage. diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp index bbb23748bf7..0be44bd25c5 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp @@ -1201,11 +1201,21 @@ void G1CollectorPolicy::record_heap_size_info_at_start(bool full) { } } +void G1CollectorPolicy::print_heap_transition(size_t bytes_before) { + size_t bytes_after = _g1->used(); + size_t capacity = _g1->capacity(); + + gclog_or_tty->print(" " SIZE_FORMAT "%s->" SIZE_FORMAT "%s(" SIZE_FORMAT "%s)", + byte_size_in_proper_unit(bytes_before), + proper_unit_for_byte_size(bytes_before), + byte_size_in_proper_unit(bytes_after), + proper_unit_for_byte_size(bytes_after), + byte_size_in_proper_unit(capacity), + proper_unit_for_byte_size(capacity)); +} + void G1CollectorPolicy::print_heap_transition() { - _g1->print_size_transition(gclog_or_tty, - _heap_used_bytes_before_gc, - _g1->used(), - _g1->capacity()); + print_heap_transition(_heap_used_bytes_before_gc); } void G1CollectorPolicy::print_detailed_heap_transition(bool full) { diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp index a4236a0a369..3cee9369634 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp @@ -700,6 +700,8 @@ public: void record_heap_size_info_at_start(bool full); // Print heap sizing transition (with less and more detail). + + void print_heap_transition(size_t bytes_before); void print_heap_transition(); void print_detailed_heap_transition(bool full = false); diff --git a/hotspot/src/share/vm/memory/sharedHeap.cpp b/hotspot/src/share/vm/memory/sharedHeap.cpp index 27672c8168d..1dde1e13c5e 100644 --- a/hotspot/src/share/vm/memory/sharedHeap.cpp +++ b/hotspot/src/share/vm/memory/sharedHeap.cpp @@ -102,17 +102,3 @@ void SharedHeap::post_initialize() { } void SharedHeap::ref_processing_init() {} - -// Some utilities. -void SharedHeap::print_size_transition(outputStream* out, - size_t bytes_before, - size_t bytes_after, - size_t capacity) { - out->print(" " SIZE_FORMAT "%s->" SIZE_FORMAT "%s(" SIZE_FORMAT "%s)", - byte_size_in_proper_unit(bytes_before), - proper_unit_for_byte_size(bytes_before), - byte_size_in_proper_unit(bytes_after), - proper_unit_for_byte_size(bytes_after), - byte_size_in_proper_unit(capacity), - proper_unit_for_byte_size(capacity)); -} diff --git a/hotspot/src/share/vm/memory/sharedHeap.hpp b/hotspot/src/share/vm/memory/sharedHeap.hpp index 80717520249..dec846acef4 100644 --- a/hotspot/src/share/vm/memory/sharedHeap.hpp +++ b/hotspot/src/share/vm/memory/sharedHeap.hpp @@ -214,16 +214,6 @@ public: // Sets the number of parallel threads that will be doing tasks // (such as process roots) subsequently. virtual void set_par_threads(uint t); - - // - // New methods from CollectedHeap - // - - // Some utilities. - void print_size_transition(outputStream* out, - size_t bytes_before, - size_t bytes_after, - size_t capacity); }; #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP From dcd40878af612c98c1955656a2198d3e6d8689a7 Mon Sep 17 00:00:00 2001 From: David Lindholm Date: Fri, 27 Mar 2015 15:03:44 +0100 Subject: [PATCH 072/362] 8076054: g1: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files Reviewed-by: brutisso, stefank --- .../vm/gc_implementation/g1/g1CardCounts.cpp | 2 - .../g1/g1CodeCacheRemSet.cpp | 2 - .../vm/gc_implementation/g1/g1HRPrinter.cpp | 12 ++--- .../vm/gc_implementation/g1/g1RemSet.cpp | 8 ++- .../vm/gc_implementation/g1/heapRegion.cpp | 52 +++++++++---------- .../gc_implementation/g1/heapRegionRemSet.cpp | 32 ++++++------ .../vm/gc_implementation/g1/heapRegionSet.cpp | 13 +++-- .../vm/gc_implementation/g1/satbQueue.cpp | 4 +- .../vm/gc_implementation/g1/survRateGroup.cpp | 2 - 9 files changed, 55 insertions(+), 72 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp index 76bf8509aea..94f258afd6f 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp @@ -31,8 +31,6 @@ #include "services/memTracker.hpp" #include "utilities/copy.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - void G1CardCountsMappingChangedListener::on_commit(uint start_idx, size_t num_regions, bool zero_filled) { if (zero_filled) { return; diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp index f70375800e7..b09d8a8a31e 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp @@ -33,8 +33,6 @@ #include "utilities/hashtable.inline.hpp" #include "utilities/stack.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - class CodeRootSetTable : public Hashtable { friend class G1CodeRootSetTest; typedef HashtableEntry Entry; diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1HRPrinter.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1HRPrinter.cpp index 8139048ef23..68a2a96d73d 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1HRPrinter.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1HRPrinter.cpp @@ -27,8 +27,6 @@ #include "gc_implementation/g1/heapRegion.hpp" #include "utilities/ostream.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - const char* G1HRPrinter::action_name(ActionType action) { switch(action) { case Alloc: return "ALLOC"; @@ -85,18 +83,18 @@ void G1HRPrinter::print(ActionType action, RegionType type, if (type_str != NULL) { if (top != NULL) { gclog_or_tty->print_cr(G1HR_PREFIX" %s(%s) "PTR_FORMAT" "PTR_FORMAT, - action_str, type_str, bottom, top); + action_str, type_str, p2i(bottom), p2i(top)); } else { gclog_or_tty->print_cr(G1HR_PREFIX" %s(%s) "PTR_FORMAT, - action_str, type_str, bottom); + action_str, type_str, p2i(bottom)); } } else { if (top != NULL) { gclog_or_tty->print_cr(G1HR_PREFIX" %s "PTR_FORMAT" "PTR_FORMAT, - action_str, bottom, top); + action_str, p2i(bottom), p2i(top)); } else { gclog_or_tty->print_cr(G1HR_PREFIX" %s "PTR_FORMAT, - action_str, bottom); + action_str, p2i(bottom)); } } } @@ -105,7 +103,7 @@ void G1HRPrinter::print(ActionType action, HeapWord* bottom, HeapWord* end) { const char* action_str = action_name(action); gclog_or_tty->print_cr(G1HR_PREFIX" %s ["PTR_FORMAT","PTR_FORMAT"]", - action_str, bottom, end); + action_str, p2i(bottom), p2i(end)); } void G1HRPrinter::print(PhaseType phase, size_t phase_num) { diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp index eff64c4cd08..b452f9adca2 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp @@ -39,8 +39,6 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/intHisto.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - #define CARD_REPEAT_HISTO 0 #if CARD_REPEAT_HISTO @@ -156,9 +154,9 @@ public: "RS names card " SIZE_FORMAT_HEX ": " "[" PTR_FORMAT ", " PTR_FORMAT ")", _worker_i, - card_region->bottom(), card_region->end(), + p2i(card_region->bottom()), p2i(card_region->end()), card_index, - card_start, card_start + G1BlockOffsetSharedArray::N_words); + p2i(card_start), p2i(card_start + G1BlockOffsetSharedArray::N_words)); } void scan_strong_code_roots(HeapRegion* r) { @@ -428,7 +426,7 @@ bool G1RemSet::refine_card(jbyte* card_ptr, uint worker_i, err_msg("Card at "PTR_FORMAT" index "SIZE_FORMAT" representing heap at "PTR_FORMAT" (%u) must be in committed heap", p2i(card_ptr), _ct_bs->index_for(_ct_bs->addr_for(card_ptr)), - _ct_bs->addr_for(card_ptr), + p2i(_ct_bs->addr_for(card_ptr)), _g1->addr_to_region(_ct_bs->addr_for(card_ptr)))); // If the card is no longer dirty, nothing to do. diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp index 0d6c16e0e12..77f6c413287 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp @@ -39,8 +39,6 @@ #include "runtime/atomic.inline.hpp" #include "runtime/orderAccess.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - int HeapRegion::LogOfHRGrainBytes = 0; int HeapRegion::LogOfHRGrainWords = 0; size_t HeapRegion::GrainBytes = 0; @@ -505,7 +503,7 @@ class VerifyStrongCodeRootOopClosure: public OopClosure { gclog_or_tty->print_cr("Object "PTR_FORMAT" in region " "["PTR_FORMAT", "PTR_FORMAT") is above " "top "PTR_FORMAT, - (void *)obj, _hr->bottom(), _hr->end(), _hr->top()); + p2i(obj), p2i(_hr->bottom()), p2i(_hr->end()), p2i(_hr->top())); _failures = true; return; } @@ -540,7 +538,7 @@ public: if (!nm->is_alive()) { gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has dead nmethod " PTR_FORMAT" in its strong code roots", - _hr->bottom(), _hr->end(), nm); + p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm)); _failures = true; } else { VerifyStrongCodeRootOopClosure oop_cl(_hr, nm); @@ -549,12 +547,12 @@ public: gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has nmethod " PTR_FORMAT" in its strong code roots " "with no pointers into region", - _hr->bottom(), _hr->end(), nm); + p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm)); _failures = true; } else if (oop_cl.failures()) { gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has other " "failures for nmethod "PTR_FORMAT, - _hr->bottom(), _hr->end(), nm); + p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm)); _failures = true; } } @@ -589,7 +587,7 @@ void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const if (strong_code_roots_length > 0) { gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is empty " "but has "SIZE_FORMAT" code root entries", - bottom(), end(), strong_code_roots_length); + p2i(bottom()), p2i(end()), strong_code_roots_length); *failures = true; } return; @@ -624,7 +622,7 @@ void HeapRegion::print_on(outputStream* st) const { st->print(" "); st->print(" TS %5d", _gc_time_stamp); st->print(" PTAMS "PTR_FORMAT" NTAMS "PTR_FORMAT, - prev_top_at_mark_start(), next_top_at_mark_start()); + p2i(prev_top_at_mark_start()), p2i(next_top_at_mark_start())); G1OffsetTableContigSpace::print_on(st); } @@ -687,23 +685,23 @@ public: gclog_or_tty->print_cr("Field "PTR_FORMAT " of live obj "PTR_FORMAT" in region " "["PTR_FORMAT", "PTR_FORMAT")", - p, (void*) _containing_obj, - from->bottom(), from->end()); + p2i(p), p2i(_containing_obj), + p2i(from->bottom()), p2i(from->end())); print_object(gclog_or_tty, _containing_obj); gclog_or_tty->print_cr("points to obj "PTR_FORMAT" not in the heap", - (void*) obj); + p2i(obj)); } else { HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj); gclog_or_tty->print_cr("Field "PTR_FORMAT " of live obj "PTR_FORMAT" in region " "["PTR_FORMAT", "PTR_FORMAT")", - p, (void*) _containing_obj, - from->bottom(), from->end()); + p2i(p), p2i(_containing_obj), + p2i(from->bottom()), p2i(from->end())); print_object(gclog_or_tty, _containing_obj); gclog_or_tty->print_cr("points to dead obj "PTR_FORMAT" in region " "["PTR_FORMAT", "PTR_FORMAT")", - (void*) obj, to->bottom(), to->end()); + p2i(obj), p2i(to->bottom()), p2i(to->end())); print_object(gclog_or_tty, obj); } gclog_or_tty->print_cr("----------"); @@ -741,12 +739,12 @@ public: gclog_or_tty->print_cr("Field "PTR_FORMAT" " "of obj "PTR_FORMAT", " "in region "HR_FORMAT, - p, (void*) _containing_obj, + p2i(p), p2i(_containing_obj), HR_FORMAT_PARAMS(from)); _containing_obj->print_on(gclog_or_tty); gclog_or_tty->print_cr("points to obj "PTR_FORMAT" " "in region "HR_FORMAT, - (void*) obj, + p2i(obj), HR_FORMAT_PARAMS(to)); obj->print_on(gclog_or_tty); gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.", @@ -783,7 +781,7 @@ void HeapRegion::verify(VerifyOption vo, !g1->is_obj_dead(obj, this)) { // Dead objects may have bigger block_size since they span several objects. gclog_or_tty->print_cr("obj "PTR_FORMAT" is of %shumongous size (" SIZE_FORMAT" words) in a %shumongous region", - p, g1->is_humongous(obj_size) ? "" : "non-", + p2i(p), g1->is_humongous(obj_size) ? "" : "non-", obj_size, is_region_humongous ? "" : "non-"); *failures = true; return; @@ -797,12 +795,12 @@ void HeapRegion::verify(VerifyOption vo, ClassLoaderDataGraph::unload_list_contains(klass)); if (!is_metaspace_object) { gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" " - "not metadata", klass, (void *)obj); + "not metadata", p2i(klass), p2i(obj)); *failures = true; return; } else if (!klass->is_klass()) { gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" " - "not a klass", klass, (void *)obj); + "not a klass", p2i(klass), p2i(obj)); *failures = true; return; } else { @@ -817,7 +815,7 @@ void HeapRegion::verify(VerifyOption vo, } } } else { - gclog_or_tty->print_cr(PTR_FORMAT" no an oop", (void *)obj); + gclog_or_tty->print_cr(PTR_FORMAT" no an oop", p2i(obj)); *failures = true; return; } @@ -832,7 +830,7 @@ void HeapRegion::verify(VerifyOption vo, if (p != top()) { gclog_or_tty->print_cr("end of last object "PTR_FORMAT" " - "does not match top "PTR_FORMAT, p, top()); + "does not match top "PTR_FORMAT, p2i(p), p2i(top())); *failures = true; return; } @@ -849,7 +847,7 @@ void HeapRegion::verify(VerifyOption vo, if (b_start_1 != p) { gclog_or_tty->print_cr("BOT look up for top: "PTR_FORMAT" " " yielded "PTR_FORMAT", expecting "PTR_FORMAT, - addr_1, b_start_1, p); + p2i(addr_1), p2i(b_start_1), p2i(p)); *failures = true; return; } @@ -861,7 +859,7 @@ void HeapRegion::verify(VerifyOption vo, if (b_start_2 != p) { gclog_or_tty->print_cr("BOT look up for top + 1: "PTR_FORMAT" " " yielded "PTR_FORMAT", expecting "PTR_FORMAT, - addr_2, b_start_2, p); + p2i(addr_2), p2i(b_start_2), p2i(p)); *failures = true; return; } @@ -875,7 +873,7 @@ void HeapRegion::verify(VerifyOption vo, if (b_start_3 != p) { gclog_or_tty->print_cr("BOT look up for top + diff: "PTR_FORMAT" " " yielded "PTR_FORMAT", expecting "PTR_FORMAT, - addr_3, b_start_3, p); + p2i(addr_3), p2i(b_start_3), p2i(p)); *failures = true; return; } @@ -887,7 +885,7 @@ void HeapRegion::verify(VerifyOption vo, if (b_start_4 != p) { gclog_or_tty->print_cr("BOT look up for end - 1: "PTR_FORMAT" " " yielded "PTR_FORMAT", expecting "PTR_FORMAT, - addr_4, b_start_4, p); + p2i(addr_4), p2i(b_start_4), p2i(p)); *failures = true; return; } @@ -896,7 +894,7 @@ void HeapRegion::verify(VerifyOption vo, if (is_region_humongous && object_num > 1) { gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous " "but has "SIZE_FORMAT", objects", - bottom(), end(), object_num); + p2i(bottom()), p2i(end()), object_num); *failures = true; return; } @@ -947,7 +945,7 @@ void G1OffsetTableContigSpace::print() const { print_short(); gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", - bottom(), top(), _offsets.threshold(), end()); + p2i(bottom()), p2i(top()), p2i(_offsets.threshold()), p2i(end())); } HeapWord* G1OffsetTableContigSpace::initialize_threshold() { diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp index 835b8e2edd8..a8416bc9984 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp @@ -37,8 +37,6 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/growableArray.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - class PerRegionTable: public CHeapObj { friend class OtherRegionsTable; friend class HeapRegionRemSetIterator; @@ -93,10 +91,10 @@ protected: if (G1TraceHeapRegionRememberedSet) { gclog_or_tty->print_cr(" PRT::Add_reference_work(" PTR_FORMAT "->" PTR_FORMAT").", - from, + p2i(from), UseCompressedOops - ? (void *)oopDesc::load_decode_heap_oop((narrowOop*)from) - : (void *)oopDesc::load_decode_heap_oop((oop*)from)); + ? p2i(oopDesc::load_decode_heap_oop((narrowOop*)from)) + : p2i(oopDesc::load_decode_heap_oop((oop*)from))); } HeapRegion* loc_hr = hr(); @@ -412,17 +410,17 @@ void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, uint tid) { if (G1TraceHeapRegionRememberedSet) { gclog_or_tty->print_cr("ORT::add_reference_work(" PTR_FORMAT "->" PTR_FORMAT ").", - from, + p2i(from), UseCompressedOops - ? (void *)oopDesc::load_decode_heap_oop((narrowOop*)from) - : (void *)oopDesc::load_decode_heap_oop((oop*)from)); + ? p2i(oopDesc::load_decode_heap_oop((narrowOop*)from)) + : p2i(oopDesc::load_decode_heap_oop((oop*)from))); } int from_card = (int)(uintptr_t(from) >> CardTableModRefBS::card_shift); if (G1TraceHeapRegionRememberedSet) { gclog_or_tty->print_cr("Table for [" PTR_FORMAT "...): card %d (cache = %d)", - _hr->bottom(), from_card, + p2i(_hr->bottom()), from_card, FromCardCache::at(tid, cur_hrm_ind)); } @@ -471,7 +469,7 @@ void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, uint tid) { "[" PTR_FORMAT "...) for ref " PTR_FORMAT ".\n", align_size_down(uintptr_t(from), CardTableModRefBS::card_size), - _hr->bottom(), from); + p2i(_hr->bottom()), p2i(from)); } } if (G1TraceHeapRegionRememberedSet) { @@ -533,7 +531,7 @@ void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, uint tid) { "[" PTR_FORMAT "...) for ref " PTR_FORMAT ".\n", align_size_down(uintptr_t(from), CardTableModRefBS::card_size), - _hr->bottom(), from); + p2i(_hr->bottom()), p2i(from)); } } assert(contains_reference(from), "We just added it!"); @@ -602,8 +600,8 @@ PerRegionTable* OtherRegionsTable::delete_region_table() { if (G1TraceHeapRegionRememberedSet) { gclog_or_tty->print("Coarsened entry in region [" PTR_FORMAT "...] " "for region [" PTR_FORMAT "...] (" SIZE_FORMAT " coarse entries).\n", - _hr->bottom(), - max->hr()->bottom(), + p2i(_hr->bottom()), + p2i(max->hr()->bottom()), _n_coarse_entries); } } @@ -857,7 +855,7 @@ void HeapRegionRemSet::print() { while (iter.has_next(card_index)) { HeapWord* card_start = G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index); - gclog_or_tty->print_cr(" Card " PTR_FORMAT, card_start); + gclog_or_tty->print_cr(" Card " PTR_FORMAT, p2i(card_start)); } if (iter.n_yielded() != occupied()) { gclog_or_tty->print_cr("Yielded disagrees with occupied:"); @@ -1152,8 +1150,8 @@ void HeapRegionRemSet::print_recorded() { } gclog_or_tty->print("Added card " PTR_FORMAT " to region [" PTR_FORMAT "...]" " for ref " PTR_FORMAT ".\n", - _recorded_cards[i], _recorded_regions[i]->bottom(), - _recorded_oops[i]); + p2i(_recorded_cards[i]), p2i(_recorded_regions[i]->bottom()), + p2i(_recorded_oops[i])); } } @@ -1240,7 +1238,7 @@ void HeapRegionRemSet::test() { while (iter.has_next(card_index)) { HeapWord* card_start = G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index); - gclog_or_tty->print_cr(" Card " PTR_FORMAT ".", card_start); + gclog_or_tty->print_cr(" Card " PTR_FORMAT ".", p2i(card_start)); sum++; } guarantee(sum == 11 - 3 + 2048, "Failure"); diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp index 37a85aa0def..9657356c3bb 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp @@ -27,8 +27,6 @@ #include "gc_implementation/g1/heapRegionRemSet.hpp" #include "gc_implementation/g1/heapRegionSet.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - uint FreeRegionList::_unrealistically_long_length = 0; void HeapRegionSetBase::fill_in_ext_msg(hrs_ext_msg* msg, const char* message) { @@ -84,7 +82,7 @@ void HeapRegionSetBase::verify_end() { void HeapRegionSetBase::print_on(outputStream* out, bool print_contents) { out->cr(); - out->print_cr("Set: %s ("PTR_FORMAT")", name(), this); + out->print_cr("Set: %s ("PTR_FORMAT")", name(), p2i(this)); out->print_cr(" Region Assumptions"); out->print_cr(" humongous : %s", BOOL_TO_STR(regions_humongous())); out->print_cr(" free : %s", BOOL_TO_STR(regions_free())); @@ -106,7 +104,7 @@ void FreeRegionList::set_unrealistically_long_length(uint len) { } void FreeRegionList::fill_in_ext_msg_extra(hrs_ext_msg* msg) { - msg->append(" hd: "PTR_FORMAT" tl: "PTR_FORMAT, _head, _tail); + msg->append(" hd: "PTR_FORMAT" tl: "PTR_FORMAT, p2i(_head), p2i(_tail)); } void FreeRegionList::remove_all() { @@ -277,8 +275,8 @@ void FreeRegionList::clear() { void FreeRegionList::print_on(outputStream* out, bool print_contents) { HeapRegionSetBase::print_on(out, print_contents); out->print_cr(" Linking"); - out->print_cr(" head : "PTR_FORMAT, _head); - out->print_cr(" tail : "PTR_FORMAT, _tail); + out->print_cr(" head : "PTR_FORMAT, p2i(_head)); + out->print_cr(" tail : "PTR_FORMAT, p2i(_tail)); if (print_contents) { out->print_cr(" Contents"); @@ -306,7 +304,8 @@ void FreeRegionList::verify_list() { count++; guarantee(count < _unrealistically_long_length, - hrs_err_msg("[%s] the calculated length: %u seems very long, is there maybe a cycle? curr: "PTR_FORMAT" prev0: "PTR_FORMAT" " "prev1: "PTR_FORMAT" length: %u", name(), count, curr, prev0, prev1, length())); + hrs_err_msg("[%s] the calculated length: %u seems very long, is there maybe a cycle? curr: "PTR_FORMAT" prev0: "PTR_FORMAT" " "prev1: "PTR_FORMAT" length: %u", + name(), count, p2i(curr), p2i(prev0), p2i(prev1), length())); if (curr->next() != NULL) { guarantee(curr->next()->prev() == curr, "Next or prev pointers messed up"); diff --git a/hotspot/src/share/vm/gc_implementation/g1/satbQueue.cpp b/hotspot/src/share/vm/gc_implementation/g1/satbQueue.cpp index 2ab59657776..4da322feb7a 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/satbQueue.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/satbQueue.cpp @@ -32,8 +32,6 @@ #include "runtime/thread.hpp" #include "runtime/vmThread.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - void ObjPtrQueue::flush() { // The buffer might contain refs into the CSet. We have to filter it // first before we flush it, otherwise we might end up with an @@ -182,7 +180,7 @@ void ObjPtrQueue::print(const char* name, void** buf, size_t index, size_t sz) { gclog_or_tty->print_cr(" SATB BUFFER [%s] buf: "PTR_FORMAT" " "index: "SIZE_FORMAT" sz: "SIZE_FORMAT, - name, buf, index, sz); + name, p2i(buf), index, sz); } #endif // PRODUCT diff --git a/hotspot/src/share/vm/gc_implementation/g1/survRateGroup.cpp b/hotspot/src/share/vm/gc_implementation/g1/survRateGroup.cpp index 4a2ea6e5aea..13c812499d3 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/survRateGroup.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/survRateGroup.cpp @@ -29,8 +29,6 @@ #include "gc_implementation/g1/survRateGroup.hpp" #include "memory/allocation.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - SurvRateGroup::SurvRateGroup(G1CollectorPolicy* g1p, const char* name, size_t summary_surv_rates_len) : From 04fdb5ca76c14ce17d2c818f31dbd27e00f33929 Mon Sep 17 00:00:00 2001 From: David Lindholm Date: Fri, 27 Mar 2015 15:10:11 +0100 Subject: [PATCH 073/362] 8076055: cms: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files Reviewed-by: brutisso, tschatzl --- .../concurrentMarkSweepGeneration.cpp | 82 +++++++++---------- .../concurrentMarkSweep/freeChunk.cpp | 4 +- .../concurrentMarkSweep/promotionInfo.cpp | 6 +- .../concurrentMarkSweep/vmCMSOperations.cpp | 2 - 4 files changed, 43 insertions(+), 51 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp index e273c205a37..037abd9ffa6 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @@ -65,8 +65,6 @@ #include "services/memoryService.hpp" #include "services/runtimeService.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // statics CMSCollector* ConcurrentMarkSweepGeneration::_collector = NULL; bool CMSCollector::_full_gc_requested = false; @@ -1593,7 +1591,7 @@ void CMSCollector::acquire_control_and_collect(bool full, bitMapLock()->lock_without_safepoint_check(); if (TraceCMSState) { gclog_or_tty->print_cr("CMS foreground collector has asked for control " - INTPTR_FORMAT " with first state %d", Thread::current(), first_state); + INTPTR_FORMAT " with first state %d", p2i(Thread::current()), first_state); gclog_or_tty->print_cr(" gets control with state %d", _collectorState); } @@ -1763,27 +1761,27 @@ void CMSCollector::print_eden_and_survivor_chunk_arrays() { // Eden if (_eden_chunk_array != NULL) { gclog_or_tty->print_cr("eden " PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "(" SIZE_FORMAT ")", - eden_space->bottom(), eden_space->top(), - eden_space->end(), eden_space->capacity()); + p2i(eden_space->bottom()), p2i(eden_space->top()), + p2i(eden_space->end()), eden_space->capacity()); gclog_or_tty->print_cr("_eden_chunk_index=" SIZE_FORMAT ", " "_eden_chunk_capacity=" SIZE_FORMAT, _eden_chunk_index, _eden_chunk_capacity); for (size_t i = 0; i < _eden_chunk_index; i++) { gclog_or_tty->print_cr("_eden_chunk_array[" SIZE_FORMAT "]=" PTR_FORMAT, - i, _eden_chunk_array[i]); + i, p2i(_eden_chunk_array[i])); } } // Survivor if (_survivor_chunk_array != NULL) { gclog_or_tty->print_cr("survivor " PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "(" SIZE_FORMAT ")", - from_space->bottom(), from_space->top(), - from_space->end(), from_space->capacity()); + p2i(from_space->bottom()), p2i(from_space->top()), + p2i(from_space->end()), from_space->capacity()); gclog_or_tty->print_cr("_survivor_chunk_index=" SIZE_FORMAT ", " "_survivor_chunk_capacity=" SIZE_FORMAT, _survivor_chunk_index, _survivor_chunk_capacity); for (size_t i = 0; i < _survivor_chunk_index; i++) { gclog_or_tty->print_cr("_survivor_chunk_array[" SIZE_FORMAT "]=" PTR_FORMAT, - i, _survivor_chunk_array[i]); + i, p2i(_survivor_chunk_array[i])); } } } @@ -1890,7 +1888,7 @@ void CMSCollector::collect_in_background(GCCause::Cause cause) { while (_collectorState != Idling) { if (TraceCMSState) { gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " in CMS state %d", - Thread::current(), _collectorState); + p2i(Thread::current()), _collectorState); } // The foreground collector // holds the Heap_lock throughout its collection. @@ -1924,7 +1922,7 @@ void CMSCollector::collect_in_background(GCCause::Cause cause) { if (TraceCMSState) { gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " exiting collection CMS state %d", - Thread::current(), _collectorState); + p2i(Thread::current()), _collectorState); } return; } else { @@ -2031,7 +2029,7 @@ void CMSCollector::collect_in_background(GCCause::Cause cause) { } if (TraceCMSState) { gclog_or_tty->print_cr(" Thread " INTPTR_FORMAT " done - next CMS state %d", - Thread::current(), _collectorState); + p2i(Thread::current()), _collectorState); } assert(_foregroundGCShouldWait, "block post-condition"); } @@ -2054,7 +2052,7 @@ void CMSCollector::collect_in_background(GCCause::Cause cause) { if (TraceCMSState) { gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " exiting collection CMS state %d", - Thread::current(), _collectorState); + p2i(Thread::current()), _collectorState); } if (PrintGC && Verbose) { _cmsGen->print_heap_change(prev_used); @@ -2112,7 +2110,7 @@ bool CMSCollector::waitForForegroundGC() { CGC_lock->notify(); if (TraceCMSState) { gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " waiting at CMS state %d", - Thread::current(), _collectorState); + p2i(Thread::current()), _collectorState); } while (_foregroundGCIsActive) { CGC_lock->wait(Mutex::_no_safepoint_check_flag); @@ -2124,7 +2122,7 @@ bool CMSCollector::waitForForegroundGC() { } if (TraceCMSState) { gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " continuing at CMS state %d", - Thread::current(), _collectorState); + p2i(Thread::current()), _collectorState); } return res; } @@ -2356,13 +2354,13 @@ bool CMSCollector::is_cms_reachable(HeapWord* addr) { // Clear the marking bit map array before starting, but, just // for kicks, first report if the given address is already marked - gclog_or_tty->print_cr("Start: Address " PTR_FORMAT " is%s marked", addr, + gclog_or_tty->print_cr("Start: Address " PTR_FORMAT " is%s marked", p2i(addr), _markBitMap.isMarked(addr) ? "" : " not"); if (verify_after_remark()) { MutexLockerEx x(verification_mark_bm()->lock(), Mutex::_no_safepoint_check_flag); bool result = verification_mark_bm()->isMarked(addr); - gclog_or_tty->print_cr("TransitiveMark: Address " PTR_FORMAT " %s marked", addr, + gclog_or_tty->print_cr("TransitiveMark: Address " PTR_FORMAT " %s marked", p2i(addr), result ? "IS" : "is NOT"); return result; } else { @@ -2377,13 +2375,13 @@ CMSCollector::print_on_error(outputStream* st) { CMSCollector* collector = ConcurrentMarkSweepGeneration::_collector; if (collector != NULL) { CMSBitMap* bitmap = &collector->_markBitMap; - st->print_cr("Marking Bits: (CMSBitMap*) " PTR_FORMAT, bitmap); + st->print_cr("Marking Bits: (CMSBitMap*) " PTR_FORMAT, p2i(bitmap)); bitmap->print_on_error(st, " Bits: "); st->cr(); CMSBitMap* mut_bitmap = &collector->_modUnionTable; - st->print_cr("Mod Union Table: (CMSBitMap*) " PTR_FORMAT, mut_bitmap); + st->print_cr("Mod Union Table: (CMSBitMap*) " PTR_FORMAT, p2i(mut_bitmap)); mut_bitmap->print_on_error(st, " Bits: "); } } @@ -2406,7 +2404,7 @@ class VerifyMarkedClosure: public BitMapClosure { HeapWord* addr = _marks->offsetToHeapWord(offset); if (!_marks->isMarked(addr)) { oop(addr)->print_on(gclog_or_tty); - gclog_or_tty->print_cr(" ("INTPTR_FORMAT" should have been marked)", addr); + gclog_or_tty->print_cr(" ("INTPTR_FORMAT" should have been marked)", p2i(addr)); _failed = true; } return true; @@ -2474,7 +2472,7 @@ bool CMSCollector::verify_after_remark(bool silent) { // presumably, a mutation to A failed to be picked up by preclean/remark? verify_after_remark_work_2(); } else { - warning("Unrecognized value %d for CMSRemarkVerifyVariant", + warning("Unrecognized value " UINTX_FORMAT " for CMSRemarkVerifyVariant", CMSRemarkVerifyVariant); } if (!silent) gclog_or_tty->print(" done] "); @@ -5056,7 +5054,7 @@ void CMSCollector::merge_survivor_plab_arrays(ContiguousSpace* surv, for (size_t i = 0; i < total - 1; i++) { if (PrintCMSStatistics > 0) { gclog_or_tty->print(" (chunk" SIZE_FORMAT ":" INTPTR_FORMAT ") ", - i, _survivor_chunk_array[i]); + i, p2i(_survivor_chunk_array[i])); } assert(_survivor_chunk_array[i] < _survivor_chunk_array[i+1], "Not sorted"); @@ -5700,8 +5698,8 @@ void ConcurrentMarkSweepGeneration::setNearLargestChunk() { gclog_or_tty->print_cr( "CMS: Large Block: " PTR_FORMAT ";" " Proximity: " PTR_FORMAT " -> " PTR_FORMAT, - largestAddr, - _cmsSpace->nearLargestChunk(), minAddr + nearLargestOffset); + p2i(largestAddr), + p2i(_cmsSpace->nearLargestChunk()), p2i(minAddr + nearLargestOffset)); } _cmsSpace->set_nearLargestChunk(minAddr + nearLargestOffset); } @@ -6184,7 +6182,7 @@ void MarkRefsIntoVerifyClosure::do_oop(oop obj) { _verification_bm->mark(addr); if (!_cms_bm->isMarked(addr)) { oop(addr)->print(); - gclog_or_tty->print_cr(" (" INTPTR_FORMAT " should have been marked)", addr); + gclog_or_tty->print_cr(" (" INTPTR_FORMAT " should have been marked)", p2i(addr)); fatal("... aborting"); } } @@ -6979,7 +6977,7 @@ void PushAndMarkVerifyClosure::do_oop(oop obj) { if (!_cms_bm->isMarked(addr)) { oop(addr)->print(); gclog_or_tty->print_cr(" (" INTPTR_FORMAT " should have been marked)", - addr); + p2i(addr)); fatal("... aborting"); } @@ -7375,16 +7373,16 @@ SweepClosure::SweepClosure(CMSCollector* collector, "sweep _limit out of bounds"); if (CMSTraceSweeper) { gclog_or_tty->print_cr("\n====================\nStarting new sweep with limit " PTR_FORMAT, - _limit); + p2i(_limit)); } } void SweepClosure::print_on(outputStream* st) const { tty->print_cr("_sp = [" PTR_FORMAT "," PTR_FORMAT ")", - _sp->bottom(), _sp->end()); - tty->print_cr("_limit = " PTR_FORMAT, _limit); - tty->print_cr("_freeFinger = " PTR_FORMAT, _freeFinger); - NOT_PRODUCT(tty->print_cr("_last_fc = " PTR_FORMAT, _last_fc);) + p2i(_sp->bottom()), p2i(_sp->end())); + tty->print_cr("_limit = " PTR_FORMAT, p2i(_limit)); + tty->print_cr("_freeFinger = " PTR_FORMAT, p2i(_freeFinger)); + NOT_PRODUCT(tty->print_cr("_last_fc = " PTR_FORMAT, p2i(_last_fc));) tty->print_cr("_inFreeRange = %d, _freeRangeInFreeLists = %d, _lastFreeRangeCoalesced = %d", _inFreeRange, _freeRangeInFreeLists, _lastFreeRangeCoalesced); } @@ -7428,7 +7426,7 @@ SweepClosure::~SweepClosure() { } if (CMSTraceSweeper) { gclog_or_tty->print_cr("end of sweep with _limit = " PTR_FORMAT "\n================", - _limit); + p2i(_limit)); } } #endif // PRODUCT @@ -7437,7 +7435,7 @@ void SweepClosure::initialize_free_range(HeapWord* freeFinger, bool freeRangeInFreeLists) { if (CMSTraceSweeper) { gclog_or_tty->print("---- Start free range at " PTR_FORMAT " with free block (%d)\n", - freeFinger, freeRangeInFreeLists); + p2i(freeFinger), freeRangeInFreeLists); } assert(!inFreeRange(), "Trampling existing free range"); set_inFreeRange(true); @@ -7501,14 +7499,14 @@ size_t SweepClosure::do_blk_careful(HeapWord* addr) { // coalesced chunk to the appropriate free list. if (inFreeRange()) { assert(freeFinger() >= _sp->bottom() && freeFinger() < _limit, - err_msg("freeFinger() " PTR_FORMAT" is out-of-bounds", freeFinger())); + err_msg("freeFinger() " PTR_FORMAT" is out-of-bounds", p2i(freeFinger()))); flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); if (CMSTraceSweeper) { gclog_or_tty->print("Sweep: last chunk: "); gclog_or_tty->print("put_free_blk " PTR_FORMAT " ("SIZE_FORMAT") " "[coalesced:%d]\n", - freeFinger(), pointer_delta(addr, freeFinger()), + p2i(freeFinger()), pointer_delta(addr, freeFinger()), lastFreeRangeCoalesced() ? 1 : 0); } } @@ -7652,7 +7650,7 @@ void SweepClosure::do_already_free_chunk(FreeChunk* fc) { // the midst of a free range, we are coalescing print_free_block_coalesced(fc); if (CMSTraceSweeper) { - gclog_or_tty->print(" -- pick up free block " PTR_FORMAT " (" SIZE_FORMAT ")\n", fc, size); + gclog_or_tty->print(" -- pick up free block " PTR_FORMAT " (" SIZE_FORMAT ")\n", p2i(fc), size); } // remove it from the free lists _sp->removeFreeChunkFromFreeLists(fc); @@ -7714,7 +7712,7 @@ size_t SweepClosure::do_garbage_chunk(FreeChunk* fc) { // this will be swept up when we hit the end of the // free range if (CMSTraceSweeper) { - gclog_or_tty->print(" -- pick up garbage " PTR_FORMAT " (" SIZE_FORMAT ")\n", fc, size); + gclog_or_tty->print(" -- pick up garbage " PTR_FORMAT " (" SIZE_FORMAT ")\n", p2i(fc), size); } // If the chunk is being coalesced and the current free range is // in the free lists, remove the current free range so that it @@ -7807,7 +7805,7 @@ void SweepClosure::do_post_free_or_garbage_chunk(FreeChunk* fc, } if (CMSTraceSweeper) { - gclog_or_tty->print_cr(" -- pick up another chunk at " PTR_FORMAT " (" SIZE_FORMAT ")", fc, chunkSize); + gclog_or_tty->print_cr(" -- pick up another chunk at " PTR_FORMAT " (" SIZE_FORMAT ")", p2i(fc), chunkSize); } HeapWord* const fc_addr = (HeapWord*) fc; @@ -7906,14 +7904,14 @@ void SweepClosure::lookahead_and_flush(FreeChunk* fc, size_t chunk_size) { err_msg("eob = " PTR_FORMAT " eob-1 = " PTR_FORMAT " _limit = " PTR_FORMAT " out of bounds wrt _sp = [" PTR_FORMAT "," PTR_FORMAT ")" " when examining fc = " PTR_FORMAT "(" SIZE_FORMAT ")", - eob, eob-1, _limit, _sp->bottom(), _sp->end(), fc, chunk_size)); + p2i(eob), p2i(eob-1), p2i(_limit), p2i(_sp->bottom()), p2i(_sp->end()), p2i(fc), chunk_size)); if (eob >= _limit) { assert(eob == _limit || fc->is_free(), "Only a free chunk should allow us to cross over the limit"); if (CMSTraceSweeper) { gclog_or_tty->print_cr("_limit " PTR_FORMAT " reached or crossed by block " "[" PTR_FORMAT "," PTR_FORMAT ") in space " "[" PTR_FORMAT "," PTR_FORMAT ")", - _limit, fc, eob, _sp->bottom(), _sp->end()); + p2i(_limit), p2i(fc), p2i(eob), p2i(_sp->bottom()), p2i(_sp->end())); } // Return the storage we are tracking back into the free lists. if (CMSTraceSweeper) { @@ -7937,7 +7935,7 @@ void SweepClosure::flush_cur_free_chunk(HeapWord* chunk, size_t size) { } if (CMSTraceSweeper) { gclog_or_tty->print_cr(" -- add free block " PTR_FORMAT " (" SIZE_FORMAT ") to free lists", - chunk, size); + p2i(chunk), size); } // A new free range is going to be starting. The current // free range has not been added to the free lists yet or @@ -8010,7 +8008,7 @@ bool debug_verify_chunk_in_free_list(FreeChunk* fc) { void SweepClosure::print_free_block_coalesced(FreeChunk* fc) const { if (CMSTraceSweeper) { gclog_or_tty->print_cr("Sweep:coal_free_blk " PTR_FORMAT " (" SIZE_FORMAT ")", - fc, fc->size()); + p2i(fc), fc->size()); } } diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeChunk.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeChunk.cpp index 133ed3c5969..e58391acfae 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeChunk.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeChunk.cpp @@ -27,8 +27,6 @@ #include "memory/freeBlockDictionary.hpp" #include "utilities/copy.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - #ifndef PRODUCT #define baadbabeHeapWord badHeapWordVal @@ -74,5 +72,5 @@ void FreeChunk::verifyList() const { void FreeChunk::print_on(outputStream* st) { st->print_cr("Next: " PTR_FORMAT " Prev: " PTR_FORMAT " %s", - next(), prev(), cantCoalesce() ? "[can't coalesce]" : ""); + p2i(next()), p2i(prev()), cantCoalesce() ? "[can't coalesce]" : ""); } diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/promotionInfo.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/promotionInfo.cpp index 44f5a287c6e..dfddda7cf2f 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/promotionInfo.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/promotionInfo.cpp @@ -28,8 +28,6 @@ #include "oops/markOop.inline.hpp" #include "oops/oop.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - ///////////////////////////////////////////////////////////////////////// //// PromotionInfo ///////////////////////////////////////////////////////////////////////// @@ -360,6 +358,6 @@ void PromotionInfo::print_on(outputStream* st) const { void SpoolBlock::print_on(outputStream* st) const { st->print("[" PTR_FORMAT "," PTR_FORMAT "), " SIZE_FORMAT " HeapWords -> " PTR_FORMAT, - this, (HeapWord*)displacedHdr + bufferSize, - bufferSize, nextSpoolBlock); + p2i(this), p2i((HeapWord*)displacedHdr + bufferSize), + bufferSize, p2i(nextSpoolBlock)); } diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp index 9587736f297..39d86cd475a 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp @@ -34,8 +34,6 @@ #include "runtime/os.hpp" #include "utilities/dtrace.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - ////////////////////////////////////////////////////////// // Methods in abstract class VM_CMS_Operation ////////////////////////////////////////////////////////// From bbadc1626fcc86f132519de92368698f1e0fc59d Mon Sep 17 00:00:00 2001 From: David Lindholm Date: Fri, 27 Mar 2015 15:24:49 +0100 Subject: [PATCH 074/362] 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files Reviewed-by: brutisso, mgerdin, stefank --- .../parallelScavenge/gcTaskManager.cpp | 56 +++++++++---------- .../parallelScavenge/gcTaskThread.cpp | 4 +- .../parallelScavenge/pcTasks.cpp | 10 ++-- .../parallelScavenge/psAdaptiveSizePolicy.cpp | 2 - .../parallelScavenge/psMarkSweep.cpp | 4 +- .../parallelScavenge/psOldGen.cpp | 8 +-- .../parallelScavenge/psParallelCompact.cpp | 48 ++++++++-------- .../parallelScavenge/psPromotionManager.cpp | 4 +- .../parallelScavenge/psScavenge.cpp | 8 +-- .../parallelScavenge/psVirtualspace.cpp | 12 ++-- .../parallelScavenge/psYoungGen.cpp | 52 ++++++++--------- 11 files changed, 94 insertions(+), 114 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/gcTaskManager.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/gcTaskManager.cpp index a35c0913138..d9f38a0e2c8 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/gcTaskManager.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/gcTaskManager.cpp @@ -32,8 +32,6 @@ #include "runtime/mutexLocker.hpp" #include "runtime/orderAccess.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // // GCTask // @@ -101,7 +99,7 @@ void GCTask::destruct() { NOT_PRODUCT( void GCTask::print(const char* message) const { tty->print(INTPTR_FORMAT " <- " INTPTR_FORMAT "(%u) -> " INTPTR_FORMAT, - newer(), this, affinity(), older()); + p2i(newer()), p2i(this), affinity(), p2i(older())); } ) @@ -113,7 +111,7 @@ GCTaskQueue* GCTaskQueue::create() { GCTaskQueue* result = new GCTaskQueue(false); if (TraceGCTaskQueue) { tty->print_cr("GCTaskQueue::create()" - " returns " INTPTR_FORMAT, result); + " returns " INTPTR_FORMAT, p2i(result)); } return result; } @@ -123,7 +121,7 @@ GCTaskQueue* GCTaskQueue::create_on_c_heap() { if (TraceGCTaskQueue) { tty->print_cr("GCTaskQueue::create_on_c_heap()" " returns " INTPTR_FORMAT, - result); + p2i(result)); } return result; } @@ -134,7 +132,7 @@ GCTaskQueue::GCTaskQueue(bool on_c_heap) : if (TraceGCTaskQueue) { tty->print_cr("[" INTPTR_FORMAT "]" " GCTaskQueue::GCTaskQueue() constructor", - this); + p2i(this)); } } @@ -147,7 +145,7 @@ void GCTaskQueue::destroy(GCTaskQueue* that) { tty->print_cr("[" INTPTR_FORMAT "]" " GCTaskQueue::destroy()" " is_c_heap_obj: %s", - that, + p2i(that), that->is_c_heap_obj() ? "true" : "false"); } // That instance may have been allocated as a CHeapObj, @@ -173,7 +171,7 @@ void GCTaskQueue::enqueue(GCTask* task) { tty->print_cr("[" INTPTR_FORMAT "]" " GCTaskQueue::enqueue(task: " INTPTR_FORMAT ")", - this, task); + p2i(this), p2i(task)); print("before:"); } assert(task != NULL, "shouldn't have null task"); @@ -200,7 +198,7 @@ void GCTaskQueue::enqueue(GCTaskQueue* list) { tty->print_cr("[" INTPTR_FORMAT "]" " GCTaskQueue::enqueue(list: " INTPTR_FORMAT ")", - this, list); + p2i(this), p2i(list)); print("before:"); list->print("list:"); } @@ -234,14 +232,14 @@ void GCTaskQueue::enqueue(GCTaskQueue* list) { GCTask* GCTaskQueue::dequeue() { if (TraceGCTaskQueue) { tty->print_cr("[" INTPTR_FORMAT "]" - " GCTaskQueue::dequeue()", this); + " GCTaskQueue::dequeue()", p2i(this)); print("before:"); } assert(!is_empty(), "shouldn't dequeue from empty list"); GCTask* result = remove(); assert(result != NULL, "shouldn't have NULL task"); if (TraceGCTaskQueue) { - tty->print_cr(" return: " INTPTR_FORMAT, result); + tty->print_cr(" return: " INTPTR_FORMAT, p2i(result)); print("after:"); } return result; @@ -251,7 +249,7 @@ GCTask* GCTaskQueue::dequeue() { GCTask* GCTaskQueue::dequeue(uint affinity) { if (TraceGCTaskQueue) { tty->print_cr("[" INTPTR_FORMAT "]" - " GCTaskQueue::dequeue(%u)", this, affinity); + " GCTaskQueue::dequeue(%u)", p2i(this), affinity); print("before:"); } assert(!is_empty(), "shouldn't dequeue from empty list"); @@ -275,7 +273,7 @@ GCTask* GCTaskQueue::dequeue(uint affinity) { result = remove(); } if (TraceGCTaskQueue) { - tty->print_cr(" return: " INTPTR_FORMAT, result); + tty->print_cr(" return: " INTPTR_FORMAT, p2i(result)); print("after:"); } return result; @@ -345,7 +343,7 @@ void GCTaskQueue::print(const char* message) const { " remove_end: " INTPTR_FORMAT " length: %d" " %s", - this, insert_end(), remove_end(), length(), message); + p2i(this), p2i(insert_end()), p2i(remove_end()), length(), message); uint count = 0; for (GCTask* element = insert_end(); element != NULL; @@ -486,7 +484,7 @@ void GCTaskManager::set_active_gang() { assert(!all_workers_active() || active_workers() == ParallelGCThreads, err_msg("all_workers_active() is incorrect: " - "active %d ParallelGCThreads %d", active_workers(), + "active %d ParallelGCThreads " UINTX_FORMAT, active_workers(), ParallelGCThreads)); if (TraceDynamicGCThreads) { gclog_or_tty->print_cr("GCTaskManager::set_active_gang(): " @@ -598,7 +596,7 @@ void GCTaskManager::add_task(GCTask* task) { MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); if (TraceGCTaskManager) { tty->print_cr("GCTaskManager::add_task(" INTPTR_FORMAT " [%s])", - task, GCTask::Kind::to_string(task->kind())); + p2i(task), GCTask::Kind::to_string(task->kind())); } queue()->enqueue(task); // Notify with the lock held to avoid missed notifies. @@ -678,7 +676,7 @@ GCTask* GCTaskManager::get_task(uint which) { assert(result != NULL, "shouldn't have null task"); if (TraceGCTaskManager) { tty->print_cr("GCTaskManager::get_task(%u) => " INTPTR_FORMAT " [%s]", - which, result, GCTask::Kind::to_string(result->kind())); + which, p2i(result), GCTask::Kind::to_string(result->kind())); tty->print_cr(" %s", result->name()); } if (!result->is_idle_task()) { @@ -864,7 +862,7 @@ void IdleGCTask::do_it(GCTaskManager* manager, uint which) { tty->print_cr("[" INTPTR_FORMAT "]" " IdleGCTask:::do_it()" " should_wait: %s", - this, wait_for_task->should_wait() ? "true" : "false"); + p2i(this), wait_for_task->should_wait() ? "true" : "false"); } MutexLockerEx ml(manager->monitor(), Mutex::_no_safepoint_check_flag); if (TraceDynamicGCThreads) { @@ -878,7 +876,7 @@ void IdleGCTask::do_it(GCTaskManager* manager, uint which) { tty->print_cr("[" INTPTR_FORMAT "]" " IdleGCTask::do_it()" " [" INTPTR_FORMAT "] (%s)->wait()", - this, manager->monitor(), manager->monitor()->name()); + p2i(this), p2i(manager->monitor()), manager->monitor()->name()); } manager->monitor()->wait(Mutex::_no_safepoint_check_flag, 0); } @@ -890,7 +888,7 @@ void IdleGCTask::do_it(GCTaskManager* manager, uint which) { tty->print_cr("[" INTPTR_FORMAT "]" " IdleGCTask::do_it() returns" " should_wait: %s", - this, wait_for_task->should_wait() ? "true" : "false"); + p2i(this), wait_for_task->should_wait() ? "true" : "false"); } // Release monitor(). } @@ -1000,7 +998,7 @@ WaitForBarrierGCTask::WaitForBarrierGCTask(bool on_c_heap) : tty->print_cr("[" INTPTR_FORMAT "]" " WaitForBarrierGCTask::WaitForBarrierGCTask()" " monitor: " INTPTR_FORMAT, - this, monitor()); + p2i(this), p2i(monitor())); } } @@ -1011,9 +1009,9 @@ void WaitForBarrierGCTask::destroy(WaitForBarrierGCTask* that) { " WaitForBarrierGCTask::destroy()" " is_c_heap_obj: %s" " monitor: " INTPTR_FORMAT, - that, + p2i(that), that->is_c_heap_obj() ? "true" : "false", - that->monitor()); + p2i(that->monitor())); } that->destruct(); if (that->is_c_heap_obj()) { @@ -1028,7 +1026,7 @@ void WaitForBarrierGCTask::destruct() { tty->print_cr("[" INTPTR_FORMAT "]" " WaitForBarrierGCTask::destruct()" " monitor: " INTPTR_FORMAT, - this, monitor()); + p2i(this), p2i(monitor())); } this->BarrierGCTask::destruct(); // Clean up that should be in the destructor, @@ -1044,7 +1042,7 @@ void WaitForBarrierGCTask::do_it(GCTaskManager* manager, uint which) { tty->print_cr("[" INTPTR_FORMAT "]" " WaitForBarrierGCTask::do_it() waiting for idle" " monitor: " INTPTR_FORMAT, - this, monitor()); + p2i(this), p2i(monitor())); } { // First, wait for the barrier to arrive. @@ -1062,7 +1060,7 @@ void WaitForBarrierGCTask::do_it(GCTaskManager* manager, uint which) { tty->print_cr("[" INTPTR_FORMAT "]" " WaitForBarrierGCTask::do_it()" " [" INTPTR_FORMAT "] (%s)->notify_all()", - this, monitor(), monitor()->name()); + p2i(this), p2i(monitor()), monitor()->name()); } monitor()->notify_all(); // Release monitor(). @@ -1074,7 +1072,7 @@ void WaitForBarrierGCTask::wait_for(bool reset) { tty->print_cr("[" INTPTR_FORMAT "]" " WaitForBarrierGCTask::wait_for()" " should_wait: %s", - this, should_wait() ? "true" : "false"); + p2i(this), should_wait() ? "true" : "false"); } { // Grab the lock and check again. @@ -1084,7 +1082,7 @@ void WaitForBarrierGCTask::wait_for(bool reset) { tty->print_cr("[" INTPTR_FORMAT "]" " WaitForBarrierGCTask::wait_for()" " [" INTPTR_FORMAT "] (%s)->wait()", - this, monitor(), monitor()->name()); + p2i(this), p2i(monitor()), monitor()->name()); } monitor()->wait(Mutex::_no_safepoint_check_flag, 0); } @@ -1096,7 +1094,7 @@ void WaitForBarrierGCTask::wait_for(bool reset) { tty->print_cr("[" INTPTR_FORMAT "]" " WaitForBarrierGCTask::wait_for() returns" " should_wait: %s", - this, should_wait() ? "true" : "false"); + p2i(this), should_wait() ? "true" : "false"); } // Release monitor(). } diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/gcTaskThread.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/gcTaskThread.cpp index 91f23612a56..13060a4a12c 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/gcTaskThread.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/gcTaskThread.cpp @@ -34,8 +34,6 @@ #include "runtime/os.hpp" #include "runtime/thread.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - GCTaskThread::GCTaskThread(GCTaskManager* manager, uint which, uint processor_id) : @@ -79,7 +77,7 @@ void GCTaskThread::print_task_time_stamps() { tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index); for(uint i=0; i<_time_stamp_index; i++) { GCTaskTimeStamp* time_stamp = time_stamp_at(i); - tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]", + tty->print_cr("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]", time_stamp->name(), time_stamp->entry_time(), time_stamp->exit_time()); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp index 13ccf71c28c..fc2cd8c6bea 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp @@ -42,8 +42,6 @@ #include "runtime/vmThread.hpp" #include "services/management.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // // ThreadRootsMarkingTask // @@ -256,7 +254,7 @@ void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) { which_stack_index = which; assert(manager->active_workers() == ParallelGCThreads, err_msg("all_workers_active has been incorrectly set: " - " active %d ParallelGCThreads %d", manager->active_workers(), + " active %d ParallelGCThreads " UINTX_FORMAT, manager->active_workers(), ParallelGCThreads)); } else { which_stack_index = ParCompactionManager::pop_recycled_stack_index(); @@ -268,7 +266,7 @@ void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) { gclog_or_tty->print_cr("StealRegionCompactionTask::do_it " "region_stack_index %d region_stack = " PTR_FORMAT " " " empty (%d) use all workers %d", - which_stack_index, ParCompactionManager::region_list(which_stack_index), + which_stack_index, p2i(ParCompactionManager::region_list(which_stack_index)), cm->region_stack()->is_empty(), use_all_workers); } @@ -335,7 +333,7 @@ void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) { which_stack_index = which; assert(manager->active_workers() == ParallelGCThreads, err_msg("all_workers_active has been incorrectly set: " - " active %d ParallelGCThreads %d", manager->active_workers(), + " active %d ParallelGCThreads " UINTX_FORMAT, manager->active_workers(), ParallelGCThreads)); } else { which_stack_index = stack_index(); @@ -369,7 +367,7 @@ void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) { void* old_region_stack = (void*) cm->region_stack(); int old_region_stack_index = cm->region_stack_index(); gclog_or_tty->print_cr("Pushing region stack " PTR_FORMAT "/%d", - old_region_stack, old_region_stack_index); + p2i(old_region_stack), old_region_stack_index); } cm->set_region_stack(NULL); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp index 229b9dd3cfa..bf979b9e420 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp @@ -35,8 +35,6 @@ #include -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - PSAdaptiveSizePolicy::PSAdaptiveSizePolicy(size_t init_eden_size, size_t init_promo_size, size_t init_survivor_size, diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp index 7288b963c9b..171f4643920 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp @@ -54,8 +54,6 @@ #include "utilities/events.hpp" #include "utilities/stack.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - elapsedTimer PSMarkSweep::_accumulated_time; jlong PSMarkSweep::_time_of_last_gc = 0; CollectorCounters* PSMarkSweep::_counters = NULL; @@ -670,7 +668,7 @@ jlong PSMarkSweep::millis_since_last_gc() { jlong ret_val = now - _time_of_last_gc; // XXX See note in genCollectedHeap::millis_since_last_gc(). if (ret_val < 0) { - NOT_PRODUCT(warning("time warp: "INT64_FORMAT, ret_val);) + NOT_PRODUCT(warning("time warp: " JLONG_FORMAT, ret_val);) return 0; } return ret_val; diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psOldGen.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psOldGen.cpp index c7ac0eb5a9b..61c6caf5364 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psOldGen.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psOldGen.cpp @@ -33,8 +33,6 @@ #include "oops/oop.inline.hpp" #include "runtime/java.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - inline const char* PSOldGen::select_name() { return UseParallelOldGC ? "ParOldGen" : "PSOldGen"; } @@ -440,9 +438,9 @@ void PSOldGen::print_on(outputStream* st) const { capacity_in_bytes()/K, used_in_bytes()/K); } st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", - virtual_space()->low_boundary(), - virtual_space()->high(), - virtual_space()->high_boundary()); + p2i(virtual_space()->low_boundary()), + p2i(virtual_space()->high()), + p2i(virtual_space()->high_boundary())); st->print(" object"); object_space()->print_on(st); } diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp index c262b0b5c95..b8f60ffdadc 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp @@ -62,8 +62,6 @@ #include -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // All sizes are in HeapWords. const size_t ParallelCompactData::Log2RegionSize = 16; // 64K words const size_t ParallelCompactData::RegionSize = (size_t)1 << Log2RegionSize; @@ -222,7 +220,7 @@ print_generic_summary_region(size_t i, const ParallelCompactData::RegionData* c) REGION_IDX_FORMAT " " PTR_FORMAT " " REGION_DATA_FORMAT " " REGION_DATA_FORMAT " " REGION_DATA_FORMAT " " REGION_IDX_FORMAT " %d", - i, c->data_location(), dci, c->destination(), + i, p2i(c->data_location()), dci, p2i(c->destination()), c->partial_obj_size(), c->live_obj_size(), c->data_size(), c->source_region(), c->destination_count()); @@ -272,7 +270,7 @@ print_initial_summary_region(size_t i, tty->print(SIZE_FORMAT_W(5) " " PTR_FORMAT " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d", - i, c->destination(), + i, p2i(c->destination()), c->partial_obj_size(), c->live_obj_size(), c->data_size(), c->source_region(), c->destination_count()); if (newline) tty->cr(); @@ -633,13 +631,13 @@ ParallelCompactData::summarize_split_space(size_t src_region, const char * split_type = partial_obj_size == 0 ? "easy" : "hard"; gclog_or_tty->print_cr("%s split: src=" PTR_FORMAT " src_c=" SIZE_FORMAT " pos=" SIZE_FORMAT, - split_type, source_next, split_region, + split_type, p2i(source_next), split_region, partial_obj_size); gclog_or_tty->print_cr("%s split: dst=" PTR_FORMAT " dst_c=" SIZE_FORMAT " tn=" PTR_FORMAT, - split_type, split_destination, + split_type, p2i(split_destination), addr_to_region_idx(split_destination), - *target_next); + p2i(*target_next)); if (partial_obj_size != 0) { HeapWord* const po_beg = split_info.destination(); @@ -648,8 +646,8 @@ ParallelCompactData::summarize_split_space(size_t src_region, "po_beg=" PTR_FORMAT " " SIZE_FORMAT " " "po_end=" PTR_FORMAT " " SIZE_FORMAT, split_type, - po_beg, addr_to_region_idx(po_beg), - po_end, addr_to_region_idx(po_end)); + p2i(po_beg), addr_to_region_idx(po_beg), + p2i(po_end), addr_to_region_idx(po_end)); } } @@ -666,8 +664,8 @@ bool ParallelCompactData::summarize(SplitInfo& split_info, HeapWord* const source_next_val = source_next == NULL ? NULL : *source_next; tty->print_cr("sb=" PTR_FORMAT " se=" PTR_FORMAT " sn=" PTR_FORMAT "tb=" PTR_FORMAT " te=" PTR_FORMAT " tn=" PTR_FORMAT, - source_beg, source_end, source_next_val, - target_beg, target_end, *target_next); + p2i(source_beg), p2i(source_end), p2i(source_next_val), + p2i(target_beg), p2i(target_end), p2i(*target_next)); } size_t cur_region = addr_to_region_idx(source_beg); @@ -1132,9 +1130,9 @@ PSParallelCompact::compute_dense_prefix_via_density(const SpaceId id, const size_t cur_deadwood = pointer_delta(dense_prefix, region_destination); if (TraceParallelOldGCDensePrefix && Verbose) { tty->print_cr("c#=" SIZE_FORMAT_W(4) " dst=" PTR_FORMAT " " - "dp=" SIZE_FORMAT_W(8) " " "cdw=" SIZE_FORMAT_W(8), - sd.region(cp), region_destination, - dense_prefix, cur_deadwood); + "dp=" PTR_FORMAT " " "cdw=" SIZE_FORMAT_W(8), + sd.region(cp), p2i(region_destination), + p2i(dense_prefix), cur_deadwood); } if (cur_deadwood >= deadwood_goal) { @@ -1200,7 +1198,7 @@ void PSParallelCompact::print_dense_prefix_stats(const char* const algorithm, "d2l=" SIZE_FORMAT " d2l%%=%6.4f " "d2r=" SIZE_FORMAT " l2r=" SIZE_FORMAT " ratio=%10.8f", - algorithm, addr, region_idx, + algorithm, p2i(addr), region_idx, space_live, dead_to_left, dead_to_left_pct, dead_to_right, live_to_right, @@ -1468,7 +1466,7 @@ PSParallelCompact::fill_with_live_objects(SpaceId id, HeapWord* const start, { if (TraceParallelOldGCSummaryPhase) { tty->print_cr("fill_with_live_objects [" PTR_FORMAT " " PTR_FORMAT ") " - SIZE_FORMAT, start, start + words, words); + SIZE_FORMAT, p2i(start), p2i(start + words), words); } ObjectStartArray* const start_array = _space_info[id].start_array(); @@ -1810,9 +1808,9 @@ PSParallelCompact::summarize_space(SpaceId id, bool maximum_compaction) tty->print_cr("id=%d cap=" SIZE_FORMAT " dp=" PTR_FORMAT " " "dp_region=" SIZE_FORMAT " " "dp_count=" SIZE_FORMAT " " "cr_count=" SIZE_FORMAT " " "nt=" PTR_FORMAT, - id, space->capacity_in_words(), dense_prefix_end, + id, space->capacity_in_words(), p2i(dense_prefix_end), dp_region, dp_words / region_size, - cr_words / region_size, new_top); + cr_words / region_size, p2i(new_top)); } } @@ -1830,10 +1828,10 @@ void PSParallelCompact::summary_phase_msg(SpaceId dst_space_id, SIZE_FORMAT "-" SIZE_FORMAT, src_space_id, space_names[src_space_id], dst_space_id, space_names[dst_space_id], - src_beg, src_end, + p2i(src_beg), p2i(src_end), _summary_data.addr_to_region_idx(src_beg), _summary_data.addr_to_region_idx(src_end), - dst_beg, dst_end, + p2i(dst_beg), p2i(dst_end), _summary_data.addr_to_region_idx(dst_beg), _summary_data.addr_to_region_idx(dst_end)); } @@ -2233,8 +2231,8 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) { heap->trace_heap_after_gc(&_gc_tracer); if (PrintGCTaskTimeStamps) { - gclog_or_tty->print_cr("VM-Thread " INT64_FORMAT " " INT64_FORMAT " " - INT64_FORMAT, + gclog_or_tty->print_cr("VM-Thread " JLONG_FORMAT " " JLONG_FORMAT " " + JLONG_FORMAT, marking_start.ticks(), compaction_start.ticks(), collection_exit.ticks()); gc_task_manager()->print_task_time_stamps(); @@ -2753,7 +2751,7 @@ void PSParallelCompact::verify_complete(SpaceId space_id) { const RegionData* const c = sd.region(cur_region); if (!c->completed()) { warning("region " SIZE_FORMAT " not filled: " - "destination_count=" SIZE_FORMAT, + "destination_count=%u", cur_region, c->destination_count()); issued_a_warning = true; } @@ -2763,7 +2761,7 @@ void PSParallelCompact::verify_complete(SpaceId space_id) { const RegionData* const c = sd.region(cur_region); if (!c->available()) { warning("region " SIZE_FORMAT " not empty: " - "destination_count=" SIZE_FORMAT, + "destination_count=%u", cur_region, c->destination_count()); issued_a_warning = true; } @@ -3298,7 +3296,7 @@ jlong PSParallelCompact::millis_since_last_gc() { jlong ret_val = now - _time_of_last_gc; // XXX See note in genCollectedHeap::millis_since_last_gc(). if (ret_val < 0) { - NOT_PRODUCT(warning("time warp: "INT64_FORMAT, ret_val);) + NOT_PRODUCT(warning("time warp: " JLONG_FORMAT, ret_val);) return 0; } return ret_val; diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp index cf79af15c4e..be4a9ed11d7 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp @@ -35,8 +35,6 @@ #include "oops/oop.inline.hpp" #include "utilities/stack.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - PaddedEnd* PSPromotionManager::_manager_array = NULL; OopStarTaskQueueSet* PSPromotionManager::_stack_array_depth = NULL; PSOldGen* PSPromotionManager::_old_gen = NULL; @@ -341,7 +339,7 @@ oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) { gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " (%d)}", "promotion-failure", obj->klass()->internal_name(), - (void *)obj, obj->size()); + p2i(obj), obj->size()); } #endif diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp index 205170b8c65..04ff184ea0c 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp @@ -55,8 +55,6 @@ #include "services/memoryService.hpp" #include "utilities/stack.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - HeapWord* PSScavenge::_to_space_top_before_gc = NULL; int PSScavenge::_consecutive_skipped_scavenges = 0; ReferenceProcessor* PSScavenge::_ref_processor = NULL; @@ -550,8 +548,8 @@ bool PSScavenge::invoke_no_policy() { if (PrintTenuringDistribution) { gclog_or_tty->cr(); - gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold " - UINTX_FORMAT " (max threshold " UINTX_FORMAT ")", + gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold %u" + " (max threshold " UINTX_FORMAT ")", size_policy->calculated_survivor_size_in_bytes(), _tenuring_threshold, MaxTenuringThreshold); } @@ -693,7 +691,7 @@ bool PSScavenge::invoke_no_policy() { scavenge_exit.update(); if (PrintGCTaskTimeStamps) { - tty->print_cr("VM-Thread " INT64_FORMAT " " INT64_FORMAT " " INT64_FORMAT, + tty->print_cr("VM-Thread " JLONG_FORMAT " " JLONG_FORMAT " " JLONG_FORMAT, scavenge_entry.ticks(), scavenge_midpoint.ticks(), scavenge_exit.ticks()); gc_task_manager()->print_task_time_stamps(); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp index 7d11d38b885..867422eaf21 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp @@ -27,8 +27,6 @@ #include "runtime/os.hpp" #include "runtime/virtualspace.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // PSVirtualSpace PSVirtualSpace::PSVirtualSpace(ReservedSpace rs, size_t alignment) : @@ -218,22 +216,22 @@ void PSVirtualSpace::verify() const { void PSVirtualSpace::print() const { gclog_or_tty->print_cr("virtual space [" PTR_FORMAT "]: alignment=" SIZE_FORMAT "K grows %s%s", - this, alignment() / K, grows_up() ? "up" : "down", + p2i(this), alignment() / K, grows_up() ? "up" : "down", special() ? " (pinned in memory)" : ""); gclog_or_tty->print_cr(" reserved=" SIZE_FORMAT "K" " [" PTR_FORMAT "," PTR_FORMAT "]" " committed=" SIZE_FORMAT "K" " [" PTR_FORMAT "," PTR_FORMAT "]", reserved_size() / K, - reserved_low_addr(), reserved_high_addr(), + p2i(reserved_low_addr()), p2i(reserved_high_addr()), committed_size() / K, - committed_low_addr(), committed_high_addr()); + p2i(committed_low_addr()), p2i(committed_high_addr())); } #endif // #ifndef PRODUCT void PSVirtualSpace::print_space_boundaries_on(outputStream* st) const { st->print_cr(" [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")", - low_boundary(), high(), high_boundary()); + p2i(low_boundary()), p2i(high()), p2i(high_boundary())); } PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs, @@ -350,5 +348,5 @@ size_t PSVirtualSpaceHighToLow::expand_into(PSVirtualSpace* other_space, void PSVirtualSpaceHighToLow::print_space_boundaries_on(outputStream* st) const { st->print_cr(" (" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]", - high_boundary(), low(), low_boundary()); + p2i(high_boundary()), p2i(low()), p2i(low_boundary())); } diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp index 77c0937eb01..286fbaa88fa 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp @@ -33,8 +33,6 @@ #include "oops/oop.inline.hpp" #include "runtime/java.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - PSYoungGen::PSYoungGen(size_t initial_size, size_t min_size, size_t max_size) : @@ -419,20 +417,22 @@ void PSYoungGen::mangle_survivors(MutableSpace* s1, // s1 gclog_or_tty->print_cr("Current region: [" PTR_FORMAT ", " PTR_FORMAT ") " "New region: [" PTR_FORMAT ", " PTR_FORMAT ")", - s1->bottom(), s1->end(), s1MR.start(), s1MR.end()); + p2i(s1->bottom()), p2i(s1->end()), + p2i(s1MR.start()), p2i(s1MR.end())); gclog_or_tty->print_cr(" Mangle before: [" PTR_FORMAT ", " PTR_FORMAT ") Mangle after: [" PTR_FORMAT ", " PTR_FORMAT ")", - delta1_left.start(), delta1_left.end(), delta1_right.start(), - delta1_right.end()); + p2i(delta1_left.start()), p2i(delta1_left.end()), + p2i(delta1_right.start()), p2i(delta1_right.end())); // s2 gclog_or_tty->print_cr("Current region: [" PTR_FORMAT ", " PTR_FORMAT ") " "New region: [" PTR_FORMAT ", " PTR_FORMAT ")", - s2->bottom(), s2->end(), s2MR.start(), s2MR.end()); + p2i(s2->bottom()), p2i(s2->end()), + p2i(s2MR.start()), p2i(s2MR.end())); gclog_or_tty->print_cr(" Mangle before: [" PTR_FORMAT ", " PTR_FORMAT ") Mangle after: [" PTR_FORMAT ", " PTR_FORMAT ")", - delta2_left.start(), delta2_left.end(), delta2_right.start(), - delta2_right.end()); + p2i(delta2_left.start()), p2i(delta2_left.end()), + p2i(delta2_right.start()), p2i(delta2_right.end())); } } @@ -456,22 +456,22 @@ void PSYoungGen::resize_spaces(size_t requested_eden_size, requested_eden_size, requested_survivor_size); gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") " SIZE_FORMAT, - eden_space()->bottom(), - eden_space()->end(), + p2i(eden_space()->bottom()), + p2i(eden_space()->end()), pointer_delta(eden_space()->end(), eden_space()->bottom(), sizeof(char))); gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") " SIZE_FORMAT, - from_space()->bottom(), - from_space()->end(), + p2i(from_space()->bottom()), + p2i(from_space()->end()), pointer_delta(from_space()->end(), from_space()->bottom(), sizeof(char))); gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") " SIZE_FORMAT, - to_space()->bottom(), - to_space()->end(), + p2i(to_space()->bottom()), + p2i(to_space()->end()), pointer_delta( to_space()->end(), to_space()->bottom(), sizeof(char))); @@ -572,18 +572,18 @@ void PSYoungGen::resize_spaces(size_t requested_eden_size, if (PrintAdaptiveSizePolicy && Verbose) { gclog_or_tty->print_cr(" [eden_start .. eden_end): " "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, - eden_start, - eden_end, + p2i(eden_start), + p2i(eden_end), pointer_delta(eden_end, eden_start, sizeof(char))); gclog_or_tty->print_cr(" [from_start .. from_end): " "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, - from_start, - from_end, + p2i(from_start), + p2i(from_end), pointer_delta(from_end, from_start, sizeof(char))); gclog_or_tty->print_cr(" [ to_start .. to_end): " "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, - to_start, - to_end, + p2i(to_start), + p2i(to_end), pointer_delta( to_end, to_start, sizeof(char))); } } else { @@ -629,18 +629,18 @@ void PSYoungGen::resize_spaces(size_t requested_eden_size, if (PrintAdaptiveSizePolicy && Verbose) { gclog_or_tty->print_cr(" [eden_start .. eden_end): " "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, - eden_start, - eden_end, + p2i(eden_start), + p2i(eden_end), pointer_delta(eden_end, eden_start, sizeof(char))); gclog_or_tty->print_cr(" [ to_start .. to_end): " "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, - to_start, - to_end, + p2i(to_start), + p2i(to_end), pointer_delta( to_end, to_start, sizeof(char))); gclog_or_tty->print_cr(" [from_start .. from_end): " "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, - from_start, - from_end, + p2i(from_start), + p2i(from_end), pointer_delta(from_end, from_start, sizeof(char))); } } From 28d7b8200d0a6d3b390bd2d315999c0e838867a9 Mon Sep 17 00:00:00 2001 From: David Lindholm Date: Fri, 27 Mar 2015 15:27:14 +0100 Subject: [PATCH 075/362] 8076072: parNew: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files Reviewed-by: stefank, brutisso --- .../vm/gc_implementation/parNew/parCardTableModRefBS.cpp | 9 ++++----- .../vm/gc_implementation/parNew/parNewGeneration.cpp | 4 +--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp index efe7e399209..6f77be956c4 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp @@ -36,8 +36,6 @@ #include "runtime/virtualspace.hpp" #include "runtime/vmThread.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - void CardTableModRefBS::non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr, OopsInGenClosure* cl, CardTableRS* ct, @@ -376,13 +374,14 @@ process_chunk_boundaries(Space* sp, " does not exceed used.end() = " PTR_FORMAT "," " yet last_chunk_index_to_check " INTPTR_FORMAT " exceeds last_chunk_index " INTPTR_FORMAT, - last_block, last_block + last_block_size, - used.end(), + p2i(last_block), p2i(last_block + last_block_size), + p2i(used.end()), last_chunk_index_to_check, last_chunk_index)); assert(sp->used_region().end() > used.end(), err_msg("Expansion did not happen: " "[" PTR_FORMAT "," PTR_FORMAT ") -> [" PTR_FORMAT "," PTR_FORMAT ")", - sp->used_region().start(), sp->used_region().end(), used.start(), used.end())); + p2i(sp->used_region().start()), p2i(sp->used_region().end()), + p2i(used.start()), p2i(used.end()))); NOISY(tty->print_cr(" process_chunk_boundary: heap expanded; explicitly bounding last_chunk");) last_chunk_index_to_check = last_chunk_index; } diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index f1be6547dd6..775a6a513c6 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -55,8 +55,6 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/workgroup.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - #ifdef _MSC_VER #pragma warning( push ) #pragma warning( disable:4355 ) // 'this' : used in base member initializer list @@ -1212,7 +1210,7 @@ oop ParNewGeneration::copy_to_survivor_space( if (TraceScavenge) { gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}", is_in_reserved(new_obj) ? "copying" : "tenuring", - new_obj->klass()->internal_name(), (void *)old, (void *)new_obj, new_obj->size()); + new_obj->klass()->internal_name(), p2i(old), p2i(new_obj), new_obj->size()); } #endif From 4e7e0848a761d8891207b5d2c82b654520ee9a72 Mon Sep 17 00:00:00 2001 From: David Lindholm Date: Fri, 27 Mar 2015 15:29:19 +0100 Subject: [PATCH 076/362] 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files Reviewed-by: stefank, brutisso --- .../vm/gc_implementation/shared/markSweep.cpp | 2 - .../shared/mutableNUMASpace.cpp | 4 +- .../gc_implementation/shared/mutableSpace.cpp | 4 +- .../shared/spaceDecorator.cpp | 4 +- .../src/share/vm/memory/defNewGeneration.cpp | 4 +- .../src/share/vm/memory/genCollectedHeap.cpp | 2 +- hotspot/src/share/vm/memory/generation.cpp | 8 +-- hotspot/src/share/vm/memory/generation.hpp | 2 +- .../src/share/vm/memory/heapInspection.cpp | 16 ++--- hotspot/src/share/vm/memory/metachunk.cpp | 4 +- hotspot/src/share/vm/memory/metaspace.cpp | 68 +++++++++---------- .../share/vm/memory/referenceProcessor.cpp | 64 +++++++++-------- hotspot/src/share/vm/memory/sharedHeap.cpp | 2 - hotspot/src/share/vm/memory/space.cpp | 18 +++-- .../vm/memory/threadLocalAllocBuffer.cpp | 6 +- hotspot/src/share/vm/memory/universe.cpp | 6 +- 16 files changed, 93 insertions(+), 121 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp b/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp index dadffdf01b5..bcf4fef7184 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp +++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp @@ -32,8 +32,6 @@ #include "oops/objArrayKlass.inline.hpp" #include "oops/oop.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - uint MarkSweep::_total_invocations = 0; Stack MarkSweep::_marking_stack; diff --git a/hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp b/hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp index bdb746fe09e..1d4564160a0 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp +++ b/hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp @@ -31,8 +31,6 @@ #include "runtime/atomic.inline.hpp" #include "runtime/thread.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - MutableNUMASpace::MutableNUMASpace(size_t alignment) : MutableSpace(alignment) { _lgrp_spaces = new (ResourceObj::C_HEAP, mtGC) GrowableArray(0, true); _page_size = os::vm_page_size(); @@ -973,7 +971,7 @@ void MutableNUMASpace::LGRPSpace::scan_pages(size_t page_size, size_t page_count break; } if (e != scan_end) { - assert(e < scan_end, err_msg("e: " PTR_FORMAT " scan_end: " PTR_FORMAT, e, scan_end)); + assert(e < scan_end, err_msg("e: " PTR_FORMAT " scan_end: " PTR_FORMAT, p2i(e), p2i(scan_end))); if ((page_expected.size != page_size || page_expected.lgrp_id != lgrp_id()) && page_expected.size != 0) { diff --git a/hotspot/src/share/vm/gc_implementation/shared/mutableSpace.cpp b/hotspot/src/share/vm/gc_implementation/shared/mutableSpace.cpp index e2e4a6b8e04..a0884bf36a2 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/mutableSpace.cpp +++ b/hotspot/src/share/vm/gc_implementation/shared/mutableSpace.cpp @@ -33,8 +33,6 @@ #include "runtime/thread.hpp" #endif // INCLUDE_ALL_GCS -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - MutableSpace::MutableSpace(size_t alignment): ImmutableSpace(), _top(NULL), _alignment(alignment) { assert(MutableSpace::alignment() % os::vm_page_size() == 0, "Space should be aligned"); @@ -253,7 +251,7 @@ void MutableSpace::print() const { print_on(tty); } void MutableSpace::print_on(outputStream* st) const { MutableSpace::print_short_on(st); st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")", - bottom(), top(), end()); + p2i(bottom()), p2i(top()), p2i(end())); } void MutableSpace::verify() { diff --git a/hotspot/src/share/vm/gc_implementation/shared/spaceDecorator.cpp b/hotspot/src/share/vm/gc_implementation/shared/spaceDecorator.cpp index 15e38aa1ba1..1ff1e51c72d 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/spaceDecorator.cpp +++ b/hotspot/src/share/vm/gc_implementation/shared/spaceDecorator.cpp @@ -27,8 +27,6 @@ #include "memory/space.inline.hpp" #include "utilities/copy.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // Catch-all file for utility classes #ifndef PRODUCT @@ -86,7 +84,7 @@ void SpaceMangler::mangle_region(MemRegion mr) { assert(ZapUnusedHeapArea, "Mangling should not be in use"); #ifdef ASSERT if(TraceZapUnusedHeapArea) { - gclog_or_tty->print("Mangling [" PTR_FORMAT " to " PTR_FORMAT ")", mr.start(), mr.end()); + gclog_or_tty->print("Mangling [" PTR_FORMAT " to " PTR_FORMAT ")", p2i(mr.start()), p2i(mr.end())); } Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord); if(TraceZapUnusedHeapArea) { diff --git a/hotspot/src/share/vm/memory/defNewGeneration.cpp b/hotspot/src/share/vm/memory/defNewGeneration.cpp index c0eeb620010..e306632374c 100644 --- a/hotspot/src/share/vm/memory/defNewGeneration.cpp +++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp @@ -49,8 +49,6 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/stack.inline.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // // DefNewGeneration functions. @@ -137,7 +135,7 @@ void KlassScanClosure::do_klass(Klass* klass) { if (TraceScavenge) { ResourceMark rm; gclog_or_tty->print_cr("KlassScanClosure::do_klass " PTR_FORMAT ", %s, dirty: %s", - klass, + p2i(klass), klass->external_name(), klass->has_modified_oops() ? "true" : "false"); } diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.cpp b/hotspot/src/share/vm/memory/genCollectedHeap.cpp index 64c37b3655c..67d4fa56eb9 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp @@ -1337,7 +1337,7 @@ jlong GenCollectedHeap::millis_since_last_gc() { // back a time later than 'now'. jlong retVal = now - tolgc_cl.time(); if (retVal < 0) { - NOT_PRODUCT(warning("time warp: "INT64_FORMAT, (int64_t) retVal);) + NOT_PRODUCT(warning("time warp: " JLONG_FORMAT, retVal);) return 0; } return retVal; diff --git a/hotspot/src/share/vm/memory/generation.cpp b/hotspot/src/share/vm/memory/generation.cpp index 205cbce34a4..e27cb603291 100644 --- a/hotspot/src/share/vm/memory/generation.cpp +++ b/hotspot/src/share/vm/memory/generation.cpp @@ -42,8 +42,6 @@ #include "utilities/copy.hpp" #include "utilities/events.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - Generation::Generation(ReservedSpace rs, size_t initial_size, int level) : _level(level), _ref_processor(NULL) { @@ -103,9 +101,9 @@ void Generation::print_on(outputStream* st) const { st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K", capacity()/K, used()/K); st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", - _virtual_space.low_boundary(), - _virtual_space.high(), - _virtual_space.high_boundary()); + p2i(_virtual_space.low_boundary()), + p2i(_virtual_space.high()), + p2i(_virtual_space.high_boundary())); } void Generation::print_summary_info() { print_summary_info_on(tty); } diff --git a/hotspot/src/share/vm/memory/generation.hpp b/hotspot/src/share/vm/memory/generation.hpp index a2e15a08895..650f54b72f8 100644 --- a/hotspot/src/share/vm/memory/generation.hpp +++ b/hotspot/src/share/vm/memory/generation.hpp @@ -399,7 +399,7 @@ class Generation: public CHeapObj { // have to guard against non-monotonicity. NOT_PRODUCT( if (now < _time_of_last_gc) { - warning("time warp: "INT64_FORMAT" to "INT64_FORMAT, (int64_t)_time_of_last_gc, (int64_t)now); + warning("time warp: " JLONG_FORMAT " to " JLONG_FORMAT, _time_of_last_gc, now); } ) return _time_of_last_gc; diff --git a/hotspot/src/share/vm/memory/heapInspection.cpp b/hotspot/src/share/vm/memory/heapInspection.cpp index c4b5ba787d0..31ba78e8db1 100644 --- a/hotspot/src/share/vm/memory/heapInspection.cpp +++ b/hotspot/src/share/vm/memory/heapInspection.cpp @@ -38,8 +38,6 @@ #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" #endif // INCLUDE_ALL_GCS -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // HeapInspection inline KlassInfoEntry::~KlassInfoEntry() { @@ -100,8 +98,8 @@ void KlassInfoEntry::print_on(outputStream* st) const { // simplify the formatting (ILP32 vs LP64) - always cast the numbers to 64-bit st->print_cr(INT64_FORMAT_W(13) " " UINT64_FORMAT_W(13) " %s", - (jlong) _instance_count, - (julong) _instance_words * HeapWordSize, + (int64_t)_instance_count, + (uint64_t)_instance_words * HeapWordSize, name()); } @@ -240,8 +238,8 @@ void KlassInfoHisto::sort() { void KlassInfoHisto::print_elements(outputStream* st) const { // simplify the formatting (ILP32 vs LP64) - store the sum in 64-bit - jlong total = 0; - julong totalw = 0; + int64_t total = 0; + uint64_t totalw = 0; for(int i=0; i < elements()->length(); i++) { st->print("%4d: ", i+1); elements()->at(i)->print_on(st); @@ -451,7 +449,7 @@ static void print_classname(outputStream* st, Klass* klass) { if (loader_oop == NULL) { st->print("null"); } else { - st->print(INTPTR_FORMAT, klass->class_loader_data()); + st->print(INTPTR_FORMAT, p2i(klass->class_loader_data())); } } @@ -557,13 +555,13 @@ void KlassInfoHisto::print_class_stats(outputStream* st, } if (csv_format) { - st->print("%d,%d", e->index(), super_index); + st->print("%ld,%d", e->index(), super_index); for (int c=0; cprint("," JULONG_FORMAT, col_table[c]);} } st->print(",%s",e->name()); } else { - st->print("%5d %5d", e->index(), super_index); + st->print("%5ld %5d", e->index(), super_index); for (int c=0; cprint_cr("Metachunk:" " bottom " PTR_FORMAT " top " PTR_FORMAT " end " PTR_FORMAT " size " SIZE_FORMAT, - bottom(), _top, end(), word_size()); + p2i(bottom()), p2i(_top), p2i(end()), word_size()); if (Verbose) { st->print_cr(" used " SIZE_FORMAT " free " SIZE_FORMAT, used_word_size(), free_word_size()); diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index 8f7476d8469..d60679d43fb 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -49,8 +49,6 @@ #include "utilities/debug.hpp" #include "utilities/macros.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - typedef BinaryTreeDictionary > BlockTreeDictionary; typedef BinaryTreeDictionary > ChunkTreeDictionary; @@ -388,7 +386,7 @@ class VirtualSpaceNode : public CHeapObj { #define assert_is_ptr_aligned(ptr, alignment) \ assert(is_ptr_aligned(ptr, alignment), \ err_msg(PTR_FORMAT " is not aligned to " \ - SIZE_FORMAT, ptr, alignment)) + SIZE_FORMAT, p2i(ptr), alignment)) #define assert_is_size_aligned(size, alignment) \ assert(is_size_aligned(size, alignment), \ @@ -800,7 +798,7 @@ void VirtualSpaceNode::inc_container_count() { _container_count++; assert(_container_count == container_count_slow(), err_msg("Inconsistency in container_count _container_count " SIZE_FORMAT - " container_count_slow() " SIZE_FORMAT, + " container_count_slow() %u", _container_count, container_count_slow())); } @@ -813,7 +811,7 @@ void VirtualSpaceNode::dec_container_count() { void VirtualSpaceNode::verify_container_count() { assert(_container_count == container_count_slow(), err_msg("Inconsistency in container_count _container_count " SIZE_FORMAT - " container_count_slow() " SIZE_FORMAT, _container_count, container_count_slow())); + " container_count_slow() %u", _container_count, container_count_slow())); } #endif @@ -916,7 +914,7 @@ Metachunk* VirtualSpaceNode::take_from_committed(size_t chunk_word_size) { if (!is_available(chunk_word_size)) { if (TraceMetadataChunkAllocation) { - gclog_or_tty->print("VirtualSpaceNode::take_from_committed() not available %d words ", chunk_word_size); + gclog_or_tty->print("VirtualSpaceNode::take_from_committed() not available " SIZE_FORMAT " words ", chunk_word_size); // Dump some information about the virtual space that is nearly full print_on(gclog_or_tty); } @@ -989,7 +987,7 @@ bool VirtualSpaceNode::initialize() { assert(reserved()->start() == (HeapWord*) _rs.base(), err_msg("Reserved start was not set properly " PTR_FORMAT - " != " PTR_FORMAT, reserved()->start(), _rs.base())); + " != " PTR_FORMAT, p2i(reserved()->start()), p2i(_rs.base()))); assert(reserved()->word_size() == _rs.size() / BytesPerWord, err_msg("Reserved size was not set properly " SIZE_FORMAT " != " SIZE_FORMAT, reserved()->word_size(), @@ -1003,13 +1001,13 @@ void VirtualSpaceNode::print_on(outputStream* st) const { size_t used = used_words_in_vs(); size_t capacity = capacity_words_in_vs(); VirtualSpace* vs = virtual_space(); - st->print_cr(" space @ " PTR_FORMAT " " SIZE_FORMAT "K, %3d%% used " + st->print_cr(" space @ " PTR_FORMAT " " SIZE_FORMAT "K, " SIZE_FORMAT_W(3) "%% used " "[" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")", - vs, capacity / K, + p2i(vs), capacity / K, capacity == 0 ? 0 : used * 100 / capacity, - bottom(), top(), end(), - vs->high_boundary()); + p2i(bottom()), p2i(top()), p2i(end()), + p2i(vs->high_boundary())); } #ifdef ASSERT @@ -1812,7 +1810,7 @@ Metachunk* ChunkManager::free_chunks_get(size_t word_size) { if (TraceMetadataChunkAllocation && Verbose) { gclog_or_tty->print_cr("ChunkManager::free_chunks_get: free_list " PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT, - free_list, chunk, chunk->word_size()); + p2i(free_list), p2i(chunk), chunk->word_size()); } } else { chunk = humongous_dictionary()->get_chunk( @@ -1872,7 +1870,7 @@ Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) { } gclog_or_tty->print("ChunkManager::chunk_freelist_allocate: " PTR_FORMAT " chunk " PTR_FORMAT " size " SIZE_FORMAT " count " SIZE_FORMAT " ", - this, chunk, chunk->word_size(), list_count); + p2i(this), p2i(chunk), chunk->word_size(), list_count); locked_print_free_chunks(gclog_or_tty); } @@ -2019,7 +2017,7 @@ void SpaceManager::locked_print_chunks_in_use_on(outputStream* st) const { for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) { Metachunk* chunk = chunks_in_use(i); st->print("SpaceManager: %s " PTR_FORMAT, - chunk_size_name(i), chunk); + chunk_size_name(i), p2i(chunk)); if (chunk != NULL) { st->print_cr(" free " SIZE_FORMAT, chunk->free_word_size()); @@ -2130,8 +2128,8 @@ void SpaceManager::print_on(outputStream* st) const { for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists ; i = next_chunk_index(i) ) { - st->print_cr(" chunks_in_use " PTR_FORMAT " chunk size " PTR_FORMAT, - chunks_in_use(i), + st->print_cr(" chunks_in_use " PTR_FORMAT " chunk size " SIZE_FORMAT, + p2i(chunks_in_use(i)), chunks_in_use(i) == NULL ? 0 : chunks_in_use(i)->word_size()); } st->print_cr(" waste: Small " SIZE_FORMAT " Medium " SIZE_FORMAT @@ -2194,7 +2192,7 @@ void SpaceManager::initialize() { } _current_chunk = NULL; if (TraceMetadataChunkAllocation && Verbose) { - gclog_or_tty->print_cr("SpaceManager(): " PTR_FORMAT, this); + gclog_or_tty->print_cr("SpaceManager(): " PTR_FORMAT, p2i(this)); } } @@ -2238,7 +2236,7 @@ SpaceManager::~SpaceManager() { dec_total_from_size_metrics(); if (TraceMetadataChunkAllocation && Verbose) { - gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, this); + gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, p2i(this)); locked_print_chunks_in_use_on(gclog_or_tty); } @@ -2258,7 +2256,7 @@ SpaceManager::~SpaceManager() { for (ChunkIndex i = ZeroIndex; i < HumongousIndex; i = next_chunk_index(i)) { if (TraceMetadataChunkAllocation && Verbose) { - gclog_or_tty->print_cr("returned %d %s chunks to freelist", + gclog_or_tty->print_cr("returned " SIZE_FORMAT " %s chunks to freelist", sum_count_in_chunks_in_use(i), chunk_size_name(i)); } @@ -2266,7 +2264,7 @@ SpaceManager::~SpaceManager() { chunk_manager()->return_chunks(i, chunks); set_chunks_in_use(i, NULL); if (TraceMetadataChunkAllocation && Verbose) { - gclog_or_tty->print_cr("updated freelist count %d %s", + gclog_or_tty->print_cr("updated freelist count " SSIZE_FORMAT " %s", chunk_manager()->free_chunks(i)->count(), chunk_size_name(i)); } @@ -2279,7 +2277,7 @@ SpaceManager::~SpaceManager() { // Humongous chunks if (TraceMetadataChunkAllocation && Verbose) { - gclog_or_tty->print_cr("returned %d %s humongous chunks to dictionary", + gclog_or_tty->print_cr("returned " SIZE_FORMAT " %s humongous chunks to dictionary", sum_count_in_chunks_in_use(HumongousIndex), chunk_size_name(HumongousIndex)); gclog_or_tty->print("Humongous chunk dictionary: "); @@ -2293,14 +2291,14 @@ SpaceManager::~SpaceManager() { #endif if (TraceMetadataChunkAllocation && Verbose) { gclog_or_tty->print(PTR_FORMAT " (" SIZE_FORMAT ") ", - humongous_chunks, + p2i(humongous_chunks), humongous_chunks->word_size()); } assert(humongous_chunks->word_size() == (size_t) align_size_up(humongous_chunks->word_size(), smallest_chunk_size()), err_msg("Humongous chunk size is wrong: word size " SIZE_FORMAT - " granularity %d", + " granularity " SIZE_FORMAT, humongous_chunks->word_size(), smallest_chunk_size())); Metachunk* next_humongous_chunks = humongous_chunks->next(); humongous_chunks->container()->dec_container_count(); @@ -2309,7 +2307,7 @@ SpaceManager::~SpaceManager() { } if (TraceMetadataChunkAllocation && Verbose) { gclog_or_tty->cr(); - gclog_or_tty->print_cr("updated dictionary count %d %s", + gclog_or_tty->print_cr("updated dictionary count " SIZE_FORMAT " %s", chunk_manager()->humongous_dictionary()->total_count(), chunk_size_name(HumongousIndex)); } @@ -2399,7 +2397,7 @@ void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) { assert(new_chunk->is_empty(), "Not ready for reuse"); if (TraceMetadataChunkAllocation && Verbose) { - gclog_or_tty->print("SpaceManager::add_chunk: %d) ", + gclog_or_tty->print("SpaceManager::add_chunk: " SIZE_FORMAT ") ", sum_count_in_chunks_in_use()); new_chunk->print_on(gclog_or_tty); chunk_manager()->locked_print_free_chunks(gclog_or_tty); @@ -3097,7 +3095,7 @@ void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, a metaspace_rs = ReservedSpace(compressed_class_space_size(), _reserve_alignment, large_pages); if (!metaspace_rs.is_reserved()) { - vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes", + vm_exit_during_initialization(err_msg("Could not allocate metaspace: " SIZE_FORMAT " bytes", compressed_class_space_size())); } } @@ -3119,10 +3117,10 @@ void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, a initialize_class_space(metaspace_rs); if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) { - gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: " SIZE_FORMAT, - Universe::narrow_klass_base(), Universe::narrow_klass_shift()); + gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: %d", + p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift()); gclog_or_tty->print_cr("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT, - compressed_class_space_size(), metaspace_rs.base(), requested_addr); + compressed_class_space_size(), p2i(metaspace_rs.base()), p2i(requested_addr)); } } @@ -3251,7 +3249,7 @@ void Metaspace::global_initialize() { vm_exit_during_initialization("Unable to dump shared archive.", err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space (" SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed " - "klass limit: " SIZE_FORMAT, cds_total, compressed_class_space_size(), + "klass limit: " UINT64_FORMAT, cds_total, compressed_class_space_size(), cds_total + compressed_class_space_size(), UnscaledClassSpaceMax)); } @@ -3262,7 +3260,7 @@ void Metaspace::global_initialize() { Universe::set_narrow_klass_base((address)_space_list->current_virtual_space()->bottom()); if (TraceMetavirtualspaceAllocation && Verbose) { gclog_or_tty->print_cr("Setting_narrow_klass_base to Address: " PTR_FORMAT, - _space_list->current_virtual_space()->bottom()); + p2i(_space_list->current_virtual_space()->bottom())); } Universe::set_narrow_klass_shift(0); @@ -3768,10 +3766,10 @@ void Metaspace::verify() { } void Metaspace::dump(outputStream* const out) const { - out->print_cr("\nVirtual space manager: " INTPTR_FORMAT, vsm()); + out->print_cr("\nVirtual space manager: " INTPTR_FORMAT, p2i(vsm())); vsm()->dump(out); if (using_class_space()) { - out->print_cr("\nClass space manager: " INTPTR_FORMAT, class_vsm()); + out->print_cr("\nClass space manager: " INTPTR_FORMAT, p2i(class_vsm())); class_vsm()->dump(out); } } @@ -3932,13 +3930,13 @@ class TestVirtualSpaceNodeTest { assert(vsn.is_available(word_size), \ err_msg(#word_size ": " PTR_FORMAT " bytes were not available in " \ "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \ - (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end())); + (uintptr_t)(word_size * BytesPerWord), p2i(vsn.bottom()), p2i(vsn.end()))); #define assert_is_available_negative(word_size) \ assert(!vsn.is_available(word_size), \ err_msg(#word_size ": " PTR_FORMAT " bytes should not be available in " \ "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \ - (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end())); + (uintptr_t)(word_size * BytesPerWord), p2i(vsn.bottom()), p2i(vsn.end()))); static void test_is_available_positive() { // Reserve some memory. diff --git a/hotspot/src/share/vm/memory/referenceProcessor.cpp b/hotspot/src/share/vm/memory/referenceProcessor.cpp index 1a011ce1e91..ad668d667ec 100644 --- a/hotspot/src/share/vm/memory/referenceProcessor.cpp +++ b/hotspot/src/share/vm/memory/referenceProcessor.cpp @@ -35,8 +35,6 @@ #include "runtime/java.hpp" #include "runtime/jniHandles.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL; ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy = NULL; bool ReferenceProcessor::_pending_list_uses_discovered_field = false; @@ -161,7 +159,7 @@ void ReferenceProcessor::update_soft_ref_master_clock() { NOT_PRODUCT( if (now < _soft_ref_timestamp_clock) { - warning("time warp: "INT64_FORMAT" to "INT64_FORMAT, + warning("time warp: " JLONG_FORMAT " to " JLONG_FORMAT, _soft_ref_timestamp_clock, now); } ) @@ -361,7 +359,7 @@ void ReferenceProcessor::enqueue_discovered_reflist(DiscoveredList& refs_list, // field. if (TraceReferenceGC && PrintGCDetails) { gclog_or_tty->print_cr("ReferenceProcessor::enqueue_discovered_reflist list " - INTPTR_FORMAT, (address)refs_list.head()); + INTPTR_FORMAT, p2i(refs_list.head())); } oop obj = NULL; @@ -375,7 +373,7 @@ void ReferenceProcessor::enqueue_discovered_reflist(DiscoveredList& refs_list, next_d = java_lang_ref_Reference::discovered(obj); if (TraceReferenceGC && PrintGCDetails) { gclog_or_tty->print_cr(" obj " INTPTR_FORMAT "/next_d " INTPTR_FORMAT, - (void *)obj, (void *)next_d); + p2i(obj), p2i(next_d)); } assert(java_lang_ref_Reference::next(obj) == NULL, "Reference not active; should not be discovered"); @@ -402,7 +400,7 @@ void ReferenceProcessor::enqueue_discovered_reflist(DiscoveredList& refs_list, next_d = java_lang_ref_Reference::discovered(obj); if (TraceReferenceGC && PrintGCDetails) { gclog_or_tty->print_cr(" obj " INTPTR_FORMAT "/next_d " INTPTR_FORMAT, - (void *)obj, (void *)next_d); + p2i(obj), p2i(next_d)); } assert(java_lang_ref_Reference::next(obj) == NULL, "The reference should not be enqueued"); @@ -565,7 +563,7 @@ ReferenceProcessor::process_phase1(DiscoveredList& refs_list, !policy->should_clear_reference(iter.obj(), _soft_ref_timestamp_clock)) { if (TraceReferenceGC) { gclog_or_tty->print_cr("Dropping reference (" INTPTR_FORMAT ": %s" ") by policy", - (void *)iter.obj(), iter.obj()->klass()->internal_name()); + p2i(iter.obj()), iter.obj()->klass()->internal_name()); } // Remove Reference object from list iter.remove(); @@ -582,9 +580,9 @@ ReferenceProcessor::process_phase1(DiscoveredList& refs_list, complete_gc->do_void(); NOT_PRODUCT( if (PrintGCDetails && TraceReferenceGC) { - gclog_or_tty->print_cr(" Dropped %d dead Refs out of %d " - "discovered Refs by policy, from list " INTPTR_FORMAT, - iter.removed(), iter.processed(), (address)refs_list.head()); + gclog_or_tty->print_cr(" Dropped " SIZE_FORMAT " dead Refs out of " SIZE_FORMAT + " discovered Refs by policy, from list " INTPTR_FORMAT, + iter.removed(), iter.processed(), p2i(refs_list.head())); } ) } @@ -604,7 +602,7 @@ ReferenceProcessor::pp2_work(DiscoveredList& refs_list, if (iter.is_referent_alive()) { if (TraceReferenceGC) { gclog_or_tty->print_cr("Dropping strongly reachable reference (" INTPTR_FORMAT ": %s)", - (void *)iter.obj(), iter.obj()->klass()->internal_name()); + p2i(iter.obj()), iter.obj()->klass()->internal_name()); } // The referent is reachable after all. // Remove Reference object from list. @@ -620,9 +618,9 @@ ReferenceProcessor::pp2_work(DiscoveredList& refs_list, } NOT_PRODUCT( if (PrintGCDetails && TraceReferenceGC && (iter.processed() > 0)) { - gclog_or_tty->print_cr(" Dropped %d active Refs out of %d " - "Refs in discovered list " INTPTR_FORMAT, - iter.removed(), iter.processed(), (address)refs_list.head()); + gclog_or_tty->print_cr(" Dropped " SIZE_FORMAT " active Refs out of " SIZE_FORMAT + " Refs in discovered list " INTPTR_FORMAT, + iter.removed(), iter.processed(), p2i(refs_list.head())); } ) } @@ -659,9 +657,9 @@ ReferenceProcessor::pp2_work_concurrent_discovery(DiscoveredList& refs_list, complete_gc->do_void(); NOT_PRODUCT( if (PrintGCDetails && TraceReferenceGC && (iter.processed() > 0)) { - gclog_or_tty->print_cr(" Dropped %d active Refs out of %d " - "Refs in discovered list " INTPTR_FORMAT, - iter.removed(), iter.processed(), (address)refs_list.head()); + gclog_or_tty->print_cr(" Dropped " SIZE_FORMAT " active Refs out of " SIZE_FORMAT + " Refs in discovered list " INTPTR_FORMAT, + iter.removed(), iter.processed(), p2i(refs_list.head())); } ) } @@ -690,7 +688,7 @@ ReferenceProcessor::process_phase3(DiscoveredList& refs_list, if (TraceReferenceGC) { gclog_or_tty->print_cr("Adding %sreference (" INTPTR_FORMAT ": %s) as pending", clear_referent ? "cleared " : "", - (void *)iter.obj(), iter.obj()->klass()->internal_name()); + p2i(iter.obj()), iter.obj()->klass()->internal_name()); } assert(iter.obj()->is_oop(UseConcMarkSweepGC), "Adding a bad reference"); iter.next(); @@ -807,11 +805,11 @@ void ReferenceProcessor::balance_queues(DiscoveredList ref_lists[]) for (uint i = 0; i < _max_num_q; ++i) { total_refs += ref_lists[i].length(); if (TraceReferenceGC && PrintGCDetails) { - gclog_or_tty->print("%d ", ref_lists[i].length()); + gclog_or_tty->print(SIZE_FORMAT " ", ref_lists[i].length()); } } if (TraceReferenceGC && PrintGCDetails) { - gclog_or_tty->print_cr(" = %d", total_refs); + gclog_or_tty->print_cr(" = " SIZE_FORMAT, total_refs); } size_t avg_refs = total_refs / _num_q + 1; uint to_idx = 0; @@ -877,11 +875,11 @@ void ReferenceProcessor::balance_queues(DiscoveredList ref_lists[]) for (uint i = 0; i < _max_num_q; ++i) { balanced_total_refs += ref_lists[i].length(); if (TraceReferenceGC && PrintGCDetails) { - gclog_or_tty->print("%d ", ref_lists[i].length()); + gclog_or_tty->print(SIZE_FORMAT " ", ref_lists[i].length()); } } if (TraceReferenceGC && PrintGCDetails) { - gclog_or_tty->print_cr(" = %d", balanced_total_refs); + gclog_or_tty->print_cr(" = " SIZE_FORMAT, balanced_total_refs); gclog_or_tty->flush(); } assert(total_refs == balanced_total_refs, "Balancing was incomplete"); @@ -923,7 +921,7 @@ ReferenceProcessor::process_discovered_reflist( size_t total_list_count = total_count(refs_lists); if (PrintReferenceGC && PrintGCDetails) { - gclog_or_tty->print(", %u refs", total_list_count); + gclog_or_tty->print(", " SIZE_FORMAT " refs", total_list_count); } // Phase 1 (soft refs only): @@ -1016,7 +1014,7 @@ inline DiscoveredList* ReferenceProcessor::get_discovered_list(ReferenceType rt) ShouldNotReachHere(); } if (TraceReferenceGC && PrintGCDetails) { - gclog_or_tty->print_cr("Thread %d gets list " INTPTR_FORMAT, id, list); + gclog_or_tty->print_cr("Thread %d gets list " INTPTR_FORMAT, id, p2i(list)); } return list; } @@ -1043,14 +1041,14 @@ ReferenceProcessor::add_to_discovered_list_mt(DiscoveredList& refs_list, if (TraceReferenceGC) { gclog_or_tty->print_cr("Discovered reference (mt) (" INTPTR_FORMAT ": %s)", - (void *)obj, obj->klass()->internal_name()); + p2i(obj), obj->klass()->internal_name()); } } else { // If retest was non NULL, another thread beat us to it: // The reference has already been discovered... if (TraceReferenceGC) { gclog_or_tty->print_cr("Already discovered reference (" INTPTR_FORMAT ": %s)", - (void *)obj, obj->klass()->internal_name()); + p2i(obj), obj->klass()->internal_name()); } } } @@ -1065,7 +1063,7 @@ void ReferenceProcessor::verify_referent(oop obj) { assert(da ? referent->is_oop() : referent->is_oop_or_null(), err_msg("Bad referent " INTPTR_FORMAT " found in Reference " INTPTR_FORMAT " during %satomic discovery ", - (void *)referent, (void *)obj, da ? "" : "non-")); + p2i(referent), p2i(obj), da ? "" : "non-")); } #endif @@ -1145,7 +1143,7 @@ bool ReferenceProcessor::discover_reference(oop obj, ReferenceType rt) { // The reference has already been discovered... if (TraceReferenceGC) { gclog_or_tty->print_cr("Already discovered reference (" INTPTR_FORMAT ": %s)", - (void *)obj, obj->klass()->internal_name()); + p2i(obj), obj->klass()->internal_name()); } if (RefDiscoveryPolicy == ReferentBasedDiscovery) { // assumes that an object is not processed twice; @@ -1203,7 +1201,7 @@ bool ReferenceProcessor::discover_reference(oop obj, ReferenceType rt) { if (TraceReferenceGC) { gclog_or_tty->print_cr("Discovered reference (" INTPTR_FORMAT ": %s)", - (void *)obj, obj->klass()->internal_name()); + p2i(obj), obj->klass()->internal_name()); } } assert(obj->is_oop(), "Discovered a bad reference"); @@ -1314,7 +1312,7 @@ ReferenceProcessor::preclean_discovered_reflist(DiscoveredList& refs_list, // active; we need to trace and mark its cohort. if (TraceReferenceGC) { gclog_or_tty->print_cr("Precleaning Reference (" INTPTR_FORMAT ": %s)", - (void *)iter.obj(), iter.obj()->klass()->internal_name()); + p2i(iter.obj()), iter.obj()->klass()->internal_name()); } // Remove Reference object from list iter.remove(); @@ -1337,9 +1335,9 @@ ReferenceProcessor::preclean_discovered_reflist(DiscoveredList& refs_list, NOT_PRODUCT( if (PrintGCDetails && PrintReferenceGC && (iter.processed() > 0)) { - gclog_or_tty->print_cr(" Dropped %d Refs out of %d " - "Refs in discovered list " INTPTR_FORMAT, - iter.removed(), iter.processed(), (address)refs_list.head()); + gclog_or_tty->print_cr(" Dropped " SIZE_FORMAT " Refs out of " SIZE_FORMAT + " Refs in discovered list " INTPTR_FORMAT, + iter.removed(), iter.processed(), p2i(refs_list.head())); } ) } diff --git a/hotspot/src/share/vm/memory/sharedHeap.cpp b/hotspot/src/share/vm/memory/sharedHeap.cpp index 1dde1e13c5e..5f07a7695ee 100644 --- a/hotspot/src/share/vm/memory/sharedHeap.cpp +++ b/hotspot/src/share/vm/memory/sharedHeap.cpp @@ -35,8 +35,6 @@ #include "utilities/copy.hpp" #include "utilities/workgroup.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - SharedHeap* SharedHeap::_sh; SharedHeap::SharedHeap(CollectorPolicy* policy_) : diff --git a/hotspot/src/share/vm/memory/space.cpp b/hotspot/src/share/vm/memory/space.cpp index 6e9984f9860..d0fdd3c615e 100644 --- a/hotspot/src/share/vm/memory/space.cpp +++ b/hotspot/src/share/vm/memory/space.cpp @@ -44,8 +44,6 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/macros.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top, HeapWord* top_obj) { if (top_obj != NULL) { @@ -456,20 +454,20 @@ void Space::print() const { print_on(tty); } void Space::print_on(outputStream* st) const { print_short_on(st); st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ")", - bottom(), end()); + p2i(bottom()), p2i(end())); } void ContiguousSpace::print_on(outputStream* st) const { print_short_on(st); st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", - bottom(), top(), end()); + p2i(bottom()), p2i(top()), p2i(end())); } void OffsetTableContigSpace::print_on(outputStream* st) const { print_short_on(st); st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", - bottom(), top(), _offsets.threshold(), end()); + p2i(bottom()), p2i(top()), p2i(_offsets.threshold()), p2i(end())); } void ContiguousSpace::verify() const { @@ -592,7 +590,7 @@ ALL_SINCE_SAVE_MARKS_CLOSURES(ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN) HeapWord* ContiguousSpace::block_start_const(const void* p) const { assert(MemRegion(bottom(), end()).contains(p), err_msg("p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")", - p, bottom(), end())); + p2i(p), p2i(bottom()), p2i(end()))); if (p >= top()) { return top(); } else { @@ -603,7 +601,7 @@ HeapWord* ContiguousSpace::block_start_const(const void* p) const { cur += oop(cur)->size(); } assert(oop(last)->is_oop(), - err_msg(PTR_FORMAT " should be an object start", last)); + err_msg(PTR_FORMAT " should be an object start", p2i(last))); return last; } } @@ -611,15 +609,15 @@ HeapWord* ContiguousSpace::block_start_const(const void* p) const { size_t ContiguousSpace::block_size(const HeapWord* p) const { assert(MemRegion(bottom(), end()).contains(p), err_msg("p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")", - p, bottom(), end())); + p2i(p), p2i(bottom()), p2i(end()))); HeapWord* current_top = top(); assert(p <= current_top, err_msg("p > current top - p: " PTR_FORMAT ", current top: " PTR_FORMAT, - p, current_top)); + p2i(p), p2i(current_top))); assert(p == current_top || oop(p)->is_oop(), err_msg("p (" PTR_FORMAT ") is not a block start - " "current_top: " PTR_FORMAT ", is_oop: %s", - p, current_top, BOOL_TO_STR(oop(p)->is_oop()))); + p2i(p), p2i(current_top), BOOL_TO_STR(oop(p)->is_oop()))); if (p < current_top) { return oop(p)->size(); } else { diff --git a/hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp b/hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp index 06033439c5a..177d638922b 100644 --- a/hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp +++ b/hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp @@ -31,8 +31,6 @@ #include "runtime/thread.inline.hpp" #include "utilities/copy.hpp" -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // Thread-Local Edens support // static member initialization @@ -154,7 +152,7 @@ void ThreadLocalAllocBuffer::resize() { if (PrintTLAB && Verbose) { gclog_or_tty->print("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]" " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT "\n", - myThread(), myThread()->osthread()->thread_id(), + p2i(myThread()), myThread()->osthread()->thread_id(), _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size); } set_desired_size(aligned_new_size); @@ -263,7 +261,7 @@ void ThreadLocalAllocBuffer::print_stats(const char* tag) { " slow allocs: %d refill waste: " SIZE_FORMAT "B" " alloc:%8.5f %8.0fKB refills: %d waste %4.1f%% gc: %dB" " slow: %dB fast: %dB\n", - tag, thrd, thrd->osthread()->thread_id(), + tag, p2i(thrd), thrd->osthread()->thread_id(), _desired_size / (K / HeapWordSize), _slow_allocations, _refill_waste_limit * HeapWordSize, _allocation_fraction.average(), diff --git a/hotspot/src/share/vm/memory/universe.cpp b/hotspot/src/share/vm/memory/universe.cpp index 6c55aed8969..75f4f96e23a 100644 --- a/hotspot/src/share/vm/memory/universe.cpp +++ b/hotspot/src/share/vm/memory/universe.cpp @@ -84,8 +84,6 @@ #include "classfile/sharedClassUtil.hpp" #endif -PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC - // Known objects Klass* Universe::_boolArrayKlassObj = NULL; Klass* Universe::_byteArrayKlassObj = NULL; @@ -792,12 +790,12 @@ jint Universe::initialize_heap() { void Universe::print_compressed_oops_mode() { tty->cr(); tty->print("heap address: " PTR_FORMAT ", size: " SIZE_FORMAT " MB", - Universe::heap()->base(), Universe::heap()->reserved_region().byte_size()/M); + p2i(Universe::heap()->base()), Universe::heap()->reserved_region().byte_size()/M); tty->print(", Compressed Oops mode: %s", narrow_oop_mode_to_string(narrow_oop_mode())); if (Universe::narrow_oop_base() != 0) { - tty->print(": " PTR_FORMAT, Universe::narrow_oop_base()); + tty->print(": " PTR_FORMAT, p2i(Universe::narrow_oop_base())); } if (Universe::narrow_oop_shift() != 0) { From 062cf882e0d69e5b6f0e4319a2bfb739e11ced13 Mon Sep 17 00:00:00 2001 From: Mikael Gerdin Date: Tue, 31 Mar 2015 07:54:56 +0200 Subject: [PATCH 077/362] 8076225: Move the thread claim parity from SharedHeap to Thread Reviewed-by: brutisso, jwilhelm, kbarrett --- .../gc_implementation/g1/concurrentMark.cpp | 2 +- .../src/share/vm/memory/genCollectedHeap.cpp | 2 +- hotspot/src/share/vm/memory/sharedHeap.cpp | 17 ++++--------- hotspot/src/share/vm/memory/sharedHeap.hpp | 13 ++++------ hotspot/src/share/vm/runtime/thread.cpp | 24 +++++++++++++++++-- hotspot/src/share/vm/runtime/thread.hpp | 7 ++++-- 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp index 49116d28b37..60ae0b4cd91 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp @@ -2581,7 +2581,7 @@ class G1RemarkThreadsClosure : public ThreadClosure { public: G1RemarkThreadsClosure(G1CollectedHeap* g1h, CMTask* task) : _cm_obj(task), _cm_cl(g1h, g1h->concurrent_mark(), task), _code_cl(&_cm_cl, !CodeBlobToOopClosure::FixRelocations), - _thread_parity(SharedHeap::heap()->strong_roots_parity()) {} + _thread_parity(Threads::thread_claim_parity()) {} void do_thread(Thread* thread) { if (thread->is_Java_thread()) { diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.cpp b/hotspot/src/share/vm/memory/genCollectedHeap.cpp index 67d4fa56eb9..3ca321cf026 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp @@ -589,7 +589,7 @@ void GenCollectedHeap::process_roots(bool activate_scope, StrongRootsScope srs(this, activate_scope); // General roots. - assert(_strong_roots_parity != 0, "must have called prologue code"); + assert(Threads::thread_claim_parity() != 0, "must have called prologue code"); assert(code_roots != NULL, "code root closure should always be set"); // _n_termination for _process_strong_tasks should be set up stream // in a method not running in a GC worker. Otherwise the GC worker diff --git a/hotspot/src/share/vm/memory/sharedHeap.cpp b/hotspot/src/share/vm/memory/sharedHeap.cpp index 5f07a7695ee..3e93264d019 100644 --- a/hotspot/src/share/vm/memory/sharedHeap.cpp +++ b/hotspot/src/share/vm/memory/sharedHeap.cpp @@ -40,7 +40,6 @@ SharedHeap* SharedHeap::_sh; SharedHeap::SharedHeap(CollectorPolicy* policy_) : CollectedHeap(), _collector_policy(policy_), - _strong_roots_parity(0), _workers(NULL) { _sh = this; // ch is static, should be set only once. @@ -68,26 +67,20 @@ void SharedHeap::set_par_threads(uint t) { _n_par_threads = t; } -void SharedHeap::change_strong_roots_parity() { - // Also set the new collection parity. - assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2, - "Not in range."); - _strong_roots_parity++; - if (_strong_roots_parity == 3) _strong_roots_parity = 1; - assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2, - "Not in range."); -} - SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* heap, bool activate) : MarkScope(activate), _sh(heap) { if (_active) { - _sh->change_strong_roots_parity(); + Threads::change_thread_claim_parity(); // Zero the claimed high water mark in the StringTable StringTable::clear_parallel_claimed_index(); } } +SharedHeap::StrongRootsScope::~StrongRootsScope() { + Threads::assert_all_threads_claimed(); +} + void SharedHeap::set_barrier_set(BarrierSet* bs) { _barrier_set = bs; // Cached barrier set for fast access in oops diff --git a/hotspot/src/share/vm/memory/sharedHeap.hpp b/hotspot/src/share/vm/memory/sharedHeap.hpp index dec846acef4..edb9e468ceb 100644 --- a/hotspot/src/share/vm/memory/sharedHeap.hpp +++ b/hotspot/src/share/vm/memory/sharedHeap.hpp @@ -113,10 +113,6 @@ protected: // A gc policy, controls global gc resource issues CollectorPolicy *_collector_policy; - // See the discussion below, in the specification of the reader function - // for this variable. - int _strong_roots_parity; - // If we're doing parallel GC, use this gang of threads. FlexibleWorkGang* _workers; @@ -156,7 +152,10 @@ public: bool no_gc_in_progress() { return !is_gc_active(); } - // Some collectors will perform "process_strong_roots" in parallel. + // Note, the below comment needs to be updated to reflect the changes + // introduced by JDK-8076225. This should be done as part of JDK-8076289. + // + //Some collectors will perform "process_strong_roots" in parallel. // Such a call will involve claiming some fine-grained tasks, such as // scanning of threads. To make this process simpler, we provide the // "strong_roots_parity()" method. Collectors that start parallel tasks @@ -182,7 +181,6 @@ public: // task-claiming variables may be initialized, to indicate "never // claimed". public: - int strong_roots_parity() { return _strong_roots_parity; } // Call these in sequential code around process_roots. // strong_roots_prologue calls change_strong_roots_parity, if @@ -192,11 +190,10 @@ public: public: StrongRootsScope(SharedHeap* heap, bool activate = true); + ~StrongRootsScope(); }; - friend class StrongRootsScope; private: - void change_strong_roots_parity(); public: FlexibleWorkGang* workers() const { return _workers; } diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp index 7d6596d30ff..544903d918e 100644 --- a/hotspot/src/share/vm/runtime/thread.cpp +++ b/hotspot/src/share/vm/runtime/thread.cpp @@ -3183,6 +3183,7 @@ JavaThread* Threads::_thread_list = NULL; int Threads::_number_of_threads = 0; int Threads::_number_of_non_daemon_threads = 0; int Threads::_return_code = 0; +int Threads::_thread_claim_parity = 0; size_t JavaThread::_stack_size_at_create = 0; #ifdef ASSERT bool Threads::_vm_complete = false; @@ -3217,7 +3218,6 @@ void Threads::threads_do(ThreadClosure* tc) { // If CompilerThreads ever become non-JavaThreads, add them here } - void Threads::initialize_java_lang_classes(JavaThread* main_thread, TRAPS) { TraceTime timer("Initialize java.lang classes", TraceStartupTime); @@ -4046,6 +4046,26 @@ void Threads::oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) { VMThread::vm_thread()->oops_do(f, cld_f, cf); } +void Threads::change_thread_claim_parity() { + // Set the new claim parity. + assert(_thread_claim_parity >= 0 && _thread_claim_parity <= 2, + "Not in range."); + _thread_claim_parity++; + if (_thread_claim_parity == 3) _thread_claim_parity = 1; + assert(_thread_claim_parity >= 1 && _thread_claim_parity <= 2, + "Not in range."); +} + +#ifndef PRODUCT +void Threads::assert_all_threads_claimed() { + ALL_JAVA_THREADS(p) { + const int thread_parity = p->oops_do_parity(); + assert((thread_parity == _thread_claim_parity), + err_msg("Thread " PTR_FORMAT " has incorrect parity %d != %d", p2i(p), thread_parity, _thread_claim_parity)); + } +} +#endif // PRODUCT + void Threads::possibly_parallel_oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) { // Introduce a mechanism allowing parallel threads to claim threads as // root groups. Overhead should be small enough to use all the time, @@ -4060,7 +4080,7 @@ void Threads::possibly_parallel_oops_do(OopClosure* f, CLDClosure* cld_f, CodeBl assert(!is_par || (SharedHeap::heap()->n_par_threads() == SharedHeap::heap()->workers()->active_workers()), "Mismatch"); - int cp = SharedHeap::heap()->strong_roots_parity(); + int cp = Threads::thread_claim_parity(); ALL_JAVA_THREADS(p) { if (p->claim_oops_do(is_par, cp)) { p->oops_do(f, cld_f, cf); diff --git a/hotspot/src/share/vm/runtime/thread.hpp b/hotspot/src/share/vm/runtime/thread.hpp index 9c6a7c79796..2744281f00e 100644 --- a/hotspot/src/share/vm/runtime/thread.hpp +++ b/hotspot/src/share/vm/runtime/thread.hpp @@ -551,6 +551,7 @@ protected: Monitor* owned_locks() const { return _owned_locks; } bool owns_locks() const { return owned_locks() != NULL; } bool owns_locks_but_compiled_lock() const; + int oops_do_parity() const { return _oops_do_parity; } // Deadlock detection bool allow_allocation() { return _allow_allocation_count == 0; } @@ -1855,6 +1856,7 @@ class Threads: AllStatic { static int _number_of_threads; static int _number_of_non_daemon_threads; static int _return_code; + static int _thread_claim_parity; #ifdef ASSERT static bool _vm_complete; #endif @@ -1884,9 +1886,10 @@ class Threads: AllStatic { // Does not include JNI_VERSION_1_1 static jboolean is_supported_jni_version(jint version); - // Garbage collection - static void follow_other_roots(void f(oop*)); + static int thread_claim_parity() { return _thread_claim_parity; } + static void change_thread_claim_parity(); + static void assert_all_threads_claimed() PRODUCT_RETURN; // Apply "f->do_oop" to all root oops in all threads. // This version may only be called by sequential code. static void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); From ff23a172834cca4061a4bd9a5dc1dc742cabff02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Lid=C3=A9n?= Date: Tue, 31 Mar 2015 08:27:30 +0200 Subject: [PATCH 078/362] 8076231: Remove unused is_in_partial_collection() Reviewed-by: brutisso, drwhite --- .../gc_implementation/g1/g1CollectedHeap.cpp | 19 ------------------- .../gc_implementation/g1/g1CollectedHeap.hpp | 4 ---- .../parallelScavenge/parallelScavengeHeap.cpp | 11 ----------- .../parallelScavenge/parallelScavengeHeap.hpp | 6 +----- .../share/vm/gc_interface/collectedHeap.hpp | 6 ------ .../src/share/vm/memory/genCollectedHeap.cpp | 2 +- .../src/share/vm/memory/genCollectedHeap.hpp | 2 +- 7 files changed, 3 insertions(+), 47 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index deb2e2af927..45fe0dd7cb9 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -402,25 +402,6 @@ HeapRegion* G1CollectedHeap::pop_dirty_cards_region() return hr; } -#ifdef ASSERT -// A region is added to the collection set as it is retired -// so an address p can point to a region which will be in the -// collection set but has not yet been retired. This method -// therefore is only accurate during a GC pause after all -// regions have been retired. It is used for debugging -// to check if an nmethod has references to objects that can -// be move during a partial collection. Though it can be -// inaccurate, it is sufficient for G1 because the conservative -// implementation of is_scavengable() for G1 will indicate that -// all nmethods must be scanned during a partial collection. -bool G1CollectedHeap::is_in_partial_collection(const void* p) { - if (p == NULL) { - return false; - } - return heap_region_containing(p)->in_collection_set(); -} -#endif - // Returns true if the reference points to an object that // can move in an incremental collection. bool G1CollectedHeap::is_scavengable(const void* p) { diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp index 11955f403af..d607455e216 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @@ -1379,10 +1379,6 @@ public: inline bool is_in_young(const oop obj); -#ifdef ASSERT - virtual bool is_in_partial_collection(const void* p); -#endif - virtual bool is_scavengable(const void* addr); // We don't need barriers for initializing stores to objects diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp index 39ee16a48f6..a50328680bc 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp @@ -203,17 +203,6 @@ bool ParallelScavengeHeap::is_scavengable(const void* addr) { return is_in_young((oop)addr); } -#ifdef ASSERT -// Don't implement this by using is_in_young(). This method is used -// in some cases to check that is_in_young() is correct. -bool ParallelScavengeHeap::is_in_partial_collection(const void *p) { - assert(is_in_reserved(p) || p == NULL, - "Does not work if address is non-null and outside of the heap"); - // The order of the generations is old (low addr), young (high addr) - return p >= old_gen()->reserved().end(); -} -#endif - // There are two levels of allocation policy here. // // When an allocation request fails, the requesting thread must invoke a VM diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp index 722ed9eeafd..82b950af8e3 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -141,10 +141,6 @@ class ParallelScavengeHeap : public CollectedHeap { bool is_in_reserved(const void* p) const; -#ifdef ASSERT - virtual bool is_in_partial_collection(const void *p); -#endif - bool is_in_young(oop p); // reserved part bool is_in_old(oop p); // reserved part diff --git a/hotspot/src/share/vm/gc_interface/collectedHeap.hpp b/hotspot/src/share/vm/gc_interface/collectedHeap.hpp index dba48ae4f92..5c6da39095c 100644 --- a/hotspot/src/share/vm/gc_interface/collectedHeap.hpp +++ b/hotspot/src/share/vm/gc_interface/collectedHeap.hpp @@ -291,12 +291,6 @@ class CollectedHeap : public CHeapObj { return p == NULL || is_in_closed_subset(p); } -#ifdef ASSERT - // Returns true if "p" is in the part of the - // heap being collected. - virtual bool is_in_partial_collection(const void *p) = 0; -#endif - // An object is scavengable if its location may move during a scavenge. // (A scavenge is a GC which is not a full GC.) virtual bool is_scavengable(const void *p) = 0; diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.cpp b/hotspot/src/share/vm/memory/genCollectedHeap.cpp index 3ca321cf026..f879b801203 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp @@ -572,7 +572,7 @@ void GenCollectedHeap::set_n_termination(uint t) { class AssertNonScavengableClosure: public OopClosure { public: virtual void do_oop(oop* p) { - assert(!Universe::heap()->is_in_partial_collection(*p), + assert(!GenCollectedHeap::heap()->is_in_partial_collection(*p), "Referent should not be scavengable."); } virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } }; diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.hpp b/hotspot/src/share/vm/memory/genCollectedHeap.hpp index bcc20bcd2aa..77336a4c9bb 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp @@ -215,7 +215,7 @@ public: bool is_in_young(oop p); #ifdef ASSERT - virtual bool is_in_partial_collection(const void* p); + bool is_in_partial_collection(const void* p); #endif virtual bool is_scavengable(const void* addr) { From a5e42354fed69f1fd96a7f96ad11c16fb45bb8a7 Mon Sep 17 00:00:00 2001 From: Bengt Rutisson Date: Tue, 31 Mar 2015 11:27:20 +0200 Subject: [PATCH 079/362] 8076237: Remove unused _collector_policy field in SharedHeap Reviewed-by: jwilhelm, drwhite, stefank --- .../src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp | 2 +- hotspot/src/share/vm/memory/genCollectedHeap.cpp | 2 +- hotspot/src/share/vm/memory/sharedHeap.cpp | 3 +-- hotspot/src/share/vm/memory/sharedHeap.hpp | 7 ++----- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index 45fe0dd7cb9..6c17645fecc 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -1728,7 +1728,7 @@ void G1CollectedHeap::shrink(size_t shrink_bytes) { G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* policy_) : - SharedHeap(policy_), + SharedHeap(), _g1_policy(policy_), _dirty_card_queue_set(false), _into_cset_dirty_card_queue_set(false), diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.cpp b/hotspot/src/share/vm/memory/genCollectedHeap.cpp index f879b801203..8b8114cb498 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp @@ -78,7 +78,7 @@ enum GCH_strong_roots_tasks { }; GenCollectedHeap::GenCollectedHeap(GenCollectorPolicy *policy) : - SharedHeap(policy), + SharedHeap(), _rem_set(NULL), _gen_policy(policy), _process_strong_tasks(new SubTasksDone(GCH_PS_NumElements)), diff --git a/hotspot/src/share/vm/memory/sharedHeap.cpp b/hotspot/src/share/vm/memory/sharedHeap.cpp index 3e93264d019..34424a66c33 100644 --- a/hotspot/src/share/vm/memory/sharedHeap.cpp +++ b/hotspot/src/share/vm/memory/sharedHeap.cpp @@ -37,9 +37,8 @@ SharedHeap* SharedHeap::_sh; -SharedHeap::SharedHeap(CollectorPolicy* policy_) : +SharedHeap::SharedHeap() : CollectedHeap(), - _collector_policy(policy_), _workers(NULL) { _sh = this; // ch is static, should be set only once. diff --git a/hotspot/src/share/vm/memory/sharedHeap.hpp b/hotspot/src/share/vm/memory/sharedHeap.hpp index edb9e468ceb..e65ca85fcbf 100644 --- a/hotspot/src/share/vm/memory/sharedHeap.hpp +++ b/hotspot/src/share/vm/memory/sharedHeap.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, 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 @@ -110,15 +110,12 @@ protected: // set the static pointer "_sh" to that instance. static SharedHeap* _sh; - // A gc policy, controls global gc resource issues - CollectorPolicy *_collector_policy; - // If we're doing parallel GC, use this gang of threads. FlexibleWorkGang* _workers; // Full initialization is done in a concrete subtype's "initialize" // function. - SharedHeap(CollectorPolicy* policy_); + SharedHeap(); // Returns true if the calling thread holds the heap lock, // or the calling thread is a par gc thread and the heap_lock is held From 68ad80c022cbb1bff4ebc6ad220f559cd31ff310 Mon Sep 17 00:00:00 2001 From: Bengt Rutisson Date: Tue, 31 Mar 2015 11:29:21 +0200 Subject: [PATCH 080/362] 8076241: Remove unused methods mod_card_iterate() and non_clean_card_iterate_serial() Reviewed-by: kbarrett, pliden, stefank --- .../parNew/parCardTableModRefBS.cpp | 3 +- .../src/share/vm/memory/cardTableModRefBS.cpp | 48 +------------------ .../src/share/vm/memory/cardTableModRefBS.hpp | 31 +----------- 3 files changed, 5 insertions(+), 77 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp index 6f77be956c4..9ab76383957 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp @@ -151,8 +151,7 @@ process_stride(Space* sp, // result of the dirty card iteration below. OrderAccess::storestore(); - // We do not call the non_clean_card_iterate_serial() version because - // we want to clear the cards: clear_cl here does the work of finding + // We want to clear the cards: clear_cl here does the work of finding // contiguous dirty ranges of cards to process and clear. clear_cl.do_MemRegion(chunk_mr); diff --git a/hotspot/src/share/vm/memory/cardTableModRefBS.cpp b/hotspot/src/share/vm/memory/cardTableModRefBS.cpp index d0024231c6d..ac8c7484f98 100644 --- a/hotspot/src/share/vm/memory/cardTableModRefBS.cpp +++ b/hotspot/src/share/vm/memory/cardTableModRefBS.cpp @@ -470,13 +470,9 @@ void CardTableModRefBS::non_clean_card_iterate_possibly_parallel(Space* sp, fatal("Parallel gc not supported here."); #endif // INCLUDE_ALL_GCS } else { - // We do not call the non_clean_card_iterate_serial() version below because - // we want to clear the cards (which non_clean_card_iterate_serial() does not - // do for us): clear_cl here does the work of finding contiguous dirty ranges - // of cards to process and clear. + // clear_cl finds contiguous dirty ranges of cards to process and clear. - DirtyCardToOopClosure* dcto_cl = sp->new_dcto_cl(cl, precision(), - cl->gen_boundary()); + DirtyCardToOopClosure* dcto_cl = sp->new_dcto_cl(cl, precision(), cl->gen_boundary()); ClearNoncleanCardWrapper clear_cl(dcto_cl, ct); clear_cl.do_MemRegion(mr); @@ -484,46 +480,6 @@ void CardTableModRefBS::non_clean_card_iterate_possibly_parallel(Space* sp, } } -// The iterator itself is not MT-aware, but -// MT-aware callers and closures can use this to -// accomplish dirty card iteration in parallel. The -// iterator itself does not clear the dirty cards, or -// change their values in any manner. -void CardTableModRefBS::non_clean_card_iterate_serial(MemRegion mr, - MemRegionClosure* cl) { - bool is_par = (SharedHeap::heap()->n_par_threads() > 0); - assert(!is_par || - (SharedHeap::heap()->n_par_threads() == - SharedHeap::heap()->workers()->active_workers()), "Mismatch"); - for (int i = 0; i < _cur_covered_regions; i++) { - MemRegion mri = mr.intersection(_covered[i]); - if (mri.word_size() > 0) { - jbyte* cur_entry = byte_for(mri.last()); - jbyte* limit = byte_for(mri.start()); - while (cur_entry >= limit) { - jbyte* next_entry = cur_entry - 1; - if (*cur_entry != clean_card) { - size_t non_clean_cards = 1; - // Should the next card be included in this range of dirty cards. - while (next_entry >= limit && *next_entry != clean_card) { - non_clean_cards++; - cur_entry = next_entry; - next_entry--; - } - // The memory region may not be on a card boundary. So that - // objects beyond the end of the region are not processed, make - // cur_cards precise with regard to the end of the memory region. - MemRegion cur_cards(addr_for(cur_entry), - non_clean_cards * card_size_in_words); - MemRegion dirty_region = cur_cards.intersection(mri); - cl->do_MemRegion(dirty_region); - } - cur_entry = next_entry; - } - } - } -} - void CardTableModRefBS::dirty_MemRegion(MemRegion mr) { assert((HeapWord*)align_size_down((uintptr_t)mr.start(), HeapWordSize) == mr.start(), "Unaligned start"); assert((HeapWord*)align_size_up ((uintptr_t)mr.end(), HeapWordSize) == mr.end(), "Unaligned end" ); diff --git a/hotspot/src/share/vm/memory/cardTableModRefBS.hpp b/hotspot/src/share/vm/memory/cardTableModRefBS.hpp index f7cf9e68499..97ce901ab80 100644 --- a/hotspot/src/share/vm/memory/cardTableModRefBS.hpp +++ b/hotspot/src/share/vm/memory/cardTableModRefBS.hpp @@ -37,7 +37,7 @@ // the head of "o" is dirtied, not necessarily the card containing the // modified field itself. For object arrays, however, the barrier *is* // precise; only the card containing the modified element is dirtied. -// Any MemRegionClosures used to scan dirty cards should take these +// Closures used to scan dirty cards should take these // considerations into account. class Generation; @@ -176,16 +176,7 @@ class CardTableModRefBS: public ModRefBarrierSet { // Iterate over the portion of the card-table which covers the given // region mr in the given space and apply cl to any dirty sub-regions - // of mr. Dirty cards are _not_ cleared by the iterator method itself, - // but closures may arrange to do so on their own should they so wish. - void non_clean_card_iterate_serial(MemRegion mr, MemRegionClosure* cl); - - // A variant of the above that will operate in a parallel mode if - // worker threads are available, and clear the dirty cards as it - // processes them. - // XXX ??? MemRegionClosure above vs OopsInGenClosure below XXX - // XXX some new_dcto_cl's take OopClosure's, plus as above there are - // some MemRegionClosures. Clean this up everywhere. XXX + // of mr. Clears the dirty cards as they are processed. void non_clean_card_iterate_possibly_parallel(Space* sp, MemRegion mr, OopsInGenClosure* cl, CardTableRS* ct); @@ -379,24 +370,6 @@ public: // *** Card-table-RemSet-specific things. - // Invoke "cl.do_MemRegion" on a set of MemRegions that collectively - // includes all the modified cards (expressing each card as a - // MemRegion). Thus, several modified cards may be lumped into one - // region. The regions are non-overlapping, and are visited in - // *decreasing* address order. (This order aids with imprecise card - // marking, where a dirty card may cause scanning, and summarization - // marking, of objects that extend onto subsequent cards.) - void mod_card_iterate(MemRegionClosure* cl) { - non_clean_card_iterate_serial(_whole_heap, cl); - } - - // Like the "mod_cards_iterate" above, except only invokes the closure - // for cards within the MemRegion "mr" (which is required to be - // card-aligned and sized.) - void mod_card_iterate(MemRegion mr, MemRegionClosure* cl) { - non_clean_card_iterate_serial(mr, cl); - } - static uintx ct_max_alignment_constraint(); // Apply closure "cl" to the dirty cards containing some part of From 5449ba9220caf96336c09764f394c9394a4851b4 Mon Sep 17 00:00:00 2001 From: David Lindholm Date: Tue, 31 Mar 2015 11:34:35 +0200 Subject: [PATCH 081/362] 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types Reviewed-by: pliden, stefank --- hotspot/src/share/vm/memory/metaspace.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index d60679d43fb..280667d16f4 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -344,7 +344,7 @@ class VirtualSpaceNode : public CHeapObj { void inc_container_count(); void dec_container_count(); #ifdef ASSERT - uint container_count_slow(); + uintx container_count_slow(); void verify_container_count(); #endif @@ -461,8 +461,8 @@ void VirtualSpaceNode::purge(ChunkManager* chunk_manager) { } #ifdef ASSERT -uint VirtualSpaceNode::container_count_slow() { - uint count = 0; +uintx VirtualSpaceNode::container_count_slow() { + uintx count = 0; Metachunk* chunk = first_chunk(); Metachunk* invalid_chunk = (Metachunk*) top(); while (chunk < invalid_chunk ) { @@ -796,10 +796,7 @@ Mutex* const SpaceManager::_expand_lock = void VirtualSpaceNode::inc_container_count() { assert_lock_strong(SpaceManager::expand_lock()); _container_count++; - assert(_container_count == container_count_slow(), - err_msg("Inconsistency in container_count _container_count " SIZE_FORMAT - " container_count_slow() %u", - _container_count, container_count_slow())); + DEBUG_ONLY(verify_container_count();) } void VirtualSpaceNode::dec_container_count() { @@ -810,8 +807,8 @@ void VirtualSpaceNode::dec_container_count() { #ifdef ASSERT void VirtualSpaceNode::verify_container_count() { assert(_container_count == container_count_slow(), - err_msg("Inconsistency in container_count _container_count " SIZE_FORMAT - " container_count_slow() %u", _container_count, container_count_slow())); + err_msg("Inconsistency in container_count _container_count " UINTX_FORMAT + " container_count_slow() " UINTX_FORMAT, _container_count, container_count_slow())); } #endif From be607cf8cfdd826321b1518933a6f4db100db536 Mon Sep 17 00:00:00 2001 From: Kim Barrett Date: Mon, 30 Mar 2015 10:24:00 -0400 Subject: [PATCH 082/362] 8075401: Remove DiscoveredListIterator::update_discovered() Remove unnecessary function Reviewed-by: brutisso, jwilhelm, ecaspole --- .../src/share/vm/memory/referenceProcessor.cpp | 3 --- .../src/share/vm/memory/referenceProcessor.hpp | 16 +--------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/hotspot/src/share/vm/memory/referenceProcessor.cpp b/hotspot/src/share/vm/memory/referenceProcessor.cpp index ad668d667ec..8943a5e675f 100644 --- a/hotspot/src/share/vm/memory/referenceProcessor.cpp +++ b/hotspot/src/share/vm/memory/referenceProcessor.cpp @@ -676,7 +676,6 @@ ReferenceProcessor::process_phase3(DiscoveredList& refs_list, ResourceMark rm; DiscoveredListIterator iter(refs_list, keep_alive, is_alive); while (iter.has_next()) { - iter.update_discovered(); iter.load_ptrs(DEBUG_ONLY(false /* allow_null_referent */)); if (clear_referent) { // NULL out referent pointer @@ -693,8 +692,6 @@ ReferenceProcessor::process_phase3(DiscoveredList& refs_list, assert(iter.obj()->is_oop(UseConcMarkSweepGC), "Adding a bad reference"); iter.next(); } - // Remember to update the next pointer of the last ref. - iter.update_discovered(); // Close the reachable set complete_gc->do_void(); } diff --git a/hotspot/src/share/vm/memory/referenceProcessor.hpp b/hotspot/src/share/vm/memory/referenceProcessor.hpp index 0600b270aa1..6dd50e5a936 100644 --- a/hotspot/src/share/vm/memory/referenceProcessor.hpp +++ b/hotspot/src/share/vm/memory/referenceProcessor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -173,20 +173,6 @@ public: } } - // Update the discovered field. - inline void update_discovered() { - // First _prev_next ref actually points into DiscoveredList (gross). - if (UseCompressedOops) { - if (!oopDesc::is_null(*(narrowOop*)_prev_next)) { - _keep_alive->do_oop((narrowOop*)_prev_next); - } - } else { - if (!oopDesc::is_null(*(oop*)_prev_next)) { - _keep_alive->do_oop((oop*)_prev_next); - } - } - } - // NULL out referent pointer. void clear_referent(); From cee2c148bcaf25847c6cafe286223ffb7a81a871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Lid=C3=A9n?= Date: Wed, 1 Apr 2015 10:49:08 +0200 Subject: [PATCH 083/362] 8076294: Cleanup of CollectedHeap::kind() Reviewed-by: stefank, ecaspole --- hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp | 2 +- .../parallelScavenge/parallelScavengeHeap.hpp | 2 +- hotspot/src/share/vm/gc_interface/collectedHeap.hpp | 4 +--- hotspot/src/share/vm/memory/genCollectedHeap.hpp | 2 +- hotspot/src/share/vm/runtime/vmStructs.cpp | 4 ++-- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp index d607455e216..1a3be8c2a9a 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @@ -1008,7 +1008,7 @@ public: // Set _n_par_threads according to a policy TBD. void set_par_threads(); - virtual CollectedHeap::Name kind() const { + virtual Name kind() const { return CollectedHeap::G1CollectedHeap; } diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp index 82b950af8e3..867bdbf55ee 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp @@ -83,7 +83,7 @@ class ParallelScavengeHeap : public CollectedHeap { MarkSweep }; - ParallelScavengeHeap::Name kind() const { + virtual Name kind() const { return CollectedHeap::ParallelScavengeHeap; } diff --git a/hotspot/src/share/vm/gc_interface/collectedHeap.hpp b/hotspot/src/share/vm/gc_interface/collectedHeap.hpp index 5c6da39095c..5dec0eca8ab 100644 --- a/hotspot/src/share/vm/gc_interface/collectedHeap.hpp +++ b/hotspot/src/share/vm/gc_interface/collectedHeap.hpp @@ -185,8 +185,6 @@ class CollectedHeap : public CHeapObj { public: enum Name { - Abstract, - SharedHeap, GenCollectedHeap, ParallelScavengeHeap, G1CollectedHeap @@ -196,7 +194,7 @@ class CollectedHeap : public CHeapObj { return _filler_array_max_size; } - virtual CollectedHeap::Name kind() const { return CollectedHeap::Abstract; } + virtual Name kind() const = 0; /** * Returns JNI error code JNI_ENOMEM if memory could not be allocated, diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.hpp b/hotspot/src/share/vm/memory/genCollectedHeap.hpp index 77336a4c9bb..a91432748a0 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp @@ -139,7 +139,7 @@ public: // Initialize ("weak") refs processing support virtual void ref_processing_init(); - virtual CollectedHeap::Name kind() const { + virtual Name kind() const { return CollectedHeap::GenCollectedHeap; } diff --git a/hotspot/src/share/vm/runtime/vmStructs.cpp b/hotspot/src/share/vm/runtime/vmStructs.cpp index 8524679cbc3..f7561b6f72f 100644 --- a/hotspot/src/share/vm/runtime/vmStructs.cpp +++ b/hotspot/src/share/vm/runtime/vmStructs.cpp @@ -2253,9 +2253,9 @@ typedef CompactHashtable SymbolCompactHashTable; \ declare_constant(CardTableRS::youngergen_card) \ \ - declare_constant(CollectedHeap::Abstract) \ - declare_constant(CollectedHeap::SharedHeap) \ declare_constant(CollectedHeap::GenCollectedHeap) \ + declare_constant(CollectedHeap::ParallelScavengeHeap) \ + declare_constant(CollectedHeap::G1CollectedHeap) \ \ declare_constant(GenCollectedHeap::max_gens) \ \ From 473bf6175fe478118dcb150f848e000690cb6d7f Mon Sep 17 00:00:00 2001 From: Jon Masamitsu Date: Tue, 17 Mar 2015 11:19:05 -0700 Subject: [PATCH 084/362] 8017462: G1: guarantee fails with UseDynamicNumberOfGCThreads Reviewed-by: tschatzl, brutisso --- .../gc_implementation/g1/g1CollectedHeap.cpp | 16 +++-- .../gc_implementation/g1/g1GCPhaseTimes.cpp | 56 ++++++++------- .../TestDynamicNumberOfGCThreads.java | 69 +++++++++++++++++++ 3 files changed, 108 insertions(+), 33 deletions(-) create mode 100644 hotspot/test/gc/ergonomics/TestDynamicNumberOfGCThreads.java diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index 6c17645fecc..8733e4714a9 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -3712,7 +3712,14 @@ G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) { TraceCPUTime tcpu(G1Log::finer(), true, gclog_or_tty); - uint active_workers = workers()->active_workers(); + uint active_workers = AdaptiveSizePolicy::calc_active_workers(workers()->total_workers(), + workers()->active_workers(), + Threads::number_of_non_daemon_threads()); + assert(UseDynamicNumberOfGCThreads || + active_workers == workers()->total_workers(), + "If not dynamic should be using all the workers"); + workers()->set_active_workers(active_workers); + double pause_start_sec = os::elapsedTime(); g1_policy()->phase_times()->note_gc_start(active_workers, mark_in_progress()); log_gc_header(); @@ -5410,15 +5417,10 @@ void G1CollectedHeap::evacuate_collection_set(EvacuationInfo& evacuation_info) { hot_card_cache->reset_hot_cache_claimed_index(); hot_card_cache->set_use_cache(false); - uint n_workers; - n_workers = - AdaptiveSizePolicy::calc_active_workers(workers()->total_workers(), - workers()->active_workers(), - Threads::number_of_non_daemon_threads()); + const uint n_workers = workers()->active_workers(); assert(UseDynamicNumberOfGCThreads || n_workers == workers()->total_workers(), "If not dynamic should be using all the workers"); - workers()->set_active_workers(n_workers); set_par_threads(n_workers); diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp index 24379ffd5b8..3b7a12b320b 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp @@ -154,28 +154,28 @@ class WorkerDataArray : public CHeapObj { _has_new_data = true; } - double average(){ - calculate_totals(); + double average(uint active_threads){ + calculate_totals(active_threads); return _average; } - T sum() { - calculate_totals(); + T sum(uint active_threads) { + calculate_totals(active_threads); return _sum; } - T minimum() { - calculate_totals(); + T minimum(uint active_threads) { + calculate_totals(active_threads); return _min; } - T maximum() { - calculate_totals(); + T maximum(uint active_threads) { + calculate_totals(active_threads); return _max; } void reset() PRODUCT_RETURN; - void verify() PRODUCT_RETURN; + void verify(uint active_threads) PRODUCT_RETURN; void set_enabled(bool enabled) { _enabled = enabled; } @@ -183,7 +183,7 @@ class WorkerDataArray : public CHeapObj { private: - void calculate_totals(){ + void calculate_totals(uint active_threads){ if (!_has_new_data) { return; } @@ -191,13 +191,14 @@ class WorkerDataArray : public CHeapObj { _sum = (T)0; _min = _data[0]; _max = _min; - for (uint i = 0; i < _length; ++i) { + assert(active_threads <= _length, "Wrong number of active threads"); + for (uint i = 0; i < active_threads; ++i) { T val = _data[i]; _sum += val; _min = MIN2(_min, val); _max = MAX2(_max, val); } - _average = (double)_sum / (double)_length; + _average = (double)_sum / (double)active_threads; _has_new_data = false; } }; @@ -226,17 +227,18 @@ void WorkerDataArray::reset() { } template -void WorkerDataArray::verify() { +void WorkerDataArray::verify(uint active_threads) { if (!_enabled) { return; } - for (uint i = 0; i < _length; i++) { + assert(active_threads <= _length, "Wrong number of active threads"); + for (uint i = 0; i < active_threads; i++) { assert(_data[i] != WorkerDataArray::uninitialized(), err_msg("Invalid data for worker %u in '%s'", i, _title)); } if (_thread_work_items != NULL) { - _thread_work_items->verify(); + _thread_work_items->verify(active_threads); } } @@ -321,7 +323,7 @@ void G1GCPhaseTimes::note_gc_end() { } for (int i = 0; i < GCParPhasesSentinel; i++) { - _gc_par_phases[i]->verify(); + _gc_par_phases[i]->verify(_active_gc_threads); } } @@ -378,7 +380,7 @@ void G1GCPhaseTimes::record_thread_work_item(GCParPhases phase, uint worker_i, s // return the average time for a phase in milliseconds double G1GCPhaseTimes::average_time_ms(GCParPhases phase) { - return _gc_par_phases[phase]->average() * 1000.0; + return _gc_par_phases[phase]->average(_active_gc_threads) * 1000.0; } double G1GCPhaseTimes::get_time_ms(GCParPhases phase, uint worker_i) { @@ -386,15 +388,15 @@ double G1GCPhaseTimes::get_time_ms(GCParPhases phase, uint worker_i) { } double G1GCPhaseTimes::sum_time_ms(GCParPhases phase) { - return _gc_par_phases[phase]->sum() * 1000.0; + return _gc_par_phases[phase]->sum(_active_gc_threads) * 1000.0; } double G1GCPhaseTimes::min_time_ms(GCParPhases phase) { - return _gc_par_phases[phase]->minimum() * 1000.0; + return _gc_par_phases[phase]->minimum(_active_gc_threads) * 1000.0; } double G1GCPhaseTimes::max_time_ms(GCParPhases phase) { - return _gc_par_phases[phase]->maximum() * 1000.0; + return _gc_par_phases[phase]->maximum(_active_gc_threads) * 1000.0; } size_t G1GCPhaseTimes::get_thread_work_item(GCParPhases phase, uint worker_i) { @@ -404,22 +406,22 @@ size_t G1GCPhaseTimes::get_thread_work_item(GCParPhases phase, uint worker_i) { size_t G1GCPhaseTimes::sum_thread_work_items(GCParPhases phase) { assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); - return _gc_par_phases[phase]->thread_work_items()->sum(); + return _gc_par_phases[phase]->thread_work_items()->sum(_active_gc_threads); } double G1GCPhaseTimes::average_thread_work_items(GCParPhases phase) { assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); - return _gc_par_phases[phase]->thread_work_items()->average(); + return _gc_par_phases[phase]->thread_work_items()->average(_active_gc_threads); } size_t G1GCPhaseTimes::min_thread_work_items(GCParPhases phase) { assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); - return _gc_par_phases[phase]->thread_work_items()->minimum(); + return _gc_par_phases[phase]->thread_work_items()->minimum(_active_gc_threads); } size_t G1GCPhaseTimes::max_thread_work_items(GCParPhases phase) { assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); - return _gc_par_phases[phase]->thread_work_items()->maximum(); + return _gc_par_phases[phase]->thread_work_items()->maximum(_active_gc_threads); } class G1GCParPhasePrinter : public StackObj { @@ -455,14 +457,16 @@ class G1GCParPhasePrinter : public StackObj { } void print_time_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray* phase) { - for (uint i = 0; i < phase->_length; ++i) { + uint active_length = _phase_times->_active_gc_threads; + for (uint i = 0; i < active_length; ++i) { buf.append(" %.1lf", _phase_times->get_time_ms(phase_id, i)); } buf.print_cr(); } void print_count_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray* thread_work_items) { - for (uint i = 0; i < thread_work_items->_length; ++i) { + uint active_length = _phase_times->_active_gc_threads; + for (uint i = 0; i < active_length; ++i) { buf.append(" " SIZE_FORMAT, _phase_times->get_thread_work_item(phase_id, i)); } buf.print_cr(); diff --git a/hotspot/test/gc/ergonomics/TestDynamicNumberOfGCThreads.java b/hotspot/test/gc/ergonomics/TestDynamicNumberOfGCThreads.java new file mode 100644 index 00000000000..f6455761ada --- /dev/null +++ b/hotspot/test/gc/ergonomics/TestDynamicNumberOfGCThreads.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test TestDynamicNumberOfGCThreads + * @bug 8017462 + * @summary Ensure that UseDynamicNumberOfGCThreads runs + * @requires vm.gc=="null" + * @key gc + * @library /testlibrary + */ + +import com.oracle.java.testlibrary.ProcessTools; +import com.oracle.java.testlibrary.OutputAnalyzer; + +public class TestDynamicNumberOfGCThreads { + public static void main(String[] args) throws Exception { + + testDynamicNumberOfGCThreads("UseConcMarkSweepGC"); + + testDynamicNumberOfGCThreads("UseG1GC"); + + testDynamicNumberOfGCThreads("UseParallelGC"); + } + + private static void verifyDynamicNumberOfGCThreads(OutputAnalyzer output) { + output.shouldContain("new_active_workers"); + output.shouldHaveExitValue(0); + } + + private static void testDynamicNumberOfGCThreads(String gcFlag) throws Exception { + // UseDynamicNumberOfGCThreads and TraceDynamicGCThreads enabled + ProcessBuilder pb_enabled = + ProcessTools.createJavaProcessBuilder("-XX:+" + gcFlag, "-Xmx10M", "-XX:+PrintGCDetails", "-XX:+UseDynamicNumberOfGCThreads", "-XX:+TraceDynamicGCThreads", GCTest.class.getName()); + verifyDynamicNumberOfGCThreads(new OutputAnalyzer(pb_enabled.start())); + } + + static class GCTest { + private static byte[] garbage; + public static void main(String [] args) { + System.out.println("Creating garbage"); + // create 128MB of garbage. This should result in at least one GC + for (int i = 0; i < 1024; i++) { + garbage = new byte[128 * 1024]; + } + System.out.println("Done"); + } + } +} From 80b33776b19c468e50c97b608bed04c92d26b9f2 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Tue, 17 Mar 2015 15:18:11 -0700 Subject: [PATCH 085/362] 8075277: JDK is still building X11 related Java files on OSX Reviewed-by: ihse, erikj, serb --- .../macosx/classes/sun/font/CFontManager.java | 10 -- .../macosx/classes/sun/font/NativeFont.java | 107 ++++++++++++++++++ .../macosx/classes/sun/font/NativeStrike.java | 86 ++++++++++++++ 3 files changed, 193 insertions(+), 10 deletions(-) create mode 100644 jdk/src/java.desktop/macosx/classes/sun/font/NativeFont.java create mode 100644 jdk/src/java.desktop/macosx/classes/sun/font/NativeStrike.java diff --git a/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java b/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java index e37e9e449ea..272999ee6b9 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java +++ b/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java @@ -44,7 +44,6 @@ import sun.awt.util.ThreadGroupUtils; import sun.lwawt.macosx.*; public final class CFontManager extends SunFontManager { - private FontConfigManager fcManager = null; private static Hashtable genericFonts = new Hashtable(); @Override @@ -231,15 +230,6 @@ public final class CFontManager extends SunFontManager { return font2D; } - /* - public synchronized FontConfigManager getFontConfigManager() { - if (fcManager == null) { - fcManager = new FontConfigManager(); - } - return fcManager; - } - */ - protected void registerFontsInDir(String dirName, boolean useJavaRasterizer, int fontRank, boolean defer, boolean resolveSymLinks) { loadNativeDirFonts(dirName); super.registerFontsInDir(dirName, useJavaRasterizer, fontRank, defer, resolveSymLinks); diff --git a/jdk/src/java.desktop/macosx/classes/sun/font/NativeFont.java b/jdk/src/java.desktop/macosx/classes/sun/font/NativeFont.java new file mode 100644 index 00000000000..0eb6db7e6e0 --- /dev/null +++ b/jdk/src/java.desktop/macosx/classes/sun/font/NativeFont.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015, 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 sun.font; + +import java.awt.FontFormatException; +import java.awt.font.FontRenderContext; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +/* + * This class should never be invoked on the windows implementation + * So the constructor throws a FontFormatException, which is caught + * and the font is ignored. + */ + +public class NativeFont extends PhysicalFont { + + /** + * Verifies native font is accessible. + * @throws FontFormatException - if the font can't be located. + */ + public NativeFont(String platName, boolean isBitmapDelegate) + throws FontFormatException { + + throw new FontFormatException("NativeFont not used on OS X"); + } + + static boolean hasExternalBitmaps(String platName) { + return false; + } + + public CharToGlyphMapper getMapper() { + return null; + } + + PhysicalFont getDelegateFont() { + return null; + } + + FontStrike createStrike(FontStrikeDesc desc) { + return null; + } + + public Rectangle2D getMaxCharBounds(FontRenderContext frc) { + return null; + } + + StrikeMetrics getFontMetrics(long pScalerContext) { + return null; + } + + public GeneralPath getGlyphOutline(long pScalerContext, + int glyphCode, + float x, float y) { + return null; + } + + public GeneralPath getGlyphVectorOutline(long pScalerContext, + int[] glyphs, int numGlyphs, + float x, float y) { + return null; + } + + + long getGlyphImage(long pScalerContext, int glyphCode) { + return 0L; + } + + + void getGlyphMetrics(long pScalerContext, int glyphCode, + Point2D.Float metrics) { + } + + + float getGlyphAdvance(long pScalerContext, int glyphCode) { + return 0f; + } + + Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext, + int glyphCode) { + return new Rectangle2D.Float(0f, 0f, 0f, 0f); + } +} diff --git a/jdk/src/java.desktop/macosx/classes/sun/font/NativeStrike.java b/jdk/src/java.desktop/macosx/classes/sun/font/NativeStrike.java new file mode 100644 index 00000000000..de5c3aca312 --- /dev/null +++ b/jdk/src/java.desktop/macosx/classes/sun/font/NativeStrike.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015, 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 sun.font; + +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; + +public class NativeStrike extends PhysicalStrike { + + NativeFont nativeFont; + + NativeStrike(NativeFont nativeFont, FontStrikeDesc desc) { + super(nativeFont, desc); + + throw new RuntimeException("NativeFont not used on OS X"); + } + + NativeStrike(NativeFont nativeFont, FontStrikeDesc desc, + boolean nocache) { + super(nativeFont, desc); + + throw new RuntimeException("NativeFont not used on Windows"); + } + + + void getGlyphImagePtrs(int[] glyphCodes, long[] images,int len) { + } + + long getGlyphImagePtr(int glyphCode) { + return 0L; + } + + long getGlyphImagePtrNoCache(int glyphCode) { + return 0L; + } + + void getGlyphImageBounds(int glyphcode, + Point2D.Float pt, + Rectangle result) { + } + + Point2D.Float getGlyphMetrics(int glyphCode) { + return null; + } + + float getGlyphAdvance(int glyphCode) { + return 0f; + } + + Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) { + return null; + } + GeneralPath getGlyphOutline(int glyphCode, float x, float y) { + return null; + } + + GeneralPath getGlyphVectorOutline(int[] glyphs, float x, float y) { + return null; + } + +} From 7b4b132f802ba561d436071062b3e5de09262b07 Mon Sep 17 00:00:00 2001 From: Yuri Nesterenko Date: Wed, 18 Mar 2015 10:30:22 +0300 Subject: [PATCH 086/362] 8074807: Fix some tests unnecessary using internal API Reviewed-by: azvegint, alexsch --- .../ModalExcludedWindowClickTest.html | 43 + .../ModalExcludedWindowClickTest.java | 291 +++++++ .../NonFocusableBlockedOwnerTest.html | 43 + .../NonFocusableBlockedOwnerTest.java | 288 +++++++ .../WindowUpdateFocusabilityTest.html | 43 + .../WindowUpdateFocusabilityTest.java | 325 +++++++ .../TypeAhead/TestDialogTypeAhead.java | 5 +- .../awt/Window/AlwaysOnTop/AutoTestOnTop.java | 795 ++++++++++++++++++ .../MovedResizedTardyEventTest.html | 43 + .../MovedResizedTardyEventTest.java | 97 +++ .../AltCharAcceleratorTest.java | 11 +- .../keyboard/EqualKeyCode/EqualKeyCode.java | 16 +- .../ToolTipManager/7123767/bug7123767.java | 18 +- 13 files changed, 1989 insertions(+), 29 deletions(-) create mode 100644 jdk/test/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.html create mode 100644 jdk/test/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.java create mode 100644 jdk/test/java/awt/Focus/NonFocusableBlockedOwnerTest/NonFocusableBlockedOwnerTest.html create mode 100644 jdk/test/java/awt/Focus/NonFocusableBlockedOwnerTest/NonFocusableBlockedOwnerTest.java create mode 100644 jdk/test/java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.html create mode 100644 jdk/test/java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.java create mode 100644 jdk/test/java/awt/Window/AlwaysOnTop/AutoTestOnTop.java create mode 100644 jdk/test/java/awt/event/ComponentEvent/MovedResizedTardyEventTest/MovedResizedTardyEventTest.html create mode 100644 jdk/test/java/awt/event/ComponentEvent/MovedResizedTardyEventTest/MovedResizedTardyEventTest.java diff --git a/jdk/test/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.html b/jdk/test/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.html new file mode 100644 index 00000000000..77502895ba6 --- /dev/null +++ b/jdk/test/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.html @@ -0,0 +1,43 @@ + + + + + +ModalExcludedWindowClickTest + + + +

ModalExcludedWindowClickTest
Bug ID: 6272324

+ +

See the dialog box (usually in upper left corner) for instructions

+ + + + diff --git a/jdk/test/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.java b/jdk/test/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.java new file mode 100644 index 00000000000..70f6d1effd2 --- /dev/null +++ b/jdk/test/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.java @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2005, 2015, 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. + * + * 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. + */ + +/* + test + @bug 6271849 + @summary Tests that component in modal excluded Window which parent is blocked responses to mouse clicks. + @author anton.tarasov@sun.com: area=awt.focus + @run applet ModalExcludedWindowClickTest.html +*/ + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.*; +import java.lang.reflect.*; + +public class ModalExcludedWindowClickTest extends Applet { + Robot robot; + Frame frame = new Frame("Frame"); + Window w = new Window(frame); + Dialog d = new Dialog ((Dialog)null, "NullParentDialog", true); + Button button = new Button("Button"); + boolean actionPerformed = false; + + public static void main (String args[]) { + ModalExcludedWindowClickTest app = new ModalExcludedWindowClickTest(); + app.init(); + app.start(); + } + + public void init() { + try { + robot = new Robot(); + } catch (AWTException e) { + throw new RuntimeException("Error: unable to create robot", e); + } + // Create instructions for the user here, as well as set up + // the environment -- set the layout manager, add buttons, + // etc. + this.setLayout (new BorderLayout ()); + Sysout.createDialogWithInstructions(new String[] + {"This is an AUTOMATIC test", "simply wait until it is done"}); + } + + public void start() { + + if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) { + Sysout.println("No testing on MToolkit."); + return; + } + + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + actionPerformed = true; + Sysout.println(e.paramString()); + } + }); + + EventQueue.invokeLater(new Runnable() { + public void run() { + frame.setSize(200, 200); + frame.setVisible(true); + + w.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); + w.add(button); + w.setSize(200, 200); + w.setLocation(230, 230); + w.setVisible(true); + + d.setSize(200, 200); + d.setLocation(0, 230); + d.setVisible(true); + + } + }); + + waitTillShown(d); + + test(); + } + + void test() { + clickOn(button); + waitForIdle(); + if (!actionPerformed) { + throw new RuntimeException("Test failed!"); + } + Sysout.println("Test passed."); + } + + void clickOn(Component c) { + Point p = c.getLocationOnScreen(); + Dimension d = c.getSize(); + + Sysout.println("Clicking " + c); + + if (c instanceof Frame) { + robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + ((Frame)c).getInsets().top/2); + } else { + robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2)); + } + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + waitForIdle(); + } + void waitTillShown(Component c) { + while (true) { + try { + Thread.sleep(100); + c.getLocationOnScreen(); + break; + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (IllegalComponentStateException e) {} + } + } + void waitForIdle() { + try { + robot.waitForIdle(); + EventQueue.invokeAndWait( new Runnable() { + public void run() {} // Dummy implementation + }); + } catch(InterruptedException ie) { + Sysout.println("waitForIdle, non-fatal exception caught:"); + ie.printStackTrace(); + } catch(InvocationTargetException ite) { + Sysout.println("waitForIdle, non-fatal exception caught:"); + ite.printStackTrace(); + } + + // wait longer... + robot.delay(200); + } +} + +/**************************************************** + Standard Test Machinery + DO NOT modify anything below -- it's a standard + chunk of code whose purpose is to make user + interaction uniform, and thereby make it simpler + to read and understand someone else's test. + ****************************************************/ + +/** + This is part of the standard test machinery. + It creates a dialog (with the instructions), and is the interface + for sending text messages to the user. + To print the instructions, send an array of strings to Sysout.createDialog + WithInstructions method. Put one line of instructions per array entry. + To display a message for the tester to see, simply call Sysout.println + with the string to be displayed. + This mimics System.out.println but works within the test harness as well + as standalone. + */ + +class Sysout +{ + static TestDialog dialog; + + public static void createDialogWithInstructions( String[] instructions ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + dialog.printInstructions( instructions ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + public static void createDialog( ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + String[] defInstr = { "Instructions will appear here. ", "" } ; + dialog.printInstructions( defInstr ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + + public static void printInstructions( String[] instructions ) + { + dialog.printInstructions( instructions ); + } + + + public static void println( String messageIn ) + { + dialog.displayMessage( messageIn ); + } + +}// Sysout class + +/** + This is part of the standard test machinery. It provides a place for the + test instructions to be displayed, and a place for interactive messages + to the user to be displayed. + To have the test instructions displayed, see Sysout. + To have a message to the user be displayed, see Sysout. + Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog +{ + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog( Frame frame, String name ) + { + super( frame, name ); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); + add( "North", instructionsText ); + + messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); + add("Center", messageText); + + pack(); + + setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions( String[] instructions ) + { + //Clear out any current instructions + instructionsText.setText( "" ); + + //Go down array of instruction strings + + String printStr, remainingStr; + for( int i=0; i < instructions.length; i++ ) + { + //chop up each into pieces maxSringLength long + remainingStr = instructions[ i ]; + while( remainingStr.length() > 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + System.out.println(messageIn); + } + +}// TestDialog class diff --git a/jdk/test/java/awt/Focus/NonFocusableBlockedOwnerTest/NonFocusableBlockedOwnerTest.html b/jdk/test/java/awt/Focus/NonFocusableBlockedOwnerTest/NonFocusableBlockedOwnerTest.html new file mode 100644 index 00000000000..a844c798cb3 --- /dev/null +++ b/jdk/test/java/awt/Focus/NonFocusableBlockedOwnerTest/NonFocusableBlockedOwnerTest.html @@ -0,0 +1,43 @@ + + + + + +NonFocusableBlockedOwnerTest + + + +

NonFocusableBlockedOwnerTest
Bug ID: 6272324

+ +

See the dialog box (usually in upper left corner) for instructions

+ + + + diff --git a/jdk/test/java/awt/Focus/NonFocusableBlockedOwnerTest/NonFocusableBlockedOwnerTest.java b/jdk/test/java/awt/Focus/NonFocusableBlockedOwnerTest/NonFocusableBlockedOwnerTest.java new file mode 100644 index 00000000000..b98fe3b522d --- /dev/null +++ b/jdk/test/java/awt/Focus/NonFocusableBlockedOwnerTest/NonFocusableBlockedOwnerTest.java @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2005, 2015, 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. + * + * 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. + */ + +/* + test + @bug 6272324 + @summary Modal excluded Window which decorated parent is blocked should be non-focusable. + @author anton.tarasov@sun.com: area=awt.focus + @run applet NonFocusableBlockedOwnerTest.html +*/ + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.*; +import java.lang.reflect.*; + +public class NonFocusableBlockedOwnerTest extends Applet { + Robot robot; + Frame frame = new Frame("Modal Blocked Frame"); + Dialog dialog = new Dialog(frame, "Modal Dialog", true); + Window excluded = new Window(frame); + Button button = new Button("button"); + + public static void main(String[] args) { + NonFocusableBlockedOwnerTest app = new NonFocusableBlockedOwnerTest(); + app.init(); + app.start(); + } + + public void init() { + try { + robot = new Robot(); + } catch (AWTException e) { + throw new RuntimeException("Error: unable to create robot", e); + } + // Create instructions for the user here, as well as set up + // the environment -- set the layout manager, add buttons, + // etc. + this.setLayout (new BorderLayout ()); + Sysout.createDialogWithInstructions(new String[] + {"This is an AUTOMATIC test", "simply wait until it is done"}); + } + + public void start() { + + if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) { + Sysout.println("No testing on MToolkit."); + return; + } + + try { + EventQueue.invokeLater(new Runnable() { + public void run() { + frame.setSize(300, 200); + frame.setVisible(true); + + excluded.setSize(300, 200); + excluded.setLocation(0, 400); + excluded.setModalExclusionType(Dialog.ModalExclusionType.TOOLKIT_EXCLUDE); + excluded.setLayout(new FlowLayout()); + excluded.add(button); + excluded.setVisible(true); + + dialog.setSize(200, 100); + dialog.setLocation(0, 250); + dialog.setVisible(true); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + + waitTillShown(dialog); + clickOn(button); + if (frame == KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow()) { + throw new RuntimeException("Test failed!"); + } + if (excluded == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow()) { + throw new RuntimeException("Test failed!"); + } + if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) { + throw new RuntimeException("Test failed!"); + } + Sysout.println("Test passed."); + } + + void clickOn(Component c) { + Point p = c.getLocationOnScreen(); + Dimension d = c.getSize(); + + Sysout.println("Clicking " + c); + + if (c instanceof Frame) { + robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + ((Frame)c).getInsets().top/2); + } else { + robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2)); + } + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + waitForIdle(); + } + + void waitTillShown(Component c) { + while (true) { + try { + Thread.sleep(100); + c.getLocationOnScreen(); + break; + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (IllegalComponentStateException e) {} + } + } + void waitForIdle() { + try { + robot.waitForIdle(); + EventQueue.invokeAndWait( new Runnable() { + public void run() {} // Dummy implementation + }); + } catch(InterruptedException ie) { + Sysout.println("waitForIdle, non-fatal exception caught:"); + ie.printStackTrace(); + } catch(InvocationTargetException ite) { + Sysout.println("waitForIdle, non-fatal exception caught:"); + ite.printStackTrace(); + } + + // wait longer... + robot.delay(200); + } +} + +/**************************************************** + Standard Test Machinery + DO NOT modify anything below -- it's a standard + chunk of code whose purpose is to make user + interaction uniform, and thereby make it simpler + to read and understand someone else's test. + ****************************************************/ + +/** + This is part of the standard test machinery. + It creates a dialog (with the instructions), and is the interface + for sending text messages to the user. + To print the instructions, send an array of strings to Sysout.createDialog + WithInstructions method. Put one line of instructions per array entry. + To display a message for the tester to see, simply call Sysout.println + with the string to be displayed. + This mimics System.out.println but works within the test harness as well + as standalone. + */ + +class Sysout +{ + static TestDialog dialog; + + public static void createDialogWithInstructions( String[] instructions ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + dialog.printInstructions( instructions ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + public static void createDialog( ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + String[] defInstr = { "Instructions will appear here. ", "" } ; + dialog.printInstructions( defInstr ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + + public static void printInstructions( String[] instructions ) + { + dialog.printInstructions( instructions ); + } + + + public static void println( String messageIn ) + { + dialog.displayMessage( messageIn ); + } + +}// Sysout class + +/** + This is part of the standard test machinery. It provides a place for the + test instructions to be displayed, and a place for interactive messages + to the user to be displayed. + To have the test instructions displayed, see Sysout. + To have a message to the user be displayed, see Sysout. + Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog +{ + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog( Frame frame, String name ) + { + super( frame, name ); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); + add( "North", instructionsText ); + + messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); + add("Center", messageText); + + pack(); + + setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions( String[] instructions ) + { + //Clear out any current instructions + instructionsText.setText( "" ); + + //Go down array of instruction strings + + String printStr, remainingStr; + for( int i=0; i < instructions.length; i++ ) + { + //chop up each into pieces maxSringLength long + remainingStr = instructions[ i ]; + while( remainingStr.length() > 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + System.out.println(messageIn); + } + +}// TestDialog class diff --git a/jdk/test/java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.html b/jdk/test/java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.html new file mode 100644 index 00000000000..56b72d53944 --- /dev/null +++ b/jdk/test/java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.html @@ -0,0 +1,43 @@ + + + + + +WindowUpdateFocusabilityTest + + + +

WindowUpdateFocusabilityTest
Bug ID: 6253913

+ +

See the dialog box (usually in upper left corner) for instructions

+ + + + diff --git a/jdk/test/java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.java b/jdk/test/java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.java new file mode 100644 index 00000000000..8070e57a382 --- /dev/null +++ b/jdk/test/java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.java @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2005, 2015, 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. + * + * 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. + */ + +/* + test + @bug 6253913 + @summary Tests that a Window shown before its owner is focusable. + @author anton.tarasov@sun.com: area=awt-focus + @run applet WindowUpdateFocusabilityTest.html +*/ + +import java.awt.*; +import java.awt.event.*; +import java.applet.Applet; +import java.lang.reflect.*; + +public class WindowUpdateFocusabilityTest extends Applet { + Robot robot; + boolean focusGained = false; + final Object monitor = new Object(); + FocusListener listener = new FocusAdapter () { + public void focusGained(FocusEvent e) { + Sysout.println(e.toString()); + synchronized (monitor) { + focusGained = true; + monitor.notifyAll(); + } + } + }; + + public static void main(String[] args) { + WindowUpdateFocusabilityTest app = new WindowUpdateFocusabilityTest(); + app.init(); + app.start(); + } + + public void init() { + try { + robot = new Robot(); + } catch (AWTException e) { + throw new RuntimeException("Error: couldn't create robot"); + } + // Create instructions for the user here, as well as set up + // the environment -- set the layout manager, add buttons, + // etc. + this.setLayout (new BorderLayout ()); + Sysout.createDialogWithInstructions(new String[] + {"This is an automatic test. Simply wait until it's done."}); + } + + public void start() { + if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) { + Sysout.println("No testing on Motif."); + return; + } + + test(new Frame("Frame owner")); + Frame dialog_owner = new Frame("dialog's owner"); + test(new Dialog(dialog_owner)); + test(new Dialog(dialog_owner, Dialog.ModalityType.DOCUMENT_MODAL)); + test(new Dialog(dialog_owner, Dialog.ModalityType.APPLICATION_MODAL)); + test(new Dialog(dialog_owner, Dialog.ModalityType.TOOLKIT_MODAL)); + test(new Dialog((Window) null, Dialog.ModalityType.MODELESS)); + test(new Dialog((Window) null, Dialog.ModalityType.DOCUMENT_MODAL)); + test(new Dialog((Window) null, Dialog.ModalityType.APPLICATION_MODAL)); + test(new Dialog((Window) null, Dialog.ModalityType.TOOLKIT_MODAL)); + dialog_owner.dispose(); + } + + private void test(final Window owner) + { + Window window0 = new Window(owner); // will not be shown + Window window1 = new Window(window0); + Window window2 = new Window(window1); + Button button1 = new Button("button1"); + Button button2 = new Button("button2"); + button1.addFocusListener(listener); + button2.addFocusListener(listener); + + owner.setBounds(800, 0, 100, 100); + window1.setBounds(800, 300, 100, 100); + window2.setBounds(800, 150, 100, 100); + + window1.add(button1); + window2.add(button2); + + window2.setVisible(true); + window1.setVisible(true); + EventQueue.invokeLater(new Runnable() { + public void run() { + owner.setVisible(true); + } + }); + + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + // do nothing just wait until previous invokeLater will be executed + } + }); + } catch (InterruptedException ie) { + throw new RuntimeException(ie); + } catch (InvocationTargetException ite) { + throw new RuntimeException(ite); + } + + robot.delay(1000); + + clickOn(button1); + + if (!isFocusGained()) { + throw new RuntimeException("Test failed: window1 is not focusable!"); + } + + focusGained = false; + clickOn(button2); + + if (!isFocusGained()) { + throw new RuntimeException("Test failed: window2 is not focusable!"); + } + + Sysout.println("Test for " + owner.getName() + " passed."); + owner.dispose(); + } + + void clickOn(Component c) { + Point p = c.getLocationOnScreen(); + Dimension d = c.getSize(); + + Sysout.println("Clicking " + c); + + robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2)); + + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + waitForIdle(); + } + + void waitForIdle() { + try { + robot.waitForIdle(); + robot.delay(50); + EventQueue.invokeAndWait( new Runnable() { + public void run() {} // Dummy implementation + }); + } catch(InterruptedException ie) { + Sysout.println("waitForIdle, non-fatal exception caught:"); + ie.printStackTrace(); + } catch(InvocationTargetException ite) { + Sysout.println("waitForIdle, non-fatal exception caught:"); + ite.printStackTrace(); + } + } + + boolean isFocusGained() { + synchronized (monitor) { + if (!focusGained) { + try { + monitor.wait(3000); + } catch (InterruptedException e) { + Sysout.println("Interrupted unexpectedly!"); + throw new RuntimeException(e); + } + } + } + return focusGained; + } +} + +/**************************************************** + Standard Test Machinery + DO NOT modify anything below -- it's a standard + chunk of code whose purpose is to make user + interaction uniform, and thereby make it simpler + to read and understand someone else's test. + ****************************************************/ + +/** + This is part of the standard test machinery. + It creates a dialog (with the instructions), and is the interface + for sending text messages to the user. + To print the instructions, send an array of strings to Sysout.createDialog + WithInstructions method. Put one line of instructions per array entry. + To display a message for the tester to see, simply call Sysout.println + with the string to be displayed. + This mimics System.out.println but works within the test harness as well + as standalone. + */ + +class Sysout +{ + static TestDialog dialog; + + public static void createDialogWithInstructions( String[] instructions ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + dialog.printInstructions( instructions ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + public static void createDialog( ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + String[] defInstr = { "Instructions will appear here. ", "" } ; + dialog.printInstructions( defInstr ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + + public static void printInstructions( String[] instructions ) + { + dialog.printInstructions( instructions ); + } + + + public static void println( String messageIn ) + { + dialog.displayMessage( messageIn ); + } + +}// Sysout class + +/** + This is part of the standard test machinery. It provides a place for the + test instructions to be displayed, and a place for interactive messages + to the user to be displayed. + To have the test instructions displayed, see Sysout. + To have a message to the user be displayed, see Sysout. + Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog +{ + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog( Frame frame, String name ) + { + super( frame, name ); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); + add( "North", instructionsText ); + + messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); + add("Center", messageText); + + pack(); + + setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions( String[] instructions ) + { + //Clear out any current instructions + instructionsText.setText( "" ); + + //Go down array of instruction strings + + String printStr, remainingStr; + for( int i=0; i < instructions.length; i++ ) + { + //chop up each into pieces maxSringLength long + remainingStr = instructions[ i ]; + while( remainingStr.length() > 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + System.out.println(messageIn); + } + +}// TestDialog class diff --git a/jdk/test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.java b/jdk/test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.java index 7ef62198768..8b6d2fea517 100644 --- a/jdk/test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.java +++ b/jdk/test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, 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 @@ -192,8 +192,7 @@ public class TestDialogTypeAhead extends Applet } private void waitForIdle() { try { - Toolkit.getDefaultToolkit().sync(); - sun.awt.SunToolkit.flushPendingEvents(); + robot.waitForIdle(); EventQueue.invokeAndWait( new Runnable() { public void run() { // dummy implementation diff --git a/jdk/test/java/awt/Window/AlwaysOnTop/AutoTestOnTop.java b/jdk/test/java/awt/Window/AlwaysOnTop/AutoTestOnTop.java new file mode 100644 index 00000000000..07843be5ea6 --- /dev/null +++ b/jdk/test/java/awt/Window/AlwaysOnTop/AutoTestOnTop.java @@ -0,0 +1,795 @@ +/* + * Copyright (c) 2003, 2015, 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. + * + * 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. + */ + +/* + @test + @bug 4632143 + @summary Unit test for the RFE window/frame/dialog always on top + @author dom@sparc.spb.su: area=awt.toplevel + @run main AutoTestOnTop +*/ + +import java.awt.*; +import java.awt.event.*; +import java.lang.reflect.*; +import javax.swing.*; +import java.util.Vector; + +/** + * @author tav@sparc.spb.su + * @author dom@sparc.spb.su + * Tests that always-on-top windows combine correctly with different kinds of window in different styles and conditions. + * + * !!! WARNING !!! + * The test fails sometimes because the toFront() method doesn't guarantee + * that after its invocation the frame will be placed above all other windows. + */ +public class AutoTestOnTop { + static Window topw; + static Frame parentw = new Frame(); + static Window f; + static Frame parentf = new Frame(); + + static Object uncheckedSrc = new Object(); // used when no need to check event source + static Object eventSrc = uncheckedSrc; + static boolean dispatchedCond; + + static Semaphore STATE_SEMA = new Semaphore(); + static Semaphore VIS_SEMA = new Semaphore(); + static Vector errors = new Vector(); + + static boolean isUnix = false; + + static StringBuffer msgError = new StringBuffer(); + static StringBuffer msgCase = new StringBuffer(); + static StringBuffer msgAction = new StringBuffer(); + static StringBuffer msgFunc = new StringBuffer(); + static StringBuffer msgVisibility = new StringBuffer(); + + static volatile int stageNum; + static volatile int actNum; + static volatile int testResult = 0; + + static volatile boolean doCheckEvents; + static volatile boolean eventsCheckPassed; + static boolean[] eventsCheckInitVals = new boolean[] { // Whether events are checked for abcence or precence + true, true, true, true, true, false, false, false, false + }; + static String[] msgEventsChecks = new String[] { + null, null, null, null, null, + "expected WindowEvent.WINDOW_STATE_CHANGED hasn't been generated", + "expected WindowEvent.WINDOW_STATE_CHANGED hasn't been generated", + "expected WindowEvent.WINDOW_STATE_CHANGED hasn't been generated", + "expected WindowEvent.WINDOW_STATE_CHANGED hasn't been generated", + }; + + static final int stagesCount = 7; + static final int actionsCount = 9; + + static Method[] preActions = new Method[actionsCount]; + static Method[] postActions = new Method[actionsCount]; + static Method[] isActionsAllowed = new Method[actionsCount]; + static Method[] checksActionEvents = new Method[actionsCount]; + + static Robot robot; + + static boolean doStartTest; + static String osName = System.getProperty("os.name"); + + + public static void main(String[] args) { + checkTesting(); + + } + + public static void performTesting() { + isUnix = osName.equals("Linux") || osName.equals("SunOS"); + + Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { + public void eventDispatched(AWTEvent e) { + if (e.getID() == MouseEvent.MOUSE_CLICKED) { + if (eventSrc != null & eventSrc != uncheckedSrc && e.getSource() != eventSrc) { + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + ": " + msgError); + testResult = -1; + } + synchronized (eventSrc) { + dispatchedCond = true; + eventSrc.notify(); + } + } + + if (doCheckEvents && (e.getSource() == topw || e.getSource() == f)) { + + //System.err.println("AWTEventListener: catched the event " + e); + + try { + checksActionEvents[actNum].invoke(null, new Object[] {e}); + } catch (InvocationTargetException ite) { + ite.printStackTrace(); + } catch (IllegalAccessException iae) { + iae.printStackTrace(); + } + return; + } + } + }, 0xffffffffffffffffL); + + Method[] allMethods; + + try { + allMethods = AutoTestOnTop.class.getDeclaredMethods(); + } catch (SecurityException se) { + throw new RuntimeException(se); + } + + for (int i = 0; i < allMethods.length; i++) { + String name = allMethods[i].getName(); + if (name.startsWith("preAction")) { + preActions[name.charAt(name.length() - 1) - '0'] = allMethods[i]; + } else if (name.startsWith("postAction")) { + postActions[name.charAt(name.length() - 1) - '0'] = allMethods[i]; + } else if (name.startsWith("isActionAllowed")) { + isActionsAllowed[name.charAt(name.length() - 1) - '0'] = allMethods[i]; + } else if (name.startsWith("checkActionEvents")) { + checksActionEvents[name.charAt(name.length() - 1) - '0'] = allMethods[i]; + } + } + + f = new Frame("Auxiliary Frame"); + f.setBounds(50, 0, 400, 50); + f.setVisible(true); + waitTillShown(f); + + try { + robot = new Robot(); + } catch (AWTException e) { + throw new RuntimeException("Error: unable to create robot", e); + } + + mainTest(); + + if (testResult != 0) { + System.err.println("The following errors were encountered: "); + for (int i = 0; i < errors.size(); i++) { + System.err.println(errors.get(i).toString()); + } + throw new RuntimeException("Test failed."); + } else { + System.err.println("Test PASSED."); + } + } + + public static void mainTest() { +// stageNum = 0; +// for (int i = 0; i < 5; i++) { +// actNum = 2; +// System.err.println("************************* A C T I O N " + actNum + " *************************"); +// doStage(stageNum, actNum); +// // pause(500); +// actNum = 3; +// System.err.println("************************* A C T I O N " + actNum + " *************************"); +// doStage(stageNum, actNum); +// // pause(500); +// } + for (stageNum = 0; stageNum < stagesCount; stageNum++) { + System.err.println("************************* S T A G E " + stageNum + " *************************"); + for (actNum = 0; actNum < actionsCount; actNum++) { + System.err.println("************************* A C T I O N " + actNum + " *************************"); + doStage(stageNum, actNum); + } // for thru actNum + } // fow thru stageNum + + eventSrc = null; + } + + private static void doStage(int stageNum, int actNum) { + try { + + if (!((Boolean)isActionsAllowed[actNum].invoke(null, new Object[0])).booleanValue()) { + System.err.println("Action skipped due to a platform limitations"); + return; + } + + STATE_SEMA.reset(); + createWindow(stageNum); + + //************************* + // Set window always-on-top + //************************* + + preActions[actNum].invoke(null, new Object[0]); + setAlwaysOnTop(topw, true); + waitForIdle(true); + + if (!topw.isAlwaysOnTopSupported()) return; + + postActions[actNum].invoke(null, new Object[0]); + waitForIdle(false); + + STATE_SEMA.reset(); + + testForAlwaysOnTop(); + + //***************************** + // Set window not always-on-top + //***************************** + + preActions[actNum].invoke(null, new Object[0]); + setAlwaysOnTop(topw, false); + waitForIdle(true); + postActions[actNum].invoke(null, new Object[0]); + waitForIdle(false); + STATE_SEMA.reset(); + + testForNotAlwaysOnTop(); + + } catch (InvocationTargetException ite) { + ite.printStackTrace(); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + private static void checkTesting() { + if (Toolkit.getDefaultToolkit().isAlwaysOnTopSupported()) { + performTesting(); + } + } + + public static void testForAlwaysOnTop() { + System.err.println("Checking for always-on-top " + topw); + + ensureInitialWinPosition(topw); + + // Check that always-on-top window is topmost. + // - Click on always-on-top window on the windows cross area. + clickOn(topw, f, 10, 30, "setting " + msgVisibility + + " window (1) always-on-top didn't make it topmost"); + + // Check that we can't change z-order of always-on-top window. + // - a) Try to put the other window on the top. + f.toFront(); + clickOn(uncheckedSrc, f, 190, 30, ""); // coz toFront() works not always + pause(300); + + // - b) Click on always-on-top window on the windows cross area. + clickOn(topw, f, 10, 30, "setting " + msgVisibility + + " window (1) always-on-top didn't make it such"); + + // Ask for always-on-top property + if (isAlwaysOnTop(topw) != true) + error("Test failed: stage #" + stageNum + ", action #" + actNum + ": " + msgCase + ": " + msgAction + + ": isAlwaysOnTop() returned 'false' for window (1) set always-on-top at state " + + msgVisibility); + } + + public static void testForNotAlwaysOnTop() { + System.err.println("Checking for non always-on-top of " + topw); + ensureInitialWinPosition(topw); + + if (msgVisibility.equals("visible") && actNum != 2) { + // Check that the window remains topmost. + // - click on the window on the windows cross area. + clickOn(topw, f, 10, 30, "setting " + msgVisibility + + " window (1) not always-on-top didn't keep it topmost"); + } + + // Check that we can change z-order of not always-on-top window. + // - a) try to put the other window on the top. + f.toFront(); + clickOn(uncheckedSrc, f, 190, 30, ""); // coz toFront() works not always + pause(300); + + // - b) click on not always-on-top window on the windows cross area. + clickOn(f, f, 10, 30, "setting " + msgVisibility + + " window (1) not always-on-top didn't make it such"); + + // Ask for always-on-top property + if (isAlwaysOnTop(topw) != false) + error("Test failed: stage #" + stageNum + ", action #" + actNum + ": " + msgCase + ": " + msgAction + + ": isAlwaysOnTop() returned 'true' for window (1) set not always-on-top at state " + + msgVisibility); + } + + + private static void createWindow(int stageNum) { + // Free native resourses + if (topw != null && topw.isVisible()) { + topw.dispose(); + } + + switch (stageNum) { + case 0: + topw = new Frame("Top Frame"); + msgCase.replace(0, msgCase.length(), "Frame (1) over Frame (2)"); + break; + case 1: + topw = new JFrame("Top JFrame"); + msgCase.replace(0, msgCase.length(), "JFrame (1) over Frame (2)"); + break; + case 2: + topw = new Dialog(parentw, "Top Dialog"); + msgCase.replace(0, msgCase.length(), "Dialog (1) over Frame (2)"); + break; + case 3: + topw = new JDialog(parentw, "Top JDialog"); + msgCase.replace(0, msgCase.length(), "JDialog (1) over Frame (2)"); + break; + case 4: + topw = new Frame("Top Frame"); + f.dispose(); + f = new Dialog(parentf, "Auxiliary Dialog"); + f.setBounds(50, 0, 250, 50); + f.setVisible(true); + waitTillShown(f); + msgCase.replace(0, msgCase.length(), "Frame (1) over Dialog (2)"); + break; + case 5: + topw = new Window(parentw); + msgCase.replace(0, msgCase.length(), "Window (1) over Frame (2)"); + break; + case 6: + topw = new JWindow(parentw); + msgCase.replace(0, msgCase.length(), "JWindow (1) over Frame (2)"); + break; + } + topw.addWindowStateListener(new WindowAdapter() { + public void windowStateChanged(WindowEvent e) { + System.err.println("* " + e); + STATE_SEMA.raise(); + } + }); + topw.setSize(200, 50); + } + + /** + * 0: setting always-on-top to invisible window + * 1: setting always-on-top to visible window + * 2: always-on-top on visible non-focusable window + * 3: always-on-top on visible, dragging topw after that + * 4: always-on-top on visible, dragging f after that + * 5: always-on-top on (visible, maximized), make normal after that + * 6: always-on-top on (visible, iconified), make normal after that + * 7: always-on-top on visible, iconify/deiconify after that + * 8: always-on-top on visible, maximize/restore after that + */ + public static void preAction_0() { + topw.setVisible(false); + } + public static void postAction_0() { + if (topw.isShowing()) { + error("Test failed: stage #" + stageNum + ", action #" + actNum + ": " + msgCase + + ": no actions with windows: changing always-on-top property at window (1) state 'invisible' makes window (1) visible"); + } + setWindowVisible("no actions with windows", "invisible"); + } + public static boolean isActionAllowed_0() { + // Window on Linux is always always-on-top! + return !((stageNum == 5 || stageNum == 6) && isUnix) && (stageNum < stagesCount); + } + public static void checkActionEvents_0(AWTEvent e) { + System.err.println(e.toString()); + } + + public static void preAction_1() { + setWindowVisible("no actions with windows", "visible"); + } + public static void postAction_1() {} + public static boolean isActionAllowed_1() { + return !((stageNum == 5 || stageNum == 6) && isUnix) && (stageNum < stagesCount ); + } + public static void checkActionEvents_1(AWTEvent e) { + System.err.println(e.toString()); + if (e instanceof PaintEvent) { + return; + } + eventsCheckPassed = false; + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + ": after call " + msgFunc + + ": unexpected event " + e + " was generated"); + } + + public static void preAction_2() { + setWindowVisible("when window (1) set not focusable", "visible"); + topw.setFocusableWindowState(false); + f.toFront(); + pause(300); + } + public static void postAction_2() {} + public static boolean isActionAllowed_2() { + return !((stageNum == 5 || stageNum == 6) && isUnix) && (stageNum < stagesCount); + } + public static void checkActionEvents_2(AWTEvent e) { + System.err.println(e.toString()); + if ( (e.getID() >= FocusEvent.FOCUS_FIRST && e.getID() <= FocusEvent.FOCUS_LAST) || + (e.getID() == WindowEvent.WINDOW_LOST_FOCUS && e.getID() == WindowEvent.WINDOW_GAINED_FOCUS)) { + eventsCheckPassed = false; + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + + msgAction + ": after call " + msgFunc + + ": unexpected event " + e + " was generated"); + } + } + + public static void preAction_3() { + setWindowVisible("after dragging", "visible"); + } + public static void postAction_3() { + Point p = topw.getLocationOnScreen(); + int x = p.x + 40, y = p.y + 5; + + try { // Take a pause to avoid double click + Thread.sleep(500); // when called one after another. + } catch (InterruptedException ie) { + ie.printStackTrace(); + } catch (IllegalComponentStateException e) { + e.printStackTrace(); + } + + // Drag the window. + robot.mouseMove(x, y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseMove(200, 50); + robot.mouseMove(x, y); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + public static boolean isActionAllowed_3() { + return (stageNum < 5); + } + public static void checkActionEvents_3(AWTEvent e) { + System.err.println(e.toString()); + } + + public static void preAction_4() { + setWindowVisible("after dragging window (2)", "visible"); + } + public static void postAction_4() { + Point p = f.getLocationOnScreen(); + int x = p.x + 150, y = p.y + 5; + + try { // Take a pause to avoid double click + Thread.sleep(500); // when called one after another. + } catch (InterruptedException ie) { + ie.printStackTrace(); + } catch (IllegalComponentStateException e) { + e.printStackTrace(); + } + + // Drag the window. + robot.mouseMove(x, y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseMove(200, 50); + robot.mouseMove(x, y); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + ensureInitialWinPosition(f); + } + public static boolean isActionAllowed_4() { + return !((stageNum == 5 || stageNum == 6) && isUnix); + } + public static void checkActionEvents_4(AWTEvent e) { + System.err.println(e.toString()); + } + + // Metacity has a bug not allowing to set a window to NORMAL state!!! + + public static void preAction_5() { + setWindowVisible("at state 'maximized'", "visible"); + ((Frame)topw).setExtendedState(Frame.MAXIMIZED_BOTH); + waitForStateChange(); + } + public static void postAction_5() { + ((Frame)topw).setExtendedState(Frame.NORMAL); + waitForStateChange(); + } + public static boolean isActionAllowed_5() { + return (stageNum < 2); + } + public static void checkActionEvents_5(AWTEvent e) { + System.err.println("=" + e.toString()); + if (e.getID() == WindowEvent.WINDOW_STATE_CHANGED) { + eventsCheckPassed = true; + } + } + + public static void preAction_6() { + setWindowVisible("at state 'iconified'", "visible"); + System.err.println("Iconifying " + topw); + ((Frame)topw).setExtendedState(Frame.ICONIFIED); + if (!waitForStateChange()) { + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + ": after call " + msgFunc + + ": state change to ICONIFIED hasn't been generated"); + } + } + public static void postAction_6() { + System.err.println("Restoring " + topw); + ((Frame)topw).setExtendedState(Frame.NORMAL); + if (!waitForStateChange()) { + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + ": after call " + msgFunc + + ": state change to NORMAL hasn't been generated"); + } + } + public static boolean isActionAllowed_6() { + return (stageNum < 2 ); + } + public static void checkActionEvents_6(AWTEvent e) { + System.err.println("+" + e.toString()); + if (e.getID() == WindowEvent.WINDOW_STATE_CHANGED) { + eventsCheckPassed = true; + } + } + + public static void preAction_7() { + setWindowVisible("before state 'iconified'", "visible"); + } + public static void postAction_7() { + System.err.println("Setting iconified"); + ((Frame)topw).setExtendedState(Frame.ICONIFIED); + if (!waitForStateChange()) { + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + ": after call " + msgFunc + + ": state change to ICONIFIED hasn't been generated"); + } + System.err.println("Setting normal"); + ((Frame)topw).setExtendedState(Frame.NORMAL); + if (!waitForStateChange()) { + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + ": after call " + msgFunc + + ": state change to NORMAL hasn't been generated"); + } + } + public static boolean isActionAllowed_7() { + return (stageNum < 2); + } + public static void checkActionEvents_7(AWTEvent e) { + System.err.println(e.toString()); + if (e.getID() == WindowEvent.WINDOW_STATE_CHANGED) { + eventsCheckPassed = true; + } + } + + public static void preAction_8() { + setWindowVisible("before state 'maximized'", "visible"); + } + public static void postAction_8() { + ((Frame)topw).setExtendedState(Frame.MAXIMIZED_BOTH); + if (!waitForStateChange()) { + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + ": after call " + msgFunc + + ": state change to MAXIMIZED hasn't been generated"); + } + ((Frame)topw).setExtendedState(Frame.NORMAL); + if (!waitForStateChange()) { + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + ": after call " + msgFunc + + ": state change to NORMAL hasn't been generated"); + } + } + public static boolean isActionAllowed_8() { + return (stageNum < 2); + } + public static void checkActionEvents_8(AWTEvent e) { + System.err.println(e.toString()); + if (e.getID() == WindowEvent.WINDOW_STATE_CHANGED) { + eventsCheckPassed = true; + } + } + + //*************************************************************************** + + private static void setWindowVisible(String mAction, String mVisibility) { + msgAction.replace(0, msgAction.length(), mAction); + msgVisibility.replace(0, msgVisibility.length(), mVisibility); + + topw.setVisible(true); + pause(100); // Needs for Sawfish + topw.setLocation(0, 0); + waitTillShown(topw); + f.toFront(); + pause(300); + } + + private static void clickOn(Object src, Window relwin, int x, int y, String errorStr) { + Point p = relwin.getLocationOnScreen(); + int counter = 10; + while (--counter > 0) { + eventSrc = src; + msgError.replace(0, msgError.length(), errorStr); + + robot.mouseMove(p.x + x, p.y + y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + synchronized (eventSrc) { + if (!dispatchedCond) { + try { + eventSrc.wait(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + if (!dispatchedCond) { + //System.err.println("clickOn: MOUSE_CLICKED event losed, trying to generate it again..."); + continue; + } + dispatchedCond = false; + } + break; + } // end while + if (counter <= 0) { + eventSrc = uncheckedSrc; + error("Test: internal error: could't catch MOUSE_CLICKED event. Skip testing this stage"); + } + } + + private static void setAlwaysOnTop(Window w, boolean value) { + System.err.println("Setting always on top on " + w + " to " + value); + robot.mouseMove(0, 100); // Move out of the window + msgFunc.replace(0, msgCase.length(), "setAlwaysOnTop()"); + try { + w.setAlwaysOnTop(value); + } catch (Exception e) { + error("Test failed: stage#" + stageNum + "action #" + actNum + ": " + msgCase + ": " + msgAction + + ": setAlwaysOnTop(" + value + ") called at state " + msgVisibility + + " threw exeption " + e); + } + } + + private static boolean isAlwaysOnTop(Window w) { + robot.mouseMove(0, 100); // Move out of the window + msgFunc.replace(0, msgCase.length(), "isAlwaysOnTop()"); + boolean result = false; + try { + result = w.isAlwaysOnTop(); + } catch (Exception e) { + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + + ": isAlwaysOnTop() called at state " + msgVisibility + + " threw exeption " + e); + } + return result; + } + + private static void waitTillShown(Component c) { + while (true) { + try { + Thread.sleep(100); + c.getLocationOnScreen(); + break; + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + } + } + + private static void waitForIdle(boolean doCheck) { + try { + robot.waitForIdle(); + EventQueue.invokeAndWait( new Runnable() { + public void run() {} // Dummy implementation + } ); + } catch(InterruptedException ite) { + System.err.println("waitForIdle, non-fatal exception caught:"); + ite.printStackTrace(); + } catch(InvocationTargetException ine) { + System.err.println("waitForIdle, non-fatal exception caught:"); + ine.printStackTrace(); + } + doCheckEvents = doCheck; + + if (doCheck) { + eventsCheckPassed = eventsCheckInitVals[actNum]; // Initialize + } else if (!eventsCheckPassed && + msgEventsChecks[actNum] != null) { + + + // Some expected event hasn't been catched, + // so give it one more chance... + doCheckEvents = true; + pause(500); + doCheckEvents = false; + + if (!eventsCheckPassed) { + testResult = -1; + error("Test failed: stage #" + stageNum + ", action # " + actNum + ": " + msgCase + ": " + msgAction + ": after call " + + msgFunc + ": " + msgEventsChecks[actNum]); + } + } + } + + private static boolean waitForStateChange() { + System.err.println("------- Waiting for state change"); + try { + STATE_SEMA.doWait(3000); + } catch (InterruptedException ie) { + System.err.println("Wait interrupted: " + ie); + } + boolean state = STATE_SEMA.getState(); + STATE_SEMA.reset(); + return state; + } + + private static void ensureInitialWinPosition(Window w) { + int counter = 30; + while (w.getLocationOnScreen().y != 0 && --counter > 0) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + } + if (counter <= 0) { + w.setLocation(0, 0); + pause(100); + System.err.println("Test: window set to initial position forcedly"); + } + } + + private static void pause(int mls) { + try { + Thread.sleep(mls); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private static void error(String msg) { + errors.add(msg); + System.err.println(msg); + } +} + +class Semaphore { + boolean state = false; + int waiting = 0; + public Semaphore() { + } + public synchronized void doWait() throws InterruptedException { + if (state) { + return; + } + waiting++; + wait(); + waiting--; + } + public synchronized void doWait(int timeout) throws InterruptedException { + if (state) { + return; + } + waiting++; + wait(timeout); + waiting--; + } + public synchronized void raise() { + state = true; + if (waiting > 0) { + notifyAll(); + } + } + + public synchronized void doNotify() { + notifyAll(); + } + public synchronized boolean getState() { + return state; + } + + public synchronized void reset() { + state = false; + } +} diff --git a/jdk/test/java/awt/event/ComponentEvent/MovedResizedTardyEventTest/MovedResizedTardyEventTest.html b/jdk/test/java/awt/event/ComponentEvent/MovedResizedTardyEventTest/MovedResizedTardyEventTest.html new file mode 100644 index 00000000000..39bbfcab4cd --- /dev/null +++ b/jdk/test/java/awt/event/ComponentEvent/MovedResizedTardyEventTest/MovedResizedTardyEventTest.html @@ -0,0 +1,43 @@ + + + + + +MovedResizedTardyEventTest + + + +

MovedResizedTardyEventTest
Bug ID: 4985250

+ +

See the dialog box (usually in upper left corner) for instructions

+ + + + diff --git a/jdk/test/java/awt/event/ComponentEvent/MovedResizedTardyEventTest/MovedResizedTardyEventTest.java b/jdk/test/java/awt/event/ComponentEvent/MovedResizedTardyEventTest/MovedResizedTardyEventTest.java new file mode 100644 index 00000000000..4c775119e9d --- /dev/null +++ b/jdk/test/java/awt/event/ComponentEvent/MovedResizedTardyEventTest/MovedResizedTardyEventTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2004, 2015, 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. + * + * 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. + */ + +/* + test + @bug 4985250 + @summary COMPONENT_MOVED/RESIZED tardy events shouldn't be generated. + @author tav@sparc.spb.su + @run applet MovedResizedTardyEventTest.html +*/ + +import java.awt.*; +import java.awt.event.*; +import java.applet.Applet; +import java.lang.reflect.InvocationTargetException; + +public class MovedResizedTardyEventTest extends Applet { + Frame f1 = new Frame("F-1"); + Frame f2 = new Frame("F-2"); + + boolean eventFlag = false; + + public static void main(String[] args) { + Applet a = new MovedResizedTardyEventTest(); + a.start(); + } + + public void start() { + f1.setVisible(true); + f2.setVisible(true); + + try { + Thread.sleep(500); + } catch (InterruptedException e) {} + + f1.addComponentListener(new ComponentAdapter() { + public void componentMoved(ComponentEvent e) { + MovedResizedTardyEventTest.this.eventFlag = true; + System.err.println(e); + } + public void componentResized(ComponentEvent e) { + MovedResizedTardyEventTest.this.eventFlag = true; + System.err.println(e); + } + }); + + f1.toFront(); + + waitForIdle(); + + try { // wait more... + Thread.sleep(500); + } catch (InterruptedException e) {} + + if (eventFlag) { + throw new RuntimeException("Test failed!"); + } + } + + void waitForIdle() { + try { + (new Robot()).waitForIdle(); + EventQueue.invokeAndWait( new Runnable() { + public void run() {} // Dummy implementation + }); + } catch(InterruptedException ie) { + System.err.println("waitForIdle, non-fatal exception caught:"); + ie.printStackTrace(); + } catch(InvocationTargetException ite) { + System.err.println("waitForIdle, non-fatal exception caught:"); + ite.printStackTrace(); + } catch(AWTException rex) { + rex.printStackTrace(); + throw new RuntimeException("unexpected exception"); + } + } +} diff --git a/jdk/test/java/awt/event/KeyEvent/AltCharAcceleratorTest/AltCharAcceleratorTest.java b/jdk/test/java/awt/event/KeyEvent/AltCharAcceleratorTest/AltCharAcceleratorTest.java index 6a5a26f84bf..741c4813903 100644 --- a/jdk/test/java/awt/event/KeyEvent/AltCharAcceleratorTest/AltCharAcceleratorTest.java +++ b/jdk/test/java/awt/event/KeyEvent/AltCharAcceleratorTest/AltCharAcceleratorTest.java @@ -29,8 +29,6 @@ @run main AltCharAcceleratorTest */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.awt.event.*; @@ -103,12 +101,11 @@ public class AltCharAcceleratorTest { } void test() throws Exception { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); - - focusLatch.await(5, TimeUnit.SECONDS); - Robot robot = new Robot(); robot.setAutoDelay(100); + robot.waitForIdle(); + + focusLatch.await(5, TimeUnit.SECONDS); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_T); @@ -133,4 +130,4 @@ public class AltCharAcceleratorTest { AltCharAcceleratorTest t = new AltCharAcceleratorTest(); t.test(); } -} \ No newline at end of file +} diff --git a/jdk/test/java/awt/keyboard/EqualKeyCode/EqualKeyCode.java b/jdk/test/java/awt/keyboard/EqualKeyCode/EqualKeyCode.java index d4acc95ef2b..9f8598c14b7 100644 --- a/jdk/test/java/awt/keyboard/EqualKeyCode/EqualKeyCode.java +++ b/jdk/test/java/awt/keyboard/EqualKeyCode/EqualKeyCode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -24,18 +24,14 @@ /* @test @bug 6799551 - @library ../../regtesthelpers - @build Util Sysout @summary Extended key codes for small letters undefined @author Andrei Dmitriev: area=awt.keyboard @run main EqualKeyCode */ -import sun.awt.*; import java.awt.*; -import test.java.awt.regtesthelpers.Util; -import test.java.awt.regtesthelpers.Sysout; +import java.awt.event.KeyEvent; public class EqualKeyCode { @@ -46,13 +42,13 @@ public class EqualKeyCode { char cSmall = LETTERS.charAt(i); char cLarge = Character.toUpperCase(cSmall); - int iSmall = ExtendedKeyCodes.getExtendedKeyCodeForChar(cSmall); - int iLarge = ExtendedKeyCodes.getExtendedKeyCodeForChar(cLarge); + int iSmall = KeyEvent.getExtendedKeyCodeForChar(cSmall); + int iLarge = KeyEvent.getExtendedKeyCodeForChar(cLarge); System.out.print(" " + cSmall + ":" + iSmall + " ---- "); System.out.println(" " + cLarge + " : " + iLarge); - if (ExtendedKeyCodes.getExtendedKeyCodeForChar(cSmall) != - ExtendedKeyCodes.getExtendedKeyCodeForChar(cLarge)) + if (KeyEvent.getExtendedKeyCodeForChar(cSmall) != + KeyEvent.getExtendedKeyCodeForChar(cLarge)) { throw new RuntimeException("ExtendedKeyCode doesn't exist or doesn't match between capital and small letters."); } diff --git a/jdk/test/javax/swing/ToolTipManager/7123767/bug7123767.java b/jdk/test/javax/swing/ToolTipManager/7123767/bug7123767.java index 4c7402d3900..143503861a1 100644 --- a/jdk/test/javax/swing/ToolTipManager/7123767/bug7123767.java +++ b/jdk/test/javax/swing/ToolTipManager/7123767/bug7123767.java @@ -28,8 +28,6 @@ @run main bug7123767 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.plaf.metal.MetalLookAndFeel; import java.awt.*; @@ -160,8 +158,10 @@ public class bug7123767 extends JFrame { // Moves mouse pointer to the corners of every GraphicsConfiguration private static void testToolTip() throws AWTException { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); + + robot = new Robot(); + robot.setAutoDelay(20); + robot.waitForIdle(); GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] devices = environment.getScreenDevices(); @@ -169,28 +169,28 @@ public class bug7123767 extends JFrame { GraphicsConfiguration[] configs = device.getConfigurations(); for (GraphicsConfiguration config : configs) { Rectangle rect = config.getBounds(); - Insets insets = toolkit.getScreenInsets(config); + Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config); adjustInsets(rect, insets); // Upper left glide(rect.x + rect.width / 2, rect.y + rect.height / 2, rect.x + MARGIN, rect.y + MARGIN); - toolkit.realSync(); + robot.waitForIdle(); // Lower left glide(rect.x + rect.width / 2, rect.y + rect.height / 2, rect.x + MARGIN, rect.y + rect.height - MARGIN); - toolkit.realSync(); + robot.waitForIdle(); // Upper right glide(rect.x + rect.width / 2, rect.y + rect.height / 2, rect.x + rect.width - MARGIN, rect.y + MARGIN); - toolkit.realSync(); + robot.waitForIdle(); // Lower right glide(rect.x + rect.width / 2, rect.y + rect.height / 2, rect.x + rect.width - MARGIN, rect.y + rect.height - MARGIN); - toolkit.realSync(); + robot.waitForIdle(); } } } From ca998d2d4c5461ba24ebf4716efd741854f257d7 Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Wed, 18 Mar 2015 15:03:16 +0400 Subject: [PATCH 087/362] 4473075: JTable header rendering problem (after setting preferred size) Reviewed-by: alexsch, serb --- .../javax/swing/table/JTableHeader.java | 20 ++++ .../JTableHeader/4473075/bug4473075.java | 106 ++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 jdk/test/javax/swing/JTableHeader/4473075/bug4473075.java diff --git a/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java b/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java index 1fac3acf73b..fbf742a43c1 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java @@ -439,6 +439,26 @@ public class JTableHeader extends JComponent implements TableColumnModelListener return tip; } + /** + * Returns the preferred size of the table header. + * This is the size required to display the header and requested for + * the viewport. + * The returned {@code Dimension} {@code width} will always be calculated by + * the underlying TableHeaderUI, regardless of any width specified by + * {@link JComponent#setPreferredSize(java.awt.Dimension)} + * + * @return the size + */ + @Override + public Dimension getPreferredSize() { + Dimension preferredSize = super.getPreferredSize(); + if (isPreferredSizeSet() && ui != null) { + Dimension size = ui.getPreferredSize(this); + if (size != null) preferredSize.width = size.width; + } + return preferredSize; + } + // // Managing TableHeaderUI // diff --git a/jdk/test/javax/swing/JTableHeader/4473075/bug4473075.java b/jdk/test/javax/swing/JTableHeader/4473075/bug4473075.java new file mode 100644 index 00000000000..a45cd16a56a --- /dev/null +++ b/jdk/test/javax/swing/JTableHeader/4473075/bug4473075.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* @test + @bug 4473075 + @summary JTable header rendering problem (after setting preferred size) + @author Semyon Sadetsky +*/ + +import javax.swing.*; +import javax.swing.table.DefaultTableModel; +import java.awt.*; +import java.awt.event.InputEvent; + +public class bug4473075 { + public static final int USER_HEADER_HEIGHT = 40; + private static JTable table; + private static JScrollPane scpScroll; + private static Point point; + private static JFrame frame; + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + robot.setAutoDelay(20); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame = new JFrame(); + frame.setUndecorated(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + table = new JTable(); + String t = "a cell text"; + table.setModel(new DefaultTableModel( + new Object[][]{new Object[]{t, t, t, t, t}}, + new Object[]{t, t, t, t, t})); + table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + scpScroll = new JScrollPane(table); + + // Manually set preferred size of header... + Dimension preferredSize = new Dimension(table.getSize().width, + USER_HEADER_HEIGHT); + table.getTableHeader().setPreferredSize(preferredSize); + + frame.setContentPane(scpScroll); + frame.setSize(250, 480); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + point = scpScroll.getHorizontalScrollBar() + .getLocationOnScreen(); + } + }); + robot.waitForIdle(); + + robot.mouseMove(point.x + 100, point.y + 5); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseMove(point.x + 150, point.y + 5); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + int headerH = table.getTableHeader().getHeight(); + if (headerH != USER_HEADER_HEIGHT) { + throw new RuntimeException("TableHeader height was not set: " + + headerH + " !=" + USER_HEADER_HEIGHT); + } + + double tableX = table.getX(); + int headerX = table.getTableHeader().getX(); + if (tableX != headerX) { + throw new RuntimeException("TableHeader X position is wrong: " + + tableX + " !=" + headerX); + } + + double tableW = table.getWidth(); + int headerW = table.getTableHeader().getWidth(); + if (tableW != headerW) { + throw new RuntimeException("TableHeader width is wrong: " + + tableW + " !=" + headerW); + } + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + frame.dispose(); + } + }); + System.out.println("ok"); + } +} From 28114420db9c0ab453a37360d78b63db6a1a988b Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Fri, 20 Mar 2015 10:00:30 -0700 Subject: [PATCH 088/362] 8075573: Add jdk_other and jdk_svc to jdk tier 2 test definition Reviewed-by: mchung --- jdk/test/TEST.groups | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jdk/test/TEST.groups b/jdk/test/TEST.groups index 2ee1007a5e7..aa80127fbe8 100644 --- a/jdk/test/TEST.groups +++ b/jdk/test/TEST.groups @@ -38,7 +38,9 @@ tier2 = \ :jdk_time \ :jdk_security \ :jdk_text \ - :core_tools + :core_tools \ + :jdk_other \ + :jdk_svc ############################################################################### # From 49dec121161c162f4aa94caf8c09413253d89377 Mon Sep 17 00:00:00 2001 From: Mikael Vidstedt Date: Fri, 20 Mar 2015 10:02:44 -0700 Subject: [PATCH 089/362] 8074839: Resolve disabled warnings for libunpack and the unpack200 binary Reviewed-by: dholmes, ksrini --- jdk/make/launcher/Launcher-jdk.pack200.gmk | 3 -- jdk/make/lib/Lib-jdk.pack200.gmk | 5 -- .../share/native/common-unpack/bytes.h | 2 +- .../share/native/common-unpack/unpack.cpp | 50 ++++++++++--------- .../share/native/common-unpack/unpack.h | 2 +- .../share/native/common-unpack/utils.cpp | 2 +- .../share/native/common-unpack/zip.cpp | 8 +-- .../share/native/common-unpack/zip.h | 4 +- .../share/native/libunpack/jni.cpp | 5 +- .../share/native/unpack200/main.cpp | 39 +++++++-------- 10 files changed, 57 insertions(+), 63 deletions(-) diff --git a/jdk/make/launcher/Launcher-jdk.pack200.gmk b/jdk/make/launcher/Launcher-jdk.pack200.gmk index 6ee00f7ccd0..affdbdb26eb 100644 --- a/jdk/make/launcher/Launcher-jdk.pack200.gmk +++ b/jdk/make/launcher/Launcher-jdk.pack200.gmk @@ -79,9 +79,6 @@ $(eval $(call SetupNativeCompilation,BUILD_UNPACKEXE, \ CFLAGS_linux := -fPIC, \ CFLAGS_solaris := -KPIC, \ CFLAGS_macosx := -fPIC, \ - DISABLED_WARNINGS_gcc := sign-compare unused-result format-nonliteral \ - format-security parentheses, \ - DISABLED_WARNINGS_microsoft := 4267 4018, \ MAPFILE := $(UNPACK_MAPFILE),\ LDFLAGS := $(UNPACKEXE_ZIPOBJS) \ $(LDFLAGS_JDKEXE) $(LDFLAGS_CXX_JDK) \ diff --git a/jdk/make/lib/Lib-jdk.pack200.gmk b/jdk/make/lib/Lib-jdk.pack200.gmk index 37e32d0a725..105f1f8b713 100644 --- a/jdk/make/lib/Lib-jdk.pack200.gmk +++ b/jdk/make/lib/Lib-jdk.pack200.gmk @@ -40,11 +40,6 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBUNPACK, \ -I$(JDK_TOPDIR)/src/jdk.pack200/share/native/common-unpack \ $(LIBJAVA_HEADER_FLAGS), \ CFLAGS_release := -DPRODUCT, \ - DISABLED_WARNINGS_gcc := conversion-null sign-compare format-security \ - format-nonliteral parentheses, \ - DISABLED_WARNINGS_clang := bool-conversion format-security, \ - DISABLED_WARNINGS_solstudio := truncwarn, \ - DISABLED_WARNINGS_microsoft := 4267 4018, \ MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libunpack/mapfile-vers, \ LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ diff --git a/jdk/src/jdk.pack200/share/native/common-unpack/bytes.h b/jdk/src/jdk.pack200/share/native/common-unpack/bytes.h index bdaf95a2f6a..60c5b4f2a69 100644 --- a/jdk/src/jdk.pack200/share/native/common-unpack/bytes.h +++ b/jdk/src/jdk.pack200/share/native/common-unpack/bytes.h @@ -63,7 +63,7 @@ struct bytes { bytes res; res.ptr = ptr + beg; res.len = end - beg; - assert(res.len == 0 || inBounds(res.ptr) && inBounds(res.limit()-1)); + assert(res.len == 0 || (inBounds(res.ptr) && inBounds(res.limit()-1))); return res; } // building C strings inside byte buffers: diff --git a/jdk/src/jdk.pack200/share/native/common-unpack/unpack.cpp b/jdk/src/jdk.pack200/share/native/common-unpack/unpack.cpp index 5af0422661d..60aa3bfdf0c 100644 --- a/jdk/src/jdk.pack200/share/native/common-unpack/unpack.cpp +++ b/jdk/src/jdk.pack200/share/native/common-unpack/unpack.cpp @@ -225,9 +225,9 @@ struct entry { } #ifdef PRODUCT - char* string() { return 0; } + const char* string() { return NULL; } #else - char* string(); // see far below + const char* string(); // see far below #endif }; @@ -718,13 +718,13 @@ void unpacker::read_file_header() { // Now we can size the whole archive. // Read everything else into a mega-buffer. rp = hdr.rp; - int header_size_0 = (int)(rp - input.base()); // used-up header (4byte + 3int) - int header_size_1 = (int)(rplimit - rp); // buffered unused initial fragment - int header_size = header_size_0+header_size_1; + size_t header_size_0 = (rp - input.base()); // used-up header (4byte + 3int) + size_t header_size_1 = (rplimit - rp); // buffered unused initial fragment + size_t header_size = header_size_0 + header_size_1; unsized_bytes_read = header_size_0; CHECK; if (foreign_buf) { - if (archive_size > (size_t)header_size_1) { + if (archive_size > header_size_1) { abort("EOF reading fixed input buffer"); return; } @@ -738,7 +738,7 @@ void unpacker::read_file_header() { return; } input.set(U_NEW(byte, add_size(header_size_0, archive_size, C_SLOP)), - (size_t) header_size_0 + archive_size); + header_size_0 + archive_size); CHECK; assert(input.limit()[0] == 0); // Move all the bytes we read initially into the real buffer. @@ -961,13 +961,13 @@ void cpool::init(unpacker* u_, int counts[CONSTANT_Limit]) { nentries = next_entry; // place a limit on future CP growth: - int generous = 0; + size_t generous = 0; generous = add_size(generous, u->ic_count); // implicit name generous = add_size(generous, u->ic_count); // outer generous = add_size(generous, u->ic_count); // outer.utf8 generous = add_size(generous, 40); // WKUs, misc generous = add_size(generous, u->class_count); // implicit SourceFile strings - maxentries = add_size(nentries, generous); + maxentries = (uint)add_size(nentries, generous); // Note that this CP does not include "empty" entries // for longs and doubles. Those are introduced when @@ -985,8 +985,9 @@ void cpool::init(unpacker* u_, int counts[CONSTANT_Limit]) { } // Initialize *all* our entries once - for (int i = 0 ; i < maxentries ; i++) + for (uint i = 0 ; i < maxentries ; i++) { entries[i].outputIndex = REQUESTED_NONE; + } initGroupIndexes(); // Initialize hashTab to a generous power-of-two size. @@ -3680,21 +3681,22 @@ void cpool::computeOutputIndexes() { unpacker* debug_u; -static bytes& getbuf(int len) { // for debugging only! +static bytes& getbuf(size_t len) { // for debugging only! static int bn = 0; static bytes bufs[8]; bytes& buf = bufs[bn++ & 7]; - while ((int)buf.len < len+10) + while (buf.len < len + 10) { buf.realloc(buf.len ? buf.len * 2 : 1000); + } buf.ptr[0] = 0; // for the sake of strcat return buf; } -char* entry::string() { +const char* entry::string() { bytes buf; switch (tag) { case CONSTANT_None: - return (char*)""; + return ""; case CONSTANT_Signature: if (value.b.ptr == null) return ref(0)->string(); @@ -3714,26 +3716,28 @@ char* entry::string() { break; default: if (nrefs == 0) { - buf = getbuf(20); - sprintf((char*)buf.ptr, TAG_NAME[tag]); + return TAG_NAME[tag]; } else if (nrefs == 1) { return refs[0]->string(); } else { - char* s1 = refs[0]->string(); - char* s2 = refs[1]->string(); - buf = getbuf((int)strlen(s1) + 1 + (int)strlen(s2) + 4 + 1); + const char* s1 = refs[0]->string(); + const char* s2 = refs[1]->string(); + buf = getbuf(strlen(s1) + 1 + strlen(s2) + 4 + 1); buf.strcat(s1).strcat(" ").strcat(s2); if (nrefs > 2) buf.strcat(" ..."); } } - return (char*)buf.ptr; + return (const char*)buf.ptr; } void print_cp_entry(int i) { entry& e = debug_u->cp.entries[i]; - char buf[30]; - sprintf(buf, ((uint)e.tag < CONSTANT_Limit)? TAG_NAME[e.tag]: "%d", e.tag); - printf(" %d\t%s %s\n", i, buf, e.string()); + + if ((uint)e.tag < CONSTANT_Limit) { + printf(" %d\t%s %s\n", i, TAG_NAME[e.tag], e.string()); + } else { + printf(" %d\t%d %s\n", i, e.tag, e.string()); + } } void print_cp_entries(int beg, int end) { diff --git a/jdk/src/jdk.pack200/share/native/common-unpack/unpack.h b/jdk/src/jdk.pack200/share/native/common-unpack/unpack.h index 621b1c1db01..ba3b7d5ad69 100644 --- a/jdk/src/jdk.pack200/share/native/common-unpack/unpack.h +++ b/jdk/src/jdk.pack200/share/native/common-unpack/unpack.h @@ -210,7 +210,7 @@ struct unpacker { byte* rp; // read pointer (< rplimit <= input.limit()) byte* rplimit; // how much of the input block has been read? julong bytes_read; - int unsized_bytes_read; + size_t unsized_bytes_read; // callback to read at least one byte, up to available input typedef jlong (*read_input_fn_t)(unpacker* self, void* buf, jlong minlen, jlong maxlen); diff --git a/jdk/src/jdk.pack200/share/native/common-unpack/utils.cpp b/jdk/src/jdk.pack200/share/native/common-unpack/utils.cpp index e5197e1a3f1..40a10055ea5 100644 --- a/jdk/src/jdk.pack200/share/native/common-unpack/utils.cpp +++ b/jdk/src/jdk.pack200/share/native/common-unpack/utils.cpp @@ -81,7 +81,7 @@ void breakpoint() { } // hook for debugger int assert_failed(const char* p) { char message[1<<12]; sprintf(message, "@assert failed: %s\n", p); - fprintf(stdout, 1+message); + fprintf(stdout, "%s", 1+message); breakpoint(); unpack_abort(message); return 0; diff --git a/jdk/src/jdk.pack200/share/native/common-unpack/zip.cpp b/jdk/src/jdk.pack200/share/native/common-unpack/zip.cpp index 8dc2634987f..a540ab42d3d 100644 --- a/jdk/src/jdk.pack200/share/native/common-unpack/zip.cpp +++ b/jdk/src/jdk.pack200/share/native/common-unpack/zip.cpp @@ -84,7 +84,7 @@ void jar::init(unpacker* u_) { } // Write data to the ZIP output stream. -void jar::write_data(void* buff, int len) { +void jar::write_data(void* buff, size_t len) { while (len > 0) { int rc = (int)fwrite(buff, 1, len, jarfp); if (rc <= 0) { @@ -323,12 +323,12 @@ void jar::write_central_directory() { // Total number of disks (int) header64[36] = (ushort)SWAP_BYTES(1); header64[37] = 0; - write_data(header64, (int)sizeof(header64)); + write_data(header64, sizeof(header64)); } // Write the End of Central Directory structure. PRINTCR((2, "end-of-directory at %d\n", output_file_offset)); - write_data(header, (int)sizeof(header)); + write_data(header, sizeof(header)); PRINTCR((2, "writing zip comment\n")); // Write the comment. @@ -590,7 +590,7 @@ void gunzip::init(unpacker* u_) { zstream = NEW(z_stream, 1); u->gzin = this; u->read_input_fn = read_input_via_gzip; - u->gzcrc = crc32(0L, Z_NULL, 0); + u->gzcrc = crc32(0, Z_NULL, 0); } void gunzip::start(int magic) { diff --git a/jdk/src/jdk.pack200/share/native/common-unpack/zip.h b/jdk/src/jdk.pack200/share/native/common-unpack/zip.h index 14ffc9d65bd..9877f6f68ca 100644 --- a/jdk/src/jdk.pack200/share/native/common-unpack/zip.h +++ b/jdk/src/jdk.pack200/share/native/common-unpack/zip.h @@ -68,8 +68,8 @@ struct jar { } // Private Methods - void write_data(void* ptr, int len); - void write_data(bytes& b) { write_data(b.ptr, (int)b.len); } + void write_data(void* ptr, size_t len); + void write_data(bytes& b) { write_data(b.ptr, b.len); } void add_to_jar_directory(const char* fname, bool store, int modtime, int len, int clen, uLong crc); void write_jar_header(const char* fname, bool store, int modtime, diff --git a/jdk/src/jdk.pack200/share/native/libunpack/jni.cpp b/jdk/src/jdk.pack200/share/native/libunpack/jni.cpp index e9109cbec96..4915590aeaa 100644 --- a/jdk/src/jdk.pack200/share/native/libunpack/jni.cpp +++ b/jdk/src/jdk.pack200/share/native/libunpack/jni.cpp @@ -292,7 +292,7 @@ Java_com_sun_java_util_jar_pack_NativeUnpack_getUnusedInput(JNIEnv *env, jobject if (uPtr->aborting()) { THROW_IOE(uPtr->get_abort_message()); - return false; + return null; } // We have fetched all the files. @@ -310,7 +310,7 @@ Java_com_sun_java_util_jar_pack_NativeUnpack_getUnusedInput(JNIEnv *env, jobject JNIEXPORT jlong JNICALL Java_com_sun_java_util_jar_pack_NativeUnpack_finish(JNIEnv *env, jobject pObj) { unpacker* uPtr = get_unpacker(env, pObj, false); - CHECK_EXCEPTION_RETURN_VALUE(uPtr, NULL); + CHECK_EXCEPTION_RETURN_VALUE(uPtr, 0); size_t consumed = uPtr->input_consumed(); free_unpacker(env, pObj, uPtr); return consumed; @@ -320,6 +320,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_java_util_jar_pack_NativeUnpack_setOption(JNIEnv *env, jobject pObj, jstring pProp, jstring pValue) { unpacker* uPtr = get_unpacker(env, pObj); + CHECK_EXCEPTION_RETURN_VALUE(uPtr, false); const char* prop = env->GetStringUTFChars(pProp, JNI_FALSE); CHECK_EXCEPTION_RETURN_VALUE(prop, false); const char* value = env->GetStringUTFChars(pValue, JNI_FALSE); diff --git a/jdk/src/jdk.pack200/share/native/unpack200/main.cpp b/jdk/src/jdk.pack200/share/native/unpack200/main.cpp index fdce8857c2c..d03db583c38 100644 --- a/jdk/src/jdk.pack200/share/native/unpack200/main.cpp +++ b/jdk/src/jdk.pack200/share/native/unpack200/main.cpp @@ -149,31 +149,28 @@ static const char* nbasename(const char* progname) { return progname; } -static const char* usage_lines[] = { - "Usage: %s [-opt... | --option=value]... x.pack[.gz] y.jar\n", - "\n", - "Unpacking Options\n", - " -H{h}, --deflate-hint={h} override transmitted deflate hint: true, false, or keep (default)\n", - " -r, --remove-pack-file remove input file after unpacking\n", - " -v, --verbose increase program verbosity\n", - " -q, --quiet set verbosity to lowest level\n", - " -l{F}, --log-file={F} output to the given log file, or '-' for standard output (default)\n", - " -?, -h, --help print this message\n", - " -V, --version print program version\n", - " -J{X} Java VM argument (ignored)\n", - null -}; +#define USAGE_HEADER "Usage: %s [-opt... | --option=value]... x.pack[.gz] y.jar\n" +#define USAGE_OPTIONS \ + "\n" \ + "Unpacking Options\n" \ + " -H{h}, --deflate-hint={h} override transmitted deflate hint: true, false, or keep (default)\n" \ + " -r, --remove-pack-file remove input file after unpacking\n" \ + " -v, --verbose increase program verbosity\n" \ + " -q, --quiet set verbosity to lowest level\n" \ + " -l{F}, --log-file={F} output to the given log file, or '-' for standard output (default)\n" \ + " -?, -h, --help print this message\n" \ + " -V, --version print program version\n" \ + " -J{X} Java VM argument (ignored)\n" static void usage(unpacker* u, const char* progname, bool full = false) { // WinMain does not set argv[0] to the progrname progname = (progname != null) ? nbasename(progname) : "unpack200"; - for (int i = 0; usage_lines[i] != null; i++) { - fprintf(u->errstrm, usage_lines[i], progname); - if (!full) { - fprintf(u->errstrm, - "(For more information, run %s --help .)\n", progname); - break; - } + + fprintf(u->errstrm, USAGE_HEADER, progname); + if (full) { + fprintf(u->errstrm, USAGE_OPTIONS); + } else { + fprintf(u->errstrm, "(For more information, run %s --help .)\n", progname); } } From 89c87896e2b9c089efbe9219af1f3e2e96a9b798 Mon Sep 17 00:00:00 2001 From: Rob McKenna Date: Fri, 20 Mar 2015 17:07:15 +0000 Subject: [PATCH 090/362] 8075039: (sctp) com/sun/nio/sctp/SctpMultiChannel/SendFailed.java fails on Solaris only Reviewed-by: chegar --- jdk/test/com/sun/nio/sctp/SctpMultiChannel/SendFailed.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jdk/test/com/sun/nio/sctp/SctpMultiChannel/SendFailed.java b/jdk/test/com/sun/nio/sctp/SctpMultiChannel/SendFailed.java index 18f7a4c7815..be50b4efb2f 100644 --- a/jdk/test/com/sun/nio/sctp/SctpMultiChannel/SendFailed.java +++ b/jdk/test/com/sun/nio/sctp/SctpMultiChannel/SendFailed.java @@ -43,11 +43,16 @@ public class SendFailed { void test(String[] args) throws IOException { SocketAddress address = null; + String os = System.getProperty("os.name").toLowerCase(); if (!Util.isSCTPSupported()) { out.println("SCTP protocol is not supported"); out.println("Test cannot be run"); return; + } else if (os.startsWith("sunos")) { + out.println("Test not supported on Solaris"); + out.println("Test cannot be run"); + return; } System.out.println("remote address: " + remoteAddress); From d7419560c26c6d74d59f7c9954b1f6aa5615406e Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Fri, 20 Mar 2015 10:37:03 -0700 Subject: [PATCH 091/362] 8075362: j.u.Properties.load() methods have misaligned @throws clauses Add spaces to align the @throws clauses, and rename Basic.java test and its @summary clause. Reviewed-by: rriggs --- jdk/src/java.base/share/classes/java/util/Properties.java | 4 ++-- .../util/Properties/{Basic.java => LoadAndStoreNPE.java} | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) rename jdk/test/java/util/Properties/{Basic.java => LoadAndStoreNPE.java} (91%) diff --git a/jdk/src/java.base/share/classes/java/util/Properties.java b/jdk/src/java.base/share/classes/java/util/Properties.java index 04397c3f9f2..a075da67d1c 100644 --- a/jdk/src/java.base/share/classes/java/util/Properties.java +++ b/jdk/src/java.base/share/classes/java/util/Properties.java @@ -309,7 +309,7 @@ class Properties extends Hashtable { * input stream. * @throws IllegalArgumentException if a malformed Unicode escape * appears in the input. - * @throws NullPointerException if {@code reader} is null. + * @throws NullPointerException if {@code reader} is null. * @since 1.6 */ public synchronized void load(Reader reader) throws IOException { @@ -335,7 +335,7 @@ class Properties extends Hashtable { * input stream. * @throws IllegalArgumentException if the input stream contains a * malformed Unicode escape sequence. - * @throws NullPointerException if {@code inStream} is null. + * @throws NullPointerException if {@code inStream} is null. * @since 1.2 */ public synchronized void load(InputStream inStream) throws IOException { diff --git a/jdk/test/java/util/Properties/Basic.java b/jdk/test/java/util/Properties/LoadAndStoreNPE.java similarity index 91% rename from jdk/test/java/util/Properties/Basic.java rename to jdk/test/java/util/Properties/LoadAndStoreNPE.java index 7827ed02957..5050139007a 100644 --- a/jdk/test/java/util/Properties/Basic.java +++ b/jdk/test/java/util/Properties/LoadAndStoreNPE.java @@ -28,10 +28,10 @@ import java.util.Properties; /* * @test - * @bug 8073214 - * @summary Basic tests of Properties methods. + * @bug 8073214 8075362 + * @summary Tests to verify that load() and store() throw NPEs as advertised. */ -public class Basic +public class LoadAndStoreNPE { public static void main(String[] args) throws Exception { @@ -68,7 +68,7 @@ public class Basic } if (failures != 0) { - throw new RuntimeException("Basic failed with " + throw new RuntimeException("LoadAndStoreNPE failed with " + failures + " errors!"); } } From f82562e36eba8ba831ee05e09585ae1b08bf7b28 Mon Sep 17 00:00:00 2001 From: Andrew Haley Date: Fri, 20 Mar 2015 17:39:29 +0000 Subject: [PATCH 092/362] 8075443: AARCH64: Missed L2I optimizations in C2 Use iRegIOrL2I for input operands whenever it makes sense. Reviewed-by: kvn --- hotspot/src/cpu/aarch64/vm/aarch64.ad | 146 +++++++++++------------ hotspot/src/cpu/aarch64/vm/aarch64_ad.m4 | 26 ++-- 2 files changed, 87 insertions(+), 85 deletions(-) diff --git a/hotspot/src/cpu/aarch64/vm/aarch64.ad b/hotspot/src/cpu/aarch64/vm/aarch64.ad index 38e8e9ead46..79213415896 100644 --- a/hotspot/src/cpu/aarch64/vm/aarch64.ad +++ b/hotspot/src/cpu/aarch64/vm/aarch64.ad @@ -6056,7 +6056,7 @@ instruct loadD_volatile(vRegD dst, /* sync_memory*/indirect mem) %} // Store Byte -instruct storeB_volatile(iRegI src, /* sync_memory*/indirect mem) +instruct storeB_volatile(iRegIorL2I src, /* sync_memory*/indirect mem) %{ match(Set mem (StoreB mem src)); @@ -6069,7 +6069,7 @@ instruct storeB_volatile(iRegI src, /* sync_memory*/indirect mem) %} // Store Char/Short -instruct storeC_volatile(iRegI src, /* sync_memory*/indirect mem) +instruct storeC_volatile(iRegIorL2I src, /* sync_memory*/indirect mem) %{ match(Set mem (StoreC mem src)); @@ -6225,7 +6225,7 @@ instruct bytes_reverse_short(iRegINoSp dst, iRegIorL2I src) %{ // ============================================================================ // Zero Count Instructions -instruct countLeadingZerosI(iRegINoSp dst, iRegI src) %{ +instruct countLeadingZerosI(iRegINoSp dst, iRegIorL2I src) %{ match(Set dst (CountLeadingZerosI src)); ins_cost(INSN_COST); @@ -6249,7 +6249,7 @@ instruct countLeadingZerosL(iRegINoSp dst, iRegL src) %{ ins_pipe(ialu_reg); %} -instruct countTrailingZerosI(iRegINoSp dst, iRegI src) %{ +instruct countTrailingZerosI(iRegINoSp dst, iRegIorL2I src) %{ match(Set dst (CountTrailingZerosI src)); ins_cost(INSN_COST * 2); @@ -6935,7 +6935,7 @@ instruct cmpL3_reg_imm(iRegINoSp dst, iRegL src1, immLAddSub src2, rFlagsReg fla // which throws a ShouldNotHappen. So, we have to provide two flavours // of each rule, one for a cmpOp and a second for a cmpOpU (sigh). -instruct cmovI_reg_reg(cmpOp cmp, rFlagsReg cr, iRegINoSp dst, iRegI src1, iRegI src2) %{ +instruct cmovI_reg_reg(cmpOp cmp, rFlagsReg cr, iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2) %{ match(Set dst (CMoveI (Binary cmp cr) (Binary src1 src2))); ins_cost(INSN_COST * 2); @@ -6951,7 +6951,7 @@ instruct cmovI_reg_reg(cmpOp cmp, rFlagsReg cr, iRegINoSp dst, iRegI src1, iRegI ins_pipe(icond_reg_reg); %} -instruct cmovUI_reg_reg(cmpOpU cmp, rFlagsRegU cr, iRegINoSp dst, iRegI src1, iRegI src2) %{ +instruct cmovUI_reg_reg(cmpOpU cmp, rFlagsRegU cr, iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2) %{ match(Set dst (CMoveI (Binary cmp cr) (Binary src1 src2))); ins_cost(INSN_COST * 2); @@ -6976,7 +6976,7 @@ instruct cmovUI_reg_reg(cmpOpU cmp, rFlagsRegU cr, iRegINoSp dst, iRegI src1, iR // we ought only to be able to cull one of these variants as the ideal // transforms ought always to order the zero consistently (to left/right?) -instruct cmovI_zero_reg(cmpOp cmp, rFlagsReg cr, iRegINoSp dst, immI0 zero, iRegI src) %{ +instruct cmovI_zero_reg(cmpOp cmp, rFlagsReg cr, iRegINoSp dst, immI0 zero, iRegIorL2I src) %{ match(Set dst (CMoveI (Binary cmp cr) (Binary zero src))); ins_cost(INSN_COST * 2); @@ -6992,7 +6992,7 @@ instruct cmovI_zero_reg(cmpOp cmp, rFlagsReg cr, iRegINoSp dst, immI0 zero, iReg ins_pipe(icond_reg); %} -instruct cmovUI_zero_reg(cmpOpU cmp, rFlagsRegU cr, iRegINoSp dst, immI0 zero, iRegI src) %{ +instruct cmovUI_zero_reg(cmpOpU cmp, rFlagsRegU cr, iRegINoSp dst, immI0 zero, iRegIorL2I src) %{ match(Set dst (CMoveI (Binary cmp cr) (Binary zero src))); ins_cost(INSN_COST * 2); @@ -7008,7 +7008,7 @@ instruct cmovUI_zero_reg(cmpOpU cmp, rFlagsRegU cr, iRegINoSp dst, immI0 zero, i ins_pipe(icond_reg); %} -instruct cmovI_reg_zero(cmpOp cmp, rFlagsReg cr, iRegINoSp dst, iRegI src, immI0 zero) %{ +instruct cmovI_reg_zero(cmpOp cmp, rFlagsReg cr, iRegINoSp dst, iRegIorL2I src, immI0 zero) %{ match(Set dst (CMoveI (Binary cmp cr) (Binary src zero))); ins_cost(INSN_COST * 2); @@ -7024,7 +7024,7 @@ instruct cmovI_reg_zero(cmpOp cmp, rFlagsReg cr, iRegINoSp dst, iRegI src, immI0 ins_pipe(icond_reg); %} -instruct cmovUI_reg_zero(cmpOpU cmp, rFlagsRegU cr, iRegINoSp dst, iRegI src, immI0 zero) %{ +instruct cmovUI_reg_zero(cmpOpU cmp, rFlagsRegU cr, iRegINoSp dst, iRegIorL2I src, immI0 zero) %{ match(Set dst (CMoveI (Binary cmp cr) (Binary src zero))); ins_cost(INSN_COST * 2); @@ -7476,7 +7476,7 @@ instruct addI_reg_reg(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2) %{ ins_pipe(ialu_reg_reg); %} -instruct addI_reg_imm(iRegINoSp dst, iRegI src1, immIAddSub src2) %{ +instruct addI_reg_imm(iRegINoSp dst, iRegIorL2I src1, immIAddSub src2) %{ match(Set dst (AddI src1 src2)); ins_cost(INSN_COST); @@ -7869,7 +7869,7 @@ instruct divI(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2) %{ ins_pipe(idiv_reg_reg); %} -instruct signExtract(iRegINoSp dst, iRegI src1, immI_31 div1, immI_31 div2) %{ +instruct signExtract(iRegINoSp dst, iRegIorL2I src1, immI_31 div1, immI_31 div2) %{ match(Set dst (URShiftI (RShiftI src1 div1) div2)); ins_cost(INSN_COST); format %{ "lsrw $dst, $src1, $div1" %} @@ -7879,7 +7879,7 @@ instruct signExtract(iRegINoSp dst, iRegI src1, immI_31 div1, immI_31 div2) %{ ins_pipe(ialu_reg_shift); %} -instruct div2Round(iRegINoSp dst, iRegI src, immI_31 div1, immI_31 div2) %{ +instruct div2Round(iRegINoSp dst, iRegIorL2I src, immI_31 div1, immI_31 div2) %{ match(Set dst (AddI src (URShiftI (RShiftI src div1) div2))); ins_cost(INSN_COST); format %{ "addw $dst, $src, LSR $div1" %} @@ -8189,7 +8189,7 @@ instruct regL_not_reg(iRegLNoSp dst, ins_pipe(ialu_reg); %} instruct regI_not_reg(iRegINoSp dst, - iRegI src1, immI_M1 m1, + iRegIorL2I src1, immI_M1 m1, rFlagsReg cr) %{ match(Set dst (XorI src1 m1)); ins_cost(INSN_COST); @@ -8206,14 +8206,14 @@ instruct regI_not_reg(iRegINoSp dst, %} instruct AndI_reg_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, immI_M1 m1, + iRegIorL2I src1, iRegIorL2I src2, immI_M1 m1, rFlagsReg cr) %{ match(Set dst (AndI src1 (XorI src2 m1))); ins_cost(INSN_COST); - format %{ "bic $dst, $src1, $src2" %} + format %{ "bicw $dst, $src1, $src2" %} ins_encode %{ - __ bic(as_Register($dst$$reg), + __ bicw(as_Register($dst$$reg), as_Register($src1$$reg), as_Register($src2$$reg), Assembler::LSL, 0); @@ -8240,14 +8240,14 @@ instruct AndL_reg_not_reg(iRegLNoSp dst, %} instruct OrI_reg_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, immI_M1 m1, + iRegIorL2I src1, iRegIorL2I src2, immI_M1 m1, rFlagsReg cr) %{ match(Set dst (OrI src1 (XorI src2 m1))); ins_cost(INSN_COST); - format %{ "orn $dst, $src1, $src2" %} + format %{ "ornw $dst, $src1, $src2" %} ins_encode %{ - __ orn(as_Register($dst$$reg), + __ ornw(as_Register($dst$$reg), as_Register($src1$$reg), as_Register($src2$$reg), Assembler::LSL, 0); @@ -8274,14 +8274,14 @@ instruct OrL_reg_not_reg(iRegLNoSp dst, %} instruct XorI_reg_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, immI_M1 m1, + iRegIorL2I src1, iRegIorL2I src2, immI_M1 m1, rFlagsReg cr) %{ match(Set dst (XorI m1 (XorI src2 src1))); ins_cost(INSN_COST); - format %{ "eon $dst, $src1, $src2" %} + format %{ "eonw $dst, $src1, $src2" %} ins_encode %{ - __ eon(as_Register($dst$$reg), + __ eonw(as_Register($dst$$reg), as_Register($src1$$reg), as_Register($src2$$reg), Assembler::LSL, 0); @@ -8308,7 +8308,7 @@ instruct XorL_reg_not_reg(iRegLNoSp dst, %} instruct AndI_reg_URShift_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, immI_M1 src4, rFlagsReg cr) %{ match(Set dst (AndI src1 (XorI(URShiftI src2 src3) src4))); ins_cost(1.9 * INSN_COST); @@ -8344,7 +8344,7 @@ instruct AndL_reg_URShift_not_reg(iRegLNoSp dst, %} instruct AndI_reg_RShift_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, immI_M1 src4, rFlagsReg cr) %{ match(Set dst (AndI src1 (XorI(RShiftI src2 src3) src4))); ins_cost(1.9 * INSN_COST); @@ -8380,7 +8380,7 @@ instruct AndL_reg_RShift_not_reg(iRegLNoSp dst, %} instruct AndI_reg_LShift_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, immI_M1 src4, rFlagsReg cr) %{ match(Set dst (AndI src1 (XorI(LShiftI src2 src3) src4))); ins_cost(1.9 * INSN_COST); @@ -8416,7 +8416,7 @@ instruct AndL_reg_LShift_not_reg(iRegLNoSp dst, %} instruct XorI_reg_URShift_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, immI_M1 src4, rFlagsReg cr) %{ match(Set dst (XorI src4 (XorI(URShiftI src2 src3) src1))); ins_cost(1.9 * INSN_COST); @@ -8452,7 +8452,7 @@ instruct XorL_reg_URShift_not_reg(iRegLNoSp dst, %} instruct XorI_reg_RShift_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, immI_M1 src4, rFlagsReg cr) %{ match(Set dst (XorI src4 (XorI(RShiftI src2 src3) src1))); ins_cost(1.9 * INSN_COST); @@ -8488,7 +8488,7 @@ instruct XorL_reg_RShift_not_reg(iRegLNoSp dst, %} instruct XorI_reg_LShift_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, immI_M1 src4, rFlagsReg cr) %{ match(Set dst (XorI src4 (XorI(LShiftI src2 src3) src1))); ins_cost(1.9 * INSN_COST); @@ -8524,7 +8524,7 @@ instruct XorL_reg_LShift_not_reg(iRegLNoSp dst, %} instruct OrI_reg_URShift_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, immI_M1 src4, rFlagsReg cr) %{ match(Set dst (OrI src1 (XorI(URShiftI src2 src3) src4))); ins_cost(1.9 * INSN_COST); @@ -8560,7 +8560,7 @@ instruct OrL_reg_URShift_not_reg(iRegLNoSp dst, %} instruct OrI_reg_RShift_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, immI_M1 src4, rFlagsReg cr) %{ match(Set dst (OrI src1 (XorI(RShiftI src2 src3) src4))); ins_cost(1.9 * INSN_COST); @@ -8596,7 +8596,7 @@ instruct OrL_reg_RShift_not_reg(iRegLNoSp dst, %} instruct OrI_reg_LShift_not_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, immI_M1 src4, rFlagsReg cr) %{ match(Set dst (OrI src1 (XorI(LShiftI src2 src3) src4))); ins_cost(1.9 * INSN_COST); @@ -8632,7 +8632,7 @@ instruct OrL_reg_LShift_not_reg(iRegLNoSp dst, %} instruct AndI_reg_URShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (AndI src1 (URShiftI src2 src3))); @@ -8670,7 +8670,7 @@ instruct AndL_reg_URShift_reg(iRegLNoSp dst, %} instruct AndI_reg_RShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (AndI src1 (RShiftI src2 src3))); @@ -8708,7 +8708,7 @@ instruct AndL_reg_RShift_reg(iRegLNoSp dst, %} instruct AndI_reg_LShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (AndI src1 (LShiftI src2 src3))); @@ -8746,7 +8746,7 @@ instruct AndL_reg_LShift_reg(iRegLNoSp dst, %} instruct XorI_reg_URShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (XorI src1 (URShiftI src2 src3))); @@ -8784,7 +8784,7 @@ instruct XorL_reg_URShift_reg(iRegLNoSp dst, %} instruct XorI_reg_RShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (XorI src1 (RShiftI src2 src3))); @@ -8822,7 +8822,7 @@ instruct XorL_reg_RShift_reg(iRegLNoSp dst, %} instruct XorI_reg_LShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (XorI src1 (LShiftI src2 src3))); @@ -8860,7 +8860,7 @@ instruct XorL_reg_LShift_reg(iRegLNoSp dst, %} instruct OrI_reg_URShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (OrI src1 (URShiftI src2 src3))); @@ -8898,7 +8898,7 @@ instruct OrL_reg_URShift_reg(iRegLNoSp dst, %} instruct OrI_reg_RShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (OrI src1 (RShiftI src2 src3))); @@ -8936,7 +8936,7 @@ instruct OrL_reg_RShift_reg(iRegLNoSp dst, %} instruct OrI_reg_LShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (OrI src1 (LShiftI src2 src3))); @@ -8974,7 +8974,7 @@ instruct OrL_reg_LShift_reg(iRegLNoSp dst, %} instruct AddI_reg_URShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (AddI src1 (URShiftI src2 src3))); @@ -9012,7 +9012,7 @@ instruct AddL_reg_URShift_reg(iRegLNoSp dst, %} instruct AddI_reg_RShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (AddI src1 (RShiftI src2 src3))); @@ -9050,7 +9050,7 @@ instruct AddL_reg_RShift_reg(iRegLNoSp dst, %} instruct AddI_reg_LShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (AddI src1 (LShiftI src2 src3))); @@ -9088,7 +9088,7 @@ instruct AddL_reg_LShift_reg(iRegLNoSp dst, %} instruct SubI_reg_URShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (SubI src1 (URShiftI src2 src3))); @@ -9126,7 +9126,7 @@ instruct SubL_reg_URShift_reg(iRegLNoSp dst, %} instruct SubI_reg_RShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (SubI src1 (RShiftI src2 src3))); @@ -9164,7 +9164,7 @@ instruct SubL_reg_RShift_reg(iRegLNoSp dst, %} instruct SubI_reg_LShift_reg(iRegINoSp dst, - iRegI src1, iRegI src2, + iRegIorL2I src1, iRegIorL2I src2, immI src3, rFlagsReg cr) %{ match(Set dst (SubI src1 (LShiftI src2 src3))); @@ -9228,7 +9228,7 @@ instruct sbfmL(iRegLNoSp dst, iRegL src, immI lshift_count, immI rshift_count) // Shift Left followed by Shift Right. // This idiom is used by the compiler for the i2b bytecode etc. -instruct sbfmwI(iRegINoSp dst, iRegI src, immI lshift_count, immI rshift_count) +instruct sbfmwI(iRegINoSp dst, iRegIorL2I src, immI lshift_count, immI rshift_count) %{ match(Set dst (RShiftI (LShiftI src lshift_count) rshift_count)); // Make sure we are not going to exceed what sbfmw can do. @@ -9274,7 +9274,7 @@ instruct ubfmL(iRegLNoSp dst, iRegL src, immI lshift_count, immI rshift_count) // Shift Left followed by Shift Right. // This idiom is used by the compiler for the i2b bytecode etc. -instruct ubfmwI(iRegINoSp dst, iRegI src, immI lshift_count, immI rshift_count) +instruct ubfmwI(iRegINoSp dst, iRegIorL2I src, immI lshift_count, immI rshift_count) %{ match(Set dst (URShiftI (LShiftI src lshift_count) rshift_count)); // Make sure we are not going to exceed what ubfmw can do. @@ -9296,7 +9296,7 @@ instruct ubfmwI(iRegINoSp dst, iRegI src, immI lshift_count, immI rshift_count) %} // Bitfield extract with shift & mask -instruct ubfxwI(iRegINoSp dst, iRegI src, immI rshift, immI_bitmask mask) +instruct ubfxwI(iRegINoSp dst, iRegIorL2I src, immI rshift, immI_bitmask mask) %{ match(Set dst (AndI (URShiftI src rshift) mask)); @@ -9362,7 +9362,7 @@ instruct extrOrL(iRegLNoSp dst, iRegL src1, iRegL src2, immI lshift, immI rshift ins_pipe(ialu_reg_reg_extr); %} -instruct extrOrI(iRegINoSp dst, iRegI src1, iRegI src2, immI lshift, immI rshift, rFlagsReg cr) +instruct extrOrI(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2, immI lshift, immI rshift, rFlagsReg cr) %{ match(Set dst (OrI (LShiftI src1 lshift) (URShiftI src2 rshift))); predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 31)); @@ -9392,7 +9392,7 @@ instruct extrAddL(iRegLNoSp dst, iRegL src1, iRegL src2, immI lshift, immI rshif ins_pipe(ialu_reg_reg_extr); %} -instruct extrAddI(iRegINoSp dst, iRegI src1, iRegI src2, immI lshift, immI rshift, rFlagsReg cr) +instruct extrAddI(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2, immI lshift, immI rshift, rFlagsReg cr) %{ match(Set dst (AddI (LShiftI src1 lshift) (URShiftI src2 rshift))); predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 31)); @@ -9571,7 +9571,7 @@ instruct SubExtI(iRegLNoSp dst, iRegL src1, iRegIorL2I src2, rFlagsReg cr) %}; -instruct AddExtI_sxth(iRegINoSp dst, iRegI src1, iRegI src2, immI_16 lshift, immI_16 rshift, rFlagsReg cr) +instruct AddExtI_sxth(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2, immI_16 lshift, immI_16 rshift, rFlagsReg cr) %{ match(Set dst (AddI src1 (RShiftI (LShiftI src2 lshift) rshift))); ins_cost(INSN_COST); @@ -9584,7 +9584,7 @@ instruct AddExtI_sxth(iRegINoSp dst, iRegI src1, iRegI src2, immI_16 lshift, imm ins_pipe(ialu_reg_reg); %} -instruct AddExtI_sxtb(iRegINoSp dst, iRegI src1, iRegI src2, immI_24 lshift, immI_24 rshift, rFlagsReg cr) +instruct AddExtI_sxtb(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2, immI_24 lshift, immI_24 rshift, rFlagsReg cr) %{ match(Set dst (AddI src1 (RShiftI (LShiftI src2 lshift) rshift))); ins_cost(INSN_COST); @@ -9597,7 +9597,7 @@ instruct AddExtI_sxtb(iRegINoSp dst, iRegI src1, iRegI src2, immI_24 lshift, imm ins_pipe(ialu_reg_reg); %} -instruct AddExtI_uxtb(iRegINoSp dst, iRegI src1, iRegI src2, immI_24 lshift, immI_24 rshift, rFlagsReg cr) +instruct AddExtI_uxtb(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2, immI_24 lshift, immI_24 rshift, rFlagsReg cr) %{ match(Set dst (AddI src1 (URShiftI (LShiftI src2 lshift) rshift))); ins_cost(INSN_COST); @@ -9663,7 +9663,7 @@ instruct AddExtL_uxtb(iRegLNoSp dst, iRegL src1, iRegL src2, immI_56 lshift, imm %} -instruct AddExtI_uxtb_and(iRegINoSp dst, iRegI src1, iRegI src2, immI_255 mask, rFlagsReg cr) +instruct AddExtI_uxtb_and(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2, immI_255 mask, rFlagsReg cr) %{ match(Set dst (AddI src1 (AndI src2 mask))); ins_cost(INSN_COST); @@ -9676,7 +9676,7 @@ instruct AddExtI_uxtb_and(iRegINoSp dst, iRegI src1, iRegI src2, immI_255 mask, ins_pipe(ialu_reg_reg); %} -instruct AddExtI_uxth_and(iRegINoSp dst, iRegI src1, iRegI src2, immI_65535 mask, rFlagsReg cr) +instruct AddExtI_uxth_and(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2, immI_65535 mask, rFlagsReg cr) %{ match(Set dst (AddI src1 (AndI src2 mask))); ins_cost(INSN_COST); @@ -9728,7 +9728,7 @@ instruct AddExtL_uxtw_and(iRegLNoSp dst, iRegL src1, iRegL src2, immL_4294967295 ins_pipe(ialu_reg_reg); %} -instruct SubExtI_uxtb_and(iRegINoSp dst, iRegI src1, iRegI src2, immI_255 mask, rFlagsReg cr) +instruct SubExtI_uxtb_and(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2, immI_255 mask, rFlagsReg cr) %{ match(Set dst (SubI src1 (AndI src2 mask))); ins_cost(INSN_COST); @@ -9741,7 +9741,7 @@ instruct SubExtI_uxtb_and(iRegINoSp dst, iRegI src1, iRegI src2, immI_255 mask, ins_pipe(ialu_reg_reg); %} -instruct SubExtI_uxth_and(iRegINoSp dst, iRegI src1, iRegI src2, immI_65535 mask, rFlagsReg cr) +instruct SubExtI_uxth_and(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2, immI_65535 mask, rFlagsReg cr) %{ match(Set dst (SubI src1 (AndI src2 mask))); ins_cost(INSN_COST); @@ -10343,7 +10343,7 @@ instruct convI2L_reg_reg(iRegLNoSp dst, iRegIorL2I src) %} // this pattern occurs in bigmath arithmetic -instruct convUI2L_reg_reg(iRegLNoSp dst, iRegI src, immL_32bits mask) +instruct convUI2L_reg_reg(iRegLNoSp dst, iRegIorL2I src, immL_32bits mask) %{ match(Set dst (AndL (ConvI2L src) mask)); @@ -10369,7 +10369,7 @@ instruct convL2I_reg(iRegINoSp dst, iRegL src) %{ ins_pipe(ialu_reg); %} -instruct convI2B(iRegINoSp dst, iRegI src, rFlagsReg cr) +instruct convI2B(iRegINoSp dst, iRegIorL2I src, rFlagsReg cr) %{ match(Set dst (Conv2B src)); effect(KILL cr); @@ -10457,7 +10457,7 @@ instruct convF2L_reg_reg(iRegLNoSp dst, vRegF src) %{ ins_pipe(pipe_class_default); %} -instruct convI2F_reg_reg(vRegF dst, iRegI src) %{ +instruct convI2F_reg_reg(vRegF dst, iRegIorL2I src) %{ match(Set dst (ConvI2F src)); ins_cost(INSN_COST * 5); @@ -10509,7 +10509,7 @@ instruct convD2L_reg_reg(iRegLNoSp dst, vRegD src) %{ ins_pipe(pipe_class_default); %} -instruct convI2D_reg_reg(vRegD dst, iRegI src) %{ +instruct convI2D_reg_reg(vRegD dst, iRegIorL2I src) %{ match(Set dst (ConvI2D src)); ins_cost(INSN_COST * 5); @@ -10772,7 +10772,7 @@ instruct clearArray_reg_reg(iRegL_R11 cnt, iRegP_R10 base, Universe dummy, rFlag // ============================================================================ // Overflow Math Instructions -instruct overflowAddI_reg_reg(rFlagsReg cr, iRegI op1, iRegI op2) +instruct overflowAddI_reg_reg(rFlagsReg cr, iRegIorL2I op1, iRegIorL2I op2) %{ match(Set cr (OverflowAddI op1 op2)); @@ -10785,7 +10785,7 @@ instruct overflowAddI_reg_reg(rFlagsReg cr, iRegI op1, iRegI op2) ins_pipe(icmp_reg_reg); %} -instruct overflowAddI_reg_imm(rFlagsReg cr, iRegI op1, immIAddSub op2) +instruct overflowAddI_reg_imm(rFlagsReg cr, iRegIorL2I op1, immIAddSub op2) %{ match(Set cr (OverflowAddI op1 op2)); @@ -10824,7 +10824,7 @@ instruct overflowAddL_reg_imm(rFlagsReg cr, iRegL op1, immLAddSub op2) ins_pipe(icmp_reg_imm); %} -instruct overflowSubI_reg_reg(rFlagsReg cr, iRegI op1, iRegI op2) +instruct overflowSubI_reg_reg(rFlagsReg cr, iRegIorL2I op1, iRegIorL2I op2) %{ match(Set cr (OverflowSubI op1 op2)); @@ -10837,7 +10837,7 @@ instruct overflowSubI_reg_reg(rFlagsReg cr, iRegI op1, iRegI op2) ins_pipe(icmp_reg_reg); %} -instruct overflowSubI_reg_imm(rFlagsReg cr, iRegI op1, immIAddSub op2) +instruct overflowSubI_reg_imm(rFlagsReg cr, iRegIorL2I op1, immIAddSub op2) %{ match(Set cr (OverflowSubI op1 op2)); @@ -10876,7 +10876,7 @@ instruct overflowSubL_reg_imm(rFlagsReg cr, iRegL op1, immLAddSub op2) ins_pipe(icmp_reg_imm); %} -instruct overflowNegI_reg(rFlagsReg cr, immI0 zero, iRegI op1) +instruct overflowNegI_reg(rFlagsReg cr, immI0 zero, iRegIorL2I op1) %{ match(Set cr (OverflowSubI zero op1)); @@ -10902,7 +10902,7 @@ instruct overflowNegL_reg(rFlagsReg cr, immI0 zero, iRegL op1) ins_pipe(icmp_reg_imm); %} -instruct overflowMulI_reg(rFlagsReg cr, iRegI op1, iRegI op2) +instruct overflowMulI_reg(rFlagsReg cr, iRegIorL2I op1, iRegIorL2I op2) %{ match(Set cr (OverflowMulI op1 op2)); @@ -10923,7 +10923,7 @@ instruct overflowMulI_reg(rFlagsReg cr, iRegI op1, iRegI op2) ins_pipe(pipe_slow); %} -instruct overflowMulI_reg_branch(cmpOp cmp, iRegI op1, iRegI op2, label labl, rFlagsReg cr) +instruct overflowMulI_reg_branch(cmpOp cmp, iRegIorL2I op1, iRegIorL2I op2, label labl, rFlagsReg cr) %{ match(If cmp (OverflowMulI op1 op2)); predicate(n->in(1)->as_Bool()->_test._test == BoolTest::overflow @@ -11393,7 +11393,7 @@ instruct compD3_reg_immD0(iRegINoSp dst, vRegD src1, immD0 zero, rFlagsReg cr) %} -instruct cmpLTMask_reg_reg(iRegINoSp dst, iRegI p, iRegI q, rFlagsReg cr) +instruct cmpLTMask_reg_reg(iRegINoSp dst, iRegIorL2I p, iRegIorL2I q, rFlagsReg cr) %{ match(Set dst (CmpLTMask p q)); effect(KILL cr); @@ -11414,7 +11414,7 @@ instruct cmpLTMask_reg_reg(iRegINoSp dst, iRegI p, iRegI q, rFlagsReg cr) ins_pipe(ialu_reg_reg); %} -instruct cmpLTMask_reg_zero(iRegINoSp dst, iRegI src, immI0 zero, rFlagsReg cr) +instruct cmpLTMask_reg_zero(iRegINoSp dst, iRegIorL2I src, immI0 zero, rFlagsReg cr) %{ match(Set dst (CmpLTMask src zero)); effect(KILL cr); @@ -11548,7 +11548,7 @@ instruct branchConU(cmpOpU cmp, rFlagsRegU cr, label lbl) // shorter than (cmp; branch), have the additional benefit of not // killing the flags. -instruct cmpI_imm0_branch(cmpOp cmp, iRegI op1, immI0 op2, label labl, rFlagsReg cr) %{ +instruct cmpI_imm0_branch(cmpOp cmp, iRegIorL2I op1, immI0 op2, label labl, rFlagsReg cr) %{ match(If cmp (CmpI op1 op2)); predicate(n->in(1)->as_Bool()->_test._test == BoolTest::ne || n->in(1)->as_Bool()->_test._test == BoolTest::eq); diff --git a/hotspot/src/cpu/aarch64/vm/aarch64_ad.m4 b/hotspot/src/cpu/aarch64/vm/aarch64_ad.m4 index 1c010187df1..dec068bc371 100644 --- a/hotspot/src/cpu/aarch64/vm/aarch64_ad.m4 +++ b/hotspot/src/cpu/aarch64/vm/aarch64_ad.m4 @@ -24,11 +24,13 @@ dnl Process this file with m4 aarch64_ad.m4 to generate the arithmetic dnl and shift patterns patterns used in aarch64.ad. dnl // BEGIN This section of the file is automatically generated. Do not edit -------------- - +dnl +define(`ORL2I', `ifelse($1,I,orL2I)') +dnl define(`BASE_SHIFT_INSN', ` instruct $2$1_reg_$4_reg(iReg$1NoSp dst, - iReg$1 src1, iReg$1 src2, + iReg$1`'ORL2I($1) src1, iReg$1`'ORL2I($1) src2, immI src3, rFlagsReg cr) %{ match(Set dst ($2$1 src1 ($4$1 src2 src3))); @@ -48,7 +50,7 @@ instruct $2$1_reg_$4_reg(iReg$1NoSp dst, define(`BASE_INVERTED_INSN', ` instruct $2$1_reg_not_reg(iReg$1NoSp dst, - iReg$1 src1, iReg$1 src2, imm$1_M1 m1, + iReg$1`'ORL2I($1) src1, iReg$1`'ORL2I($1) src2, imm$1_M1 m1, rFlagsReg cr) %{ dnl This ifelse is because hotspot reassociates (xor (xor ..)..) dnl into this canonical form. @@ -70,7 +72,7 @@ dnl into this canonical form. define(`INVERTED_SHIFT_INSN', ` instruct $2$1_reg_$4_not_reg(iReg$1NoSp dst, - iReg$1 src1, iReg$1 src2, + iReg$1`'ORL2I($1) src1, iReg$1`'ORL2I($1) src2, immI src3, imm$1_M1 src4, rFlagsReg cr) %{ dnl This ifelse is because hotspot reassociates (xor (xor ..)..) dnl into this canonical form. @@ -92,7 +94,7 @@ dnl into this canonical form. %}')dnl define(`NOT_INSN', `instruct reg$1_not_reg(iReg$1NoSp dst, - iReg$1 src1, imm$1_M1 m1, + iReg$1`'ORL2I($1) src1, imm$1_M1 m1, rFlagsReg cr) %{ match(Set dst (Xor$1 src1 m1)); ins_cost(INSN_COST); @@ -113,7 +115,7 @@ define(`BOTH_SHIFT_INSNS', BASE_SHIFT_INSN(L, $1, $2, $3, $4)')dnl dnl define(`BOTH_INVERTED_INSNS', -`BASE_INVERTED_INSN(I, $1, $2, $3, $4) +`BASE_INVERTED_INSN(I, $1, $2w, $3, $4) BASE_INVERTED_INSN(L, $1, $2, $3, $4)')dnl dnl define(`BOTH_INVERTED_SHIFT_INSNS', @@ -149,7 +151,7 @@ define(`EXTEND', `($2$1 (LShift$1 $3 $4) $5)') define(`BFM_INSN',` // Shift Left followed by Shift Right. // This idiom is used by the compiler for the i2b bytecode etc. -instruct $4$1(iReg$1NoSp dst, iReg$1 src, immI lshift_count, immI rshift_count) +instruct $4$1(iReg$1NoSp dst, iReg$1`'ORL2I($1) src, immI lshift_count, immI rshift_count) %{ match(Set dst EXTEND($1, $3, src, lshift_count, rshift_count)); // Make sure we are not going to exceed what $4 can do. @@ -176,7 +178,7 @@ BFM_INSN(I, 31, URShift, ubfmw) dnl // Bitfield extract with shift & mask define(`BFX_INSN', -`instruct $3$1(iReg$1NoSp dst, iReg$1 src, immI rshift, imm$1_bitmask mask) +`instruct $3$1(iReg$1NoSp dst, iReg$1`'ORL2I($1) src, immI rshift, imm$1_bitmask mask) %{ match(Set dst (And$1 ($2$1 src rshift) mask)); @@ -215,7 +217,7 @@ instruct ubfxIConvI2L(iRegLNoSp dst, iRegIorL2I src, immI rshift, immI_bitmask m // Rotations define(`EXTRACT_INSN', -`instruct extr$3$1(iReg$1NoSp dst, iReg$1 src1, iReg$1 src2, immI lshift, immI rshift, rFlagsReg cr) +`instruct extr$3$1(iReg$1NoSp dst, iReg$1`'ORL2I($1) src1, iReg$1`'ORL2I($1) src2, immI lshift, immI rshift, rFlagsReg cr) %{ match(Set dst ($3$1 (LShift$1 src1 lshift) (URShift$1 src2 rshift))); predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & $2)); @@ -299,7 +301,7 @@ ROR_INSN(I, 0, ror) // Add/subtract (extended) dnl ADD_SUB_EXTENDED(mode, size, add node, shift node, insn, shift type, wordsize define(`ADD_SUB_CONV', ` -instruct $3Ext$1(iReg$2NoSp dst, iReg$2 src1, iReg$1orL2I src2, rFlagsReg cr) +instruct $3Ext$1(iReg$2NoSp dst, iReg$2`'ORL2I($2) src1, iReg$1`'ORL2I($1) src2, rFlagsReg cr) %{ match(Set dst ($3$2 src1 (ConvI2L src2))); ins_cost(INSN_COST); @@ -315,7 +317,7 @@ ADD_SUB_CONV(I,L,Add,add,sxtw); ADD_SUB_CONV(I,L,Sub,sub,sxtw); dnl define(`ADD_SUB_EXTENDED', ` -instruct $3Ext$1_$6(iReg$1NoSp dst, iReg$1 src1, iReg$1 src2, immI_`'eval($7-$2) lshift, immI_`'eval($7-$2) rshift, rFlagsReg cr) +instruct $3Ext$1_$6(iReg$1NoSp dst, iReg$1`'ORL2I($1) src1, iReg$1`'ORL2I($1) src2, immI_`'eval($7-$2) lshift, immI_`'eval($7-$2) rshift, rFlagsReg cr) %{ match(Set dst ($3$1 src1 EXTEND($1, $4, src2, lshift, rshift))); ins_cost(INSN_COST); @@ -337,7 +339,7 @@ ADD_SUB_EXTENDED(L,8,Add,URShift,add,uxtb,64) dnl dnl ADD_SUB_ZERO_EXTEND(mode, size, add node, insn, shift type) define(`ADD_SUB_ZERO_EXTEND', ` -instruct $3Ext$1_$5_and(iReg$1NoSp dst, iReg$1 src1, iReg$1 src2, imm$1_$2 mask, rFlagsReg cr) +instruct $3Ext$1_$5_and(iReg$1NoSp dst, iReg$1`'ORL2I($1) src1, iReg$1`'ORL2I($1) src2, imm$1_$2 mask, rFlagsReg cr) %{ match(Set dst ($3$1 src1 (And$1 src2 mask))); ins_cost(INSN_COST); From 1eb4f850a6a8195862d24f7e23b5e196e8232de4 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Fri, 20 Mar 2015 15:25:07 -0700 Subject: [PATCH 093/362] 8075655: NIO test generation scripts have incorrect path to Spp.java Correct the path to Spp.java Reviewed-by: rriggs --- jdk/test/java/nio/Buffer/genBasic.sh | 4 ++-- jdk/test/java/nio/Buffer/genCopyDirectMemory.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jdk/test/java/nio/Buffer/genBasic.sh b/jdk/test/java/nio/Buffer/genBasic.sh index df271b948cd..1090476807c 100644 --- a/jdk/test/java/nio/Buffer/genBasic.sh +++ b/jdk/test/java/nio/Buffer/genBasic.sh @@ -1,7 +1,7 @@ #! /bin/sh # -# Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2000, 2015, 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 @@ -23,7 +23,7 @@ # questions. # -javac -d . ../../../../make/tools/src/build/tools/spp/Spp.java +javac -d . ../../../../make/src/classes/build/tools/spp/Spp.java gen() { java build.tools.spp.Spp -K$1 -Dtype=$1 -DType=$2 -DFulltype=$3 Basic$2.java diff --git a/jdk/test/java/nio/Buffer/genCopyDirectMemory.sh b/jdk/test/java/nio/Buffer/genCopyDirectMemory.sh index b6c2421b13e..64c51e52904 100644 --- a/jdk/test/java/nio/Buffer/genCopyDirectMemory.sh +++ b/jdk/test/java/nio/Buffer/genCopyDirectMemory.sh @@ -1,7 +1,7 @@ #! /bin/sh # -# Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2002, 2015, 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 @@ -23,7 +23,7 @@ # questions. # -javac -d . ../../../../make/tools/src/build/tools/spp/Spp.java > Spp.java +javac -d . ../../../../make/src/classes/build/tools/spp/Spp.java > Spp.java gen() { java build.tools.spp.Spp -K$1 -Dtype=$1 -DType=$2 -DFulltype=$3CopyDirect$2Memory.java From ed05aef3fc58d9d263272e711fc11de494d6138a Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Sun, 22 Mar 2015 10:27:22 -0700 Subject: [PATCH 094/362] 8075567: Mark intermittently failuring security-libs tests Reviewed-by: mullan --- jdk/test/sun/security/mscapi/ShortRSAKey1024.sh | 1 + jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/jdk/test/sun/security/mscapi/ShortRSAKey1024.sh b/jdk/test/sun/security/mscapi/ShortRSAKey1024.sh index 8c290ebbdec..f7094f210af 100644 --- a/jdk/test/sun/security/mscapi/ShortRSAKey1024.sh +++ b/jdk/test/sun/security/mscapi/ShortRSAKey1024.sh @@ -30,6 +30,7 @@ # @run shell ShortRSAKey1024.sh 1024 # @run shell ShortRSAKey1024.sh 768 # @run shell ShortRSAKey1024.sh 512 +# @key intermittent # set a few environment variables so that the shell-script can run stand-alone # in the source directory diff --git a/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.sh b/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.sh index 961d1e5e3f1..e8c93a75781 100644 --- a/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.sh +++ b/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.sh @@ -28,6 +28,7 @@ # @bug 6578658 # @run shell SignUsingNONEwithRSA.sh # @summary Sign using the NONEwithRSA signature algorithm from SunMSCAPI +# @key intermittent # set a few environment variables so that the shell-script can run stand-alone # in the source directory From 3fbfa7ee8992b150d8cf27c83c0a549c3ec27dc5 Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Mon, 23 Mar 2015 08:51:51 +0800 Subject: [PATCH 095/362] 8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did Reviewed-by: mullan --- .../classes/sun/security/pkcs10/PKCS10.java | 3 +- .../sun/security/provider/X509Factory.java | 4 +- .../sun/security/tools/keytool/Main.java | 13 ++-- .../share/classes/sun/security/util/Pem.java | 52 +++++++++++++ .../sun/security/x509/X509CertImpl.java | 2 +- .../security/provider/X509Factory/BadPem.java | 76 +++++++++++++++++++ .../security/tools/keytool/KeyToolTest.java | 22 ++++++ 7 files changed, 164 insertions(+), 8 deletions(-) create mode 100644 jdk/src/java.base/share/classes/sun/security/util/Pem.java create mode 100644 jdk/test/sun/security/provider/X509Factory/BadPem.java diff --git a/jdk/src/java.base/share/classes/sun/security/pkcs10/PKCS10.java b/jdk/src/java.base/share/classes/sun/security/pkcs10/PKCS10.java index af4e8a4a178..02ed730b9af 100644 --- a/jdk/src/java.base/share/classes/sun/security/pkcs10/PKCS10.java +++ b/jdk/src/java.base/share/classes/sun/security/pkcs10/PKCS10.java @@ -290,8 +290,9 @@ public class PKCS10 { throw new SignatureException("Cert request was not signed"); + byte[] CRLF = new byte[] {'\r', '\n'}; out.println("-----BEGIN NEW CERTIFICATE REQUEST-----"); - out.println(Base64.getMimeEncoder().encodeToString(encoded)); + out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(encoded)); out.println("-----END NEW CERTIFICATE REQUEST-----"); } diff --git a/jdk/src/java.base/share/classes/sun/security/provider/X509Factory.java b/jdk/src/java.base/share/classes/sun/security/provider/X509Factory.java index 46b1a3c8d7d..5fa9416e60d 100644 --- a/jdk/src/java.base/share/classes/sun/security/provider/X509Factory.java +++ b/jdk/src/java.base/share/classes/sun/security/provider/X509Factory.java @@ -28,6 +28,8 @@ package sun.security.provider; import java.io.*; import java.util.*; import java.security.cert.*; + +import sun.security.util.Pem; import sun.security.x509.X509CertImpl; import sun.security.x509.X509CRLImpl; import sun.security.pkcs.PKCS7; @@ -633,7 +635,7 @@ public class X509Factory extends CertificateFactorySpi { checkHeaderFooter(header.toString(), footer.toString()); - return Base64.getMimeDecoder().decode(new String(data, 0, pos)); + return Pem.decode(new String(data, 0, pos)); } } diff --git a/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java b/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java index faf8d58dae0..c1e58b5714f 100644 --- a/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java +++ b/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java @@ -80,6 +80,7 @@ import sun.security.pkcs.PKCS9Attribute; import sun.security.tools.KeyStoreUtil; import sun.security.tools.PathList; import sun.security.util.DerValue; +import sun.security.util.Pem; import sun.security.x509.*; import static java.security.KeyStore.*; @@ -100,6 +101,8 @@ import static sun.security.tools.keytool.Main.Option.*; */ public final class Main { + private static final byte[] CRLF = new byte[] {'\r', '\n'}; + private boolean debug = false; private Command command = null; private String sigAlgName = null; @@ -1266,7 +1269,7 @@ public final class Main { sb.append(s); } } - byte[] rawReq = Base64.getMimeDecoder().decode(new String(sb)); + byte[] rawReq = Pem.decode(new String(sb)); PKCS10 req = new PKCS10(rawReq); info.set(X509CertInfo.KEY, new CertificateX509Key(req.getSubjectPublicKeyInfo())); @@ -1343,7 +1346,7 @@ public final class Main { crl.sign(privateKey, sigAlgName); if (rfc) { out.println("-----BEGIN X509 CRL-----"); - out.println(Base64.getMimeEncoder().encodeToString(crl.getEncodedInternal())); + out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(crl.getEncodedInternal())); out.println("-----END X509 CRL-----"); } else { out.write(crl.getEncodedInternal()); @@ -2304,7 +2307,7 @@ public final class Main { if (rfc) { X509CRL xcrl = (X509CRL)crl; out.println("-----BEGIN X509 CRL-----"); - out.println(Base64.getMimeEncoder().encodeToString(xcrl.getEncoded())); + out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(xcrl.getEncoded())); out.println("-----END X509 CRL-----"); } else { out.println(crl.toString()); @@ -2331,7 +2334,7 @@ public final class Main { sb.append(s); } } - PKCS10 req = new PKCS10(Base64.getMimeDecoder().decode(new String(sb))); + PKCS10 req = new PKCS10(Pem.decode(new String(sb))); PublicKey pkey = req.getSubjectPublicKeyInfo(); out.printf(rb.getString("PKCS.10.Certificate.Request.Version.1.0.Subject.s.Public.Key.s.format.s.key."), @@ -3115,7 +3118,7 @@ public final class Main { { if (rfc) { out.println(X509Factory.BEGIN_CERT); - out.println(Base64.getMimeEncoder().encodeToString(cert.getEncoded())); + out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(cert.getEncoded())); out.println(X509Factory.END_CERT); } else { out.write(cert.getEncoded()); // binary diff --git a/jdk/src/java.base/share/classes/sun/security/util/Pem.java b/jdk/src/java.base/share/classes/sun/security/util/Pem.java new file mode 100644 index 00000000000..7e7a0e6d5fb --- /dev/null +++ b/jdk/src/java.base/share/classes/sun/security/util/Pem.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015, 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 sun.security.util; + +import java.io.IOException; +import java.util.Base64; + +/** + * The Length interface defines the length of an object + */ +public class Pem { + + /** + * Decodes a PEM-encoded block. + * + * @param input the input string, according to RFC 1421, can only contain + * characters in the base-64 alphabet and whitespaces. + * @return the decoded bytes + * @throws java.io.IOException if input is invalid + */ + public static byte[] decode(String input) throws IOException { + byte[] src = input.replaceAll("\\s+", "").getBytes(); + try { + return Base64.getDecoder().decode(src); + } catch (IllegalArgumentException e) { + throw new IOException(e); + } + } +} diff --git a/jdk/src/java.base/share/classes/sun/security/x509/X509CertImpl.java b/jdk/src/java.base/share/classes/sun/security/x509/X509CertImpl.java index aa24360f46f..201e10a6cfe 100644 --- a/jdk/src/java.base/share/classes/sun/security/x509/X509CertImpl.java +++ b/jdk/src/java.base/share/classes/sun/security/x509/X509CertImpl.java @@ -271,7 +271,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder { der = new DerValue(decstream.toByteArray()); break; } else { - decstream.write(Base64.getMimeDecoder().decode(line)); + decstream.write(Pem.decode(line)); } } } catch (IOException ioe2) { diff --git a/jdk/test/sun/security/provider/X509Factory/BadPem.java b/jdk/test/sun/security/provider/X509Factory/BadPem.java new file mode 100644 index 00000000000..9147ab8ce93 --- /dev/null +++ b/jdk/test/sun/security/provider/X509Factory/BadPem.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8074935 + * @summary jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did + */ + +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.security.KeyStore; +import java.security.cert.CertificateException; +import java.util.Arrays; +import java.util.Base64; + +import sun.security.provider.X509Factory; +import java.security.cert.CertificateFactory; +import java.io.ByteArrayInputStream; + +public class BadPem { + + public static void main(String[] args) throws Exception { + String ks = System.getProperty("test.src", ".") + + "/../../../../javax/net/ssl/etc/keystore"; + String pass = "passphrase"; + String alias = "dummy"; + + KeyStore keyStore = KeyStore.getInstance("JKS"); + keyStore.load(new FileInputStream(ks), pass.toCharArray()); + byte[] cert = keyStore.getCertificate(alias).getEncoded(); + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + PrintStream pout = new PrintStream(bout); + byte[] CRLF = new byte[] {'\r', '\n'}; + pout.println(X509Factory.BEGIN_CERT); + for (int i=0; i i + 48) ? 48 : (cert.length - i); + pout.println("!" + Base64.getEncoder() + .encodeToString(Arrays.copyOfRange(cert, i, i + blockLen))); + } + pout.println(X509Factory.END_CERT); + + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + try { + cf.generateCertificate(new ByteArrayInputStream(bout.toByteArray())); + throw new Exception("Should fail"); + } catch (CertificateException e) { + // Good + } + } +} + diff --git a/jdk/test/sun/security/tools/keytool/KeyToolTest.java b/jdk/test/sun/security/tools/keytool/KeyToolTest.java index 74290da1c81..a036db96da0 100644 --- a/jdk/test/sun/security/tools/keytool/KeyToolTest.java +++ b/jdk/test/sun/security/tools/keytool/KeyToolTest.java @@ -56,6 +56,8 @@ * NSS PKCS11 config file are changed, DSA not supported now. */ +import java.nio.file.Files; +import java.nio.file.Paths; import java.security.KeyStore; import sun.security.x509.*; import java.io.*; @@ -1222,6 +1224,24 @@ public class KeyToolTest { remove("mykey.cert"); } + // 8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness + static void checkPem(String file) throws Exception { + boolean maybeLast = false; + for (String s: Files.readAllLines(Paths.get(file))) { + if (s.isEmpty()) continue; + if (s.startsWith("---")) continue; + if (maybeLast) { + throw new Exception("Last line already seen"); + } + if (s.length() > 64) { + throw new Exception(s); + } + if (s.length() < 64) { + maybeLast = true; + } + } + } + void v3extTest(String keyAlg) throws Exception { KeyStore ks; remove("x.jks"); @@ -1588,12 +1608,14 @@ public class KeyToolTest { "-rfc -file test.req"); // printcertreq testOK("", "-printcertreq -file test.req"); + checkPem("test.req"); // issue: deny KU, change criticality of 1.2.3 and 1.2.4, // change content of BC, add 2.3.4 testOK("", simple+"-gencert -alias ca -infile test.req -ext " + "honored=all,-KU,1.2.3:critical,1.2.4:non-critical " + "-ext BC=2 -ext 2.3.4=01020304 " + "-debug -rfc -outfile test.cert"); + checkPem("test.cert"); testOK("", simple+"-importcert -file test.cert -alias a"); ks = loadStore("x.jks", "changeit", "JKS"); X509CertImpl a = (X509CertImpl)ks.getCertificate("a"); From 31a45d5c8602946e6f5b643c10115dc4ea022aca Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Thu, 26 Mar 2015 11:34:50 +0100 Subject: [PATCH 096/362] 8054220: Debugger doesn't show variables *outside* lambda 8058227: Debugger has no access to outer variables inside Lambda Put local variables captured by lambda into the lambda method's LocalVariableTable. Reviewed-by: mcimadamore, rfield --- .../sun/tools/javac/comp/LambdaToMethod.java | 35 +++++-------------- .../classes/com/sun/tools/javac/jvm/Code.java | 6 +++- .../javac/MethodParameters/LambdaTest.out | 2 +- .../javac/lambda/LocalVariableTable.java | 8 ++--- 4 files changed, 18 insertions(+), 33 deletions(-) diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java index 933950c02b8..1b0b7d18ca7 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java @@ -1885,7 +1885,7 @@ public class LambdaToMethod extends TreeTranslator { * Translate a symbol of a given kind into something suitable for the * synthetic lambda body */ - Symbol translate(Name name, final Symbol sym, LambdaSymbolKind skind) { + Symbol translate(final Symbol sym, LambdaSymbolKind skind) { Symbol ret; switch (skind) { case CAPTURED_THIS: @@ -1893,7 +1893,7 @@ public class LambdaToMethod extends TreeTranslator { break; case TYPE_VAR: // Just erase the type var - ret = new VarSymbol(sym.flags(), name, + ret = new VarSymbol(sym.flags(), sym.name, types.erasure(sym.type), sym.owner); /* this information should also be kept for LVT generation at Gen @@ -1902,7 +1902,7 @@ public class LambdaToMethod extends TreeTranslator { ((VarSymbol)ret).pos = ((VarSymbol)sym).pos; break; case CAPTURED_VAR: - ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, name, types.erasure(sym.type), translatedSym) { + ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, sym.name, types.erasure(sym.type), translatedSym) { @Override public Symbol baseSymbol() { //keep mapping with original captured symbol @@ -1911,16 +1911,16 @@ public class LambdaToMethod extends TreeTranslator { }; break; case LOCAL_VAR: - ret = new VarSymbol(sym.flags() & FINAL, name, sym.type, translatedSym); + ret = new VarSymbol(sym.flags() & FINAL, sym.name, sym.type, translatedSym); ((VarSymbol) ret).pos = ((VarSymbol) sym).pos; break; case PARAM: - ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, name, types.erasure(sym.type), translatedSym); + ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, sym.name, types.erasure(sym.type), translatedSym); ((VarSymbol) ret).pos = ((VarSymbol) sym).pos; break; default: - ret = makeSyntheticVar(FINAL, name, types.erasure(sym.type), translatedSym); - ((VarSymbol) ret).pos = ((VarSymbol) sym).pos; + Assert.error(skind.name()); + throw new AssertionError(); } if (ret != sym) { ret.setDeclarationAttributes(sym.getRawAttributes()); @@ -1931,27 +1931,8 @@ public class LambdaToMethod extends TreeTranslator { void addSymbol(Symbol sym, LambdaSymbolKind skind) { Map transMap = getSymbolMap(skind); - Name preferredName; - switch (skind) { - case CAPTURED_THIS: - preferredName = names.fromString("encl$" + transMap.size()); - break; - case CAPTURED_VAR: - preferredName = names.fromString("cap$" + transMap.size()); - break; - case LOCAL_VAR: - preferredName = sym.name; - break; - case PARAM: - preferredName = sym.name; - break; - case TYPE_VAR: - preferredName = sym.name; - break; - default: throw new AssertionError(); - } if (!transMap.containsKey(sym)) { - transMap.put(sym, translate(preferredName, sym, skind)); + transMap.put(sym, translate(sym, skind)); } } diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java index 329deb81353..09459431696 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java @@ -2166,7 +2166,11 @@ public class Code { boolean keepLocalVariables = varDebugInfo || (var.sym.isExceptionParameter() && var.sym.hasTypeAnnotations()); if (!keepLocalVariables) return; - if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return; + //don't keep synthetic vars, unless they are lambda method parameters + boolean ignoredSyntheticVar = (var.sym.flags() & Flags.SYNTHETIC) != 0 && + ((var.sym.owner.flags() & Flags.LAMBDA_METHOD) == 0 || + (var.sym.flags() & Flags.PARAMETER) == 0); + if (ignoredSyntheticVar) return; if (varBuffer == null) varBuffer = new LocalVar[20]; else diff --git a/langtools/test/tools/javac/MethodParameters/LambdaTest.out b/langtools/test/tools/javac/MethodParameters/LambdaTest.out index 2349dd0e0c5..d8367934afd 100644 --- a/langtools/test/tools/javac/MethodParameters/LambdaTest.out +++ b/langtools/test/tools/javac/MethodParameters/LambdaTest.out @@ -2,6 +2,6 @@ class LambdaTest -- LambdaTest.() LambdaTest.foo(i) LambdaTest.lambda$static$1(x1/*synthetic*/)/*synthetic*/ -LambdaTest.lambda$null$0(final cap$0/*synthetic*/, x2/*synthetic*/)/*synthetic*/ +LambdaTest.lambda$null$0(final x1/*synthetic*/, x2/*synthetic*/)/*synthetic*/ static interface LambdaTest$I -- inner LambdaTest$I.m(x) diff --git a/langtools/test/tools/javac/lambda/LocalVariableTable.java b/langtools/test/tools/javac/lambda/LocalVariableTable.java index 8a4d04a061b..b70bc73556a 100644 --- a/langtools/test/tools/javac/lambda/LocalVariableTable.java +++ b/langtools/test/tools/javac/lambda/LocalVariableTable.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8025998 8026749 + * @bug 8025998 8026749 8054220 8058227 * @summary Missing LV table in lambda bodies * @compile -g LocalVariableTable.java * @run main LocalVariableTable @@ -183,7 +183,7 @@ public class LocalVariableTable { Run1 r = (a) -> { int x = a; }; } - @Expect({ "a", "x" }) + @Expect({ "a", "x", "v" }) static class Lambda_Args1_Local1_Captured1 { void m() { int v = 0; @@ -191,7 +191,7 @@ public class LocalVariableTable { } } - @Expect({ "a1", "a2", "x1", "x2", "this" }) + @Expect({ "a1", "a2", "x1", "x2", "this", "v1", "v2" }) static class Lambda_Args2_Local2_Captured2_this { int v; void m() { @@ -204,7 +204,7 @@ public class LocalVariableTable { } } - @Expect({ "e" }) + @Expect({ "e", "c" }) static class Lambda_Try_Catch { private static Runnable asUncheckedRunnable(Closeable c) { return () -> { From ffae4d69552329e6b617bad34545e11963420174 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Thu, 26 Mar 2015 16:17:36 +0100 Subject: [PATCH 097/362] 8076060: Improve make bootstrap process Reviewed-by: erikj --- langtools/make/Makefile | 49 ----------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 langtools/make/Makefile diff --git a/langtools/make/Makefile b/langtools/make/Makefile deleted file mode 100644 index ce3a3333405..00000000000 --- a/langtools/make/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -# Copyright (c) 2012, 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 -# 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. -# - -# Locate this Makefile -ifeq ($(filter /%, $(lastword $(MAKEFILE_LIST))), ) - makefile_path := $(CURDIR)/$(lastword $(MAKEFILE_LIST)) -else - makefile_path := $(lastword $(MAKEFILE_LIST)) -endif -repo_dir := $(patsubst %/make/Makefile, %, $(makefile_path)) - -# What is the name of this subsystem (langtools, corba, etc)? -subsystem_name := $(notdir $(repo_dir)) - -# Try to locate top-level makefile -top_level_makefile := $(repo_dir)/../Makefile -ifneq ($(wildcard $(top_level_makefile)), ) - $(info Will run $(subsystem_name) target on top-level Makefile) - $(info WARNING: This is a non-recommended way of building!) - $(info ===================================================) -else - $(info Cannot locate top-level Makefile. Is this repo not checked out as part of a complete forest?) - $(error Build from top-level Makefile instead) -endif - -all: - @$(MAKE) -f $(top_level_makefile) $(subsystem_name) From 38527cecd5014425e823f86a80350211992d6fb7 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Fri, 27 Mar 2015 10:11:21 -0700 Subject: [PATCH 098/362] 8075184: javac is mistakenly considering an missing enclosing instance error as an overload error Reviewed-by: mcimadamore --- .../com/sun/tools/javac/code/Kinds.java | 30 +++++++++------- .../com/sun/tools/javac/comp/Attr.java | 7 ++-- .../sun/tools/javac/comp/DeferredAttr.java | 4 +-- .../com/sun/tools/javac/comp/Resolve.java | 36 +++++++++---------- .../examples/CantAccessInnerClsConstr.java | 5 ++- .../tools/javac/lambda/MethodReference23.java | 2 +- .../tools/javac/lambda/MethodReference23.out | 8 ++--- 7 files changed, 49 insertions(+), 43 deletions(-) diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java index c29549a221b..263d0c50bd9 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -66,22 +66,22 @@ public class Kinds { MTH(Category.BASIC, KindName.METHOD, KindSelector.MTH), POLY(Category.BASIC, KindSelector.POLY), ERR(Category.ERROR, KindSelector.ERR), - AMBIGUOUS(Category.OVERLOAD), - HIDDEN(Category.OVERLOAD), - STATICERR(Category.OVERLOAD), - MISSING_ENCL(Category.OVERLOAD), - ABSENT_VAR(Category.OVERLOAD, KindName.VAR), - WRONG_MTHS(Category.OVERLOAD, KindName.METHOD), - WRONG_MTH(Category.OVERLOAD, KindName.METHOD), - ABSENT_MTH(Category.OVERLOAD, KindName.METHOD), - ABSENT_TYP(Category.OVERLOAD, KindName.CLASS); + AMBIGUOUS(Category.RESOLUTION_TARGET), // overloaded target + HIDDEN(Category.RESOLUTION_TARGET), // not overloaded non-target + STATICERR(Category.RESOLUTION_TARGET), // overloaded? target + MISSING_ENCL(Category.RESOLUTION), // not overloaded non-target + ABSENT_VAR(Category.RESOLUTION_TARGET, KindName.VAR), // not overloaded non-target + WRONG_MTHS(Category.RESOLUTION_TARGET, KindName.METHOD), // overloaded target + WRONG_MTH(Category.RESOLUTION_TARGET, KindName.METHOD), // not overloaded target + ABSENT_MTH(Category.RESOLUTION_TARGET, KindName.METHOD), // not overloaded non-target + ABSENT_TYP(Category.RESOLUTION_TARGET, KindName.CLASS); // not overloaded non-target // There are essentially two "levels" to the Kind datatype. // The first is a totally-ordered set of categories of // solutions. Within each category, we have more // possibilities. private enum Category { - BASIC, ERROR, OVERLOAD; + BASIC, ERROR, RESOLUTION, RESOLUTION_TARGET; } private final KindName kindName; @@ -127,8 +127,12 @@ public class Kinds { return selector.contains(kindSelectors); } - public boolean isOverloadError() { - return category == Category.OVERLOAD; + public boolean isResolutionError() { + return category == Category.RESOLUTION || category == Category.RESOLUTION_TARGET; + } + + public boolean isResolutionTargetError() { + return category == Category.RESOLUTION_TARGET; } public boolean isValid() { diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index c3b467de0e5..4c9b083ef06 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -2109,7 +2109,7 @@ public class Attr extends JCTree.Visitor { clazztype = cdef.sym.type; Symbol sym = tree.constructor = rs.resolveConstructor( tree.pos(), localEnv, clazztype, argtypes, typeargtypes); - Assert.check(!sym.kind.isOverloadError()); + Assert.check(!sym.kind.isResolutionError()); tree.constructor = sym; tree.constructorType = checkId(noCheckTree, clazztype, @@ -2647,17 +2647,20 @@ public class Attr extends JCTree.Visitor { Symbol refSym = refResult.fst; Resolve.ReferenceLookupHelper lookupHelper = refResult.snd; + /** this switch will need to go away and be replaced by the new RESOLUTION_TARGET testing + * JDK-8075541 + */ if (refSym.kind != MTH) { boolean targetError; switch (refSym.kind) { case ABSENT_MTH: + case MISSING_ENCL: targetError = false; break; case WRONG_MTH: case WRONG_MTHS: case AMBIGUOUS: case HIDDEN: - case MISSING_ENCL: case STATICERR: targetError = true; break; diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java index 8a7156155fd..5432166b48f 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java @@ -1209,8 +1209,8 @@ public class DeferredAttr extends JCTree.Visitor { rs.getMemberReference(tree, localEnv, mref2, exprTree.type, tree.name); tree.sym = res; - if (res.kind.isOverloadError() || - res.type.hasTag(FORALL) || + if (res.kind.isResolutionTargetError() || + res.type != null && res.type.hasTag(FORALL) || (res.flags() & Flags.VARARGS) != 0 || (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) && exprTree.type.isRaw())) { diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java index 5e1fb9e8040..258999e8afb 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -194,7 +194,7 @@ public class Resolve { void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site, List argtypes, List typeargtypes, Symbol bestSoFar) { - boolean success = !bestSoFar.kind.isOverloadError(); + boolean success = !bestSoFar.kind.isResolutionError(); if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) { return; @@ -1389,7 +1389,7 @@ public class Resolve { if (currentSymbol.kind != VAR) continue; // invariant: sym.kind == Symbol.Kind.VAR - if (!bestSoFar.kind.isOverloadError() && + if (!bestSoFar.kind.isResolutionError() && currentSymbol.owner != bestSoFar.owner) return new AmbiguityError(bestSoFar, currentSymbol); else if (!bestSoFar.kind.betterThan(VAR)) { @@ -1432,11 +1432,11 @@ public class Resolve { !sym.isInheritedIn(site.tsym, types)) { return bestSoFar; } else if (useVarargs && (sym.flags() & VARARGS) == 0) { - return bestSoFar.kind.isOverloadError() ? + return bestSoFar.kind.isResolutionError() ? new BadVarargsMethod((ResolveError)bestSoFar.baseSymbol()) : bestSoFar; } - Assert.check(!sym.kind.isOverloadError()); + Assert.check(!sym.kind.isResolutionError()); try { Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, allowBoxing, useVarargs, types.noWarnings); @@ -1457,7 +1457,7 @@ public class Resolve { ? new AccessError(env, site, sym) : bestSoFar; } - return (bestSoFar.kind.isOverloadError() && bestSoFar.kind != AMBIGUOUS) + return (bestSoFar.kind.isResolutionError() && bestSoFar.kind != AMBIGUOUS) ? sym : mostSpecific(argtypes, sym, bestSoFar, env, site, useVarargs); } @@ -1939,8 +1939,8 @@ public class Resolve { bestSoFar.kind != AMBIGUOUS && l.nonEmpty(); l = l.tail) { sym = findMemberType(env, site, name, l.head.tsym); - if (!bestSoFar.kind.isOverloadError() && - !sym.kind.isOverloadError() && + if (!bestSoFar.kind.isResolutionError() && + !sym.kind.isResolutionError() && sym.owner != bestSoFar.owner) bestSoFar = new AmbiguityError(bestSoFar, sym); else @@ -2176,7 +2176,7 @@ public class Resolve { List argtypes, List typeargtypes, LogResolveHelper logResolveHelper) { - if (sym.kind.isOverloadError()) { + if (sym.kind.isResolutionError()) { ResolveError errSym = (ResolveError)sym.baseSymbol(); sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); argtypes = logResolveHelper.getArgumentTypes(errSym, sym, name, argtypes); @@ -2366,7 +2366,7 @@ public class Resolve { } @Override Symbol access(Env env, DiagnosticPosition pos, Symbol location, Symbol sym) { - if (sym.kind.isOverloadError()) { + if (sym.kind.isResolutionError()) { sym = super.access(env, pos, location, sym); } else if (allowMethodHandles) { MethodSymbol msym = (MethodSymbol)sym; @@ -2523,7 +2523,7 @@ public class Resolve { } @Override Symbol access(Env env, DiagnosticPosition pos, Symbol location, Symbol sym) { - if (sym.kind.isOverloadError()) { + if (sym.kind.isResolutionError()) { if (sym.kind != WRONG_MTH && sym.kind != WRONG_MTHS) { sym = super.access(env, pos, location, sym); @@ -2933,7 +2933,7 @@ public class Resolve { */ final boolean shouldStop(Symbol sym, MethodResolutionPhase phase) { return phase.ordinal() > maxPhase.ordinal() || - !sym.kind.isOverloadError() || sym.kind == AMBIGUOUS; + !sym.kind.isResolutionError() || sym.kind == AMBIGUOUS; } /** @@ -2979,7 +2979,7 @@ public class Resolve { @Override Symbol access(Env env, DiagnosticPosition pos, Symbol location, Symbol sym) { - if (sym.kind.isOverloadError()) { + if (sym.kind.isResolutionError()) { //if nothing is found return the 'first' error sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes); } @@ -3321,7 +3321,7 @@ public class Resolve { boolean hasEnclosingInstance(Env env, Type type) { Symbol encl = resolveSelfContainingInternal(env, type.tsym, false); - return encl != null && !encl.kind.isOverloadError(); + return encl != null && !encl.kind.isResolutionError(); } private Symbol resolveSelfContainingInternal(Env env, @@ -3503,7 +3503,7 @@ public class Resolve { @Override public Symbol access(Name name, TypeSymbol location) { - if (!sym.kind.isOverloadError() && sym.kind.matches(KindSelector.TYP)) + if (!sym.kind.isResolutionError() && sym.kind.matches(KindSelector.TYP)) return types.createErrorType(name, location, sym.type).tsym; else return sym; @@ -4053,7 +4053,7 @@ public class Resolve { } else { key = "bad.instance.method.in.unbound.lookup"; } - return sym.kind.isOverloadError() ? + return sym.kind.isResolutionError() ? ((ResolveError)sym).getDiagnostic(dkind, pos, location, site, name, argtypes, typeargtypes) : diags.create(dkind, log.currentSource(), pos, key, Kinds.kindName(sym), sym); } @@ -4232,8 +4232,8 @@ public class Resolve { @Override public Symbol mergeResults(Symbol bestSoFar, Symbol sym) { //Check invariants (see {@code LookupHelper.shouldStop}) - Assert.check(bestSoFar.kind.isOverloadError() && bestSoFar.kind != AMBIGUOUS); - if (!sym.kind.isOverloadError()) { + Assert.check(bestSoFar.kind.isResolutionError() && bestSoFar.kind != AMBIGUOUS); + if (!sym.kind.isResolutionError()) { //varargs resolution successful return sym; } else { diff --git a/langtools/test/tools/javac/diags/examples/CantAccessInnerClsConstr.java b/langtools/test/tools/javac/diags/examples/CantAccessInnerClsConstr.java index ce4f3238abd..112862cd2ef 100644 --- a/langtools/test/tools/javac/diags/examples/CantAccessInnerClsConstr.java +++ b/langtools/test/tools/javac/diags/examples/CantAccessInnerClsConstr.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -21,9 +21,8 @@ * questions. */ -// key: compiler.err.prob.found.req // key: compiler.misc.cant.access.inner.cls.constr -// key: compiler.misc.invalid.mref +// key: compiler.err.invalid.mref class CantAccessInnerClsConstructor { diff --git a/langtools/test/tools/javac/lambda/MethodReference23.java b/langtools/test/tools/javac/lambda/MethodReference23.java index b7610389a02..2ac0e04b3ee 100644 --- a/langtools/test/tools/javac/lambda/MethodReference23.java +++ b/langtools/test/tools/javac/lambda/MethodReference23.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 8003280 + * @bug 8003280 8075184 * @summary Add lambda tests * check that pair of bound/non-bound constructor references is flagged as ambiguous * @author Maurizio Cimadamore diff --git a/langtools/test/tools/javac/lambda/MethodReference23.out b/langtools/test/tools/javac/lambda/MethodReference23.out index 462a75105ff..456a002bd99 100644 --- a/langtools/test/tools/javac/lambda/MethodReference23.out +++ b/langtools/test/tools/javac/lambda/MethodReference23.out @@ -1,6 +1,6 @@ -MethodReference23.java:52:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23)) -MethodReference23.java:53:15: compiler.err.cant.apply.symbol: kindname.method, call11, MethodReference23.SAM11, @1140, kindname.class, MethodReference23, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23))) -MethodReference23.java:57:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23)) -MethodReference23.java:58:15: compiler.err.cant.apply.symbol: kindname.method, call12, MethodReference23.SAM12, @1282, kindname.class, MethodReference23, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23))) +MethodReference23.java:52:19: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23) +MethodReference23.java:53:16: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23) +MethodReference23.java:57:19: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23) +MethodReference23.java:58:16: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23) MethodReference23.java:72:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference23.SAM21), MethodReference23, kindname.method, call3(MethodReference23.SAM22), MethodReference23 5 errors From 8b611ba470ae21d66344edd454f2dbe61762ff23 Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Sat, 28 Mar 2015 10:18:27 -0700 Subject: [PATCH 099/362] 8076026: DocTree should parse hyphenated attributes correctly Reviewed-by: jjg, ksrini --- .../tools/javac/parser/DocCommentParser.java | 12 ++++++-- .../test/tools/javac/doctree/AttrTest.java | 28 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java index 17409cca180..1dee684f910 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -797,7 +797,7 @@ public class DocCommentParser { loop: while (isIdentifierStart(ch)) { int namePos = bp; - Name name = readIdentifier(); + Name name = readAttributeName(); skipWhitespace(); List value = null; ValueKind vkind = ValueKind.EMPTY; @@ -905,6 +905,14 @@ public class DocCommentParser { return names.fromChars(buf, start, bp - start); } + protected Name readAttributeName() { + int start = bp; + nextChar(); + while (bp < buflen && (Character.isUnicodeIdentifierPart(ch) || ch == '-')) + nextChar(); + return names.fromChars(buf, start, bp - start); + } + protected Name readTagName() { int start = bp; nextChar(); diff --git a/langtools/test/tools/javac/doctree/AttrTest.java b/langtools/test/tools/javac/doctree/AttrTest.java index 2e13a16059a..9eace1357b7 100644 --- a/langtools/test/tools/javac/doctree/AttrTest.java +++ b/langtools/test/tools/javac/doctree/AttrTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8076026 * @summary extend com.sun.source API to support parsing javadoc comments * @build DocCommentTester * @run main DocCommentTester AttrTest.java @@ -52,6 +52,30 @@ DocComment[DOC_COMMENT, pos:1 body: empty block tags: empty ] +*/ + + /** + * foo + */ + void hyphened_attr() { } +/* +DocComment[DOC_COMMENT, pos:1 + firstSentence: 3 + StartElement[START_ELEMENT, pos:1 + name:a + attributes: 1 + Attribute[ATTRIBUTE, pos:4 + name: name-test + vkind: UNQUOTED + value: 1 + Text[TEXT, pos:14, hyphened] + ] + ] + Text[TEXT, pos:23, foo] + EndElement[END_ELEMENT, pos:26, a] + body: empty + block tags: empty +] */ /** From 8afd89977c59c2bfb98f4e47e588fc096a0b3435 Mon Sep 17 00:00:00 2001 From: Srikanth Adayapalam Date: Mon, 30 Mar 2015 17:09:14 +0530 Subject: [PATCH 100/362] 8062373: Project Coin: diamond and anonymous classes Allow diamond inference in combination with anonymous class instance creation Co-authored-by: Maurizio Cimadamore Reviewed-by: mcimadamore, vromero --- .../com/sun/tools/javac/code/Source.java | 3 + .../com/sun/tools/javac/comp/Analyzer.java | 6 +- .../com/sun/tools/javac/comp/Attr.java | 241 ++++++++++++------ .../com/sun/tools/javac/comp/AttrContext.java | 8 +- .../com/sun/tools/javac/comp/Check.java | 77 +++++- .../sun/tools/javac/comp/DeferredAttr.java | 34 ++- .../com/sun/tools/javac/comp/Enter.java | 3 +- .../com/sun/tools/javac/comp/Resolve.java | 3 +- .../tools/javac/resources/compiler.properties | 19 +- .../com/sun/tools/javac/tree/TreeInfo.java | 14 +- .../InnerClassesInAnonymousClassTest.java | 6 +- .../diags/examples/DiamondAndAnonClass.java | 6 +- .../examples/DiamondAndNonDenotableTypes.java | 42 +++ .../javac/failover/CheckAttributedTree.java | 8 +- .../generics/diamond/6939780/T6939780.java | 7 +- .../generics/diamond/6939780/T6939780_7.out | 8 +- .../generics/diamond/6939780/T6939780_8.out | 10 +- .../generics/diamond/6939780/T6939780_9.out | 13 + .../generics/diamond/6996914/T6996914a.java | 36 ++- .../generics/diamond/6996914/T6996914b.java | 5 +- .../generics/diamond/8065986/T8065986b.java | 9 +- .../generics/diamond/8065986/T8065986b.out | 12 +- .../diamond/MultipleInferenceHooksTest.java | 38 +++ .../javac/generics/diamond/neg/Neg01.java | 13 +- .../javac/generics/diamond/neg/Neg01.out | 16 +- .../javac/generics/diamond/neg/Neg02.java | 22 +- .../javac/generics/diamond/neg/Neg02.out | 58 +++-- .../javac/generics/diamond/neg/Neg03.java | 32 ++- .../javac/generics/diamond/neg/Neg03.out | 100 +++++--- .../javac/generics/diamond/neg/Neg04.java | 12 +- .../javac/generics/diamond/neg/Neg04.out | 16 +- .../javac/generics/diamond/neg/Neg05.java | 22 +- .../javac/generics/diamond/neg/Neg05.out | 66 +++-- .../javac/generics/diamond/neg/Neg06.java | 6 +- .../javac/generics/diamond/neg/Neg06.out | 8 +- .../javac/generics/diamond/neg/Neg07.java | 3 +- .../javac/generics/diamond/neg/Neg07.out | 3 +- .../javac/generics/diamond/neg/Neg09.java | 6 +- .../javac/generics/diamond/neg/Neg09.out | 10 +- .../javac/generics/diamond/neg/Neg12.java | 33 +++ .../javac/generics/diamond/neg/Neg12.out | 4 + .../javac/generics/diamond/neg/Neg13.java | 49 ++++ .../javac/generics/diamond/neg/Neg13.out | 5 + .../javac/generics/diamond/neg/Neg14.java | 49 ++++ .../javac/generics/diamond/neg/Neg14.out | 5 + .../javac/generics/diamond/neg/Neg15.java | 66 +++++ .../javac/generics/diamond/neg/Neg15.out | 4 + .../javac/generics/diamond/neg/Neg16.java | 36 +++ .../javac/generics/diamond/neg/Neg16.out | 2 + .../javac/generics/diamond/neg/Neg17.java | 21 ++ .../javac/generics/diamond/neg/Neg17.out | 2 + .../javac/generics/diamond/neg/Neg18.java | 16 ++ .../javac/generics/diamond/neg/Neg18.out | 3 + .../javac/generics/diamond/neg/Neg19.java | 21 ++ .../javac/generics/diamond/neg/Neg19.out | 2 + .../generics/diamond/neg/pkg/Neg18_01.java | 29 +++ .../javac/generics/diamond/pos/Pos01.java | 16 +- .../javac/generics/diamond/pos/Pos02.java | 24 +- .../javac/generics/diamond/pos/Pos03.java | 34 ++- .../javac/generics/diamond/pos/Pos04.java | 14 +- .../javac/generics/diamond/pos/Pos05.java | 11 +- .../generics/inference/8055963/T8055963.java | 11 +- .../tools/javac/lambda/8066974/T8066974.java | 4 +- .../tools/javac/lambda/8066974/T8066974.out | 7 +- .../test/tools/javac/lambda/TargetType46.java | 3 +- .../test/tools/javac/lambda/TargetType46.out | 3 +- .../test/tools/javac/lambda/TargetType68.java | 8 +- .../test/tools/javac/lambda/TargetType68.out | 3 + .../test/tools/javac/lambda/TargetType69.java | 5 +- .../org/openjdk/tests/javac/FDTest.java | 5 +- .../tools/javac/scope/DupUnsharedTest.java | 6 +- 71 files changed, 1257 insertions(+), 245 deletions(-) create mode 100644 langtools/test/tools/javac/diags/examples/DiamondAndNonDenotableTypes.java create mode 100644 langtools/test/tools/javac/generics/diamond/6939780/T6939780_9.out create mode 100644 langtools/test/tools/javac/generics/diamond/MultipleInferenceHooksTest.java create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg12.java create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg12.out create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg13.java create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg13.out create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg14.java create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg14.out create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg15.java create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg15.out create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg16.java create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg16.out create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg17.java create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg17.out create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg18.java create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg18.out create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg19.java create mode 100644 langtools/test/tools/javac/generics/diamond/neg/Neg19.out create mode 100644 langtools/test/tools/javac/generics/diamond/neg/pkg/Neg18_01.java create mode 100644 langtools/test/tools/javac/lambda/TargetType68.out diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java index 5f2dd39c32a..687012387de 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java @@ -209,6 +209,9 @@ public enum Source { public boolean allowPrivateSafeVarargs() { return compareTo(JDK1_9) >= 0; } + public boolean allowDiamondWithAnonymousClassCreation() { + return compareTo(JDK1_9) >= 0; + } public boolean allowUnderscoreIdentifier() { return compareTo(JDK1_8) <= 0; } diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java index 1eb1ab48808..f5975776fa2 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -90,6 +90,7 @@ public class Analyzer { final DeferredAttr deferredAttr; final TreeMaker make; final Names names; + private final boolean allowDiamondWithAnonymousClassCreation; final EnumSet analyzerModes; @@ -112,6 +113,7 @@ public class Analyzer { String findOpt = options.get("find"); //parse modes Source source = Source.instance(context); + allowDiamondWithAnonymousClassCreation = source.allowDiamondWithAnonymousClassCreation(); analyzerModes = AnalyzerMode.getAnalyzerModes(findOpt, source); } @@ -210,7 +212,7 @@ public class Analyzer { boolean match(JCNewClass tree) { return tree.clazz.hasTag(TYPEAPPLY) && !TreeInfo.isDiamond(tree) && - tree.def == null; + (tree.def == null || allowDiamondWithAnonymousClassCreation); } @Override diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index 4c9b083ef06..36a9c6bc9ce 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -46,6 +46,10 @@ import com.sun.tools.javac.comp.DeferredAttr.AttrMode; import com.sun.tools.javac.comp.Infer.InferenceContext; import com.sun.tools.javac.comp.Infer.FreeTypeListener; import com.sun.tools.javac.jvm.*; +import static com.sun.tools.javac.resources.CompilerProperties.Fragments.Diamond; +import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArg; +import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArgs; +import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Fragments; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; @@ -54,6 +58,7 @@ import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.DefinedBy.Api; import com.sun.tools.javac.util.Dependencies.AttributionKind; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; +import com.sun.tools.javac.util.JCDiagnostic.Fragment; import com.sun.tools.javac.util.List; import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.ANNOTATION; @@ -219,6 +224,26 @@ public class Attr extends JCTree.Visitor { final Type found, final KindSelector ownkind, final ResultInfo resultInfo) { + return check(tree, found, ownkind, resultInfo, true); + } + /** Check kind and type of given tree against protokind and prototype. + * If check succeeds, store type in tree and return it. + * If check fails, store errType in tree and return it. + * No checks are performed if the prototype is a method type. + * It is not necessary in this case since we know that kind and type + * are correct. + * + * @param tree The tree whose kind and type is checked + * @param found The computed type of the tree + * @param ownkind The computed kind of the tree + * @param resultInfo The expected result of the tree + * @param recheckPostInference If true and inference is underway, arrange to recheck the tree after inference finishes. + */ + Type check(final JCTree tree, + final Type found, + final KindSelector ownkind, + final ResultInfo resultInfo, + boolean recheckPostInference) { InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); Type owntype; boolean shouldCheck = !found.hasTag(ERROR) && @@ -233,12 +258,14 @@ public class Attr extends JCTree.Visitor { //delay the check if there are inference variables in the found type //this means we are dealing with a partially inferred poly expression owntype = shouldCheck ? resultInfo.pt : found; - inferenceContext.addFreeTypeListener(List.of(found, resultInfo.pt), - instantiatedContext -> { - ResultInfo pendingResult = - resultInfo.dup(inferenceContext.asInstType(resultInfo.pt)); - check(tree, inferenceContext.asInstType(found), ownkind, pendingResult); - }); + if (recheckPostInference) { + inferenceContext.addFreeTypeListener(List.of(found, resultInfo.pt), + instantiatedContext -> { + ResultInfo pendingResult = + resultInfo.dup(inferenceContext.asInstType(resultInfo.pt)); + check(tree, inferenceContext.asInstType(found), ownkind, pendingResult, false); + }); + } } else { owntype = shouldCheck ? resultInfo.check(tree, found) : @@ -862,7 +889,7 @@ public class Attr extends JCTree.Visitor { } else { chk.checkOverrideClashes(tree.pos(), env.enclClass.type, m); } - chk.checkOverride(tree, m); + chk.checkOverride(env, tree, m); if (isDefaultMethod && types.overridesObjectMethod(m.enclClass(), m)) { log.error(tree, "default.overrides.object.member", m.name, Kinds.kindName(m.location()), m.location()); @@ -1969,11 +1996,16 @@ public class Attr extends JCTree.Visitor { (((JCVariableDecl) env.tree).mods.flags & Flags.ENUM) == 0 || ((JCVariableDecl) env.tree).init != tree)) log.error(tree.pos(), "enum.cant.be.instantiated"); + + boolean isSpeculativeDiamondInferenceRound = TreeInfo.isDiamond(tree) && + resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; + boolean skipNonDiamondPath = false; // Check that class is not abstract - if (cdef == null && + if (cdef == null && !isSpeculativeDiamondInferenceRound && // class body may be nulled out in speculative tree copy (clazztype.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { log.error(tree.pos(), "abstract.cant.be.instantiated", clazztype.tsym); + skipNonDiamondPath = true; } else if (cdef != null && clazztype.tsym.isInterface()) { // Check that no constructor arguments are given to // anonymous classes implementing an interface @@ -1986,7 +2018,9 @@ public class Attr extends JCTree.Visitor { // Error recovery: pretend no arguments were supplied. argtypes = List.nil(); typeargtypes = List.nil(); - } else if (TreeInfo.isDiamond(tree)) { + skipNonDiamondPath = true; + } + if (TreeInfo.isDiamond(tree)) { ClassType site = new ClassType(clazztype.getEnclosingType(), clazztype.tsym.type.getTypeArguments(), clazztype.tsym, @@ -2022,7 +2056,7 @@ public class Attr extends JCTree.Visitor { tree.clazz.type = types.createErrorType(clazztype); if (!constructorType.isErroneous()) { - tree.clazz.type = clazztype = constructorType.getReturnType(); + tree.clazz.type = clazz.type = constructorType.getReturnType(); tree.constructorType = types.createMethodTypeWithReturn(constructorType, syms.voidType); } clazztype = chk.checkClassType(tree.clazz, tree.clazz.type, true); @@ -2031,7 +2065,7 @@ public class Attr extends JCTree.Visitor { // Resolve the called constructor under the assumption // that we are referring to a superclass instance of the // current instance (JLS ???). - else { + else if (!skipNonDiamondPath) { //the following code alters some of the fields in the current //AttrContext - hence, the current context must be dup'ed in //order to avoid downstream failures @@ -2052,70 +2086,8 @@ public class Attr extends JCTree.Visitor { } if (cdef != null) { - // We are seeing an anonymous class instance creation. - // In this case, the class instance creation - // expression - // - // E.new C(args) { ... } - // - // is represented internally as - // - // E . new C(args) ( class { ... } ) . - // - // This expression is then *transformed* as follows: - // - // (1) add an extends or implements clause - // (2) add a constructor. - // - // For instance, if C is a class, and ET is the type of E, - // the expression - // - // E.new C(args) { ... } - // - // is translated to (where X is a fresh name and typarams is the - // parameter list of the super constructor): - // - // new X(<*nullchk*>E, args) where - // X extends C { - // X(ET e, args) { - // e.super(args) - // } - // ... - // } - - if (clazztype.tsym.isInterface()) { - cdef.implementing = List.of(clazz); - } else { - cdef.extending = clazz; - } - - if (resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK && - isSerializable(clazztype)) { - localEnv.info.isSerializable = true; - } - - attribStat(cdef, localEnv); - - // If an outer instance is given, - // prefix it to the constructor arguments - // and delete it from the new expression - if (tree.encl != null && !clazztype.tsym.isInterface()) { - tree.args = tree.args.prepend(makeNullCheck(tree.encl)); - argtypes = argtypes.prepend(tree.encl.type); - tree.encl = null; - } - - // Reassign clazztype and recompute constructor. - clazztype = cdef.sym.type; - Symbol sym = tree.constructor = rs.resolveConstructor( - tree.pos(), localEnv, clazztype, argtypes, typeargtypes); - Assert.check(!sym.kind.isResolutionError()); - tree.constructor = sym; - tree.constructorType = checkId(noCheckTree, - clazztype, - tree.constructor, - localEnv, - new ResultInfo(pkind, newMethodTemplate(syms.voidType, argtypes, typeargtypes))); + visitAnonymousClassDefinition(tree, clazz, clazztype, cdef, localEnv, argtypes, typeargtypes, pkind); + return; } if (tree.constructor != null && tree.constructor.kind == MTH) @@ -2133,6 +2105,125 @@ public class Attr extends JCTree.Visitor { chk.validate(tree.typeargs, localEnv); } + // where + private void visitAnonymousClassDefinition(JCNewClass tree, JCExpression clazz, Type clazztype, + JCClassDecl cdef, Env localEnv, + List argtypes, List typeargtypes, + KindSelector pkind) { + // We are seeing an anonymous class instance creation. + // In this case, the class instance creation + // expression + // + // E.new C(args) { ... } + // + // is represented internally as + // + // E . new C(args) ( class { ... } ) . + // + // This expression is then *transformed* as follows: + // + // (1) add an extends or implements clause + // (2) add a constructor. + // + // For instance, if C is a class, and ET is the type of E, + // the expression + // + // E.new C(args) { ... } + // + // is translated to (where X is a fresh name and typarams is the + // parameter list of the super constructor): + // + // new X(<*nullchk*>E, args) where + // X extends C { + // X(ET e, args) { + // e.super(args) + // } + // ... + // } + InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); + final boolean isDiamond = TreeInfo.isDiamond(tree); + if (isDiamond + && ((tree.constructorType != null && inferenceContext.free(tree.constructorType)) + || (tree.clazz.type != null && inferenceContext.free(tree.clazz.type)))) { + inferenceContext.addFreeTypeListener(List.of(tree.constructorType, tree.clazz.type), + instantiatedContext -> { + tree.constructorType = instantiatedContext.asInstType(tree.constructorType); + clazz.type = instantiatedContext.asInstType(clazz.type); + visitAnonymousClassDefinition(tree, clazz, clazz.type, cdef, localEnv, argtypes, typeargtypes, pkind); + }); + } else { + if (isDiamond && clazztype.hasTag(CLASS)) { + List invalidDiamondArgs = chk.checkDiamondDenotable((ClassType)clazztype); + if (!clazztype.isErroneous() && invalidDiamondArgs.nonEmpty()) { + // One or more types inferred in the previous steps is non-denotable. + Fragment fragment = Diamond(clazztype.tsym); + log.error(tree.clazz.pos(), + Errors.CantApplyDiamond1( + fragment, + invalidDiamondArgs.size() > 1 ? + DiamondInvalidArgs(invalidDiamondArgs, fragment) : + DiamondInvalidArg(invalidDiamondArgs, fragment))); + } + // For <>(){}, inferred types must also be accessible. + for (Type t : clazztype.getTypeArguments()) { + rs.checkAccessibleType(env, t); + } + } + + // If we already errored, be careful to avoid a further avalanche. ErrorType answers + // false for isInterface call even when the original type is an interface. + boolean implementing = clazztype.tsym.isInterface() || + clazztype.isErroneous() && clazztype.getOriginalType().tsym.isInterface(); + + if (implementing) { + cdef.implementing = List.of(clazz); + } else { + cdef.extending = clazz; + } + + if (resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK && + isSerializable(clazztype)) { + localEnv.info.isSerializable = true; + } + + attribStat(cdef, localEnv); + + List finalargtypes; + // If an outer instance is given, + // prefix it to the constructor arguments + // and delete it from the new expression + if (tree.encl != null && !clazztype.tsym.isInterface()) { + tree.args = tree.args.prepend(makeNullCheck(tree.encl)); + finalargtypes = argtypes.prepend(tree.encl.type); + tree.encl = null; + } else { + finalargtypes = argtypes; + } + + // Reassign clazztype and recompute constructor. As this necessarily involves + // another attribution pass for deferred types in the case of <>, replicate + // them. Original arguments have right decorations already. + if (isDiamond && pkind.contains(KindSelector.POLY)) { + finalargtypes = finalargtypes.map(deferredAttr.deferredCopier); + } + + clazztype = cdef.sym.type; + Symbol sym = tree.constructor = rs.resolveConstructor( + tree.pos(), localEnv, clazztype, finalargtypes, typeargtypes); + Assert.check(!sym.kind.isResolutionError()); + tree.constructor = sym; + tree.constructorType = checkId(noCheckTree, + clazztype, + tree.constructor, + localEnv, + new ResultInfo(pkind, newMethodTemplate(syms.voidType, finalargtypes, typeargtypes))); + } + Type owntype = (tree.constructor != null && tree.constructor.kind == MTH) ? + clazztype : types.createErrorType(tree.type); + result = check(tree, owntype, KindSelector.VAL, resultInfo, false); + chk.validate(tree.typeargs, localEnv); + } + /** Make an attributed null check tree. */ public JCExpression makeNullCheck(JCExpression arg) { diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java index db812ff0687..84d4a5318a6 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -63,6 +63,11 @@ public class AttrContext { */ boolean isSpeculative = false; + /** + * Is this an attribution environment for an anonymous class instantiated using <> ? + */ + boolean isAnonymousDiamond = false; + /** Are arguments to current function applications boxed into an array for varargs? */ Resolve.MethodResolutionPhase pendingResolutionPhase = null; @@ -100,6 +105,7 @@ public class AttrContext { info.defaultSuperCallSite = defaultSuperCallSite; info.isSerializable = isSerializable; info.isSpeculative = isSpeculative; + info.isAnonymousDiamond = isAnonymousDiamond; return info; } diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index b2af981a8ea..2f74ea42998 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -32,6 +32,8 @@ import javax.tools.JavaFileManager; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Attribute.Compound; import com.sun.tools.javac.jvm.*; +import com.sun.tools.javac.resources.CompilerProperties.Errors; +import com.sun.tools.javac.resources.CompilerProperties.Fragments; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; @@ -84,6 +86,7 @@ public class Check { private boolean suppressAbortOnBadClassFile; private boolean enableSunApiLintControl; private final JavaFileManager fileManager; + private final Source source; private final Profile profile; private final boolean warnOnAccessToSensitiveMembers; @@ -122,11 +125,12 @@ public class Check { lint = Lint.instance(context); fileManager = context.get(JavaFileManager.class); - Source source = Source.instance(context); + source = Source.instance(context); allowSimplifiedVarargs = source.allowSimplifiedVarargs(); allowDefaultMethods = source.allowDefaultMethods(); allowStrictMethodClashCheck = source.allowStrictMethodClashCheck(); allowPrivateSafeVarargs = source.allowPrivateSafeVarargs(); + allowDiamondWithAnonymousClassCreation = source.allowDiamondWithAnonymousClassCreation(); complexInference = options.isSet("complexinference"); warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile"); @@ -169,6 +173,10 @@ public class Check { */ boolean allowPrivateSafeVarargs; + /** Switch: can diamond inference be used in anonymous instance creation ? + */ + boolean allowDiamondWithAnonymousClassCreation; + /** Switch: -complexinference option set? */ boolean complexInference; @@ -773,10 +781,9 @@ public class Check { if (!TreeInfo.isDiamond(tree) || t.isErroneous()) { return checkClassType(tree.clazz.pos(), t, true); - } else if (tree.def != null) { + } else if (tree.def != null && !allowDiamondWithAnonymousClassCreation) { log.error(tree.clazz.pos(), - "cant.apply.diamond.1", - t, diags.fragment("diamond.and.anon.class", t)); + Errors.CantApplyDiamond1(t, Fragments.DiamondAndAnonClassNotSupportedInSource(source.name))); return types.createErrorType(t); } else if (t.tsym.type.getTypeArguments().isEmpty()) { log.error(tree.clazz.pos(), @@ -794,6 +801,59 @@ public class Check { } } + /** Check that the type inferred using the diamond operator does not contain + * non-denotable types such as captured types or intersection types. + * @param t the type inferred using the diamond operator + * @return the (possibly empty) list of non-denotable types. + */ + List checkDiamondDenotable(ClassType t) { + ListBuffer buf = new ListBuffer<>(); + for (Type arg : t.getTypeArguments()) { + if (!diamondTypeChecker.visit(arg, null)) { + buf.append(arg); + } + } + return buf.toList(); + } + // where + + /** diamondTypeChecker: A type visitor that descends down the given type looking for non-denotable + * types. The visit methods return false as soon as a non-denotable type is encountered and true + * otherwise. + */ + private static final Types.SimpleVisitor diamondTypeChecker = new Types.SimpleVisitor() { + @Override + public Boolean visitType(Type t, Void s) { + return true; + } + @Override + public Boolean visitClassType(ClassType t, Void s) { + if (t.isCompound()) { + return false; + } + for (Type targ : t.getTypeArguments()) { + if (!visit(targ, s)) { + return false; + } + } + return true; + } + @Override + public Boolean visitCapturedType(CapturedType t, Void s) { + return false; + } + + @Override + public Boolean visitArrayType(ArrayType t, Void s) { + return visit(t.elemtype, s); + } + + @Override + public Boolean visitWildcardType(WildcardType t, Void s) { + return visit(t.type, s); + } + }; + void checkVarargsMethodDecl(Env env, JCMethodDecl tree) { MethodSymbol m = tree.sym; if (!allowSimplifiedVarargs) return; @@ -1917,7 +1977,7 @@ public class Check { * for errors. * @param m The overriding method. */ - void checkOverride(JCMethodDecl tree, MethodSymbol m) { + void checkOverride(Env env, JCMethodDecl tree, MethodSymbol m) { ClassSymbol origin = (ClassSymbol)m.owner; if ((origin.flags() & ENUM) != 0 && names.finalize.equals(m.name)) if (m.overrides(syms.enumFinalFinalize, origin, types, false)) { @@ -1934,7 +1994,12 @@ public class Check { } } - if (m.attribute(syms.overrideType.tsym) != null && !isOverrider(m)) { + // Check if this method must override a super method due to being annotated with @Override + // or by virtue of being a member of a diamond inferred anonymous class. Latter case is to + // be treated "as if as they were annotated" with @Override. + boolean mustOverride = m.attribute(syms.overrideType.tsym) != null || + (env.info.isAnonymousDiamond && !m.isConstructor() && !m.isPrivate()); + if (mustOverride && !isOverrider(m)) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.overrideType.tsym) { diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java index 5432166b48f..9cb73b3a545 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java @@ -26,6 +26,7 @@ package com.sun.tools.javac.comp; import com.sun.source.tree.LambdaExpressionTree.BodyKind; +import com.sun.source.tree.NewClassTree; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Type.TypeMapping; import com.sun.tools.javac.comp.Resolve.ResolveError; @@ -81,6 +82,8 @@ public class DeferredAttr extends JCTree.Visitor { final Log log; final Symtab syms; final TreeMaker make; + final TreeCopier treeCopier; + final TypeMapping deferredCopier; final Types types; final Flow flow; final Names names; @@ -125,6 +128,35 @@ public class DeferredAttr extends JCTree.Visitor { return "Empty deferred context!"; } }; + + // For speculative attribution, skip the class definition in <>. + treeCopier = + new TreeCopier(make) { + @Override @DefinedBy(Api.COMPILER_TREE) + public JCTree visitNewClass(NewClassTree node, Void p) { + JCNewClass t = (JCNewClass) node; + if (TreeInfo.isDiamond(t)) { + JCExpression encl = copy(t.encl, p); + List typeargs = copy(t.typeargs, p); + JCExpression clazz = copy(t.clazz, p); + List args = copy(t.args, p); + JCClassDecl def = null; + return make.at(t.pos).NewClass(encl, typeargs, clazz, args, def); + } else { + return super.visitNewClass(node, p); + } + } + }; + deferredCopier = new TypeMapping () { + @Override + public Type visitType(Type t, Void v) { + if (t.hasTag(DEFERRED)) { + DeferredType dt = (DeferredType) t; + return new DeferredType(treeCopier.copy(dt.tree), dt.env); + } + return t; + } + }; } /** shared tree for stuck expressions */ @@ -364,7 +396,7 @@ public class DeferredAttr extends JCTree.Visitor { * disabled during speculative type-checking. */ JCTree attribSpeculative(JCTree tree, Env env, ResultInfo resultInfo) { - return attribSpeculative(tree, env, resultInfo, new TreeCopier<>(make), + return attribSpeculative(tree, env, resultInfo, treeCopier, (newTree)->new DeferredAttrDiagHandler(log, newTree)); } diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java index d8abe3b6855..177dbf8df2f 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -192,6 +192,7 @@ public class Enter extends JCTree.Visitor { localEnv.info.isSelfCall = false; localEnv.info.lint = null; // leave this to be filled in by Attr, // when annotations have been processed + localEnv.info.isAnonymousDiamond = TreeInfo.isDiamond(env.tree); return localEnv; } diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java index 258999e8afb..ba0e01df0a2 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -2555,7 +2555,8 @@ public class Resolve { boolean allowBoxing, boolean useVarargs) { Symbol bestSoFar = methodNotFound; - for (final Symbol sym : site.tsym.members().getSymbolsByName(names.init)) { + TypeSymbol tsym = site.tsym.isInterface() ? syms.objectType.tsym : site.tsym; + for (final Symbol sym : tsym.members().getSymbolsByName(names.init)) { //- System.out.println(" e " + e.sym); if (sym.kind == MTH && (sym.flags_field & SYNTHETIC) == 0) { diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index c3a8900c57c..6dc46740995 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -2010,6 +2010,16 @@ compiler.misc.diamond=\ compiler.misc.diamond.non.generic=\ cannot use ''<>'' with non-generic class {0} +# 0: list of type, 1: message segment +compiler.misc.diamond.invalid.arg=\ + type argument {0} inferred for {1} is not allowed in this context\n\ + inferred argument is not expressible in the Signature attribute + +# 0: list of type, 1: message segment +compiler.misc.diamond.invalid.args=\ + type arguments {0} inferred for {1} are not allowed in this context\n\ + inferred arguments are not expressible in the Signature attribute + # 0: unused compiler.misc.diamond.and.explicit.params=\ cannot use ''<>'' with explicit type parameters for constructor @@ -2271,10 +2281,6 @@ compiler.misc.varargs.implement=\ compiler.misc.varargs.clash.with=\ {0} in {1} overrides {2} in {3} -# 0: unused -compiler.misc.diamond.and.anon.class=\ - cannot use ''<>'' with anonymous inner classes - # 0: symbol kind, 1: symbol, 2: symbol, 3: message segment compiler.misc.inapplicable.method=\ {0} {1}.{2} is not applicable\n\ @@ -2283,6 +2289,11 @@ compiler.misc.inapplicable.method=\ ######################################## # Diagnostics for language feature changes ######################################## +# 0: string +compiler.misc.diamond.and.anon.class.not.supported.in.source=\ + cannot use ''<>'' with anonymous inner classes in -source {0}\n\ + (use -source 9 or higher to enable ''<>'' with anonymous inner classes) + # 0: string compiler.err.unsupported.binary.lit=\ binary literals are not supported in -source {0}\n\ diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java index b97af9782ef..af23690482f 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -190,6 +190,18 @@ public class TreeInfo { } } + /** Return true if the given tree represents a type elided anonymous class instance creation. */ + public static boolean isAnonymousDiamond(JCTree tree) { + switch(tree.getTag()) { + case NEWCLASS: { + JCNewClass nc = (JCNewClass)tree; + return nc.def != null && isDiamond(nc.clazz); + } + case ANNOTATED_TYPE: return isAnonymousDiamond(((JCAnnotatedType)tree).underlyingType); + default: return false; + } + } + public static boolean isEnumInit(JCTree tree) { switch (tree.getTag()) { case VARDEF: diff --git a/langtools/test/tools/javac/classfiles/attributes/innerclasses/InnerClassesInAnonymousClassTest.java b/langtools/test/tools/javac/classfiles/attributes/innerclasses/InnerClassesInAnonymousClassTest.java index 78a5287f6c7..04a563ce99f 100644 --- a/langtools/test/tools/javac/classfiles/attributes/innerclasses/InnerClassesInAnonymousClassTest.java +++ b/langtools/test/tools/javac/classfiles/attributes/innerclasses/InnerClassesInAnonymousClassTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8042251 + * @bug 8042251 8062373 * @summary Testing InnerClasses_attribute of inner classes in anonymous class. * @library /tools/lib /tools/javac/lib ../lib * @build InnerClassesTestBase TestResult TestBase InMemoryFileManager ToolBox @@ -73,6 +73,6 @@ public class InnerClassesInAnonymousClassTest extends InnerClassesTestBase { public void getAdditionalFlags(Map> class2Flags, ClassType type, Modifier... flags) { super.getAdditionalFlags(class2Flags, type, flags); class2Flags.put("Anonymous", getFlags(currentClassType, Arrays.asList(flags))); - class2Flags.put("1", new HashSet<>()); + class2Flags.put("1", new HashSet<>() {}); } } diff --git a/langtools/test/tools/javac/diags/examples/DiamondAndAnonClass.java b/langtools/test/tools/javac/diags/examples/DiamondAndAnonClass.java index 26ef5e7cfb5..8e94de00630 100644 --- a/langtools/test/tools/javac/diags/examples/DiamondAndAnonClass.java +++ b/langtools/test/tools/javac/diags/examples/DiamondAndAnonClass.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015 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 @@ -21,8 +21,10 @@ * questions. */ -// key: compiler.misc.diamond.and.anon.class +// key: compiler.misc.diamond.and.anon.class.not.supported.in.source // key: compiler.err.cant.apply.diamond.1 +// key: compiler.warn.source.no.bootclasspath +// options: -source 8 import java.util.*; diff --git a/langtools/test/tools/javac/diags/examples/DiamondAndNonDenotableTypes.java b/langtools/test/tools/javac/diags/examples/DiamondAndNonDenotableTypes.java new file mode 100644 index 00000000000..0f2650d3e47 --- /dev/null +++ b/langtools/test/tools/javac/diags/examples/DiamondAndNonDenotableTypes.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 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. + * + * 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. + */ + +// key: compiler.misc.diamond +// key: compiler.err.cant.apply.diamond.1 +// key: compiler.misc.diamond.invalid.arg +// key: compiler.misc.diamond.invalid.args + +import java.util.*; + +class DiamondAndNonDenotableType { + DiamondAndNonDenotableType(T t) {} +} + +class DiamondAndNonDenotableTypes { + DiamondAndNonDenotableTypes(T t, S s) {} + void m() { + List wl = null; + new DiamondAndNonDenotableTypes<>(wl, wl) {}; + new DiamondAndNonDenotableType<>(wl) {}; + }; +} diff --git a/langtools/test/tools/javac/failover/CheckAttributedTree.java b/langtools/test/tools/javac/failover/CheckAttributedTree.java index 34222c8736d..66f91ee5e91 100644 --- a/langtools/test/tools/javac/failover/CheckAttributedTree.java +++ b/langtools/test/tools/javac/failover/CheckAttributedTree.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6970584 8006694 + * @bug 6970584 8006694 8062373 * @summary assorted position errors in compiler syntax trees * temporarily workaround combo tests are causing time out in several platforms * @library ../lib @@ -290,7 +290,7 @@ public class CheckAttributedTree extends JavacTestingAbstractThreadedTest { } public void finished(TaskEvent e) { } }); - + int i = 0; try { Iterable trees = task.parse(); // JavaCompiler c = JavaCompiler.instance(((JavacTaskImpl) task).getContext()); @@ -308,7 +308,7 @@ public class CheckAttributedTree extends JavacTestingAbstractThreadedTest { if (def.hasTag(CLASSDEF) && analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) { //System.err.println("Adding pair..." + cu.sourcefile + " " + ((JCTree.JCClassDecl) def).name); - res.add(new Pair<>(cu, def)); + res.add((i++ % 2) == 0 ? new Pair<>(cu, def) {} : new Pair<>(cu, def)); } } } diff --git a/langtools/test/tools/javac/generics/diamond/6939780/T6939780.java b/langtools/test/tools/javac/generics/diamond/6939780/T6939780.java index 6d7ef0da676..603d48bae4b 100644 --- a/langtools/test/tools/javac/generics/diamond/6939780/T6939780.java +++ b/langtools/test/tools/javac/generics/diamond/6939780/T6939780.java @@ -1,11 +1,12 @@ /* * @test /nodynamiccopyright/ - * @bug 6939780 7020044 8009459 8021338 8064365 + * @bug 6939780 7020044 8009459 8021338 8064365 8062373 * - * @summary add a warning to detect diamond sites + * @summary add a warning to detect diamond sites (including anonymous class instance creation at source >= 9) * @author mcimadamore * @compile/ref=T6939780_7.out -Xlint:-options -source 7 T6939780.java -XDrawDiagnostics -XDfind=diamond - * @compile/ref=T6939780_8.out T6939780.java -XDrawDiagnostics -XDfind=diamond + * @compile/ref=T6939780_8.out -Xlint:-options -source 8 T6939780.java -XDrawDiagnostics -XDfind=diamond + * @compile/ref=T6939780_9.out -Xlint:-options -source 9 T6939780.java -XDrawDiagnostics -XDfind=diamond * */ diff --git a/langtools/test/tools/javac/generics/diamond/6939780/T6939780_7.out b/langtools/test/tools/javac/generics/diamond/6939780/T6939780_7.out index 52d621d78df..fbf2fe6a0c8 100644 --- a/langtools/test/tools/javac/generics/diamond/6939780/T6939780_7.out +++ b/langtools/test/tools/javac/generics/diamond/6939780/T6939780_7.out @@ -1,5 +1,5 @@ -T6939780.java:21:28: compiler.warn.diamond.redundant.args -T6939780.java:22:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo -T6939780.java:30:19: compiler.warn.diamond.redundant.args -T6939780.java:31:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo +T6939780.java:22:28: compiler.warn.diamond.redundant.args +T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo +T6939780.java:31:19: compiler.warn.diamond.redundant.args +T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo 4 warnings diff --git a/langtools/test/tools/javac/generics/diamond/6939780/T6939780_8.out b/langtools/test/tools/javac/generics/diamond/6939780/T6939780_8.out index 3d979d15147..76e2ea00260 100644 --- a/langtools/test/tools/javac/generics/diamond/6939780/T6939780_8.out +++ b/langtools/test/tools/javac/generics/diamond/6939780/T6939780_8.out @@ -1,7 +1,7 @@ -T6939780.java:20:33: compiler.warn.diamond.redundant.args -T6939780.java:21:28: compiler.warn.diamond.redundant.args -T6939780.java:22:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo -T6939780.java:29:19: compiler.warn.diamond.redundant.args +T6939780.java:21:33: compiler.warn.diamond.redundant.args +T6939780.java:22:28: compiler.warn.diamond.redundant.args +T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo T6939780.java:30:19: compiler.warn.diamond.redundant.args -T6939780.java:31:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo +T6939780.java:31:19: compiler.warn.diamond.redundant.args +T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo 6 warnings diff --git a/langtools/test/tools/javac/generics/diamond/6939780/T6939780_9.out b/langtools/test/tools/javac/generics/diamond/6939780/T6939780_9.out new file mode 100644 index 00000000000..308851596b5 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/6939780/T6939780_9.out @@ -0,0 +1,13 @@ +T6939780.java:21:33: compiler.warn.diamond.redundant.args +T6939780.java:22:28: compiler.warn.diamond.redundant.args +T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo +T6939780.java:24:33: compiler.warn.diamond.redundant.args +T6939780.java:25:28: compiler.warn.diamond.redundant.args +T6939780.java:26:28: compiler.warn.diamond.redundant.args +T6939780.java:30:19: compiler.warn.diamond.redundant.args +T6939780.java:31:19: compiler.warn.diamond.redundant.args +T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo, T6939780.Foo +T6939780.java:33:19: compiler.warn.diamond.redundant.args +T6939780.java:34:19: compiler.warn.diamond.redundant.args +T6939780.java:35:19: compiler.warn.diamond.redundant.args +12 warnings diff --git a/langtools/test/tools/javac/generics/diamond/6996914/T6996914a.java b/langtools/test/tools/javac/generics/diamond/6996914/T6996914a.java index 47e7f98a40c..b0f42327d86 100644 --- a/langtools/test/tools/javac/generics/diamond/6996914/T6996914a.java +++ b/langtools/test/tools/javac/generics/diamond/6996914/T6996914a.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6996914 7020044 + * @bug 6996914 7020044 8062373 * @summary Diamond inference: problem when accessing protected constructor * @run main T6996914a */ @@ -53,6 +53,17 @@ public class T6996914a { } } + enum DiamondKind { + STANDARD("new Foo<>();"), + ANON("new Foo<>() {};"); + + String expr; + + DiamondKind(String expr) { + this.expr = expr; + } + } + enum ConstructorKind { PACKAGE(""), PROTECTED("protected"), @@ -93,14 +104,14 @@ public class T6996914a { final static String sourceStub = "#I\n" + "class Test {\n" + - " Foo fs = new Foo<>();\n" + + " Foo fs = #D\n" + "}\n"; String source; - public ClientClass(PackageKind pk) { + public ClientClass(PackageKind pk, DiamondKind dk) { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); - source = sourceStub.replace("#I", pk.importDecl); + source = sourceStub.replace("#I", pk.importDecl).replace("#D", dk.expr); } @Override @@ -112,20 +123,22 @@ public class T6996914a { public static void main(String... args) throws Exception { for (PackageKind pk : PackageKind.values()) { for (ConstructorKind ck : ConstructorKind.values()) { - compileAndCheck(pk, ck); + for (DiamondKind dk : DiamondKind.values()) { + compileAndCheck(pk, ck, dk); + } } } } - static void compileAndCheck(PackageKind pk, ConstructorKind ck) throws Exception { + static void compileAndCheck(PackageKind pk, ConstructorKind ck, DiamondKind dk) throws Exception { FooClass foo = new FooClass(pk, ck); - ClientClass client = new ClientClass(pk); + ClientClass client = new ClientClass(pk, dk); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); ErrorListener el = new ErrorListener(); JavacTask ct = (JavacTask)tool.getTask(null, null, el, null, null, Arrays.asList(foo, client)); ct.analyze(); - if (el.errors > 0 == check(pk, ck)) { + if (el.errors > 0 == check(pk, ck, dk)) { String msg = el.errors > 0 ? "Error compiling files" : "No error when compiling files"; @@ -133,9 +146,10 @@ public class T6996914a { } } - static boolean check(PackageKind pk, ConstructorKind ck) { + static boolean check(PackageKind pk, ConstructorKind ck, DiamondKind dk) { switch (pk) { - case A: return ck == ConstructorKind.PUBLIC; + case A: return ck == ConstructorKind.PUBLIC || + (ck == ConstructorKind.PROTECTED && dk == DiamondKind.ANON); case DEFAULT: return ck != ConstructorKind.PRIVATE; default: throw new AssertionError("Unknown package kind"); } diff --git a/langtools/test/tools/javac/generics/diamond/6996914/T6996914b.java b/langtools/test/tools/javac/generics/diamond/6996914/T6996914b.java index 42339dbb0aa..651ce36a36a 100644 --- a/langtools/test/tools/javac/generics/diamond/6996914/T6996914b.java +++ b/langtools/test/tools/javac/generics/diamond/6996914/T6996914b.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6996914 7020044 + * @bug 6996914 7020044 8062373 * @summary Diamond inference: problem when accessing protected constructor * @compile T6996914b.java */ @@ -35,4 +35,5 @@ class Super { class Test { Super ssi1 = new Super<>(1, "", 2); + Super ssi2 = new Super<>(1, "", 2) {}; } diff --git a/langtools/test/tools/javac/generics/diamond/8065986/T8065986b.java b/langtools/test/tools/javac/generics/diamond/8065986/T8065986b.java index 40a6a8b573e..9793363d9c9 100644 --- a/langtools/test/tools/javac/generics/diamond/8065986/T8065986b.java +++ b/langtools/test/tools/javac/generics/diamond/8065986/T8065986b.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 8065986 + * @bug 8065986 8062373 * * @summary Compiler fails to NullPointerException when calling super with Object<>() * @compile/fail/ref=T8065986b.out T8065986b.java -XDrawDiagnostics @@ -29,5 +29,12 @@ class T8065986b { this(cond ? o1 : o2); } + T8065986b(int x) { + this(new Object<>() {}); + } + + T8065986b(int x, int y) { + this(new ArrayList<>() {}); + } static void m() { } } diff --git a/langtools/test/tools/javac/generics/diamond/8065986/T8065986b.out b/langtools/test/tools/javac/generics/diamond/8065986/T8065986b.out index 30bcfb6eb65..ec65f48b075 100644 --- a/langtools/test/tools/javac/generics/diamond/8065986/T8065986b.out +++ b/langtools/test/tools/javac/generics/diamond/8065986/T8065986b.out @@ -1,6 +1,8 @@ T8065986b.java:13:24: compiler.err.cant.apply.diamond.1: java.lang.Object, (compiler.misc.diamond.non.generic: java.lang.Object) -T8065986b.java:17:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, java.util.ArrayList,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: java.util.ArrayList), (compiler.misc.infer.no.conforming.instance.exists: E, java.util.ArrayList, boolean)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))} -T8065986b.java:21:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @435,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: boolean))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))} -T8065986b.java:25:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @516,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: boolean))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))} -T8065986b.java:29:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @603,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.type.in.conditional: (compiler.misc.inconvertible.types: java.lang.Object, boolean)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))} -5 errors +T8065986b.java:17:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, java.util.ArrayList,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: java.util.ArrayList), (compiler.misc.infer.no.conforming.instance.exists: E, java.util.ArrayList, boolean)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: java.util.ArrayList), (compiler.misc.infer.no.conforming.instance.exists: E, java.util.ArrayList, int)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int,int), (compiler.misc.arg.length.mismatch))} +T8065986b.java:21:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @443,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: boolean))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: int))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int,int), (compiler.misc.arg.length.mismatch))} +T8065986b.java:25:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @524,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: boolean))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: int))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int,int), (compiler.misc.arg.length.mismatch))} +T8065986b.java:29:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @611,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.type.in.conditional: (compiler.misc.inconvertible.types: java.lang.Object, boolean)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.type.in.conditional: (compiler.misc.inconvertible.types: java.lang.Object, int)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int,int), (compiler.misc.arg.length.mismatch))} +T8065986b.java:33:24: compiler.err.cant.apply.diamond.1: java.lang.Object, (compiler.misc.diamond.non.generic: java.lang.Object) +T8065986b.java:37:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, java.util.ArrayList,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: java.util.ArrayList), (compiler.misc.infer.no.conforming.instance.exists: E, java.util.ArrayList, boolean)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: java.util.ArrayList), (compiler.misc.infer.no.conforming.instance.exists: E, java.util.ArrayList, int)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(int,int), (compiler.misc.arg.length.mismatch))} +7 errors diff --git a/langtools/test/tools/javac/generics/diamond/MultipleInferenceHooksTest.java b/langtools/test/tools/javac/generics/diamond/MultipleInferenceHooksTest.java new file mode 100644 index 00000000000..af3f943bedc --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/MultipleInferenceHooksTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8062373 + * @summary Test that <>(){} works fine without verify error when there are multiple post inference hooks. + */ + +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Set; + +public class MultipleInferenceHooksTest { + public static void main(String[] args) { + Set result = Collections.newSetFromMap(new IdentityHashMap<>() {}); + } +} diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg01.java b/langtools/test/tools/javac/generics/diamond/neg/Neg01.java index acbb06cd6c2..f0e98394110 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg01.java +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg01.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary Check that diamond fails when inference violates declared bounds * (basic test with nested class, generic/non-generic constructors) @@ -25,5 +25,16 @@ class Neg01 { Neg01 n6 = new Neg01<>("", ""); Neg01 n7 = new Neg01<>("", ""); Foo n8 = new Neg01<>("", ""); + + Neg01 n9 = new Neg01<>("", ""){}; + Neg01 n10 = new Neg01<>("", ""){}; + Neg01 n11 = new Neg01<>("", ""){}; + Neg01 n12 = new Neg01<>("", ""){}; + + Neg01 n13 = new Neg01<>(""){}; + Neg01 n14 = new Neg01<>(""){}; + Neg01 n15 = new Neg01<>(""){}; + Neg01 n16 = new Neg01<>(""){}; + } } diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg01.out b/langtools/test/tools/javac/generics/diamond/neg/Neg01.out index c2bbf4c35b9..4f54718d44e 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg01.out +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg01.out @@ -12,4 +12,18 @@ Neg01.java:25:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01 Neg01.java:26:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null Neg01.java:27:9: compiler.err.cant.resolve.location: kindname.class, Foo, , , (compiler.misc.location: kindname.class, Neg01, null) Neg01.java:27:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null -14 errors +Neg01.java:29:15: compiler.err.not.within.bounds: java.lang.String, X +Neg01.java:29:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null +Neg01.java:30:15: compiler.err.not.within.bounds: ? extends java.lang.String, X +Neg01.java:30:39: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null +Neg01.java:31:24: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null +Neg01.java:32:15: compiler.err.not.within.bounds: ? super java.lang.String, X +Neg01.java:32:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null +Neg01.java:34:15: compiler.err.not.within.bounds: java.lang.String, X +Neg01.java:34:29: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null +Neg01.java:35:15: compiler.err.not.within.bounds: ? extends java.lang.String, X +Neg01.java:35:39: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null +Neg01.java:36:24: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null +Neg01.java:37:15: compiler.err.not.within.bounds: ? super java.lang.String, X +Neg01.java:37:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null +28 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg02.java b/langtools/test/tools/javac/generics/diamond/neg/Neg02.java index ac4cc2cb998..26ff47d9949 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg02.java +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg02.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary Check that diamond fails when inference violates declared bounds * (test with nested class, qualified/simple type expressions) @@ -26,6 +26,16 @@ class Neg02 { Foo f6 = new Foo<>("", ""); Foo f7 = new Foo<>("", ""); Foo f8 = new Foo<>("", ""); + + Foo f9 = new Foo<>(""){}; + Foo f10 = new Foo<>(""){}; + Foo f11 = new Foo<>(""){}; + Foo f12 = new Foo<>(""){}; + + Foo f13 = new Foo<>("", ""){}; + Foo f14 = new Foo<>("", ""){}; + Foo f15 = new Foo<>("", ""){}; + Foo f16 = new Foo<>("", ""){}; } void testQualified() { @@ -38,5 +48,15 @@ class Neg02 { Foo f6 = new Neg02.Foo<>("", ""); Foo f7 = new Neg02.Foo<>("", ""); Foo f8 = new Neg02.Foo<>("", ""); + + Foo f9 = new Neg02.Foo<>(""){}; + Foo f10 = new Neg02.Foo<>(""){}; + Foo f11 = new Neg02.Foo<>(""){}; + Foo f12 = new Neg02.Foo<>(""){}; + + Foo f13 = new Neg02.Foo<>("", ""){}; + Foo f14 = new Neg02.Foo<>("", ""){}; + Foo f15 = new Neg02.Foo<>("", ""){}; + Foo f16 = new Neg02.Foo<>("", ""){}; } } diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg02.out b/langtools/test/tools/javac/generics/diamond/neg/Neg02.out index 4e3d7d201ce..73126ec1f8d 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg02.out +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg02.out @@ -12,18 +12,46 @@ Neg02.java:26:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02 Neg02.java:27:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:28:13: compiler.err.not.within.bounds: ? super java.lang.String, X Neg02.java:28:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null -Neg02.java:32:13: compiler.err.not.within.bounds: java.lang.String, X -Neg02.java:32:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null -Neg02.java:33:13: compiler.err.not.within.bounds: ? extends java.lang.String, X -Neg02.java:33:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null -Neg02.java:34:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null -Neg02.java:35:13: compiler.err.not.within.bounds: ? super java.lang.String, X -Neg02.java:35:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null -Neg02.java:37:13: compiler.err.not.within.bounds: java.lang.String, X -Neg02.java:37:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null -Neg02.java:38:13: compiler.err.not.within.bounds: ? extends java.lang.String, X -Neg02.java:38:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null -Neg02.java:39:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null -Neg02.java:40:13: compiler.err.not.within.bounds: ? super java.lang.String, X -Neg02.java:40:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null -28 errors +Neg02.java:30:13: compiler.err.not.within.bounds: java.lang.String, X +Neg02.java:30:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:31:13: compiler.err.not.within.bounds: ? extends java.lang.String, X +Neg02.java:31:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:32:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:33:13: compiler.err.not.within.bounds: ? super java.lang.String, X +Neg02.java:33:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:35:13: compiler.err.not.within.bounds: java.lang.String, X +Neg02.java:35:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:36:13: compiler.err.not.within.bounds: ? extends java.lang.String, X +Neg02.java:36:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:37:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:38:13: compiler.err.not.within.bounds: ? super java.lang.String, X +Neg02.java:38:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:42:13: compiler.err.not.within.bounds: java.lang.String, X +Neg02.java:42:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:43:13: compiler.err.not.within.bounds: ? extends java.lang.String, X +Neg02.java:43:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:44:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:45:13: compiler.err.not.within.bounds: ? super java.lang.String, X +Neg02.java:45:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:47:13: compiler.err.not.within.bounds: java.lang.String, X +Neg02.java:47:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:48:13: compiler.err.not.within.bounds: ? extends java.lang.String, X +Neg02.java:48:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:49:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:50:13: compiler.err.not.within.bounds: ? super java.lang.String, X +Neg02.java:50:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:52:13: compiler.err.not.within.bounds: java.lang.String, X +Neg02.java:52:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:53:13: compiler.err.not.within.bounds: ? extends java.lang.String, X +Neg02.java:53:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:54:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:55:13: compiler.err.not.within.bounds: ? super java.lang.String, X +Neg02.java:55:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:57:13: compiler.err.not.within.bounds: java.lang.String, X +Neg02.java:57:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:58:13: compiler.err.not.within.bounds: ? extends java.lang.String, X +Neg02.java:58:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:59:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +Neg02.java:60:13: compiler.err.not.within.bounds: ? super java.lang.String, X +Neg02.java:60:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null +56 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg03.java b/langtools/test/tools/javac/generics/diamond/neg/Neg03.java index 83994b3b42e..54e68129398 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg03.java +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg03.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary Check that diamond fails when inference violates declared bounds * (test with inner class, qualified/simple type expressions) @@ -26,6 +26,16 @@ class Neg03 { Foo f6 = new Foo<>("", ""); Foo f7 = new Foo<>("", ""); Foo f8 = new Foo<>("", ""); + + Foo f9 = new Foo<>(""){}; + Foo f10 = new Foo<>(""){}; + Foo f11 = new Foo<>(""){}; + Foo f12 = new Foo<>(""){}; + + Foo f13 = new Foo<>("", ""){}; + Foo f14 = new Foo<>("", ""){}; + Foo f15 = new Foo<>("", ""){}; + Foo f16 = new Foo<>("", ""){}; } void testQualified_1() { @@ -38,6 +48,16 @@ class Neg03 { Foo f6 = new Neg03.Foo<>("", ""); Foo f7 = new Neg03.Foo<>("", ""); Foo f8 = new Neg03.Foo<>("", ""); + + Foo f9 = new Neg03.Foo<>(""){}; + Foo f10 = new Neg03.Foo<>(""){}; + Foo f11 = new Neg03.Foo<>(""){}; + Foo f12 = new Neg03.Foo<>(""){}; + + Foo f13 = new Neg03.Foo<>("", ""){}; + Foo f14 = new Neg03.Foo<>("", ""){}; + Foo f15 = new Neg03.Foo<>("", ""){}; + Foo f16 = new Neg03.Foo<>("", ""){}; } void testQualified_2(Neg03 n) { @@ -50,5 +70,15 @@ class Neg03 { Foo f6 = n.new Foo<>("", ""); Foo f7 = n.new Foo<>("", ""); Foo f8 = n.new Foo<>("", ""); + + Foo f9 = n.new Foo<>(""){}; + Foo f10 = n.new Foo<>(""){}; + Foo f11 = n.new Foo<>(""){}; + Foo f12 = n.new Foo<>(""){}; + + Foo f13 = n.new Foo<>("", ""){}; + Foo f14 = n.new Foo<>("", ""){}; + Foo f15 = n.new Foo<>("", ""){}; + Foo f16 = n.new Foo<>("", ""){}; } } diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg03.out b/langtools/test/tools/javac/generics/diamond/neg/Neg03.out index b255fca3c99..20ecb6ca326 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg03.out +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg03.out @@ -12,32 +12,74 @@ Neg03.java:26:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03 Neg03.java:27:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:28:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg03.java:28:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:32:13: compiler.err.not.within.bounds: java.lang.String, V -Neg03.java:32:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:33:13: compiler.err.not.within.bounds: ? extends java.lang.String, V -Neg03.java:33:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:34:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:35:13: compiler.err.not.within.bounds: ? super java.lang.String, V -Neg03.java:35:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:37:13: compiler.err.not.within.bounds: java.lang.String, V -Neg03.java:37:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:38:13: compiler.err.not.within.bounds: ? extends java.lang.String, V -Neg03.java:38:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:39:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:40:13: compiler.err.not.within.bounds: ? super java.lang.String, V -Neg03.java:40:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:44:13: compiler.err.not.within.bounds: java.lang.String, V -Neg03.java:44:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:45:13: compiler.err.not.within.bounds: ? extends java.lang.String, V -Neg03.java:45:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:46:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:47:13: compiler.err.not.within.bounds: ? super java.lang.String, V -Neg03.java:47:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:49:13: compiler.err.not.within.bounds: java.lang.String, V -Neg03.java:49:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:50:13: compiler.err.not.within.bounds: ? extends java.lang.String, V -Neg03.java:50:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:51:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -Neg03.java:52:13: compiler.err.not.within.bounds: ? super java.lang.String, V -Neg03.java:52:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null -42 errors +Neg03.java:30:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:30:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:31:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:31:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:32:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:33:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:33:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:35:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:35:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:36:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:36:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:37:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:38:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:38:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:42:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:42:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:43:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:43:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:44:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:45:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:45:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:47:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:47:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:48:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:48:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:49:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:50:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:50:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:52:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:52:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:53:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:53:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:54:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:55:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:55:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:57:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:57:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:58:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:58:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:59:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:60:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:60:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:64:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:64:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:65:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:65:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:66:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:67:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:67:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:69:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:69:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:70:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:70:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:71:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:72:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:72:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:74:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:74:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:75:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:75:39: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:76:24: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:77:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:77:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:79:13: compiler.err.not.within.bounds: java.lang.String, V +Neg03.java:79:29: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:80:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg03.java:80:39: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:81:24: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +Neg03.java:82:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg03.java:82:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null +84 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg04.java b/langtools/test/tools/javac/generics/diamond/neg/Neg04.java index 94aa8d638b3..28b01b4de67 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg04.java +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg04.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary Check that diamond fails when inference violates declared bounds * (test with local class, qualified/simple type expressions) @@ -25,5 +25,15 @@ class Neg04 { Foo n6 = new Foo<>("", ""); Foo n7 = new Foo<>("", ""); Foo n8 = new Foo<>("", ""); + + Foo n9 = new Foo<>(""){}; + Foo n10 = new Foo<>(""){}; + Foo n11 = new Foo<>(""){}; + Foo n12 = new Foo<>(""){}; + + Foo n13 = new Foo<>("", ""){}; + Foo n14 = new Foo<>("", ""){}; + Foo n15 = new Foo<>("", ""){}; + Foo n16 = new Foo<>("", ""){}; } } diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg04.out b/langtools/test/tools/javac/generics/diamond/neg/Neg04.out index 656d268015f..d8d7512aee1 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg04.out +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg04.out @@ -12,4 +12,18 @@ Neg04.java:25:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), Neg04.java:26:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null Neg04.java:27:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg04.java:27:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null -14 errors +Neg04.java:29:13: compiler.err.not.within.bounds: java.lang.String, V +Neg04.java:29:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null +Neg04.java:30:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg04.java:30:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null +Neg04.java:31:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null +Neg04.java:32:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg04.java:32:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null +Neg04.java:34:13: compiler.err.not.within.bounds: java.lang.String, V +Neg04.java:34:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null +Neg04.java:35:13: compiler.err.not.within.bounds: ? extends java.lang.String, V +Neg04.java:35:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null +Neg04.java:36:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null +Neg04.java:37:13: compiler.err.not.within.bounds: ? super java.lang.String, V +Neg04.java:37:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null +28 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg05.java b/langtools/test/tools/javac/generics/diamond/neg/Neg05.java index 53ee397b50f..960f5729cde 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg05.java +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg05.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary Check that usage of rare types doesn't cause spurious diamond diagnostics * @author mcimadamore @@ -25,6 +25,16 @@ class Neg05 { Neg05.Foo f6 = new Neg05.Foo<>("", ""); Neg05.Foo f7 = new Neg05.Foo<>("", ""); Neg05.Foo f8 = new Neg05.Foo<>("", ""); + + Neg05.Foo f9 = new Neg05.Foo<>(""){}; + Neg05.Foo f10 = new Neg05.Foo<>(""){}; + Neg05.Foo f11 = new Neg05.Foo<>(""){}; + Neg05.Foo f12 = new Neg05.Foo<>(""){}; + + Neg05.Foo f13 = new Neg05.Foo<>("", ""){}; + Neg05.Foo f14 = new Neg05.Foo<>("", ""){}; + Neg05.Foo f15 = new Neg05.Foo<>("", ""){}; + Neg05.Foo f16 = new Neg05.Foo<>("", ""){}; } void testRare_2(Neg05 n) { @@ -37,5 +47,15 @@ class Neg05 { Neg05.Foo f6 = n.new Foo<>("", ""); Neg05.Foo f7 = n.new Foo<>("", ""); Neg05.Foo f8 = n.new Foo<>("", ""); + + Neg05.Foo f9 = n.new Foo<>(""){}; + Neg05.Foo f10 = n.new Foo<>(""){}; + Neg05.Foo f11 = n.new Foo<>(""){}; + Neg05.Foo f12 = n.new Foo<>(""){}; + + Neg05.Foo f13 = n.new Foo<>("", ""){}; + Neg05.Foo f14 = n.new Foo<>("", ""){}; + Neg05.Foo f15 = n.new Foo<>("", ""){}; + Neg05.Foo f16 = n.new Foo<>("", ""){}; } } diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg05.out b/langtools/test/tools/javac/generics/diamond/neg/Neg05.out index 7ab2ece7e0e..8f31285f0ef 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg05.out +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg05.out @@ -6,20 +6,52 @@ Neg05.java:24:48: compiler.err.improperly.formed.type.inner.raw.param Neg05.java:25:58: compiler.err.improperly.formed.type.inner.raw.param Neg05.java:26:43: compiler.err.improperly.formed.type.inner.raw.param Neg05.java:27:56: compiler.err.improperly.formed.type.inner.raw.param -Neg05.java:31:37: compiler.err.improperly.formed.type.inner.raw.param -Neg05.java:31:44: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) -Neg05.java:32:47: compiler.err.improperly.formed.type.inner.raw.param -Neg05.java:32:54: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) -Neg05.java:33:32: compiler.err.improperly.formed.type.inner.raw.param -Neg05.java:33:39: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) -Neg05.java:34:45: compiler.err.improperly.formed.type.inner.raw.param -Neg05.java:34:52: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) -Neg05.java:36:37: compiler.err.improperly.formed.type.inner.raw.param -Neg05.java:36:44: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) -Neg05.java:37:47: compiler.err.improperly.formed.type.inner.raw.param -Neg05.java:37:54: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) -Neg05.java:38:32: compiler.err.improperly.formed.type.inner.raw.param -Neg05.java:38:39: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) -Neg05.java:39:45: compiler.err.improperly.formed.type.inner.raw.param -Neg05.java:39:52: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) -24 errors +Neg05.java:29:48: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:29:35: compiler.err.cant.apply.symbol: kindname.constructor, , V, java.lang.String, kindname.class, compiler.misc.anonymous.class: , (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, V)) +Neg05.java:30:59: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:30:46: compiler.err.cant.apply.symbol: kindname.constructor, , V, java.lang.String, kindname.class, compiler.misc.anonymous.class: , (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, V)) +Neg05.java:31:44: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:31:31: compiler.err.cant.apply.symbol: kindname.constructor, , V, java.lang.String, kindname.class, compiler.misc.anonymous.class: , (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, V)) +Neg05.java:32:57: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:32:44: compiler.err.cant.apply.symbol: kindname.constructor, , V, java.lang.String, kindname.class, compiler.misc.anonymous.class: , (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, V)) +Neg05.java:34:49: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:34:36: compiler.err.cant.apply.symbol: kindname.constructor, , V,Z, java.lang.String,java.lang.String, kindname.class, compiler.misc.anonymous.class: , (compiler.misc.infer.no.conforming.assignment.exists: Z, (compiler.misc.inconvertible.types: java.lang.String, V)) +Neg05.java:35:59: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:35:46: compiler.err.cant.apply.symbol: kindname.constructor, , V,Z, java.lang.String,java.lang.String, kindname.class, compiler.misc.anonymous.class: , (compiler.misc.infer.no.conforming.assignment.exists: Z, (compiler.misc.inconvertible.types: java.lang.String, V)) +Neg05.java:36:44: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:36:31: compiler.err.cant.apply.symbol: kindname.constructor, , V,Z, java.lang.String,java.lang.String, kindname.class, compiler.misc.anonymous.class: , (compiler.misc.infer.no.conforming.assignment.exists: Z, (compiler.misc.inconvertible.types: java.lang.String, V)) +Neg05.java:37:57: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:37:44: compiler.err.cant.apply.symbol: kindname.constructor, , V,Z, java.lang.String,java.lang.String, kindname.class, compiler.misc.anonymous.class: , (compiler.misc.infer.no.conforming.assignment.exists: Z, (compiler.misc.inconvertible.types: java.lang.String, V)) +Neg05.java:41:37: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:41:44: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) +Neg05.java:42:47: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:42:54: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) +Neg05.java:43:32: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:43:39: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) +Neg05.java:44:45: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:44:52: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) +Neg05.java:46:37: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:46:44: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) +Neg05.java:47:47: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:47:54: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) +Neg05.java:48:32: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:48:39: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) +Neg05.java:49:45: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:49:52: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) +Neg05.java:51:37: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:51:44: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) +Neg05.java:52:48: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:52:55: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) +Neg05.java:53:33: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:53:40: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) +Neg05.java:54:46: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:54:53: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo, Neg05.Foo)) +Neg05.java:56:38: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:56:45: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) +Neg05.java:57:48: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:57:55: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) +Neg05.java:58:33: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:58:40: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) +Neg05.java:59:46: compiler.err.improperly.formed.type.inner.raw.param +Neg05.java:59:53: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo, Neg05.Foo)) +56 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg06.java b/langtools/test/tools/javac/generics/diamond/neg/Neg06.java index 73aae17b00e..e4f98dccd6b 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg06.java +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg06.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary Check that diamond works where LHS is supertype of RHS (nilary constructor) * @author mcimadamore @@ -9,9 +9,13 @@ */ class Neg06 { + interface ISuperFoo {} + interface IFoo extends ISuperFoo {} static class CSuperFoo {} static class CFoo extends CSuperFoo {} + ISuperFoo isf = new IFoo<>() {}; CSuperFoo csf1 = new CFoo<>(); + CSuperFoo csf2 = new CFoo<>() {}; } diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg06.out b/langtools/test/tools/javac/generics/diamond/neg/Neg06.out index bf439f78f89..c085b5ebdd6 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg06.out +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg06.out @@ -1,2 +1,6 @@ -Neg06.java:16:37: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg06.CFoo), (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) -1 error +Neg06.java:18:36: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg06.IFoo), (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) +Neg06.java:18:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, Neg06.ISuperFoo) +Neg06.java:19:37: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg06.CFoo), (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) +Neg06.java:20:37: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg06.CFoo), (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) +Neg06.java:20:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: , Neg06.CSuperFoo) +5 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg07.java b/langtools/test/tools/javac/generics/diamond/neg/Neg07.java index f65bee8e1d8..199a2e861f4 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg07.java +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg07.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary Check that diamond works where LHS is supertype of RHS (1-ary constructor) * @author mcimadamore @@ -15,4 +15,5 @@ class Neg07 { } SuperFoo sf1 = new Foo<>(""); + SuperFoo sf2 = new Foo<>("") {}; } diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg07.out b/langtools/test/tools/javac/generics/diamond/neg/Neg07.out index 59c37899ed0..8bec602bdba 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg07.out +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg07.out @@ -1,2 +1,3 @@ Neg07.java:17:27: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg07.Foo), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number) -1 error +Neg07.java:18:27: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg07.Foo), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number) +2 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg09.java b/langtools/test/tools/javac/generics/diamond/neg/Neg09.java index 4a85619e45b..729a3f1d10b 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg09.java +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg09.java @@ -1,10 +1,10 @@ /* * @test /nodynamiccopyright/ - * @bug 7020044 + * @bug 7020044 8062373 * - * @summary Check that diamond is not allowed with anonymous inner class expressions + * @summary Check that diamond is not allowed with anonymous inner class expressions at source < 9 * @author Maurizio Cimadamore - * @compile/fail/ref=Neg09.out Neg09.java -XDrawDiagnostics + * @compile/fail/ref=Neg09.out Neg09.java -source 8 -XDrawDiagnostics * */ diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg09.out b/langtools/test/tools/javac/generics/diamond/neg/Neg09.out index 5893555fba8..af5238b72ca 100644 --- a/langtools/test/tools/javac/generics/diamond/neg/Neg09.out +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg09.out @@ -1,5 +1,7 @@ -Neg09.java:17:34: compiler.err.cant.apply.diamond.1: Neg09.Member, (compiler.misc.diamond.and.anon.class: Neg09.Member) -Neg09.java:18:34: compiler.err.cant.apply.diamond.1: Neg09.Nested, (compiler.misc.diamond.and.anon.class: Neg09.Nested) -Neg09.java:22:39: compiler.err.cant.apply.diamond.1: Neg09.Member, (compiler.misc.diamond.and.anon.class: Neg09.Member) -Neg09.java:23:40: compiler.err.cant.apply.diamond.1: Neg09.Nested, (compiler.misc.diamond.and.anon.class: Neg09.Nested) +- compiler.warn.source.no.bootclasspath: 1.8 +Neg09.java:17:34: compiler.err.cant.apply.diamond.1: Neg09.Member, (compiler.misc.diamond.and.anon.class.not.supported.in.source: 1.8) +Neg09.java:18:34: compiler.err.cant.apply.diamond.1: Neg09.Nested, (compiler.misc.diamond.and.anon.class.not.supported.in.source: 1.8) +Neg09.java:22:39: compiler.err.cant.apply.diamond.1: Neg09.Member, (compiler.misc.diamond.and.anon.class.not.supported.in.source: 1.8) +Neg09.java:23:40: compiler.err.cant.apply.diamond.1: Neg09.Nested, (compiler.misc.diamond.and.anon.class.not.supported.in.source: 1.8) 4 errors +1 warning diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg12.java b/langtools/test/tools/javac/generics/diamond/neg/Neg12.java new file mode 100644 index 00000000000..526f84626f5 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg12.java @@ -0,0 +1,33 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8062373 + * + * @summary Test diamond + anonymous classes with non-denotable types + * @author mcimadamore + * @compile/fail/ref=Neg12.out Neg12.java -XDrawDiagnostics + * + */ + + class Neg12 { + static class Foo { + Foo(X x) { } + } + + static class DoubleFoo { + DoubleFoo(X x,Y y) { } + } + + static class TripleFoo { + TripleFoo(X x,Y y,Z z) { } + } + + Foo fi = new Foo<>(1); + Foo fw = new Foo<>(fi) {}; // Error. + Foo fw1 = new Foo<>(fi); // OK. + Foo fd = new Foo<>(3.0); + DoubleFoo dw = new DoubleFoo<>(fi,fd) {}; // Error. + DoubleFoo dw1 = new DoubleFoo<>(fi,fd); // OK. + Foo fs = new Foo<>("one"); + TripleFoo tw = new TripleFoo<>(fi,fd,fs) {}; // Error. + TripleFoo tw1 = new TripleFoo<>(fi,fd,fs); // OK. + } diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg12.out b/langtools/test/tools/javac/generics/diamond/neg/Neg12.out new file mode 100644 index 00000000000..aaa54b38073 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg12.out @@ -0,0 +1,4 @@ +Neg12.java:25:24: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg12.Foo), (compiler.misc.diamond.invalid.arg: Neg12.Foo, (compiler.misc.diamond: Neg12.Foo)) +Neg12.java:28:38: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg12.DoubleFoo), (compiler.misc.diamond.invalid.args: Neg12.Foo,Neg12.Foo, (compiler.misc.diamond: Neg12.DoubleFoo)) +Neg12.java:31:40: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg12.TripleFoo), (compiler.misc.diamond.invalid.args: Neg12.Foo,Neg12.Foo, (compiler.misc.diamond: Neg12.TripleFoo)) +3 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg13.java b/langtools/test/tools/javac/generics/diamond/neg/Neg13.java new file mode 100644 index 00000000000..45c6ecaae98 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg13.java @@ -0,0 +1,49 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8062373 + * + * @summary Test diamond + anonymous classes with abstract super type + * @author sadayapalam + * @compile/fail/ref=Neg13.out Neg13.java -XDrawDiagnostics + * + */ +class Neg13 { + + static abstract class A { + abstract void foo(); + } + + static void foo(A as) {} + + public static void main(String[] args) { + + // Method invocation context - good <>(){} + foo(new A<>() { + public void foo() {} + }); + + // Assignment context - good <>(){} + A aq = new A<>() { + public void foo() {} + }; + + // When the anonymous type subtypes an abstract class but is missing definitions for + // abstract methods, expect no overload resolution error, but an attribution error + // while attributing anonymous class body. + + + // Method invocation context - bad <>(){} + foo(new A<>() { + }); + + // Assignment invocation context - bad <>(){} + aq = new A<>() { + }; + + // Method invocation context - bad <>() + foo(new A<>()); + + // Assignment invocation context - bad <>() + aq = new A<>(); + } +} diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg13.out b/langtools/test/tools/javac/generics/diamond/neg/Neg13.out new file mode 100644 index 00000000000..a179a772a54 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg13.out @@ -0,0 +1,5 @@ +Neg13.java:36:23: compiler.err.does.not.override.abstract: compiler.misc.anonymous.class: Neg13$3, foo(), Neg13.A +Neg13.java:40:24: compiler.err.does.not.override.abstract: compiler.misc.anonymous.class: Neg13$4, foo(), Neg13.A +Neg13.java:44:13: compiler.err.abstract.cant.be.instantiated: Neg13.A +Neg13.java:47:14: compiler.err.abstract.cant.be.instantiated: Neg13.A +4 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg14.java b/langtools/test/tools/javac/generics/diamond/neg/Neg14.java new file mode 100644 index 00000000000..0ad9114c784 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg14.java @@ -0,0 +1,49 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8062373 + * + * @summary Test diamond + anonymous classes with super type being an interface. + * @author sadayapalam + * @compile/fail/ref=Neg14.out Neg14.java -XDrawDiagnostics + * + */ +class Neg14 { + + static interface A { + void foo(); + } + + static void foo(A as) {} + + public static void main(String[] args) { + + // Method invocation context - good <>(){} + foo(new A<>() { + public void foo() {} + }); + + // Assignment context - good <>(){} + A aq = new A<>() { + public void foo() {} + }; + + // When the anonymous type subtypes an interface but is missing definitions for + // abstract methods, expect no overload resolution error, but an attribution error + // while attributing anonymous class body. + + + // Method invocation context - bad <>(){} + foo(new A<>() { + }); + + // Assignment invocation context - bad <>(){} + aq = new A<>() { + }; + + // Method invocation context - bad <>() + foo(new A<>()); + + // Assignment invocation context - bad <>() + aq = new A<>(); + } +} diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg14.out b/langtools/test/tools/javac/generics/diamond/neg/Neg14.out new file mode 100644 index 00000000000..8b0514018a7 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg14.out @@ -0,0 +1,5 @@ +Neg14.java:36:23: compiler.err.does.not.override.abstract: compiler.misc.anonymous.class: Neg14$3, foo(), Neg14.A +Neg14.java:40:24: compiler.err.does.not.override.abstract: compiler.misc.anonymous.class: Neg14$4, foo(), Neg14.A +Neg14.java:44:13: compiler.err.abstract.cant.be.instantiated: Neg14.A +Neg14.java:47:14: compiler.err.abstract.cant.be.instantiated: Neg14.A +4 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg15.java b/langtools/test/tools/javac/generics/diamond/neg/Neg15.java new file mode 100644 index 00000000000..2c0d28607fa --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg15.java @@ -0,0 +1,66 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8062373 + * + * @summary Test that javac complains when a <> inferred class contains a public method that does override a supertype method. + * @author sadayapalam + * @compile/fail/ref=Neg15.out Neg15.java -XDrawDiagnostics + * + */ + +class Neg15 { + + interface Predicate { + default boolean test(T t) { + System.out.println("Default method"); + return false; + } + } + + + static void someMethod(Predicate p) { + if (!p.test(null)) + throw new Error("Blew it"); + } + + public static void main(String[] args) { + + someMethod(new Predicate() { + public boolean test(Integer n) { + System.out.println("Override"); + return true; + } + boolean test(Integer n, int i) { + System.out.println("Override"); + return true; + } + protected boolean test(Integer n, int i, int j) { + System.out.println("Override"); + return true; + } + private boolean test(Integer n, int i, long j) { + System.out.println("Override"); + return true; + } + }); + + someMethod(new Predicate<>() { + public boolean test(Integer n) { // bad. + System.out.println("Override"); + return true; + } + boolean test(Integer n, int i) { // bad, package access. + System.out.println("Override"); + return true; + } + protected boolean test(Integer n, int i, int j) { // bad, protected access. + System.out.println("Override"); + return true; + } + private boolean test(Integer n, int i, long j) { // OK, private method. + System.out.println("Override"); + return true; + } + }); + } +} diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg15.out b/langtools/test/tools/javac/generics/diamond/neg/Neg15.out new file mode 100644 index 00000000000..1e6f1efa8ac --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg15.out @@ -0,0 +1,4 @@ +Neg15.java:48:28: compiler.err.method.does.not.override.superclass +Neg15.java:52:21: compiler.err.method.does.not.override.superclass +Neg15.java:56:31: compiler.err.method.does.not.override.superclass +3 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg16.java b/langtools/test/tools/javac/generics/diamond/neg/Neg16.java new file mode 100644 index 00000000000..775c17231d5 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg16.java @@ -0,0 +1,36 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8062373 + * @summary Test that javac does not recommend a diamond site that would result in error. + * @compile/ref=Neg16.out -Xlint:-options Neg16.java -XDrawDiagnostics -XDfind=diamond + */ + +class Neg16 { + + interface Predicate { + default boolean test(T t) { + System.out.println("Default method"); + return false; + } + } + + static void someMethod(Predicate p) { + if (!p.test(null)) + throw new Error("Blew it"); + } + + public static void main(String[] args) { + someMethod(new Predicate() { // cannot convert to diamond + public boolean test(Integer n) { + System.out.println("Override"); + return true; + } + }); + someMethod(new Predicate() { // can convert to diamond. + public boolean test(Number n) { + System.out.println("Override"); + return true; + } + }); + } +} diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg16.out b/langtools/test/tools/javac/generics/diamond/neg/Neg16.out new file mode 100644 index 00000000000..712aa4fba63 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg16.out @@ -0,0 +1,2 @@ +Neg16.java:29:33: compiler.warn.diamond.redundant.args +1 warning diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg17.java b/langtools/test/tools/javac/generics/diamond/neg/Neg17.java new file mode 100644 index 00000000000..960fbd77a63 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg17.java @@ -0,0 +1,21 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8062373 + * @summary Test that the anonymous class constructor appears to returns a Foo, when it actually returns a Anon$1. (status as of now - may change in future) + * @compile/fail/ref=Neg17.out Neg17.java -XDrawDiagnostics + */ + +import java.util.Collections; + +abstract class Neg17 { + + abstract void m(); + + public static void main(String[] args) { + Collections.singletonList(new Neg17<>() { void m() {} }).get(0).m(); // good. + Collections.singletonList(new Neg17<>() { + void m() {} + private void n() {} + }).get(0).n(); // bad unknown method n() + } +} diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg17.out b/langtools/test/tools/javac/generics/diamond/neg/Neg17.out new file mode 100644 index 00000000000..aeb7601d59b --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg17.out @@ -0,0 +1,2 @@ +Neg17.java:19:21: compiler.err.cant.resolve.location.args: kindname.method, n, , , (compiler.misc.location: kindname.class, Neg17, null) +1 error diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg18.java b/langtools/test/tools/javac/generics/diamond/neg/Neg18.java new file mode 100644 index 00000000000..4acb7ef2f09 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg18.java @@ -0,0 +1,16 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8062373 + * @summary Test that inaccessible vararg element type triggers an error during diamond inferred anonymous class instance creation. + * @compile/fail/ref=Neg18.out Neg18.java -XDrawDiagnostics + */ + +import java.util.Collections; +import pkg.Neg18_01; + +class Neg18 { + + public static void main(String[] args) { + new Neg18_01<>() {}; + } +} diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg18.out b/langtools/test/tools/javac/generics/diamond/neg/Neg18.out new file mode 100644 index 00000000000..edbff10f635 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg18.out @@ -0,0 +1,3 @@ +Neg18.java:14:21: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: pkg.Neg18_01), (compiler.misc.inaccessible.varargs.type: pkg.Neg18_01.PkgPrivate, kindname.class, Neg18)) +Neg18.java:14:26: compiler.err.not.def.public.cant.access: pkg.Neg18_01.PkgPrivate, pkg.Neg18_01 +2 errors diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg19.java b/langtools/test/tools/javac/generics/diamond/neg/Neg19.java new file mode 100644 index 00000000000..173a72a8db9 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg19.java @@ -0,0 +1,21 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8062373 + * @summary Test that when inaccessible types constitute the inferred types of <> the compiler complains. + * @compile/fail/ref=Neg19.out Neg19.java -XDrawDiagnostics + */ + + + +class Neg19 { + public static void main(String[] args) { + new Neg19_01().foo(new Neg19_01<>()); // OK. + new Neg19_01().foo(new Neg19_01<>() {}); // ERROR. + } +} + +class Neg19_01 { + private class Private {} + Neg19_01() {} + void foo(Neg19_01 p) {} +} diff --git a/langtools/test/tools/javac/generics/diamond/neg/Neg19.out b/langtools/test/tools/javac/generics/diamond/neg/Neg19.out new file mode 100644 index 00000000000..aaba880ed1c --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg19.out @@ -0,0 +1,2 @@ +Neg19.java:13:34: compiler.err.report.access: Neg19_01.Private, private, Neg19_01 +1 error diff --git a/langtools/test/tools/javac/generics/diamond/neg/pkg/Neg18_01.java b/langtools/test/tools/javac/generics/diamond/neg/pkg/Neg18_01.java new file mode 100644 index 00000000000..569096025a4 --- /dev/null +++ b/langtools/test/tools/javac/generics/diamond/neg/pkg/Neg18_01.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015, 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. + * + * 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 pkg; + +public class Neg18_01 { + static class PkgPrivate {} + public Neg18_01 (PkgPrivate ... pp) {} +} diff --git a/langtools/test/tools/javac/generics/diamond/pos/Pos01.java b/langtools/test/tools/javac/generics/diamond/pos/Pos01.java index 1ae7f9bf76b..9a60314f4a8 100644 --- a/langtools/test/tools/javac/generics/diamond/pos/Pos01.java +++ b/langtools/test/tools/javac/generics/diamond/pos/Pos01.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary basic test for diamond (generic/non-generic constructors) * @author mcimadamore @@ -48,7 +48,17 @@ public class Pos01 { Pos01 p6 = new Pos01<>(1, ""); Pos01 p7 = new Pos01<>(1, ""); Pos01 p8 = new Pos01<>(1, ""); - } + + Pos01 p9 = new Pos01<>(1){}; + Pos01 p10 = new Pos01<>(1){}; + Pos01 p11 = new Pos01<>(1){}; + Pos01 p12 = new Pos01<>(1){}; + + Pos01 p13 = new Pos01<>(1, ""){}; + Pos01 p14= new Pos01<>(1, ""){}; + Pos01 p15 = new Pos01<>(1, ""){}; + Pos01 p16 = new Pos01<>(1, ""){}; + } public static void main(String[] args) { Pos01 p1 = new Pos01<>(""); diff --git a/langtools/test/tools/javac/generics/diamond/pos/Pos02.java b/langtools/test/tools/javac/generics/diamond/pos/Pos02.java index 835020c40a1..72800e1814f 100644 --- a/langtools/test/tools/javac/generics/diamond/pos/Pos02.java +++ b/langtools/test/tools/javac/generics/diamond/pos/Pos02.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary basic test for diamond (simple/qualified type-expressions) * @author mcimadamore @@ -48,6 +48,16 @@ public class Pos02 { Foo f6 = new Foo<>(1, ""); Foo f7 = new Foo<>(1, ""); Foo f8 = new Foo<>(1, ""); + + Foo f9 = new Foo<>(1){}; + Foo f10 = new Foo<>(1){}; + Foo f11 = new Foo<>(1){}; + Foo f12 = new Foo<>(1){}; + + Foo f13 = new Foo<>(1, ""){}; + Foo f14 = new Foo<>(1, ""){}; + Foo f15 = new Foo<>(1, ""){}; + Foo f16 = new Foo<>(1, ""){}; } void testQualified() { @@ -60,6 +70,16 @@ public class Pos02 { Foo f6 = new Pos02.Foo<>(1, ""); Foo f7 = new Pos02.Foo<>(1, ""); Foo f8 = new Pos02.Foo<>(1, ""); + + Foo f9 = new Pos02.Foo<>(1){}; + Foo f10 = new Pos02.Foo<>(1){}; + Foo f11 = new Pos02.Foo<>(1){}; + Foo f12 = new Pos02.Foo<>(1){}; + + Foo f13 = new Pos02.Foo<>(1, ""){}; + Foo f14 = new Pos02.Foo<>(1, ""){}; + Foo f15 = new Pos02.Foo<>(1, ""){}; + Foo f16 = new Pos02.Foo<>(1, ""){}; } public static void main(String[] args) { diff --git a/langtools/test/tools/javac/generics/diamond/pos/Pos03.java b/langtools/test/tools/javac/generics/diamond/pos/Pos03.java index 9f975cfc642..aa7fed2f464 100644 --- a/langtools/test/tools/javac/generics/diamond/pos/Pos03.java +++ b/langtools/test/tools/javac/generics/diamond/pos/Pos03.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary basic test for diamond (simple/qualified type-expressions, member inner) * @author mcimadamore @@ -49,6 +49,16 @@ public class Pos03 { Foo f6 = new Foo<>(1, ""); Foo f7 = new Foo<>(1, ""); Foo f8 = new Foo<>(1, ""); + + Foo f9 = new Foo<>(1){}; + Foo f10 = new Foo<>(1){}; + Foo f11 = new Foo<>(1){}; + Foo f12 = new Foo<>(1){}; + + Foo f13 = new Foo<>(1, ""){}; + Foo f14 = new Foo<>(1, ""){}; + Foo f15 = new Foo<>(1, ""){}; + Foo f16 = new Foo<>(1, ""){}; } void testQualified_1() { @@ -61,6 +71,16 @@ public class Pos03 { Foo f6 = new Pos03.Foo<>(1, ""); Foo f7 = new Pos03.Foo<>(1, ""); Foo f8 = new Pos03.Foo<>(1, ""); + + Foo f9 = new Pos03.Foo<>(1){}; + Foo f10 = new Pos03.Foo<>(1){}; + Foo f11 = new Pos03.Foo<>(1){}; + Foo f12 = new Pos03.Foo<>(1){}; + + Foo f13 = new Pos03.Foo<>(1, ""){}; + Foo f14 = new Pos03.Foo<>(1, ""){}; + Foo f15 = new Pos03.Foo<>(1, ""){}; + Foo f16 = new Pos03.Foo<>(1, ""){}; } void testQualified_2(Pos03 p) { @@ -73,6 +93,16 @@ public class Pos03 { Foo f6 = p.new Foo<>(1, ""); Foo f7 = p.new Foo<>(1, ""); Foo f8 = p.new Foo<>(1, ""); + + Foo f9 = p.new Foo<>(1){}; + Foo f10 = p.new Foo<>(1){}; + Foo f11 = p.new Foo<>(1){}; + Foo f12 = p.new Foo<>(1){}; + + Foo f13 = p.new Foo<>(1, ""){}; + Foo f14 = p.new Foo<>(1, ""){}; + Foo f15 = p.new Foo<>(1, ""){}; + Foo f16 = p.new Foo<>(1, ""){}; } public static void main(String[] args) { diff --git a/langtools/test/tools/javac/generics/diamond/pos/Pos04.java b/langtools/test/tools/javac/generics/diamond/pos/Pos04.java index c0a3516f91e..664cfa1ea75 100644 --- a/langtools/test/tools/javac/generics/diamond/pos/Pos04.java +++ b/langtools/test/tools/javac/generics/diamond/pos/Pos04.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary basic test for diamond (simple/qualified type-expressions, local class) * @author mcimadamore @@ -48,6 +48,16 @@ public class Pos04 { Foo p6 = new Foo<>(1, ""); Foo p7 = new Foo<>(1, ""); Foo p8 = new Foo<>(1, ""); + + Foo p9 = new Foo<>(1){}; + Foo p10 = new Foo<>(1){}; + Foo p11 = new Foo<>(1){}; + Foo p12 = new Foo<>(1){}; + + Foo p13 = new Foo<>(1, ""){}; + Foo p14 = new Foo<>(1, ""){}; + Foo p15 = new Foo<>(1, ""){}; + Foo p16 = new Foo<>(1, ""){}; } public static void main(String[] args) { diff --git a/langtools/test/tools/javac/generics/diamond/pos/Pos05.java b/langtools/test/tools/javac/generics/diamond/pos/Pos05.java index 9223ae8f2a7..74fc84cf388 100644 --- a/langtools/test/tools/javac/generics/diamond/pos/Pos05.java +++ b/langtools/test/tools/javac/generics/diamond/pos/Pos05.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -23,11 +23,10 @@ /* * @test - * @bug 6939620 7020044 + * @bug 6939620 7020044 8062373 * * @summary Check that 'complex' inference sometimes works in method context * @author mcimadamore - * @compile Pos05.java * */ @@ -41,5 +40,11 @@ public class Pos05 { void test() { m(new Foo<>(1)); + m(new Foo<>(1) {}); } + + public static void main(String [] args) { + new Pos05().test(); + } + } diff --git a/langtools/test/tools/javac/generics/inference/8055963/T8055963.java b/langtools/test/tools/javac/generics/inference/8055963/T8055963.java index 82f00275b8d..0d4e12076d5 100644 --- a/langtools/test/tools/javac/generics/inference/8055963/T8055963.java +++ b/langtools/test/tools/javac/generics/inference/8055963/T8055963.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -25,11 +25,10 @@ /** * @test - * @bug 8055963 + * @bug 8055963 8062373 * @summary Inference failure with nested invocation - * @compile T8055963.java */ -class T8055963 { +public class T8055963 { static class C {} @@ -38,4 +37,8 @@ class T8055963 { void test() { C cs = choose(new C(), new C<>()); } + + public static void main(String [] args) { + new T8055963().test(); + } } diff --git a/langtools/test/tools/javac/lambda/8066974/T8066974.java b/langtools/test/tools/javac/lambda/8066974/T8066974.java index 8f47277f734..fd8119dd970 100644 --- a/langtools/test/tools/javac/lambda/8066974/T8066974.java +++ b/langtools/test/tools/javac/lambda/8066974/T8066974.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 8066974 + * @bug 8066974 8062373 * @summary Compiler doesn't infer method's generic type information in lambda body * @compile/fail/ref=T8066974.out -XDrawDiagnostics T8066974.java */ @@ -34,11 +34,13 @@ class T8066974 { map(p->p.m(rt)); map(mapper(rt)); map(new ThrowingMapper<>(rt)); + map(new ThrowingMapper<>(rt) {}); } void testChecked(CheckedThrowing ct) { map(p->p.m(ct)); map(mapper(ct)); map(new ThrowingMapper<>(ct)); + map(new ThrowingMapper<>(ct) {}); } } diff --git a/langtools/test/tools/javac/lambda/8066974/T8066974.out b/langtools/test/tools/javac/lambda/8066974/T8066974.out index 59772fc59a4..101a18ac191 100644 --- a/langtools/test/tools/javac/lambda/8066974/T8066974.out +++ b/langtools/test/tools/javac/lambda/8066974/T8066974.out @@ -1,4 +1,5 @@ -T8066974.java:40:19: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception T8066974.java:41:19: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception -T8066974.java:42:13: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception -3 errors +T8066974.java:42:19: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception +T8066974.java:43:13: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception +T8066974.java:44:13: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception +4 errors diff --git a/langtools/test/tools/javac/lambda/TargetType46.java b/langtools/test/tools/javac/lambda/TargetType46.java index da371231427..680ff3a7bed 100644 --- a/langtools/test/tools/javac/lambda/TargetType46.java +++ b/langtools/test/tools/javac/lambda/TargetType46.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 8003280 + * @bug 8003280 8062373 * @summary Add lambda tests * compiler doesn't report accessibility problem due to inaccessible target * @compile/fail/ref=TargetType46.out -XDrawDiagnostics TargetType46.java @@ -22,6 +22,7 @@ class TargetType46 { outer.m(()->{}); //access error outer.m(this::g); //access error outer.m(new ArrayList<>()); //ok + outer.m(new ArrayList<>() {}); // access error outer.m(Collections.emptyList()); //ok } diff --git a/langtools/test/tools/javac/lambda/TargetType46.out b/langtools/test/tools/javac/lambda/TargetType46.out index ac3a1254589..30cd7034217 100644 --- a/langtools/test/tools/javac/lambda/TargetType46.out +++ b/langtools/test/tools/javac/lambda/TargetType46.out @@ -1,3 +1,4 @@ TargetType46.java:22:17: compiler.err.report.access: TargetType46Outer.PI, private, TargetType46Outer TargetType46.java:23:17: compiler.err.report.access: TargetType46Outer.PI, private, TargetType46Outer -2 errors +TargetType46.java:25:16: compiler.err.report.access: TargetType46Outer.PI, private, TargetType46Outer +3 errors diff --git a/langtools/test/tools/javac/lambda/TargetType68.java b/langtools/test/tools/javac/lambda/TargetType68.java index 92ce99bd8ad..13cad4f16b0 100644 --- a/langtools/test/tools/javac/lambda/TargetType68.java +++ b/langtools/test/tools/javac/lambda/TargetType68.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -23,9 +23,9 @@ /* * @test - * @bug 8010303 + * @bug 8010303 8062373 * @summary Graph inference: missing incorporation step causes spurious inference error - * @compile TargetType68.java + * @compile/fail/ref=TargetType68.out -XDrawDiagnostics TargetType68.java */ import java.util.*; @@ -58,6 +58,6 @@ class TargetType68 { List> data_2 = new ArrayList<>(); numberChart.getData().setAll( Arrays.asList(new XYChart.Series<>("Data", FXCollections.observableList(data_1)), - new XYChart.Series<>("Data", FXCollections.observableList(data_2)))); + new XYChart.Series<>("Data", FXCollections.observableList(data_2)) {})); } } diff --git a/langtools/test/tools/javac/lambda/TargetType68.out b/langtools/test/tools/javac/lambda/TargetType68.out new file mode 100644 index 00000000000..6dd8e49c233 --- /dev/null +++ b/langtools/test/tools/javac/lambda/TargetType68.out @@ -0,0 +1,3 @@ +TargetType68.java:61:32: compiler.err.cant.inherit.from.final: TargetType68.XYChart.Series +TargetType68.java:61:39: compiler.err.cant.inherit.from.final: TargetType68.XYChart.Series +2 errors diff --git a/langtools/test/tools/javac/lambda/TargetType69.java b/langtools/test/tools/javac/lambda/TargetType69.java index 065c1e95fb2..46b7a22ce9b 100644 --- a/langtools/test/tools/javac/lambda/TargetType69.java +++ b/langtools/test/tools/javac/lambda/TargetType69.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8010303 + * @bug 8010303 8062373 * @summary Graph inference: missing incorporation step causes spurious inference error * @compile TargetType69.java */ @@ -47,5 +47,6 @@ class TargetType69 { void test(Function classifier, Function>> coll) { exerciseMapTabulation(coll, new GroupedMapAssertion<>(classifier)); + exerciseMapTabulation(coll, new GroupedMapAssertion<>(classifier) {}); } } diff --git a/langtools/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java b/langtools/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java index d63f7734dbf..813c588349f 100644 --- a/langtools/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java +++ b/langtools/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -108,9 +108,10 @@ public class FDTest { public static List> generateCases() { ArrayList> list = new ArrayList<>(); HierarchyGenerator hg = new HierarchyGenerator(); + int i = 0; for (TestKind tk : TestKind.values()) { for (Hierarchy hs : tk.getHierarchy(hg)) { - list.add(new Pair<>(tk, hs)); + list.add((i++ % 2) == 0 ? new Pair<>(tk, hs) {} : new Pair<>(tk, hs)); } } return list; diff --git a/langtools/test/tools/javac/scope/DupUnsharedTest.java b/langtools/test/tools/javac/scope/DupUnsharedTest.java index 7506648aa85..b60a2d1c7cb 100644 --- a/langtools/test/tools/javac/scope/DupUnsharedTest.java +++ b/langtools/test/tools/javac/scope/DupUnsharedTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015 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 @@ -68,7 +68,7 @@ public class DupUnsharedTest { } void runScopeContentTest() throws Exception { - Set expected = Collections.newSetFromMap(new IdentityHashMap<>()); + Set expected = Collections.newSetFromMap(new IdentityHashMap<>() {}); Set notExpected = Collections.newSetFromMap(new IdentityHashMap<>()); WriteableScope s1 = WriteableScope.create(symtab.rootPackage); ClassSymbol acceptSym = symtab.arrayClass; @@ -105,7 +105,7 @@ public class DupUnsharedTest { } Set toSet(Iterable it) { - Set result = Collections.newSetFromMap(new IdentityHashMap<>()); + Set result = Collections.newSetFromMap(new IdentityHashMap<>() {}); for (Symbol sym : it) { result.add(sym); From 68593842f8cc6aa71e6ca59a452a1d90f1a96ad4 Mon Sep 17 00:00:00 2001 From: Srikanth Adayapalam Date: Mon, 23 Mar 2015 09:48:37 +0530 Subject: [PATCH 101/362] 7040592: Gen.java: fix code for handling 'null' literal when expected type is array Eliminate needless checkcast when null is assigned to a multi-dimensional array typedobject Reviewed-by: mcimadamore --- .../classes/com/sun/tools/javac/jvm/Code.java | 8 +- .../classes/com/sun/tools/javac/jvm/Gen.java | 14 ++-- .../CoerceNullToMoreSpecificTypeTest.java | 66 +++++++++++++++++ .../test/tools/javac/T7040592/T7040592.java | 74 +++++++++++++++++++ 4 files changed, 150 insertions(+), 12 deletions(-) create mode 100644 langtools/test/tools/javac/T7040592/CoerceNullToMoreSpecificTypeTest.java create mode 100644 langtools/test/tools/javac/T7040592/T7040592.java diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java index 09459431696..305847f6ac3 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java @@ -497,13 +497,9 @@ public class Code { case aaload: { state.pop(1);// index Type a = state.stack[state.stacksize-1]; + Assert.check(!a.hasTag(BOT)); // null type as is cannot be indexed. state.pop(1); - //sometimes 'null type' is treated as a one-dimensional array type - //see Gen.visitLiteral - we should handle this case accordingly - Type stackType = a.hasTag(BOT) ? - syms.objectType : - types.erasure(types.elemtype(a)); - state.push(stackType); } + state.push(types.erasure(types.elemtype(a))); } break; case goto_: markDead(); diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java index 67f47e6b8e6..402ae13470b 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java @@ -1860,6 +1860,13 @@ public class Gen extends JCTree.Visitor { public void visitAssign(JCAssign tree) { Item l = genExpr(tree.lhs, tree.lhs.type); genExpr(tree.rhs, tree.lhs.type).load(); + if (tree.rhs.type.hasTag(BOT)) { + /* This is just a case of widening reference conversion that per 5.1.5 simply calls + for "regarding a reference as having some other type in a manner that can be proved + correct at compile time." + */ + code.state.forceStackTop(tree.lhs.type); + } result = items.makeAssignItem(l); } @@ -2272,12 +2279,7 @@ public class Gen extends JCTree.Visitor { public void visitLiteral(JCLiteral tree) { if (tree.type.hasTag(BOT)) { code.emitop0(aconst_null); - if (types.dimensions(pt) > 1) { - code.emitop2(checkcast, makeRef(tree.pos(), pt)); - result = items.makeStackItem(pt); - } else { - result = items.makeStackItem(tree.type); - } + result = items.makeStackItem(tree.type); } else result = items.makeImmediateItem(tree.type, tree.value); diff --git a/langtools/test/tools/javac/T7040592/CoerceNullToMoreSpecificTypeTest.java b/langtools/test/tools/javac/T7040592/CoerceNullToMoreSpecificTypeTest.java new file mode 100644 index 00000000000..ba84ef5f795 --- /dev/null +++ b/langtools/test/tools/javac/T7040592/CoerceNullToMoreSpecificTypeTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 7040592 + * @summary Test that the assertion in State.forceStackTop does not fail at compile time. + */ + +import java.lang.reflect.Field; +import java.util.ArrayList; +import org.w3c.dom.Element; + +public class CoerceNullToMoreSpecificTypeTest { + abstract class NodeImpl { + } + + NodeImpl ownerNode; + + public Element getElement() { + return (Element) (isOwned() ? ownerNode : null); + } + + boolean isOwned() { + return true; + } + + static void processArrays(boolean expectNulls, Object [] nulla, Object [][] nullaa) { + if (expectNulls) { + if (nulla != null || nullaa != null) { + throw new AssertionError("Null actual, but not null formal"); + } + } else { + if (nulla.length != 123 || nullaa.length != 321) + throw new AssertionError("Wrong arrays received"); + } + } + + public static void main(String[] args) { + ArrayList> typeList = new ArrayList<>(); + Field rf = null; + typeList.add((rf != null) ? rf.getType() : null); + processArrays(true, null, null); + processArrays(false, new Object[123], new Object[321][]); + } +} diff --git a/langtools/test/tools/javac/T7040592/T7040592.java b/langtools/test/tools/javac/T7040592/T7040592.java new file mode 100644 index 00000000000..04939cbcc2b --- /dev/null +++ b/langtools/test/tools/javac/T7040592/T7040592.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 7040592 + * @summary Verify that null can be assigned freely to array types without a checkcast + */ + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.Paths; + +public class T7040592 { + + private static final String assertionErrorMsg = + "null should be assignable to array type without a checkcast"; + + public static void main(String[] args) { + new T7040592().run(); + } + + void run() { + check("-c", Paths.get(System.getProperty("test.classes"), + "T7040592_01.class").toString()); + } + + void check(String... params) { + StringWriter s; + String out; + try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { + com.sun.tools.javap.Main.run(params, pw); + out = s.toString(); + } + if (out.contains("checkcast")) { + throw new AssertionError(assertionErrorMsg); + } + } + +} + +class T7040592_01 { + static void handleArrays(Object [] a, Object [][] b, Object [][][] c) { + } + public static void main(String[] args) { + Object a[]; + Object o = (a = null)[0]; + Object b[][]; + o = (b = null)[0][0]; + Object c[][][]; + o = (c = null)[0][0][0]; + handleArrays(null, null, null); + } +} From 35c411ea7e09c8d3f1a944efc55864cae0763d95 Mon Sep 17 00:00:00 2001 From: Zaiyao Liu Date: Mon, 23 Mar 2015 15:37:03 +0800 Subject: [PATCH 102/362] 8048618: Tests for PKCS12 write operations Reviewed-by: weijun --- .../KeyStore/PKCS12/WriteP12Test.java | 371 ++++++++++++++++++ .../PKCS12/certs/writeP12/keystoreCA.jks.data | 38 ++ .../PKCS12/certs/writeP12/keystoreEU.jks.data | 79 ++++ 3 files changed, 488 insertions(+) create mode 100644 jdk/test/java/security/KeyStore/PKCS12/WriteP12Test.java create mode 100644 jdk/test/java/security/KeyStore/PKCS12/certs/writeP12/keystoreCA.jks.data create mode 100644 jdk/test/java/security/KeyStore/PKCS12/certs/writeP12/keystoreEU.jks.data diff --git a/jdk/test/java/security/KeyStore/PKCS12/WriteP12Test.java b/jdk/test/java/security/KeyStore/PKCS12/WriteP12Test.java new file mode 100644 index 00000000000..f4024090f2f --- /dev/null +++ b/jdk/test/java/security/KeyStore/PKCS12/WriteP12Test.java @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2003, 2015, 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. + * + * 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. + */ + +import static java.lang.System.out; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.Key; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.UnrecoverableKeyException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.Base64; +import java.util.Enumeration; + +/* + * @test + * @bug 8048618 + * @summary Write different types p12 key store to Check the write related + * APIs. + * @run main WriteP12Test + */ + +public class WriteP12Test { + + private static final String IN_KEYSTORE_TYPE = "jks"; + private static final String IN_KEYSTORE_PRV = "SUN"; + + private static final String IN_KEYSTORE_ENDUSER = "keystoreEU.jks.data"; + private static final String IN_KEYSTORE_CA = "keystoreCA.jks.data"; + private static final String OUT_KEYSTORE = "outKeyStore.p12"; + + private static final String IN_STORE_PASS = "storepass"; + private static final String IN_KEY_PASS = "keypass"; + + private static final String CERT_PATH = System.getProperty("test.src", ".") + + File.separator + "certs" + File.separator + "writeP12" + + File.separator; + + private static final String CA_CERT_STR = "-----BEGIN CERTIFICATE-----\n" + + "MIIDFzCCAf8CBD8+0nAwDQYJKoZIhvcNAQEFBQAwUDELMAkGA1UEBhMCV\n" + + "VMxETAPBgNVBAoTCEphdmFTb2Z0MRUwEwYDVQQLEwxTZWN1cml0eSBTUU\n" + + "UxFzAVBgNVBAMTDlBLQ1MxMiBUZXN0IENBMB4XDTAzMDgxNzAwNTUxMlo\n" + + "XDTEzMDgxNDAwNTUxMlowUDELMAkGA1UEBhMCVVMxETAPBgNVBAoTCEph\n" + + "dmFTb2Z0MRUwEwYDVQQLEwxTZWN1cml0eSBTUUUxFzAVBgNVBAMTDlBLQ\n" + + "1MxMiBUZXN0IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQ\n" + + "EAk7Sh+K/yGsmJacZnjfkZfuWxGNJCPW0q69exwoRP+eBHMQwG00yi9aL\n" + + "SsZAqNpJSCDvpgySOAUmBd+f8WFhHqJfRVREVfv3mradDKZCjhqtsUI7I\n" + + "wRTYYy9clFkeeK4dHaxbuFMPpUu7yQfwSTXgvOA/UJ4kJuGtaYAdTJI4e\n" + + "f1mUASo6+dea0UZA/FHCuV7O6z3hr5VHlyhJL2/o/8M5tGBTBISODJSnn\n" + + "GNBvtQLNHnWYvs470UAE2BtuCGYh1V/3HAH1tRirS3MBBcb1XnIkiiXR3\n" + + "tjaBSB+XhoCfuG8KtInXXFaAnvKfY9mYFw6VJt9JYQpY2VDC7281/Pbz0\n" + + "dQIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQBzXZ8zHWrnC8/E+N/n2Czhx\n" + + "i18YQc2LPWBDLYTTxoFEazWmYLv1k/JT7Nta1qu1quvxXJ4uV1XHbd9NF\n" + + "AJWKwtFQEpfv4o6I7qWUPoxnfA+jyqKXxv27z25tzt+Y4xOEhqvO03G0Q\n" + + "imhkiNt9MF7L69y2U0/U73+uFNGzdAEDiI9EibvICiOnr1TeQ5GekK3Yb\n" + + "k5qe3lviMZPkkSXepTJI8m0AiXCji+eXj97jVLeH+RxeBchBY+uELrqUr\n" + + "sVOVWh7IBCqC/V7FqUTkmD1IFlzkkinatpl42s1MbhJId2yQkzaeBRc\n" + + "suE63bDEtuRWp9ynMO3QA4Yu85uBRWGzQ1Di\n" + + "-----END CERTIFICATE-----"; + private static final String LEAD_CERT = "-----BEGIN CERTIFICATE-----\n" + + "MIICwDCCAaigAwIBAgIEPz7S1jANBgkqhkiG9w0BAQQFADBQMQswCQYDV\n" + + "QQGEwJVUzERMA8GA1UEChMISmF2YVNvZnQxFTATBgNVBAsTDFNlY3VyaX\n" + + "R5IFNRRTEXMBUGA1UEAxMOUEtDUzEyIFRlc3QgQ0EwHhcNMDAwODA5MDc\n" + + "wMDAwWhcNMTAwODA3MDcwMDAwWjBSMQswCQYDVQQGEwJVUzERMA8GA1UE\n" + + "ChMISmF2YVNvZnQxFTATBgNVBAsTDFNlY3VyaXR5IFNRRTEZMBcGA1UEA\n" + + "xMQUEtDUzEyIFRlc3QgTGVhZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgY\n" + + "kCgYEAzq9X2USz/WjDhT+jUyZWqB5h4A33tS11YqH5qYvqjTXjcUI6gOp\n" + + "moXMafDG9RHRlIccvp51xLp7Ap3WMrv411lWBttqtZi5c1/DEC1cEM/Sl\n" + + "PCk1r2zFbkJu7QKieXeMcrjZEo6LcBHMwQjIpI+up9cr3VjuyqG/olQkU\n" + + "mXVuS0CAwEAAaMkMCIwDwYDVR0PAQH/BAUDAweAADAPBgNVHRMBAf8EBT\n" + + "ADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBhbuim98TWmtv9vSldRE7RvQ8\n" + + "FlS0TyZVO7kcSNtfCUE4R76J1ElN74Koc5pQnUtduLeQJs2ao/mEcCZsE\n" + + "zVcwI3mSZrSzPhc8s7w5gOQA4TUwVLSSjKgBCaZ7R3+qJ3QeqPJ5O6sFz\n" + + "pvBYkgSa4MWptK41jbmT8cwZQJXFCi8WxFFJ+p97F1Ppm3LgmYmtiUP4M\n" + + "ZQwOBvpTZWXU0WrqFXpzWQx0mg4SX19fZm4nLcJAerCEUphf8ILagtpQM\n" + + "EErT3/jg6mfCdT3Rj055QXPfF4OiRFevPF5a1fZgrCePCukRQZcd7s8K5\n" + + "OBIaryuM0MdFtlzxi6XWeUNpVFFHURcy\n" + + "-----END CERTIFICATE-----"; + private static final String END_CERT = "-----BEGIN CERTIFICATE-----\n" + + "MIICNjCCAZ+gAwIBAgIEPz7WtzANBgkqhkiG9w0BAQQFADBSMQswCQYDV\n" + + "QQGEwJVUzERMA8GA1UEChMISmF2YVNvZnQxFTATBgNVBAsTDFNlY3VyaX\n" + + "R5IFNRRTEZMBcGA1UEAxMQUEtDUzEyIFRlc3QgTGVhZDAeFw0wMDA4MDk\n" + + "wNzAwMDBaFw0xMDA4MDcwNzAwMDBaMFgxCzAJBgNVBAYTAlVTMREwDwYD\n" + + "VQQKEwhKYXZhU29mdDEVMBMGA1UECxMMU2VjdXJpdHkgU1FFMR8wHQYDV\n" + + "QQDExZQS0NTMTIgVGVzdCBFbmQgVXNlciAxMIGfMA0GCSqGSIb3DQEBAQ\n" + + "UAA4GNADCBiQKBgQDIKomSYomDzH/V63eDQEG7od0DLcnnVZ81pbWhDss\n" + + "8gHV2m8pADdRqdihBmnSQEaMW4D3uZ4sFE1LtkQls6hjd7SdOsG5Y24L8\n" + + "15jot9a2JcB73H8H0VKirrObL5BZdt7BtASPDnYtW4Spt++YjDoJFxyF0\n" + + "HchkavzXaVTlexakwIDAQABoxMwETAPBgNVHQ8BAf8EBQMDB4AAMA0GCS\n" + + "qGSIb3DQEBBAUAA4GBAIFA3JXEmb9AXn3RD7t+Mn6DoyVDIy5jsn6xOKT\n" + + "JV25I0obpDUzgw4QaAMmM0ZvusOmZ2wZNS8MtyTUgdANyakbzn5SdxbTy\n" + + "TLEqQsFbX8UVC38fx5ZM6ExA5YSAvgmXudZpOVC0ATccoZS3JFU8CxSfW\n" + + "+Q3IC2MLh+QTg3hUJ5b\n-----END CERTIFICATE-----"; + + private final Certificate testerCert; + private final Certificate testLeadCert; + private final Certificate caCert; + + WriteP12Test() throws CertificateException { + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + caCert = cf.generateCertificate(new ByteArrayInputStream(CA_CERT_STR + .getBytes())); + testLeadCert = cf.generateCertificate(new ByteArrayInputStream( + LEAD_CERT.getBytes())); + testerCert = cf.generateCertificate(new ByteArrayInputStream(END_CERT + .getBytes())); + } + + public static void main(String[] args) throws CertificateException, + UnrecoverableKeyException, KeyStoreException, + NoSuchProviderException, NoSuchAlgorithmException, IOException { + WriteP12Test jstest = new WriteP12Test(); + out.println("test WriteP12CertChain"); + /* + * WriteP12CertChain: This test creates a p12 keystore contains one + * entry with private key and a certificate chains contains three + * certificates in the order of user->lead->ca. This case expects to + * pass. + */ + jstest.test(new Certificate[] { jstest.testerCert, jstest.testLeadCert, + jstest.caCert }, IN_KEYSTORE_ENDUSER, "pkcs12testenduser1", + "pass", "pass"); + + /* + * WriteP12CertChainBad: same as WriteP12CertChain but chains order is + * user-ca-lead, the order is wrong so expects to fail. + */ + out.println("test WriteP12CertChainBad"); + try { + jstest.test(new Certificate[] { jstest.testerCert, jstest.caCert, + jstest.testLeadCert }, IN_KEYSTORE_ENDUSER, + "pkcs12testenduser1", "pass", "pass"); + throw new RuntimeException( + " Certificate chain is not valid, test should not pass." + + " Test failed."); + } catch (KeyStoreException e) { + e.printStackTrace(); + out.println(" Certificate chain is not valid,exception is" + + " expected. Test passed."); + } + /* + * WriteP12PrivateKey:This test creates a p12 contains a self-signed + * cert and private key,expects no exception + */ + out.println("test WriteP12PrivateKey"); + jstest.test(null, IN_KEYSTORE_ENDUSER, "pkcs12testenduser1", "pass", + "pass"); + + /* + * WriteP12TwoEntry: This test creates a p12 keystore with different + * storepass and keypass, and contains two entries. + */ + out.println("test WriteP12TwoEntry"); + jstest.testTwoEntry(IN_KEYSTORE_ENDUSER, IN_KEYSTORE_CA, + "pkcs12testenduser1", "pass", "pass"); + /* + * WriteP12TwoPass: This test creates a p12 keystore with different + * storepass and keypass, and contains one entry with private key and a + * certificate + */ + out.println("test WriteP12TwoPass"); + jstest.test(null, IN_KEYSTORE_CA, "pkcs12testCA", "storepass", + "keypass"); + } + + private void test(Certificate certs[], String inKeyStorePath, + String userAlias, String outStorePass, String outKeyPass) + throws KeyStoreException, NoSuchProviderException, IOException, + CertificateException, UnrecoverableKeyException, + NoSuchAlgorithmException { + // init output key store + KeyStore outputKeyStore = KeyStore.getInstance("pkcs12", "SunJSSE"); + outputKeyStore.load(null, null); + try (FileOutputStream fout = new FileOutputStream(OUT_KEYSTORE)) { + // KeyStore have encoded by Base64.getMimeEncoder().encode(),need + // decode first. + byte[] input = Files.readAllBytes(Paths.get(CERT_PATH, + inKeyStorePath)); + ByteArrayInputStream arrayIn = new ByteArrayInputStream(Base64 + .getMimeDecoder().decode(input)); + // input key store + KeyStore inputKeyStore = KeyStore.getInstance(IN_KEYSTORE_TYPE, + IN_KEYSTORE_PRV); + inputKeyStore.load(arrayIn, IN_STORE_PASS.toCharArray()); + // add key/certificate to output key store + Key key = inputKeyStore + .getKey(userAlias, IN_KEY_PASS.toCharArray()); + out.println("Input Key Algorithm " + key.getAlgorithm()); + out.println("====Input Certs====="); + if (certs == null) { + certs = new Certificate[] { inputKeyStore + .getCertificate(userAlias) }; + } + for (Certificate cert : certs) { + out.println(((X509Certificate) cert).getSubjectDN()); + } + outputKeyStore.setKeyEntry(userAlias, key, + outKeyPass.toCharArray(), certs); + Certificate retCerts[] = outputKeyStore + .getCertificateChain(userAlias); + out.println("====Output Certs====="); + for (Certificate retCert : retCerts) { + out.println(((X509Certificate) retCert).getSubjectDN()); + } + out.println("====Output Key Algorithm====="); + Key outKey = outputKeyStore.getKey(userAlias, + outKeyPass.toCharArray()); + out.println(outKey.getAlgorithm()); + + if (!key.equals(outKey)) { + throw new RuntimeException("key don't match"); + } + if (!Arrays.equals(certs, retCerts)) { + throw new RuntimeException("certs don't match"); + } + // save output + outputKeyStore.store(fout, outStorePass.toCharArray()); + // test output + testKeyStore(outputKeyStore, outKeyPass.toCharArray()); + } + } + + private void testTwoEntry(String inKeyStoreOnePath, + String inKeyStoreTwoPath, String userAlias, String outStorePass, + String outKeyPass) throws KeyStoreException, + NoSuchProviderException, NoSuchAlgorithmException, + CertificateException, IOException, UnrecoverableKeyException { + // initial KeyStore + KeyStore outputKeyStore = KeyStore.getInstance("pkcs12", "SunJSSE"); + try (FileOutputStream fout = new FileOutputStream(OUT_KEYSTORE);) { + outputKeyStore.load(null, null); + KeyStore inputKeyStoreOne, inputKeyStoreTwo; + inputKeyStoreOne = KeyStore.getInstance(IN_KEYSTORE_TYPE, + IN_KEYSTORE_PRV); + // KeyStore have encoded by Base64.getMimeEncoder().encode(),need + // decode first. + byte[] inputBytes = Files.readAllBytes(Paths.get(CERT_PATH, + inKeyStoreOnePath)); + ByteArrayInputStream arrayIn = new ByteArrayInputStream(Base64 + .getMimeDecoder().decode(inputBytes)); + // input key store + inputKeyStoreOne.load(arrayIn, IN_STORE_PASS.toCharArray()); + + inputBytes = Files.readAllBytes(Paths.get(CERT_PATH, + inKeyStoreTwoPath)); + arrayIn = new ByteArrayInputStream(Base64.getMimeDecoder().decode( + inputBytes)); + inputKeyStoreTwo = KeyStore.getInstance(IN_KEYSTORE_TYPE, + IN_KEYSTORE_PRV); + inputKeyStoreTwo.load(arrayIn, IN_STORE_PASS.toCharArray()); + + // add key/certificate to output key store + out.println("====First Entry====="); + Key inputKey = inputKeyStoreOne.getKey(userAlias, + IN_KEY_PASS.toCharArray()); + Certificate cert = inputKeyStoreOne.getCertificate(userAlias); + Certificate certs[] = new Certificate[1]; + certs[0] = cert; + + out.println("====Input1 Key====="); + out.println(inputKey.getAlgorithm()); + out.println("====Input1 Certs====="); + out.println("Certificate :"); + out.println(((X509Certificate) cert).getSubjectDN()); + outputKeyStore.setKeyEntry("USER", inputKey, + outKeyPass.toCharArray(), certs); + out.println("====Second Entry====="); + String caAlias = "pkcs12testca"; + inputKey = inputKeyStoreTwo.getKey(caAlias, + IN_KEY_PASS.toCharArray()); + cert = inputKeyStoreTwo.getCertificate(caAlias); + certs[0] = cert; + out.println("====Input2 Key====="); + out.println(inputKey.getAlgorithm()); + out.println("====Input2 Certs====="); + out.println("Certificate :"); + out.println(((X509Certificate) cert).getSubjectDN()); + outputKeyStore.setKeyEntry("CA", inputKey, + outKeyPass.toCharArray(), certs); + // save output + outputKeyStore.store(fout, outStorePass.toCharArray()); + // test output + testKeyStore(outputKeyStore, outKeyPass.toCharArray()); + } + } + + private void testKeyStore(KeyStore inputKeyStore, char[] keypass) + throws KeyStoreException, UnrecoverableKeyException, + NoSuchAlgorithmException { + out.println("========== Key Store =========="); + out.println("getProvider : " + inputKeyStore.getProvider()); + out.println("getType : " + inputKeyStore.getType()); + out.println("getDefaultType : " + KeyStore.getDefaultType()); + + int idx = 0; + Enumeration e = inputKeyStore.aliases(); + String alias; + while (e.hasMoreElements()) { + alias = e.nextElement(); + if (!inputKeyStore.containsAlias(alias)) { + throw new RuntimeException("Alias not found"); + } + out.println("Alias " + idx + " : " + alias); + out.println("getCreationDate : " + + inputKeyStore.getCreationDate(alias)); + X509Certificate cert = (X509Certificate) inputKeyStore + .getCertificate(alias); + out.println("getCertificate : " + cert.getSubjectDN()); + String retAlias = inputKeyStore.getCertificateAlias(cert); + if (!retAlias.equals(alias)) { + throw new RuntimeException("Alias mismatch, actually " + + retAlias + ", expected " + alias); + } + out.println("getCertificateAlias : " + retAlias); + Certificate[] certs = inputKeyStore.getCertificateChain(alias); + int i = 0; + for (Certificate certification : certs) { + out.println("getCertificateChain " + i + + ((X509Certificate) certification).getSubjectDN()); + i++; + } + if (inputKeyStore.isCertificateEntry(alias)) { + throw new RuntimeException( + "inputKeystore should not be certEntry because this" + + " keystore only contain key pair entries."); + } + if (!inputKeyStore.isKeyEntry(alias)) { + throw new RuntimeException("Entry type unknown."); + } + idx++; + } + int size = inputKeyStore.size(); + if (idx != size) { + throw new RuntimeException("Size not match, actually " + idx + + ", expected " + size); + } + } + +} diff --git a/jdk/test/java/security/KeyStore/PKCS12/certs/writeP12/keystoreCA.jks.data b/jdk/test/java/security/KeyStore/PKCS12/certs/writeP12/keystoreCA.jks.data new file mode 100644 index 00000000000..1d6b5a4b6ac --- /dev/null +++ b/jdk/test/java/security/KeyStore/PKCS12/certs/writeP12/keystoreCA.jks.data @@ -0,0 +1,38 @@ +/u3+7QAAAAIAAAABAAAAAQAMcGtjczEydGVzdGNhAAAA9w1mDAMAAAUCMIIE/jAOBgorBgEEASoC +EQEBBQAEggTqFhceJz85XyVsicsfonXYx+vvFXkb9Jmr11eh9n570ZdiFZ1hv4XRk/x/1C1spy5X +J2wv4lABGAOA5gV0aTKij+82NLoEz9zDW5fwAnrBKVjAq/NxdwEi9lvipiSVx1qglx/mQAHeEi4i +6vDoai3hVNQqVmd/TG2deyk/fQ9MZ7U2fmWcJDH4YbP39psQ+7rp9cDJ0P7GWoLXwbWs1vftbN0R +4fWitH1+6hBbIbVT9o0cM9ilAjpkNFr10pBEsfrikaE8IsN562soWfNxGwwrsjExEFeKlMrtNtWM +Wc4+YZ1ybVi/6krK/kFfOa+R3mtjBoD7zM4TSG9dptuvBLVgey8RXh3BQ8pU7uN5q+9Omqo1SsRN +wHYKjTrfWMozt+37ZlyCZ70Kb/2jJYWFuo9+wqXQU+MYnpZZB+cLt3PIFMakhIu1vpMpJCcoceaS +bjDWxCG8HHZjjFJPxAE3HEbCzaj4BevxQfxtp57llmtI2I0NJvua8JbFjf0U9MK6iRi4IpmBztpP +vxvaetT54wC+2c0QaDqANIn3Oc4tmvD4RGJfmFrEYEX6dQbCwYHAJF8sczqDb4xIYwrGmiMNeeha +4g9fcEa7Q+t1o1XLmNOp5e6I/TjUfXGvKlEyYeQ1FNLRqTtI5KvHQ1l71n1aQyEPvcff93NlF3jv +jWuqOqLzFT7sIZQxgjoum4i0DwLzOtuAWIDELNJ03MCciq5j0SjoLO2/ISctNTyGuYBmerjGCI9c +CLhGYnwLCOvvZN1yIqT79Se6qe/tBV5nEYUdXEt4ROJNabf1H4GmkXYeDQvtHrQ1IHM+Kg1UyEJz +fwdhJ68EU3gFenTtFgVJ+90YpemGtptgS6CvS3qC2H/H3XaKKQGpsXRCMSCRZcfMMOQEc6WLPsVY +rEhorQIAbbgHp4//H+RkNzG+5NN4pac5bo0kDTpeQkiOXGZZKyMHgagFvwLCN35rTi2HnHEXnYoi +jU1sGmUV+kRgRJ+N3Gx6D+uWNctkZMeTuVg+9ftIhEClGdtBSXWZu9lr/48cXkWJBubd4CWYrFMm +cTYezlQiTvmQgodrrwtcdo17J/L4PK74C72aIqPlWdEImGQs7I4n1mvceXoHvjYu5+tOxS0HH4sm +Y4iMr3hsqVAag2/LeLCG1gumpGiTdh9hk/aOcSWASv7rjq8JVpxWJe3JbrQ5k0U3e1nE2AdSXjEj +knBDpDFpGsnJaP2xxTdvQ+oV1pZ3m30xOeCTVV+0VBIw8eL0PDATSgqQ7FuWnYZ/FGaOrgnn14JM +HQicEfFN7TOa8q3/lbY5JTRtuG5umoWL2AWaaAW6G5GRTUNMOvBI5xTvR/kr3iNKTK2caKi0XTJ3 +WXd9jeuyLstpbtokG6xBbSiAb/SSL9yoh400DbKFTlVHKD8cijfuLKIM1TmL2ZksEh6JvF8GfdLl +FXZH7Ny8aJ63Ef947P9Y8+6WMzZDrkyoV+uInRq1TVXk6Ps6qiqI0j9fhMI8XMju61vjkeXprzBE +Pk2GbXo7MtHrBTobffkD3BszrFJai8n9vDrQgsaZYwWi4IxlKYefmWDaagiq/qDBZhKQCgyuJNN/ +5sQZDb6+J/MIgDk0M2bXEs6f2gT1rAyuH+rbnsnfUu9jRQupP4q0/ZCY2WOIaf8W34FnMdNzOUH8 +iE2T59UbMGQ0DLJeHwAAAAEABVguNTA5AAADGzCCAxcwggH/AgQ/PtJwMA0GCSqGSIb3DQEBBQUA +MFAxCzAJBgNVBAYTAlVTMREwDwYDVQQKEwhKYXZhU29mdDEVMBMGA1UECxMMU2VjdXJpdHkgU1FF +MRcwFQYDVQQDEw5QS0NTMTIgVGVzdCBDQTAeFw0wMzA4MTcwMDU1MTJaFw0xMzA4MTQwMDU1MTJa +MFAxCzAJBgNVBAYTAlVTMREwDwYDVQQKEwhKYXZhU29mdDEVMBMGA1UECxMMU2VjdXJpdHkgU1FF +MRcwFQYDVQQDEw5QS0NTMTIgVGVzdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AJO0ofiv8hrJiWnGZ435GX7lsRjSQj1tKuvXscKET/ngRzEMBtNMovWi0rGQKjaSUgg76YMkjgFJ +gXfn/FhYR6iX0VURFX795q2nQymQo4arbFCOyMEU2GMvXJRZHniuHR2sW7hTD6VLu8kH8Ek14Lzg +P1CeJCbhrWmAHUySOHn9ZlAEqOvnXmtFGQPxRwrlezus94a+VR5coSS9v6P/DObRgUwSEjgyUp5x +jQb7UCzR51mL7OO9FABNgbbghmIdVf9xwB9bUYq0tzAQXG9V5yJIol0d7Y2gUgfl4aAn7hvCrSJ1 +1xWgJ7yn2PZmBcOlSbfSWEKWNlQwu9vNfz289HUCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAc12f +Mx1q5wvPxPjf59gs4cYtfGEHNiz1gQy2E08aBRGs1pmC79ZPyU+zbWtartarr8VyeLldVx23fTRQ +CVisLRUBKX7+KOiO6llD6MZ3wPo8qil8b9u89ubc7fmOMThIarztNxtEIpoZIjbfTBey+vctlNP1 +O9/rhTRs3QBA4iPRIm7yAojp69U3kORnpCt2G5Oant5b4jGT5JEl3qUySPJtAIlwo4vnl4/e41S3 +h/kcXgXIQWPrhC66lK7FTlVoeyAQqgv1exalE5Jg9SBZc5JIp2raZeNrNTG4SSHdskJM2ngUXLLh +Ot2wxLbkVqfcpzDt0AOGLvObgUVhs0NQ4nYQH5SPMKBNY+nGGfmMLaFPAelF \ No newline at end of file diff --git a/jdk/test/java/security/KeyStore/PKCS12/certs/writeP12/keystoreEU.jks.data b/jdk/test/java/security/KeyStore/PKCS12/certs/writeP12/keystoreEU.jks.data new file mode 100644 index 00000000000..c8e4ecf4705 --- /dev/null +++ b/jdk/test/java/security/KeyStore/PKCS12/certs/writeP12/keystoreEU.jks.data @@ -0,0 +1,79 @@ +/u3+7QAAAAIAAAADAAAAAgAMcGtjczEydGVzdGNhAAAA9w18bwQABVguNTA5AAADGzCCAxcwggH/ +AgQ/PtJwMA0GCSqGSIb3DQEBBQUAMFAxCzAJBgNVBAYTAlVTMREwDwYDVQQKEwhKYXZhU29mdDEV +MBMGA1UECxMMU2VjdXJpdHkgU1FFMRcwFQYDVQQDEw5QS0NTMTIgVGVzdCBDQTAeFw0wMzA4MTcw +MDU1MTJaFw0xMzA4MTQwMDU1MTJaMFAxCzAJBgNVBAYTAlVTMREwDwYDVQQKEwhKYXZhU29mdDEV +MBMGA1UECxMMU2VjdXJpdHkgU1FFMRcwFQYDVQQDEw5QS0NTMTIgVGVzdCBDQTCCASIwDQYJKoZI +hvcNAQEBBQADggEPADCCAQoCggEBAJO0ofiv8hrJiWnGZ435GX7lsRjSQj1tKuvXscKET/ngRzEM +BtNMovWi0rGQKjaSUgg76YMkjgFJgXfn/FhYR6iX0VURFX795q2nQymQo4arbFCOyMEU2GMvXJRZ +HniuHR2sW7hTD6VLu8kH8Ek14LzgP1CeJCbhrWmAHUySOHn9ZlAEqOvnXmtFGQPxRwrlezus94a+ +VR5coSS9v6P/DObRgUwSEjgyUp5xjQb7UCzR51mL7OO9FABNgbbghmIdVf9xwB9bUYq0tzAQXG9V +5yJIol0d7Y2gUgfl4aAn7hvCrSJ11xWgJ7yn2PZmBcOlSbfSWEKWNlQwu9vNfz289HUCAwEAATAN +BgkqhkiG9w0BAQUFAAOCAQEAc12fMx1q5wvPxPjf59gs4cYtfGEHNiz1gQy2E08aBRGs1pmC79ZP +yU+zbWtartarr8VyeLldVx23fTRQCVisLRUBKX7+KOiO6llD6MZ3wPo8qil8b9u89ubc7fmOMThI +arztNxtEIpoZIjbfTBey+vctlNP1O9/rhTRs3QBA4iPRIm7yAojp69U3kORnpCt2G5Oant5b4jGT +5JEl3qUySPJtAIlwo4vnl4/e41S3h/kcXgXIQWPrhC66lK7FTlVoeyAQqgv1exalE5Jg9SBZc5JI +p2raZeNrNTG4SSHdskJM2ngUXLLhOt2wxLbkVqfcpzDt0AOGLvObgUVhs0NQ4gAAAAIADnBrY3Mx +MnRlc3RsZWFkAAAA9w1+meMABVguNTA5AAACxDCCAsAwggGooAMCAQICBD8+0tYwDQYJKoZIhvcN +AQEEBQAwUDELMAkGA1UEBhMCVVMxETAPBgNVBAoTCEphdmFTb2Z0MRUwEwYDVQQLEwxTZWN1cml0 +eSBTUUUxFzAVBgNVBAMTDlBLQ1MxMiBUZXN0IENBMB4XDTAwMDgwOTA3MDAwMFoXDTEwMDgwNzA3 +MDAwMFowUjELMAkGA1UEBhMCVVMxETAPBgNVBAoTCEphdmFTb2Z0MRUwEwYDVQQLEwxTZWN1cml0 +eSBTUUUxGTAXBgNVBAMTEFBLQ1MxMiBUZXN0IExlYWQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ +AoGBAM6vV9lEs/1ow4U/o1MmVqgeYeAN97UtdWKh+amL6o0143FCOoDqZqFzGnwxvUR0ZSHHL6ed +cS6ewKd1jK7+NdZVgbbarWYuXNfwxAtXBDP0pTwpNa9sxW5Cbu0Conl3jHK42RKOi3ARzMEIyKSP +rqfXK91Y7sqhv6JUJFJl1bktAgMBAAGjJDAiMA8GA1UdDwEB/wQFAwMHgAAwDwYDVR0TAQH/BAUw +AwEB/zANBgkqhkiG9w0BAQQFAAOCAQEAYW7opvfE1prb/b0pXURO0b0PBZUtE8mVTu5HEjbXwlBO +Ee+idRJTe+CqHOaUJ1LXbi3kCbNmqP5hHAmbBM1XMCN5kma0sz4XPLO8OYDkAOE1MFS0koyoAQmm +e0d/qid0HqjyeTurBc6bwWJIEmuDFqbSuNY25k/HMGUCVxQovFsRRSfqfexdT6Zty4JmJrYlD+DG +UMDgb6U2Vl1NFq6hV6c1kMdJoOEl9fX2ZuJy3CQHqwhFKYX/CC2oLaUDBBK09/44OpnwnU90Y9Oe +UFz3xeDokRXrzxeWtX2YKwnjwrpEUGXHe7PCuTgSGq8rjNDHRbZc8Yul1nlDaVRRR1EXMgAAAAEA +EnBrY3MxMnRlc3RlbmR1c2VyMQAAAPcNgTivAAACuTCCArUwDgYKKwYBBAEqAhEBAQUABIICoU6N +bD6qkNDM8KJFHCTHUevURAV8SUuzzBwsfYC0tEDMa2zGNUEvrmgyM3b5z7qR8XbTZvVBFJJLp3Jx +HmQpg0vLltDFFIPiVgRVcUEDPSmks1KP/bP/mE1uos31R6VyfNMGS3JnQblcSipcB893NrFFXNu2 +PUPjKCC9GrQZAmSM78BBTrwWD/Yd4rKcVh57DLKtUySoF29qXthusJjhSaqRZERaMV6egviE5+W8 +f8ppTYLx2gJmOyi9edJEdHxMcPzRvWgxlmUqUCDg0KVsosbxjjJKcmJ9b1KWuadKyAYkqxSDi8sx +2iwEQW3PQjLGBVHeQNntUF1wapp21sD1lVmDV3+61+fIphAUVRQXjmoYsEhrTc93IkDtQWgfJsgz +xjVVDbcy29VnMAK4f3tT/p5HeFO6yRQBE2B3IngSomRxbNh143VswNYqtZYy03UhOm8vbF2OfOJ/ +NzwC/F+19XgntnC0qv5j6VzwMGTt2NYPWXUqSzVIFswSunj70+ZsprCRX5IEFnpHDSL7OwDjEMFc +z6dpYQ9pwgyKh7JiLZxAr/9Nhb8QQDGrolzHoDt1QnC/DYvDGfTKu0ZjlXR4EQN4XFV+FAiykRfA +N1jIsTY7fCmLpLuW4paQnR1lPSGLeSvi63DOgN+lfVSJ5YjZm4yIRIS6lpvLVgcqodDqBRmPMP7x +fJ3osv1Wt4L/77BdJpZrUUygysRpzyUKlC6NwXr338HKPyAnfrkzIpHKnhTUaRVmfgAuzrXMFp8C +ejyYXJQwPPFAL5mIdUMkLDQKzESI0T3AD1LWVDM/0mGud9GhqiycI6AqC0j7MynRCvQG0LyRunFG +EQ2KipM//qPFKqwoVukxrLTunmGyeOe6UxodtK+qcn7SIXZ8jJM14a5rSDwAAAADAAVYLjUwOQAA +AjowggI2MIIBn6ADAgECAgQ/Pta3MA0GCSqGSIb3DQEBBAUAMFIxCzAJBgNVBAYTAlVTMREwDwYD +VQQKEwhKYXZhU29mdDEVMBMGA1UECxMMU2VjdXJpdHkgU1FFMRkwFwYDVQQDExBQS0NTMTIgVGVz +dCBMZWFkMB4XDTAwMDgwOTA3MDAwMFoXDTEwMDgwNzA3MDAwMFowWDELMAkGA1UEBhMCVVMxETAP +BgNVBAoTCEphdmFTb2Z0MRUwEwYDVQQLEwxTZWN1cml0eSBTUUUxHzAdBgNVBAMTFlBLQ1MxMiBU +ZXN0IEVuZCBVc2VyIDEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMgqiZJiiYPMf9Xrd4NA +Qbuh3QMtyedVnzWltaEOyzyAdXabykAN1Gp2KEGadJARoxbgPe5niwUTUu2RCWzqGN3tJ06wbljb +gvzXmOi31rYlwHvcfwfRUqKus5svkFl23sG0BI8Odi1bhKm375iMOgkXHIXQdyGRq/NdpVOV7FqT +AgMBAAGjEzARMA8GA1UdDwEB/wQFAwMHgAAwDQYJKoZIhvcNAQEEBQADgYEAgUDclcSZv0BefdEP +u34yfoOjJUMjLmOyfrE4pMlXbkjShukNTODDhBoAyYzRm+6w6ZnbBk1Lwy3JNSB0A3JqRvOflJ3F +tPJMsSpCwVtfxRULfx/HlkzoTEDlhIC+CZe51mk5ULQBNxyhlLckVTwLFJ9b5DcgLYwuH5BODeFQ +nlsABVguNTA5AAACxDCCAsAwggGooAMCAQICBD8+0tYwDQYJKoZIhvcNAQEEBQAwUDELMAkGA1UE +BhMCVVMxETAPBgNVBAoTCEphdmFTb2Z0MRUwEwYDVQQLEwxTZWN1cml0eSBTUUUxFzAVBgNVBAMT +DlBLQ1MxMiBUZXN0IENBMB4XDTAwMDgwOTA3MDAwMFoXDTEwMDgwNzA3MDAwMFowUjELMAkGA1UE +BhMCVVMxETAPBgNVBAoTCEphdmFTb2Z0MRUwEwYDVQQLEwxTZWN1cml0eSBTUUUxGTAXBgNVBAMT +EFBLQ1MxMiBUZXN0IExlYWQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAM6vV9lEs/1ow4U/ +o1MmVqgeYeAN97UtdWKh+amL6o0143FCOoDqZqFzGnwxvUR0ZSHHL6edcS6ewKd1jK7+NdZVgbba +rWYuXNfwxAtXBDP0pTwpNa9sxW5Cbu0Conl3jHK42RKOi3ARzMEIyKSPrqfXK91Y7sqhv6JUJFJl +1bktAgMBAAGjJDAiMA8GA1UdDwEB/wQFAwMHgAAwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0B +AQQFAAOCAQEAYW7opvfE1prb/b0pXURO0b0PBZUtE8mVTu5HEjbXwlBOEe+idRJTe+CqHOaUJ1LX +bi3kCbNmqP5hHAmbBM1XMCN5kma0sz4XPLO8OYDkAOE1MFS0koyoAQmme0d/qid0HqjyeTurBc6b +wWJIEmuDFqbSuNY25k/HMGUCVxQovFsRRSfqfexdT6Zty4JmJrYlD+DGUMDgb6U2Vl1NFq6hV6c1 +kMdJoOEl9fX2ZuJy3CQHqwhFKYX/CC2oLaUDBBK09/44OpnwnU90Y9OeUFz3xeDokRXrzxeWtX2Y +KwnjwrpEUGXHe7PCuTgSGq8rjNDHRbZc8Yul1nlDaVRRR1EXMgAFWC41MDkAAAMbMIIDFzCCAf8C +BD8+0nAwDQYJKoZIhvcNAQEFBQAwUDELMAkGA1UEBhMCVVMxETAPBgNVBAoTCEphdmFTb2Z0MRUw +EwYDVQQLEwxTZWN1cml0eSBTUUUxFzAVBgNVBAMTDlBLQ1MxMiBUZXN0IENBMB4XDTAzMDgxNzAw +NTUxMloXDTEzMDgxNDAwNTUxMlowUDELMAkGA1UEBhMCVVMxETAPBgNVBAoTCEphdmFTb2Z0MRUw +EwYDVQQLEwxTZWN1cml0eSBTUUUxFzAVBgNVBAMTDlBLQ1MxMiBUZXN0IENBMIIBIjANBgkqhkiG +9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk7Sh+K/yGsmJacZnjfkZfuWxGNJCPW0q69exwoRP+eBHMQwG +00yi9aLSsZAqNpJSCDvpgySOAUmBd+f8WFhHqJfRVREVfv3mradDKZCjhqtsUI7IwRTYYy9clFke +eK4dHaxbuFMPpUu7yQfwSTXgvOA/UJ4kJuGtaYAdTJI4ef1mUASo6+dea0UZA/FHCuV7O6z3hr5V +HlyhJL2/o/8M5tGBTBISODJSnnGNBvtQLNHnWYvs470UAE2BtuCGYh1V/3HAH1tRirS3MBBcb1Xn +IkiiXR3tjaBSB+XhoCfuG8KtInXXFaAnvKfY9mYFw6VJt9JYQpY2VDC7281/Pbz0dQIDAQABMA0G +CSqGSIb3DQEBBQUAA4IBAQBzXZ8zHWrnC8/E+N/n2Czhxi18YQc2LPWBDLYTTxoFEazWmYLv1k/J +T7Nta1qu1quvxXJ4uV1XHbd9NFAJWKwtFQEpfv4o6I7qWUPoxnfA+jyqKXxv27z25tzt+Y4xOEhq +vO03G0QimhkiNt9MF7L69y2U0/U73+uFNGzdAEDiI9EibvICiOnr1TeQ5GekK3Ybk5qe3lviMZPk +kSXepTJI8m0AiXCji+eXj97jVLeH+RxeBchBY+uELrqUrsVOVWh7IBCqC/V7FqUTkmD1IFlzkkin +atpl42s1MbhJId2yQkzaeBRcsuE63bDEtuRWp9ynMO3QA4Yu85uBRWGzQ1Di7p2dz0wNRNimbVP4 +VL+NWQOgtME= \ No newline at end of file From e7e3187500352c4e113698abc39a64def26a2ab7 Mon Sep 17 00:00:00 2001 From: Andrew Brygin Date: Mon, 23 Mar 2015 11:19:41 +0300 Subject: [PATCH 103/362] 8074954: ImageInputStreamImpl.readShort/readInt do not behave correctly at EOF Reviewed-by: prr, serb --- .../imageio/stream/ImageInputStreamImpl.java | 4 +- .../javax/imageio/stream/ShortStreamTest.java | 127 ++++++++++++++++++ 2 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 jdk/test/javax/imageio/stream/ShortStreamTest.java diff --git a/jdk/src/java.desktop/share/classes/javax/imageio/stream/ImageInputStreamImpl.java b/jdk/src/java.desktop/share/classes/javax/imageio/stream/ImageInputStreamImpl.java index 5d2484017cb..8cad9a4f223 100644 --- a/jdk/src/java.desktop/share/classes/javax/imageio/stream/ImageInputStreamImpl.java +++ b/jdk/src/java.desktop/share/classes/javax/imageio/stream/ImageInputStreamImpl.java @@ -225,7 +225,7 @@ public abstract class ImageInputStreamImpl implements ImageInputStream { } public short readShort() throws IOException { - if (read(byteBuf, 0, 2) < 0) { + if (read(byteBuf, 0, 2) != 2) { throw new EOFException(); } @@ -247,7 +247,7 @@ public abstract class ImageInputStreamImpl implements ImageInputStream { } public int readInt() throws IOException { - if (read(byteBuf, 0, 4) < 0) { + if (read(byteBuf, 0, 4) != 4) { throw new EOFException(); } diff --git a/jdk/test/javax/imageio/stream/ShortStreamTest.java b/jdk/test/javax/imageio/stream/ShortStreamTest.java new file mode 100644 index 00000000000..2b133a57a7c --- /dev/null +++ b/jdk/test/javax/imageio/stream/ShortStreamTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/** + * @test + * @bug 8074954 + * @summary Test verifies that an IOException is triggered if input stream + * does not contain enough data to read a multi-byte type. + * + * @run main ShortStreamTest + */ + +import javax.imageio.ImageIO; +import javax.imageio.stream.ImageInputStream; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +public class ShortStreamTest { + public static void main(String[] args) throws IOException { + TestCase[] tests = createTests(); + + for (TestCase t : tests) { + t.test(); + } + } + + private static abstract class TestCase { + abstract void testRead(ImageInputStream iis) throws IOException; + + public void test() { + boolean gotException = false; + + ImageInputStream iis = createShortStream(); + + try { + testRead(iis); + } catch (IOException e) { + e.printStackTrace(System.out); + gotException = true; + } + + if (!gotException) { + throw new RuntimeException("Test failed."); + } + System.out.println("Test PASSED"); + } + } + + + private static ImageInputStream createShortStream() { + try { + byte[] integerTestArray = new byte[] { 80 }; + ByteArrayInputStream bais = new ByteArrayInputStream(integerTestArray); + + return ImageIO.createImageInputStream(bais); + } catch (IOException e) { + return null; + } + } + + private static TestCase[] createTests() { + return new TestCase[]{ + new TestCase() { + @Override + void testRead(ImageInputStream iis) throws IOException { + iis.readInt(); + } + }, + new TestCase() { + @Override + void testRead(ImageInputStream iis) throws IOException { + iis.readShort(); + } + }, + new TestCase() { + @Override + void testRead(ImageInputStream iis) throws IOException { + iis.readDouble(); + } + }, + new TestCase() { + @Override + void testRead(ImageInputStream iis) throws IOException { + iis.readFloat(); + } + }, + new TestCase() { + @Override + void testRead(ImageInputStream iis) throws IOException { + iis.readLong(); + } + }, + new TestCase() { + @Override + void testRead(ImageInputStream iis) throws IOException { + iis.readUnsignedInt(); + } + }, + new TestCase() { + @Override + void testRead(ImageInputStream iis) throws IOException { + iis.readUnsignedShort(); + } + } + }; + } +} From 7e09df43e65bdd56df31e0b6eb48db194739923f Mon Sep 17 00:00:00 2001 From: Dmitry Samersoff Date: Mon, 23 Mar 2015 02:29:47 -0700 Subject: [PATCH 104/362] 8075569: jmap test fails due to "ERROR: java.nio.file.NoSuchFileException: 2906081d-06bc-4738-a7e8-f37b8bf13658.lck" Lock file is deleted while we are setting modified time Reviewed-by: alanb --- jdk/test/sun/tools/jmap/heapconfig/LingeredApp.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jdk/test/sun/tools/jmap/heapconfig/LingeredApp.java b/jdk/test/sun/tools/jmap/heapconfig/LingeredApp.java index 1ac1a137088..a6f1a64ee88 100644 --- a/jdk/test/sun/tools/jmap/heapconfig/LingeredApp.java +++ b/jdk/test/sun/tools/jmap/heapconfig/LingeredApp.java @@ -417,7 +417,9 @@ public class LingeredApp { setLastModified(theLockFileName, epoch()); Thread.sleep(spinDelay); } - + } catch (NoSuchFileException ex) { + // Lock deleted while we are setting last modified time. + // Ignore error and lets the app exits } catch (Exception ex) { System.err.println("LingeredApp ERROR: " + ex); // Leave exit_code = 1 to Java launcher From bc29dd414c35f60c29d43fdf16ade08b9598c3d6 Mon Sep 17 00:00:00 2001 From: James Laskey Date: Mon, 23 Mar 2015 09:04:59 -0300 Subject: [PATCH 105/362] 8075623: Temporary patch to get fx imports working interim Reviewed-by: lagergren --- .../nashorn/internal/runtime/resources/fx/base.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/fx/base.js b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/fx/base.js index 382eabb22ee..4ab4e5f4cd2 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/fx/base.js +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/fx/base.js @@ -45,11 +45,19 @@ function LOAD_FX_CLASSES(clsList) { var SUFFIX_LENGTH = ".class".length; + // TODO - temporary patch until fx is moved to module system. + // + var jfxrtJar; try { - var jfxrtJar = new ZipFile(System.getProperty("java.home") + "/lib/ext/jfxrt.jar"); - } catch (ex) { - throw new Error("JavaFX runtime not found"); + jfxrtJar = new ZipFile(System.getProperty("java.home") + "/lib/jfxrt.jar"); + } catch (ex1) { + try { + jfxrtJar = new ZipFile(System.getProperty("java.home") + "/lib/ext/jfxrt.jar"); + } catch (ex2) { + throw new Error("JavaFX runtime not found"); + } } + // var entries = jfxrtJar.entries(); From 497fe8d068fc9caa720424dadfe32b6a4a5d0032 Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Mon, 23 Mar 2015 14:20:39 +0100 Subject: [PATCH 106/362] 8075560: Typo in Javadoc for java.util.Optional.equals() Reviewed-by: alanb --- jdk/src/java.base/share/classes/java/util/Optional.java | 2 +- jdk/src/java.base/share/classes/java/util/OptionalDouble.java | 2 +- jdk/src/java.base/share/classes/java/util/OptionalInt.java | 2 +- jdk/src/java.base/share/classes/java/util/OptionalLong.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/util/Optional.java b/jdk/src/java.base/share/classes/java/util/Optional.java index 21fef4c13e0..cc5c1309663 100644 --- a/jdk/src/java.base/share/classes/java/util/Optional.java +++ b/jdk/src/java.base/share/classes/java/util/Optional.java @@ -346,7 +346,7 @@ public final class Optional { * * * @param obj an object to be tested for equality - * @return {code true} if the other object is "equal to" this object + * @return {@code true} if the other object is "equal to" this object * otherwise {@code false} */ @Override diff --git a/jdk/src/java.base/share/classes/java/util/OptionalDouble.java b/jdk/src/java.base/share/classes/java/util/OptionalDouble.java index 3de841e80f4..88c4cbf04b2 100644 --- a/jdk/src/java.base/share/classes/java/util/OptionalDouble.java +++ b/jdk/src/java.base/share/classes/java/util/OptionalDouble.java @@ -244,7 +244,7 @@ public final class OptionalDouble { * * * @param obj an object to be tested for equality - * @return {code true} if the other object is "equal to" this object + * @return {@code true} if the other object is "equal to" this object * otherwise {@code false} */ @Override diff --git a/jdk/src/java.base/share/classes/java/util/OptionalInt.java b/jdk/src/java.base/share/classes/java/util/OptionalInt.java index 38b9bd0294c..92a1d855be8 100644 --- a/jdk/src/java.base/share/classes/java/util/OptionalInt.java +++ b/jdk/src/java.base/share/classes/java/util/OptionalInt.java @@ -244,7 +244,7 @@ public final class OptionalInt { * * * @param obj an object to be tested for equality - * @return {code true} if the other object is "equal to" this object + * @return {@code true} if the other object is "equal to" this object * otherwise {@code false} */ @Override diff --git a/jdk/src/java.base/share/classes/java/util/OptionalLong.java b/jdk/src/java.base/share/classes/java/util/OptionalLong.java index d6d56b9aee4..9a4c4d22f48 100644 --- a/jdk/src/java.base/share/classes/java/util/OptionalLong.java +++ b/jdk/src/java.base/share/classes/java/util/OptionalLong.java @@ -244,7 +244,7 @@ public final class OptionalLong { * * * @param obj an object to be tested for equality - * @return {code true} if the other object is "equal to" this object + * @return {@code true} if the other object is "equal to" this object * otherwise {@code false} */ @Override From 7cb7ae5914c92a86a44c64882f1cde82974cc309 Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Mon, 23 Mar 2015 09:52:42 -0400 Subject: [PATCH 107/362] 8071480: (process spec) ProcessBuilder.start spec linked to the wrong checkRead and checkWrite methods Disambiguate with links to checkRead(String) and checkWrite(String) Reviewed-by: alanb, martin --- jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java b/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java index 940084cfbc6..0cb6f741326 100644 --- a/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java +++ b/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java @@ -988,14 +988,14 @@ public final class ProcessBuilder *
  • the standard input to the subprocess was * {@linkplain #redirectInput redirected from a file} * and the security manager's - * {@link SecurityManager#checkRead checkRead} method + * {@link SecurityManager#checkRead(String) checkRead} method * denies read access to the file, or * *
  • the standard output or standard error of the * subprocess was * {@linkplain #redirectOutput redirected to a file} * and the security manager's - * {@link SecurityManager#checkWrite checkWrite} method + * {@link SecurityManager#checkWrite(String) checkWrite} method * denies write access to the file * * From c92b8a33a683928764bcd4eabba90443a43f062a Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Mon, 23 Mar 2015 09:53:08 -0400 Subject: [PATCH 108/362] 8073220: A typo in the documentation for class ProcessBuilder Correct reference to be OutputStream Reviewed-by: martin, alanb --- jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java b/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java index 0cb6f741326..f49b6a9cb9b 100644 --- a/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java +++ b/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java @@ -82,7 +82,7 @@ import java.util.Map; *
  • a destination for standard output * and standard error. By default, the subprocess writes standard * output and standard error to pipes. Java code can access these pipes - * via the input streams returned by {@link Process#getInputStream()} and + * via the input streams returned by {@link Process#getOutputStream()} and * {@link Process#getErrorStream()}. However, standard output and * standard error may be redirected to other destinations using * {@link #redirectOutput(Redirect) redirectOutput} and From a056457b52b51d01b2fcb2cd327145e9219fee6a Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Mon, 23 Mar 2015 10:13:32 -0400 Subject: [PATCH 109/362] 8067796: (process) Process.waitFor(timeout, unit) doesn't throw NPE if timeout is less than, or equal to zero when unit == null Implement checking for NPE in Process implementation before other conditions Reviewed-by: martin, chegar --- .../unix/classes/java/lang/ProcessImpl.java | 3 +- .../classes/java/lang/ProcessImpl.java | 3 +- jdk/test/java/lang/ProcessBuilder/Basic.java | 51 +++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/jdk/src/java.base/unix/classes/java/lang/ProcessImpl.java b/jdk/src/java.base/unix/classes/java/lang/ProcessImpl.java index a35405fc8d9..42d40592633 100644 --- a/jdk/src/java.base/unix/classes/java/lang/ProcessImpl.java +++ b/jdk/src/java.base/unix/classes/java/lang/ProcessImpl.java @@ -496,12 +496,11 @@ final class ProcessImpl extends Process { public synchronized boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException { + long remainingNanos = unit.toNanos(timeout); // throw NPE before other conditions if (hasExited) return true; if (timeout <= 0) return false; - long remainingNanos = unit.toNanos(timeout); long deadline = System.nanoTime() + remainingNanos; - do { // Round up to next millisecond wait(TimeUnit.NANOSECONDS.toMillis(remainingNanos + 999_999L)); diff --git a/jdk/src/java.base/windows/classes/java/lang/ProcessImpl.java b/jdk/src/java.base/windows/classes/java/lang/ProcessImpl.java index ec90ea0da3a..f6ed286d991 100644 --- a/jdk/src/java.base/windows/classes/java/lang/ProcessImpl.java +++ b/jdk/src/java.base/windows/classes/java/lang/ProcessImpl.java @@ -458,12 +458,11 @@ final class ProcessImpl extends Process { public boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException { + long remainingNanos = unit.toNanos(timeout); // throw NPE before other conditions if (getExitCodeProcess(handle) != STILL_ACTIVE) return true; if (timeout <= 0) return false; - long remainingNanos = unit.toNanos(timeout); long deadline = System.nanoTime() + remainingNanos ; - do { // Round up to next millisecond long msTimeout = TimeUnit.NANOSECONDS.toMillis(remainingNanos + 999_999L); diff --git a/jdk/test/java/lang/ProcessBuilder/Basic.java b/jdk/test/java/lang/ProcessBuilder/Basic.java index cfc4d443ff8..93855f19bcb 100644 --- a/jdk/test/java/lang/ProcessBuilder/Basic.java +++ b/jdk/test/java/lang/ProcessBuilder/Basic.java @@ -27,6 +27,7 @@ * 5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313 * 6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958 * 4947220 7018606 7034570 4244896 5049299 8003488 8054494 8058464 + * 8067796 * @summary Basic tests for Process and Environment Variable code * @run main/othervm/timeout=300 Basic * @run main/othervm/timeout=300 -Djdk.lang.Process.launchMechanism=fork Basic @@ -2386,6 +2387,56 @@ public class Basic { p.destroy(); } catch (Throwable t) { unexpected(t); } + //---------------------------------------------------------------- + // Check that Process.waitFor(timeout, null) throws NPE. + //---------------------------------------------------------------- + try { + List childArgs = new ArrayList(javaChildArgs); + childArgs.add("sleep"); + final Process p = new ProcessBuilder(childArgs).start(); + THROWS(NullPointerException.class, + () -> p.waitFor(10L, null)); + THROWS(NullPointerException.class, + () -> p.waitFor(0L, null)); + THROWS(NullPointerException.class, + () -> p.waitFor(-1L, null)); + // Terminate process and recheck after it exits + p.destroy(); + p.waitFor(); + THROWS(NullPointerException.class, + () -> p.waitFor(10L, null)); + THROWS(NullPointerException.class, + () -> p.waitFor(0L, null)); + THROWS(NullPointerException.class, + () -> p.waitFor(-1L, null)); + } catch (Throwable t) { unexpected(t); } + + //---------------------------------------------------------------- + // Check that default implementation of Process.waitFor(timeout, null) throws NPE. + //---------------------------------------------------------------- + try { + List childArgs = new ArrayList(javaChildArgs); + childArgs.add("sleep"); + final Process proc = new ProcessBuilder(childArgs).start(); + final DelegatingProcess p = new DelegatingProcess(proc); + + THROWS(NullPointerException.class, + () -> p.waitFor(10L, null)); + THROWS(NullPointerException.class, + () -> p.waitFor(0L, null)); + THROWS(NullPointerException.class, + () -> p.waitFor(-1L, null)); + // Terminate process and recheck after it exits + p.destroy(); + p.waitFor(); + THROWS(NullPointerException.class, + () -> p.waitFor(10L, null)); + THROWS(NullPointerException.class, + () -> p.waitFor(0L, null)); + THROWS(NullPointerException.class, + () -> p.waitFor(-1L, null)); + } catch (Throwable t) { unexpected(t); } + //---------------------------------------------------------------- // Check the default implementation for // Process.waitFor(long, TimeUnit) From 07cd37173808518d4e2a71e6945785741ec277ab Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Mon, 23 Mar 2015 09:45:32 -0700 Subject: [PATCH 110/362] 8075670: Remove intermittent keyword from some tests Reviewed-by: alanb --- jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java | 1 - jdk/test/java/nio/channels/Selector/Wakeup.java | 1 - jdk/test/java/nio/file/Files/InterruptCopy.java | 1 - 3 files changed, 3 deletions(-) diff --git a/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java b/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java index 8f9e426a740..9442f9b5408 100644 --- a/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java +++ b/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java @@ -25,7 +25,6 @@ * @bug 4607272 6842687 6878369 6944810 7023403 * @summary Unit test for AsynchronousSocketChannel * @run main Basic -skipSlowConnectTest - * @key intermittent */ import java.nio.ByteBuffer; diff --git a/jdk/test/java/nio/channels/Selector/Wakeup.java b/jdk/test/java/nio/channels/Selector/Wakeup.java index e51bd1d38fc..40aa71729c8 100644 --- a/jdk/test/java/nio/channels/Selector/Wakeup.java +++ b/jdk/test/java/nio/channels/Selector/Wakeup.java @@ -25,7 +25,6 @@ * @bug 6405995 * @summary Unit test for selector wakeup and interruption * @library .. - * @key intermittent */ import java.io.*; diff --git a/jdk/test/java/nio/file/Files/InterruptCopy.java b/jdk/test/java/nio/file/Files/InterruptCopy.java index 29cfa006e40..c83479c9e46 100644 --- a/jdk/test/java/nio/file/Files/InterruptCopy.java +++ b/jdk/test/java/nio/file/Files/InterruptCopy.java @@ -25,7 +25,6 @@ * @bug 4313887 6993267 * @summary Unit test for Sun-specific ExtendedCopyOption.INTERRUPTIBLE option * @library .. - * @key intermittent */ import java.nio.file.*; From 2b63b5d1d76914fa75b884e386f7f84bbcde53f4 Mon Sep 17 00:00:00 2001 From: Lev Priima Date: Tue, 24 Mar 2015 03:46:57 -0400 Subject: [PATCH 111/362] 8075071: [TEST_BUG] TimSortStackSize2.java: OOME: Java heap space: MaxHeap shrinked by MaxRAMFraction Reviewed-by: dholmes --- .../java/util/Arrays/TimSortStackSize2.java | 53 ++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/jdk/test/java/util/Arrays/TimSortStackSize2.java b/jdk/test/java/util/Arrays/TimSortStackSize2.java index a456c883000..9e212fd00bd 100644 --- a/jdk/test/java/util/Arrays/TimSortStackSize2.java +++ b/jdk/test/java/util/Arrays/TimSortStackSize2.java @@ -24,22 +24,63 @@ /* * @test * @bug 8072909 - * @run main/othervm -Xms385m TimSortStackSize2 67108864 + * @library /lib/testlibrary /../../test/lib + * @build jdk.testlibrary.* + * @build TimSortStackSize2 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions + * -XX:+WhiteBoxAPI TimSortStackSize2 * @summary Test TimSort stack size on big arrays - * big tests not for regular execution on all platforms: - * run main/othervm -Xmx8g TimSortStackSize2 1073741824 - * run main/othervm -Xmx16g TimSortStackSize2 2147483644 */ import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.List; import java.util.function.Consumer; +import jdk.testlibrary.OutputAnalyzer; +import jdk.testlibrary.ProcessTools; +import jdk.testlibrary.Utils; +import sun.hotspot.WhiteBox; + public class TimSortStackSize2 { public static void main(String[] args) { - int lengthOfTest = Integer.parseInt(args[0]); + if ( args == null || args.length == 0 ){ + startMeWithArgs(); + } else { + doTestOfTwoTimSorts(Integer.parseInt(args[0])); + } + } + + private static void startMeWithArgs(){ + /* + * big tests not for regular execution on all platforms: + * run main/othervm -Xmx8g TimSortStackSize2 1073741824 + * run main/othervm -Xmx16g TimSortStackSize2 2147483644 + */ + try { + Boolean compressedOops = WhiteBox.getWhiteBox() + .getBooleanVMFlag("UseCompressedOops"); + final String xmsValue = "-Xms" + + ((compressedOops == null || compressedOops) ? "385" : "770") + + "m"; + System.out.println( "compressedOops: " + compressedOops + + "; Test will be started with \"" + xmsValue + "\""); + ProcessBuilder processBuilder = ProcessTools + .createJavaProcessBuilder(Utils.addTestJavaOpts(xmsValue, + "TimSortStackSize2", "67108864" + ) + ); + OutputAnalyzer output = ProcessTools.executeProcess(processBuilder); + System.out.println(output.getOutput()); + output.shouldHaveExitValue(0); + } catch( Exception e ){ + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + private static void doTestOfTwoTimSorts(final int lengthOfTest){ boolean passed = doTest("TimSort", lengthOfTest, (Integer [] a) -> Arrays.sort(a)); passed = doTest("ComparableTimSort", lengthOfTest, (Integer [] a) -> From 0803c083558fcb434b42cd6c879364c2caccd625 Mon Sep 17 00:00:00 2001 From: Athijegannathan Sundararajan Date: Tue, 24 Mar 2015 13:59:31 +0530 Subject: [PATCH 112/362] 8074410: Startup time: Port shell.js to Java Reviewed-by: lagergren, hannesw --- .../jdk/nashorn/internal/objects/Global.java | 12 ++ .../classes/jdk/nashorn/tools/Shell.java | 13 +-- .../jdk/nashorn/tools/ShellFunctions.java | 104 ++++++++++++++++++ .../jdk/nashorn/tools/resources/shell.js | 83 -------------- 4 files changed, 117 insertions(+), 95 deletions(-) create mode 100644 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/ShellFunctions.java delete mode 100644 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/resources/shell.js diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java index 46455911db3..305c86a40e9 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java @@ -77,6 +77,7 @@ import jdk.nashorn.internal.runtime.linker.InvokeByName; import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; import jdk.nashorn.internal.runtime.regexp.RegExpResult; import jdk.nashorn.internal.scripts.JO; +import jdk.nashorn.tools.ShellFunctions; /** * Representation of global scope. @@ -1816,6 +1817,17 @@ public final class Global extends ScriptObject implements Scope { return invocation; } + /** + * Adds jjs shell interactive mode builtin functions to global scope. + */ + public void addShellBuiltins() { + Object value = ScriptFunctionImpl.makeFunction("input", ShellFunctions.INPUT); + addOwnProperty("input", Attribute.NOT_ENUMERABLE, value); + + value = ScriptFunctionImpl.makeFunction("evalinput", ShellFunctions.EVALINPUT); + addOwnProperty("evalinput", Attribute.NOT_ENUMERABLE, value); + } + private synchronized SwitchPoint getLexicalScopeSwitchPoint() { SwitchPoint switchPoint = lexicalScopeSwitchPoint; if (switchPoint == null || switchPoint.hasBeenInvalidated()) { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/Shell.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/Shell.java index ac630ccaa79..4206eb88050 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/Shell.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/Shell.java @@ -417,18 +417,7 @@ public class Shell { Context.setGlobal(global); } - // initialize with "shell.js" script - try { - final Source source = sourceFor("", Shell.class.getResource("resources/shell.js")); - context.eval(global, source.getString(), global, "", false); - } catch (final Exception e) { - err.println(e); - if (env._dump_on_error) { - e.printStackTrace(err); - } - - return INTERNAL_ERROR; - } + global.addShellBuiltins(); while (true) { err.print(prompt); diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/ShellFunctions.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/ShellFunctions.java new file mode 100644 index 00000000000..0c4e4cb016d --- /dev/null +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/ShellFunctions.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2015, 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 jdk.nashorn.tools; + +import static jdk.nashorn.internal.lookup.Lookup.MH; +import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import jdk.nashorn.internal.runtime.JSType; +import jdk.nashorn.internal.objects.Global; + +/** + * Global functions supported only in shell interactive mode. + */ +public final class ShellFunctions { + + /** Handle to implementation of {@link ShellFunctions#input} - Nashorn extension */ + public static final MethodHandle INPUT = findOwnMH("input", Object.class, Object.class, Object.class, Object.class); + + /** Handle to implementation of {@link ShellFunctions#evalinput} - Nashorn extension */ + public static final MethodHandle EVALINPUT = findOwnMH("evalinput", Object.class, Object.class, Object.class, Object.class); + + private ShellFunctions() { + } + + /** + * Nashorn extension: global.input (shell-interactive-mode-only) + * Read one or more lines of input from the standard input till the + * given end marker is seen in standard input. + * + * @param self self reference + * @param endMarker String used as end marker for input + * @param prompt String used as input prompt + * + * @return line that was read + * + * @throws IOException if an exception occurs + */ + public static Object input(final Object self, final Object endMarker, final Object prompt) throws IOException { + final String endMarkerStr = (endMarker != UNDEFINED)? JSType.toString(endMarker) : ""; + final String promptStr = (prompt != UNDEFINED)? JSType.toString(prompt) : ">> "; + final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + final StringBuilder buf = new StringBuilder(); + while (true) { + System.out.print(promptStr); + final String line = reader.readLine(); + if (line == null || line.equals(endMarkerStr)) { + break; + } + buf.append(line); + buf.append('\n'); + } + return buf.toString(); + } + + /** + * Nashorn extension: Reads zero or more lines from standard input and + * evaluates the concatenated string as code + * + * @param self self reference + * @param endMarker String used as end marker for input + * @param prompt String used as input prompt + * + * @return output from evaluating the script + * + * @throws IOException if an exception occurs + */ + public static Object evalinput(final Object self, final Object endMarker, final Object prompt) throws IOException { + return Global.eval(self, input(self, endMarker, prompt)); + } + + private static MethodHandle findOwnMH(final String name, final Class rtype, final Class... types) { + return MH.findStatic(MethodHandles.lookup(), ShellFunctions.class, name, MH.type(rtype, types)); + } +} diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/resources/shell.js b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/resources/shell.js deleted file mode 100644 index fdfde7ad78a..00000000000 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/resources/shell.js +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2010, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * 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. - */ - -/* - * Initialization script for shell when running in interactive mode. - */ - -/** - * Reads zero or more lines from standard input and returns concatenated string - * - * @param endMarker marker string that signals end of input - * @param prompt prompt printed for each line - */ -Object.defineProperty(this, "input", { - value: function input(endMarker, prompt) { - if (!endMarker) { - endMarker = ""; - } - - if (!prompt) { - prompt = " >> "; - } - - var imports = new JavaImporter(java.io, java.lang); - var str = ""; - with (imports) { - var reader = new BufferedReader(new InputStreamReader(System['in'])); - var line; - while (true) { - System.out.print(prompt); - line = reader.readLine(); - if (line == null || line == endMarker) { - break; - } - str += line + "\n"; - } - } - - return str; - }, - enumerable: false, - writable: true, - configurable: true -}); - - -/** - * Reads zero or more lines from standard input and evaluates the concatenated - * string as code - * - * @param endMarker marker string that signals end of input - * @param prompt prompt printed for each line - */ -Object.defineProperty(this, "evalinput", { - value: function evalinput(endMarker, prompt) { - var code = input(endMarker, prompt); - // make sure everything is evaluated in global scope! - return this.eval(code); - }, - enumerable: false, - writable: true, - configurable: true -}); From 7f727ff4dfd7c2a6cfe47c698ce67a80a254d29d Mon Sep 17 00:00:00 2001 From: Stefan Johansson Date: Tue, 24 Mar 2015 10:24:31 +0100 Subject: [PATCH 113/362] 8075735: Missing include causes minimal build failure Added the missing include. Reviewed-by: jprovino, dholmes, stefank --- hotspot/src/share/vm/runtime/thread.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp index 622fb5c34bd..7d6596d30ff 100644 --- a/hotspot/src/share/vm/runtime/thread.cpp +++ b/hotspot/src/share/vm/runtime/thread.cpp @@ -87,8 +87,9 @@ #include "utilities/defaultStream.hpp" #include "utilities/dtrace.hpp" #include "utilities/events.hpp" -#include "utilities/preserveException.hpp" #include "utilities/macros.hpp" +#include "utilities/preserveException.hpp" +#include "utilities/workgroup.hpp" #if INCLUDE_ALL_GCS #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" #include "gc_implementation/g1/concurrentMarkThread.inline.hpp" From c8ac9172fc8ae77c1affe4a6f816c728fdb53355 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Tue, 24 Mar 2015 10:52:08 +0100 Subject: [PATCH 114/362] 8075717: Replace INTERNAL_BUILD with DEBUG in awt Reviewed-by: serb, azvegint --- jdk/make/lib/Awt2dLibraries.gmk | 8 -------- .../native/libawt_xawt/awt/gtk2_interface.c | 20 +++++++++---------- .../native/libawt_xawt/xawt/XlibWrapper.c | 5 ++--- .../native/libawt_xawt/xawt/gnome_interface.c | 12 +++++------ .../windows/native/libawt/windows/awt.h | 2 +- 5 files changed, 19 insertions(+), 28 deletions(-) diff --git a/jdk/make/lib/Awt2dLibraries.gmk b/jdk/make/lib/Awt2dLibraries.gmk index 549068675fd..c7ce8d9c202 100644 --- a/jdk/make/lib/Awt2dLibraries.gmk +++ b/jdk/make/lib/Awt2dLibraries.gmk @@ -236,10 +236,6 @@ ifeq ($(OPENJDK_TARGET_OS), windows) LIBAWT_VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/java.desktop/windows/native/libawt/windows/awt.rc endif -ifeq ($(MILESTONE), internal) - LIBAWT_CFLAGS += -DINTERNAL_BUILD -endif - LIBAWT_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libawt/mapfile-vers ifeq ($(OPENJDK_TARGET_OS), linux) LIBAWT_MAPFILE := @@ -347,10 +343,6 @@ ifeq ($(findstring $(OPENJDK_TARGET_OS),windows macosx),) endif endif - ifeq ($(MILESTONE), internal) - LIBAWT_XAWT_CFLAGS += -DINTERNAL_BUILD - endif - LIBAWT_XAWT_LDFLAGS_SUFFIX := $(LIBM) -lawt -lXext -lX11 -lXrender $(LIBDL) -lXtst -lXi -ljava -ljvm -lc ifeq ($(OPENJDK_TARGET_OS), linux) diff --git a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk2_interface.c b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk2_interface.c index 2e35e5ea43a..e8a45cb2059 100644 --- a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk2_interface.c +++ b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk2_interface.c @@ -368,9 +368,9 @@ const char *getStrFor(JNIEnv *env, jstring val) if (length > CONV_BUFFER_SIZE-1) { length = CONV_BUFFER_SIZE-1; -#ifdef INTERNAL_BUILD +#ifdef DEBUG fprintf(stderr, "Note: Detail is too long: %d chars\n", length); -#endif /* INTERNAL_BUILD */ +#endif /* DEBUG */ } (*env)->GetStringUTFRegion(env, val, 0, length, convertionBuffer); @@ -507,9 +507,9 @@ void update_supported_actions(JNIEnv *env) { } } } else { -#ifdef INTERNAL_BUILD +#ifdef DEBUG fprintf(stderr, "Cannot load g_vfs_get_supported_uri_schemes\n"); -#endif /* INTERNAL_BUILD */ +#endif /* DEBUG */ } } @@ -522,23 +522,23 @@ gboolean gtk2_show_uri_load(JNIEnv *env) { const char *gtk_version = fp_gtk_check_version(2, 14, 0); if (gtk_version != NULL) { // The gtk_show_uri is available from GTK+ 2.14 -#ifdef INTERNAL_BUILD +#ifdef DEBUG fprintf (stderr, "The version of GTK is %s. " "The gtk_show_uri function is supported " "since GTK+ 2.14.\n", gtk_version); -#endif /* INTERNAL_BUILD */ +#endif /* DEBUG */ } else { // Loading symbols only if the GTK version is 2.14 and higher fp_gtk_show_uri = dl_symbol("gtk_show_uri"); const char *dlsym_error = dlerror(); if (dlsym_error) { -#ifdef INTERNAL_BUILD +#ifdef DEBUG fprintf (stderr, "Cannot load symbol: %s \n", dlsym_error); -#endif /* INTERNAL_BUILD */ +#endif /* DEBUG */ } else if (fp_gtk_show_uri == NULL) { -#ifdef INTERNAL_BUILD +#ifdef DEBUG fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n"); -#endif /* INTERNAL_BUILD */ +#endif /* DEBUG */ } else { update_supported_actions(env); success = TRUE; diff --git a/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c b/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c index f1d63185186..c40200e5c6c 100644 --- a/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c +++ b/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -49,7 +49,7 @@ #include -#if defined(DEBUG) || defined(INTERNAL_BUILD) +#if defined(DEBUG) static jmethodID lockIsHeldMID = NULL; static void @@ -2346,4 +2346,3 @@ Java_sun_awt_X11_XlibWrapper_SetBitmapShape (*env)->ReleaseIntArrayElements(env, bitmap, values, JNI_ABORT); } - diff --git a/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/gnome_interface.c b/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/gnome_interface.c index 90d56de93d1..46c96e13680 100644 --- a/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/gnome_interface.c +++ b/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/gnome_interface.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -42,7 +42,7 @@ gboolean gnome_load() { // we are trying to load the library without a version suffix vfs_handle = dlopen(JNI_LIB_NAME("gnomevfs-2"), RTLD_LAZY); if (vfs_handle == NULL) { - #ifdef INTERNAL_BUILD + #ifdef DEBUG fprintf(stderr, "can not load libgnomevfs-2.so\n"); #endif return FALSE; @@ -51,13 +51,13 @@ gboolean gnome_load() { dlerror(); /* Clear errors */ gnome_vfs_init = (GNOME_VFS_INIT_TYPE*)dlsym(vfs_handle, "gnome_vfs_init"); if (gnome_vfs_init == NULL){ - #ifdef INTERNAL_BUILD + #ifdef DEBUG fprintf(stderr, "dlsym( gnome_vfs_init) returned NULL\n"); #endif return FALSE; } if ((errmsg = dlerror()) != NULL) { - #ifdef INTERNAL_BUILD + #ifdef DEBUG fprintf(stderr, "can not find symbol gnome_vfs_init %s \n", errmsg); #endif return FALSE; @@ -69,7 +69,7 @@ gboolean gnome_load() { if (gnome_handle == NULL) { gnome_handle = dlopen(JNI_LIB_NAME("gnome-2"), RTLD_LAZY); if (gnome_handle == NULL) { - #ifdef INTERNAL_BUILD + #ifdef DEBUG fprintf(stderr, "can not load libgnome-2.so\n"); #endif return FALSE; @@ -78,7 +78,7 @@ gboolean gnome_load() { dlerror(); /* Clear errors */ gnome_url_show = (GNOME_URL_SHOW_TYPE*)dlsym(gnome_handle, "gnome_url_show"); if ((errmsg = dlerror()) != NULL) { - #ifdef INTERNAL_BUILD + #ifdef DEBUG fprintf(stderr, "can not find symble gnome_url_show\n"); #endif return FALSE; diff --git a/jdk/src/java.desktop/windows/native/libawt/windows/awt.h b/jdk/src/java.desktop/windows/native/libawt/windows/awt.h index 83c3fcbeb8f..0a84f65e0a5 100644 --- a/jdk/src/java.desktop/windows/native/libawt/windows/awt.h +++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt.h @@ -228,7 +228,7 @@ extern JavaVM *jvm; /* * checks if the current thread is/isn't the toolkit thread */ -#if defined(DEBUG) || defined(INTERNAL_BUILD) +#if defined(DEBUG) #define CHECK_IS_TOOLKIT_THREAD() \ if (GetCurrentThreadId() != AwtToolkit::MainThread()) \ { JNU_ThrowInternalError(env,"Operation is not permitted on non-toolkit thread!\n"); } From 8efb3ab7c1cf0164237c50d60c4cd564b3d6a897 Mon Sep 17 00:00:00 2001 From: Mikael Gerdin Date: Tue, 24 Mar 2015 13:49:56 +0100 Subject: [PATCH 115/362] 8075511: Enable -Woverloaded-virtual C++ warning for HotSpot build Reviewed-by: erikj, simonis, ehelin --- hotspot/make/linux/makefiles/gcc.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotspot/make/linux/makefiles/gcc.make b/hotspot/make/linux/makefiles/gcc.make index c1d59e990a0..85aa5c33ded 100644 --- a/hotspot/make/linux/makefiles/gcc.make +++ b/hotspot/make/linux/makefiles/gcc.make @@ -207,7 +207,7 @@ ifeq ($(USE_CLANG), true) WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body endif -WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wunused-value -Wformat=2 -Wreturn-type +WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wunused-value -Wformat=2 -Wreturn-type -Woverloaded-virtual ifeq ($(USE_CLANG),) # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit From 0c57e77d43943d792a62fc80c38817b15ae88b5a Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Tue, 24 Mar 2015 11:21:21 +0100 Subject: [PATCH 116/362] 8075803: Fix GC includes and forward declarations Reviewed-by: pliden, mgerdin --- .../compactibleFreeListSpace.hpp | 4 +++- .../concurrentMarkSweepGeneration.hpp | 5 ++++- .../vm/gc_implementation/g1/concurrentMark.hpp | 1 + .../vm/gc_implementation/g1/g1CollectedHeap.hpp | 1 + .../gc_implementation/parNew/parNewGeneration.hpp | 1 + .../parNew/parOopClosures.inline.hpp | 3 ++- .../gc_implementation/parallelScavenge/pcTasks.cpp | 3 ++- .../parallelScavenge/psMarkSweep.hpp | 4 ++-- .../parallelScavenge/psParallelCompact.hpp | 3 +-- .../vm/gc_implementation/shared/markSweep.cpp | 10 +++++++++- .../vm/gc_implementation/shared/markSweep.hpp | 14 +++++--------- hotspot/src/share/vm/memory/defNewGeneration.hpp | 3 +++ .../share/vm/memory/defNewGeneration.inline.hpp | 4 +++- hotspot/src/share/vm/memory/space.cpp | 1 - hotspot/src/share/vm/oops/cpCache.cpp | 3 --- 15 files changed, 37 insertions(+), 23 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp index 72eecc19fbc..4c6fb3c5b1b 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -36,7 +36,9 @@ // space, in this case a CompactibleFreeListSpace. // Forward declarations +class CMSCollector; class CompactibleFreeListSpace; +class ConcurrentMarkSweepGeneration; class BlkClosure; class BlkClosureCareful; class FreeChunk; diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp index 98f13cbc258..c316db870e3 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -25,6 +25,7 @@ #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CONCURRENTMARKSWEEPGENERATION_HPP #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CONCURRENTMARKSWEEPGENERATION_HPP +#include "gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp" #include "gc_implementation/shared/gcHeapSummary.hpp" #include "gc_implementation/shared/gSpaceCounters.hpp" #include "gc_implementation/shared/gcStats.hpp" @@ -55,6 +56,7 @@ // means of a sliding mark-compact. class AdaptiveSizePolicy; +class CMSCollector; class CMSConcMarkingTask; class CMSGCAdaptivePolicyCounters; class CMSTracer; @@ -64,6 +66,7 @@ class ConcurrentMarkSweepPolicy; class ConcurrentMarkSweepThread; class CompactibleFreeListSpace; class FreeChunk; +class ParNewGeneration; class PromotionInfo; class ScanMarkedObjectsAgainCarefullyClosure; class TenuredGeneration; diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp index c8783171096..be9773b7991 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp @@ -34,6 +34,7 @@ class G1CollectedHeap; class CMBitMap; class CMTask; +class ConcurrentMark; typedef GenericTaskQueue CMTaskQueue; typedef GenericTaskQueueSet CMTaskQueueSet; diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp index 91b47100797..11955f403af 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @@ -56,6 +56,7 @@ class HRRSCleanupTask; class GenerationSpec; class OopsInHeapRegionClosure; class G1KlassScanClosure; +class G1ParScanThreadState; class ObjectClosure; class SpaceClosure; class CompactibleSpaceClosure; diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp index aa97271ac85..8e81515ed69 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp @@ -25,6 +25,7 @@ #ifndef SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP #define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP +#include "gc_implementation/parNew/parOopClosures.hpp" #include "gc_implementation/shared/gcTrace.hpp" #include "gc_implementation/shared/parGCAllocBuffer.hpp" #include "gc_implementation/shared/copyFailedInfo.hpp" diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parOopClosures.inline.hpp b/hotspot/src/share/vm/gc_implementation/parNew/parOopClosures.inline.hpp index 9658d59e1e4..93000ce2f84 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parOopClosures.inline.hpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parOopClosures.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2015, 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 @@ -29,6 +29,7 @@ #include "gc_implementation/parNew/parOopClosures.hpp" #include "memory/cardTableRS.hpp" #include "memory/genCollectedHeap.hpp" +#include "memory/genOopClosures.inline.hpp" template inline void ParScanWeakRefClosure::do_oop_work(T* p) { assert (!oopDesc::is_null(*p), "null weak reference?"); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp index bd22eb5574f..c277038c904 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -25,6 +25,7 @@ #include "precompiled.hpp" #include "classfile/systemDictionary.hpp" #include "code/codeCache.hpp" +#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" #include "gc_implementation/parallelScavenge/pcTasks.hpp" #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" #include "gc_implementation/shared/gcTimer.hpp" diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.hpp index 7b5678db161..2c97a150cb0 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -26,7 +26,7 @@ #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSMARKSWEEP_HPP #include "gc_implementation/shared/collectorCounters.hpp" -#include "gc_implementation/shared/markSweep.inline.hpp" +#include "gc_implementation/shared/markSweep.hpp" #include "utilities/stack.hpp" class PSAdaptiveSizePolicy; diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp index c098e455741..d402309851f 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -29,7 +29,6 @@ #include "gc_implementation/parallelScavenge/parMarkBitMap.hpp" #include "gc_implementation/parallelScavenge/psCompactionManager.hpp" #include "gc_implementation/shared/collectorCounters.hpp" -#include "gc_implementation/shared/markSweep.hpp" #include "gc_implementation/shared/mutableSpace.hpp" #include "memory/sharedHeap.hpp" #include "oops/oop.hpp" diff --git a/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp b/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp index 309a955d8a3..01e7e88f5b8 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp +++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -84,6 +84,14 @@ MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure; void MarkSweep::FollowStackClosure::do_void() { follow_stack(); } +void PreservedMark::adjust_pointer() { + MarkSweep::adjust_pointer(&_obj); +} + +void PreservedMark::restore() { + _obj->set_mark(_mark); +} + // We preserve the mark which should be replaced at the end and the location // that it will go. Note that the object that this markOop belongs to isn't // currently at that address but it will be after phase4 diff --git a/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp b/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp index 462643e2f52..37928ea2ac6 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp +++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -26,7 +26,8 @@ #define SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP #include "gc_interface/collectedHeap.hpp" -#include "memory/universe.hpp" +#include "memory/genOopClosures.hpp" +#include "memory/iterator.hpp" #include "oops/markOop.hpp" #include "oops/oop.hpp" #include "runtime/timer.hpp" @@ -182,13 +183,8 @@ public: _mark = mark; } - void adjust_pointer() { - MarkSweep::adjust_pointer(&_obj); - } - - void restore() { - _obj->set_mark(_mark); - } + void adjust_pointer(); + void restore(); }; #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP diff --git a/hotspot/src/share/vm/memory/defNewGeneration.hpp b/hotspot/src/share/vm/memory/defNewGeneration.hpp index 4e7899eb229..4d12a022359 100644 --- a/hotspot/src/share/vm/memory/defNewGeneration.hpp +++ b/hotspot/src/share/vm/memory/defNewGeneration.hpp @@ -29,11 +29,14 @@ #include "gc_implementation/shared/cSpaceCounters.hpp" #include "gc_implementation/shared/generationCounters.hpp" #include "gc_implementation/shared/copyFailedInfo.hpp" +#include "memory/generation.hpp" #include "utilities/stack.hpp" class ContiguousSpace; class ScanClosure; class STWGCTimer; +class CSpaceCounters; +class ScanWeakRefClosure; // DefNewGeneration is a young generation containing eden, from- and // to-space. diff --git a/hotspot/src/share/vm/memory/defNewGeneration.inline.hpp b/hotspot/src/share/vm/memory/defNewGeneration.inline.hpp index d30ad37885d..111db332bab 100644 --- a/hotspot/src/share/vm/memory/defNewGeneration.inline.hpp +++ b/hotspot/src/share/vm/memory/defNewGeneration.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -25,8 +25,10 @@ #ifndef SHARE_VM_MEMORY_DEFNEWGENERATION_INLINE_HPP #define SHARE_VM_MEMORY_DEFNEWGENERATION_INLINE_HPP +#include "gc_interface/collectedHeap.hpp" #include "memory/cardTableRS.hpp" #include "memory/defNewGeneration.hpp" +#include "memory/genOopClosures.inline.hpp" #include "memory/space.hpp" // Methods of protected closure types diff --git a/hotspot/src/share/vm/memory/space.cpp b/hotspot/src/share/vm/memory/space.cpp index a7ea1b648f0..6e9984f9860 100644 --- a/hotspot/src/share/vm/memory/space.cpp +++ b/hotspot/src/share/vm/memory/space.cpp @@ -26,7 +26,6 @@ #include "classfile/systemDictionary.hpp" #include "classfile/vmSymbols.hpp" #include "gc_implementation/shared/liveRange.hpp" -#include "gc_implementation/shared/markSweep.hpp" #include "gc_implementation/shared/spaceDecorator.hpp" #include "gc_interface/collectedHeap.inline.hpp" #include "memory/blockOffsetTable.inline.hpp" diff --git a/hotspot/src/share/vm/oops/cpCache.cpp b/hotspot/src/share/vm/oops/cpCache.cpp index f9f73d218da..90416b468fc 100644 --- a/hotspot/src/share/vm/oops/cpCache.cpp +++ b/hotspot/src/share/vm/oops/cpCache.cpp @@ -35,9 +35,6 @@ #include "runtime/handles.inline.hpp" #include "runtime/orderAccess.inline.hpp" #include "utilities/macros.hpp" -#if INCLUDE_ALL_GCS -# include "gc_implementation/parallelScavenge/psPromotionManager.hpp" -#endif // INCLUDE_ALL_GCS PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC From 82dd135b5fb6b3262c5fbbb6c047d16025b5ec8a Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Tue, 24 Mar 2015 14:48:11 +0000 Subject: [PATCH 117/362] 8075824: Add default[Read|Write]Object to java.util.Date Reviewed-by: alanb, rriggs --- jdk/src/java.base/share/classes/java/util/Date.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jdk/src/java.base/share/classes/java/util/Date.java b/jdk/src/java.base/share/classes/java/util/Date.java index c05f50c4b95..253b67a792a 100644 --- a/jdk/src/java.base/share/classes/java/util/Date.java +++ b/jdk/src/java.base/share/classes/java/util/Date.java @@ -1317,6 +1317,7 @@ public class Date private void writeObject(ObjectOutputStream s) throws IOException { + s.defaultWriteObject(); s.writeLong(getTimeImpl()); } @@ -1326,6 +1327,7 @@ public class Date private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { + s.defaultReadObject(); fastTime = s.readLong(); } From 6a2c954d633d1edbb1aaff3c7f46900c0330a9ea Mon Sep 17 00:00:00 2001 From: Jason Uh Date: Tue, 24 Mar 2015 11:31:04 -0700 Subject: [PATCH 118/362] 8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages Reviewed-by: mullan --- .../com/sun/net/ssl/HttpsURLConnection.java | 9 +++---- .../https/HttpsURLConnectionOldImpl.java | 21 +--------------- .../AbstractDelegateHttpsURLConnection.java | 21 ---------------- .../net/www/protocol/https/HttpsClient.java | 15 ------------ .../https/HttpsURLConnectionImpl.java | 24 ------------------- .../net/ssl/FixingJavadocs/ComURLNulls.java | 4 ++-- .../https/NewImpl/ComHTTPSConnection.java | 8 +++---- 7 files changed, 12 insertions(+), 90 deletions(-) diff --git a/jdk/src/java.base/share/classes/com/sun/net/ssl/HttpsURLConnection.java b/jdk/src/java.base/share/classes/com/sun/net/ssl/HttpsURLConnection.java index c60435331ec..6ce3b16ff0b 100644 --- a/jdk/src/java.base/share/classes/com/sun/net/ssl/HttpsURLConnection.java +++ b/jdk/src/java.base/share/classes/com/sun/net/ssl/HttpsURLConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, 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 @@ -32,10 +32,10 @@ package com.sun.net.ssl; import java.net.URL; import java.net.HttpURLConnection; import java.io.IOException; +import java.security.cert.Certificate; import javax.net.SocketFactory; import javax.net.ssl.SSLSocketFactory; - -import javax.security.cert.X509Certificate; +import javax.net.ssl.SSLPeerUnverifiedException; /** * HTTP URL connection with support for HTTPS-specific features. See @@ -70,7 +70,8 @@ class HttpsURLConnection extends HttpURLConnection * the server did not authenticate. * @return the server certificate chain */ - public abstract X509Certificate [] getServerCertificateChain(); + public abstract Certificate[] getServerCertificates() + throws SSLPeerUnverifiedException; /** * HostnameVerifier provides a callback mechanism so that diff --git a/jdk/src/java.base/share/classes/com/sun/net/ssl/internal/www/protocol/https/HttpsURLConnectionOldImpl.java b/jdk/src/java.base/share/classes/com/sun/net/ssl/internal/www/protocol/https/HttpsURLConnectionOldImpl.java index fba0b3befce..07ff87ba85a 100644 --- a/jdk/src/java.base/share/classes/com/sun/net/ssl/internal/www/protocol/https/HttpsURLConnectionOldImpl.java +++ b/jdk/src/java.base/share/classes/com/sun/net/ssl/internal/www/protocol/https/HttpsURLConnectionOldImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2015, 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 @@ -187,25 +187,6 @@ public class HttpsURLConnectionOldImpl return delegate.getServerCertificates(); } - /** - * Returns the server's X.509 certificate chain, or null if - * the server did not authenticate. - * - * NOTE: This method is not necessary for the version of this class - * implementing javax.net.ssl.HttpsURLConnection, but provided for - * compatibility with the com.sun.net.ssl.HttpsURLConnection version. - */ - public javax.security.cert.X509Certificate[] getServerCertificateChain() { - try { - return delegate.getServerCertificateChain(); - } catch (SSLPeerUnverifiedException e) { - // this method does not throw an exception as declared in - // com.sun.net.ssl.HttpsURLConnection. - // Return null for compatibility. - return null; - } - } - /* * Allowable input/output sequences: * [interpreted as POST/PUT] diff --git a/jdk/src/java.base/share/classes/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java b/jdk/src/java.base/share/classes/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java index 9d70053d35f..cb80173b506 100644 --- a/jdk/src/java.base/share/classes/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java +++ b/jdk/src/java.base/share/classes/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java @@ -261,27 +261,6 @@ public abstract class AbstractDelegateHttpsURLConnection extends } } - /** - * Returns the server's X.509 certificate chain, or null if - * the server did not authenticate. - * - * @deprecated This method returns the deprecated - * {@code javax.security.cert.X509Certificate} type. - * Use {@code getServerCertificates()} instead. - */ - @Deprecated - public javax.security.cert.X509Certificate[] getServerCertificateChain() - throws SSLPeerUnverifiedException { - if (cachedResponse != null) { - throw new UnsupportedOperationException("this method is not supported when using cache"); - } - if (http == null) { - throw new IllegalStateException("connection not yet open"); - } else { - return ((HttpsClient)http).getServerCertificateChain(); - } - } - /** * Returns the server's principal, or throws SSLPeerUnverifiedException * if the server did not authenticate. diff --git a/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsClient.java b/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsClient.java index 5bc55ed9e50..3aecc419cb2 100644 --- a/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsClient.java +++ b/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsClient.java @@ -696,21 +696,6 @@ final class HttpsClient extends HttpClient return session.getPeerCertificates(); } - /** - * Returns the X.509 certificate chain with which the server - * authenticated itself, or null if the server did not authenticate. - * - * @deprecated This method returns the deprecated - * {@code javax.security.cert.X509Certificate} type. - * Use {@code getServerCertificates()} instead. - */ - @Deprecated - javax.security.cert.X509Certificate [] getServerCertificateChain() - throws SSLPeerUnverifiedException - { - return session.getPeerCertificateChain(); - } - /** * Returns the principal with which the server authenticated * itself, or throw a SSLPeerUnverifiedException if the diff --git a/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java b/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java index 5477b2cab80..429079804f0 100644 --- a/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java +++ b/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java @@ -197,30 +197,6 @@ public class HttpsURLConnectionImpl return delegate.getServerCertificates(); } - /** - * Returns the server's X.509 certificate chain, or null if - * the server did not authenticate. - * - * NOTE: This method is not necessary for the version of this class - * implementing javax.net.ssl.HttpsURLConnection, but provided for - * compatibility with the com.sun.net.ssl.HttpsURLConnection version. - * - * @deprecated This method returns the deprecated - * {@code javax.security.cert.X509Certificate} type. - * Use {@code getServerCertificates()} instead. - */ - @Deprecated - public javax.security.cert.X509Certificate[] getServerCertificateChain() { - try { - return delegate.getServerCertificateChain(); - } catch (SSLPeerUnverifiedException e) { - // this method does not throw an exception as declared in - // com.sun.net.ssl.HttpsURLConnection. - // Return null for compatibility. - return null; - } - } - /** * Returns the principal with which the server authenticated itself, * or throw a SSLPeerUnverifiedException if the server did not authenticate. diff --git a/jdk/test/javax/net/ssl/FixingJavadocs/ComURLNulls.java b/jdk/test/javax/net/ssl/FixingJavadocs/ComURLNulls.java index 88aa92772c8..e0dc82a2dc1 100644 --- a/jdk/test/javax/net/ssl/FixingJavadocs/ComURLNulls.java +++ b/jdk/test/javax/net/ssl/FixingJavadocs/ComURLNulls.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -80,7 +80,7 @@ public class ComURLNulls { } try { - urlc.getServerCertificateChain(); + urlc.getServerCertificates(); } catch (IllegalStateException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); diff --git a/jdk/test/sun/net/www/protocol/https/NewImpl/ComHTTPSConnection.java b/jdk/test/sun/net/www/protocol/https/NewImpl/ComHTTPSConnection.java index 486d234003c..24e2572f78f 100644 --- a/jdk/test/sun/net/www/protocol/https/NewImpl/ComHTTPSConnection.java +++ b/jdk/test/sun/net/www/protocol/https/NewImpl/ComHTTPSConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -34,8 +34,8 @@ import java.io.*; import java.net.*; +import java.security.cert.Certificate; import javax.net.ssl.*; -import javax.security.cert.*; import com.sun.net.ssl.HostnameVerifier; import com.sun.net.ssl.HttpsURLConnection; @@ -240,8 +240,8 @@ public class ComHTTPSConnection { System.out.println("Cipher Suite: " + ((HttpsURLConnection)urlc).getCipherSuite()); - X509Certificate[] certs = - ((HttpsURLConnection)urlc).getServerCertificateChain(); + Certificate[] certs = + ((HttpsURLConnection)urlc).getServerCertificates(); for (int i = 0; i < certs.length; i++) { System.out.println(certs[0]); } From b2805ba95add88d3b92547dd520947ceef908acd Mon Sep 17 00:00:00 2001 From: Amy Lu Date: Tue, 24 Mar 2015 21:11:48 -0700 Subject: [PATCH 119/362] 8075692: jaxp/test/Makefile reference of win32 directory no longer valid Reviewed-by: joehw --- jaxp/test/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jaxp/test/Makefile b/jaxp/test/Makefile index 0a3acdafb7c..912f2b98406 100644 --- a/jaxp/test/Makefile +++ b/jaxp/test/Makefile @@ -262,8 +262,8 @@ ifdef CONCURRENCY EXTRA_JTREG_OPTIONS += -concurrency:$(CONCURRENCY) endif -# Default JTREG to run (win32 script works for everybody) -JTREG = $(JT_HOME)/win32/bin/jtreg +# Default JTREG to run +JTREG = $(JT_HOME)/bin/jtreg # run in agentvm mode JTREG_BASIC_OPTIONS += -agentvm # Only run automatic tests From 22d4785f1d0d291afc2948c884ec4c7ab9e87937 Mon Sep 17 00:00:00 2001 From: Andrei Eremeev Date: Wed, 25 Mar 2015 10:29:14 +0300 Subject: [PATCH 120/362] 8049238: Implement classfile tests for Signature attribute Reviewed-by: jjg, shurailine, anazarov --- .../attributes/Signature/ConstructorTest.java | 170 ++++++ .../attributes/Signature/Driver.java | 239 ++++++++ .../attributes/Signature/EnumTest.java | 39 ++ .../attributes/Signature/ExceptionTest.java | 98 ++++ .../Signature/ExpectedSignature.java | 34 ++ .../Signature/ExpectedSignatureContainer.java | 30 + .../attributes/Signature/FieldTest.java | 206 +++++++ .../attributes/Signature/InnerClassTest.java | 362 ++++++++++++ .../Signature/MethodParameterTest.java | 203 +++++++ .../Signature/MethodTypeBoundTest.java | 79 +++ .../attributes/Signature/ReturnTypeTest.java | 549 ++++++++++++++++++ .../classfiles/attributes/lib/TestResult.java | 36 +- 12 files changed, 2032 insertions(+), 13 deletions(-) create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/ConstructorTest.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/Driver.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/EnumTest.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/ExceptionTest.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignature.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignatureContainer.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/FieldTest.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/InnerClassTest.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/MethodParameterTest.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/MethodTypeBoundTest.java create mode 100644 langtools/test/tools/javac/classfiles/attributes/Signature/ReturnTypeTest.java diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/ConstructorTest.java b/langtools/test/tools/javac/classfiles/attributes/Signature/ConstructorTest.java new file mode 100644 index 00000000000..cf1c5e149dd --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ConstructorTest.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for constructors. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build ConstructorTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver ConstructorTest + */ + +import java.lang.ref.ReferenceQueue; +import java.util.*; + +@ExpectedSignature(descriptor = "ConstructorTest", signature = "Ljava/lang/Object;") +public class ConstructorTest { + + @ExpectedSignature(descriptor = "(java.lang.Object, boolean)", signature = "(TT;Z)V") + ConstructorTest(T a, boolean b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, byte)", signature = "(TT;B)V") + ConstructorTest(T a, byte b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, char)", signature = "(TT;C)V") + ConstructorTest(T a, char b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, short)", signature = "(TT;S)V") + ConstructorTest(T a, short b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, int)", signature = "(TT;I)V") + ConstructorTest(T a, int b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, long)", signature = "(TT;J)V") + ConstructorTest(T a, long b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, float)", signature = "(TT;F)V") + ConstructorTest(T a, float b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, double)", signature = "(TT;D)V") + ConstructorTest(T a, double b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, java.lang.Runnable)", signature = "(TT;Ljava/lang/Runnable;)V") + ConstructorTest(T a, Runnable r) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, boolean[])", signature = "(TT;[Z)V") + ConstructorTest(T a, boolean[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, byte[])", signature = "(TT;[B)V") + ConstructorTest(T a, byte[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, char[])", signature = "(TT;[C)V") + ConstructorTest(T a, char[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, short[])", signature = "(TT;[S)V") + ConstructorTest(T a, short[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, int[])", signature = "(TT;[I)V") + ConstructorTest(T a, int[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, long[])", signature = "(TT;[J)V") + ConstructorTest(T a, long[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, float[])", signature = "(TT;[F)V") + ConstructorTest(T a, float[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, double[])", signature = "(TT;[D)V") + ConstructorTest(T a, double[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, java.lang.Runnable[])", signature = "(TT;[Ljava/lang/Runnable;)V") + ConstructorTest(T a, Runnable[] r) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object[])", signature = "([TT;)V") + ConstructorTest(T[] a) { + } + + @ExpectedSignature(descriptor = "(java.lang.Runnable[])", + signature = "([TT;)V") + ConstructorTest(T...a) { + } + + @ExpectedSignature(descriptor = "(java.util.Map)", signature = "(Ljava/util/Map<**>;)V") + ConstructorTest(Map a) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object)", signature = "(TT;)V") + ConstructorTest(T a) { + } + + @ExpectedSignature(descriptor = "(java.util.Set, java.util.Set)", + signature = ";>(TE;TE;)V") + > ConstructorTest(E a, E b) { + } + + @ExpectedSignature(descriptor = "(java.lang.ref.ReferenceQueue, java.lang.ref.ReferenceQueue)", + signature = ";:Ljava/util/Map<-TT;+TT;>;>(TE;TE;)V") + & Map> ConstructorTest(E a, E b) { + } + + @ExpectedSignature(descriptor = "(java.util.List)", signature = "(Ljava/util/List<+TT;>;)V") + ConstructorTest(List b) { + } + + @ExpectedSignature(descriptor = "(java.util.Set)", signature = "(Ljava/util/Set<-TT;>;)V") + ConstructorTest(Set b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Runnable)", signature = "(TE;)V") + ConstructorTest(E a) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, java.lang.Object)", signature = "(TT;TE;)V") + ConstructorTest(T a, E b) { + } + + // no Signature attribute + ConstructorTest(boolean b) { + } + + // no Signature attribute + ConstructorTest(HashMap a) { + } + + // no Signature attribute + ConstructorTest(boolean[] b) { + } + + // no Signature attribute + ConstructorTest(HashMap[] a) { + } +} diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/Driver.java b/langtools/test/tools/javac/classfiles/attributes/Signature/Driver.java new file mode 100644 index 00000000000..800851863f4 --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/Driver.java @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +import com.sun.tools.classfile.*; +import com.sun.tools.classfile.Field; +import com.sun.tools.classfile.Method; + +import java.io.File; +import java.io.FilenameFilter; +import java.lang.reflect.*; +import java.util.*; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * The main class of Signature tests. + * Driver reads golden data of each class member that must have a Signature attribute, + * after that the class compares expected data with actual one. + * + * Example of usage Driver: + * java Driver Test + * + * Each member of the class Test should have @ExpectedSignature annotations + * if it must have the Signature attribute. Anonymous class cannot be annotated. + * So its enclosing class should be annotated and method isAnonymous + * of ExpectedSignature must return true. + */ +public class Driver extends TestResult { + + private final static String ACC_BRIDGE = "ACC_BRIDGE"; + + private final String topLevelClassName; + private final File[] files; + + public Driver(String topLevelClassName) { + this.topLevelClassName = topLevelClassName; + // Get top level class and all inner classes. + FilenameFilter filter = (dir, file) -> + file.equals(topLevelClassName + ".class") + || file.matches(topLevelClassName + "\\$.*\\.class"); + files = getClassDir().listFiles(filter); + } + + private boolean isAnonymous(String className) { + return className.matches(".*\\$\\d+$"); + } + + private Class getEnclosingClass(String className) throws ClassNotFoundException { + return Class.forName(className.replaceFirst("\\$\\d+$", "")); + } + + private ExpectedSignature getExpectedClassSignature(String className, Class clazz) + throws ClassNotFoundException { + // anonymous class cannot be annotated, so information about anonymous class + // is located in its enclosing class. + boolean isAnonymous = isAnonymous(className); + clazz = isAnonymous ? getEnclosingClass(className) : clazz; + return Stream.of(clazz.getAnnotationsByType(ExpectedSignature.class)) + .filter(s -> s.isAnonymous() == isAnonymous) + .collect(Collectors.toMap(ExpectedSignature::descriptor, Function.identity())) + .get(className); + } + + // Class.getName() cannot be used here, because the method can rely on signature attribute. + private Map getClassExpectedSignature(String className, Class clazz) + throws ClassNotFoundException { + Map classSignatures = new HashMap<>(); + ExpectedSignature classSignature = getExpectedClassSignature(className, clazz); + if (classSignature != null) { + classSignatures.put(className, classSignature); + } + return classSignatures; + } + + private Map getExpectedExecutableSignatures(Executable[] executables, + Predicate filterBridge) { + return Stream.of(executables) + .filter(filterBridge) + .map(e -> e.getAnnotation(ExpectedSignature.class)) + .filter(Objects::nonNull) + .collect(Collectors.toMap(ExpectedSignature::descriptor, Function.identity())); + } + + private Map getExpectedMethodSignatures(Class clazz) { + Map methodSignatures = + getExpectedExecutableSignatures(clazz.getDeclaredMethods(), + m -> !((java.lang.reflect.Method) m).isBridge()); + methodSignatures.putAll( + getExpectedExecutableSignatures(clazz.getDeclaredConstructors(), + m -> true)); + return methodSignatures; + } + + private Map getExpectedFieldSignatures(Class clazz) { + return Stream.of(clazz.getDeclaredFields()) + .map(f -> f.getAnnotation(ExpectedSignature.class)) + .filter(Objects::nonNull) + .collect(Collectors.toMap(ExpectedSignature::descriptor, Function.identity())); + } + + public void test() throws TestFailedException { + try { + addTestCase("Source is " + topLevelClassName + ".java"); + assertTrue(files.length > 0, "No class files found"); + for (File file : files) { + try { + String className = file.getName().replace(".class", ""); + Class clazz = Class.forName(className); + printf("Testing class %s\n", className); + ClassFile classFile = readClassFile(file); + + // test class signature + testAttribute( + className, + classFile, + () -> (Signature_attribute) classFile.getAttribute(Attribute.Signature), + getClassExpectedSignature(className, clazz).get(className)); + + testFields(getExpectedFieldSignatures(clazz), classFile); + + testMethods(getExpectedMethodSignatures(clazz), classFile); + } catch (Exception e) { + addFailure(e); + } + } + } catch (Exception e) { + addFailure(e); + } finally { + checkStatus(); + } + } + + private void checkAllMembersFound(Set found, Map signatures, String message) { + if (signatures != null) { + checkContains(found, + signatures.values().stream() + .map(ExpectedSignature::descriptor) + .collect(Collectors.toSet()), + message); + } + } + + private void testMethods(Map expectedSignatures, ClassFile classFile) + throws ConstantPoolException, Descriptor.InvalidDescriptor { + String className = classFile.getName(); + Set foundMethods = new HashSet<>(); + for (Method method : classFile.methods) { + String methodName = getMethodName(classFile, method); + printf("Testing method %s\n", methodName); + if (method.access_flags.getMethodFlags().contains(ACC_BRIDGE)) { + printf("Bridge method is skipped : %s\n", methodName); + continue; + } + testAttribute( + methodName, + classFile, + () -> (Signature_attribute) method.attributes.get(Attribute.Signature), + expectedSignatures.get(methodName)); + foundMethods.add(methodName); + } + checkAllMembersFound(foundMethods, expectedSignatures, + "Checking that all methods of class " + className + " with Signature attribute found"); + } + + private String getMethodName(ClassFile classFile, Method method) + throws ConstantPoolException, Descriptor.InvalidDescriptor { + return String.format("%s%s", + method.getName(classFile.constant_pool), + method.descriptor.getParameterTypes(classFile.constant_pool)); + } + + private void testFields(Map expectedSignatures, ClassFile classFile) + throws ConstantPoolException { + String className = classFile.getName(); + Set foundFields = new HashSet<>(); + for (Field field : classFile.fields) { + String fieldName = field.getName(classFile.constant_pool); + printf("Testing field %s\n", fieldName); + testAttribute( + fieldName, + classFile, + () -> (Signature_attribute) field.attributes.get(Attribute.Signature), + expectedSignatures.get(fieldName)); + foundFields.add(fieldName); + } + checkAllMembersFound(foundFields, expectedSignatures, + "Checking that all fields of class " + className + " with Signature attribute found"); + } + + private void testAttribute( + String memberName, + ClassFile classFile, + Supplier sup, + ExpectedSignature expectedSignature) + throws ConstantPoolException { + + Signature_attribute attribute = sup.get(); + if (expectedSignature != null && checkNotNull(attribute, memberName + " must have attribute")) { + checkEquals(classFile.constant_pool.getUTF8Value(attribute.attribute_name_index), + "Signature", "Attribute's name : " + memberName); + checkEquals(attribute.attribute_length, 2, "Attribute's length : " + memberName); + checkEquals(attribute.getSignature(classFile.constant_pool), + expectedSignature.signature(), + "Testing signature of : " + memberName); + } else { + checkNull(attribute, memberName + " must not have attribute"); + } + } + + public static void main(String[] args) throws TestFailedException { + if (args.length != 1) { + throw new IllegalArgumentException("Usage: Driver "); + } + new Driver(args[0]).test(); + } +} \ No newline at end of file diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/EnumTest.java b/langtools/test/tools/javac/classfiles/attributes/Signature/EnumTest.java new file mode 100644 index 00000000000..6f4572dddcb --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/EnumTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for enum. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build EnumTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver EnumTest + */ + +@ExpectedSignature(descriptor = "EnumTest", signature = "Ljava/lang/Enum;") +public enum EnumTest {; + // see 8026480 + @ExpectedSignature(descriptor = "(java.lang.String, int)", signature = "()V") + private EnumTest() {} +} \ No newline at end of file diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/ExceptionTest.java b/langtools/test/tools/javac/classfiles/attributes/Signature/ExceptionTest.java new file mode 100644 index 00000000000..075456e8fd7 --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ExceptionTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for methods which throw exceptions. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build ExceptionTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver ExceptionTest + */ + +import java.io.IOError; +import java.io.IOException; + +@ExpectedSignature(descriptor = "ExceptionTest", + signature = "Ljava/lang/Object;") +public class ExceptionTest { + + @ExpectedSignature(descriptor = "()", signature = "()V^TE;") + ExceptionTest() throws E { + } + + @ExpectedSignature(descriptor = "(int)", + signature = "(I)V^Ljava/io/IOException;^TE;^Ljava/io/IOError;") + ExceptionTest(int a) throws IOException, E, IOError { + } + + @ExpectedSignature(descriptor = "(long)", signature = "(J)V^TExc;") + ExceptionTest(long a) throws Exc { + } + + @ExpectedSignature(descriptor = "(byte)", signature = "(B)V^Ljava/io/IOError;^TExc;^Ljava/io/IOException;") + ExceptionTest(byte a) throws IOError, Exc, IOException { + } + + @ExpectedSignature(descriptor = "(java.lang.RuntimeException)", signature = "(TExc;)V") + ExceptionTest(Exc a) throws IOException { + } + + // no Signature attribute + ExceptionTest(String a) throws IOError { + } + + void noSignatureAttributeMethod() throws IOException { + } + + @ExpectedSignature(descriptor = "genericMethod(int)", signature = "(I)V^TExc;") + void genericMethod(int a) throws Exc { + } + + @ExpectedSignature(descriptor = "genericMethod(long)", signature = "(J)V^TExc;^Ljava/io/IOException;") + void genericMethod(long a) throws Exc, IOException { + } + + @ExpectedSignature(descriptor = "genericMethod(java.lang.RuntimeException)", signature = "(TExc;)V") + void genericMethod(Exc a) throws IOError { + } + + static void staticNoSignatureAttributeMethod() throws IOException { + } + + @ExpectedSignature(descriptor = "staticGenericMethod(int)", + signature = "(I)V^TE;") + static void staticGenericMethod(int a) throws E { + } + + @ExpectedSignature(descriptor = "staticGenericMethod(long)", + signature = "(J)V^Ljava/io/IOError;^TE;^Ljava/io/IOException;") + static void staticGenericMethod(long a) throws IOError, E, IOException { + } + + @ExpectedSignature(descriptor = "staticGenericMethod(java.lang.Exception)", + signature = "(TE;)V") + static void staticGenericMethod(E a) throws IOError { + } +} diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignature.java b/langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignature.java new file mode 100644 index 00000000000..293aba32690 --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignature.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Repeatable(ExpectedSignatureContainer.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExpectedSignature { + boolean isAnonymous() default false; + String descriptor(); + String signature(); +} \ No newline at end of file diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignatureContainer.java b/langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignatureContainer.java new file mode 100644 index 00000000000..c2141a0d14b --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignatureContainer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface ExpectedSignatureContainer { + ExpectedSignature[] value(); +} \ No newline at end of file diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/FieldTest.java b/langtools/test/tools/javac/classfiles/attributes/Signature/FieldTest.java new file mode 100644 index 00000000000..f71ace02e4a --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/FieldTest.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for fields. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build FieldTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver FieldTest + */ + +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +@ExpectedSignature(descriptor = "FieldTest", signature = "Ljava/lang/Object;") +public class FieldTest { + + @ExpectedSignature(descriptor = "typeInList", signature = "Ljava/util/List;") + List typeInList; + + @ExpectedSignature(descriptor = "boundsType", signature = "Ljava/util/List;>;") + List> boundsType; + + @ExpectedSignature(descriptor = "type", signature = "TT;") + T type; + + @ExpectedSignature(descriptor = "typeInArray", signature = "[TT;") + T[] typeInArray; + + @ExpectedSignature(descriptor = "byteArrayInList", signature = "Ljava/util/List<[B>;") + List byteArrayInList; + + @ExpectedSignature(descriptor = "shortArrayInList", signature = "Ljava/util/List<[S>;") + List shortArrayInList; + + @ExpectedSignature(descriptor = "intArrayInList", signature = "Ljava/util/List<[I>;") + List intArrayInList; + + @ExpectedSignature(descriptor = "longArrayInList", signature = "Ljava/util/List<[J>;") + List longArrayInList; + + @ExpectedSignature(descriptor = "charArrayInList", signature = "Ljava/util/List<[C>;") + List charArrayInList; + + @ExpectedSignature(descriptor = "booleanArrayInList", signature = "Ljava/util/List<[Z>;") + List booleanArrayInList; + + @ExpectedSignature(descriptor = "floatArrayInList", signature = "Ljava/util/List<[F>;") + List floatArrayInList; + + @ExpectedSignature(descriptor = "doubleArrayInList", signature = "Ljava/util/List<[D>;") + List doubleArrayInList; + + @ExpectedSignature(descriptor = "integerInList", signature = "Ljava/util/List;") + List integerInList; + + @ExpectedSignature(descriptor = "typeInMultiArray", signature = "[[TT;") + T[][] typeInMultiArray; + + @ExpectedSignature(descriptor = "arrayOfClasses", signature = "[Ljava/util/List;") + List[] arrayOfClasses; + + @ExpectedSignature(descriptor = "extendsWildCard", signature = "Ljava/util/List<+TT;>;") + List extendsWildCard; + + @ExpectedSignature(descriptor = "superWildCard", signature = "Ljava/util/Comparator<-TT;>;") + Comparator superWildCard; + + @ExpectedSignature(descriptor = "extendsSuperWildCard", + signature = "Ljava/util/List<+Ljava/util/Comparator<-TT;>;>;") + List> extendsSuperWildCard; + + @ExpectedSignature(descriptor = "wildCard", signature = "Ljava/util/Comparator<*>;") + Comparator wildCard; + + @ExpectedSignature(descriptor = "boundsBooleanArray", signature = "Ljava/util/Map<+[Z-[Z>;") + Map boundsBooleanArray; + + @ExpectedSignature(descriptor = "boundsByteArray", signature = "Ljava/util/Map<+[B-[B>;") + Map boundsByteArray; + + @ExpectedSignature(descriptor = "boundsShortArray", signature = "Ljava/util/Map<+[S-[S>;") + Map boundsShortArray; + + @ExpectedSignature(descriptor = "boundsIntArray", signature = "Ljava/util/Map<+[I-[I>;") + Map boundsIntArray; + + @ExpectedSignature(descriptor = "boundsLongArray", signature = "Ljava/util/Map<+[J-[J>;") + Map boundsLongArray; + + @ExpectedSignature(descriptor = "boundsCharArray", signature = "Ljava/util/Map<+[C-[C>;") + Map boundsCharArray; + + @ExpectedSignature(descriptor = "boundsFloatArray", signature = "Ljava/util/Map<+[F-[F>;") + Map boundsFloatArray; + + @ExpectedSignature(descriptor = "boundsDoubleArray", signature = "Ljava/util/Map<+[D-[D>;") + Map boundsDoubleArray; + + @ExpectedSignature(descriptor = "boundsObjectArray", + signature = "Ljava/util/Map<+[Ljava/lang/Object;-[Ljava/lang/Object;>;") + Map boundsObjectArray; + + boolean booleanNoSignatureAttribute; + byte byteNoSignatureAttribute; + char charNoSignatureAttribute; + short shortNoSignatureAttribute; + int intNoSignatureAttribute; + long longNoSignatureAttribute; + float floatNoSignatureAttribute; + double doubleNoSignatureAttribute; + + List listNoSignatureAttribute; + + @ExpectedSignature(descriptor = "staticByteArrayInList", signature = "Ljava/util/List<[B>;") + static List staticByteArrayInList; + + @ExpectedSignature(descriptor = "staticShortArrayInList", signature = "Ljava/util/List<[S>;") + static List staticShortArrayInList; + + @ExpectedSignature(descriptor = "staticIntArrayInList", signature = "Ljava/util/List<[I>;") + static List staticIntArrayInList; + + @ExpectedSignature(descriptor = "staticLongArrayInList", signature = "Ljava/util/List<[J>;") + static List staticLongArrayInList; + + @ExpectedSignature(descriptor = "staticCharArrayInList", signature = "Ljava/util/List<[C>;") + static List staticCharArrayInList; + + @ExpectedSignature(descriptor = "staticBooleanArrayInList", signature = "Ljava/util/List<[Z>;") + static List staticBooleanArrayInList; + + @ExpectedSignature(descriptor = "staticFloatArrayInList", signature = "Ljava/util/List<[F>;") + static List staticFloatArrayInList; + + @ExpectedSignature(descriptor = "staticDoubleArrayInList", signature = "Ljava/util/List<[D>;") + static List staticDoubleArrayInList; + + @ExpectedSignature(descriptor = "staticIntegerInList", signature = "Ljava/util/List;") + static List staticIntegerInList; + + @ExpectedSignature(descriptor = "staticWildCard", signature = "Ljava/util/Comparator<*>;") + static Comparator staticWildCard; + + @ExpectedSignature(descriptor = "staticBoundsBooleanArray", signature = "Ljava/util/Map<+[Z-[Z>;") + static Map staticBoundsBooleanArray; + + @ExpectedSignature(descriptor = "staticBoundsByteArray", signature = "Ljava/util/Map<+[B-[B>;") + static Map staticBoundsByteArray; + + @ExpectedSignature(descriptor = "staticBoundsShortArray", signature = "Ljava/util/Map<+[S-[S>;") + static Map staticBoundsShortArray; + + @ExpectedSignature(descriptor = "staticBoundsIntArray", signature = "Ljava/util/Map<+[I-[I>;") + static Map staticBoundsIntArray; + + @ExpectedSignature(descriptor = "staticBoundsLongArray", signature = "Ljava/util/Map<+[J-[J>;") + static Map staticBoundsLongArray; + + @ExpectedSignature(descriptor = "staticBoundsCharArray", signature = "Ljava/util/Map<+[C-[C>;") + static Map staticBoundsCharArray; + + @ExpectedSignature(descriptor = "staticBoundsFloatArray", signature = "Ljava/util/Map<+[F-[F>;") + static Map staticBoundsFloatArray; + + @ExpectedSignature(descriptor = "staticBoundsDoubleArray", signature = "Ljava/util/Map<+[D-[D>;") + static Map staticBoundsDoubleArray; + + @ExpectedSignature(descriptor = "staticBoundsObjectArray", + signature = "Ljava/util/Map<+[Ljava/lang/Object;-[Ljava/lang/Object;>;") + static Map staticBoundsObjectArray; + + static boolean staticBooleanNoSignatureAttribute; + static byte staticByteNoSignatureAttribute; + static char staticCharNoSignatureAttribute; + static short staticShortNoSignatureAttribute; + static int staticIntNoSignatureAttribute; + static long staticLongNoSignatureAttribute; + static float staticFloatNoSignatureAttribute; + static double staticDoubleNoSignatureAttribute; + + static List staticListNoSignatureAttribute; +} diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/InnerClassTest.java b/langtools/test/tools/javac/classfiles/attributes/Signature/InnerClassTest.java new file mode 100644 index 00000000000..572c68810da --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/InnerClassTest.java @@ -0,0 +1,362 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for inner classes. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build InnerClassTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver InnerClassTest + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; + +@ExpectedSignature(descriptor = "InnerClassTest", + signature = ";:Ljava/lang/Runnable;>Ljava/lang/Object;") +@ExpectedSignature(descriptor = "InnerClassTest$1", + signature = "LInnerClassTest$1Local1;", isAnonymous = true) +@ExpectedSignature(descriptor = "InnerClassTest$2", + signature = "LInnerClassTest$1Local2;" + + "Ljava/util/Map;Ljava/util/ArrayList;>;>;", isAnonymous = true) +public class InnerClassTest & Runnable> { + + { + class Local1 { + // no Signature attribute + Local1() { + } + + @ExpectedSignature(descriptor = "genericType", signature = "TT;") + T genericType; + + @ExpectedSignature(descriptor = "genericTypeArray", signature = "[TT;") + T[] genericTypeArray; + } + + @ExpectedSignature(descriptor = "InnerClassTest$1Local2", + signature = ";>Ljava/lang/Object;") + class Local2> { + // no Signature attribute + Local2() { + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.lang.Object, java.util.Map)", + signature = "(TT;TU;)V") + Local2(T a, U b) { + } + + @ExpectedSignature(descriptor = "genericMethod(java.lang.Object[])", + signature = "([TT;)[TU;") + U[] genericMethod(T...a) { + return null; + } + } + + @ExpectedSignature(descriptor = "InnerClassTest$1Local3", + signature = "LInnerClassTest$1Local2;" + + "Ljava/util/Map;Ljava/util/ArrayList;>;>;") + class Local3 extends Local2, Map, ArrayList>> { + } + + new Local1() { + @ExpectedSignature(descriptor = "genericType", signature = "TT;") + T genericType; + + @ExpectedSignature(descriptor = "genericTypeArray", signature = "[TT;") + T[] genericTypeArray; + }; + + new Local2, Map, ArrayList>>() { + }; + } + + @ExpectedSignature(descriptor = "InnerClassTest$InnerClass1", + signature = ";>Ljava/lang/Object;") + class InnerClass1> { + @ExpectedSignature(descriptor = "genericTypeArray", signature = "[TT;") + T[] genericTypeArray; + + @ExpectedSignature(descriptor = "genericListExtendsBound", signature = "Ljava/util/List<+TT;>;") + List genericListExtendsBound; + + @ExpectedSignature(descriptor = "genericListSuperBound", signature = "Ljava/util/List<-TU;>;") + List genericListSuperBound; + + @ExpectedSignature(descriptor = "genericListWildCard", signature = "Ljava/util/List<*>;") + List genericListWildCard; + + @ExpectedSignature(descriptor = "genericListExactType", signature = "Ljava/util/List;") + List genericListExactType; + + @ExpectedSignature(descriptor = "listWithGenericType", signature = "Ljava/util/List;") + List listWithGenericType; + + List listNoSignatureAttribute; + + // no Signature attribute + InnerClass1(List a) { + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.util.ArrayList)", + signature = "(TT;)V") + InnerClass1(T a) { + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.util.ArrayList, java.util.ArrayList)", + signature = "(TT;TE;)V") + InnerClass1(T a, E b) { + } + + @ExpectedSignature(descriptor = "genericMethod(java.util.ArrayList)", + signature = "(TT;)TE;") + E genericMethod(T a) { + return null; + } + } + + @ExpectedSignature(descriptor = "InnerClassTest$InnerInterface", + signature = "Ljava/lang/Object;") + interface InnerInterface { + @ExpectedSignature(descriptor = "genericMethod(java.lang.Object)", signature = "(TT;)TT;") + T genericMethod(T a); + + @ExpectedSignature(descriptor = "genericListExtendsBound", signature = "Ljava/util/List<+Ljava/lang/Number;>;") + List genericListExtendsBound = null; + + @ExpectedSignature(descriptor = "genericListSuperBound", signature = "Ljava/util/List<-Ljava/lang/Number;>;") + List genericListSuperBound = null; + + @ExpectedSignature(descriptor = "genericListWildCard", signature = "Ljava/util/List<*>;") + List genericListWildCard = null; + + @ExpectedSignature(descriptor = "genericListExactType", signature = "Ljava/util/List;") + List genericListExactType = null; + + List listNoSignatureAttribute = null; + + @ExpectedSignature(descriptor = "genericBoundsMethod1(java.util.List)", + signature = "(Ljava/util/List<-TT;>;)Ljava/util/List<+TT;>;") + List genericBoundsMethod1(List a); + + @ExpectedSignature(descriptor = "genericBoundsMethod2(java.util.List)", + signature = "(Ljava/util/List<+TT;>;)Ljava/util/List<-TT;>;") + List genericBoundsMethod2(List a); + + @ExpectedSignature(descriptor = "genericWildCardMethod(java.util.Map)", + signature = "(Ljava/util/Map<**>;)Ljava/util/Map<**>;") + Map genericWildCardMethod(Map a); + + @ExpectedSignature(descriptor = "defaultGenericMethod(java.util.List, java.util.List, java.util.Map)", + signature = "(Ljava/util/List<+TT;>;Ljava/util/List<-TT;>;Ljava/util/Map<**>;)Ljava/util/List<*>;") + default List defaultGenericMethod(List list1, List list2, Map map) { return null; } + + + default List defaultNoSignatureAttributeMethod(List list1, List list2, Map list3) { return null; } + + @ExpectedSignature(descriptor = "staticGenericMethod(java.util.List, java.util.List, java.util.Map)", + signature = "(Ljava/util/List<+TT;>;Ljava/util/List<-TT;>;Ljava/util/Map<**>;)Ljava/util/List<*>;") + static List staticGenericMethod(List list1, List list2, Map map) { return null; } + + + static List staticNoSignatureAttributeMethod(List list1, List list2, Map list3) { return null; } + } + + @ExpectedSignature(descriptor = "InnerClassTest$InnerClass2", + signature = "LInnerClassTest.InnerClass1;>;LInnerClassTest$InnerInterface;") + class InnerClass2 extends InnerClass1> implements InnerInterface { + + // no Signature attribute + InnerClass2() { + super(null); + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.util.ArrayList)", + signature = "(TT;)V") + InnerClass2(T a) { + super(a); + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.util.ArrayList, java.util.ArrayList)", + signature = "(TT;TT;)V") + InnerClass2(T a, T b) { + super(a, b); + } + + @ExpectedSignature(descriptor = "genericMethod(java.util.ArrayList)", signature = "(TT;)TT;") + @Override + public T genericMethod(T a) { + return null; + } + + @ExpectedSignature(descriptor = "genericBoundsMethod1(java.util.List)", + signature = "(Ljava/util/List<-TT;>;)Ljava/util/List<+TT;>;") + @Override + public List genericBoundsMethod1(List a) { + return null; + } + + @ExpectedSignature(descriptor = "genericBoundsMethod2(java.util.List)", + signature = "(Ljava/util/List<+TT;>;)Ljava/util/List<-TT;>;") + @Override + public List genericBoundsMethod2(List a) { + return null; + } + + @ExpectedSignature(descriptor = "genericWildCardMethod(java.util.Map)", + signature = "(Ljava/util/Map<**>;)Ljava/util/Map<**>;") + @Override + public Map genericWildCardMethod(Map a) { + return null; + } + } + + @ExpectedSignature(descriptor = "InnerClassTest$StaticInnerClass", + signature = ";>" + + "Ljava/lang/Object;LInnerClassTest$InnerInterface;") + static class StaticInnerClass> implements InnerInterface { + // no Signature attribute + StaticInnerClass(List a) { + } + + @ExpectedSignature(descriptor = "(java.lang.Runnable)", + signature = "(TE;)V") + StaticInnerClass(E a) { + } + + @ExpectedSignature(descriptor = "(java.lang.String)", + signature = "(TT;)V") + StaticInnerClass(T a) { + } + + @ExpectedSignature(descriptor = "(java.lang.String, java.util.Set)", + signature = "(TT;TE;)V") + StaticInnerClass(T a, E b) { + } + + @ExpectedSignature(descriptor = "genericListExtendsBound", signature = "Ljava/util/List<+Ljava/lang/Number;>;") + static List genericListExtendsBound; + + @ExpectedSignature(descriptor = "genericListSuperBound", signature = "Ljava/util/List<-Ljava/lang/Number;>;") + static List genericListSuperBound; + + @ExpectedSignature(descriptor = "genericListWildCard", signature = "Ljava/util/List<*>;") + static List genericListWildCard; + + @ExpectedSignature(descriptor = "genericListExactType", signature = "Ljava/util/List;") + static List genericListExactType; + + static List listNoSignatureAttribute; + + @ExpectedSignature(descriptor = "genericMethod(java.util.Set)", + signature = "(TE;)TE;") + @Override + public E genericMethod(E a) { + return null; + } + + @ExpectedSignature(descriptor = "genericBoundsMethod1(java.util.List)", + signature = "(Ljava/util/List<-TE;>;)Ljava/util/List<+TE;>;") + @Override + public List genericBoundsMethod1(List a) { + return null; + } + + @ExpectedSignature(descriptor = "genericBoundsMethod2(java.util.List)", + signature = "(Ljava/util/List<+TE;>;)Ljava/util/List<-TE;>;") + @Override + public List genericBoundsMethod2(List a) { + return null; + } + + @ExpectedSignature(descriptor = "genericWildCardMethod(java.util.Map)", + signature = "(Ljava/util/Map<**>;)Ljava/util/Map<**>;") + @Override + public Map genericWildCardMethod(Map a) { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericMethod(java.lang.Object)", + signature = "(TE;)TE;") + public static E staticGenericMethod(E a) { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericBoundsMethod1(java.util.List)", + signature = "(Ljava/util/List<-TE;>;)Ljava/util/List<+TE;>;") + public static List staticGenericBoundsMethod1(List a) { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericBoundsMethod2(java.util.List)", + signature = "(Ljava/util/List<+TE;>;)Ljava/util/List<-TE;>;") + public static List staticGenericBoundsMethod2(List a) { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericWildCardMethod(java.util.Map)", + signature = "(Ljava/util/Map<**>;)Ljava/util/Map<**>;") + public static Map staticGenericWildCardMethod(Map a) { + return null; + } + } + + @ExpectedSignature(descriptor = "InnerClassTest$InnerClass3", + signature = "Ljava/lang/Object;LInnerClassTest$ExceptionHolder" + + ";Ljava/util/concurrent/Callable;>;") + public static class InnerClass3 implements ExceptionHolder, Callable> { + @ExpectedSignature(descriptor = "call()", signature = "()Ljava/util/Map<**>;") + @Override + public Map call() throws Exception { + return null; + } + + @Override + public void Throw() throws RuntimeException { + } + + @Override + public RuntimeException Return() { + return null; + } + } + + /** + * Class is for checking that the Signature attribute is not generated + * for overridden methods despite of the appropriate methods in the parent class + * have the Signature attribute. + */ + @ExpectedSignature(descriptor = "InnerClassTest$ExceptionHolder", + signature = "Ljava/lang/Object;") + interface ExceptionHolder { + @ExpectedSignature(descriptor = "Throw()", signature = "()V^TE;") + void Throw() throws E; + @ExpectedSignature(descriptor = "Return()", signature = "()TE;") + E Return(); + } +} diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/MethodParameterTest.java b/langtools/test/tools/javac/classfiles/attributes/Signature/MethodParameterTest.java new file mode 100644 index 00000000000..ec93b57f5e9 --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/MethodParameterTest.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for method parameters. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build MethodParameterTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver MethodParameterTest + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@ExpectedSignature(descriptor = "MethodParameterTest", signature = "Ljava/lang/Object;") +public class MethodParameterTest { + + @ExpectedSignature(descriptor = "(java.lang.Object, java.util.Set, java.util.ArrayList)", + signature = ";:Ljava/lang/Runnable;>" + + "(TT;Ljava/util/Set<-TE;>;Ljava/util/ArrayList<+Ljava/util/Set;>;)V") + & Runnable> + MethodParameterTest(T a, Set b, ArrayList> c) { + } + + @ExpectedSignature(descriptor = "method(java.lang.Object, java.util.List, java.util.ArrayList)", + signature = ";:Ljava/lang/Runnable;>" + + "(TT;TU;Ljava/util/ArrayList<+Ljava/util/Set;>;)V") + & Runnable> + void method(T a, U b, ArrayList> c) { + } + + @ExpectedSignature(descriptor = "staticMethod(java.util.Set, java.util.List[], java.util.Map)", + signature = ";E::Ljava/util/Set<-TT;>;>(TE;[TT;Ljava/util/Map<*+TE;>;)TE;") + static , E extends Set> E staticMethod(E a, T[] b, Map c) { + return null; + } + + @ExpectedSignature(descriptor = "(java.lang.Object, boolean[])", signature = "(TT;[Z)V") + MethodParameterTest(T a, boolean...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, char[])", signature = "(TT;[C)V") + MethodParameterTest(T a, char...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, byte[])", signature = "(TT;[B)V") + MethodParameterTest(T a, byte...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, short[])", signature = "(TT;[S)V") + MethodParameterTest(T a, short...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, int[])", signature = "(TT;[I)V") + MethodParameterTest(T a, int...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, long[])", signature = "(TT;[J)V") + MethodParameterTest(T a, long...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, float[])", signature = "(TT;[F)V") + MethodParameterTest(T a, float...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, double[])", signature = "(TT;[D)V") + MethodParameterTest(T a, double...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, java.lang.Object[])", + signature = "(TT;[Ljava/lang/Object;)V") + MethodParameterTest(T a, Object...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object[])", signature = "([TT;)V") + MethodParameterTest(T...a) { + } + + // no Signature attribute + MethodParameterTest(int...a) { + } + + @ExpectedSignature(descriptor = "genericBooleanMethod(java.lang.Object, boolean[])", signature = "(TT;[Z)V") + void genericBooleanMethod(T a, boolean...b) { + } + + @ExpectedSignature(descriptor = "genericCharMethod(java.lang.Object, char[])", signature = "(TT;[C)V") + void genericCharMethod(T a, char...b) { + } + + @ExpectedSignature(descriptor = "genericByteMethod(java.lang.Object, byte[])", signature = "(TT;[B)V") + void genericByteMethod(T a, byte...b) { + } + + @ExpectedSignature(descriptor = "genericShortMethod(java.lang.Object, short[])", signature = "(TT;[S)V") + void genericShortMethod(T a, short...b) { + } + + @ExpectedSignature(descriptor = "genericIntMethod(java.lang.Object, int[])", signature = "(TT;[I)V") + void genericIntMethod(T a, int...b) { + } + + @ExpectedSignature(descriptor = "genericLongMethod(java.lang.Object, long[])", signature = "(TT;[J)V") + void genericLongMethod(T a, long...b) { + } + + @ExpectedSignature(descriptor = "genericFloatMethod(java.lang.Object, float[])", signature = "(TT;[F)V") + void genericFloatMethod(T a, float...b) { + } + + @ExpectedSignature(descriptor = "genericDoubleMethod(java.lang.Object, double[])", signature = "(TT;[D)V") + void genericDoubleMethod(T a, double...b) { + } + + @ExpectedSignature(descriptor = "genericObjectMethod(java.lang.Object, java.lang.Object[])", + signature = "(TT;[Ljava/lang/Object;)V") + void genericObjectMethod(T a, Object...b) { + } + + @ExpectedSignature(descriptor = "genericMethod(java.lang.Object[])", signature = "([TT;)V") + void genericMethod(T...a) { + } + + void noSignature(int...a) { + } + + @ExpectedSignature(descriptor = "staticGenericBooleanMethod(java.lang.Object, boolean[])", + signature = "(TT;[Z)V") + static void staticGenericBooleanMethod(T a, boolean...b) { + } + + @ExpectedSignature(descriptor = "staticGenericCharMethod(java.lang.Object, char[])", + signature = "(TT;[C)V") + static void staticGenericCharMethod(T a, char...b) { + } + + @ExpectedSignature(descriptor = "staticGenericByteMethod(java.lang.Object, byte[])", + signature = "(TT;[B)V") + static void staticGenericByteMethod(T a, byte...b) { + } + + @ExpectedSignature(descriptor = "staticGenericShortMethod(java.lang.Object, short[])", + signature = "(TT;[S)V") + static void staticGenericShortMethod(T a, short...b) { + } + + @ExpectedSignature(descriptor = "staticGenericIntMethod(java.lang.Object, int[])", + signature = "(TT;[I)V") + static void staticGenericIntMethod(T a, int...b) { + } + + @ExpectedSignature(descriptor = "staticGenericLongMethod(java.lang.Object, long[])", + signature = "(TT;[J)V") + static void staticGenericLongMethod(T a, long...b) { + } + + @ExpectedSignature(descriptor = "staticGenericFloatMethod(java.lang.Object, float[])", + signature = "(TT;[F)V") + static void staticGenericFloatMethod(T a, float...b) { + } + + @ExpectedSignature(descriptor = "staticGenericDoubleMethod(java.lang.Object, double[])", + signature = "(TT;[D)V") + static void staticGenericDoubleMethod(T a, double...b) { + } + + @ExpectedSignature(descriptor = "staticGenericObjectMethod(java.lang.Object, java.lang.Object[])", + signature = "(TT;[Ljava/lang/Object;)V") + static void staticGenericObjectMethod(T a, Object...b) { + } + + @ExpectedSignature(descriptor = "staticGenericMethod(java.lang.Object[])", + signature = "([TT;)V") + static void staticGenericMethod(T...a) { + } + + static void staticNoSignatureAttribute(int...a) { + } +} diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/MethodTypeBoundTest.java b/langtools/test/tools/javac/classfiles/attributes/Signature/MethodTypeBoundTest.java new file mode 100644 index 00000000000..d188c2a496e --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/MethodTypeBoundTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for type bounds. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build MethodTypeBoundTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver MethodTypeBoundTest + */ + +import java.util.*; + +@ExpectedSignature(descriptor = "MethodTypeBoundTest", signature = "Ljava/lang/Object;") +public class MethodTypeBoundTest { + + @ExpectedSignature(descriptor = "method1(java.lang.String)", + signature = ";>(TE;)TE;") + > E method1(E a) { + return a; + } + + @ExpectedSignature(descriptor = "method2(java.lang.Runnable)", + signature = ";>(TE;)TE;") + > E method2(E a) { + return a; + } + + @ExpectedSignature(descriptor = "method3(java.util.ArrayList)", + signature = ";>(TE;)TE;") + > E method3(E a) { + return a; + } + + @ExpectedSignature(descriptor = "method4(java.util.LinkedList)", + signature = ";:Ljava/util/List;>(TE;)TE;") + & List> E method4(E a) { + return a; + } + + @ExpectedSignature(descriptor = "method5(java.util.Iterator)", + signature = ";:Ljava/util/List;" + + "U::Ljava/util/Iterator<-LMethodTypeBoundTest.InnerClass;>;>(TU;)TE;") + & List, U extends Iterator>> E method5(U a) { + return null; + } + + @ExpectedSignature(descriptor = "method6()", + signature = ";U:TE;>()V") + , U extends E> void method6() { + } + + @ExpectedSignature(descriptor = "MethodTypeBoundTest$InnerClass", + signature = "Ljava/lang/Object;") + class InnerClass { + } +} diff --git a/langtools/test/tools/javac/classfiles/attributes/Signature/ReturnTypeTest.java b/langtools/test/tools/javac/classfiles/attributes/Signature/ReturnTypeTest.java new file mode 100644 index 00000000000..dea47aa8527 --- /dev/null +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ReturnTypeTest.java @@ -0,0 +1,549 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for array return type of method. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build ReturnTypeTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver ReturnTypeTest + */ + +import java.awt.Frame; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + +@ExpectedSignature(descriptor = "ReturnTypeTest", + signature = ";>Ljava/lang/Object;") +public class ReturnTypeTest> { + + @ExpectedSignature(descriptor = "byteArrayReturnType(java.awt.Frame)", + signature = "(TT;)[B") + byte[] byteArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "shortArrayReturnType(java.awt.Frame)", + signature = "(TT;)[S") + short[] shortArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "charArrayReturnType(java.awt.Frame)", + signature = "(TT;)[C") + char[] charArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "intArrayReturnType(java.awt.Frame)", + signature = "(TT;)[I") + int[] intArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "longArrayReturnType(java.awt.Frame)", + signature = "(TT;)[J") + long[] longArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "booleanArrayReturnType(java.awt.Frame)", + signature = "(TT;)[Z") + boolean[] booleanArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "floatArrayReturnType(java.awt.Frame)", + signature = "(TT;)[F") + float[] floatArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "doubleArrayReturnType(java.awt.Frame)", + signature = "(TT;)[D") + double[] doubleArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "objectArrayReturnType(java.awt.Frame)", + signature = "(TT;)[Ljava/lang/Object;") + Object[] objectArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticByteArrayReturnType(java.lang.Object)", + signature = "(TT;)[B") + static byte[] staticByteArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticShortArrayReturnType(java.lang.Object)", + signature = "(TT;)[S") + static short[] staticShortArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticCharArrayReturnType(java.lang.Object)", + signature = "(TT;)[C") + static char[] staticCharArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticIntArrayReturnType(java.lang.Object)", + signature = "(TT;)[I") + static int[] staticIntArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticLongArrayReturnType(java.lang.Object)", + signature = "(TT;)[J") + static long[] staticLongArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticBooleanArrayReturnType(java.lang.Object)", + signature = "(TT;)[Z") + static boolean[] staticBooleanArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticFloatArrayReturnType(java.lang.Object)", + signature = "(TT;)[F") + static float[] staticFloatArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticDoubleArrayReturnType(java.lang.Object)", + signature = "(TT;)[D") + static double[] staticDoubleArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticObjectArrayReturnType(java.lang.Object)", + signature = "(TT;)[Ljava/lang/Object;") + static Object[] staticObjectArrayReturnType(T a) { + return null; + } + + byte[] byteArrayReturnTypeNoSignatureAttribute() { + return null; + } + + short[] shortArrayReturnTypeNoSignatureAttribute() { + return null; + } + + char[] charArrayReturnTypeNoSignatureAttribute() { + return null; + } + + int[] intArrayReturnTypeNoSignatureAttribute() { + return null; + } + + long[] longArrayReturnTypeNoSignatureAttribute() { + return null; + } + + boolean[] booleanArrayReturnTypeNoSignatureAttribute() { + return null; + } + + float[] floatArrayReturnTypeNoSignatureAttribute() { + return null; + } + + double[] doubleArrayReturnTypeNoSignatureAttribute() { + return null; + } + + Object[] objectArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static byte[] staticByteArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static short[] staticShortArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static char[] staticCharArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static int[] staticIntArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static long[] staticLongArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static boolean[] staticBooleanArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static float[] staticFloatArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static double[] staticDoubleArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static Object[] staticObjectArrayReturnTypeNoSignatureAttribute() { + return null; + } + + @ExpectedSignature(descriptor = "typeReturnType()", + signature = "()TT;") + T typeReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "typeArrayReturnType()", + signature = "()[TT;") + T[] typeArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "extendsReturnType()", + signature = "()TE;") + E extendsReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "extendsArrayReturnType()", + signature = "()[TE;") + E[] extendsArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "genericListReturnType()", + signature = "()Ljava/util/List;") + List genericListReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "genericListArrayReturnType()", + signature = "()[Ljava/util/List;") + List[] genericListArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "extendsBoundReturnType()", + signature = "()Ljava/util/List<+TT;>;") + List extendsBoundReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "extendsBoundArrayReturnType()", + signature = "()[Ljava/util/List<+TT;>;") + List[] extendsBoundArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "superBoundReturnType()", + signature = "()Ljava/util/List<-TT;>;") + List superBoundReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "superBoundArrayReturnType()", + signature = "()[Ljava/util/List<-TT;>;") + List[] superBoundArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "wildcardReturnType()", + signature = "()Ljava/util/Map<**>;") + Map wildcardReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "wildcardArrayReturnType()", + signature = "()[Ljava/util/Map<**>;") + Map[] wildcardArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticTypeReturnType()", + signature = "()TT;") + static T staticTypeReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticTypeArrayReturnType()", + signature = "()[TT;") + static T[] staticTypeArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticExtendsReturnType()", + signature = "()TE;") + static E staticExtendsReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticExtendsArrayReturnType()", + signature = "()[TE;") + static E[] staticExtendsArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericListReturnType()", + signature = "()Ljava/util/List;") + static List staticGenericListReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericListArrayReturnType()", + signature = "()[Ljava/util/List;") + static List[] staticGenericListArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticExtendsBoundReturnType()", + signature = "()Ljava/util/List<+TT;>;") + static List staticExtendsBoundReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticExtendsBoundArrayReturnType()", + signature = "()[Ljava/util/List<+TT;>;") + static List[] staticExtendsBoundArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticSuperBoundReturnType()", + signature = "()Ljava/util/List<-TT;>;") + static List staticSuperBoundReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticSuperBoundArrayReturnType()", + signature = "()[Ljava/util/List<-TT;>;") + static List[] staticSuperBoundArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticWildcardReturnType()", + signature = "()Ljava/util/Map<**>;") + static Map staticWildcardReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticWildcardArrayReturnType()", + signature = "()[Ljava/util/Map<**>;") + static Map[] staticWildcardArrayReturnType() { + return null; + } + + List noSignature() { + return null; + } + + static List staticNoSignatureAttribute() { + return null; + } + + @ExpectedSignature(descriptor = "boundsBooleanArray()", + signature = "()Ljava/util/Map<+[Z-[Z>;") + Map boundsBooleanArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsByteArray()", + signature = "()Ljava/util/Map<+[B-[B>;") + Map boundsByteArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsShortArray()", + signature = "()Ljava/util/Map<+[S-[S>;") + Map boundsShortArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsIntArray()", + signature = "()Ljava/util/Map<+[I-[I>;") + Map boundsIntArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsLongArray()", + signature = "()Ljava/util/Map<+[J-[J>;") + Map boundsLongArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsCharArray()", + signature = "()Ljava/util/Map<+[C-[C>;") + Map boundsCharArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsFloatArray()", + signature = "()Ljava/util/Map<+[F-[F>;") + Map boundsFloatArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsDoubleArray()", + signature = "()Ljava/util/Map<+[D-[D>;") + Map boundsDoubleArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsObjectArray()", + signature = "()Ljava/util/Map<+[Ljava/lang/Object;-[Ljava/lang/Object;>;") + Map boundsObjectArray() { + return null; + } + + @ExpectedSignature(descriptor = "voidMethod(java.awt.Frame)", signature = "(TT;)V") + void voidMethod(T a) { + } + + @ExpectedSignature(descriptor = "byteMethod(java.awt.Frame)", signature = "(TT;)B") + byte byteMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "shortMethod(java.awt.Frame)", signature = "(TT;)S") + short shortMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "charMethod(java.awt.Frame)", signature = "(TT;)C") + char charMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "intMethod(java.awt.Frame)", signature = "(TT;)I") + int intMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "longMethod(java.awt.Frame)", signature = "(TT;)J") + long longMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "booleanMethod(java.awt.Frame)", signature = "(TT;)Z") + boolean booleanMethod(T a) { + return false; + } + + @ExpectedSignature(descriptor = "floatMethod(java.awt.Frame)", signature = "(TT;)F") + float floatMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "doubleMethod(java.awt.Frame)", signature = "(TT;)D") + double doubleMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "objectMethod(java.awt.Frame)", signature = "(TT;)Ljava/lang/Object;") + Object objectMethod(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticVoidMethod(java.lang.Object)", signature = "(TT;)V") + static void staticVoidMethod(T a) { + } + + @ExpectedSignature(descriptor = "staticByteMethod(java.lang.Object)", signature = "(TT;)B") + static byte staticByteMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticShortMethod(java.lang.Object)", signature = "(TT;)S") + static short staticShortMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticCharMethod(java.lang.Object)", signature = "(TT;)C") + static char staticCharMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticIntMethod(java.lang.Object)", signature = "(TT;)I") + static int staticIntMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticLongMethod(java.lang.Object)", signature = "(TT;)J") + static long staticLongMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticBooleanMethod(java.lang.Object)", signature = "(TT;)Z") + static boolean staticBooleanMethod(T a) { + return false; + } + + @ExpectedSignature(descriptor = "staticFloatMethod(java.lang.Object)", signature = "(TT;)F") + static float staticFloatMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticDoubleMethod(java.lang.Object)", signature = "(TT;)D") + static double staticDoubleMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticObjectMethod(java.lang.Object)", + signature = "(TT;)Ljava/lang/Object;") + static Object staticObjectMethod(T a) { + return null; + } + + void voidReturnTypeNoSignatureAttribute() { + } + + byte byteReturnTypeNoSignatureAttribute() { + return 0; + } + + Object objectReturnNoSignatureAttribute() { + return null; + } + + static void staticVoidReturnTypeNoSignatureAttribute() { + } + + static byte staticByteReturnTypeNoSignatureAttribute() { + return 0; + } + + static Object staticObjectReturnTypeNoSignatureAttribute() { + return null; + } +} diff --git a/langtools/test/tools/javac/classfiles/attributes/lib/TestResult.java b/langtools/test/tools/javac/classfiles/attributes/lib/TestResult.java index 1e760eddb5e..300c6bed3a7 100644 --- a/langtools/test/tools/javac/classfiles/attributes/lib/TestResult.java +++ b/langtools/test/tools/javac/classfiles/attributes/lib/TestResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -56,8 +56,9 @@ public class TestResult extends TestBase { public boolean checkEquals(Object actual, Object expected, String message) { echo("Testing : " + message); if (!Objects.equals(actual, expected)) { - getLastTestCase().addAssert(new AssertionFailedException( - String.format("%s%nGot: %s, Expected: %s", message, actual, expected))); + getLastTestCase().addAssert(String.format("%s\n" + + "Expected: %s,\n" + + " Got: %s", message, expected, actual)); return false; } return true; @@ -70,8 +71,7 @@ public class TestResult extends TestBase { public boolean checkNotNull(Object actual, String message) { echo("Testing : " + message); if (Objects.isNull(actual)) { - getLastTestCase().addAssert(new AssertionFailedException( - message + " : Expected not null value")); + getLastTestCase().addAssert(message + " : Expected not null value"); return false; } return true; @@ -88,7 +88,11 @@ public class TestResult extends TestBase { public boolean checkContains(Set found, Set expected, String message) { Set copy = new HashSet<>(expected); copy.removeAll(found); - return checkTrue(found.containsAll(expected), message + " : " + copy); + if (!found.containsAll(expected)) { + return checkTrue(false, message + " FAIL : not found elements : " + copy); + } else { + return checkTrue(true, message + " PASS : all elements found"); + } } public void addFailure(Throwable th) { @@ -119,7 +123,7 @@ public class TestResult extends TestBase { private class Info { private final String info; - private final List asserts; + private final List asserts; private final List errors; private Info(String info) { @@ -141,19 +145,25 @@ public class TestResult extends TestBase { printf("[ERROR] : %s\n", getStackTrace(th)); } - public void addAssert(AssertionFailedException e) { + public void addAssert(String e) { asserts.add(e); - printf("[ASSERT] : %s\n", getStackTrace(e)); + printf("[ASSERT] : %s\n", e); } public String getMessage() { - return (asserts.size() > 0 ? getErrorMessage("[ASSERT]", asserts) + "\n" : "") - + getErrorMessage("[ERROR]", errors); + return (asserts.size() > 0 ? getAssertMessages(asserts) + "\n" : "") + + getErrorMessages(errors); } - public String getErrorMessage(String header, List list) { + public String getAssertMessages(List list) { return list.stream() - .map(throwable -> String.format("%s : %s", header, getStackTrace(throwable))) + .map(message -> String.format("[ASSERT] : %s", message)) + .collect(Collectors.joining("\n")); + } + + public String getErrorMessages(List list) { + return list.stream() + .map(throwable -> String.format("[ERROR] : %s", getStackTrace(throwable))) .collect(Collectors.joining("\n")); } From a5bc56dcecbc348606664e5b248ec19f6eeee072 Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Wed, 25 Mar 2015 12:37:36 +0400 Subject: [PATCH 121/362] 8075244: [macosx] The fix for JDK-8043869 should be reworked Reviewed-by: prr, serb, ant --- .../native/libsplashscreen/splashscreen_sys.m | 30 ++++++++--- .../MultiResolutionSplashTest.java | 50 +++++++++++++++++-- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/jdk/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m b/jdk/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m index bca822d3dfa..07bbd43e0a5 100644 --- a/jdk/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m +++ b/jdk/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m @@ -126,12 +126,30 @@ done: return buf; } +BOOL isSWTRunning() { + char envVar[80]; + // If this property is present we are running SWT + snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid()); + return getenv(envVar) != NULL; +} + char* SplashGetScaledImageName(const char* jar, const char* file, float *scaleFactor) { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; *scaleFactor = 1; + + if(isSWTRunning()){ + return nil; + } + + NSAutoreleasePool *pool = [NSAutoreleasePool new]; char* scaledFile = nil; - float screenScaleFactor = 1; + __block float screenScaleFactor = 1; + + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ + // initialize NSApplication and AWT stuff + [NSApplicationAWT sharedApplication]; + screenScaleFactor = [SplashNSScreen() backingScaleFactor]; + }]; if (screenScaleFactor > 1) { NSString *fileName = [NSString stringWithUTF8String: file]; @@ -176,12 +194,8 @@ SplashInitPlatform(Splash * splash) { splash->screenFormat.byteOrder = 1 ? BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST; splash->screenFormat.depthBytes = 4; - // If this property is present we are running SWT and should not start a runLoop - // Can't check if running SWT in webstart, so splash screen in webstart SWT - // applications is not supported - char envVar[80]; - snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid()); - if (getenv(envVar) == NULL) { + // If we are running SWT we should not start a runLoop + if (!isSWTRunning()) { [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() { [NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]]; }]; diff --git a/jdk/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java b/jdk/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java index 92de5f516ec..4173e9b91bb 100644 --- a/jdk/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java +++ b/jdk/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java @@ -23,21 +23,24 @@ import java.awt.Color; import java.awt.Dialog; +import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Panel; import java.awt.Rectangle; import java.awt.Robot; import java.awt.SplashScreen; +import java.awt.TextField; import java.awt.Window; +import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; import sun.java2d.SunGraphics2D; /** - * test - * @bug 8043869 + * @test + * @bug 8043869 8075244 * @author Alexander Scherbatiy * @summary [macosx] java -splash does not honor 2x hi dpi notation for retina * support @@ -45,6 +48,7 @@ import sun.java2d.SunGraphics2D; * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_SPLASH 0 * @run main/othervm -splash:splash2 MultiResolutionSplashTest TEST_SPLASH 1 * @run main/othervm -splash:splash3. MultiResolutionSplashTest TEST_SPLASH 2 + * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_FOCUS */ public class MultiResolutionSplashTest { @@ -69,6 +73,9 @@ public class MultiResolutionSplashTest { int index = Integer.parseInt(args[1]); testSplash(tests[index]); break; + case "TEST_FOCUS": + testFocus(); + break; default: throw new RuntimeException("Unknown test: " + test); } @@ -92,12 +99,49 @@ public class MultiResolutionSplashTest { float scaleFactor = getScaleFactor(); Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x; - if (!testColor.equals(splashScreenColor)) { + if (!compare(testColor, splashScreenColor)) { throw new RuntimeException( "Image with wrong resolution is used for splash screen!"); } } + static void testFocus() throws Exception { + + System.out.println("Focus Test!"); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + Frame frame = new Frame(); + frame.setSize(100, 100); + String test = "123"; + TextField textField = new TextField(test); + frame.add(textField); + frame.setVisible(true); + robot.waitForIdle(); + + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyPress(KeyEvent.VK_B); + robot.keyRelease(KeyEvent.VK_B); + robot.waitForIdle(); + + frame.dispose(); + + if(!textField.getText().equals("ab")){ + throw new RuntimeException("Focus is lost!"); + } + } + + static boolean compare(Color c1, Color c2){ + return compare(c1.getRed(), c2.getRed()) + && compare(c1.getGreen(), c2.getGreen()) + && compare(c1.getBlue(), c2.getBlue()); + } + + static boolean compare(int n, int m){ + return Math.abs(n - m) <= 50; + } + static float getScaleFactor() { final Dialog dialog = new Dialog((Window) null); From 78c0bdbda5a48726d64b9ffb9308288a80137873 Mon Sep 17 00:00:00 2001 From: Masayoshi Okutsu Date: Wed, 25 Mar 2015 17:59:59 +0900 Subject: [PATCH 122/362] 8075173: DateFormat in german locale returns wrong value for month march Reviewed-by: naoto, peytoia --- .../share/classes/sun/text/resources/de/FormatData_de.java | 4 ++-- jdk/test/sun/text/resources/LocaleData | 3 +++ jdk/test/sun/text/resources/LocaleDataTest.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jdk/src/jdk.localedata/share/classes/sun/text/resources/de/FormatData_de.java b/jdk/src/jdk.localedata/share/classes/sun/text/resources/de/FormatData_de.java index 435a79742d2..85c079cbb32 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/text/resources/de/FormatData_de.java +++ b/jdk/src/jdk.localedata/share/classes/sun/text/resources/de/FormatData_de.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2015, 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 @@ -142,7 +142,7 @@ public class FormatData_de extends ParallelListResourceBundle { new String[] { "Jan", // abb january "Feb", // abb february - "Mrz", // abb march + "M\u00e4r", // abb march "Apr", // abb april "Mai", // abb may "Jun", // abb june diff --git a/jdk/test/sun/text/resources/LocaleData b/jdk/test/sun/text/resources/LocaleData index 719cc3df066..9033fe6c125 100644 --- a/jdk/test/sun/text/resources/LocaleData +++ b/jdk/test/sun/text/resources/LocaleData @@ -8279,3 +8279,6 @@ FormatData/fi/DatePatterns/0=d. MMMM yyyy FormatData/fi/DatePatterns/1=d. MMMM yyyy FormatData/fi/DatePatterns/2=d.M.yyyy FormatData/fi/DatePatterns/3=d.M.yyyy + +# bug #8075173 +FormatData/de/standalone.MonthAbbreviations/2=M\u00e4r diff --git a/jdk/test/sun/text/resources/LocaleDataTest.java b/jdk/test/sun/text/resources/LocaleDataTest.java index 96d6d1d9a75..bd2b331fc78 100644 --- a/jdk/test/sun/text/resources/LocaleDataTest.java +++ b/jdk/test/sun/text/resources/LocaleDataTest.java @@ -36,7 +36,7 @@ * 6919624 6998391 7019267 7020960 7025837 7020583 7036905 7066203 7101495 * 7003124 7085757 7028073 7171028 7189611 8000983 7195759 8004489 8006509 * 7114053 7074882 7040556 8013836 8021121 6192407 6931564 8027695 8017142 - * 8037343 8055222 8042126 8074791 + * 8037343 8055222 8042126 8074791 8075173 * @summary Verify locale data * */ From de784d82f16a94419e7c526838483e8f277bb120 Mon Sep 17 00:00:00 2001 From: Athijegannathan Sundararajan Date: Wed, 25 Mar 2015 14:36:22 +0530 Subject: [PATCH 123/362] 8012190: Global scope should be initialized lazily Reviewed-by: lagergren, hannesw, attila --- .../jdk/nashorn/internal/objects/Global.java | 652 ++++++++++++++---- .../nashorn/internal/objects/NativeDate.java | 6 +- .../internal/objects/NativeRegExp.java | 12 +- 3 files changed, 521 insertions(+), 149 deletions(-) diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java index 305c86a40e9..76a787fa922 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java @@ -54,8 +54,10 @@ import jdk.nashorn.api.scripting.ClassFilter; import jdk.nashorn.api.scripting.ScriptObjectMirror; import jdk.nashorn.internal.lookup.Lookup; import jdk.nashorn.internal.objects.annotations.Attribute; +import jdk.nashorn.internal.objects.annotations.Getter; import jdk.nashorn.internal.objects.annotations.Property; import jdk.nashorn.internal.objects.annotations.ScriptClass; +import jdk.nashorn.internal.objects.annotations.Setter; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.ECMAErrors; import jdk.nashorn.internal.runtime.GlobalConstants; @@ -89,6 +91,9 @@ public final class Global extends ScriptObject implements Scope { private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); + // placeholder value for lazily initialized global objects + private static final Object LAZY_SENTINEL = new Object(); + /** * Optimistic builtin names that require switchpoint invalidation * upon assignment. Overly conservative, but works for now, to avoid @@ -214,20 +219,76 @@ public final class Global extends ScriptObject implements Scope { public volatile Object number; /** ECMA 15.1.4.7 Date constructor */ - @Property(name = "Date", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object date; + @Getter(name = "Date", attributes = Attribute.NOT_ENUMERABLE) + public static Object getDate(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.date == LAZY_SENTINEL) { + global.date = global.getBuiltinDate(); + } + return global.date; + } + + @Setter(name = "Date", attributes = Attribute.NOT_ENUMERABLE) + public static void setDate(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.date = value; + } + + private volatile Object date = LAZY_SENTINEL; /** ECMA 15.1.4.8 RegExp constructor */ - @Property(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object regexp; + @Getter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) + public static Object getRegExp(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.regexp == LAZY_SENTINEL) { + global.regexp = global.getBuiltinRegExp(); + } + return global.regexp; + } + + @Setter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) + public static void setRegExp(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.regexp = value; + } + + private volatile Object regexp = LAZY_SENTINEL; /** ECMA 15.12 - The JSON object */ - @Property(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object json; + @Getter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) + public static Object getJSON(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.json == LAZY_SENTINEL) { + global.json = global.getBuiltinJSON(); + } + return global.json; + } + + @Setter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) + public static void setJSON(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.json = value; + } + + private volatile Object json = LAZY_SENTINEL; /** Nashorn extension: global.JSAdapter */ - @Property(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object jsadapter; + @Getter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) + public static Object getJSAdapter(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.jsadapter == LAZY_SENTINEL) { + global.jsadapter = global.getBuiltinJSAdapter(); + } + return global.jsadapter; + } + + @Setter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) + public static void setJSAdapter(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.jsadapter = value; + } + + private volatile Object jsadapter = LAZY_SENTINEL; /** ECMA 15.8 - The Math object */ @Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE) @@ -238,12 +299,40 @@ public final class Global extends ScriptObject implements Scope { public volatile Object error; /** EvalError object */ - @Property(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object evalError; + @Getter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) + public static Object getEvalError(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.evalError == LAZY_SENTINEL) { + global.evalError = global.getBuiltinEvalError(); + } + return global.evalError; + } + + @Setter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) + public static void setEvalError(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.evalError = value; + } + + private volatile Object evalError = LAZY_SENTINEL; /** RangeError object */ - @Property(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object rangeError; + @Getter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) + public static Object getRangeError(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.rangeError == LAZY_SENTINEL) { + global.rangeError = global.getBuiltinRangeError(); + } + return global.rangeError; + } + + @Setter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) + public static void setRangeError(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.rangeError = value; + } + + private volatile Object rangeError = LAZY_SENTINEL; /** ReferenceError object */ @Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE) @@ -258,52 +347,220 @@ public final class Global extends ScriptObject implements Scope { public volatile Object typeError; /** URIError object */ - @Property(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object uriError; + @Getter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) + public static Object getURIError(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.uriError == LAZY_SENTINEL) { + global.uriError = global.getBuiltinURIError(); + } + return global.uriError; + } + + @Setter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) + public static void setURIError(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.uriError = value; + } + + private volatile Object uriError = LAZY_SENTINEL; /** ArrayBuffer object */ - @Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object arrayBuffer; + @Getter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) + public static Object getArrayBuffer(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.arrayBuffer == LAZY_SENTINEL) { + global.arrayBuffer = global.getBuiltinArrayBuffer(); + } + return global.arrayBuffer; + } + + @Setter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) + public static void setArrayBuffer(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.arrayBuffer = value; + } + + private volatile Object arrayBuffer; /** DataView object */ - @Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object dataView; + @Getter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) + public static Object getDataView(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.dataView == LAZY_SENTINEL) { + global.dataView = global.getBuiltinDataView(); + } + return global.dataView; + } + + @Setter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) + public static void setDataView(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.dataView = value; + } + + private volatile Object dataView; /** TypedArray (int8) */ - @Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object int8Array; + @Getter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) + public static Object getInt8Array(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.int8Array == LAZY_SENTINEL) { + global.int8Array = global.getBuiltinInt8Array(); + } + return global.int8Array; + } + + @Setter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) + public static void setInt8Array(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.int8Array = value; + } + + private volatile Object int8Array; /** TypedArray (uint8) */ - @Property(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object uint8Array; + @Getter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) + public static Object getUint8Array(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.uint8Array == LAZY_SENTINEL) { + global.uint8Array = global.getBuiltinUint8Array(); + } + return global.uint8Array; + } + + @Setter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) + public static void setUint8Array(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.uint8Array = value; + } + + private volatile Object uint8Array; /** TypedArray (uint8) - Clamped */ - @Property(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object uint8ClampedArray; + @Getter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) + public static Object getUint8ClampedArray(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.uint8ClampedArray == LAZY_SENTINEL) { + global.uint8ClampedArray = global.getBuiltinUint8ClampedArray(); + } + return global.uint8ClampedArray; + } + + @Setter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) + public static void setUint8ClampedArray(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.uint8ClampedArray = value; + } + + private volatile Object uint8ClampedArray; /** TypedArray (int16) */ - @Property(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object int16Array; + @Getter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) + public static Object getInt16Array(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.int16Array == LAZY_SENTINEL) { + global.int16Array = global.getBuiltinInt16Array(); + } + return global.int16Array; + } + + @Setter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) + public static void setInt16Array(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.int16Array = value; + } + + private volatile Object int16Array; /** TypedArray (uint16) */ - @Property(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object uint16Array; + @Getter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) + public static Object getUint16Array(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.uint16Array == LAZY_SENTINEL) { + global.uint16Array = global.getBuiltinUint16Array(); + } + return global.uint16Array; + } + + @Setter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) + public static void setUint16Array(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.uint16Array = value; + } + + private volatile Object uint16Array; /** TypedArray (int32) */ - @Property(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object int32Array; + @Getter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) + public static Object getInt32Array(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.int32Array == LAZY_SENTINEL) { + global.int32Array = global.getBuiltinInt32Array(); + } + return global.int32Array; + } + + @Setter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) + public static void setInt32Array(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.int32Array = value; + } + + private volatile Object int32Array; /** TypedArray (uint32) */ - @Property(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object uint32Array; + @Getter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) + public static Object getUint32Array(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.uint32Array == LAZY_SENTINEL) { + global.uint32Array = global.getBuiltinUint32Array(); + } + return global.uint32Array; + } + + @Setter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) + public static void setUint32Array(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.uint32Array = value; + } + + private volatile Object uint32Array; /** TypedArray (float32) */ - @Property(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object float32Array; + @Getter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) + public static Object getFloat32Array(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.float32Array == LAZY_SENTINEL) { + global.float32Array = global.getBuiltinFloat32Array(); + } + return global.float32Array; + } + + @Setter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) + public static void setFloat32Array(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.float32Array = value; + } + + private volatile Object float32Array; /** TypedArray (float64) */ - @Property(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object float64Array; + @Getter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) + public static Object getFloat64Array(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.float64Array == LAZY_SENTINEL) { + global.float64Array = global.getBuiltinFloat64Array(); + } + return global.float64Array; + } + + @Setter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) + public static void setFloat64Array(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.float64Array = value; + } + + private volatile Object float64Array; /** Nashorn extension: Java access - global.Packages */ @Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE) @@ -334,12 +591,40 @@ public final class Global extends ScriptObject implements Scope { public volatile Object org; /** Nashorn extension: Java access - global.javaImporter */ - @Property(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object javaImporter; + @Getter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) + public static Object getJavaImporter(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.javaImporter == LAZY_SENTINEL) { + global.javaImporter = global.getBuiltinJavaImporter(); + } + return global.javaImporter; + } + + @Setter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) + public static void setJavaImporter(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.javaImporter = value; + } + + private volatile Object javaImporter; /** Nashorn extension: global.Java Object constructor. */ - @Property(name = "Java", attributes = Attribute.NOT_ENUMERABLE) - public volatile Object javaApi; + @Getter(name = "Java", attributes = Attribute.NOT_ENUMERABLE) + public static Object getJavaApi(final Object self) { + final Global global = Global.instanceFrom(self); + if (global.javaApi == LAZY_SENTINEL) { + global.javaApi = global.getBuiltinJavaApi(); + } + return global.javaApi; + } + + @Setter(name = "Java", attributes = Attribute.NOT_ENUMERABLE) + public static void setJavaApi(final Object self, final Object value) { + final Global global = Global.instanceFrom(self); + global.javaApi = value; + } + + private volatile Object javaApi; /** Nashorn extension: current script's file name */ @Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) @@ -353,11 +638,19 @@ public final class Global extends ScriptObject implements Scope { @Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER; + private volatile NativeDate DEFAULT_DATE; + /** Used as Date.prototype's default value */ - public NativeDate DEFAULT_DATE; + NativeDate getDefaultDate() { + return DEFAULT_DATE; + } + + private volatile NativeRegExp DEFAULT_REGEXP; /** Used as RegExp.prototype's default value */ - public NativeRegExp DEFAULT_REGEXP; + NativeRegExp getDefaultRegExp() { + return DEFAULT_REGEXP; + } /* * Built-in constructor objects: Even if user changes dynamic values of @@ -1034,7 +1327,7 @@ public final class Global extends ScriptObject implements Scope { /** * Get the builtin Object prototype. - * @return the object prototype. + * @return the object prototype. */ public ScriptObject getObjectPrototype() { return ScriptFunction.getPrototype(builtinObject); @@ -1057,11 +1350,11 @@ public final class Global extends ScriptObject implements Scope { } ScriptObject getDatePrototype() { - return ScriptFunction.getPrototype(builtinDate); + return ScriptFunction.getPrototype(getBuiltinDate()); } ScriptObject getRegExpPrototype() { - return ScriptFunction.getPrototype(builtinRegExp); + return ScriptFunction.getPrototype(getBuiltinRegExp()); } ScriptObject getStringPrototype() { @@ -1073,11 +1366,11 @@ public final class Global extends ScriptObject implements Scope { } ScriptObject getEvalErrorPrototype() { - return ScriptFunction.getPrototype(builtinEvalError); + return ScriptFunction.getPrototype(getBuiltinEvalError()); } ScriptObject getRangeErrorPrototype() { - return ScriptFunction.getPrototype(builtinRangeError); + return ScriptFunction.getPrototype(getBuiltinRangeError()); } ScriptObject getReferenceErrorPrototype() { @@ -1093,59 +1386,136 @@ public final class Global extends ScriptObject implements Scope { } ScriptObject getURIErrorPrototype() { - return ScriptFunction.getPrototype(builtinURIError); + return ScriptFunction.getPrototype(getBuiltinURIError()); } ScriptObject getJavaImporterPrototype() { - return ScriptFunction.getPrototype(builtinJavaImporter); + return ScriptFunction.getPrototype(getBuiltinJavaImporter()); } ScriptObject getJSAdapterPrototype() { - return ScriptFunction.getPrototype(builtinJSAdapter); + return ScriptFunction.getPrototype(getBuiltinJSAdapter()); + } + + private synchronized ScriptFunction getBuiltinArrayBuffer() { + if (this.builtinArrayBuffer == null) { + this.builtinArrayBuffer = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class); + } + return this.builtinArrayBuffer; } ScriptObject getArrayBufferPrototype() { - return ScriptFunction.getPrototype(builtinArrayBuffer); + return ScriptFunction.getPrototype(getBuiltinArrayBuffer()); + } + + private synchronized ScriptFunction getBuiltinDataView() { + if (this.builtinDataView == null) { + this.builtinDataView = initConstructorAndSwitchPoint("DataView", ScriptFunction.class); + } + return this.builtinDataView; } ScriptObject getDataViewPrototype() { - return ScriptFunction.getPrototype(builtinDataView); + return ScriptFunction.getPrototype(getBuiltinDataView()); + } + + private synchronized ScriptFunction getBuiltinInt8Array() { + if (this.builtinInt8Array == null) { + this.builtinInt8Array = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class); + } + return this.builtinInt8Array; } ScriptObject getInt8ArrayPrototype() { - return ScriptFunction.getPrototype(builtinInt8Array); + return ScriptFunction.getPrototype(getBuiltinInt8Array()); + } + + private synchronized ScriptFunction getBuiltinUint8Array() { + if (this.builtinUint8Array == null) { + this.builtinUint8Array = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class); + } + return this.builtinUint8Array; } ScriptObject getUint8ArrayPrototype() { - return ScriptFunction.getPrototype(builtinUint8Array); + return ScriptFunction.getPrototype(getBuiltinUint8Array()); + } + + private synchronized ScriptFunction getBuiltinUint8ClampedArray() { + if (this.builtinUint8ClampedArray == null) { + this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class); + } + return this.builtinUint8ClampedArray; } ScriptObject getUint8ClampedArrayPrototype() { - return ScriptFunction.getPrototype(builtinUint8ClampedArray); + return ScriptFunction.getPrototype(getBuiltinUint8ClampedArray()); + } + + private synchronized ScriptFunction getBuiltinInt16Array() { + if (this.builtinInt16Array == null) { + this.builtinInt16Array = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class); + } + return this.builtinInt16Array; } ScriptObject getInt16ArrayPrototype() { - return ScriptFunction.getPrototype(builtinInt16Array); + return ScriptFunction.getPrototype(getBuiltinInt16Array()); + } + + private synchronized ScriptFunction getBuiltinUint16Array() { + if (this.builtinUint16Array == null) { + this.builtinUint16Array = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class); + } + return this.builtinUint16Array; } ScriptObject getUint16ArrayPrototype() { - return ScriptFunction.getPrototype(builtinUint16Array); + return ScriptFunction.getPrototype(getBuiltinUint16Array()); + } + + private synchronized ScriptFunction getBuiltinInt32Array() { + if (this.builtinInt32Array == null) { + this.builtinInt32Array = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class); + } + return this.builtinInt32Array; } ScriptObject getInt32ArrayPrototype() { - return ScriptFunction.getPrototype(builtinInt32Array); + return ScriptFunction.getPrototype(getBuiltinInt32Array()); + } + + private synchronized ScriptFunction getBuiltinUint32Array() { + if (this.builtinUint32Array == null) { + this.builtinUint32Array = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class); + } + return this.builtinUint32Array; } ScriptObject getUint32ArrayPrototype() { - return ScriptFunction.getPrototype(builtinUint32Array); + return ScriptFunction.getPrototype(getBuiltinUint32Array()); + } + + private synchronized ScriptFunction getBuiltinFloat32Array() { + if (this.builtinFloat32Array == null) { + this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class); + } + return this.builtinFloat32Array; } ScriptObject getFloat32ArrayPrototype() { - return ScriptFunction.getPrototype(builtinFloat32Array); + return ScriptFunction.getPrototype(getBuiltinFloat32Array()); + } + + private synchronized ScriptFunction getBuiltinFloat64Array() { + if (this.builtinFloat64Array == null) { + this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class); + } + return this.builtinFloat64Array; } ScriptObject getFloat64ArrayPrototype() { - return ScriptFunction.getPrototype(builtinFloat64Array); + return ScriptFunction.getPrototype(getBuiltinFloat64Array()); } private ScriptFunction getBuiltinArray() { @@ -1180,8 +1550,14 @@ public final class Global extends ScriptObject implements Scope { return instance._boolean == instance.getBuiltinBoolean(); } - private ScriptFunction getBuiltinDate() { - return builtinDate; + private synchronized ScriptFunction getBuiltinDate() { + if (this.builtinDate == null) { + this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class); + final ScriptObject dateProto = ScriptFunction.getPrototype(builtinDate); + // initialize default date + this.DEFAULT_DATE = new NativeDate(NaN, dateProto); + } + return this.builtinDate; } /** @@ -1191,7 +1567,7 @@ public final class Global extends ScriptObject implements Scope { */ public static boolean isBuiltinDate() { final Global instance = Global.instance(); - return instance.date == instance.getBuiltinDate(); + return instance.date == LAZY_SENTINEL || instance.date == instance.getBuiltinDate(); } private ScriptFunction getBuiltinError() { @@ -1208,8 +1584,11 @@ public final class Global extends ScriptObject implements Scope { return instance.error == instance.getBuiltinError(); } - private ScriptFunction getBuiltinEvalError() { - return builtinEvalError; + private synchronized ScriptFunction getBuiltinEvalError() { + if (this.builtinEvalError == null) { + this.builtinEvalError = initErrorSubtype("EvalError", getErrorPrototype()); + } + return this.builtinEvalError; } /** @@ -1219,7 +1598,7 @@ public final class Global extends ScriptObject implements Scope { */ public static boolean isBuiltinEvalError() { final Global instance = Global.instance(); - return instance.evalError == instance.getBuiltinEvalError(); + return instance.evalError == LAZY_SENTINEL || instance.evalError == instance.getBuiltinEvalError(); } private ScriptFunction getBuiltinFunction() { @@ -1270,7 +1649,10 @@ public final class Global extends ScriptObject implements Scope { return isBuiltinFunctionProperty("call"); } - private ScriptFunction getBuiltinJSAdapter() { + private synchronized ScriptFunction getBuiltinJSAdapter() { + if (this.builtinJSAdapter == null) { + this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class); + } return builtinJSAdapter; } @@ -1281,11 +1663,14 @@ public final class Global extends ScriptObject implements Scope { */ public static boolean isBuiltinJSAdapter() { final Global instance = Global.instance(); - return instance.jsadapter == instance.getBuiltinJSAdapter(); + return instance.jsadapter == LAZY_SENTINEL || instance.jsadapter == instance.getBuiltinJSAdapter(); } - private ScriptObject getBuiltinJSON() { - return builtinJSON; + private synchronized ScriptObject getBuiltinJSON() { + if (this.builtinJSON == null) { + this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class); + } + return this.builtinJSON; } /** @@ -1295,7 +1680,7 @@ public final class Global extends ScriptObject implements Scope { */ public static boolean isBuiltinJSON() { final Global instance = Global.instance(); - return instance.json == instance.getBuiltinJSON(); + return instance.json == LAZY_SENTINEL || instance.json == instance.getBuiltinJSON(); } private ScriptObject getBuiltinJava() { @@ -1326,8 +1711,18 @@ public final class Global extends ScriptObject implements Scope { return instance.javax == instance.getBuiltinJavax(); } - private ScriptObject getBuiltinJavaImporter() { - return builtinJavaImporter; + private synchronized ScriptFunction getBuiltinJavaImporter() { + if (this.builtinJavaImporter == null) { + this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class); + } + return this.builtinJavaImporter; + } + + private synchronized ScriptObject getBuiltinJavaApi() { + if (this.builtinJavaApi == null) { + this.builtinJavaApi = initConstructor("Java", ScriptObject.class); + } + return this.builtinJavaApi; } /** @@ -1337,11 +1732,7 @@ public final class Global extends ScriptObject implements Scope { */ public static boolean isBuiltinJavaImporter() { final Global instance = Global.instance(); - return instance.javaImporter == instance.getBuiltinJavaImporter(); - } - - private ScriptObject getBuiltinMath() { - return builtinMath; + return instance.javaImporter == LAZY_SENTINEL || instance.javaImporter == instance.getBuiltinJavaImporter(); } /** @@ -1351,7 +1742,7 @@ public final class Global extends ScriptObject implements Scope { */ public static boolean isBuiltinMath() { final Global instance = Global.instance(); - return instance.math == instance.getBuiltinMath(); + return instance.math == instance.builtinMath; } private ScriptFunction getBuiltinNumber() { @@ -1396,7 +1787,10 @@ public final class Global extends ScriptObject implements Scope { return instance.packages == instance.getBuiltinPackages(); } - private ScriptFunction getBuiltinRangeError() { + private synchronized ScriptFunction getBuiltinRangeError() { + if (this.builtinRangeError == null) { + this.builtinRangeError = initErrorSubtype("RangeError", getErrorPrototype()); + } return builtinRangeError; } @@ -1407,10 +1801,10 @@ public final class Global extends ScriptObject implements Scope { */ public static boolean isBuiltinRangeError() { final Global instance = Global.instance(); - return instance.rangeError == instance.getBuiltinRangeError(); + return instance.rangeError == LAZY_SENTINEL || instance.rangeError == instance.getBuiltinRangeError(); } - private ScriptFunction getBuiltinReferenceError() { + private synchronized ScriptFunction getBuiltinReferenceError() { return builtinReferenceError; } @@ -1424,7 +1818,16 @@ public final class Global extends ScriptObject implements Scope { return instance.referenceError == instance.getBuiltinReferenceError(); } - private ScriptFunction getBuiltinRegExp() { + private synchronized ScriptFunction getBuiltinRegExp() { + if (this.builtinRegExp == null) { + this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class); + final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp); + // initialize default regexp object + this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto); + // RegExp.prototype should behave like a RegExp object. So copy the + // properties. + regExpProto.addBoundProperties(DEFAULT_REGEXP); + } return builtinRegExp; } @@ -1435,7 +1838,7 @@ public final class Global extends ScriptObject implements Scope { */ public static boolean isBuiltinRegExp() { final Global instance = Global.instance(); - return instance.regexp == instance.getBuiltinRegExp(); + return instance.regexp == LAZY_SENTINEL || instance.regexp == instance.getBuiltinRegExp(); } private ScriptFunction getBuiltinString() { @@ -1480,8 +1883,11 @@ public final class Global extends ScriptObject implements Scope { return instance.typeError == instance.getBuiltinTypeError(); } - private ScriptFunction getBuiltinURIError() { - return builtinURIError; + private synchronized ScriptFunction getBuiltinURIError() { + if (this.builtinURIError == null) { + this.builtinURIError = initErrorSubtype("URIError", getErrorPrototype()); + } + return this.builtinURIError; } /** @@ -1491,7 +1897,7 @@ public final class Global extends ScriptObject implements Scope { */ public static boolean isBuiltinURIError() { final Global instance = Global.instance(); - return instance.uriError == instance.getBuiltinURIError(); + return instance.uriError == LAZY_SENTINEL || instance.uriError == instance.getBuiltinURIError(); } @Override @@ -1903,13 +2309,9 @@ public final class Global extends ScriptObject implements Scope { // built-in constructors this.builtinArray = initConstructorAndSwitchPoint("Array", ScriptFunction.class); this.builtinBoolean = initConstructorAndSwitchPoint("Boolean", ScriptFunction.class); - this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class); - this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class); - this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class); - this.builtinMath = initConstructorAndSwitchPoint("Math", ScriptObject.class); this.builtinNumber = initConstructorAndSwitchPoint("Number", ScriptFunction.class); - this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class); this.builtinString = initConstructorAndSwitchPoint("String", ScriptFunction.class); + this.builtinMath = initConstructorAndSwitchPoint("Math", ScriptObject.class); // initialize String.prototype.length to 0 // add String.prototype.length @@ -1920,26 +2322,28 @@ public final class Global extends ScriptObject implements Scope { final ScriptObject arrayPrototype = getArrayPrototype(); arrayPrototype.setIsArray(); - this.DEFAULT_DATE = new NativeDate(Double.NaN, this); - - // initialize default regexp object - this.DEFAULT_REGEXP = new NativeRegExp("(?:)", this); - - // RegExp.prototype should behave like a RegExp object. So copy the - // properties. - final ScriptObject regExpProto = getRegExpPrototype(); - regExpProto.addBoundProperties(DEFAULT_REGEXP); - // Error stuff initErrorObjects(); // java access if (! env._no_java) { + this.javaApi = LAZY_SENTINEL; + this.javaImporter = LAZY_SENTINEL; initJavaAccess(); } if (! env._no_typed_arrays) { - initTypedArray(); + this.arrayBuffer = LAZY_SENTINEL; + this.dataView = LAZY_SENTINEL; + this.int8Array = LAZY_SENTINEL; + this.uint8Array = LAZY_SENTINEL; + this.uint8ClampedArray = LAZY_SENTINEL; + this.int16Array = LAZY_SENTINEL; + this.uint16Array = LAZY_SENTINEL; + this.int32Array = LAZY_SENTINEL; + this.uint32Array = LAZY_SENTINEL; + this.float32Array = LAZY_SENTINEL; + this.float64Array = LAZY_SENTINEL; } if (env._scripting) { @@ -2013,12 +2417,9 @@ public final class Global extends ScriptObject implements Scope { tagBuiltinProperties("Error", builtinError); - this.builtinEvalError = initErrorSubtype("EvalError", errorProto); - this.builtinRangeError = initErrorSubtype("RangeError", errorProto); this.builtinReferenceError = initErrorSubtype("ReferenceError", errorProto); this.builtinSyntaxError = initErrorSubtype("SyntaxError", errorProto); this.builtinTypeError = initErrorSubtype("TypeError", errorProto); - this.builtinURIError = initErrorSubtype("URIError", errorProto); } private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) { @@ -2040,8 +2441,6 @@ public final class Global extends ScriptObject implements Scope { this.builtinJavafx = new NativeJavaPackage("javafx", objectProto); this.builtinJavax = new NativeJavaPackage("javax", objectProto); this.builtinOrg = new NativeJavaPackage("org", objectProto); - this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class); - this.builtinJavaApi = initConstructor("Java", ScriptObject.class); } private void initScripting(final ScriptEnvironment scriptEnv) { @@ -2093,60 +2492,25 @@ public final class Global extends ScriptObject implements Scope { } } - private void initTypedArray() { - this.builtinArrayBuffer = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class); - this.builtinDataView = initConstructorAndSwitchPoint("DataView", ScriptFunction.class); - this.builtinInt8Array = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class); - this.builtinUint8Array = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class); - this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class); - this.builtinInt16Array = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class); - this.builtinUint16Array = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class); - this.builtinInt32Array = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class); - this.builtinUint32Array = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class); - this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class); - this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class); - - } - private void copyBuiltins() { this.array = this.builtinArray; this._boolean = this.builtinBoolean; - this.date = this.builtinDate; this.error = this.builtinError; - this.evalError = this.builtinEvalError; this.function = this.builtinFunction; - this.jsadapter = this.builtinJSAdapter; - this.json = this.builtinJSON; this.com = this.builtinCom; this.edu = this.builtinEdu; this.java = this.builtinJava; this.javafx = this.builtinJavafx; this.javax = this.builtinJavax; this.org = this.builtinOrg; - this.javaImporter = this.builtinJavaImporter; - this.javaApi = this.builtinJavaApi; this.math = this.builtinMath; this.number = this.builtinNumber; this.object = this.builtinObject; this.packages = this.builtinPackages; - this.rangeError = this.builtinRangeError; this.referenceError = this.builtinReferenceError; - this.regexp = this.builtinRegExp; this.string = this.builtinString; this.syntaxError = this.builtinSyntaxError; this.typeError = this.builtinTypeError; - this.uriError = this.builtinURIError; - this.arrayBuffer = this.builtinArrayBuffer; - this.dataView = this.builtinDataView; - this.int8Array = this.builtinInt8Array; - this.uint8Array = this.builtinUint8Array; - this.uint8ClampedArray = this.builtinUint8ClampedArray; - this.int16Array = this.builtinInt16Array; - this.uint16Array = this.builtinUint16Array; - this.int32Array = this.builtinInt32Array; - this.uint32Array = this.builtinUint32Array; - this.float32Array = this.builtinFloat32Array; - this.float64Array = this.builtinFloat64Array; } private void initDebug() { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDate.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDate.java index 88846d88793..7462e4fb459 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDate.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDate.java @@ -121,6 +121,10 @@ public final class NativeDate extends ScriptObject { this.timezone = env._timezone; } + NativeDate(final double time, final ScriptObject proto) { + this(time, proto, $nasgenmap$); + } + NativeDate(final double time, final Global global) { this(time, global.getDatePrototype(), $nasgenmap$); } @@ -1276,7 +1280,7 @@ public final class NativeDate extends ScriptObject { if (self instanceof NativeDate) { return (NativeDate)self; } else if (self != null && self == Global.instance().getDatePrototype()) { - return Global.instance().DEFAULT_DATE; + return Global.instance().getDefaultDate(); } else { throw typeError("not.a.date", ScriptRuntime.safeToString(self)); } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeRegExp.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeRegExp.java index 33ef284985f..62ef4835c61 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeRegExp.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeRegExp.java @@ -78,8 +78,8 @@ public final class NativeRegExp extends ScriptObject { this.globalObject = global; } - NativeRegExp(final String input, final String flagString, final Global global) { - this(global); + NativeRegExp(final String input, final String flagString, final Global global, final ScriptObject proto) { + super(proto, $nasgenmap$); try { this.regexp = RegExpFactory.create(input, flagString); } catch (final ParserException e) { @@ -87,10 +87,14 @@ public final class NativeRegExp extends ScriptObject { e.throwAsEcmaException(); throw new AssertionError(); //guard against null warnings below } - + this.globalObject = global; this.setLastIndex(0); } + NativeRegExp(final String input, final String flagString, final Global global) { + this(input, flagString, global, global.getRegExpPrototype()); + } + NativeRegExp(final String input, final String flagString) { this(input, flagString, Global.instance()); } @@ -928,7 +932,7 @@ public final class NativeRegExp extends ScriptObject { if (self instanceof NativeRegExp) { return (NativeRegExp)self; } else if (self != null && self == Global.instance().getRegExpPrototype()) { - return Global.instance().DEFAULT_REGEXP; + return Global.instance().getDefaultRegExp(); } else { throw typeError("not.a.regexp", ScriptRuntime.safeToString(self)); } From b980d9390988a1f63e74b1a40b0a3051f4ca428a Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Wed, 25 Mar 2015 10:08:09 +0100 Subject: [PATCH 124/362] 8075809: Add missing includes of stack.inline.hpp Reviewed-by: jmasa, pliden --- .../gc_implementation/parallelScavenge/psPromotionManager.cpp | 3 ++- .../share/vm/gc_implementation/parallelScavenge/psTasks.cpp | 1 + hotspot/src/share/vm/memory/genMarkSweep.cpp | 1 + hotspot/src/share/vm/memory/heapInspection.cpp | 1 + hotspot/src/share/vm/oops/klass.cpp | 2 +- 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp index 4a6716aefab..33d300fcbb7 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -34,6 +34,7 @@ #include "memory/padded.inline.hpp" #include "oops/oop.inline.hpp" #include "oops/oop.psgc.inline.hpp" +#include "utilities/stack.inline.hpp" PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp index df320d87ff0..e944dfea010 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp @@ -40,6 +40,7 @@ #include "runtime/thread.hpp" #include "runtime/vmThread.hpp" #include "services/management.hpp" +#include "utilities/stack.inline.hpp" #include "utilities/taskqueue.hpp" // diff --git a/hotspot/src/share/vm/memory/genMarkSweep.cpp b/hotspot/src/share/vm/memory/genMarkSweep.cpp index eac303540f2..ef2707999f2 100644 --- a/hotspot/src/share/vm/memory/genMarkSweep.cpp +++ b/hotspot/src/share/vm/memory/genMarkSweep.cpp @@ -50,6 +50,7 @@ #include "runtime/vmThread.hpp" #include "utilities/copy.hpp" #include "utilities/events.hpp" +#include "utilities/stack.inline.hpp" void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, bool clear_all_softrefs) { guarantee(level == 1, "We always collect both old and young."); diff --git a/hotspot/src/share/vm/memory/heapInspection.cpp b/hotspot/src/share/vm/memory/heapInspection.cpp index 4d8091210b5..c4b5ba787d0 100644 --- a/hotspot/src/share/vm/memory/heapInspection.cpp +++ b/hotspot/src/share/vm/memory/heapInspection.cpp @@ -33,6 +33,7 @@ #include "runtime/os.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/macros.hpp" +#include "utilities/stack.inline.hpp" #if INCLUDE_ALL_GCS #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" #endif // INCLUDE_ALL_GCS diff --git a/hotspot/src/share/vm/oops/klass.cpp b/hotspot/src/share/vm/oops/klass.cpp index 295008dd309..09256c71971 100644 --- a/hotspot/src/share/vm/oops/klass.cpp +++ b/hotspot/src/share/vm/oops/klass.cpp @@ -39,8 +39,8 @@ #include "runtime/atomic.inline.hpp" #include "runtime/orderAccess.inline.hpp" #include "trace/traceMacros.hpp" -#include "utilities/stack.hpp" #include "utilities/macros.hpp" +#include "utilities/stack.inline.hpp" #if INCLUDE_ALL_GCS #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" From 602b7d79e988f22e274b19ec3fd29782609907e8 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Wed, 25 Mar 2015 10:13:56 +0100 Subject: [PATCH 125/362] 8075829: Move CSpaceCounters implementation to cSpaceCounters.cpp Reviewed-by: jwilhelm, brutisso --- .../shared/cSpaceCounters.cpp | 19 ++++++++++++++- .../shared/cSpaceCounters.hpp | 23 +++++-------------- hotspot/src/share/vm/memory/space.hpp | 4 ++-- .../src/share/vm/precompiled/precompiled.hpp | 1 - 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/shared/cSpaceCounters.cpp b/hotspot/src/share/vm/gc_implementation/shared/cSpaceCounters.cpp index 0e40ce7ec83..9b371987e1d 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/cSpaceCounters.cpp +++ b/hotspot/src/share/vm/gc_implementation/shared/cSpaceCounters.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -63,3 +63,20 @@ CSpaceCounters::CSpaceCounters(const char* name, int ordinal, size_t max_size, _space->capacity(), CHECK); } } + +void CSpaceCounters::update_capacity() { + _capacity->set_value(_space->capacity()); +} + +void CSpaceCounters::update_used() { + _used->set_value(_space->used()); +} + +void CSpaceCounters::update_all() { + update_used(); + update_capacity(); +} + +jlong ContiguousSpaceUsedHelper::take_sample(){ + return _space->used(); +} diff --git a/hotspot/src/share/vm/gc_implementation/shared/cSpaceCounters.hpp b/hotspot/src/share/vm/gc_implementation/shared/cSpaceCounters.hpp index 12d759566ac..e30044bc5e3 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/cSpaceCounters.hpp +++ b/hotspot/src/share/vm/gc_implementation/shared/cSpaceCounters.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -26,7 +26,7 @@ #define SHARE_VM_GC_IMPLEMENTATION_SHARED_CSPACECOUNTERS_HPP #include "gc_implementation/shared/generationCounters.hpp" -#include "memory/space.inline.hpp" +#include "memory/space.hpp" #include "runtime/perfData.hpp" // A CSpaceCounters is a holder class for performance counters @@ -56,18 +56,9 @@ class CSpaceCounters: public CHeapObj { if (_name_space != NULL) FREE_C_HEAP_ARRAY(char, _name_space); } - virtual inline void update_capacity() { - _capacity->set_value(_space->capacity()); - } - - virtual inline void update_used() { - _used->set_value(_space->used()); - } - - virtual inline void update_all() { - update_used(); - update_capacity(); - } + virtual void update_capacity(); + virtual void update_used(); + virtual void update_all(); const char* name_space() const { return _name_space; } }; @@ -79,9 +70,7 @@ class ContiguousSpaceUsedHelper : public PerfLongSampleHelper { public: ContiguousSpaceUsedHelper(ContiguousSpace* space) : _space(space) { } - inline jlong take_sample() { - return _space->used(); - } + jlong take_sample(); }; #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_CSPACECOUNTERS_HPP diff --git a/hotspot/src/share/vm/memory/space.hpp b/hotspot/src/share/vm/memory/space.hpp index f5649764ffa..61761ba3815 100644 --- a/hotspot/src/share/vm/memory/space.hpp +++ b/hotspot/src/share/vm/memory/space.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -195,7 +195,7 @@ class Space: public CHeapObj { // structure supporting these calls, possibly speeding up future calls. // The default implementation, however, is simply to call the const // version. - inline virtual HeapWord* block_start(const void* p); + virtual HeapWord* block_start(const void* p); // Requires "addr" to be the start of a chunk, and returns its size. // "addr + size" is required to be the start of a new chunk, or the end diff --git a/hotspot/src/share/vm/precompiled/precompiled.hpp b/hotspot/src/share/vm/precompiled/precompiled.hpp index a2ae0465c3d..e69fdf460ad 100644 --- a/hotspot/src/share/vm/precompiled/precompiled.hpp +++ b/hotspot/src/share/vm/precompiled/precompiled.hpp @@ -135,7 +135,6 @@ # include "memory/resourceArea.hpp" # include "memory/sharedHeap.hpp" # include "memory/space.hpp" -# include "memory/space.inline.hpp" # include "memory/threadLocalAllocBuffer.hpp" # include "memory/threadLocalAllocBuffer.inline.hpp" # include "memory/universe.hpp" From b220e6cb1dd273dc4e97ae81dff1f0f6d795ea38 Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Wed, 25 Mar 2015 10:50:08 +0000 Subject: [PATCH 126/362] 8075307: Pipeline calculating inconsistent flag state for parallel stateful ops Reviewed-by: smarks --- .../java/util/stream/AbstractPipeline.java | 120 ++++++++---------- .../classes/java/util/stream/ReduceOps.java | 20 +++ .../java/util/stream/UnorderedTest.java | 4 +- .../tests/java/util/stream/CountTest.java | 58 ++++++++- .../java/util/stream/DistinctOpTest.java | 4 +- 5 files changed, 137 insertions(+), 69 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/util/stream/AbstractPipeline.java b/jdk/src/java.base/share/classes/java/util/stream/AbstractPipeline.java index e0ca02101da..c4cc508421c 100644 --- a/jdk/src/java.base/share/classes/java/util/stream/AbstractPipeline.java +++ b/jdk/src/java.base/share/classes/java/util/stream/AbstractPipeline.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -379,60 +379,6 @@ abstract class AbstractPipeline> return StreamOpFlag.toStreamFlags(combinedFlags); } - /** - * Prepare the pipeline for a parallel execution. As the pipeline is built, - * the flags and depth indicators are set up for a sequential execution. - * If the execution is parallel, and there are any stateful operations, then - * some of these need to be adjusted, as well as adjusting for flags from - * the terminal operation (such as back-propagating UNORDERED). - * Need not be called for a sequential execution. - * - * @param terminalFlags Operation flags for the terminal operation - */ - private void parallelPrepare(int terminalFlags) { - @SuppressWarnings("rawtypes") - AbstractPipeline backPropagationHead = sourceStage; - if (sourceStage.sourceAnyStateful) { - int depth = 1; - for ( @SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage; - p != null; - u = p, p = p.nextStage) { - int thisOpFlags = p.sourceOrOpFlags; - if (p.opIsStateful()) { - // If the stateful operation is a short-circuit operation - // then move the back propagation head forwards - // NOTE: there are no size-injecting ops - if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) { - backPropagationHead = p; - // Clear the short circuit flag for next pipeline stage - // This stage encapsulates short-circuiting, the next - // stage may not have any short-circuit operations, and - // if so spliterator.forEachRemaining should be used - // for traversal - thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT; - } - - depth = 0; - // The following injects size, it is equivalent to: - // StreamOpFlag.combineOpFlags(StreamOpFlag.IS_SIZED, p.combinedFlags); - thisOpFlags = (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED; - } - p.depth = depth++; - p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags); - } - } - - // Apply the upstream terminal flags - if (terminalFlags != 0) { - int upstreamTerminalFlags = terminalFlags & StreamOpFlag.UPSTREAM_TERMINAL_OP_MASK; - for ( @SuppressWarnings("rawtypes") AbstractPipeline p = backPropagationHead; p.nextStage != null; p = p.nextStage) { - p.combinedFlags = StreamOpFlag.combineOpFlags(upstreamTerminalFlags, p.combinedFlags); - } - - combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags); - } - } - /** * Get the source spliterator for this pipeline stage. For a sequential or * stateless parallel pipeline, this is the source spliterator. For a @@ -456,24 +402,70 @@ abstract class AbstractPipeline> throw new IllegalStateException(MSG_CONSUMED); } - if (isParallel()) { - // @@@ Merge parallelPrepare with the loop below and use the - // spliterator characteristics to determine if SIZED - // should be injected - parallelPrepare(terminalFlags); + boolean hasTerminalFlags = terminalFlags != 0; + if (isParallel() && sourceStage.sourceAnyStateful) { + // Adjust pipeline stages if there are stateful ops, + // and find the last short circuiting op, if any, that + // defines the head stage for back-propagation of terminal flags + @SuppressWarnings("rawtypes") + AbstractPipeline backPropagationHead = sourceStage; + int depth = 1; + for (@SuppressWarnings("rawtypes") AbstractPipeline p = sourceStage.nextStage; + p != null; + p = p.nextStage) { + if (p.opIsStateful()) { + if (StreamOpFlag.SHORT_CIRCUIT.isKnown(p.sourceOrOpFlags)) { + // If the stateful operation is a short-circuit operation + // then move the back propagation head forwards + // NOTE: there are no size-injecting ops + backPropagationHead = p; + } + + depth = 0; + } + p.depth = depth++; + } // Adapt the source spliterator, evaluating each stateful op // in the pipeline up to and including this pipeline stage - for ( @SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this; + // Flags for each pipeline stage are adjusted accordingly + boolean backPropagate = false; + int upstreamTerminalFlags = terminalFlags & StreamOpFlag.UPSTREAM_TERMINAL_OP_MASK; + for (@SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this; u != e; u = p, p = p.nextStage) { - if (p.opIsStateful()) { - spliterator = p.opEvaluateParallelLazy(u, spliterator); + if (hasTerminalFlags && + (backPropagate || (backPropagate = (u == backPropagationHead)))) { + // Back-propagate flags from the terminal operation + u.combinedFlags = StreamOpFlag.combineOpFlags(upstreamTerminalFlags, u.combinedFlags); } + + int thisOpFlags = p.sourceOrOpFlags; + if (p.opIsStateful()) { + if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) { + // Clear the short circuit flag for next pipeline stage + // This stage encapsulates short-circuiting, the next + // stage may not have any short-circuit operations, and + // if so spliterator.forEachRemaining should be used + // for traversal + thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT; + } + + spliterator = p.opEvaluateParallelLazy(u, spliterator); + + // Inject or clear SIZED on the source pipeline stage + // based on the stage's spliterator + thisOpFlags = spliterator.hasCharacteristics(Spliterator.SIZED) + ? (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED + : (thisOpFlags & ~StreamOpFlag.IS_SIZED) | StreamOpFlag.NOT_SIZED; + } + p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags); } } - else if (terminalFlags != 0) { + + if (hasTerminalFlags) { + // Apply flags from the terminal operation to last pipeline stage combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags); } diff --git a/jdk/src/java.base/share/classes/java/util/stream/ReduceOps.java b/jdk/src/java.base/share/classes/java/util/stream/ReduceOps.java index e3cf2979f45..6928409760b 100644 --- a/jdk/src/java.base/share/classes/java/util/stream/ReduceOps.java +++ b/jdk/src/java.base/share/classes/java/util/stream/ReduceOps.java @@ -264,6 +264,11 @@ final class ReduceOps { return spliterator.getExactSizeIfKnown(); return super.evaluateParallel(helper, spliterator); } + + @Override + public int getOpFlags() { + return StreamOpFlag.NOT_ORDERED; + } }; } @@ -433,6 +438,11 @@ final class ReduceOps { return spliterator.getExactSizeIfKnown(); return super.evaluateParallel(helper, spliterator); } + + @Override + public int getOpFlags() { + return StreamOpFlag.NOT_ORDERED; + } }; } @@ -602,6 +612,11 @@ final class ReduceOps { return spliterator.getExactSizeIfKnown(); return super.evaluateParallel(helper, spliterator); } + + @Override + public int getOpFlags() { + return StreamOpFlag.NOT_ORDERED; + } }; } @@ -771,6 +786,11 @@ final class ReduceOps { return spliterator.getExactSizeIfKnown(); return super.evaluateParallel(helper, spliterator); } + + @Override + public int getOpFlags() { + return StreamOpFlag.NOT_ORDERED; + } }; } diff --git a/jdk/test/java/util/stream/boottest/java/util/stream/UnorderedTest.java b/jdk/test/java/util/stream/boottest/java/util/stream/UnorderedTest.java index 47eb533d8a2..4254b15765f 100644 --- a/jdk/test/java/util/stream/boottest/java/util/stream/UnorderedTest.java +++ b/jdk/test/java/util/stream/boottest/java/util/stream/UnorderedTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -251,7 +251,7 @@ public class UnorderedTest extends OpTestCase { final int lastLimitIndex = l; return s -> { - if (lastLimitIndex == -1) + if (lastLimitIndex == -1 && fs.size() > 0) s = fi.apply(s); for (int i = 0; i < fs.size(); i++) { s = fs.get(i).apply(s); diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CountTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CountTest.java index 0ed5ddc1a17..41f6ecf00b9 100644 --- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CountTest.java +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CountTest.java @@ -24,11 +24,12 @@ /** * @test * @summary Tests counting of streams - * @bug 8031187 8067969 + * @bug 8031187 8067969 8075307 */ package org.openjdk.tests.java.util.stream; +import java.util.HashSet; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.DoubleStream; import java.util.stream.DoubleStreamTestDataProvider; @@ -59,6 +60,19 @@ public class CountTest extends OpTestCase { terminal(s -> s.filter(e -> true), Stream::count). expectedResult(expectedCount). exercise(); + + // Test with stateful distinct op that is a barrier or lazy + // depending if source is not already distinct and encounter order is + // preserved or not + expectedCount = data.into(new HashSet<>()).size(); + withData(data). + terminal(Stream::distinct, Stream::count). + expectedResult(expectedCount). + exercise(); + withData(data). + terminal(s -> s.unordered().distinct(), Stream::count). + expectedResult(expectedCount). + exercise(); } @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) @@ -74,6 +88,16 @@ public class CountTest extends OpTestCase { terminal(s -> s.filter(e -> true), IntStream::count). expectedResult(expectedCount). exercise(); + + expectedCount = data.into(new HashSet<>()).size(); + withData(data). + terminal(IntStream::distinct, IntStream::count). + expectedResult(expectedCount). + exercise(); + withData(data). + terminal(s -> s.unordered().distinct(), IntStream::count). + expectedResult(expectedCount). + exercise(); } @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) @@ -89,6 +113,16 @@ public class CountTest extends OpTestCase { terminal(s -> s.filter(e -> true), LongStream::count). expectedResult(expectedCount). exercise(); + + expectedCount = data.into(new HashSet<>()).size(); + withData(data). + terminal(LongStream::distinct, LongStream::count). + expectedResult(expectedCount). + exercise(); + withData(data). + terminal(s -> s.unordered().distinct(), LongStream::count). + expectedResult(expectedCount). + exercise(); } @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) @@ -104,6 +138,16 @@ public class CountTest extends OpTestCase { terminal(s -> s.filter(e -> true), DoubleStream::count). expectedResult(expectedCount). exercise(); + + expectedCount = data.into(new HashSet<>()).size(); + withData(data). + terminal(DoubleStream::distinct, DoubleStream::count). + expectedResult(expectedCount). + exercise(); + withData(data). + terminal(s -> s.unordered().distinct(), DoubleStream::count). + expectedResult(expectedCount). + exercise(); } public void testNoEvaluationForSizedStream() { @@ -111,24 +155,36 @@ public class CountTest extends OpTestCase { AtomicInteger ai = new AtomicInteger(); Stream.of(1, 2, 3, 4).peek(e -> ai.getAndIncrement()).count(); assertEquals(ai.get(), 0); + + Stream.of(1, 2, 3, 4).peek(e -> ai.getAndIncrement()).parallel().count(); + assertEquals(ai.get(), 0); } { AtomicInteger ai = new AtomicInteger(); IntStream.of(1, 2, 3, 4).peek(e -> ai.getAndIncrement()).count(); assertEquals(ai.get(), 0); + + IntStream.of(1, 2, 3, 4).peek(e -> ai.getAndIncrement()).parallel().count(); + assertEquals(ai.get(), 0); } { AtomicInteger ai = new AtomicInteger(); LongStream.of(1, 2, 3, 4).peek(e -> ai.getAndIncrement()).count(); assertEquals(ai.get(), 0); + + LongStream.of(1, 2, 3, 4).peek(e -> ai.getAndIncrement()).parallel().count(); + assertEquals(ai.get(), 0); } { AtomicInteger ai = new AtomicInteger(); DoubleStream.of(1, 2, 3, 4).peek(e -> ai.getAndIncrement()).count(); assertEquals(ai.get(), 0); + + DoubleStream.of(1, 2, 3, 4).peek(e -> ai.getAndIncrement()).parallel().count(); + assertEquals(ai.get(), 0); } } } diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java index 69432cfedf6..89f762010ee 100644 --- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -128,7 +128,7 @@ public class DistinctOpTest extends OpTestCase { @Test(dataProvider = "StreamTestData", dataProviderClass = StreamTestDataProvider.class) public void testDistinctDistinct(String name, TestData.OfRef data) { Collection result = withData(data) - .stream(s -> s.distinct().distinct(), new CollectorOps.TestParallelSizedOp<>()) + .stream(s -> s.distinct().distinct()) .exercise(); assertUnique(result); } From 540bb21731fd720c81b5bcc33201d799022dcb94 Mon Sep 17 00:00:00 2001 From: Sergey Lugovoy Date: Wed, 25 Mar 2015 14:39:39 +0300 Subject: [PATCH 127/362] 8075240: Output of some tests contains platform specific line break Reviewed-by: sundar --- nashorn/test/script/nosecurity/parserapi.js | 2 +- .../script/nosecurity/parserapi.js.EXPECTED | 636 +++++++++--------- .../test/script/nosecurity/treeapi/utils.js | 2 +- 3 files changed, 333 insertions(+), 307 deletions(-) diff --git a/nashorn/test/script/nosecurity/parserapi.js b/nashorn/test/script/nosecurity/parserapi.js index 2f5fb87b989..22b1fd2822b 100644 --- a/nashorn/test/script/nosecurity/parserapi.js +++ b/nashorn/test/script/nosecurity/parserapi.js @@ -97,7 +97,7 @@ function processFiles(subdir) { var parser = new Parser(); var tree = parser.parse(subdir + "/" + file.name, script, function(diagnostic) { - print(JSON.stringify(parser.convert(diagnostic), null, 2)); + print(JSON.stringify(parser.convert(diagnostic), null, 2).replace(/\\r/g, '')); print(","); }); diff --git a/nashorn/test/script/nosecurity/parserapi.js.EXPECTED b/nashorn/test/script/nosecurity/parserapi.js.EXPECTED index 4c4acc96c37..ebd72ba610b 100644 --- a/nashorn/test/script/nosecurity/parserapi.js.EXPECTED +++ b/nashorn/test/script/nosecurity/parserapi.js.EXPECTED @@ -1,4 +1,4 @@ -[ +[ { "endPosition": "1113", "kind": "COMPILATION_UNIT", @@ -132,8 +132,8 @@ "sourceName": "parsertests/array_literal.js", "strict": "false", "startPosition": "1113" -} -, +} +, { "endPosition": "1126", "kind": "COMPILATION_UNIT", @@ -406,8 +406,8 @@ "sourceName": "parsertests/assignmentExpr.js", "strict": "false", "startPosition": "1126" -} -, +} +, { "endPosition": "1116", "kind": "COMPILATION_UNIT", @@ -912,8 +912,8 @@ "sourceName": "parsertests/binaryExpr.js", "strict": "false", "startPosition": "1116" -} -, +} +, { "endPosition": "1117", "kind": "COMPILATION_UNIT", @@ -959,8 +959,8 @@ "sourceName": "parsertests/block.js", "strict": "false", "startPosition": "1117" -} -, +} +, { "endPosition": "1117", "kind": "COMPILATION_UNIT", @@ -1060,8 +1060,8 @@ "sourceName": "parsertests/breakStat.js", "strict": "false", "startPosition": "1117" -} -, +} +, { "endPosition": "1117", "kind": "COMPILATION_UNIT", @@ -1098,8 +1098,8 @@ "sourceName": "parsertests/condExpr.js", "strict": "false", "startPosition": "1117" -} -, +} +, { "endPosition": "1120", "kind": "COMPILATION_UNIT", @@ -1199,8 +1199,8 @@ "sourceName": "parsertests/continueStat.js", "strict": "false", "startPosition": "1120" -} -, +} +, { "endPosition": "1118", "kind": "COMPILATION_UNIT", @@ -1214,8 +1214,8 @@ "sourceName": "parsertests/debuggerStat.js", "strict": "false", "startPosition": "1118" -} -, +} +, { "endPosition": "1137", "kind": "COMPILATION_UNIT", @@ -1500,8 +1500,8 @@ "sourceName": "parsertests/functions.js", "strict": "false", "startPosition": "1137" -} -, +} +, { "endPosition": "1114", "kind": "COMPILATION_UNIT", @@ -1604,8 +1604,8 @@ "sourceName": "parsertests/ifStat.js", "strict": "false", "startPosition": "1114" -} -, +} +, { "endPosition": "1113", "kind": "COMPILATION_UNIT", @@ -1668,8 +1668,8 @@ "sourceName": "parsertests/labelledStat.js", "strict": "false", "startPosition": "1113" -} -, +} +, { "endPosition": "1125", "kind": "COMPILATION_UNIT", @@ -2066,8 +2066,8 @@ "sourceName": "parsertests/lhsExpr.js", "strict": "false", "startPosition": "1125" -} -, +} +, { "endPosition": "1110", "kind": "COMPILATION_UNIT", @@ -2350,8 +2350,8 @@ "sourceName": "parsertests/loopStat.js", "strict": "false", "startPosition": "1110" -} -, +} +, { "endPosition": "1125", "kind": "COMPILATION_UNIT", @@ -2705,8 +2705,8 @@ "sourceName": "parsertests/objectLitExpr.js", "strict": "false", "startPosition": "1125" -} -, +} +, { "endPosition": "1118", "kind": "COMPILATION_UNIT", @@ -2781,8 +2781,8 @@ "sourceName": "parsertests/parenExpr.js", "strict": "false", "startPosition": "1118" -} -, +} +, { "endPosition": "1119", "kind": "COMPILATION_UNIT", @@ -2995,8 +2995,8 @@ "sourceName": "parsertests/primaryExpr.js", "strict": "false", "startPosition": "1119" -} -, +} +, { "endPosition": "1114", "kind": "COMPILATION_UNIT", @@ -3044,8 +3044,8 @@ "sourceName": "parsertests/regexp_literal.js", "strict": "false", "startPosition": "1114" -} -, +} +, { "endPosition": "1118", "kind": "COMPILATION_UNIT", @@ -3144,8 +3144,8 @@ "sourceName": "parsertests/returnStat.js", "strict": "false", "startPosition": "1118" -} -, +} +, { "endPosition": "1111", "kind": "COMPILATION_UNIT", @@ -3309,8 +3309,8 @@ "sourceName": "parsertests/switchStat.js", "strict": "false", "startPosition": "1111" -} -, +} +, { "endPosition": "1110", "kind": "COMPILATION_UNIT", @@ -3421,8 +3421,8 @@ "sourceName": "parsertests/throwStat.js", "strict": "false", "startPosition": "1110" -} -, +} +, { "endPosition": "1121", "kind": "COMPILATION_UNIT", @@ -3783,8 +3783,8 @@ "sourceName": "parsertests/tryCatchStat.js", "strict": "false", "startPosition": "1121" -} -, +} +, { "endPosition": "1115", "kind": "COMPILATION_UNIT", @@ -3969,8 +3969,8 @@ "sourceName": "parsertests/unaryExpr.js", "strict": "false", "startPosition": "1115" -} -, +} +, { "endPosition": "1122", "kind": "COMPILATION_UNIT", @@ -4016,8 +4016,8 @@ "sourceName": "parsertests/useStrict.js", "strict": "true", "startPosition": "1122" -} -, +} +, { "endPosition": "1143", "kind": "COMPILATION_UNIT", @@ -4092,8 +4092,8 @@ "sourceName": "parsertests/varDecl.js", "strict": "false", "startPosition": "1143" -} -, +} +, { "endPosition": "1111", "kind": "COMPILATION_UNIT", @@ -4142,8 +4142,8 @@ "sourceName": "parsertests/withStat.js", "strict": "false", "startPosition": "1111" -} -, +} +, { "fileName": "parsernegativetests/caseoutofswitch.js", "code": "case (1090, 4)", @@ -4152,8 +4152,8 @@ "position": "1090", "message": "parsernegativetests/caseoutofswitch.js:29:0 Expected an operand but found case\ncase 23:\n^", "lineNumber": "29" -} -, +} +, { "fileName": "parsernegativetests/caseoutofswitch.js", "code": "default (1112, 7)", @@ -4162,8 +4162,8 @@ "position": "1112", "message": "parsernegativetests/caseoutofswitch.js:31:0 Expected an operand but found default\ndefault:\n^", "lineNumber": "31" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4240,8 +4240,8 @@ "sourceName": "parsernegativetests/caseoutofswitch.js", "strict": "false", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/illegalbreak.js", "code": "break (1090, 5)", @@ -4250,8 +4250,8 @@ "position": "1090", "message": "parsernegativetests/illegalbreak.js:29:0 Illegal break statement\nbreak;\n^", "lineNumber": "29" -} -, +} +, { "fileName": "parsernegativetests/illegalbreak.js", "code": "ident (1103, 3)", @@ -4260,8 +4260,8 @@ "position": "1103", "message": "parsernegativetests/illegalbreak.js:30:6 Undefined Label \"foo\"\nbreak foo;\n ^", "lineNumber": "30" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4290,8 +4290,8 @@ "sourceName": "parsernegativetests/illegalbreak.js", "strict": "false", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/illegalcontinue.js", "code": "continue (1090, 8)", @@ -4300,8 +4300,8 @@ "position": "1090", "message": "parsernegativetests/illegalcontinue.js:29:0 Illegal continue statement\ncontinue;\n^", "lineNumber": "29" -} -, +} +, { "fileName": "parsernegativetests/illegalcontinue.js", "code": "ident (1109, 3)", @@ -4310,8 +4310,8 @@ "position": "1109", "message": "parsernegativetests/illegalcontinue.js:30:9 Undefined Label \"foo\"\ncontinue foo;\n ^", "lineNumber": "30" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4340,8 +4340,8 @@ "sourceName": "parsernegativetests/illegalcontinue.js", "strict": "false", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/illegallvalue.js", "code": "decimal (1090, 2)", @@ -4350,8 +4350,8 @@ "position": "1090", "message": "parsernegativetests/illegallvalue.js:29:0 Invalid left hand side for assignment\n44 = 54;\n^", "lineNumber": "29" -} -, +} +, { "fileName": "parsernegativetests/illegallvalue.js", "code": "decimal (1099, 3)", @@ -4360,8 +4360,8 @@ "position": "1099", "message": "parsernegativetests/illegallvalue.js:30:0 Invalid left hand side for assignment\n233 += 33;\n^", "lineNumber": "30" -} -, +} +, { "fileName": "parsernegativetests/illegallvalue.js", "code": "decimal (1110, 4)", @@ -4370,8 +4370,8 @@ "position": "1110", "message": "parsernegativetests/illegallvalue.js:31:0 Invalid left hand side for assignment\n3423 -= 234;\n^", "lineNumber": "31" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4410,8 +4410,8 @@ "sourceName": "parsernegativetests/illegallvalue.js", "strict": "false", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/illegaloperator.js", "code": "* (1093, 1)", @@ -4420,8 +4420,8 @@ "position": "1093", "message": "parsernegativetests/illegaloperator.js:29:3 Expected an operand but found *\nx ** y\n ^", "lineNumber": "29" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4440,8 +4440,8 @@ "sourceName": "parsernegativetests/illegaloperator.js", "strict": "false", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/keywordident.js", "code": "var (1094, 3)", @@ -4450,8 +4450,8 @@ "position": "1094", "message": "parsernegativetests/keywordident.js:29:4 Expected ident but found var\nvar var = 23;\n ^", "lineNumber": "29" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4482,8 +4482,8 @@ "sourceName": "parsernegativetests/keywordident.js", "strict": "false", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/parenmissing.js", "code": "; (1096, 1)", @@ -4492,8 +4492,8 @@ "position": "1096", "message": "parsernegativetests/parenmissing.js:29:6 Expected ) but found ;\n(1 + 2;\n ^", "lineNumber": "29" -} -, +} +, { "fileName": "parsernegativetests/parenmissing.js", "code": ") (1103, 1)", @@ -4502,8 +4502,8 @@ "position": "1103", "message": "parsernegativetests/parenmissing.js:30:5 Expected ; but found )\nx * y);\n ^", "lineNumber": "30" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4554,8 +4554,8 @@ "sourceName": "parsernegativetests/parenmissing.js", "strict": "false", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/repeatedproperty.js", "code": "ident (1111, 3)", @@ -4564,8 +4564,8 @@ "position": "1111", "message": "parsernegativetests/repeatedproperty.js:29:21 Property \"foo\" already defined\nvar obj = { foo: 34, get foo() { return 'hello' } };\n ^", "lineNumber": "29" -} -, +} +, { "fileName": "parsernegativetests/repeatedproperty.js", "code": "ident (1165, 3)", @@ -4574,8 +4574,8 @@ "position": "1165", "message": "parsernegativetests/repeatedproperty.js:30:22 Property \"foo\" already defined\nvar obj1 = { foo: 34, set foo(x) { } };\n ^", "lineNumber": "30" -} -, +} +, { "fileName": "parsernegativetests/repeatedproperty.js", "code": "ident (1205, 3)", @@ -4584,8 +4584,8 @@ "position": "1205", "message": "parsernegativetests/repeatedproperty.js:31:22 Property \"foo\" already defined\nvar obj2 = { foo: 34, set foo(x) { } };\n ^", "lineNumber": "31" -} -, +} +, { "fileName": "parsernegativetests/repeatedproperty.js", "code": "ident (1251, 3)", @@ -4594,8 +4594,8 @@ "position": "1251", "message": "parsernegativetests/repeatedproperty.js:32:28 Property \"bar\" already defined\nvar obj3 = { get bar() { }, get bar() {} };\n ^", "lineNumber": "32" -} -, +} +, { "fileName": "parsernegativetests/repeatedproperty.js", "code": "ident (1296, 3)", @@ -4604,8 +4604,8 @@ "position": "1296", "message": "parsernegativetests/repeatedproperty.js:33:29 Property \"bar\" already defined\nvar obj4 = { set bar(x) { }, set bar(x) {} };\n ^", "lineNumber": "33" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4664,8 +4664,8 @@ "sourceName": "parsernegativetests/repeatedproperty.js", "strict": "false", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/strict_repeatedproperty.js", "code": "ident (1126, 3)", @@ -4674,8 +4674,8 @@ "position": "1126", "message": "parsernegativetests/strict_repeatedproperty.js:31:21 Property \"foo\" already defined\nvar obj = { foo: 34, foo: 'hello' };\n ^", "lineNumber": "31" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4705,8 +4705,8 @@ "sourceName": "parsernegativetests/strict_repeatedproperty.js", "strict": "true", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/strict_repeatparam.js", "code": "ident (1119, 1)", @@ -4715,8 +4715,8 @@ "position": "1119", "message": "parsernegativetests/strict_repeatparam.js:31:14 strict mode function cannot have duplicate parameter name \"x\"\nfunction func(x, x) {}\n ^", "lineNumber": "31" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4746,8 +4746,8 @@ "sourceName": "parsernegativetests/strict_repeatparam.js", "strict": "true", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/strict_with.js", "code": "with (1105, 4)", @@ -4756,8 +4756,8 @@ "position": "1105", "message": "parsernegativetests/strict_with.js:31:0 \"with\" statement cannot be used in strict mode\nwith({}) {}\n^", "lineNumber": "31" -} -, +} +, { "fileName": "parsernegativetests/strict_with.js", "code": ") (1112, 1)", @@ -4766,8 +4766,8 @@ "position": "1112", "message": "parsernegativetests/strict_with.js:31:7 Expected ; but found )\nwith({}) {}\n ^", "lineNumber": "31" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4807,8 +4807,8 @@ "sourceName": "parsernegativetests/strict_with.js", "strict": "true", "startPosition": "1090" -} -, +} +, { "fileName": "parsernegativetests/toplevelreturn.js", "code": "return (1090, 6)", @@ -4817,8 +4817,8 @@ "position": "1090", "message": "parsernegativetests/toplevelreturn.js:29:0 Invalid return statement\nreturn;\n^", "lineNumber": "29" -} -, +} +, { "fileName": "parsernegativetests/toplevelreturn.js", "code": "return (1098, 6)", @@ -4827,8 +4827,8 @@ "position": "1098", "message": "parsernegativetests/toplevelreturn.js:30:0 Invalid return statement\nreturn 23;\n^", "lineNumber": "30" -} -, +} +, { "endPosition": "1090", "kind": "COMPILATION_UNIT", @@ -4857,8 +4857,8 @@ "sourceName": "parsernegativetests/toplevelreturn.js", "strict": "false", "startPosition": "1090" -} -, +} +, { "endPosition": "1136", "kind": "COMPILATION_UNIT", @@ -6189,11 +6189,11 @@ "startPosition": "1972" }, { - "endPosition": "3598", + "endPosition": "3618", "kind": "FUNCTION", "name": "processFiles", "body": { - "endPosition": "3555", + "endPosition": "3575", "kind": "BLOCK", "statements": [ { @@ -6335,7 +6335,7 @@ "name": "files", "startPosition": "3053" }, - "endPosition": "3555", + "endPosition": "3575", "kind": "FOR_IN_LOOP", "forEach": "true", "variable": { @@ -6345,7 +6345,7 @@ "startPosition": "3045" }, "statement": { - "endPosition": "3555", + "endPosition": "3575", "kind": "BLOCK", "statements": [ { @@ -6380,11 +6380,11 @@ ], "startPosition": "3073" }, - "endPosition": "3550", + "endPosition": "3570", "kind": "IF", "startPosition": "3069", "thenStatement": { - "endPosition": "3550", + "endPosition": "3570", "kind": "BLOCK", "statements": [ { @@ -6436,12 +6436,12 @@ } }, { - "endPosition": "3415", + "endPosition": "3435", "kind": "VARIABLE", "name": "tree", "startPosition": "3196", "initializer": { - "endPosition": "3415", + "endPosition": "3435", "kind": "FUNCTION_INVOCATION", "functionSelect": { "identifier": "parse", @@ -6500,12 +6500,12 @@ "endPosition": "3286", "kind": "FUNCTION_EXPRESSION", "body": { - "endPosition": "3397", + "endPosition": "3417", "kind": "BLOCK", "statements": [ { "expression": { - "endPosition": "3365", + "endPosition": "3385", "kind": "FUNCTION_INVOCATION", "functionSelect": { "endPosition": "3312", @@ -6515,90 +6515,116 @@ }, "arguments": [ { - "endPosition": "3364", + "endPosition": "3384", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "identifier": "stringify", + "identifier": "replace", "expression": { - "endPosition": "3317", - "kind": "IDENTIFIER", - "name": "JSON", + "endPosition": "3364", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "stringify", + "expression": { + "endPosition": "3317", + "kind": "IDENTIFIER", + "name": "JSON", + "startPosition": "3313" + }, + "endPosition": "3327", + "kind": "MEMBER_SELECT", + "startPosition": "3313" + }, + "arguments": [ + { + "endPosition": "3354", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "convert", + "expression": { + "endPosition": "3334", + "kind": "IDENTIFIER", + "name": "parser", + "startPosition": "3328" + }, + "endPosition": "3342", + "kind": "MEMBER_SELECT", + "startPosition": "3328" + }, + "arguments": [ + { + "endPosition": "3353", + "kind": "IDENTIFIER", + "name": "diagnostic", + "startPosition": "3343" + } + ], + "startPosition": "3328" + }, + { + "endPosition": "3360", + "kind": "NULL_LITERAL", + "startPosition": "3356" + }, + { + "endPosition": "3363", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "3362" + } + ], "startPosition": "3313" }, - "endPosition": "3327", + "endPosition": "3372", "kind": "MEMBER_SELECT", "startPosition": "3313" }, "arguments": [ { - "endPosition": "3354", - "kind": "FUNCTION_INVOCATION", - "functionSelect": { - "identifier": "convert", - "expression": { - "endPosition": "3334", - "kind": "IDENTIFIER", - "name": "parser", - "startPosition": "3328" - }, - "endPosition": "3342", - "kind": "MEMBER_SELECT", - "startPosition": "3328" - }, - "arguments": [ - { - "endPosition": "3353", - "kind": "IDENTIFIER", - "name": "diagnostic", - "startPosition": "3343" - } - ], - "startPosition": "3328" + "endPosition": "3379", + "kind": "REGEXP_LITERAL", + "options": "g", + "pattern": "\\\\r", + "startPosition": "3373" }, { - "endPosition": "3360", - "kind": "NULL_LITERAL", - "startPosition": "3356" - }, - { - "endPosition": "3363", - "kind": "NUMBER_LITERAL", - "value": "2", - "startPosition": "3362" + "endPosition": "3382", + "kind": "STRING_LITERAL", + "value": "", + "startPosition": "3382" } ], - "startPosition": "3313" + "startPosition": "3372" } ], "startPosition": "3307" }, - "endPosition": "3365", + "endPosition": "3385", "kind": "EXPRESSION_STATEMENT", "startPosition": "3307" }, { "expression": { - "endPosition": "3396", + "endPosition": "3416", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3391", + "endPosition": "3411", "kind": "IDENTIFIER", "name": "print", - "startPosition": "3386" + "startPosition": "3406" }, "arguments": [ { - "endPosition": "3394", + "endPosition": "3414", "kind": "STRING_LITERAL", "value": ",", - "startPosition": "3393" + "startPosition": "3413" } ], - "startPosition": "3386" + "startPosition": "3406" }, - "endPosition": "3396", + "endPosition": "3416", "kind": "EXPRESSION_STATEMENT", - "startPosition": "3386" + "startPosition": "3406" } ], "startPosition": "3286" @@ -6621,107 +6647,107 @@ { "condition": { "leftOperand": { - "endPosition": "3437", + "endPosition": "3457", "kind": "IDENTIFIER", "name": "tree", - "startPosition": "3433" + "startPosition": "3453" }, - "endPosition": "3445", + "endPosition": "3465", "kind": "NOT_EQUAL_TO", "rightOperand": { - "endPosition": "3445", + "endPosition": "3465", "kind": "NULL_LITERAL", - "startPosition": "3441" + "startPosition": "3461" }, - "startPosition": "3433" + "startPosition": "3453" }, - "endPosition": "3541", + "endPosition": "3561", "kind": "IF", - "startPosition": "3429", + "startPosition": "3449", "thenStatement": { - "endPosition": "3541", + "endPosition": "3561", "kind": "BLOCK", "statements": [ { "expression": { - "endPosition": "3500", + "endPosition": "3520", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3469", + "endPosition": "3489", "kind": "IDENTIFIER", "name": "print", - "startPosition": "3464" + "startPosition": "3484" }, "arguments": [ { - "endPosition": "3499", + "endPosition": "3519", "kind": "FUNCTION_INVOCATION", "functionSelect": { "identifier": "stringify", "expression": { - "endPosition": "3474", + "endPosition": "3494", "kind": "IDENTIFIER", "name": "JSON", - "startPosition": "3470" + "startPosition": "3490" }, - "endPosition": "3484", + "endPosition": "3504", "kind": "MEMBER_SELECT", - "startPosition": "3470" + "startPosition": "3490" }, "arguments": [ { - "endPosition": "3489", + "endPosition": "3509", "kind": "IDENTIFIER", "name": "tree", - "startPosition": "3485" + "startPosition": "3505" }, { - "endPosition": "3495", + "endPosition": "3515", "kind": "NULL_LITERAL", - "startPosition": "3491" + "startPosition": "3511" }, { - "endPosition": "3498", + "endPosition": "3518", "kind": "NUMBER_LITERAL", "value": "2", - "startPosition": "3497" + "startPosition": "3517" } ], - "startPosition": "3470" + "startPosition": "3490" } ], - "startPosition": "3464" + "startPosition": "3484" }, - "endPosition": "3500", + "endPosition": "3520", "kind": "EXPRESSION_STATEMENT", - "startPosition": "3464" + "startPosition": "3484" }, { "expression": { - "endPosition": "3527", + "endPosition": "3547", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3522", + "endPosition": "3542", "kind": "IDENTIFIER", "name": "print", - "startPosition": "3517" + "startPosition": "3537" }, "arguments": [ { - "endPosition": "3525", + "endPosition": "3545", "kind": "STRING_LITERAL", "value": ",", - "startPosition": "3524" + "startPosition": "3544" } ], - "startPosition": "3517" + "startPosition": "3537" }, - "endPosition": "3527", + "endPosition": "3547", "kind": "EXPRESSION_STATEMENT", - "startPosition": "3517" + "startPosition": "3537" } ], - "startPosition": "3447" + "startPosition": "3467" } } ], @@ -6748,268 +6774,268 @@ ] }, { - "endPosition": "3901", + "endPosition": "3921", "kind": "FUNCTION", "name": "main", "body": { - "endPosition": "3899", + "endPosition": "3919", "kind": "BLOCK", "statements": [ { "expression": { - "endPosition": "3631", + "endPosition": "3651", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3626", + "endPosition": "3646", "kind": "IDENTIFIER", "name": "print", - "startPosition": "3621" + "startPosition": "3641" }, "arguments": [ { - "endPosition": "3629", + "endPosition": "3649", "kind": "STRING_LITERAL", "value": "[", - "startPosition": "3628" + "startPosition": "3648" } ], - "startPosition": "3621" + "startPosition": "3641" }, - "endPosition": "3631", + "endPosition": "3651", "kind": "EXPRESSION_STATEMENT", - "startPosition": "3621" + "startPosition": "3641" }, { "expression": { - "endPosition": "3665", + "endPosition": "3685", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3650", + "endPosition": "3670", "kind": "IDENTIFIER", "name": "processFiles", - "startPosition": "3638" + "startPosition": "3658" }, "arguments": [ { - "endPosition": "3663", + "endPosition": "3683", "kind": "STRING_LITERAL", "value": "parsertests", - "startPosition": "3652" + "startPosition": "3672" } ], - "startPosition": "3638" + "startPosition": "3658" }, - "endPosition": "3665", + "endPosition": "3685", "kind": "EXPRESSION_STATEMENT", - "startPosition": "3638" + "startPosition": "3658" }, { "expression": { - "endPosition": "3706", + "endPosition": "3726", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3683", + "endPosition": "3703", "kind": "IDENTIFIER", "name": "processFiles", - "startPosition": "3671" + "startPosition": "3691" }, "arguments": [ { - "endPosition": "3704", + "endPosition": "3724", "kind": "STRING_LITERAL", "value": "parsernegativetests", - "startPosition": "3685" + "startPosition": "3705" } ], - "startPosition": "3671" + "startPosition": "3691" }, - "endPosition": "3706", + "endPosition": "3726", "kind": "EXPRESSION_STATEMENT", - "startPosition": "3671" + "startPosition": "3691" }, { - "endPosition": "3775", + "endPosition": "3795", "kind": "VARIABLE", "name": "script", - "startPosition": "3747", + "startPosition": "3767", "initializer": { - "endPosition": "3775", + "endPosition": "3795", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3765", + "endPosition": "3785", "kind": "IDENTIFIER", "name": "readFully", - "startPosition": "3756" + "startPosition": "3776" }, "arguments": [ { - "endPosition": "3774", + "endPosition": "3794", "kind": "IDENTIFIER", "name": "__FILE__", - "startPosition": "3766" + "startPosition": "3786" } ], - "startPosition": "3756" + "startPosition": "3776" } }, { - "endPosition": "3840", + "endPosition": "3860", "kind": "VARIABLE", "name": "tree", - "startPosition": "3785", + "startPosition": "3805", "initializer": { - "endPosition": "3840", + "endPosition": "3860", "kind": "FUNCTION_INVOCATION", "functionSelect": { "identifier": "parse", "expression": { "constructorExpression": { - "endPosition": "3804", + "endPosition": "3824", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3802", + "endPosition": "3822", "kind": "IDENTIFIER", "name": "Parser", - "startPosition": "3796" + "startPosition": "3816" }, "arguments": [], - "startPosition": "3796" + "startPosition": "3816" }, - "endPosition": "3804", + "endPosition": "3824", "kind": "NEW", - "startPosition": "3792" + "startPosition": "3812" }, - "endPosition": "3810", + "endPosition": "3830", "kind": "MEMBER_SELECT", - "startPosition": "3792" + "startPosition": "3812" }, "arguments": [ { - "endPosition": "3824", + "endPosition": "3844", "kind": "STRING_LITERAL", "value": "parserapi.js", - "startPosition": "3812" + "startPosition": "3832" }, { - "endPosition": "3833", + "endPosition": "3853", "kind": "IDENTIFIER", "name": "script", - "startPosition": "3827" + "startPosition": "3847" }, { - "endPosition": "3839", + "endPosition": "3859", "kind": "NULL_LITERAL", - "startPosition": "3835" + "startPosition": "3855" } ], - "startPosition": "3792" + "startPosition": "3812" } }, { "expression": { - "endPosition": "3882", + "endPosition": "3902", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3851", + "endPosition": "3871", "kind": "IDENTIFIER", "name": "print", - "startPosition": "3846" + "startPosition": "3866" }, "arguments": [ { - "endPosition": "3881", + "endPosition": "3901", "kind": "FUNCTION_INVOCATION", "functionSelect": { "identifier": "stringify", "expression": { - "endPosition": "3856", + "endPosition": "3876", "kind": "IDENTIFIER", "name": "JSON", - "startPosition": "3852" + "startPosition": "3872" }, - "endPosition": "3866", + "endPosition": "3886", "kind": "MEMBER_SELECT", - "startPosition": "3852" + "startPosition": "3872" }, "arguments": [ { - "endPosition": "3871", + "endPosition": "3891", "kind": "IDENTIFIER", "name": "tree", - "startPosition": "3867" + "startPosition": "3887" }, { - "endPosition": "3877", + "endPosition": "3897", "kind": "NULL_LITERAL", - "startPosition": "3873" + "startPosition": "3893" }, { - "endPosition": "3880", + "endPosition": "3900", "kind": "NUMBER_LITERAL", "value": "2", - "startPosition": "3879" + "startPosition": "3899" } ], - "startPosition": "3852" + "startPosition": "3872" } ], - "startPosition": "3846" + "startPosition": "3866" }, - "endPosition": "3882", + "endPosition": "3902", "kind": "EXPRESSION_STATEMENT", - "startPosition": "3846" + "startPosition": "3866" }, { "expression": { - "endPosition": "3898", + "endPosition": "3918", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3893", + "endPosition": "3913", "kind": "IDENTIFIER", "name": "print", - "startPosition": "3888" + "startPosition": "3908" }, "arguments": [ { - "endPosition": "3896", + "endPosition": "3916", "kind": "STRING_LITERAL", "value": "]", - "startPosition": "3895" + "startPosition": "3915" } ], - "startPosition": "3888" + "startPosition": "3908" }, - "endPosition": "3898", + "endPosition": "3918", "kind": "EXPRESSION_STATEMENT", - "startPosition": "3888" + "startPosition": "3908" } ], - "startPosition": "3615" + "startPosition": "3635" }, "strict": "false", - "startPosition": "3599", + "startPosition": "3619", "parameters": [] }, { "expression": { - "endPosition": "3909", + "endPosition": "3929", "kind": "FUNCTION_INVOCATION", "functionSelect": { - "endPosition": "3907", + "endPosition": "3927", "kind": "IDENTIFIER", "name": "main", - "startPosition": "3903" + "startPosition": "3923" }, "arguments": [], - "startPosition": "3903" + "startPosition": "3923" }, - "endPosition": "3909", + "endPosition": "3929", "kind": "EXPRESSION_STATEMENT", - "startPosition": "3903" + "startPosition": "3923" } ], "sourceName": "parserapi.js", "strict": "false", "startPosition": "1136" -} -] +} +] diff --git a/nashorn/test/script/nosecurity/treeapi/utils.js b/nashorn/test/script/nosecurity/treeapi/utils.js index 1d73f5a9ff3..9d57485d27d 100644 --- a/nashorn/test/script/nosecurity/treeapi/utils.js +++ b/nashorn/test/script/nosecurity/treeapi/utils.js @@ -78,5 +78,5 @@ function parseDiagnostic (code, args) { var tree = parser.create(args).parse("test.js", code, function (message) { messages.push(convert(message)) }) - print(JSON.stringify(messages, null, 2)) + print(JSON.stringify(messages, null, 2).replace(/\\r/g, '')) } \ No newline at end of file From a76b85f2bbd5c00a3771549483e5a28efe02902d Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Wed, 25 Mar 2015 16:31:05 +0400 Subject: [PATCH 128/362] 8033000: No Horizontal Mouse Wheel Support In Reviewed-by: serb, azvegint --- .../com/apple/laf/AquaScrollPaneUI.java | 22 +-- .../swing/plaf/basic/BasicScrollPaneUI.java | 6 + .../swing/JScrollPane/8033000/bug8033000.java | 162 ++++++++++++++++++ 3 files changed, 170 insertions(+), 20 deletions(-) create mode 100644 jdk/test/javax/swing/JScrollPane/8033000/bug8033000.java diff --git a/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaScrollPaneUI.java b/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaScrollPaneUI.java index ee0bf7cdf54..0729321552d 100644 --- a/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaScrollPaneUI.java +++ b/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaScrollPaneUI.java @@ -29,6 +29,7 @@ import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicScrollPaneUI; public class AquaScrollPaneUI extends javax.swing.plaf.basic.BasicScrollPaneUI { public static ComponentUI createUI(final JComponent x) { @@ -39,28 +40,9 @@ public class AquaScrollPaneUI extends javax.swing.plaf.basic.BasicScrollPaneUI { return new XYMouseWheelHandler(); } - // This is a grody hack to trick BasicScrollPaneUI into scrolling horizontally - // when we notice that the shift key is down. This should be removed when AWT/Swing - // becomes aware of multi-axis scroll wheels. - protected class XYMouseWheelHandler extends javax.swing.plaf.basic.BasicScrollPaneUI.MouseWheelHandler { + protected class XYMouseWheelHandler extends BasicScrollPaneUI.MouseWheelHandler { public void mouseWheelMoved(final MouseWheelEvent e) { - JScrollBar vScrollBar = null; - boolean wasVisible = false; - - if (e.isShiftDown()) { - vScrollBar = scrollpane.getVerticalScrollBar(); - if (vScrollBar != null) { - wasVisible = vScrollBar.isVisible(); - vScrollBar.setVisible(false); - } - } - super.mouseWheelMoved(e); - - if (wasVisible) { - vScrollBar.setVisible(true); - } - // Consume the event even when the scrollBar is invisible // see #7124320 e.consume(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java index 18df8abf202..c34104bf884 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java @@ -962,6 +962,12 @@ public class BasicScrollPaneUI return; } orientation = SwingConstants.HORIZONTAL; + } else if(e.isShiftDown()){ + JScrollBar hScroll = scrollpane.getHorizontalScrollBar(); + if (hScroll != null && hScroll.isVisible()) { + toScroll = hScroll; + orientation = SwingConstants.HORIZONTAL; + } } e.consume(); diff --git a/jdk/test/javax/swing/JScrollPane/8033000/bug8033000.java b/jdk/test/javax/swing/JScrollPane/8033000/bug8033000.java new file mode 100644 index 00000000000..4e5d23149ab --- /dev/null +++ b/jdk/test/javax/swing/JScrollPane/8033000/bug8033000.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ +import java.awt.BorderLayout; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.KeyEvent; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import jdk.testlibrary.OSInfo; + +/** + * @test + * @bug 8033000 + * @author Alexander Scherbatiy + * @summary No Horizontal Mouse Wheel Support In BasicScrollPaneUI + * @library ../../../../lib/testlibrary + * @build jdk.testlibrary.OSInfo + * @run main bug8033000 + */ +public class bug8033000 { + + private static JScrollPane scrollPane; + private static JTextArea textArea; + private static Point point; + private static final int delta; + + static { + delta = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ? -30 : 30; + } + + public static void main(String[] args) throws Exception { + + Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(bug8033000::createAndShowGUI); + robot.waitForIdle(); + + SwingUtilities.invokeAndWait(() -> { + Point locationOnScreen = scrollPane.getLocationOnScreen(); + point = new Point( + locationOnScreen.x + scrollPane.getWidth() / 2, + locationOnScreen.y + scrollPane.getHeight() / 2); + }); + + robot.mouseMove(point.x, point.y); + robot.waitForIdle(); + + // vertical scroll bar is enabled + initScrollPane(true, false); + robot.waitForIdle(); + robot.mouseWheel(delta); + robot.waitForIdle(); + checkScrollPane(true); + + // vertical scroll bar is enabled + shift + initScrollPane(true, false); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_SHIFT); + robot.mouseWheel(delta); + robot.keyRelease(KeyEvent.VK_SHIFT); + robot.waitForIdle(); + checkScrollPane(true); + + // horizontal scroll bar is enabled + initScrollPane(false, true); + robot.waitForIdle(); + robot.mouseWheel(delta); + robot.waitForIdle(); + checkScrollPane(false); + + // horizontal scroll bar is enabled + shift + initScrollPane(false, true); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_SHIFT); + robot.mouseWheel(delta); + robot.keyRelease(KeyEvent.VK_SHIFT); + robot.waitForIdle(); + checkScrollPane(false); + + // both scroll bars are enabled + initScrollPane(true, true); + robot.waitForIdle(); + robot.mouseWheel(delta); + robot.waitForIdle(); + checkScrollPane(true); + + // both scroll bars are enabled + shift + initScrollPane(true, true); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_SHIFT); + robot.mouseWheel(delta); + robot.keyRelease(KeyEvent.VK_SHIFT); + robot.waitForIdle(); + checkScrollPane(false); + } + + static void initScrollPane(boolean vVisible, boolean hVisible) throws Exception { + SwingUtilities.invokeAndWait(() -> { + scrollPane.getVerticalScrollBar().setValue(0); + scrollPane.getHorizontalScrollBar().setValue(0); + + textArea.setRows(vVisible ? 100 : 1); + textArea.setColumns(hVisible ? 100 : 1); + scrollPane.getVerticalScrollBar().setVisible(vVisible); + scrollPane.getHorizontalScrollBar().setVisible(hVisible); + }); + } + + static void checkScrollPane(boolean verticalScrolled) throws Exception { + SwingUtilities.invokeAndWait(() -> { + + if (verticalScrolled) { + if (scrollPane.getVerticalScrollBar().getValue() == 0 + || scrollPane.getHorizontalScrollBar().getValue() != 0) { + throw new RuntimeException("Wrong vertical scrolling!"); + } + } else { + if (scrollPane.getVerticalScrollBar().getValue() != 0 + || scrollPane.getHorizontalScrollBar().getValue() == 0) { + throw new RuntimeException("Wrong horizontal scrolling!"); + } + } + }); + } + + static void createAndShowGUI() { + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(300, 300); + textArea = new JTextArea("Hello World!"); + scrollPane = new JScrollPane(textArea); + JPanel panel = new JPanel(new BorderLayout()); + panel.add(scrollPane, BorderLayout.CENTER); + frame.getContentPane().add(panel); + frame.setVisible(true); + } +} From 268d8ef7a6b94a4e23c23ce51ee0f45e0c596b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Wed, 25 Mar 2015 14:41:47 +0100 Subject: [PATCH 129/362] 8075927: toNumber(String) accepts illegal characters Reviewed-by: attila, sundar --- .../jdk/nashorn/internal/runtime/JSType.java | 12 ++++-- nashorn/test/script/basic/JDK-8075927.js | 38 +++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 nashorn/test/script/basic/JDK-8075927.js diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java index 1f9d9a205e0..c7eae4f5c30 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java @@ -933,11 +933,15 @@ public enum JSType { if (start + 1 < end && f == '0' && Character.toLowerCase(str.charAt(start + 1)) == 'x') { //decode hex string value = parseRadix(str.toCharArray(), start + 2, end, 16); + } else if (f == 'I' && end - start == 8 && str.regionMatches(start, "Infinity", 0, 8)) { + return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else { - // Fast (no NumberFormatException) path to NaN for non-numeric strings. We allow those starting with "I" or - // "N" to allow for parsing "NaN" and "Infinity" correctly. - if ((f < '0' || f > '9') && f != '.' && f != 'I' && f != 'N') { - return Double.NaN; + // Fast (no NumberFormatException) path to NaN for non-numeric strings. + for (int i = start; i < end; i++) { + f = str.charAt(i); + if ((f < '0' || f > '9') && f != '.' && f != 'e' && f != 'E' && f != '+' && f != '-') { + return Double.NaN; + } } try { value = Double.parseDouble(str.substring(start, end)); diff --git a/nashorn/test/script/basic/JDK-8075927.js b/nashorn/test/script/basic/JDK-8075927.js new file mode 100644 index 00000000000..e596fb0a118 --- /dev/null +++ b/nashorn/test/script/basic/JDK-8075927.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2014, 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. + * + * 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. + */ + +/** + * JDK-8075927: toNumber(String) accepts illegal characters + * + * @test + * @run + */ + +Assert.assertTrue(isNaN(Number("-123d"))); +Assert.assertTrue(isNaN(Number("-123f"))); +Assert.assertTrue(Number(" 123 ") === 123); +Assert.assertTrue(Number(" -123 ") === -123); +Assert.assertEquals(Number(" Infinity "), Infinity); +Assert.assertEquals(Number(" +Infinity "), Infinity); +Assert.assertEquals(Number(" -Infinity "), -Infinity); + From 9454c8c825ea06d0d093fe8c750372eab161c50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Wed, 25 Mar 2015 17:43:55 +0100 Subject: [PATCH 130/362] 8073868: Regex matching causes java.lang.ArrayIndexOutOfBoundsException: 64 Reviewed-by: attila, lagergren --- .../runtime/regexp/joni/ArrayCompiler.java | 3 - .../runtime/regexp/joni/ByteCodeMachine.java | 24 ---- .../runtime/regexp/joni/StackMachine.java | 114 +----------------- .../regexp/joni/constants/TargetInfo.java | 1 - nashorn/test/script/basic/JDK-8073868.js | 45 +++++++ 5 files changed, 47 insertions(+), 140 deletions(-) create mode 100644 nashorn/test/script/basic/JDK-8073868.js diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/ArrayCompiler.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/ArrayCompiler.java index 0e789333bb7..b343d775297 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/ArrayCompiler.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/ArrayCompiler.java @@ -145,9 +145,6 @@ final class ArrayCompiler extends Compiler { case TargetInfo.IS_EMPTY_MEM: addOpcode(OPCode.NULL_CHECK_END_MEMST); break; - case TargetInfo.IS_EMPTY_REC: - addOpcode(OPCode.NULL_CHECK_END_MEMST_PUSH); - break; default: break; } // switch diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java index 30cfe907af5..dbed5d18285 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java @@ -183,7 +183,6 @@ class ByteCodeMachine extends StackMachine { case OPCode.NULL_CHECK_START: opNullCheckStart(); continue; case OPCode.NULL_CHECK_END: opNullCheckEnd(); continue; case OPCode.NULL_CHECK_END_MEMST: opNullCheckEndMemST(); continue; - case OPCode.NULL_CHECK_END_MEMST_PUSH: opNullCheckEndMemSTPush(); continue; case OPCode.JUMP: opJump(); continue; case OPCode.PUSH: opPush(); continue; @@ -1025,29 +1024,6 @@ class ByteCodeMachine extends StackMachine { } } - // USE_SUBEXP_CALL - private void opNullCheckEndMemSTPush() { - final int mem = code[ip++]; /* mem: null check id */ - - int isNull; - if (Config.USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT) { - isNull = nullCheckMemStRec(mem, s); - } else { - isNull = nullCheckRec(mem, s); - } - - if (isNull != 0) { - if (Config.DEBUG_MATCH) { - Config.log.println("NULL_CHECK_END_MEMST_PUSH: skip id:" + mem + ", s:" + s); - } - - if (isNull == -1) {opFail(); return;} - nullCheckFound(); - } else { - pushNullCheckEnd(mem); - } - } - private void opJump() { ip += code[ip] + 1; } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/StackMachine.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/StackMachine.java index fc498c454e8..4cc33baf9bc 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/StackMachine.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/StackMachine.java @@ -19,7 +19,6 @@ */ package jdk.nashorn.internal.runtime.regexp.joni; -import static jdk.nashorn.internal.runtime.regexp.joni.BitStatus.bsAt; import java.lang.ref.WeakReference; import jdk.nashorn.internal.runtime.regexp.joni.constants.StackPopLevel; import jdk.nashorn.internal.runtime.regexp.joni.constants.StackType; @@ -369,118 +368,9 @@ abstract class StackMachine extends Matcher implements StackType { } } - protected final int nullCheckRec(final int id, final int s) { - int level = 0; - int k = stk; - while (true) { - k--; - final StackEntry e = stack[k]; - - if (e.type == NULL_CHECK_START) { - if (e.getNullCheckNum() == id) { - if (level == 0) { - return e.getNullCheckPStr() == s ? 1 : 0; - } - level--; - } - } else if (e.type == NULL_CHECK_END) { - level++; - } - } - } - protected final int nullCheckMemSt(final int id, final int s) { - int k = stk; - int isNull; - while (true) { - k--; - StackEntry e = stack[k]; - - if (e.type == NULL_CHECK_START) { - if (e.getNullCheckNum() == id) { - if (e.getNullCheckPStr() != s) { - isNull = 0; - break; - } - int endp; - isNull = 1; - while (k < stk) { - if (e.type == MEM_START) { - if (e.getMemEnd() == INVALID_INDEX) { - isNull = 0; - break; - } - if (bsAt(regex.btMemEnd, e.getMemNum())) { - endp = stack[e.getMemEnd()].getMemPStr(); - } else { - endp = e.getMemEnd(); - } - if (stack[e.getMemStart()].getMemPStr() != endp) { - isNull = 0; - break; - } else if (endp != s) { - isNull = -1; /* empty, but position changed */ - } - } - k++; - e = stack[k]; // !! - } - break; - } - } - } - return isNull; - } - - protected final int nullCheckMemStRec(final int id, final int s) { - int level = 0; - int k = stk; - int isNull; - while (true) { - k--; - StackEntry e = stack[k]; - - if (e.type == NULL_CHECK_START) { - if (e.getNullCheckNum() == id) { - if (level == 0) { - if (e.getNullCheckPStr() != s) { - isNull = 0; - break; - } - int endp; - isNull = 1; - while (k < stk) { - if (e.type == MEM_START) { - if (e.getMemEnd() == INVALID_INDEX) { - isNull = 0; - break; - } - if (bsAt(regex.btMemEnd, e.getMemNum())) { - endp = stack[e.getMemEnd()].getMemPStr(); - } else { - endp = e.getMemEnd(); - } - if (stack[e.getMemStart()].getMemPStr() != endp) { - isNull = 0; - break; - } else if (endp != s) { - isNull = -1; /* empty, but position changed */ - } - } - k++; - e = stack[k]; - } - break; - } - level--; - } - } else if (e.type == NULL_CHECK_END) { - if (e.getNullCheckNum() == id) { - level++; - } - } - } - return isNull; + // Return -1 here to cause operation to fail + return -nullCheck(id, s); } protected final int getRepeat(final int id) { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/constants/TargetInfo.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/constants/TargetInfo.java index 8dfb92bd611..5708a397fdc 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/constants/TargetInfo.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/constants/TargetInfo.java @@ -24,5 +24,4 @@ public interface TargetInfo { final int ISNOT_EMPTY = 0; final int IS_EMPTY = 1; final int IS_EMPTY_MEM = 2; - final int IS_EMPTY_REC = 3; } diff --git a/nashorn/test/script/basic/JDK-8073868.js b/nashorn/test/script/basic/JDK-8073868.js new file mode 100644 index 00000000000..f35fb161eeb --- /dev/null +++ b/nashorn/test/script/basic/JDK-8073868.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/** + * JDK-8073868: Regex matching causes java.lang.ArrayIndexOutOfBoundsException: 64 + * + * @test + * @run + */ + +function test(input) { + var comma = input.indexOf(","); + Assert.assertEquals(/([^\s]+),(.*)+/.exec(input)[0], input.trimLeft()); + Assert.assertEquals(/([^\s]+),(.*)+/.exec(input)[1], input.substring(0, comma).trimLeft()); + Assert.assertEquals(/([^\s]+),(.*)+/.exec(input)[2], input.substring(comma + 1)); + Assert.assertEquals(/(.*)+/.exec(input)[0], input); + Assert.assertEquals(/(.*)+/.exec(input)[1], input); +} + +test(" xxxx, xxx xxxxxx xxxxxxxxx xxxxxxx, xxxx xxxxx xxxxx "); +test(" xxxx, xxx xxxxxx xxxxxxxxx xxxxxxx, xxxx xxxxx xxxxx "); +test("x, xxxxxxxxxx xxxxxxxxx xxxxxxx, xxxx xxxxx xxxxx "); + +Assert.assertEquals(/(?:\1a|())*/.exec("a")[0], "a"); +Assert.assertEquals(/(?:\1a|())*/.exec("a")[1], undefined); From 87529b486445420ae0f5c320f2c9039b6a97e0ea Mon Sep 17 00:00:00 2001 From: Ed Nevill Date: Wed, 25 Mar 2015 10:24:51 -0700 Subject: [PATCH 131/362] 8075860: aarch64: jdk9/dev fails to build Fix undefined os::Linux::ucontext_set_pc in aarch64 build Reviewed-by: kvn --- .../os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp b/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp index 11bd2f7fe31..2d116ef212c 100644 --- a/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp +++ b/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp @@ -116,6 +116,14 @@ address os::Linux::ucontext_get_pc(ucontext_t * uc) { #endif } +void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) { +#ifdef BUILTIN_SIM + uc->uc_mcontext.gregs[REG_PC] = (intptr_t)pc; +#else + uc->uc_mcontext.pc = (intptr_t)pc; +#endif +} + intptr_t* os::Linux::ucontext_get_sp(ucontext_t * uc) { #ifdef BUILTIN_SIM return (intptr_t*)uc->uc_mcontext.gregs[REG_SP]; @@ -311,7 +319,7 @@ JVM_handle_linux_signal(int sig, } #else if (StubRoutines::is_safefetch_fault(pc)) { - uc->uc_mcontext.pc = intptr_t(StubRoutines::continuation_for_safefetch_fault(pc)); + os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc)); return 1; } #endif @@ -432,11 +440,7 @@ JVM_handle_linux_signal(int sig, // save all thread context in case we need to restore it if (thread != NULL) thread->set_saved_exception_pc(pc); -#ifdef BUILTIN_SIM - uc->uc_mcontext.gregs[REG_PC] = (greg_t)stub; -#else - uc->uc_mcontext.pc = (__u64)stub; -#endif + os::Linux::ucontext_set_pc(uc, stub); return true; } From edbd6cb695fe66633c2a0f2ccbef8e4380ca9e08 Mon Sep 17 00:00:00 2001 From: Jesper Wilhelmsson Date: Wed, 25 Mar 2015 19:50:00 +0100 Subject: [PATCH 132/362] 8076012: SA don't support flags of type size_t Added support for flags of type size_t in VM.Flags Reviewed-by: sla, kbarrett --- .../classes/sun/jvm/hotspot/runtime/VM.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java index caf06eadf76..ee0b541bdbf 100644 --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java @@ -123,6 +123,7 @@ public class VM { private static Type intxType; private static Type uintxType; + private static Type sizetType; private static CIntegerType boolType; private Boolean sharingEnabled; private Boolean compressedOopsEnabled; @@ -175,7 +176,7 @@ public class VM { public long getIntx() { if (Assert.ASSERTS_ENABLED) { - Assert.that(isIntx(), "not a intx flag!"); + Assert.that(isIntx(), "not an intx flag!"); } return addr.getCIntegerAt(0, intxType.getSize(), false); } @@ -191,6 +192,17 @@ public class VM { return addr.getCIntegerAt(0, uintxType.getSize(), true); } + public boolean isSizet() { + return type.equals("size_t"); + } + + public long getSizet() { + if (Assert.ASSERTS_ENABLED) { + Assert.that(isSizet(), "not a size_t flag!"); + } + return addr.getCIntegerAt(0, sizetType.getSize(), true); + } + public String getValue() { if (isBool()) { return new Boolean(getBool()).toString(); @@ -198,6 +210,8 @@ public class VM { return new Long(getIntx()).toString(); } else if (isUIntx()) { return new Long(getUIntx()).toString(); + } else if (isSizet()) { + return new Long(getSizet()).toString(); } else { return null; } @@ -323,6 +337,7 @@ public class VM { intxType = db.lookupType("intx"); uintxType = db.lookupType("uintx"); + sizetType = db.lookupType("size_t"); boolType = (CIntegerType) db.lookupType("bool"); minObjAlignmentInBytes = getObjectAlignmentInBytes(); From f0fb07515ac90f03d152a795b9d29ba23a0fbf9d Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Thu, 26 Mar 2015 16:17:33 +0100 Subject: [PATCH 133/362] 8076060: Improve make bootstrap process Reviewed-by: erikj --- jdk/make/Makefile | 49 ----------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 jdk/make/Makefile diff --git a/jdk/make/Makefile b/jdk/make/Makefile deleted file mode 100644 index ce3a3333405..00000000000 --- a/jdk/make/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -# Copyright (c) 2012, 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 -# 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. -# - -# Locate this Makefile -ifeq ($(filter /%, $(lastword $(MAKEFILE_LIST))), ) - makefile_path := $(CURDIR)/$(lastword $(MAKEFILE_LIST)) -else - makefile_path := $(lastword $(MAKEFILE_LIST)) -endif -repo_dir := $(patsubst %/make/Makefile, %, $(makefile_path)) - -# What is the name of this subsystem (langtools, corba, etc)? -subsystem_name := $(notdir $(repo_dir)) - -# Try to locate top-level makefile -top_level_makefile := $(repo_dir)/../Makefile -ifneq ($(wildcard $(top_level_makefile)), ) - $(info Will run $(subsystem_name) target on top-level Makefile) - $(info WARNING: This is a non-recommended way of building!) - $(info ===================================================) -else - $(info Cannot locate top-level Makefile. Is this repo not checked out as part of a complete forest?) - $(error Build from top-level Makefile instead) -endif - -all: - @$(MAKE) -f $(top_level_makefile) $(subsystem_name) From 3f410c76ca891cd97a3b7faf6e8215596d229fa2 Mon Sep 17 00:00:00 2001 From: Srikanth Adayapalam Date: Thu, 26 Mar 2015 11:59:41 +0530 Subject: [PATCH 134/362] 8076039: Remove the unused internal API sun.reflect.misc.FieldUtil.getDeclaredFields Reviewed-by: mchung, hawtin --- .../java.base/share/classes/sun/reflect/misc/FieldUtil.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/jdk/src/java.base/share/classes/sun/reflect/misc/FieldUtil.java b/jdk/src/java.base/share/classes/sun/reflect/misc/FieldUtil.java index d0cb48f003f..705597c5ecb 100644 --- a/jdk/src/java.base/share/classes/sun/reflect/misc/FieldUtil.java +++ b/jdk/src/java.base/share/classes/sun/reflect/misc/FieldUtil.java @@ -45,9 +45,4 @@ public final class FieldUtil { ReflectUtil.checkPackageAccess(cls); return cls.getFields(); } - - public static Field[] getDeclaredFields(Class cls) { - ReflectUtil.checkPackageAccess(cls); - return cls.getDeclaredFields(); - } } From fc1c3b4838023900e0b0268e69f75d99c96e92f0 Mon Sep 17 00:00:00 2001 From: Alexander Stepanov Date: Thu, 26 Mar 2015 14:09:44 +0400 Subject: [PATCH 135/362] 8075934: Fix some tidy warnings/errors for javax/imageio Minor HTML markup fix Reviewed-by: serb --- .../metadata/doc-files/gif_metadata.html | 14 ++++------- .../metadata/doc-files/jpeg_metadata.html | 23 ++++++------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/jdk/src/java.desktop/share/classes/javax/imageio/metadata/doc-files/gif_metadata.html b/jdk/src/java.desktop/share/classes/javax/imageio/metadata/doc-files/gif_metadata.html index b448b77ed28..4eaea551363 100644 --- a/jdk/src/java.desktop/share/classes/javax/imageio/metadata/doc-files/gif_metadata.html +++ b/jdk/src/java.desktop/share/classes/javax/imageio/metadata/doc-files/gif_metadata.html @@ -2,7 +2,7 @@ diff --git a/nashorn/test/script/sandbox/interfaceimpl.js b/nashorn/test/script/sandbox/interfaceimpl.js index 0745318c816..17745fc9bb9 100644 --- a/nashorn/test/script/sandbox/interfaceimpl.js +++ b/nashorn/test/script/sandbox/interfaceimpl.js @@ -29,8 +29,8 @@ * @security */ -var Window = Java.type("jdk.nashorn.api.scripting.Window"); -var WindowEventHandler = Java.type("jdk.nashorn.api.scripting.WindowEventHandler"); +var Window = Java.type("jdk.nashorn.api.scripting.test.Window"); +var WindowEventHandler = Java.type("jdk.nashorn.api.scripting.test.WindowEventHandler"); var w = new Window(); diff --git a/nashorn/test/script/trusted/JDK-8025629.js b/nashorn/test/script/trusted/JDK-8025629.js index 609cfe8b84a..f3f4cbad42b 100644 --- a/nashorn/test/script/trusted/JDK-8025629.js +++ b/nashorn/test/script/trusted/JDK-8025629.js @@ -28,6 +28,6 @@ * @run */ -load("classpath:jdk/nashorn/internal/runtime/resources/load_test.js") +load("classpath:jdk/nashorn/internal/runtime/test/resources/load_test.js") Assert.assertEquals(loadedFunc("hello"), "HELLO"); diff --git a/nashorn/test/src/META-INF/services/java.sql.Driver b/nashorn/test/src/META-INF/services/java.sql.Driver index 295fe48075f..d1bb7d3328d 100644 --- a/nashorn/test/src/META-INF/services/java.sql.Driver +++ b/nashorn/test/src/META-INF/services/java.sql.Driver @@ -1 +1 @@ -jdk.nashorn.api.NashornSQLDriver +jdk.nashorn.api.test.NashornSQLDriver diff --git a/nashorn/test/src/jdk/internal/dynalink/beans/CallerSensitiveTest.java b/nashorn/test/src/jdk/internal/dynalink/beans/test/CallerSensitiveTest.java similarity index 94% rename from nashorn/test/src/jdk/internal/dynalink/beans/CallerSensitiveTest.java rename to nashorn/test/src/jdk/internal/dynalink/beans/test/CallerSensitiveTest.java index d9a44551741..2a6b746e485 100644 --- a/nashorn/test/src/jdk/internal/dynalink/beans/CallerSensitiveTest.java +++ b/nashorn/test/src/jdk/internal/dynalink/beans/test/CallerSensitiveTest.java @@ -23,8 +23,9 @@ * questions. */ -package jdk.internal.dynalink.beans; +package jdk.internal.dynalink.beans.test; +import jdk.internal.dynalink.beans.BeansLinker; import jdk.nashorn.test.models.ClassLoaderAware; import org.testng.annotations.Test; diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/ArrayConversionTest.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/ArrayConversionTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/ArrayConversionTest.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/ArrayConversionTest.java index 1da767b77e5..a7a17a2c224 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/ArrayConversionTest.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/ArrayConversionTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/BooleanAccessTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/BooleanAccessTest.java index 234484f720f..f460927f05c 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/BooleanAccessTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/ConsStringTest.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/ConsStringTest.java similarity index 98% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/ConsStringTest.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/ConsStringTest.java index 2b12b04628c..db8794b19d8 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/ConsStringTest.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/ConsStringTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; import static org.testng.AssertJUnit.assertEquals; import java.util.HashMap; diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/MethodAccessTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/MethodAccessTest.java index 8bac7e6a864..91487a8819c 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/MethodAccessTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/NumberAccessTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/NumberAccessTest.java index fd4ab9da4e3..ffe7db32a31 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/NumberAccessTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/NumberBoxingTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/NumberBoxingTest.java index 40db6845fa9..fb9aa6a0933 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/NumberBoxingTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/ObjectAccessTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/ObjectAccessTest.java index 00798a4efa3..fdecf257fde 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/ObjectAccessTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; import static org.testng.AssertJUnit.assertEquals; import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/Person.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/Person.java similarity index 97% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/Person.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/Person.java index 32b1c9b795b..3e563b1113a 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/Person.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/Person.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; @SuppressWarnings("javadoc") public class Person { diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/SharedObject.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/SharedObject.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/SharedObject.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/SharedObject.java index 93c93e19f70..3c41ac101b2 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/SharedObject.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/SharedObject.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; import javax.script.Invocable; import javax.script.ScriptEngine; diff --git a/nashorn/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/StringAccessTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java rename to nashorn/test/src/jdk/nashorn/api/javaaccess/test/StringAccessTest.java index 1e0a96aaf9c..8ec43e63d39 100644 --- a/nashorn/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java +++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/test/StringAccessTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.javaaccess; +package jdk.nashorn.api.javaaccess.test; import static org.testng.AssertJUnit.assertEquals; import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/InvocableTest.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/InvocableTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/scripting/InvocableTest.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/InvocableTest.java index 4e44a296983..bba4ce50240 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/InvocableTest.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/InvocableTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/MultipleEngineTest.java similarity index 98% rename from nashorn/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/MultipleEngineTest.java index 218deff1e89..1dd6908e089 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/MultipleEngineTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/PluggableJSObjectTest.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/PluggableJSObjectTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/scripting/PluggableJSObjectTest.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/PluggableJSObjectTest.java index d6b9dcde1e5..0d9dc4d6cff 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/PluggableJSObjectTest.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/PluggableJSObjectTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -36,6 +36,7 @@ import java.util.LinkedHashMap; import java.util.Set; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; +import jdk.nashorn.api.scripting.AbstractJSObject; import org.testng.annotations.Test; /** diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/ScopeTest.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/scripting/ScopeTest.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java index f3e613b4474..6bc0c3bfd1f 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/ScopeTest.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -35,6 +35,8 @@ import javax.script.ScriptEngineManager; import javax.script.ScriptException; import javax.script.SimpleBindings; import javax.script.SimpleScriptContext; +import jdk.nashorn.api.scripting.ScriptObjectMirror; +import jdk.nashorn.api.scripting.URLReader; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptEngineSecurityTest.java similarity index 98% rename from nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptEngineSecurityTest.java index 06b89e83b19..dfebd44d60a 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptEngineSecurityTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; import static org.testng.Assert.fail; import java.lang.reflect.InvocationHandler; @@ -32,6 +32,8 @@ import java.lang.reflect.Proxy; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import jdk.nashorn.api.scripting.ClassFilter; +import jdk.nashorn.api.scripting.NashornScriptEngineFactory; import org.testng.annotations.Test; /** diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptEngineTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptEngineTest.java index 1c412c688bc..258c6bc6beb 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptEngineTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -51,6 +51,7 @@ import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineManager; import javax.script.ScriptException; import javax.script.SimpleScriptContext; +import jdk.nashorn.api.scripting.ScriptObjectMirror; import org.testng.annotations.Test; /** @@ -541,7 +542,7 @@ public class ScriptEngineTest { final ScriptEngineManager m = new ScriptEngineManager(); final ScriptEngine e = m.getEngineByName("nashorn"); e.eval("obj = { foo: 'hello' }"); - e.put("Window", e.eval("Packages.jdk.nashorn.api.scripting.Window")); + e.put("Window", e.eval("Packages.jdk.nashorn.api.scripting.test.Window")); assertEquals(e.eval("Window.funcJSObject(obj)"), "hello"); assertEquals(e.eval("Window.funcScriptObjectMirror(obj)"), "hello"); assertEquals(e.eval("Window.funcMap(obj)"), "hello"); diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptObjectMirrorTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptObjectMirrorTest.java index ce3b421ce50..f9c78fc7abf 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptObjectMirrorTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -41,6 +41,8 @@ import javax.script.ScriptContext; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import jdk.nashorn.api.scripting.JSObject; +import jdk.nashorn.api.scripting.ScriptObjectMirror; import org.testng.annotations.Test; /** diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/VariableArityTestInterface.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/VariableArityTestInterface.java similarity index 97% rename from nashorn/test/src/jdk/nashorn/api/scripting/VariableArityTestInterface.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/VariableArityTestInterface.java index 8ce5e4902af..7761a3d6e4a 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/VariableArityTestInterface.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/VariableArityTestInterface.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; @SuppressWarnings("javadoc") public interface VariableArityTestInterface { diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/Window.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/Window.java similarity index 95% rename from nashorn/test/src/jdk/nashorn/api/scripting/Window.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/Window.java index 7a7476f5e86..6c60b163b7f 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/Window.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/Window.java @@ -23,10 +23,12 @@ * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; import java.util.Map; import javax.script.Bindings; +import jdk.nashorn.api.scripting.JSObject; +import jdk.nashorn.api.scripting.ScriptObjectMirror; @SuppressWarnings("javadoc") public class Window { diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/WindowEventHandler.java b/nashorn/test/src/jdk/nashorn/api/scripting/test/WindowEventHandler.java similarity index 97% rename from nashorn/test/src/jdk/nashorn/api/scripting/WindowEventHandler.java rename to nashorn/test/src/jdk/nashorn/api/scripting/test/WindowEventHandler.java index dfcad5a9ff8..ddc879c89f2 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/WindowEventHandler.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/WindowEventHandler.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api.scripting; +package jdk.nashorn.api.scripting.test; @SuppressWarnings("javadoc") public interface WindowEventHandler { diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/resources/func.js b/nashorn/test/src/jdk/nashorn/api/scripting/test/resources/func.js similarity index 100% rename from nashorn/test/src/jdk/nashorn/api/scripting/resources/func.js rename to nashorn/test/src/jdk/nashorn/api/scripting/test/resources/func.js diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/resources/gettersetter.js b/nashorn/test/src/jdk/nashorn/api/scripting/test/resources/gettersetter.js similarity index 100% rename from nashorn/test/src/jdk/nashorn/api/scripting/resources/gettersetter.js rename to nashorn/test/src/jdk/nashorn/api/scripting/test/resources/gettersetter.js diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/resources/witheval.js b/nashorn/test/src/jdk/nashorn/api/scripting/test/resources/witheval.js similarity index 100% rename from nashorn/test/src/jdk/nashorn/api/scripting/resources/witheval.js rename to nashorn/test/src/jdk/nashorn/api/scripting/test/resources/witheval.js diff --git a/nashorn/test/src/jdk/nashorn/api/NashornSQLDriver.java b/nashorn/test/src/jdk/nashorn/api/test/NashornSQLDriver.java similarity index 98% rename from nashorn/test/src/jdk/nashorn/api/NashornSQLDriver.java rename to nashorn/test/src/jdk/nashorn/api/test/NashornSQLDriver.java index dd624096d37..d1a5377f747 100644 --- a/nashorn/test/src/jdk/nashorn/api/NashornSQLDriver.java +++ b/nashorn/test/src/jdk/nashorn/api/test/NashornSQLDriver.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.api; +package jdk.nashorn.api.test; import java.sql.Connection; import java.sql.Driver; diff --git a/nashorn/test/src/jdk/nashorn/api/tree/ParseAPITest.java b/nashorn/test/src/jdk/nashorn/api/tree/test/ParseAPITest.java similarity index 97% rename from nashorn/test/src/jdk/nashorn/api/tree/ParseAPITest.java rename to nashorn/test/src/jdk/nashorn/api/tree/test/ParseAPITest.java index e198512953a..00504d93cd6 100644 --- a/nashorn/test/src/jdk/nashorn/api/tree/ParseAPITest.java +++ b/nashorn/test/src/jdk/nashorn/api/tree/test/ParseAPITest.java @@ -22,13 +22,16 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package jdk.nashorn.api.tree; +package jdk.nashorn.api.tree.test; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import jdk.nashorn.api.tree.Parser; +import jdk.nashorn.api.tree.SimpleTreeVisitorES5_1; +import jdk.nashorn.api.tree.Tree; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/nashorn/test/src/jdk/nashorn/internal/codegen/CompilerTest.java b/nashorn/test/src/jdk/nashorn/internal/codegen/test/CompilerTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/internal/codegen/CompilerTest.java rename to nashorn/test/src/jdk/nashorn/internal/codegen/test/CompilerTest.java index 0c67af89192..a6e86feaceb 100644 --- a/nashorn/test/src/jdk/nashorn/internal/codegen/CompilerTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/codegen/test/CompilerTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.internal.codegen; +package jdk.nashorn.internal.codegen.test; import static jdk.nashorn.internal.runtime.Source.readFully; import static jdk.nashorn.internal.runtime.Source.sourceFor; diff --git a/nashorn/test/src/jdk/nashorn/internal/parser/ParserTest.java b/nashorn/test/src/jdk/nashorn/internal/parser/test/ParserTest.java similarity index 98% rename from nashorn/test/src/jdk/nashorn/internal/parser/ParserTest.java rename to nashorn/test/src/jdk/nashorn/internal/parser/test/ParserTest.java index 24d507a786c..17259cc9682 100644 --- a/nashorn/test/src/jdk/nashorn/internal/parser/ParserTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/parser/test/ParserTest.java @@ -23,11 +23,12 @@ * questions. */ -package jdk.nashorn.internal.parser; +package jdk.nashorn.internal.parser.test; import static jdk.nashorn.internal.runtime.Source.readFully; import static jdk.nashorn.internal.runtime.Source.sourceFor; import java.io.File; +import jdk.nashorn.internal.parser.Parser; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.ErrorManager; import jdk.nashorn.internal.runtime.Source; diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/regexp/joni/JoniTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/regexp/joni/test/JoniTest.java similarity index 95% rename from nashorn/test/src/jdk/nashorn/internal/runtime/regexp/joni/JoniTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/regexp/joni/test/JoniTest.java index 616f769f949..a208d02cb82 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/regexp/joni/JoniTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/regexp/joni/test/JoniTest.java @@ -23,8 +23,9 @@ * questions. */ -package jdk.nashorn.internal.runtime.regexp.joni; +package jdk.nashorn.internal.runtime.regexp.joni.test; +import jdk.nashorn.internal.runtime.regexp.joni.Regex; import org.testng.annotations.Test; /** diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/regexp/JdkRegExpTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/regexp/test/JdkRegExpTest.java similarity index 91% rename from nashorn/test/src/jdk/nashorn/internal/runtime/regexp/JdkRegExpTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/regexp/test/JdkRegExpTest.java index 8156b7864fa..87a27d00023 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/regexp/JdkRegExpTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/regexp/test/JdkRegExpTest.java @@ -23,8 +23,11 @@ * questions. */ -package jdk.nashorn.internal.runtime.regexp; +package jdk.nashorn.internal.runtime.regexp.test; +import jdk.nashorn.internal.runtime.regexp.RegExp; +import jdk.nashorn.internal.runtime.regexp.RegExpFactory; +import jdk.nashorn.internal.runtime.regexp.RegExpMatcher; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/ClassFilterTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/ClassFilterTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/internal/runtime/ClassFilterTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/ClassFilterTest.java index 5c69141dfc1..7f535405663 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/ClassFilterTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/ClassFilterTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; import static org.testng.Assert.fail; import java.io.File; diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/CodeStoreAndPathTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/CodeStoreAndPathTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/internal/runtime/CodeStoreAndPathTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/CodeStoreAndPathTest.java index 2ca4820be7b..1d10d81d571 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/CodeStoreAndPathTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/CodeStoreAndPathTest.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/ConsStringTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/ConsStringTest.java similarity index 98% rename from nashorn/test/src/jdk/nashorn/internal/runtime/ConsStringTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/ConsStringTest.java index 16c360686bf..161a2123415 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/ConsStringTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/ConsStringTest.java @@ -23,8 +23,9 @@ * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; +import jdk.nashorn.internal.runtime.ConsString; import static org.testng.Assert.assertEquals; import org.testng.annotations.Test; diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/ContextTest.java similarity index 94% rename from nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/ContextTest.java index 6770d7ec3e7..fbe20d88a98 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/ContextTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; import static jdk.nashorn.internal.runtime.Source.sourceFor; import static org.testng.Assert.assertEquals; @@ -31,6 +31,12 @@ import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.util.Map; import jdk.nashorn.internal.objects.Global; +import jdk.nashorn.internal.runtime.Context; +import jdk.nashorn.internal.runtime.ErrorManager; +import jdk.nashorn.internal.runtime.ScriptFunction; +import jdk.nashorn.internal.runtime.ScriptObject; +import jdk.nashorn.internal.runtime.ScriptRuntime; +import jdk.nashorn.internal.runtime.Source; import jdk.nashorn.internal.runtime.options.Options; import org.testng.annotations.Test; diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/ExceptionsNotSerializable.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/ExceptionsNotSerializable.java similarity index 94% rename from nashorn/test/src/jdk/nashorn/internal/runtime/ExceptionsNotSerializable.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/ExceptionsNotSerializable.java index 3b6d91b25d6..1c80bdeb36b 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/ExceptionsNotSerializable.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/ExceptionsNotSerializable.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; @@ -34,6 +34,8 @@ import java.io.ObjectOutputStream; import javax.script.ScriptEngine; import javax.script.ScriptException; import jdk.nashorn.api.scripting.NashornScriptEngineFactory; +import jdk.nashorn.internal.runtime.RewriteException; +import jdk.nashorn.internal.runtime.UnwarrantedOptimismException; import org.testng.annotations.Test; /** diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/JSTypeTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/JSTypeTest.java similarity index 98% rename from nashorn/test/src/jdk/nashorn/internal/runtime/JSTypeTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/JSTypeTest.java index 406ce1c3ed3..71f818ccf61 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/JSTypeTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/JSTypeTest.java @@ -23,8 +23,10 @@ * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; +import jdk.nashorn.internal.runtime.JSType; +import jdk.nashorn.internal.runtime.ScriptRuntime; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/LexicalBindingTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/LexicalBindingTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/internal/runtime/LexicalBindingTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/LexicalBindingTest.java index 2cd0bf01ee1..eb68232cdaf 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/LexicalBindingTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/LexicalBindingTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; import jdk.nashorn.api.scripting.NashornScriptEngineFactory; import org.testng.annotations.Test; diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/NoPersistenceCachingTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/NoPersistenceCachingTest.java index 91f19606771..0872448106e 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/NoPersistenceCachingTest.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; import static org.testng.Assert.fail; import java.io.ByteArrayOutputStream; diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/SourceTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/SourceTest.java similarity index 98% rename from nashorn/test/src/jdk/nashorn/internal/runtime/SourceTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/SourceTest.java index 12645c05896..d62b2f47ba6 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/SourceTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/SourceTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; import static jdk.nashorn.internal.runtime.Source.sourceFor; import static org.testng.Assert.assertEquals; @@ -36,6 +36,7 @@ import java.io.Reader; import java.net.URL; import java.util.Arrays; import jdk.nashorn.api.scripting.URLReader; +import jdk.nashorn.internal.runtime.Source; import org.testng.annotations.Test; /** diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/TrustedScriptEngineTest.java b/nashorn/test/src/jdk/nashorn/internal/runtime/test/TrustedScriptEngineTest.java similarity index 99% rename from nashorn/test/src/jdk/nashorn/internal/runtime/TrustedScriptEngineTest.java rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/TrustedScriptEngineTest.java index 09c90dc6f8c..416a204bdc3 100644 --- a/nashorn/test/src/jdk/nashorn/internal/runtime/TrustedScriptEngineTest.java +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/test/TrustedScriptEngineTest.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.nashorn.internal.runtime; +package jdk.nashorn.internal.runtime.test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -36,6 +36,7 @@ import javax.script.ScriptException; import javax.script.SimpleScriptContext; import jdk.nashorn.api.scripting.ClassFilter; import jdk.nashorn.api.scripting.NashornScriptEngineFactory; +import jdk.nashorn.internal.runtime.Version; import org.testng.annotations.Test; /** diff --git a/nashorn/test/src/jdk/nashorn/internal/runtime/resources/load_test.js b/nashorn/test/src/jdk/nashorn/internal/runtime/test/resources/load_test.js similarity index 100% rename from nashorn/test/src/jdk/nashorn/internal/runtime/resources/load_test.js rename to nashorn/test/src/jdk/nashorn/internal/runtime/test/resources/load_test.js From 781190634ac0ba016a32b235b8ec3d90f0b4990a Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Fri, 3 Apr 2015 17:17:36 +0300 Subject: [PATCH 194/362] 8027771: Enhance thread contexts Reviewed-by: anthony, serb --- .../com/apple/laf/AquaFileSystemModel.java | 36 ++++++---- .../macosx/classes/sun/font/CFontManager.java | 21 +++--- .../macosx/classes/sun/lwawt/LWToolkit.java | 37 +++++++---- .../lwawt/macosx/CDragSourceContextPeer.java | 39 +++++------ .../classes/sun/lwawt/macosx/CFileDialog.java | 7 +- .../sun/lwawt/macosx/CPrinterDialogPeer.java | 18 +++-- .../classes/sun/lwawt/macosx/CPrinterJob.java | 10 ++- .../com/sun/imageio/stream/StreamCloser.java | 45 +++++++------ .../plaf/windows/WindowsLookAndFeel.java | 7 +- .../sun/media/sound/JSSecurityManager.java | 11 +++- .../com/sun/media/sound/SoftAudioPusher.java | 8 ++- .../sun/media/sound/SoftJitterCorrector.java | 13 ++-- .../com/sun/media/sound/SoftSynthesizer.java | 8 ++- .../classes/java/awt/EventDispatchThread.java | 6 +- .../renderable/RenderableImageProducer.java | 13 +++- .../share/classes/javax/swing/JTable.java | 33 ++++++---- .../share/classes/javax/swing/TimerQueue.java | 27 ++++---- .../swing/plaf/basic/BasicDirectoryModel.java | 65 +++++++++++-------- .../javax/swing/text/JTextComponent.java | 7 +- .../classes/javax/swing/text/LayoutQueue.java | 42 +++++------- .../classes/sun/applet/AppletClassLoader.java | 5 +- .../share/classes/sun/applet/AppletPanel.java | 6 +- .../classes/sun/applet/AppletViewer.java | 5 +- .../classes/sun/awt/AWTAutoShutdown.java | 9 ++- .../share/classes/sun/awt/AppContext.java | 9 ++- .../sun/awt/im/InputMethodManager.java | 9 ++- .../classes/sun/awt/image/ImageFetcher.java | 5 +- .../classes/sun/font/CreatedFontTracker.java | 32 +++++---- .../classes/sun/font/SunFontManager.java | 24 +++---- .../share/classes/sun/java2d/Disposer.java | 31 ++++----- .../sun/java2d/loops/GraphicsPrimitive.java | 21 ++++-- .../sun/java2d/opengl/OGLRenderQueue.java | 26 +++++--- .../share/classes/sun/print/PrintJob2D.java | 9 ++- .../classes/sun/print/ServiceNotifier.java | 6 +- .../sun/awt/X11/GtkFileDialogPeer.java | 16 +++-- .../unix/classes/sun/awt/X11/InfoWindow.java | 18 +++-- .../unix/classes/sun/awt/X11/XToolkit.java | 43 +++++++----- .../classes/sun/awt/X11GraphicsDevice.java | 10 ++- .../sun/print/PrintServiceLookupProvider.java | 14 +++- .../awt/shell/Win32ShellFolderManager2.java | 58 +++++++++-------- .../sun/awt/windows/WFileDialogPeer.java | 12 ++-- .../sun/awt/windows/WPageDialogPeer.java | 34 +++++----- .../sun/awt/windows/WPrintDialogPeer.java | 27 ++++---- .../classes/sun/awt/windows/WToolkit.java | 18 ++++- .../java2d/d3d/D3DScreenUpdateManager.java | 62 ++++++++++-------- .../sun/print/PrintServiceLookupProvider.java | 12 +++- 46 files changed, 600 insertions(+), 374 deletions(-) diff --git a/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaFileSystemModel.java b/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaFileSystemModel.java index b0713215077..7aa82f51a9e 100644 --- a/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaFileSystemModel.java +++ b/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaFileSystemModel.java @@ -25,15 +25,16 @@ package com.apple.laf; + import java.beans.*; import java.io.File; import java.util.*; - import javax.swing.*; import javax.swing.event.ListDataEvent; import javax.swing.filechooser.FileSystemView; import javax.swing.table.AbstractTableModel; +import sun.misc.ManagedLocalsThread; /** * NavServices-like implementation of a file Table * @@ -42,7 +43,7 @@ import javax.swing.table.AbstractTableModel; @SuppressWarnings("serial") // Superclass is not serializable across versions class AquaFileSystemModel extends AbstractTableModel implements PropertyChangeListener { private final JTable fFileList; - private LoadFilesThread loadThread = null; + private FilesLoader filesLoader = null; private Vector files = null; JFileChooser filechooser = null; @@ -141,9 +142,9 @@ class AquaFileSystemModel extends AbstractTableModel implements PropertyChangeLi public void runWhenDone(final Runnable runnable){ synchronized (fileCacheLock) { - if (loadThread != null) { - if (loadThread.isAlive()) { - loadThread.queuedTasks.add(runnable); + if (filesLoader != null) { + if (filesLoader.loadThread.isAlive()) { + filesLoader.queuedTasks.add(runnable); return; } } @@ -160,9 +161,9 @@ class AquaFileSystemModel extends AbstractTableModel implements PropertyChangeLi return; } - if (loadThread != null) { + if (filesLoader != null) { // interrupt - loadThread.interrupt(); + filesLoader.loadThread.interrupt(); } fetchID++; @@ -173,8 +174,7 @@ class AquaFileSystemModel extends AbstractTableModel implements PropertyChangeLi fileCache = new Vector(50); } - loadThread = new LoadFilesThread(currentDirectory, fetchID); - loadThread.start(); + filesLoader = new FilesLoader(currentDirectory, fetchID); } public int getColumnCount() { @@ -373,17 +373,25 @@ class AquaFileSystemModel extends AbstractTableModel implements PropertyChangeLi } } - class LoadFilesThread extends Thread { - Vector queuedTasks = new Vector(); + class FilesLoader implements Runnable { + Vector queuedTasks = new Vector<>(); File currentDirectory = null; int fid; + Thread loadThread; - public LoadFilesThread(final File currentDirectory, final int fid) { - super("Aqua L&F File Loading Thread"); + public FilesLoader(final File currentDirectory, final int fid) { this.currentDirectory = currentDirectory; this.fid = fid; + String name = "Aqua L&F File Loading Thread"; + if (System.getSecurityManager() == null) { + this.loadThread = new Thread(FilesLoader.this, name); + } else { + this.loadThread = new ManagedLocalsThread(FilesLoader.this, name); + } + this.loadThread.start(); } + @Override public void run() { final Vector runnables = new Vector(10); final FileSystemView fileSystem = filechooser.getFileSystemView(); @@ -415,7 +423,7 @@ class AquaFileSystemModel extends AbstractTableModel implements PropertyChangeLi runnables.addElement(runnable); SwingUtilities.invokeLater(runnable); chunk = new Vector(10); - if (isInterrupted()) { + if (loadThread.isInterrupted()) { // interrupted, cancel all runnables cancelRunnables(runnables); return; diff --git a/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java b/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java index 272999ee6b9..341af9ff347 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java +++ b/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java @@ -42,6 +42,7 @@ import sun.awt.FontConfiguration; import sun.awt.HeadlessToolkit; import sun.awt.util.ThreadGroupUtils; import sun.lwawt.macosx.*; +import sun.misc.InnocuousThread; public final class CFontManager extends SunFontManager { private static Hashtable genericFonts = new Hashtable(); @@ -211,14 +212,18 @@ public final class CFontManager extends SunFontManager { }); } }; - AccessController.doPrivileged( - (PrivilegedAction) () -> { - /* The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); - fileCloser = new Thread(rootTG, fileCloserRunnable); + AccessController.doPrivileged((PrivilegedAction) () -> { + if (System.getSecurityManager() == null) { + /* The thread must be a member of a thread group + * which will not get GCed before VM exit. + * Make its parent the top-level thread group. + */ + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + fileCloser = new Thread(rootTG, fileCloserRunnable); + } else { + /* InnocuousThread is a member of a correct TG by default */ + fileCloser = new InnocuousThread(fileCloserRunnable); + } fileCloser.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(fileCloser); return null; diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java index 315a19a7ff3..9aea94cdc6c 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java @@ -35,6 +35,7 @@ import java.security.*; import java.util.*; import sun.awt.*; +import sun.misc.InnocuousThread; import sun.print.*; import sun.awt.util.ThreadGroupUtils; @@ -71,22 +72,32 @@ public abstract class LWToolkit extends SunToolkit implements Runnable { */ protected final void init() { AWTAutoShutdown.notifyToolkitThreadBusy(); - - ThreadGroup rootTG = AccessController.doPrivileged( - (PrivilegedAction) ThreadGroupUtils::getRootThreadGroup); - - Runtime.getRuntime().addShutdownHook( - new Thread(rootTG, () -> { + AccessController.doPrivileged((PrivilegedAction) () -> { + Runnable shutdownRunnable = () -> { shutdown(); waitForRunState(STATE_CLEANUP); - }) - ); - - Thread toolkitThread = new Thread(rootTG, this, "AWT-LW"); - toolkitThread.setDaemon(true); - toolkitThread.setPriority(Thread.NORM_PRIORITY + 1); - toolkitThread.start(); + }; + Thread shutdown; + if (System.getSecurityManager() == null) { + shutdown = new Thread(ThreadGroupUtils.getRootThreadGroup(), shutdownRunnable); + } else { + shutdown = new InnocuousThread(shutdownRunnable); + } + shutdown.setContextClassLoader(null); + Runtime.getRuntime().addShutdownHook(shutdown); + String name = "AWT-LW"; + Thread toolkitThread; + if (System.getSecurityManager() == null) { + toolkitThread = new Thread(ThreadGroupUtils.getRootThreadGroup(), LWToolkit.this, name); + } else { + toolkitThread = new InnocuousThread(LWToolkit.this, name); + } + toolkitThread.setDaemon(true); + toolkitThread.setPriority(Thread.NORM_PRIORITY + 1); + toolkitThread.start(); + return null; + }); waitForRunState(STATE_MESSAGELOOP); } diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java index 20c48cd4133..0f4224bb803 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java @@ -31,7 +31,6 @@ import java.awt.datatransfer.*; import java.awt.dnd.*; import java.awt.event.*; import java.awt.image.*; -import java.awt.peer.*; import javax.swing.*; import javax.swing.text.*; @@ -44,6 +43,7 @@ import sun.awt.dnd.*; import sun.lwawt.LWComponentPeer; import sun.lwawt.LWWindowPeer; import sun.lwawt.PlatformWindow; +import sun.misc.ManagedLocalsThread; public final class CDragSourceContextPeer extends SunDragSourceContextPeer { @@ -164,28 +164,29 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer { // are posted during dragging by native event handlers. try { - Thread dragThread = new Thread() { - public void run() { - final long nativeDragSource = getNativeContext(); - try { - doDragging(nativeDragSource); - } catch (Exception e) { - e.printStackTrace(); - } finally { - releaseNativeDragSource(nativeDragSource); - fDragImage = null; - if (fDragCImage != null) { - fDragCImage.dispose(); - fDragCImage = null; - } + Runnable dragRunnable = () -> { + final long nativeDragSource = getNativeContext(); + try { + doDragging(nativeDragSource); + } catch (Exception e) { + e.printStackTrace(); + } finally { + releaseNativeDragSource(nativeDragSource); + fDragImage = null; + if (fDragCImage != null) { + fDragCImage.dispose(); + fDragCImage = null; } } }; - + Thread dragThread; + if (System.getSecurityManager() == null) { + dragThread = new Thread(dragRunnable); + } else { + dragThread = new ManagedLocalsThread(dragRunnable); + } dragThread.start(); - } - - catch (Exception e) { + } catch (Exception e) { final long nativeDragSource = getNativeContext(); setNativeContext(0); releaseNativeDragSource(nativeDragSource); diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java index cc31b532f76..0e8ee1e1fc4 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java @@ -37,6 +37,7 @@ import java.io.*; import sun.awt.CausedFocusEvent.Cause; import sun.awt.AWTAccessor; import sun.java2d.pipe.Region; +import sun.misc.ManagedLocalsThread; import sun.security.action.GetBooleanAction; class CFileDialog implements FileDialogPeer { @@ -119,7 +120,11 @@ class CFileDialog implements FileDialogPeer { if (visible) { // Java2 Dialog class requires peer to run code in a separate thread // and handles keeping the call modal - new Thread(new Task()).start(); // invokes my 'run' method, below... + if (System.getSecurityManager() == null) { + new Thread(new Task()).start(); + } else { + new ManagedLocalsThread(new Task()).start(); + } } // We hide ourself before "show" returns - setVisible(false) // doesn't apply diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterDialogPeer.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterDialogPeer.java index 8dfe7e1e51e..6ff3ec01e0e 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterDialogPeer.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterDialogPeer.java @@ -29,6 +29,7 @@ import java.awt.*; import java.awt.dnd.*; import sun.lwawt.*; +import sun.misc.ManagedLocalsThread; public class CPrinterDialogPeer extends LWWindowPeer { static { @@ -53,13 +54,16 @@ public class CPrinterDialogPeer extends LWWindowPeer { public void setVisible(boolean visible) { if (visible) { - new Thread(new Runnable() { - public void run() { - CPrinterDialog printerDialog = (CPrinterDialog)fTarget; - printerDialog.setRetVal(printerDialog.showDialog()); - printerDialog.setVisible(false); - } - }).start(); + Runnable task = () -> { + CPrinterDialog printerDialog = (CPrinterDialog)fTarget; + printerDialog.setRetVal(printerDialog.showDialog()); + printerDialog.setVisible(false); + }; + if (System.getSecurityManager() == null) { + new Thread(task).start(); + } else { + new ManagedLocalsThread(task).start(); + } } } diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java index ede3bec7b73..b82094d5b7d 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java @@ -39,6 +39,7 @@ import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.standard.PageRanges; import sun.java2d.*; +import sun.misc.ManagedLocalsThread; import sun.print.*; public final class CPrinterJob extends RasterPrinterJob { @@ -731,9 +732,12 @@ public final class CPrinterJob extends RasterPrinterJob { // upcall from native private static void detachPrintLoop(final long target, final long arg) { - new Thread() { public void run() { - _safePrintLoop(target, arg); - }}.start(); + Runnable task = () -> _safePrintLoop(target, arg); + if (System.getSecurityManager() == null) { + new Thread(task).start(); + } else { + new ManagedLocalsThread(task).start(); + } } private static native void _safePrintLoop(long target, long arg); diff --git a/jdk/src/java.desktop/share/classes/com/sun/imageio/stream/StreamCloser.java b/jdk/src/java.desktop/share/classes/com/sun/imageio/stream/StreamCloser.java index 356c0c092f9..b660f272e2c 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/imageio/stream/StreamCloser.java +++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/stream/StreamCloser.java @@ -25,7 +25,12 @@ package com.sun.imageio.stream; +import sun.awt.util.ThreadGroupUtils; +import sun.misc.InnocuousThread; + import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Set; import java.util.WeakHashMap; import javax.imageio.stream.ImageInputStream; @@ -81,27 +86,25 @@ public class StreamCloser { } }; - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - /* The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup tg = - Thread.currentThread().getThreadGroup(); - for (ThreadGroup tgn = tg; - tgn != null; - tg = tgn, tgn = tg.getParent()); - streamCloser = new Thread(tg, streamCloserRunnable); - /* Set context class loader to null in order to avoid - * keeping a strong reference to an application classloader. - */ - streamCloser.setContextClassLoader(null); - Runtime.getRuntime().addShutdownHook(streamCloser); - return null; - } - }); + AccessController.doPrivileged((PrivilegedAction) () -> { + if (System.getSecurityManager() == null) { + /* The thread must be a member of a thread group + * which will not get GCed before VM exit. + * Make its parent the top-level thread group. + */ + ThreadGroup tg = ThreadGroupUtils.getRootThreadGroup(); + streamCloser = new Thread(tg, streamCloserRunnable); + } else { + /* InnocuousThread is a member of a correct TG by default */ + streamCloser = new InnocuousThread(streamCloserRunnable); + } + /* Set context class loader to null in order to avoid + * keeping a strong reference to an application classloader. + */ + streamCloser.setContextClassLoader(null); + Runtime.getRuntime().addShutdownHook(streamCloser); + return null; + }); } } } diff --git a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java index ee81a15f637..0a666b12e25 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java +++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java @@ -64,6 +64,7 @@ import sun.awt.SunToolkit; import sun.awt.OSInfo; import sun.awt.shell.ShellFolder; import sun.font.FontUtilities; +import sun.misc.ManagedLocalsThread; import sun.security.action.GetPropertyAction; import sun.swing.DefaultLayoutStyle; @@ -2037,7 +2038,11 @@ public class WindowsLookAndFeel extends BasicLookAndFeel if (audioRunnable != null) { // Runnable appears to block until completed playing, hence // start up another thread to handle playing. - new Thread(audioRunnable).start(); + if (System.getSecurityManager() == null) { + new Thread(audioRunnable).start(); + } else { + new ManagedLocalsThread(audioRunnable).start(); + } } } } diff --git a/jdk/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java b/jdk/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java index 8382f15e8c2..63eaba1c4ec 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java +++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java @@ -25,6 +25,9 @@ package com.sun.media.sound; +import sun.misc.InnocuousThread; +import sun.misc.ManagedLocalsThread; + import java.io.BufferedInputStream; import java.io.InputStream; import java.io.File; @@ -144,7 +147,13 @@ final class JSSecurityManager { final String threadName, final boolean isDaemon, final int priority, final boolean doStart) { - Thread thread = new Thread(runnable); + Thread thread; + if (System.getSecurityManager() == null) { + thread = new Thread(runnable); + } else { + thread = new ManagedLocalsThread(runnable); + } + if (threadName != null) { thread.setName(threadName); } diff --git a/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftAudioPusher.java b/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftAudioPusher.java index 1a07a23ec6f..a5fdd4e9f86 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftAudioPusher.java +++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftAudioPusher.java @@ -24,6 +24,8 @@ */ package com.sun.media.sound; +import sun.misc.ManagedLocalsThread; + import java.io.IOException; import javax.sound.sampled.AudioInputStream; @@ -53,7 +55,11 @@ public final class SoftAudioPusher implements Runnable { if (active) return; active = true; - audiothread = new Thread(this); + if (System.getSecurityManager() == null) { + audiothread = new Thread(this); + } else { + audiothread = new ManagedLocalsThread(this); + } audiothread.setDaemon(true); audiothread.setPriority(Thread.MAX_PRIORITY); audiothread.start(); diff --git a/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftJitterCorrector.java b/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftJitterCorrector.java index 0f5ff294574..85c615e1801 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftJitterCorrector.java +++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftJitterCorrector.java @@ -24,12 +24,13 @@ */ package com.sun.media.sound; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; +import sun.misc.ManagedLocalsThread; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; /** * A jitter corrector to be used with SoftAudioPusher. @@ -215,7 +216,11 @@ public final class SoftJitterCorrector extends AudioInputStream { } }; - thread = new Thread(runnable); + if (System.getSecurityManager() == null) { + thread = new Thread(runnable); + } else { + thread = new ManagedLocalsThread(runnable); + } thread.setDaemon(true); thread.setPriority(Thread.MAX_PRIORITY); thread.start(); diff --git a/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java b/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java index e895ead074f..81c33ff788b 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java +++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java @@ -25,6 +25,8 @@ package com.sun.media.sound; +import sun.misc.ManagedLocalsThread; + import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -139,7 +141,11 @@ public final class SoftSynthesizer implements AudioSynthesizer, pusher = null; jitter_stream = null; sourceDataLine = null; - new Thread(runnable).start(); + if (System.getSecurityManager() == null) { + new Thread(runnable).start(); + } else { + new ManagedLocalsThread(runnable).start(); + } } return len; } diff --git a/jdk/src/java.desktop/share/classes/java/awt/EventDispatchThread.java b/jdk/src/java.desktop/share/classes/java/awt/EventDispatchThread.java index 5bf91e6ab8c..dd9ea860ec2 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/EventDispatchThread.java +++ b/jdk/src/java.desktop/share/classes/java/awt/EventDispatchThread.java @@ -30,6 +30,8 @@ import java.awt.event.ActionEvent; import java.awt.event.WindowEvent; import java.util.ArrayList; + +import sun.misc.ManagedLocalsThread; import sun.util.logging.PlatformLogger; import sun.awt.dnd.SunDragSourceContextPeer; @@ -53,7 +55,7 @@ import sun.awt.dnd.SunDragSourceContextPeer; * * @since 1.1 */ -class EventDispatchThread extends Thread { +class EventDispatchThread extends ManagedLocalsThread { private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventDispatchThread"); @@ -65,7 +67,7 @@ class EventDispatchThread extends Thread { private ArrayList eventFilters = new ArrayList(); EventDispatchThread(ThreadGroup group, String name, EventQueue queue) { - super(group, name); + super(group, null, name); setEventQueue(queue); } diff --git a/jdk/src/java.desktop/share/classes/java/awt/image/renderable/RenderableImageProducer.java b/jdk/src/java.desktop/share/classes/java/awt/image/renderable/RenderableImageProducer.java index 206869ae1bf..4bd6c8b7396 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/image/renderable/RenderableImageProducer.java +++ b/jdk/src/java.desktop/share/classes/java/awt/image/renderable/RenderableImageProducer.java @@ -34,10 +34,11 @@ **********************************************************************/ package java.awt.image.renderable; -import java.awt.color.ColorSpace; + +import sun.misc.ManagedLocalsThread; + import java.awt.image.ColorModel; import java.awt.image.DataBuffer; -import java.awt.image.DirectColorModel; import java.awt.image.ImageConsumer; import java.awt.image.ImageProducer; import java.awt.image.Raster; @@ -135,7 +136,13 @@ public class RenderableImageProducer implements ImageProducer, Runnable { public synchronized void startProduction(ImageConsumer ic) { addConsumer(ic); // Need to build a runnable object for the Thread. - Thread thread = new Thread(this, "RenderableImageProducer Thread"); + String name = "RenderableImageProducer Thread"; + Thread thread; + if (System.getSecurityManager() == null) { + thread = new Thread(this, name); + } else { + thread = new ManagedLocalsThread(this); + } thread.start(); } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JTable.java b/jdk/src/java.desktop/share/classes/javax/swing/JTable.java index 56d3430ce3e..c70d06b6caf 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JTable.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JTable.java @@ -53,6 +53,8 @@ import java.util.List; import javax.print.attribute.*; import javax.print.PrintService; + +import sun.misc.ManagedLocalsThread; import sun.reflect.misc.ReflectUtil; import sun.swing.SwingUtilities2; @@ -6384,25 +6386,28 @@ public class JTable extends JComponent implements TableModelListener, Scrollable // this runnable will be used to do the printing // (and save any throwables) on another thread - Runnable runnable = new Runnable() { - public void run() { - try { - // do the printing - job.print(copyAttr); - } catch (Throwable t) { - // save any Throwable to be rethrown - synchronized(lock) { - printError = t; - } - } finally { - // we're finished - hide the dialog - printingStatus.dispose(); + Runnable runnable = () -> { + try { + // do the printing + job.print(copyAttr); + } catch (Throwable t) { + // save any Throwable to be rethrown + synchronized(lock) { + printError = t; } + } finally { + // we're finished - hide the dialog + printingStatus.dispose(); } }; // start printing on another thread - Thread th = new Thread(runnable); + Thread th; + if (System.getSecurityManager() == null) { + th = new Thread(runnable); + } else { + th = new ManagedLocalsThread(runnable); + } th.start(); printingStatus.showModal(true); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/TimerQueue.java b/jdk/src/java.desktop/share/classes/javax/swing/TimerQueue.java index a6791d64fbc..c74ac7d0f6c 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/TimerQueue.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/TimerQueue.java @@ -29,12 +29,14 @@ package javax.swing; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.locks.*; import java.util.concurrent.atomic.AtomicLong; import sun.awt.AppContext; - +import sun.misc.InnocuousThread; /** @@ -94,18 +96,19 @@ class TimerQueue implements Runnable if (! running) { runningLock.lock(); try { - final ThreadGroup threadGroup = - AppContext.getAppContext().getThreadGroup(); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - Thread timerThread = new Thread(threadGroup, TimerQueue.this, - "TimerQueue"); - timerThread.setDaemon(true); - timerThread.setPriority(Thread.NORM_PRIORITY); - timerThread.start(); - return null; + final ThreadGroup threadGroup = AppContext.getAppContext().getThreadGroup(); + AccessController.doPrivileged((PrivilegedAction) () -> { + String name = "TimerQueue"; + Thread timerThread; + if (System.getSecurityManager() == null) { + timerThread = new Thread(threadGroup, TimerQueue.this, name); + } else { + timerThread = new InnocuousThread(threadGroup, TimerQueue.this, name); } + timerThread.setDaemon(true); + timerThread.setPriority(Thread.NORM_PRIORITY); + timerThread.start(); + return null; }); running = true; } finally { diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java index c31332b15aa..51ad39aa7c6 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java @@ -25,15 +25,19 @@ package javax.swing.plaf.basic; -import java.io.File; -import java.util.*; -import java.util.concurrent.Callable; -import javax.swing.*; -import javax.swing.filechooser.*; -import javax.swing.event.*; -import java.beans.*; - import sun.awt.shell.ShellFolder; +import sun.misc.ManagedLocalsThread; + +import javax.swing.*; +import javax.swing.event.ListDataEvent; +import javax.swing.filechooser.FileSystemView; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.File; +import java.util.List; +import java.util.Vector; +import java.util.concurrent.Callable; /** * Basic implementation of a file list. @@ -46,7 +50,7 @@ public class BasicDirectoryModel extends AbstractListModel implements Pr private JFileChooser filechooser = null; // PENDING(jeff) pick the size more sensibly private Vector fileCache = new Vector(50); - private LoadFilesThread loadThread = null; + private FilesLoader filesLoader = null; private Vector files = null; private Vector directories = null; private int fetchID = 0; @@ -91,10 +95,10 @@ public class BasicDirectoryModel extends AbstractListModel implements Pr * This method is used to interrupt file loading thread. */ public void invalidateFileCache() { - if (loadThread != null) { - loadThread.interrupt(); - loadThread.cancelRunnables(); - loadThread = null; + if (filesLoader != null) { + filesLoader.loadThread.interrupt(); + filesLoader.cancelRunnables(); + filesLoader = null; } } @@ -149,15 +153,14 @@ public class BasicDirectoryModel extends AbstractListModel implements Pr if (currentDirectory == null) { return; } - if (loadThread != null) { - loadThread.interrupt(); - loadThread.cancelRunnables(); + if (filesLoader != null) { + filesLoader.loadThread.interrupt(); + filesLoader.cancelRunnables(); } setBusy(true, ++fetchID); - loadThread = new LoadFilesThread(currentDirectory, fetchID); - loadThread.start(); + filesLoader = new FilesLoader(currentDirectory, fetchID); } /** @@ -251,17 +254,25 @@ public class BasicDirectoryModel extends AbstractListModel implements Pr } - class LoadFilesThread extends Thread { + class FilesLoader implements Runnable { File currentDirectory = null; int fid; Vector runnables = new Vector(10); + final Thread loadThread; - public LoadFilesThread(File currentDirectory, int fid) { - super("Basic L&F File Loading Thread"); + public FilesLoader(File currentDirectory, int fid) { this.currentDirectory = currentDirectory; this.fid = fid; + String name = "Basic L&F File Loading Thread"; + if (System.getSecurityManager() == null) { + this.loadThread = new Thread(this, name); + } else { + this.loadThread = new ManagedLocalsThread(this, name); + } + this.loadThread.start(); } + @Override public void run() { run0(); setBusy(false, fid); @@ -270,13 +281,13 @@ public class BasicDirectoryModel extends AbstractListModel implements Pr public void run0() { FileSystemView fileSystem = filechooser.getFileSystemView(); - if (isInterrupted()) { + if (loadThread.isInterrupted()) { return; } File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled()); - if (isInterrupted()) { + if (loadThread.isInterrupted()) { return; } @@ -296,7 +307,7 @@ public class BasicDirectoryModel extends AbstractListModel implements Pr newFiles.addElement(file); } - if (isInterrupted()) { + if (loadThread.isInterrupted()) { return; } } @@ -333,7 +344,7 @@ public class BasicDirectoryModel extends AbstractListModel implements Pr } if (start >= 0 && end > start && newFileCache.subList(end, newSize).equals(fileCache.subList(start, oldSize))) { - if (isInterrupted()) { + if (loadThread.isInterrupted()) { return null; } return new DoChangeContents(newFileCache.subList(start, end), start, null, 0, fid); @@ -351,14 +362,14 @@ public class BasicDirectoryModel extends AbstractListModel implements Pr } if (start >= 0 && end > start && fileCache.subList(end, oldSize).equals(newFileCache.subList(start, newSize))) { - if (isInterrupted()) { + if (loadThread.isInterrupted()) { return null; } return new DoChangeContents(null, 0, new Vector<>(fileCache.subList(start, end)), start, fid); } } if (!fileCache.equals(newFileCache)) { - if (isInterrupted()) { + if (loadThread.isInterrupted()) { cancelRunnables(runnables); } return new DoChangeContents(newFileCache, 0, fileCache, 0, fid); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java b/jdk/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java index 63c27ce1ecb..2d22b2a0f08 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java @@ -68,6 +68,7 @@ import javax.print.attribute.*; import sun.awt.AppContext; +import sun.misc.ManagedLocalsThread; import sun.swing.PrintingStatus; import sun.swing.SwingUtilities2; import sun.swing.text.TextComponentPrintable; @@ -2363,7 +2364,11 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A runnablePrinting.run(); } else { if (isEventDispatchThread) { - (new Thread(runnablePrinting)).start(); + if (System.getSecurityManager() == null) { + new Thread(runnablePrinting).start(); + } else { + new ManagedLocalsThread(runnablePrinting).start(); + } printingStatus.showModal(true); } else { printingStatus.showModal(false); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java b/jdk/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java index c4ba1c0ba06..67d4072793b 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java @@ -26,6 +26,7 @@ package javax.swing.text; import java.util.Vector; import sun.awt.AppContext; +import sun.misc.ManagedLocalsThread; /** * A queue of text layout tasks. @@ -80,7 +81,22 @@ public class LayoutQueue { */ public synchronized void addTask(Runnable task) { if (worker == null) { - worker = new LayoutThread(); + Runnable workerRunnable = () -> { + Runnable work; + do { + work = waitForWork(); + if (work != null) { + work.run(); + } + } while (work != null); + }; + String name = "text-layout"; + if (System.getSecurityManager() == null) { + worker = new Thread(workerRunnable, name); + } else { + worker = new ManagedLocalsThread(workerRunnable, name); + } + worker.setPriority(Thread.MIN_PRIORITY); worker.start(); } tasks.addElement(task); @@ -102,28 +118,4 @@ public class LayoutQueue { tasks.removeElementAt(0); return work; } - - /** - * low priority thread to perform layout work forever - */ - class LayoutThread extends Thread { - - LayoutThread() { - super("text-layout"); - setPriority(Thread.MIN_PRIORITY); - } - - public void run() { - Runnable work; - do { - work = waitForWork(); - if (work != null) { - work.run(); - } - } while (work != null); - } - - - } - } diff --git a/jdk/src/java.desktop/share/classes/sun/applet/AppletClassLoader.java b/jdk/src/java.desktop/share/classes/sun/applet/AppletClassLoader.java index 83684cb36f2..13b000d5582 100644 --- a/jdk/src/java.desktop/share/classes/sun/applet/AppletClassLoader.java +++ b/jdk/src/java.desktop/share/classes/sun/applet/AppletClassLoader.java @@ -52,6 +52,7 @@ import java.security.PermissionCollection; import sun.awt.AppContext; import sun.awt.SunToolkit; import sun.misc.IOUtils; +import sun.misc.ManagedLocalsThread; import sun.net.www.ParseUtil; import sun.security.util.SecurityConstants; @@ -855,13 +856,13 @@ public void grab() { * this operation to complete before continuing, wait for the notifyAll() * operation on the syncObject to occur. */ -class AppContextCreator extends Thread { +class AppContextCreator extends ManagedLocalsThread { Object syncObject = new Object(); AppContext appContext = null; volatile boolean created = false; AppContextCreator(ThreadGroup group) { - super(group, "AppContextCreator"); + super(group, null, "AppContextCreator"); } public void run() { diff --git a/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java b/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java index 9c1a038cd72..9226afb3742 100644 --- a/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java +++ b/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java @@ -42,6 +42,7 @@ import sun.awt.AWTAccessor; import sun.awt.AppContext; import sun.awt.EmbeddedFrame; import sun.awt.SunToolkit; +import sun.misc.ManagedLocalsThread; import sun.misc.MessageUtils; import sun.misc.PerformanceLogger; import sun.misc.Queue; @@ -176,8 +177,7 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable { ThreadGroup appletGroup = loader.getThreadGroup(); - - handler = new Thread(appletGroup, this, "thread " + nm); + handler = new ManagedLocalsThread(appletGroup, this, "thread " + nm); // set the context class loader for this thread AccessController.doPrivileged(new PrivilegedAction() { @Override @@ -410,7 +410,7 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable { if (loaderThread == null) { // REMIND: do we want a name? //System.out.println("------------------- loading applet"); - setLoaderThread(new Thread(this)); + setLoaderThread(new ManagedLocalsThread(this)); loaderThread.start(); // we get to go to sleep while this runs loaderThread.join(); diff --git a/jdk/src/java.desktop/share/classes/sun/applet/AppletViewer.java b/jdk/src/java.desktop/share/classes/sun/applet/AppletViewer.java index 6143517ed7c..a8b5707a91c 100644 --- a/jdk/src/java.desktop/share/classes/sun/applet/AppletViewer.java +++ b/jdk/src/java.desktop/share/classes/sun/applet/AppletViewer.java @@ -38,6 +38,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import sun.awt.SunToolkit; import sun.awt.AppContext; +import sun.misc.ManagedLocalsThread; /** * A frame to show the applet tag in. @@ -853,7 +854,7 @@ public class AppletViewer extends Frame implements AppletContext, Printable { // final AppletPanel p = panel; - new Thread(new Runnable() + new ManagedLocalsThread(new Runnable() { @Override public void run() @@ -889,7 +890,7 @@ public class AppletViewer extends Frame implements AppletContext, Printable { // spawn a new thread to avoid blocking the event queue // when calling appletShutdown. // - new Thread(new Runnable() + new ManagedLocalsThread(new Runnable() { @Override public void run() diff --git a/jdk/src/java.desktop/share/classes/sun/awt/AWTAutoShutdown.java b/jdk/src/java.desktop/share/classes/sun/awt/AWTAutoShutdown.java index de3df3a2bdf..0dfb5dbd1d0 100644 --- a/jdk/src/java.desktop/share/classes/sun/awt/AWTAutoShutdown.java +++ b/jdk/src/java.desktop/share/classes/sun/awt/AWTAutoShutdown.java @@ -34,6 +34,7 @@ import java.util.IdentityHashMap; import java.util.Map; import java.util.Set; +import sun.misc.InnocuousThread; import sun.util.logging.PlatformLogger; import sun.awt.util.ThreadGroupUtils; @@ -340,7 +341,13 @@ public final class AWTAutoShutdown implements Runnable { * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION} */ private void activateBlockerThread() { - Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown"); + Thread thread; + String name = "AWT-Shutdown"; + if (System.getSecurityManager() == null) { + thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, name); + } else { + thread = new InnocuousThread(this, name); + } thread.setContextClassLoader(null); thread.setDaemon(false); blockerThread = thread; diff --git a/jdk/src/java.desktop/share/classes/sun/awt/AppContext.java b/jdk/src/java.desktop/share/classes/sun/awt/AppContext.java index c218a5e1833..e777ed35d18 100644 --- a/jdk/src/java.desktop/share/classes/sun/awt/AppContext.java +++ b/jdk/src/java.desktop/share/classes/sun/awt/AppContext.java @@ -43,6 +43,8 @@ import java.util.HashSet; import java.beans.PropertyChangeSupport; import java.beans.PropertyChangeListener; import java.lang.ref.SoftReference; + +import sun.misc.InnocuousThread; import sun.util.logging.PlatformLogger; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; @@ -589,7 +591,12 @@ public final class AppContext { } public Thread run() { - Thread t = new Thread(appContext.getThreadGroup(), runnable); + Thread t; + if (System.getSecurityManager() == null) { + t = new Thread(appContext.getThreadGroup(), runnable); + } else { + t = new InnocuousThread(appContext.getThreadGroup(), runnable, "AppContext Disposer"); + } t.setContextClassLoader(appContext.getContextClassLoader()); t.setPriority(Thread.NORM_PRIORITY + 1); t.setDaemon(true); diff --git a/jdk/src/java.desktop/share/classes/sun/awt/im/InputMethodManager.java b/jdk/src/java.desktop/share/classes/sun/awt/im/InputMethodManager.java index 51b7951b27f..3747257ad69 100644 --- a/jdk/src/java.desktop/share/classes/sun/awt/im/InputMethodManager.java +++ b/jdk/src/java.desktop/share/classes/sun/awt/im/InputMethodManager.java @@ -55,6 +55,8 @@ import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import sun.awt.InputMethodSupport; import sun.awt.SunToolkit; +import sun.misc.InnocuousThread; +import sun.misc.ManagedLocalsThread; /** * InputMethodManager is an abstract class that manages the input @@ -165,7 +167,12 @@ public abstract class InputMethodManager { // to choose from. Otherwise, just keep the instance. if (imm.hasMultipleInputMethods()) { imm.initialize(); - Thread immThread = new Thread(imm, threadName); + Thread immThread; + if (System.getSecurityManager() == null) { + immThread = new Thread(imm, threadName); + } else { + immThread = new ManagedLocalsThread(imm, threadName); + } immThread.setDaemon(true); immThread.setPriority(Thread.NORM_PRIORITY + 1); immThread.start(); diff --git a/jdk/src/java.desktop/share/classes/sun/awt/image/ImageFetcher.java b/jdk/src/java.desktop/share/classes/sun/awt/image/ImageFetcher.java index eaccf335db0..9e71c9d47c2 100644 --- a/jdk/src/java.desktop/share/classes/sun/awt/image/ImageFetcher.java +++ b/jdk/src/java.desktop/share/classes/sun/awt/image/ImageFetcher.java @@ -27,6 +27,7 @@ package sun.awt.image; import java.util.Vector; import sun.awt.AppContext; +import sun.misc.ManagedLocalsThread; /** * An ImageFetcher is a thread used to fetch ImageFetchable objects. @@ -41,7 +42,7 @@ import sun.awt.AppContext; * @author Jim Graham * @author Fred Ecks */ -class ImageFetcher extends Thread { +class ImageFetcher extends ManagedLocalsThread { static final int HIGH_PRIORITY = 8; static final int LOW_PRIORITY = 3; static final int ANIM_PRIORITY = 2; @@ -54,7 +55,7 @@ class ImageFetcher extends Thread { * Constructor for ImageFetcher -- only called by add() below. */ private ImageFetcher(ThreadGroup threadGroup, int index) { - super(threadGroup, "Image Fetcher " + index); + super(threadGroup, null, "Image Fetcher " + index); setDaemon(true); } diff --git a/jdk/src/java.desktop/share/classes/sun/font/CreatedFontTracker.java b/jdk/src/java.desktop/share/classes/sun/font/CreatedFontTracker.java index 43f8b098658..439a30aa575 100644 --- a/jdk/src/java.desktop/share/classes/sun/font/CreatedFontTracker.java +++ b/jdk/src/java.desktop/share/classes/sun/font/CreatedFontTracker.java @@ -36,6 +36,7 @@ import java.util.concurrent.TimeUnit; import sun.awt.AppContext; import sun.awt.util.ThreadGroupUtils; +import sun.misc.InnocuousThread; public class CreatedFontTracker { @@ -115,18 +116,25 @@ public class CreatedFontTracker { static void init() { if (t == null) { // Add a shutdown hook to remove the temp file. - AccessController.doPrivileged( - (PrivilegedAction) () -> { - /* The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); - t = new Thread(rootTG, TempFileDeletionHook::runHooks); - t.setContextClassLoader(null); - Runtime.getRuntime().addShutdownHook(t); - return null; - }); + AccessController.doPrivileged((PrivilegedAction) () -> { + if (System.getSecurityManager() == null) { + /* The thread must be a member of a thread group + * which will not get GCed before VM exit. + * Make its parent the top-level thread group. + */ + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + t = new Thread(rootTG, TempFileDeletionHook::runHooks); + } else { + /* InnocuousThread is a member of a correct TG by default */ + t = new InnocuousThread(TempFileDeletionHook::runHooks); + } + /* Set context class loader to null in order to avoid + * keeping a strong reference to an application classloader. + */ + t.setContextClassLoader(null); + Runtime.getRuntime().addShutdownHook(t); + return null; + }); } } diff --git a/jdk/src/java.desktop/share/classes/sun/font/SunFontManager.java b/jdk/src/java.desktop/share/classes/sun/font/SunFontManager.java index 274ec690ef9..7a994042cf6 100644 --- a/jdk/src/java.desktop/share/classes/sun/font/SunFontManager.java +++ b/jdk/src/java.desktop/share/classes/sun/font/SunFontManager.java @@ -54,6 +54,7 @@ import sun.awt.FontConfiguration; import sun.awt.SunToolkit; import sun.awt.util.ThreadGroupUtils; import sun.java2d.FontSupport; +import sun.misc.InnocuousThread; import sun.util.logging.PlatformLogger; /** @@ -2529,18 +2530,17 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE { }); } }; - AccessController.doPrivileged( - (PrivilegedAction) () -> { - /* The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); - fileCloser = new Thread(rootTG, fileCloserRunnable); - fileCloser.setContextClassLoader(null); - Runtime.getRuntime().addShutdownHook(fileCloser); - return null; - }); + AccessController.doPrivileged((PrivilegedAction) () -> { + if (System.getSecurityManager() == null) { + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + fileCloser = new Thread(rootTG, fileCloserRunnable); + } else { + fileCloser = new InnocuousThread(fileCloserRunnable); + } + fileCloser.setContextClassLoader(null); + Runtime.getRuntime().addShutdownHook(fileCloser); + return null; + }); } } } diff --git a/jdk/src/java.desktop/share/classes/sun/java2d/Disposer.java b/jdk/src/java.desktop/share/classes/sun/java2d/Disposer.java index ba69ce763dd..a3fd6143a77 100644 --- a/jdk/src/java.desktop/share/classes/sun/java2d/Disposer.java +++ b/jdk/src/java.desktop/share/classes/sun/java2d/Disposer.java @@ -26,6 +26,7 @@ package sun.java2d; import sun.awt.util.ThreadGroupUtils; +import sun.misc.InnocuousThread; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; @@ -81,21 +82,21 @@ public class Disposer implements Runnable { } } disposerInstance = new Disposer(); - AccessController.doPrivileged( - (PrivilegedAction) () -> { - /* The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); - Thread t = new Thread(rootTG, disposerInstance, "Java2D Disposer"); - t.setContextClassLoader(null); - t.setDaemon(true); - t.setPriority(Thread.MAX_PRIORITY); - t.start(); - return null; - } - ); + AccessController.doPrivileged((PrivilegedAction) () -> { + String name = "Java2D Disposer"; + Thread t; + if (System.getSecurityManager() == null) { + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + t = new Thread(rootTG, disposerInstance, name); + } else { + t = new InnocuousThread(disposerInstance, name); + } + t.setContextClassLoader(null); + t.setDaemon(true); + t.setPriority(Thread.MAX_PRIORITY); + t.start(); + return null; + }); } /** diff --git a/jdk/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitive.java b/jdk/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitive.java index ca23fe72aec..e7d2e2448f6 100644 --- a/jdk/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitive.java +++ b/jdk/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitive.java @@ -33,6 +33,7 @@ import java.awt.image.BufferedImage; import java.awt.AlphaComposite; import java.awt.Rectangle; import sun.awt.image.BufImgSurfaceData; +import sun.awt.util.ThreadGroupUtils; import sun.java2d.SurfaceData; import sun.java2d.pipe.Region; import java.lang.reflect.Field; @@ -46,6 +47,8 @@ import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.security.AccessController; import java.security.PrivilegedAction; + +import sun.misc.InnocuousThread; import sun.security.action.GetPropertyAction; /** @@ -413,15 +416,19 @@ public abstract class GraphicsPrimitive { return traceout; } - public static class TraceReporter extends Thread { + public static class TraceReporter implements Runnable { public static void setShutdownHook() { - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - TraceReporter t = new TraceReporter(); - t.setContextClassLoader(null); - Runtime.getRuntime().addShutdownHook(t); - return null; + AccessController.doPrivileged((PrivilegedAction) () -> { + TraceReporter t = new TraceReporter(); + Thread thread; + if (System.getSecurityManager() == null) { + thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), t); + } else { + thread = new InnocuousThread(t); } + thread.setContextClassLoader(null); + Runtime.getRuntime().addShutdownHook(thread); + return null; }); } diff --git a/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLRenderQueue.java b/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLRenderQueue.java index ecf1ed3467b..9e45eb3d7a1 100644 --- a/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLRenderQueue.java +++ b/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLRenderQueue.java @@ -28,6 +28,8 @@ package sun.java2d.opengl; import sun.awt.util.ThreadGroupUtils; import sun.java2d.pipe.RenderBuffer; import sun.java2d.pipe.RenderQueue; +import sun.misc.InnocuousThread; + import static sun.java2d.pipe.BufferedOpCodes.*; import java.security.AccessController; import java.security.PrivilegedAction; @@ -48,9 +50,7 @@ public class OGLRenderQueue extends RenderQueue { * The thread must be a member of a thread group * which will not get GCed before VM exit. */ - flusher = AccessController.doPrivileged((PrivilegedAction) () -> { - return new QueueFlusher(ThreadGroupUtils.getRootThreadGroup()); - }); + flusher = AccessController.doPrivileged((PrivilegedAction) QueueFlusher::new); } /** @@ -115,7 +115,7 @@ public class OGLRenderQueue extends RenderQueue { * Returns true if the current thread is the OGL QueueFlusher thread. */ public static boolean isQueueFlusherThread() { - return (Thread.currentThread() == getInstance().flusher); + return (Thread.currentThread() == getInstance().flusher.thread); } public void flushNow() { @@ -153,16 +153,22 @@ public class OGLRenderQueue extends RenderQueue { refSet.clear(); } - private class QueueFlusher extends Thread { + private class QueueFlusher implements Runnable { private boolean needsFlush; private Runnable task; private Error error; + private final Thread thread; - public QueueFlusher(ThreadGroup threadGroup) { - super(threadGroup, "Java2D Queue Flusher"); - setDaemon(true); - setPriority(Thread.MAX_PRIORITY); - start(); + public QueueFlusher() { + String name = "Java2D Queue Flusher"; + if (System.getSecurityManager() == null) { + this.thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, name); + } else { + this.thread = new InnocuousThread(this, name); + } + thread.setDaemon(true); + thread.setPriority(Thread.MAX_PRIORITY); + thread.start(); } public synchronized void flushNow() { diff --git a/jdk/src/java.desktop/share/classes/sun/print/PrintJob2D.java b/jdk/src/java.desktop/share/classes/sun/print/PrintJob2D.java index 23e4ed4d64d..cab43fef354 100644 --- a/jdk/src/java.desktop/share/classes/sun/print/PrintJob2D.java +++ b/jdk/src/java.desktop/share/classes/sun/print/PrintJob2D.java @@ -71,6 +71,7 @@ import javax.print.attribute.standard.OrientationRequested; import javax.print.attribute.standard.MediaSizeName; import javax.print.attribute.standard.PageRanges; +import sun.misc.ManagedLocalsThread; import sun.print.SunPageSelection; import sun.print.SunMinMaxPage; @@ -986,8 +987,12 @@ public class PrintJob2D extends PrintJob implements Printable, Runnable { } private void startPrinterJobThread() { - - printerJobThread = new Thread(this, "printerJobThread"); + String name = "printerJobThread"; + if (System.getSecurityManager() == null) { + printerJobThread = new Thread(this, name); + } else { + printerJobThread = new ManagedLocalsThread(this, name); + } printerJobThread.start(); } diff --git a/jdk/src/java.desktop/share/classes/sun/print/ServiceNotifier.java b/jdk/src/java.desktop/share/classes/sun/print/ServiceNotifier.java index a6a6dbb6cdc..5172acaa58b 100644 --- a/jdk/src/java.desktop/share/classes/sun/print/ServiceNotifier.java +++ b/jdk/src/java.desktop/share/classes/sun/print/ServiceNotifier.java @@ -25,6 +25,8 @@ package sun.print; +import sun.misc.ManagedLocalsThread; + import java.util.Vector; import javax.print.PrintService; @@ -40,7 +42,7 @@ import javax.print.event.PrintServiceAttributeListener; * to obtain the state of the attributes and notifies the listeners of * any changes. */ -class ServiceNotifier extends Thread { +class ServiceNotifier extends ManagedLocalsThread { private PrintService service; private Vector listeners; @@ -48,7 +50,7 @@ class ServiceNotifier extends Thread { private PrintServiceAttributeSet lastSet; ServiceNotifier(PrintService service) { - super(service.getName() + " notifier"); + super((Runnable) null, service.getName() + " notifier"); this.service = service; listeners = new Vector<>(); try { diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11/GtkFileDialogPeer.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11/GtkFileDialogPeer.java index fad3b3b6c09..8c0dc54a3b8 100644 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/GtkFileDialogPeer.java +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/GtkFileDialogPeer.java @@ -29,6 +29,7 @@ import java.awt.peer.FileDialogPeer; import java.io.File; import java.io.FilenameFilter; import sun.awt.AWTAccessor; +import sun.misc.ManagedLocalsThread; /** * FileDialogPeer for the GtkFileChooser. @@ -111,13 +112,16 @@ final class GtkFileDialogPeer extends XDialogPeer implements FileDialogPeer { XToolkit.awtLock(); try { if (b) { - Thread t = new Thread() { - public void run() { - showNativeDialog(); - fd.setVisible(false); - } + Runnable task = () -> { + showNativeDialog(); + fd.setVisible(false); }; - t.start(); + if (System.getSecurityManager() == null) { + new Thread(task).start(); + } else { + new ManagedLocalsThread(task).start(); + } + } else { quit(); fd.setVisible(false); diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11/InfoWindow.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11/InfoWindow.java index 41d0ef0f2d0..33cc44fccec 100644 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/InfoWindow.java +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/InfoWindow.java @@ -29,6 +29,9 @@ import java.awt.*; import java.awt.event.*; import java.awt.peer.TrayIconPeer; import sun.awt.*; +import sun.misc.InnocuousThread; +import sun.misc.ManagedLocalsThread; + import java.awt.image.*; import java.text.BreakIterator; import java.util.concurrent.ArrayBlockingQueue; @@ -338,7 +341,7 @@ public abstract class InfoWindow extends Window { lineLabels[i].setBackground(Color.white); } - displayer.start(); + displayer.thread.start(); } public void display(String caption, String text, String messageType) { @@ -415,7 +418,7 @@ public abstract class InfoWindow extends Window { } public void dispose() { - displayer.interrupt(); + displayer.thread.interrupt(); super.dispose(); } @@ -444,16 +447,23 @@ public abstract class InfoWindow extends Window { } } - private class Displayer extends Thread { + private class Displayer implements Runnable { final int MAX_CONCURRENT_MSGS = 10; ArrayBlockingQueue messageQueue = new ArrayBlockingQueue(MAX_CONCURRENT_MSGS); boolean isDisplayed; + final Thread thread; Displayer() { - setDaemon(true); + if (System.getSecurityManager() == null) { + this.thread = new Thread(this); + } else { + this.thread = new ManagedLocalsThread(this); + } + this.thread.setDaemon(true); } + @Override public void run() { while (true) { Message msg = null; diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java index bfe94c9f27c..3adbc8d35c5 100644 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java @@ -266,21 +266,26 @@ public final class XToolkit extends UNIXToolkit implements Runnable { awtUnlock(); } PrivilegedAction a = () -> { - Thread shutdownThread = new Thread(ThreadGroupUtils.getRootThreadGroup(), "XToolkt-Shutdown-Thread") { - public void run() { - XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance(); - if (peer != null) { - peer.dispose(); - } - if (xs != null) { - ((XAWTXSettings)xs).dispose(); - } - freeXKB(); - if (log.isLoggable(PlatformLogger.Level.FINE)) { - dumpPeers(); - } - } - }; + Runnable r = () -> { + XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance(); + if (peer != null) { + peer.dispose(); + } + if (xs != null) { + ((XAWTXSettings)xs).dispose(); + } + freeXKB(); + if (log.isLoggable(PlatformLogger.Level.FINE)) { + dumpPeers(); + } + }; + String name = "XToolkt-Shutdown-Thread"; + Thread shutdownThread; + if (System.getSecurityManager() == null) { + shutdownThread = new Thread(ThreadGroupUtils.getRootThreadGroup(), r, name); + } else { + shutdownThread = new InnocuousThread(r, name); + } shutdownThread.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(shutdownThread); return null; @@ -326,7 +331,13 @@ public final class XToolkit extends UNIXToolkit implements Runnable { XWM.init(); toolkitThread = AccessController.doPrivileged((PrivilegedAction) () -> { - Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), XToolkit.this, "AWT-XAWT"); + String name = "AWT-XAWT"; + Thread thread; + if (System.getSecurityManager() == null) { + thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), XToolkit.this, name); + } else { + thread = new InnocuousThread(XToolkit.this, name); + } thread.setContextClassLoader(null); thread.setPriority(Thread.NORM_PRIORITY + 1); thread.setDaemon(true); diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java index 009035326d9..93511617183 100644 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java @@ -43,6 +43,7 @@ import sun.java2d.xr.XRGraphicsConfig; import sun.java2d.loops.SurfaceType; import sun.awt.util.ThreadGroupUtils; +import sun.misc.InnocuousThread; /** * This is an implementation of a GraphicsDevice object for a single @@ -428,7 +429,6 @@ public class X11GraphicsDevice // hook will have no effect) shutdownHookRegistered = true; PrivilegedAction a = () -> { - ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); Runnable r = () -> { Window old = getFullScreenWindow(); if (old != null) { @@ -436,7 +436,13 @@ public class X11GraphicsDevice setDisplayMode(origDisplayMode); } }; - Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen); + String name = "Display-Change-Shutdown-Thread-" + screen; + Thread t; + if (System.getSecurityManager() == null) { + t = new Thread(ThreadGroupUtils.getRootThreadGroup(), r, name); + } else { + t = new InnocuousThread(r, name); + } t.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(t); return null; diff --git a/jdk/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java b/jdk/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java index 96acd53d58a..e40ba274b46 100644 --- a/jdk/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java +++ b/jdk/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java @@ -25,6 +25,8 @@ package sun.print; +import sun.misc.ManagedLocalsThread; + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStream; @@ -211,7 +213,12 @@ public class PrintServiceLookupProvider extends PrintServiceLookup public PrintServiceLookupProvider() { // start the printer listener thread if (pollServices) { - PrinterChangeListener thr = new PrinterChangeListener(); + Thread thr; + if (System.getSecurityManager() == null) { + thr = new Thread(new PrinterChangeListener()); + } else { + thr = new ManagedLocalsThread(new PrinterChangeListener()); + } thr.setDaemon(true); thr.start(); IPPPrintService.debug_println(debugPrefix+"polling turned on"); @@ -934,8 +941,9 @@ public class PrintServiceLookupProvider extends PrintServiceLookup } } - private class PrinterChangeListener extends Thread { + private class PrinterChangeListener implements Runnable { + @Override public void run() { int refreshSecs; while (true) { @@ -954,7 +962,7 @@ public class PrintServiceLookupProvider extends PrintServiceLookup refreshSecs = minRefreshTime; } try { - sleep(refreshSecs * 1000); + Thread.sleep(refreshSecs * 1000); } catch (InterruptedException e) { break; } diff --git a/jdk/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java b/jdk/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java index 1f3e2c3e987..52d198f034c 100644 --- a/jdk/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java +++ b/jdk/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java @@ -41,6 +41,7 @@ import java.util.stream.Stream; import static sun.awt.shell.Win32ShellFolder2.*; import sun.awt.OSInfo; import sun.awt.util.ThreadGroupUtils; +import sun.misc.InnocuousThread; // NOTE: This class supersedes Win32ShellFolderManager, which was removed // from distribution after version 1.4.2. @@ -516,26 +517,22 @@ final class Win32ShellFolderManager2 extends ShellFolderManager { private static Thread comThread; private ComInvoker() { - super(1, 1, 0, TimeUnit.DAYS, new LinkedBlockingQueue()); + super(1, 1, 0, TimeUnit.DAYS, new LinkedBlockingQueue<>()); allowCoreThreadTimeOut(false); setThreadFactory(this); - final Runnable shutdownHook = new Runnable() { - public void run() { - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - shutdownNow(); - return null; - } - }); - } - }; - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - Runtime.getRuntime().addShutdownHook( - new Thread(shutdownHook) - ); - return null; + final Runnable shutdownHook = () -> AccessController.doPrivileged((PrivilegedAction) () -> { + shutdownNow(); + return null; + }); + AccessController.doPrivileged((PrivilegedAction) () -> { + Thread t; + if (System.getSecurityManager() == null) { + t = new Thread(ThreadGroupUtils.getRootThreadGroup(), shutdownHook); + } else { + t = new InnocuousThread(shutdownHook); } + Runtime.getRuntime().addShutdownHook(t); + return null; }); } @@ -550,17 +547,22 @@ final class Win32ShellFolderManager2 extends ShellFolderManager { } } }; - comThread = AccessController.doPrivileged((PrivilegedAction) () -> { - /* The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); - Thread thread = new Thread(rootTG, comRun, "Swing-Shell"); - thread.setDaemon(true); - return thread; - } - ); + comThread = AccessController.doPrivileged((PrivilegedAction) () -> { + String name = "Swing-Shell"; + Thread thread; + if (System.getSecurityManager() == null) { + /* The thread must be a member of a thread group + * which will not get GCed before VM exit. + * Make its parent the top-level thread group. + */ + thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), comRun, name); + } else { + /* InnocuousThread is a member of a correct TG by default */ + thread = new InnocuousThread(comRun, name); + } + thread.setDaemon(true); + return thread; + }); return comThread; } diff --git a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java index beeb1031332..81a28c6b7d3 100644 --- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java +++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java @@ -36,6 +36,7 @@ import java.util.MissingResourceException; import java.util.Vector; import sun.awt.CausedFocusEvent; import sun.awt.AWTAccessor; +import sun.misc.ManagedLocalsThread; final class WFileDialogPeer extends WWindowPeer implements FileDialogPeer { @@ -97,12 +98,11 @@ final class WFileDialogPeer extends WWindowPeer implements FileDialogPeer { @Override public void show() { - new Thread(new Runnable() { - @Override - public void run() { - _show(); - } - }).start(); + if (System.getSecurityManager() == null) { + new Thread(this::_show).start(); + } else { + new ManagedLocalsThread(this::_show).start(); + } } @Override diff --git a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPageDialogPeer.java b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPageDialogPeer.java index 78a1c04cf12..7a146d965cd 100644 --- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPageDialogPeer.java +++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPageDialogPeer.java @@ -25,6 +25,8 @@ package sun.awt.windows; +import sun.misc.ManagedLocalsThread; + final class WPageDialogPeer extends WPrintDialogPeer { WPageDialogPeer(WPageDialog target) { @@ -39,20 +41,22 @@ final class WPageDialogPeer extends WPrintDialogPeer { @Override public void show() { - new Thread(new Runnable() { - @Override - public void run() { - // Call pageSetup even with no printer installed, this - // will display Windows error dialog and return false. - try { - ((WPrintDialog)target).setRetVal(_show()); - } catch (Exception e) { - // No exception should be thrown by native dialog code, - // but if it is we need to trap it so the thread does - // not hide is called and the thread doesn't hang. - } - ((WPrintDialog)target).setVisible(false); - } - }).start(); + Runnable runnable = () -> { + // Call pageSetup even with no printer installed, this + // will display Windows error dialog and return false. + try { + ((WPrintDialog)target).setRetVal(_show()); + } catch (Exception e) { + // No exception should be thrown by native dialog code, + // but if it is we need to trap it so the thread does + // not hide is called and the thread doesn't hang. + } + ((WPrintDialog)target).setVisible(false); + }; + if (System.getSecurityManager() == null) { + new Thread(runnable).start(); + } else { + new ManagedLocalsThread(runnable).start(); + } } } diff --git a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPrintDialogPeer.java b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPrintDialogPeer.java index d1efab01404..2f728f18899 100644 --- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPrintDialogPeer.java +++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPrintDialogPeer.java @@ -32,6 +32,7 @@ import java.awt.dnd.DropTarget; import java.util.Vector; import sun.awt.CausedFocusEvent; import sun.awt.AWTAccessor; +import sun.misc.ManagedLocalsThread; class WPrintDialogPeer extends WWindowPeer implements DialogPeer { @@ -67,19 +68,21 @@ class WPrintDialogPeer extends WWindowPeer implements DialogPeer { @Override public void show() { - new Thread(new Runnable() { - @Override - public void run() { - try { - ((WPrintDialog)target).setRetVal(_show()); - } catch (Exception e) { - // No exception should be thrown by native dialog code, - // but if it is we need to trap it so the thread does - // not hide is called and the thread doesn't hang. - } - ((WPrintDialog)target).setVisible(false); + Runnable runnable = () -> { + try { + ((WPrintDialog)target).setRetVal(_show()); + } catch (Exception e) { + // No exception should be thrown by native dialog code, + // but if it is we need to trap it so the thread does + // not hide is called and the thread doesn't hang. } - }).start(); + ((WPrintDialog)target).setVisible(false); + }; + if (System.getSecurityManager() == null) { + new Thread(runnable).start(); + } else { + new ManagedLocalsThread(runnable).start(); + } } synchronized void setHWnd(long hwnd) { diff --git a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java index 7915982c95a..50207fd0f52 100644 --- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java +++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java @@ -49,6 +49,7 @@ import sun.awt.datatransfer.DataTransferer; import sun.java2d.d3d.D3DRenderQueue; import sun.java2d.opengl.OGLRenderQueue; +import sun.misc.InnocuousThread; import sun.print.PrintJob2D; import java.awt.dnd.DragSource; @@ -247,11 +248,17 @@ public final class WToolkit extends SunToolkit implements Runnable { */ AWTAutoShutdown.notifyToolkitThreadBusy(); - // Find a root TG and attach Appkit thread to it + // Find a root TG and attach toolkit thread to it ThreadGroup rootTG = AccessController.doPrivileged( (PrivilegedAction) ThreadGroupUtils::getRootThreadGroup); if (!startToolkitThread(this, rootTG)) { - Thread toolkitThread = new Thread(rootTG, this, "AWT-Windows"); + String name = "AWT-Windows"; + Thread toolkitThread; + if (System.getSecurityManager() == null) { + toolkitThread = new Thread(rootTG, this, name); + } else { + toolkitThread = new InnocuousThread(this, name); + } toolkitThread.setDaemon(true); toolkitThread.start(); } @@ -278,7 +285,12 @@ public final class WToolkit extends SunToolkit implements Runnable { private void registerShutdownHook() { AccessController.doPrivileged((PrivilegedAction) () -> { - Thread shutdown = new Thread(ThreadGroupUtils.getRootThreadGroup(), this::shutdown); + Thread shutdown; + if (System.getSecurityManager() == null) { + shutdown = new Thread(ThreadGroupUtils.getRootThreadGroup(), this::shutdown); + } else { + shutdown = new InnocuousThread(this::shutdown); + } shutdown.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(shutdown); return null; diff --git a/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java b/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java index 1ab30124296..fd4bd592402 100644 --- a/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java +++ b/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java @@ -48,6 +48,7 @@ import sun.java2d.SurfaceData; import sun.java2d.windows.GDIWindowSurfaceData; import sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData; import sun.java2d.windows.WindowsFlags; +import sun.misc.InnocuousThread; /** * This class handles rendering to the screen with the D3D pipeline. @@ -92,22 +93,25 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager public D3DScreenUpdateManager() { done = false; - AccessController.doPrivileged( - (PrivilegedAction) () -> { - ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); - Thread shutdown = new Thread(rootTG, () -> { - done = true; - wakeUpUpdateThread(); - }); - shutdown.setContextClassLoader(null); - try { - Runtime.getRuntime().addShutdownHook(shutdown); - } catch (Exception e) { - done = true; - } - return null; - } - ); + AccessController.doPrivileged((PrivilegedAction) () -> { + Runnable shutdownRunnable = () -> { + done = true; + wakeUpUpdateThread(); + }; + Thread shutdown; + if (System.getSecurityManager() == null) { + shutdown = new Thread(ThreadGroupUtils.getRootThreadGroup(), shutdownRunnable); + } else { + shutdown = new InnocuousThread(shutdownRunnable); + } + shutdown.setContextClassLoader(null); + try { + Runtime.getRuntime().addShutdownHook(shutdown); + } catch (Exception e) { + done = true; + } + return null; + }); } /** @@ -345,17 +349,21 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager */ private synchronized void startUpdateThread() { if (screenUpdater == null) { - screenUpdater = AccessController.doPrivileged( - (PrivilegedAction) () -> { - ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); - Thread t = new Thread(rootTG, - D3DScreenUpdateManager.this, - "D3D Screen Updater"); - // REMIND: should it be higher? - t.setPriority(Thread.NORM_PRIORITY + 2); - t.setDaemon(true); - return t; - }); + screenUpdater = AccessController.doPrivileged((PrivilegedAction) () -> { + Thread t; + String name = "D3D Screen Updater"; + if (System.getSecurityManager() == null) { + t = new Thread(ThreadGroupUtils.getRootThreadGroup(), + D3DScreenUpdateManager.this, + name); + } else { + t = new InnocuousThread(D3DScreenUpdateManager.this, name); + } + // REMIND: should it be higher? + t.setPriority(Thread.NORM_PRIORITY + 2); + t.setDaemon(true); + return t; + }); screenUpdater.start(); } else { wakeUpUpdateThread(); diff --git a/jdk/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java b/jdk/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java index b3f56c8b55c..903673efdbf 100644 --- a/jdk/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java +++ b/jdk/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java @@ -25,6 +25,8 @@ package sun.print; +import sun.misc.ManagedLocalsThread; + import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -97,7 +99,12 @@ public class PrintServiceLookupProvider extends PrintServiceLookup { return; } // start the printer listener thread - PrinterChangeListener thr = new PrinterChangeListener(); + Thread thr; + if (System.getSecurityManager() == null) { + thr = new Thread(new PrinterChangeListener()); + } else { + thr = new ManagedLocalsThread(new PrinterChangeListener()); + } thr.setDaemon(true); thr.start(); } /* else condition ought to never happen! */ @@ -316,12 +323,13 @@ public class PrintServiceLookupProvider extends PrintServiceLookup { return defaultPrintService; } - class PrinterChangeListener extends Thread { + class PrinterChangeListener implements Runnable { long chgObj; PrinterChangeListener() { chgObj = notifyFirstPrinterChange(null); } + @Override public void run() { if (chgObj != -1) { while (true) { From 1392515988b84c8dc652570e1e21f23b84399b02 Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Fri, 3 Apr 2015 16:09:49 +0100 Subject: [PATCH 195/362] 8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference Reviewed-by: alanb --- .../MulticastSendReceiveTests.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/jdk/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java b/jdk/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java index 8f0f9a5fba3..848f2820954 100644 --- a/jdk/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java +++ b/jdk/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java @@ -97,7 +97,7 @@ public class MulticastSendReceiveTests { // no datagram received if (sa == null) { if (expectedSender != null) { - throw new RuntimeException("Expected message not recieved"); + throw new RuntimeException("Expected message not received"); } System.out.println("No message received (correct)"); return; @@ -109,10 +109,15 @@ public class MulticastSendReceiveTests { buf.flip(); byte[] bytes = new byte[buf.remaining()]; buf.get(bytes); - int receivedId = Integer.parseInt(new String(bytes)); - - System.out.format("Received message from %s (id=0x%x)\n", - sender, receivedId); + String s = new String(bytes, "UTF-8"); + int receivedId = -1; + try { + receivedId = Integer.parseInt(s); + System.out.format("Received message from %s (id=0x%x)\n", + sender, receivedId); + } catch (NumberFormatException x) { + System.out.format("Received message from %s (msg=%s)\n", sender, s); + } if (expectedSender == null) { if (receivedId == id) From b26b2b8c688304da2041144bd0d71ea3e9e75ebe Mon Sep 17 00:00:00 2001 From: Erik Joelsson Date: Fri, 3 Apr 2015 08:45:08 -0700 Subject: [PATCH 196/362] 8076531: Switch default compiler on Windows to VS2013 Reviewed-by: tbell --- README-builds.html | 58 +++++----- common/autoconf/generated-configure.sh | 6 +- common/autoconf/toolchain_windows.m4 | 18 ++-- make/jprt.properties | 140 +++++++++++++------------ 4 files changed, 114 insertions(+), 108 deletions(-) diff --git a/README-builds.html b/README-builds.html index 85a1040db38..edc8f742d65 100644 --- a/README-builds.html +++ b/README-builds.html @@ -441,7 +441,7 @@
  • Install - Visual Studio 2010 + Visual Studio 2013
  • @@ -750,23 +750,23 @@ -
    Visual Studio 2010 Compilers
    +
    Visual Studio 2013 Compilers

    The 32-bit and 64-bit OpenJDK Windows build requires - Microsoft Visual Studio C++ 2010 (VS2010) Professional + Microsoft Visual Studio C++ 2013 (VS2013) Professional Edition or Express compiler. The compiler and other tools are expected to reside in the location defined by the variable - VS100COMNTOOLS which + VS120COMNTOOLS which is set by the Microsoft Visual Studio installer.

    - Only the C++ part of VS2010 is needed. + Only the C++ part of VS2013 is needed. Try to let the installation go to the default install directory. - Always reboot your system after installing VS2010. - The system environment variable VS100COMNTOOLS + Always reboot your system after installing VS2013. + The system environment variable VS120COMNTOOLS should be set in your environment.

    @@ -1040,7 +1040,7 @@
    This is usually picked up automatically from the redist - directories of Visual Studio 2010. + directories of Visual Studio 2013. @@ -1854,54 +1854,54 @@ Linux X86 (32-bit) and X64 (64-bit) - Fedora 9 - gcc 4.3 - JDK 7u7 + Oracle Enterprise Linux 6.4 + gcc 4.8.2 + JDK 8 2 or more 1 GB 6 GB - Solaris SPARC (32-bit) and SPARCV9 (64-bit) - Solaris 10 Update 6 - Studio 12 Update 1 + patches - JDK 7u7 + Solaris SPARCV9 (64-bit) + Solaris 10 Update 10 + Studio 12 Update 3 + patches + JDK 8 4 or more 4 GB 8 GB - Solaris X86 (32-bit) and X64 (64-bit) - Solaris 10 Update 6 - Studio 12 Update 1 + patches - JDK 7u7 + Solaris X64 (64-bit) + Solaris 10 Update 10 + Studio 12 Update 3 + patches + JDK 8 4 or more 4 GB 8 GB Windows X86 (32-bit) - Windows XP - Microsoft Visual Studio C++ 2010 Professional Edition - JDK 7u7 + Windows Server 2012 R2 x64 + Microsoft Visual Studio C++ 2013 Professional Edition + JDK 8 2 or more 2 GB 6 GB Windows X64 (64-bit) - Windows Server 2003 - Enterprise x64 Edition - Microsoft Visual Studio C++ 2010 Professional Edition - JDK 7u7 + Windows Server 2012 R2 x64 + Microsoft Visual Studio C++ 2013 Professional Edition + JDK 8 2 or more 2 GB 6 GB Mac OS X X64 (64-bit) - Mac OS X 10.7 "Lion" - XCode 4.5.2 or newer - JDK 7u7 + Mac OS X 10.9 "Mavericks" + XCode 5.1.1 or newer + JDK 8 2 or more 4 GB 6 GB @@ -2009,7 +2009,7 @@

    Ubuntu 12.04

    -
    +
    After installing Ubuntu 12.04 you need to install several build dependencies. The simplest way to do it is to execute the following commands: diff --git a/common/autoconf/generated-configure.sh b/common/autoconf/generated-configure.sh index d7648b21e96..54b40ca2a39 100644 --- a/common/autoconf/generated-configure.sh +++ b/common/autoconf/generated-configure.sh @@ -4294,8 +4294,8 @@ TOOLCHAIN_DESCRIPTION_xlc="IBM XL C/C++" # ################################################################################ - -VALID_VS_VERSIONS="2010 2012 2013" +# The order of these defines the priority by which we try to find them. +VALID_VS_VERSIONS="2013 2012 2010" VS_DESCRIPTION_2010="Microsoft Visual Studio 2010" VS_VERSION_INTERNAL_2010=100 @@ -4369,7 +4369,7 @@ VS_SDK_PLATFORM_NAME_2013= #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1426774983 +DATE_WHEN_GENERATED=1428017006 ############################################################################### # diff --git a/common/autoconf/toolchain_windows.m4 b/common/autoconf/toolchain_windows.m4 index 78e03f78c40..dc1a24875c2 100644 --- a/common/autoconf/toolchain_windows.m4 +++ b/common/autoconf/toolchain_windows.m4 @@ -24,8 +24,8 @@ # ################################################################################ - -VALID_VS_VERSIONS="2010 2012 2013" +# The order of these defines the priority by which we try to find them. +VALID_VS_VERSIONS="2013 2012 2010" VS_DESCRIPTION_2010="Microsoft Visual Studio 2010" VS_VERSION_INTERNAL_2010=100 @@ -72,7 +72,7 @@ AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT], else VCVARSFILE="vc/bin/amd64/vcvars64.bat" fi - + BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(VS_BASE) if test -d "$VS_BASE"; then if test -f "$VS_BASE/$VCVARSFILE"; then @@ -404,7 +404,7 @@ AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL], METHOD="$3" if test -n "$POSSIBLE_MSVC_DLL" -a -e "$POSSIBLE_MSVC_DLL"; then AC_MSG_NOTICE([Found $1 at $POSSIBLE_MSVC_DLL using $METHOD]) - + # Need to check if the found msvcr is correct architecture AC_MSG_CHECKING([found $1 architecture]) MSVC_DLL_FILETYPE=`$FILE -b "$POSSIBLE_MSVC_DLL"` @@ -463,9 +463,9 @@ AC_DEFUN([TOOLCHAIN_SETUP_MSVC_DLL], TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL], [well-known location in Boot JDK]) fi - + if test "x$MSVC_DLL" = x; then - # Probe: Look in the Windows system32 directory + # Probe: Look in the Windows system32 directory CYGWIN_SYSTEMROOT="$SYSTEMROOT" BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_SYSTEMROOT) POSSIBLE_MSVC_DLL="$CYGWIN_SYSTEMROOT/system32/$DLL_NAME" @@ -489,7 +489,7 @@ AC_DEFUN([TOOLCHAIN_SETUP_MSVC_DLL], [search of VS100COMNTOOLS]) fi fi - + if test "x$MSVC_DLL" = x; then # Probe: Search wildly in the VCINSTALLDIR. We've probably lost by now. # (This was the original behaviour; kept since it might turn something up) @@ -506,12 +506,12 @@ AC_DEFUN([TOOLCHAIN_SETUP_MSVC_DLL], | $HEAD --lines 1` fi fi - + TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL], [search of VCINSTALLDIR]) fi fi - + if test "x$MSVC_DLL" = x; then AC_MSG_CHECKING([for $DLL_NAME]) AC_MSG_RESULT([no]) diff --git a/make/jprt.properties b/make/jprt.properties index 15eccf8be1c..9af05c9b65f 100644 --- a/make/jprt.properties +++ b/make/jprt.properties @@ -119,6 +119,12 @@ jprt.i586.productOpen.build.configure.args= \ ${my.i586.default.build.configure.args} \ ${jprt.productOpen.build.configure.args} +jprt.windows_i586_6.2.build.configure.args= \ + --with-toolchain-version=2013 \ + ${jprt.i586.build.configure.args} +jprt.windows_x64_6.2.build.configure.args= \ + --with-toolchain-version=2013 + ######## # # Build targets and options (default/jdk) @@ -133,9 +139,9 @@ my.build.targets.default= \ solaris_x64_5.11-{product|fastdebug}, \ linux_i586_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \ - macosx_x64_10.7-{product|fastdebug}, \ - windows_i586_6.1-{product|fastdebug}, \ - windows_x64_6.1-{product|fastdebug} + macosx_x64_10.9-{product|fastdebug}, \ + windows_i586_6.2-{product|fastdebug}, \ + windows_x64_6.2-{product|fastdebug} # Test target list (no fastdebug & limited c2 testing) my.test.target.set= \ @@ -143,9 +149,9 @@ my.test.target.set= \ solaris_x64_5.11-product-c2-TESTNAME, \ linux_i586_2.6-product-{c1|c2}-TESTNAME, \ linux_x64_2.6-product-c2-TESTNAME, \ - macosx_x64_10.7-product-c2-TESTNAME, \ - windows_i586_6.1-product-c1-TESTNAME, \ - windows_x64_6.1-product-c2-TESTNAME + macosx_x64_10.9-product-c2-TESTNAME, \ + windows_i586_6.2-product-c1-TESTNAME, \ + windows_x64_6.2-product-c2-TESTNAME # Default vm test targets (testset=default) my.test.targets.default= \ @@ -255,9 +261,9 @@ my.build.targets.hotspot= \ solaris_x64_5.11-{product|fastdebug}, \ linux_i586_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \ - macosx_x64_10.7-{product|fastdebug}, \ - windows_i586_6.1-{product|fastdebug}, \ - windows_x64_6.1-{product|fastdebug}, \ + macosx_x64_10.9-{product|fastdebug}, \ + windows_i586_6.2-{product|fastdebug}, \ + windows_x64_6.2-{product|fastdebug}, \ solaris_x64_5.11-{debugOpen}, \ linux_x64_2.6-{productOpen}, \ ${my.additional.build.targets.hotspot} @@ -332,57 +338,57 @@ my.test.targets.hotspot.linux.x64= \ linux_x64_2.6-{product|fastdebug}-c2-jbb_ParOldGC my.test.targets.hotspot.macosx.x64= \ - macosx_x64_10.7-{product|fastdebug}-c2-jvm98, \ - macosx_x64_10.7-{product|fastdebug}-c2-jvm98_nontiered, \ - macosx_x64_10.7-{product|fastdebug}-c2-scimark, \ - macosx_x64_10.7-{product|fastdebug}-c2-GCBasher_SerialGC, \ - macosx_x64_10.7-{product|fastdebug}-c2-GCBasher_ParallelGC, \ - macosx_x64_10.7-{product|fastdebug}-c2-GCBasher_CMS, \ - macosx_x64_10.7-{product|fastdebug}-c2-GCBasher_G1, \ - macosx_x64_10.7-{product|fastdebug}-c2-GCBasher_ParOldGC, \ - macosx_x64_10.7-{product|fastdebug}-c2-jbb_default_nontiered, \ - macosx_x64_10.7-{product|fastdebug}-c2-jbb_ParallelGC, \ - macosx_x64_10.7-{product|fastdebug}-c2-jbb_G1, \ - macosx_x64_10.7-{product|fastdebug}-c2-jbb_ParOldGC + macosx_x64_10.9-{product|fastdebug}-c2-jvm98, \ + macosx_x64_10.9-{product|fastdebug}-c2-jvm98_nontiered, \ + macosx_x64_10.9-{product|fastdebug}-c2-scimark, \ + macosx_x64_10.9-{product|fastdebug}-c2-GCBasher_SerialGC, \ + macosx_x64_10.9-{product|fastdebug}-c2-GCBasher_ParallelGC, \ + macosx_x64_10.9-{product|fastdebug}-c2-GCBasher_CMS, \ + macosx_x64_10.9-{product|fastdebug}-c2-GCBasher_G1, \ + macosx_x64_10.9-{product|fastdebug}-c2-GCBasher_ParOldGC, \ + macosx_x64_10.9-{product|fastdebug}-c2-jbb_default_nontiered, \ + macosx_x64_10.9-{product|fastdebug}-c2-jbb_ParallelGC, \ + macosx_x64_10.9-{product|fastdebug}-c2-jbb_G1, \ + macosx_x64_10.9-{product|fastdebug}-c2-jbb_ParOldGC my.test.targets.hotspot.windows.i586= \ - windows_i586_6.1-{product|fastdebug}-{c1|c2}-jvm98, \ - windows_i586_6.1-{product|fastdebug}-c2-jvm98_nontiered, \ - windows_i586_6.1-{product|fastdebug}-{c1|c2}-scimark, \ - windows_i586_6.1-product-{c1|c2}-runThese8, \ - windows_i586_6.1-product-{c1|c2}-runThese8_Xcomp_lang, \ - windows_i586_6.1-product-{c1|c2}-runThese8_Xcomp_vm, \ - windows_i586_6.1-fastdebug-c1-runThese8_Xshare, \ - windows_i586_6.1-{product|fastdebug}-{c1|c2}-GCBasher_SerialGC, \ - windows_i586_6.1-{product|fastdebug}-{c1|c2}-GCBasher_ParallelGC, \ - windows_i586_6.1-{product|fastdebug}-{c1|c2}-GCBasher_CMS, \ - windows_i586_6.1-{product|fastdebug}-{c1|c2}-GCBasher_G1, \ - windows_i586_6.1-{product|fastdebug}-{c1|c2}-GCBasher_ParOldGC, \ - windows_i586_6.1-{product|fastdebug}-{c1|c2}-jbb_default, \ - windows_i586_6.1-{product|fastdebug}-c2-jbb_default_nontiered, \ - windows_i586_6.1-product-{c1|c2}-jbb_ParallelGC, \ - windows_i586_6.1-product-{c1|c2}-jbb_CMS, \ - windows_i586_6.1-product-{c1|c2}-jbb_G1, \ - windows_i586_6.1-product-{c1|c2}-jbb_ParOldGC + windows_i586_6.2-{product|fastdebug}-{c1|c2}-jvm98, \ + windows_i586_6.2-{product|fastdebug}-c2-jvm98_nontiered, \ + windows_i586_6.2-{product|fastdebug}-{c1|c2}-scimark, \ + windows_i586_6.2-product-{c1|c2}-runThese8, \ + windows_i586_6.2-product-{c1|c2}-runThese8_Xcomp_lang, \ + windows_i586_6.2-product-{c1|c2}-runThese8_Xcomp_vm, \ + windows_i586_6.2-fastdebug-c1-runThese8_Xshare, \ + windows_i586_6.2-{product|fastdebug}-{c1|c2}-GCBasher_SerialGC, \ + windows_i586_6.2-{product|fastdebug}-{c1|c2}-GCBasher_ParallelGC, \ + windows_i586_6.2-{product|fastdebug}-{c1|c2}-GCBasher_CMS, \ + windows_i586_6.2-{product|fastdebug}-{c1|c2}-GCBasher_G1, \ + windows_i586_6.2-{product|fastdebug}-{c1|c2}-GCBasher_ParOldGC, \ + windows_i586_6.2-{product|fastdebug}-{c1|c2}-jbb_default, \ + windows_i586_6.2-{product|fastdebug}-c2-jbb_default_nontiered, \ + windows_i586_6.2-product-{c1|c2}-jbb_ParallelGC, \ + windows_i586_6.2-product-{c1|c2}-jbb_CMS, \ + windows_i586_6.2-product-{c1|c2}-jbb_G1, \ + windows_i586_6.2-product-{c1|c2}-jbb_ParOldGC my.test.targets.hotspot.windows.x64= \ - windows_x64_6.1-{product|fastdebug}-c2-jvm98, \ - windows_x64_6.1-{product|fastdebug}-c2-jvm98_nontiered, \ - windows_x64_6.1-{product|fastdebug}-c2-scimark, \ - windows_x64_6.1-product-c2-runThese8, \ - windows_x64_6.1-product-c2-runThese8_Xcomp_lang, \ - windows_x64_6.1-product-c2-runThese8_Xcomp_vm, \ - windows_x64_6.1-{product|fastdebug}-c2-GCBasher_SerialGC, \ - windows_x64_6.1-{product|fastdebug}-c2-GCBasher_ParallelGC, \ - windows_x64_6.1-{product|fastdebug}-c2-GCBasher_CMS, \ - windows_x64_6.1-{product|fastdebug}-c2-GCBasher_G1, \ - windows_x64_6.1-{product|fastdebug}-c2-GCBasher_ParOldGC, \ - windows_x64_6.1-{product|fastdebug}-c2-jbb_default, \ - windows_x64_6.1-{product|fastdebug}-c2-jbb_default_nontiered, \ - windows_x64_6.1-product-c2-jbb_CMS, \ - windows_x64_6.1-product-c2-jbb_ParallelGC, \ - windows_x64_6.1-product-c2-jbb_G1, \ - windows_x64_6.1-product-c2-jbb_ParOldGC + windows_x64_6.2-{product|fastdebug}-c2-jvm98, \ + windows_x64_6.2-{product|fastdebug}-c2-jvm98_nontiered, \ + windows_x64_6.2-{product|fastdebug}-c2-scimark, \ + windows_x64_6.2-product-c2-runThese8, \ + windows_x64_6.2-product-c2-runThese8_Xcomp_lang, \ + windows_x64_6.2-product-c2-runThese8_Xcomp_vm, \ + windows_x64_6.2-{product|fastdebug}-c2-GCBasher_SerialGC, \ + windows_x64_6.2-{product|fastdebug}-c2-GCBasher_ParallelGC, \ + windows_x64_6.2-{product|fastdebug}-c2-GCBasher_CMS, \ + windows_x64_6.2-{product|fastdebug}-c2-GCBasher_G1, \ + windows_x64_6.2-{product|fastdebug}-c2-GCBasher_ParOldGC, \ + windows_x64_6.2-{product|fastdebug}-c2-jbb_default, \ + windows_x64_6.2-{product|fastdebug}-c2-jbb_default_nontiered, \ + windows_x64_6.2-product-c2-jbb_CMS, \ + windows_x64_6.2-product-c2-jbb_ParallelGC, \ + windows_x64_6.2-product-c2-jbb_G1, \ + windows_x64_6.2-product-c2-jbb_ParOldGC # Some basic "smoke" tests for OpenJDK builds my.test.targets.hotspot.open= \ @@ -411,36 +417,36 @@ my.test.targets.hotspot= \ my.make.rule.test.targets.hotspot.clienttests= \ linux_i586_2.6-*-c1-hotspot_clienttest, \ - windows_i586_6.1-*-c1-hotspot_clienttest + windows_i586_6.2-*-c1-hotspot_clienttest my.make.rule.test.targets.hotspot.servertests= \ solaris_sparcv9_5.11-*-c2-hotspot_servertest, \ solaris_x64_5.11-*-c2-hotspot_servertest, \ linux_i586_2.6-*-c2-hotspot_servertest, \ linux_x64_2.6-*-c2-hotspot_servertest, \ - macosx_x64_10.7-*-c2-hotspot_servertest, \ - windows_i586_6.1-*-c2-hotspot_servertest, \ - windows_x64_6.1-*-c2-hotspot_servertest + macosx_x64_10.9-*-c2-hotspot_servertest, \ + windows_i586_6.2-*-c2-hotspot_servertest, \ + windows_x64_6.2-*-c2-hotspot_servertest my.make.rule.test.targets.hotspot.internalvmtests= \ solaris_sparcv9_5.11-fastdebug-c2-hotspot_internalvmtests, \ solaris_x64_5.11-fastdebug-c2-hotspot_internalvmtests, \ linux_i586_2.6-fastdebug-c2-hotspot_internalvmtests, \ linux_x64_2.6-fastdebug-c2-hotspot_internalvmtests, \ - macosx_x64_10.7-fastdebug-c2-hotspot_internalvmtests, \ - windows_i586_6.1-fastdebug-c2-hotspot_internalvmtests, \ - windows_x64_6.1-fastdebug-c2-hotspot_internalvmtests + macosx_x64_10.9-fastdebug-c2-hotspot_internalvmtests, \ + windows_i586_6.2-fastdebug-c2-hotspot_internalvmtests, \ + windows_x64_6.2-fastdebug-c2-hotspot_internalvmtests my.make.rule.test.targets.hotspot.reg.group= \ solaris_sparcv9_5.11-fastdebug-c2-GROUP, \ solaris_x64_5.11-fastdebug-c2-GROUP, \ linux_i586_2.6-fastdebug-c2-GROUP, \ linux_x64_2.6-fastdebug-c2-GROUP, \ - macosx_x64_10.7-fastdebug-c2-GROUP, \ - windows_i586_6.1-fastdebug-c2-GROUP, \ - windows_x64_6.1-fastdebug-c2-GROUP, \ + macosx_x64_10.9-fastdebug-c2-GROUP, \ + windows_i586_6.2-fastdebug-c2-GROUP, \ + windows_x64_6.2-fastdebug-c2-GROUP, \ linux_i586_2.6-fastdebug-c1-GROUP, \ - windows_i586_6.1-fastdebug-c1-GROUP + windows_i586_6.2-fastdebug-c1-GROUP my.make.rule.test.targets.hotspot= \ ${my.make.rule.test.targets.hotspot.clienttests}, \ From a9992adde7e87de10ba22bcf8e8c58805580da93 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Fri, 3 Apr 2015 10:41:34 -0700 Subject: [PATCH 197/362] 8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}} Reviewed-by: alexsch --- .../swing/plaf/metal/MetalFileChooserUI.java | 8 ++++++-- .../plaf/nimbus/AbstractRegionPainter.java | 12 +++++++++-- .../javax/swing/plaf/nimbus/NimbusStyle.java | 8 +++++++- .../plaf/synth/SynthInternalFrameUI.java | 6 +++++- .../swing/plaf/synth/SynthScrollBarUI.java | 7 ++++++- .../javax/swing/plaf/synth/SynthSliderUI.java | 6 +++++- .../javax/swing/table/AbstractTableModel.java | 7 +++---- .../swing/table/DefaultTableCellRenderer.java | 5 ++++- .../swing/table/DefaultTableColumnModel.java | 7 +++---- .../javax/swing/table/DefaultTableModel.java | 10 +--------- .../javax/swing/table/JTableHeader.java | 20 +++---------------- .../swing/tree/DefaultTreeCellEditor.java | 14 ++++++++++++- .../javax/swing/tree/DefaultTreeModel.java | 7 +++---- .../swing/tree/DefaultTreeSelectionModel.java | 7 +++---- .../swing/tree/FixedHeightLayoutCache.java | 6 ++++-- .../swing/tree/VariableHeightLayoutCache.java | 5 ++++- .../javax/swing/undo/CompoundEdit.java | 5 ++++- .../classes/javax/swing/undo/StateEdit.java | 10 +++++++++- .../javax/swing/undo/UndoableEditSupport.java | 14 ++++++++++++- 19 files changed, 106 insertions(+), 58 deletions(-) diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java index c35d96fe3d4..0e905398dac 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java @@ -569,7 +569,9 @@ public class MetalFileChooserUI extends BasicFileChooserUI { return super.createListSelectionListener(fc); } - // Obsolete class, not used in this version. + /** + * Obsolete class, not used in this version. + */ protected class SingleClickListener extends MouseAdapter { /** * Constructs an instance of {@code SingleClickListener}. @@ -580,7 +582,9 @@ public class MetalFileChooserUI extends BasicFileChooserUI { } } - // Obsolete class, not used in this version. + /** + * Obsolete class, not used in this version. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class FileRenderer extends DefaultListCellRenderer { } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java index c41d9247138..60537bf7564 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -495,8 +495,16 @@ public abstract class AbstractRegionPainter implements Painter { * control points and bezier curve anchors. */ protected static class PaintContext { + /** + * Cache mode. + */ protected static enum CacheMode { - NO_CACHING, FIXED_SIZES, NINE_SQUARE_SCALE + /** No caching.*/ + NO_CACHING, + /** Fixed sizes.*/ + FIXED_SIZES, + /** Nine square scale.*/ + NINE_SQUARE_SCALE } private static Insets EMPTY_INSETS = new Insets(0, 0, 0, 0); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/NimbusStyle.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/NimbusStyle.java index 9eb6d80ba0d..7fdbe384f57 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/NimbusStyle.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/NimbusStyle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -120,11 +120,17 @@ import java.util.TreeMap; */ public final class NimbusStyle extends SynthStyle { /* Keys and scales for large/small/mini components, based on Apples sizes */ + /** Large key */ public static final String LARGE_KEY = "large"; + /** Small key */ public static final String SMALL_KEY = "small"; + /** Mini key */ public static final String MINI_KEY = "mini"; + /** Large scale */ public static final double LARGE_SCALE = 1.15; + /** Small scale */ public static final double SMALL_SCALE = 0.857; + /** Mini scale */ public static final double MINI_SCALE = 0.714; /** diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthInternalFrameUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthInternalFrameUI.java index c5c1ef7fdad..8ed25333234 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthInternalFrameUI.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthInternalFrameUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -56,6 +56,10 @@ public class SynthInternalFrameUI extends BasicInternalFrameUI return new SynthInternalFrameUI((JInternalFrame)b); } + /** + * Constructs a {@code SynthInternalFrameUI}. + * @param b an internal frame + */ protected SynthInternalFrameUI(JInternalFrame b) { super(b); } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthScrollBarUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthScrollBarUI.java index 498d69e1e86..bf86f377412 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthScrollBarUI.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthScrollBarUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -48,6 +48,11 @@ public class SynthScrollBarUI extends BasicScrollBarUI private boolean validMinimumThumbSize; + /** + * Returns a UI. + * @return a UI + * @param c a component + */ public static ComponentUI createUI(JComponent c) { return new SynthScrollBarUI(); } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java index 912f3f43e7f..9c222e1a925 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -93,6 +93,10 @@ public class SynthSliderUI extends BasicSliderUI return new SynthSliderUI((JSlider)c); } + /** + * Constructs a {@code SynthSliderUI}. + * @param c a slider + */ protected SynthSliderUI(JSlider c) { super(c); } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/table/AbstractTableModel.java b/jdk/src/java.desktop/share/classes/javax/swing/table/AbstractTableModel.java index d7c63bce05a..bc1c9ef8887 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/table/AbstractTableModel.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/table/AbstractTableModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -320,9 +320,8 @@ public abstract class AbstractTableModel implements TableModel, Serializable * * If no such listeners exist, this method returns an empty array. * - * @param listenerType the type of listeners requested; this parameter - * should specify an interface that descends from - * java.util.EventListener + * @param the listener type + * @param listenerType the type of listeners requested * @return an array of all objects registered as * FooListeners on this component, * or an empty array if no such diff --git a/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableCellRenderer.java b/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableCellRenderer.java index 123ac8d5e64..0a7504da6ea 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableCellRenderer.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableCellRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -95,6 +95,9 @@ public class DefaultTableCellRenderer extends JLabel */ private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1); private static final Border DEFAULT_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1); + /** + * A border without focus. + */ protected static Border noFocusBorder = DEFAULT_NO_FOCUS_BORDER; // We need a place to store the color the JLabel should be returned diff --git a/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableColumnModel.java b/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableColumnModel.java index 16a11995847..af19749c9d3 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableColumnModel.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableColumnModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -652,9 +652,8 @@ public class DefaultTableColumnModel implements TableColumnModel, * * If no such listeners exist, this method returns an empty array. * - * @param listenerType the type of listeners requested; this parameter - * should specify an interface that descends from - * java.util.EventListener + * @param the listener type + * @param listenerType the type of listeners requested * @return an array of all objects registered as * FooListeners on this model, * or an empty array if no such diff --git a/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableModel.java b/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableModel.java index 2d34384693b..58e79cd0fb7 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableModel.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -314,15 +314,7 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl /** * Obsolete as of Java 2 platform v1.3. Please use setRowCount instead. - */ - /* - * Sets the number of rows in the model. If the new size is greater - * than the current size, new rows are added to the end of the model - * If the new size is less than the current size, all - * rows at index rowCount and greater are discarded. - * * @param rowCount the new number of rows - * @see #setRowCount */ public void setNumRows(int rowCount) { int old = getRowCount(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java b/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java index fbf742a43c1..12ebf26ee51 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -281,14 +281,8 @@ public class JTableHeader extends JComponent implements TableColumnModelListener /** * Obsolete as of Java 2 platform v1.3. Real time repaints, in response to * column dragging or resizing, are now unconditional. - */ - /* - * Sets whether the body of the table updates in real time when - * a column is resized or dragged. - * - * @param flag true if tableView should update - * the body of the table in real time - * @see #getUpdateTableInRealTime + * @param flag true if tableView should update the body of the + * table in real time */ public void setUpdateTableInRealTime(boolean flag) { updateTableInRealTime = flag; @@ -297,15 +291,7 @@ public class JTableHeader extends JComponent implements TableColumnModelListener /** * Obsolete as of Java 2 platform v1.3. Real time repaints, in response to * column dragging or resizing, are now unconditional. - */ - /* - * Returns true if the body of the table view updates in real - * time when a column is resized or dragged. User can set this flag to - * false to speed up the table's response to user resize or drag actions. - * The default is true. - * * @return true if the table updates in real time - * @see #setUpdateTableInRealTime */ public boolean getUpdateTableInRealTime() { return updateTableInRealTime; diff --git a/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellEditor.java b/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellEditor.java index 7f401775001..fdd8e5c1cc5 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellEditor.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -477,6 +477,15 @@ public class DefaultTreeCellEditor implements ActionListener, TreeCellEditor, return true; } + /** + * Determine the offset. + * @param tree a JTree object + * @param value a value + * @param isSelected selection status + * @param expanded expansion status + * @param leaf leaf status + * @param row current row + */ protected void determineOffset(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { @@ -653,6 +662,9 @@ public class DefaultTreeCellEditor implements ActionListener, TreeCellEditor, // This should not be used. It will be removed when new API is // allowed. + /** + * Do not use. + */ public void EditorContainer() { setLayout(null); } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeModel.java b/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeModel.java index d3f9a2e1e16..29ae359b782 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeModel.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -657,9 +657,8 @@ public class DefaultTreeModel implements Serializable, TreeModel { * * If no such listeners exist, this method returns an empty array. * - * @param listenerType the type of listeners requested; this parameter - * should specify an interface that descends from - * java.util.EventListener + * @param the listener type + * @param listenerType the type of listeners requested * @return an array of all objects registered as * FooListeners on this component, * or an empty array if no such diff --git a/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeSelectionModel.java b/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeSelectionModel.java index b46bb1ec8c2..810262b97f4 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeSelectionModel.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeSelectionModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -664,9 +664,8 @@ public class DefaultTreeSelectionModel implements Cloneable, Serializable, TreeS * * If no such listeners exist, this method returns an empty array. * - * @param listenerType the type of listeners requested; this parameter - * should specify an interface that descends from - * java.util.EventListener + * @param the listener type + * @param listenerType the type of listeners requested * @return an array of all objects registered as * FooListeners on this component, * or an empty array if no such diff --git a/jdk/src/java.desktop/share/classes/javax/swing/tree/FixedHeightLayoutCache.java b/jdk/src/java.desktop/share/classes/javax/swing/tree/FixedHeightLayoutCache.java index fe2ad0b263c..a6aa7520409 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/tree/FixedHeightLayoutCache.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/tree/FixedHeightLayoutCache.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -74,7 +74,9 @@ public class FixedHeightLayoutCache extends AbstractLayoutCache { private Stack> tempStacks; - + /** + * Constructs a {@code FixedHeightLayoutCache}. + */ public FixedHeightLayoutCache() { super(); tempStacks = new Stack>(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java b/jdk/src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java index f2944365cc0..470f07d930a 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -88,6 +88,9 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache { private Stack> tempStacks; + /** + * Constructs a {@code VariableHeightLayoutCache}. + */ public VariableHeightLayoutCache() { super(); tempStacks = new Stack>(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/undo/CompoundEdit.java b/jdk/src/java.desktop/share/classes/javax/swing/undo/CompoundEdit.java index 3732d554169..18e5368a198 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/undo/CompoundEdit.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/undo/CompoundEdit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -45,6 +45,9 @@ public class CompoundEdit extends AbstractUndoableEdit { */ protected Vector edits; + /** + * Constructs a {@code CompoundEdit}. + */ public CompoundEdit() { super(); inProgress = true; diff --git a/jdk/src/java.desktop/share/classes/javax/swing/undo/StateEdit.java b/jdk/src/java.desktop/share/classes/javax/swing/undo/StateEdit.java index 177fa129cfb..3988b313bc3 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/undo/StateEdit.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/undo/StateEdit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -59,6 +59,9 @@ import java.util.Vector; public class StateEdit extends AbstractUndoableEdit { + /** + * Obsolete RCS version identity. + */ protected static final String RCSID = "$Id: StateEdit.java,v 1.6 1997/10/01 20:05:51 sandipc Exp $"; // @@ -114,6 +117,11 @@ public class StateEdit init (anObject,name); } + /** + * Initialize the state edit. + * @param anObject The object to watch for changing state + * @param name The presentation name to be used for this edit + */ protected void init (StateEditable anObject, String name) { this.object = anObject; this.preState = new Hashtable(11); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/undo/UndoableEditSupport.java b/jdk/src/java.desktop/share/classes/javax/swing/undo/UndoableEditSupport.java index 8f2c96e59ab..decd6afb9a0 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/undo/UndoableEditSupport.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/undo/UndoableEditSupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -34,9 +34,21 @@ import java.util.*; * @author Ray Ryan */ public class UndoableEditSupport { + /** + * The update level. + */ protected int updateLevel; + /** + * The compound edit. + */ protected CompoundEdit compoundEdit; + /** + * The list of listeners. + */ protected Vector listeners; + /** + * The real source. + */ protected Object realSource; /** From 4b07750bb17f6fb41ec1ade04dd5196ece9b3a49 Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Fri, 3 Apr 2015 15:23:02 -0700 Subject: [PATCH 198/362] 8076583: move jdk.Exported from langtools to jdk Reviewed-by: darcy, alanb, tbell, mchung, jlahoda --- langtools/make/CompileInterim.gmk | 1 - langtools/make/build.properties | 11 ++- langtools/make/build.xml | 4 - langtools/make/intellij/langtools.iml | 2 - langtools/make/intellij/workspace.xml | 12 +-- .../netbeans/langtools/nbproject/project.xml | 60 +------------- .../java.base/share/classes/jdk/Exported.java | 80 ------------------- 7 files changed, 14 insertions(+), 156 deletions(-) delete mode 100644 langtools/src/java.base/share/classes/jdk/Exported.java diff --git a/langtools/make/CompileInterim.gmk b/langtools/make/CompileInterim.gmk index d3c78279b2a..c957a904978 100644 --- a/langtools/make/CompileInterim.gmk +++ b/langtools/make/CompileInterim.gmk @@ -43,7 +43,6 @@ $(eval $(call SetupJavaCompilation,BUILD_INTERIM_LANGTOOLS, \ $(LANGTOOLS_TOPDIR)/src/jdk.compiler/share/classes \ $(LANGTOOLS_TOPDIR)/src/jdk.dev/share/classes \ $(LANGTOOLS_TOPDIR)/src/jdk.javadoc/share/classes \ - $(LANGTOOLS_TOPDIR)/src/java.base/share/classes \ $(SUPPORT_OUTPUTDIR)/gensrc/jdk.compiler \ $(SUPPORT_OUTPUTDIR)/gensrc/jdk.dev \ $(SUPPORT_OUTPUTDIR)/gensrc/jdk.javadoc, \ diff --git a/langtools/make/build.properties b/langtools/make/build.properties index 2a12dbec711..dd902e0ad9e 100644 --- a/langtools/make/build.properties +++ b/langtools/make/build.properties @@ -47,12 +47,11 @@ boot.javac.source = 8 boot.javac.target = 8 #configuration of submodules (share by both the bootstrap and normal compilation): -langtools.modules=java.base:java.compiler:jdk.compiler:jdk.dev:jdk.javadoc -java.base.dependencies= -java.compiler.dependencies=java.base -jdk.compiler.dependencies=java.base:java.compiler -jdk.javadoc.dependencies=java.base:java.compiler:jdk.compiler -jdk.dev.dependencies=java.base:java.compiler:jdk.compiler +langtools.modules=java.compiler:jdk.compiler:jdk.dev:jdk.javadoc +java.compiler.dependencies= +jdk.compiler.dependencies=java.compiler +jdk.javadoc.dependencies=java.compiler:jdk.compiler +jdk.dev.dependencies=java.compiler:jdk.compiler javac.resource.includes = \ com/sun/tools/javac/resources/compiler.properties diff --git a/langtools/make/build.xml b/langtools/make/build.xml index bdaae283bde..e88cf9e76c4 100644 --- a/langtools/make/build.xml +++ b/langtools/make/build.xml @@ -254,7 +254,6 @@ warningsProperty="findbugs.all.warnings" jvm="${target.java.home}/bin/java" jvmargs="-Xmx512M"> - @@ -461,7 +460,6 @@ - @@ -522,8 +520,6 @@ - - - diff --git a/langtools/make/intellij/workspace.xml b/langtools/make/intellij/workspace.xml index bff7ec024c2..135f05a0fd3 100644 --- a/langtools/make/intellij/workspace.xml +++ b/langtools/make/intellij/workspace.xml @@ -10,7 +10,7 @@
    * *

    diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAnyElement.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAnyElement.java index 0fcd2dc372f..ce76369549a 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAnyElement.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAnyElement.java @@ -94,15 +94,15 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; *

    Schema To Java example

    * * The following schema would produce the following Java class: - *
    - * <xs:complexType name="foo">
    - *   <xs:sequence>
    - *     <xs:element name="a" type="xs:int" />
    - *     <xs:element name="b" type="xs:int" />
    - *     <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
    - *   </xs:sequence>
    - * </xs:complexType>
    - * 
    + *
    {@code
    + * 
    + *   
    + *     
    + *     
    + *     
    + *   
    + * 
    + * }
    * *
      * class Foo {
    @@ -115,30 +115,30 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
      *
      * It can unmarshal instances like
      *
    - * 
    - * <foo xmlns:e="extra">
    - *   <a>1</a>
    - *   <e:other />  // this will be bound to DOM, because unmarshalling is orderless
    - *   <b>3</b>
    - *   <e:other />
    - *   <c>5</c>     // this will be bound to DOM, because the annotation doesn't remember namespaces.
    - * </foo>
    - * 
    + *
    {@code
    + * 
    + *   1
    + *     // this will be bound to DOM, because unmarshalling is orderless
    + *   3
    + *   
    + *   5     // this will be bound to DOM, because the annotation doesn't remember namespaces.
    + * 
    + * }
    * * * * The following schema would produce the following Java class: - *
    - * <xs:complexType name="bar">
    - *   <xs:complexContent>
    - *   <xs:extension base="foo">
    - *     <xs:sequence>
    - *       <xs:element name="c" type="xs:int" />
    - *       <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
    - *     </xs:sequence>
    - *   </xs:extension>
    - * </xs:complexType>
    - * 
    + *
    {@code
    + * 
    + *   
    + *   
    + *     
    + *       
    + *       
    + *     
    + *   
    + * 
    + * }
    * *
      * class Bar extends Foo {
    @@ -150,16 +150,16 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
      *
      * It can unmarshal instances like
      *
    - * 
    - * <bar xmlns:e="extra">
    - *   <a>1</a>
    - *   <e:other />  // this will be bound to DOM, because unmarshalling is orderless
    - *   <b>3</b>
    - *   <e:other />
    - *   <c>5</c>     // this now goes to Bar.c
    - *   <e:other />  // this will go to Foo.any
    - * </bar>
    - * 
    + *
    {@code
    + * 
    + *   1
    + *     // this will be bound to DOM, because unmarshalling is orderless
    + *   3
    + *   
    + *   5     // this now goes to Bar.c
    + *     // this will go to Foo.any
    + * 
    + * }
    * * * @@ -171,15 +171,15 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; * *

    * The following schema would produce the following Java class: - *

    - * <xs:complexType name="foo">
    - *   <xs:choice maxOccurs="unbounded" minOccurs="0">
    - *     <xs:element name="a" type="xs:int" />
    - *     <xs:element name="b" type="xs:int" />
    - *     <xs:any namespace="##other" processContents="lax" />
    - *   </xs:choice>
    - * </xs:complexType>
    - * 
    + *
    {@code
    + * 
    + *   
    + *     
    + *     
    + *     
    + *   
    + * 
    + * }
    * *
      * class Foo {
    @@ -204,11 +204,11 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
      * It can unmarshal instances like
      *
      * 
    - * <foo xmlns:e="extra">
    - *   <a>1</a>     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
    - *   <e:other />  // this will unmarshal to a DOM {@link Element}.
    - *   <b>3</b>     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
    - * </foo>
    + *{@code }
    + *{@code   1}     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
    + *{@code   }  // this will unmarshal to a DOM {@link Element}.
    + *{@code   3}     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
    + *{@code }
      * 
    * * @@ -225,11 +225,11 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; * } *
    * then the following document will unmarshal like this: - *
    - * <foo>
    - *   <unknown />
    - *   <foo />
    - * </foo>
    + * 
    {@code
    + * 
    + *   
    + *   
    + * 
      *
      * Foo foo = unmarshal();
      * // 1 for 'unknown', another for 'foo'
    @@ -239,7 +239,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
      * // because of lax=true, the 'foo' element eagerly
      * // unmarshals to a Foo object.
      * assert foo.others[1] instanceof Foo;
    - * 
    + * }
    * * @author Kohsuke Kawaguchi * @since 1.6, JAXB 2.0 diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAttachmentRef.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAttachmentRef.java index 92d8e91eb3a..a658a0801cb 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAttachmentRef.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAttachmentRef.java @@ -51,16 +51,16 @@ import java.lang.annotation.Target; * } *
    * The above code maps to the following XML: - *
    - * <xs:element name="foo" xmlns:ref="http://ws-i.org/profiles/basic/1.1/xsd">
    - *   <xs:complexType>
    - *     <xs:sequence>
    - *       <xs:element name="body" type="ref:swaRef" minOccurs="0" />
    - *     </xs:sequence>
    - *     <xs:attribute name="data" type="ref:swaRef" use="optional" />
    - *   </xs:complexType>
    - * </xs:element>
    - * 
    + *
    {@code
    + * 
    + *   
    + *     
    + *       
    + *     
    + *     
    + *   
    + * 
    + * }
    * *

    * The above binding supports WS-I AP 1.0 WS-I Attachments Profile Version 1.0. diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAttribute.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAttribute.java index 8e367582ca3..713c5c0f5c0 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAttribute.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAttribute.java @@ -89,14 +89,15 @@ import static java.lang.annotation.RetentionPolicy.*; * public java.math.BigDecimal getPrice() {...} ; * public void setPrice(java.math.BigDecimal ) {...}; * } + * {@code * - * <!-- Example: XML Schema fragment --> - * <xs:complexType name="USPrice"> - * <xs:sequence> - * </xs:sequence> - * <xs:attribute name="price" type="xs:decimal"/> - * </xs:complexType> - *

    + * + * + * + * + * + * + * } * *

    Example 2: Map a JavaBean property to an XML attribute with anonymous type.

    * See Example 7 in @{@link XmlType}. @@ -108,17 +109,18 @@ import static java.lang.annotation.RetentionPolicy.*; * ... * @XmlAttribute List<Integer> items; * } + * {@code * - * <!-- Example: XML Schema fragment --> - * <xs:complexType name="foo"> + * + * * ... - * <xs:attribute name="items"> - * <xs:simpleType> - * <xs:list itemType="xs:int"/> - * </xs:simpleType> - * </xs:complexType> + * + * + * + * + * * - * + * } * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @see XmlType * @since 1.6, JAXB 2.0 diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElement.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElement.java index 3d7c89dc836..8f2d881236b 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElement.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElement.java @@ -82,14 +82,15 @@ import static java.lang.annotation.RetentionPolicy.*; * @XmlElement(name="itemprice") * public java.math.BigDecimal price; * } + * {@code * - * <!-- Example: Local XML Schema element --> - * <xs:complexType name="USPrice"/> - * <xs:sequence> - * <xs:element name="itemprice" type="xs:decimal" minOccurs="0"/> - * </sequence> - * </xs:complexType> - * + * + * + * + * + * + * + * } *

    * * Example 2: Map a field to a nillable element. @@ -100,14 +101,15 @@ import static java.lang.annotation.RetentionPolicy.*; * @XmlElement(nillable=true) * public java.math.BigDecimal price; * } + * {@code * - * <!-- Example: Local XML Schema element --> - * <xs:complexType name="USPrice"> - * <xs:sequence> - * <xs:element name="price" type="xs:decimal" nillable="true" minOccurs="0"/> - * </sequence> - * </xs:complexType> - * + * + * + * + * + * + * + * } *

    * Example 3: Map a field to a nillable, required element. *

    @@ -117,14 +119,15 @@ import static java.lang.annotation.RetentionPolicy.*;
      *         @XmlElement(nillable=true, required=true)
      *         public java.math.BigDecimal price;
      *     }
    + * {@code
      *
    - *     <!-- Example: Local XML Schema element -->
    - *     <xs:complexType name="USPrice">
    - *       <xs:sequence>
    - *         <xs:element name="price" type="xs:decimal" nillable="true" minOccurs="1"/>
    - *       </sequence>
    - *     </xs:complexType>
    - *   
    + * + * + * + * + * + * + * } * *

    Example 4: Map a JavaBean property to an XML element * with anonymous type.

    @@ -179,7 +182,7 @@ public @interface XmlElement { * the enclosing class. * *
  • - * Otherwise '' (which produces unqualified element in the default + * Otherwise {@literal ''} (which produces unqualified element in the default * namespace. * */ diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementDecl.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementDecl.java index 6920957a5e6..6d791e95c05 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementDecl.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementDecl.java @@ -65,21 +65,22 @@ import static java.lang.annotation.ElementType.METHOD; * JAXBElement<String> createFoo(String s) { ... } * } * - *
    - *     <!-- XML input -->
    - *       <foo>string</foo>
    + * 
     {@code
    + *
    + *     
    + *     string
      *
      *     // Example: code fragment corresponding to XML input
    - *     JAXBElement<String> o =
    - *     (JAXBElement<String>)unmarshaller.unmarshal(aboveDocument);
    + *     JAXBElement o =
    + *     (JAXBElement)unmarshaller.unmarshal(aboveDocument);
      *     // print JAXBElement instance to show values
      *     System.out.println(o.getName());   // prints  "{}foo"
      *     System.out.println(o.getValue());  // prints  "string"
      *     System.out.println(o.getValue().getClass()); // prints "java.lang.String"
      *
    - *     <!-- Example: XML schema definition -->
    - *     <xs:element name="foo" type="xs:string"/>
    - * 
    + * + * + * }
    * *

    Example 2: Element declaration with non local scope *

    @@ -90,18 +91,18 @@ import static java.lang.annotation.ElementType.METHOD; * The following example may be replaced in a future revision of * this javadoc. * - *

    - *     <!-- Example: XML schema definition -->
    - *     <xs:schema>
    - *       <xs:complexType name="pea">
    - *         <xs:choice maxOccurs="unbounded">
    - *           <xs:element name="foo" type="xs:string"/>
    - *           <xs:element name="bar" type="xs:string"/>
    - *         </xs:choice>
    - *       </xs:complexType>
    - *       <xs:element name="foo" type="xs:int"/>
    - *     </xs:schema>
    - * 
    + *
    {@code
    + *     
    + *     
    + *       
    + *         
    + *           
    + *           
    + *         
    + *       
    + *       
    + *     
    + * }
    *
      *     // Example: expected default binding
      *     class Pea {
    diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementRef.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementRef.java
    index 9f99ca3d80b..b420d7b1414 100644
    --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementRef.java
    +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementRef.java
    @@ -56,10 +56,10 @@ import static java.lang.annotation.ElementType.METHOD;
      * support for substitution groups using an element property,
      * (section 5.5.5, "Element Property" of JAXB 2.0 specification). An
      * element property method signature is of the form:
    - * 
    - *     public void setTerm(JAXBElement<? extends Operator>);
    - *     public JAXBElement<? extends Operator> getTerm();
    - * 
    + *
    {@code
    + *     public void setTerm(JAXBElement);
    + *     public JAXBElement getTerm();
    + * }
    *

    * An element factory method annotated with {@link XmlElementDecl} is * used to create a JAXBElement instance, containing an XML @@ -121,19 +121,20 @@ import static java.lang.annotation.ElementType.METHOD; * class JavacTask extends Task { * ... * } + * {@code * - * <!-- XML Schema fragment --> - * <xs:element name="target" type="Target"> - * <xs:complexType name="Target"> - * <xs:sequence> - * <xs:choice maxOccurs="unbounded"> - * <xs:element ref="jar"> - * <xs:element ref="javac"> - * </xs:choice> - * </xs:sequence> - * </xs:complexType> + * + * + * + * + * + * + * + * + * + * * - *

    + * } *

    * Thus the following code fragment: *

    @@ -143,16 +144,16 @@ import static java.lang.annotation.ElementType.METHOD;
      *     marshal(target);
      * 
    * will produce the following XML output: - *
    - *     <target>
    - *       <jar>
    + * 
    {@code
    + *     
    + *       
      *         ....
    - *       </jar>
    - *       <javac>
    + *       
    + *       
      *         ....
    - *       </javac>
    - *     </target>
    - * 
    + * + * + * }
    *

    * It is not an error to have a class that extends Task * that doesn't have {@link XmlRootElement}. But they can't show up in an @@ -207,11 +208,11 @@ import static java.lang.annotation.ElementType.METHOD; * marshal(m); * * will produce the following XML output: - *

    - *     <math>
    - *       <add>...</add>
    - *     </math>
    - * 
    + *
    {@code
    + *     
    + *       ...
    + *     
    + * }
    * * * @author
    • Kohsuke Kawaguchi, Sun Microsystems,Inc.
    • Sekhar Vajjhala, Sun Microsystems, Inc.
    diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementWrapper.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementWrapper.java index fc7d09c05e8..69f50411fdc 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementWrapper.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementWrapper.java @@ -39,21 +39,21 @@ import java.lang.annotation.Target; * XML element around collections. The annotation therefore supports * two forms of serialization shown below. * - *
    + * 
    {@code
      *    //Example: code fragment
      *      int[] names;
      *
      *    // XML Serialization Form 1 (Unwrapped collection)
    - *    <names> ... </names>
    - *    <names> ... </names>
    + *     ... 
    + *     ... 
      *
      *    // XML Serialization Form 2 ( Wrapped collection )
    - *    <wrapperElement>
    - *       <names> value-of-item </names>
    - *       <names> value-of-item </names>
    + *    
    + *        value-of-item 
    + *        value-of-item 
      *       ....
    - *    </wrapperElement>
    - * 
    + * + * }
    * *

    The two serialized XML forms allow a null collection to be * represented either by absence or presence of an element with a diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElements.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElements.java index e15bb1e4146..fb64513d697 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElements.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElements.java @@ -44,7 +44,7 @@ import java.lang.annotation.Target; * @XmlElements({ @XmlElement(...),@XmlElement(...) }) * * - *

    The @XmlElements annnotation can be used with the + *

    The @XmlElements annotation can be used with the * following program elements:

    *
      *
    • a JavaBean property
    • @@ -78,28 +78,29 @@ import java.lang.annotation.Target; * @XmlElements( * @XmlElement(name="A", type=Integer.class), * @XmlElement(name="B", type=Float.class) - * } + * ) * public List items; * } + * {@code * - * <!-- XML Representation for a List of {1,2.5} - * XML output is not wrapped using another element --> + * * ... - * <A> 1 </A> - * <B> 2.5 </B> + * 1 + * 2.5 * ... * - * <!-- XML Schema fragment --> - * <xs:complexType name="Foo"> - * <xs:sequence> - * <xs:choice minOccurs="0" maxOccurs="unbounded"> - * <xs:element name="A" type="xs:int"/> - * <xs:element name="B" type="xs:float"/> - * <xs:choice> - * </xs:sequence> - * </xs:complexType> + * + * + * + * + * + * + * + * + * * - * + * } * *

      Example 2: Map to a list of elements wrapped with another element *

      @@ -114,21 +115,22 @@ import java.lang.annotation.Target; * } * public List items; * } + * {@code * - * <!-- XML Schema fragment --> - * <xs:complexType name="Foo"> - * <xs:sequence> - * <xs:element name="bar"> - * <xs:complexType> - * <xs:choice minOccurs="0" maxOccurs="unbounded"> - * <xs:element name="A" type="xs:int"/> - * <xs:element name="B" type="xs:float"/> - * </xs:choice> - * </xs:complexType> - * </xs:element> - * </xs:sequence> - * </xs:complexType> - * + * + * + * + * + * + * + * + * + * + * + * + * + * + * } * *

      Example 3: Change element name based on type using an adapter. *

      @@ -145,21 +147,22 @@ import java.lang.annotation.Target; * @XmlType abstract class P {...} * @XmlType(name="PX") class PX extends P {...} * @XmlType(name="PY") class PY extends P {...} + * {@code * - * <!-- XML Schema fragment --> - * <xs:complexType name="Foo"> - * <xs:sequence> - * <xs:element name="bar"> - * <xs:complexType> - * <xs:choice minOccurs="0" maxOccurs="unbounded"> - * <xs:element name="A" type="PX"/> - * <xs:element name="B" type="PY"/> - * </xs:choice> - * </xs:complexType> - * </xs:element> - * </xs:sequence> - * </xs:complexType> - * + * + * + * + * + * + * + * + * + * + * + * + * + * + * } * * @author
      • Kohsuke Kawaguchi, Sun Microsystems, Inc.
      • Sekhar Vajjhala, Sun Microsystems, Inc.
      * @see XmlElement diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlEnumValue.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlEnumValue.java index bcdebcb1a5f..fc29ac0786b 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlEnumValue.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlEnumValue.java @@ -56,23 +56,24 @@ import static java.lang.annotation.ElementType.FIELD; *

      In the absence of this annotation, {@link Enum#name()} is used * as the XML representation. * - *

      Example 1: Map enum constant name -> enumeration facet

      + *

      Example 1: Map enum constant name {@literal ->} enumeration facet

      *
        *     //Example: Code fragment
        *     @XmlEnum(String.class)
        *     public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
      + * {@code
        *
      - *     <!-- Example: XML Schema fragment -->
      - *     <xs:simpleType name="Card">
      - *       <xs:restriction base="xs:string"/>
      - *         <xs:enumeration value="CLUBS"/>
      - *         <xs:enumeration value="DIAMONDS"/>
      - *         <xs:enumeration value="HEARTS"/>
      - *         <xs:enumeration value="SPADES"/>
      - *     </xs:simpleType>
      - * 
      + * + * + * + * + * + * + * + * + * } * - *

      Example 2: Map enum constant name(value) -> enumeration facet

      + *

      Example 2: Map enum constant name(value) {@literal ->} enumeration facet

      *
        *     //Example: code fragment
        *     @XmlType
      @@ -82,19 +83,20 @@ import static java.lang.annotation.ElementType.FIELD;
        *         @XmlEnumValue("5") NICKEL(5),
        *         @XmlEnumValue("10") DIME(10),
        *         @XmlEnumValue("25") QUARTER(25) }
      + * {@code
        *
      - *     <!-- Example: XML Schema fragment -->
      - *     <xs:simpleType name="Coin">
      - *       <xs:restriction base="xs:int">
      - *         <xs:enumeration value="1"/>
      - *         <xs:enumeration value="5"/>
      - *         <xs:enumeration value="10"/>
      - *         <xs:enumeration value="25"/>
      - *       </xs:restriction>
      - *     </xs:simpleType>
      - * 
      + * + * + * + * + * + * + * + * + * + * } * - *

      Example 3: Map enum constant name -> enumeration facet

      + *

      Example 3: Map enum constant name {@literal ->} enumeration facet

      * *
        *     //Code fragment
      @@ -104,15 +106,16 @@ import static java.lang.annotation.ElementType.FIELD;
        *         @XmlEnumValue("1") ONE,
        *         @XmlEnumValue("2") TWO;
        *     }
      + * {@code
        *
      - *     <!-- Example: XML Schema fragment -->
      - *     <xs:simpleType name="Code">
      - *       <xs:restriction base="xs:int">
      - *         <xs:enumeration value="1"/>
      - *         <xs:enumeration value="2"/>
      - *       </xs:restriction>
      - *     </xs:simpleType>
      - * 
      + * + * + * + * + * + * + * + * } * * @since 1.6, JAXB 2.0 */ diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlID.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlID.java index 441dc5d101b..52d03609f02 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlID.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlID.java @@ -73,17 +73,18 @@ import static java.lang.annotation.RetentionPolicy.*; * public void setCustomerID(String id); * .... other properties not shown * } + * {@code * - * <!-- Example: XML Schema fragment --> - * <xs:complexType name="Customer"> - * <xs:complexContent> - * <xs:sequence> + * + * + * + * * .... - * </xs:sequence> - * <xs:attribute name="customerID" type="xs:ID"/> - * </xs:complexContent> - * </xs:complexType> - * + * + * + * + * + * } * * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @see XmlIDREF diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlIDREF.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlIDREF.java index 2ad68419da9..503f936d03e 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlIDREF.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlIDREF.java @@ -37,7 +37,7 @@ import static java.lang.annotation.RetentionPolicy.*; *

      * To preserve referential integrity of an object graph across XML * serialization followed by a XML deserialization, requires an object - * reference to be marshalled by reference or containment + * reference to be marshaled by reference or containment * appropriately. Annotations @XmlID and @XmlIDREF * together allow a customized mapping of a JavaBean property's * type by containment or reference. @@ -82,18 +82,19 @@ import static java.lang.annotation.RetentionPolicy.*; * public void setCustomer(Customer customer); * .... * } + * {@code * - * <!-- Example: XML Schema fragment --> - * <xs:complexType name="Shipping"> - * <xs:complexContent> - * <xs:sequence> - * <xs:element name="customer" type="xs:IDREF"/> + * + * + * + * + * * .... - * </xs:sequence> - * </xs:complexContent> - * </xs:complexType> + * + * + * * - * + * } * * *

      Example 2: The following is a complete example of @@ -142,64 +143,65 @@ import static java.lang.annotation.RetentionPolicy.*; * // maps reference to Invoice by containment by default. * public Invoice getInvoice(); * } + * {@code * - * <!-- XML Schema mapping for above code frament --> + * * - * <xs:complexType name="Invoice"> - * <xs:complexContent> - * <xs:sequence> - * <xs:element name="customer" type="xs:IDREF"/> + * + * + * + * * .... - * </xs:sequence> - * </xs:complexContent> - * </xs:complexType> + * + * + * * - * <xs:complexType name="Shipping"> - * <xs:complexContent> - * <xs:sequence> - * <xs:element name="customer" type="xs:IDREF"/> + * + * + * + * * .... - * </xs:sequence> - * </xs:complexContent> - * </xs:complexType> + * + * + * * - * <xs:complexType name="Customer"> - * <xs:complexContent> - * <xs:sequence> + * + * + * * .... - * </xs:sequence> - * <xs:attribute name="CustomerID" type="xs:ID"/> - * </xs:complexContent> - * </xs:complexType> + * + * + * + * * - * <xs:complexType name="CustomerData"> - * <xs:complexContent> - * <xs:sequence> - * <xs:element name="customer" type="xs:Customer"/> - * <xs:element name="shipping" type="xs:Shipping"/> - * <xs:element name="invoice" type="xs:Invoice"/> - * </xs:sequence> - * </xs:complexContent> - * </xs:complexType> + * + * + * + * + * + * + * + * + * * - * <xs:element name"customerData" type="xs:CustomerData"/> + * * - * <!-- Instance document conforming to the above XML Schema --> - * <customerData> - * <customer customerID="Alice"> + * + * + * * .... - * </customer> + * * - * <shipping customer="Alice"> + * * .... - * </shipping> + * * - * <invoice customer="Alice"> + * * .... - * </invoice> - * </customerData> + * + * * - * + * } * *

      Example 3: Mapping List to repeating element of type IDREF *

      @@ -209,16 +211,17 @@ import static java.lang.annotation.RetentionPolicy.*;
        *         @XmlElement(name="Alice")
        *             public List customers;
        *     }
      + * {@code
        *
      - *     <!-- XML schema fragment -->
      - *     <xs:complexType name="Shipping">
      - *       <xs:sequence>
      - *         <xs:choice minOccurs="0" maxOccurs="unbounded">
      - *           <xs:element name="Alice" type="xs:IDREF"/>
      - *         </xs:choice>
      - *       </xs:sequence>
      - *     </xs:complexType>
      - * 
      + * + * + * + * + * + * + * + * + * } * *

      Example 4: Mapping a List to a list of elements of type IDREF. *

      @@ -230,17 +233,18 @@ import static java.lang.annotation.RetentionPolicy.*;
        *              @XmlElement(name="John", type="InternationalCustomer.class")
        *         public List customers;
        *     }
      + * {@code
        *
      - *     <!-- XML Schema fragment -->
      - *     <xs:complexType name="Shipping">
      - *       <xs:sequence>
      - *         <xs:choice minOccurs="0" maxOccurs="unbounded">
      - *           <xs:element name="Alice" type="xs:IDREF"/>
      - *           <xs:element name="John" type="xs:IDREF"/>
      - *         </xs:choice>
      - *       </xs:sequence>
      - *     </xs:complexType>
      - * 
      + * + * + * + * + * + * + * + * + * + * } * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @see XmlID * @since 1.6, JAXB 2.0 diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlList.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlList.java index 9bd81d03355..675fbb4b7f2 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlList.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlList.java @@ -59,12 +59,12 @@ import static java.lang.annotation.ElementType.PARAMETER; * * would produce XML like this: * - *
      - * <foo>
      - *   <data>abc</data>
      - *   <data>def</data>
      - * </foo>
      - * 
      + *
      {@code
      + * 
      + *   abc
      + *   def
      + * 
      + * }
      * * @XmlList annotation, on the other hand, allows multiple values to be * represented as whitespace-separated tokens in a single element. For example, @@ -80,11 +80,11 @@ import static java.lang.annotation.ElementType.PARAMETER; * * the above code will produce XML like this: * - *
      - * <foo>
      - *   <data>abc def</data>
      - * </foo>
      - * 
      + *
      {@code
      + * 
      + *   abc def
      + * 
      + * }
      * *

      This annotation can be used with the following annotations: * {@link XmlElement}, diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlMixed.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlMixed.java index 83c5da66d12..87d160d54d6 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlMixed.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlMixed.java @@ -56,32 +56,33 @@ import javax.xml.bind.JAXBElement; *

    * * Below is an example of binding and creation of mixed content. - *
    - *  <!-- schema fragment having  mixed content -->
    - *  <xs:complexType name="letterBody" mixed="true">
    - *    <xs:sequence>
    - *      <xs:element name="name" type="xs:string"/>
    - *      <xs:element name="quantity" type="xs:positiveInteger"/>
    - *      <xs:element name="productName" type="xs:string"/>
    - *      <!-- etc. -->
    - *    </xs:sequence>
    - *  </xs:complexType>
    - *  <xs:element name="letterBody" type="letterBody"/>
    + * 
    {@code
    + *
    + *  
    + *  
    + *    
    + *      
    + *      
    + *      
    + *      
    + *    
    + *  
    + *  
      *
      * // Schema-derived Java code:
      * // (Only annotations relevant to mixed content are shown below,
    - * //  others are ommitted.)
    + * //  others are omitted.)
      * import java.math.BigInteger;
      * public class ObjectFactory {
      *      // element instance factories
    - *      JAXBElement<LetterBody> createLetterBody(LetterBody value);
    - *      JAXBElement<String>     createLetterBodyName(String value);
    - *      JAXBElement<BigInteger> createLetterBodyQuantity(BigInteger value);
    - *      JAXBElement<String>     createLetterBodyProductName(String value);
    + *      JAXBElement createLetterBody(LetterBody value);
    + *      JAXBElement     createLetterBodyName(String value);
    + *      JAXBElement createLetterBodyQuantity(BigInteger value);
    + *      JAXBElement     createLetterBodyProductName(String value);
      *      // type instance factory
      *      LetterBody createLetterBody();
      * }
    - * 
    + * }
    *
      * public class LetterBody {
      *      // Mixed content can contain instances of Element classes
    @@ -96,17 +97,17 @@ import javax.xml.bind.JAXBElement;
      * }
      * 
    * The following is an XML instance document with mixed content - *
    - * <letterBody>
    - * Dear Mr.<name>Robert Smith</name>
    - * Your order of <quantity>1</quantity> <productName>Baby
    - * Monitor</productName> shipped from our warehouse. ....
    - * </letterBody>
    - * 
    + *
    {@code
    + * 
    + * Dear Mr.Robert Smith
    + * Your order of 1 Baby
    + * Monitor shipped from our warehouse. ....
    + * 
    + * }
    * that can be constructed using following JAXB API calls. - *
    + * 
    {@code
      * LetterBody lb = ObjectFactory.createLetterBody();
    - * JAXBElement<LetterBody> lbe = ObjectFactory.createLetterBody(lb);
    + * JAXBElement lbe = ObjectFactory.createLetterBody(lb);
      * List gcl = lb.getContent();  //add mixed content to general content property.
      * gcl.add("Dear Mr.");  // add text information item as a String.
      *
    @@ -119,7 +120,7 @@ import javax.xml.bind.JAXBElement;
      *                      createLetterBodyQuantity(new BigInteger("1")));
      * gcl.add(ObjectFactory.createLetterBodyProductName("Baby Monitor"));
      * gcl.add("shipped from our warehouse");  // add text information item
    - * 
    + * }
    * *

    See "Package Specification" in javax.xml.bind.package javadoc for * additional common information.

    diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlRootElement.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlRootElement.java index b84e71beca2..fbbf2f69dc9 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlRootElement.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlRootElement.java @@ -73,28 +73,30 @@ import static java.lang.annotation.ElementType.TYPE; * marshal( new Point(3,5), System.out); * * - *
    - *     <!-- Example: XML output -->
    - *     <point>
    - *       <x> 3 </x>
    - *       <y> 5 </y>
    - *     </point>
    - * 
    + *
    {@code
    + *
    + *     
    + *     
    + *        3 
    + *        5 
    + *     
    + * }
    * * The annotation causes an global element declaration to be produced * in the schema. The global element declaration is associated with * the XML schema type to which the class is mapped. * - *
    - *     <!-- Example: XML schema definition -->
    - *     <xs:element name="point" type="point"/>
    - *     <xs:complexType name="point">
    - *       <xs:sequence>
    - *         <xs:element name="x" type="xs:int"/>
    - *         <xs:element name="y" type="xs:int"/>
    - *       </xs:sequence>
    - *     </xs:complexType>
    - * 
    + *
    {@code
    + *
    + *     
    + *     
    + *     
    + *       
    + *         
    + *         
    + *       
    + *     
    + * }
    * *

    * @@ -113,27 +115,28 @@ import static java.lang.annotation.ElementType.TYPE; * * //Example: Code fragment corresponding to XML output * * marshal( new Point3D(3,5,0), System.out ); + * {@code * - * <!-- Example: XML output --> - * <!-- The element name is point3D not point --> - * <point3D> - * <x>3</x> - * <y>5</y> - * <z>0</z> - * </point3D> + * + * + * + * 3 + * 5 + * 0 + * * - * <!-- Example: XML schema definition --> - * <xs:element name="point3D" type="point3D"/> - * <xs:complexType name="point3D"> - * <xs:complexContent> - * <xs:extension base="point"> - * <xs:sequence> - * <xs:element name="z" type="xs:int"/> - * </xs:sequence> - * </xs:extension> - * </xs:complexContent> - * </xs:complexType> - * + * + * + * + * + * + * + * + * + * + * + * + * } * * Example 3: Associate a global element with XML Schema type * to which the class is mapped. @@ -144,15 +147,16 @@ import static java.lang.annotation.ElementType.TYPE; * @XmlElement * public java.math.BigDecimal price; * } + * {@code * - * <!-- Example: XML schema definition --> - * <xs:element name="PriceElement" type="USPrice"/> - * <xs:complexType name="USPrice"> - * <xs:sequence> - * <xs:element name="price" type="xs:decimal"/> - * </sequence> - * </xs:complexType> - * + * + * + * + * + * + * + * + * } * * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @since 1.6, JAXB 2.0 diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlSchema.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlSchema.java index 6d25d57a266..db25ef00765 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlSchema.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlSchema.java @@ -63,16 +63,17 @@ import static java.lang.annotation.RetentionPolicy.*; * @javax.xml.bind.annotation.XmlSchema ( * namespace = "http://www.example.com/MYPO1" * ) + * {@code * - * <!-- XML Schema fragment --> - * <schema + * + * + * > + * + * } * *

    Example 2: Customize namespace prefix, namespace URI * mapping

    @@ -86,16 +87,17 @@ import static java.lang.annotation.RetentionPolicy.*; * * @javax.xml.bind.annotation.XmlNs(prefix="xs", * namespaceURI="http://www.w3.org/2001/XMLSchema") - * ) + * } * ) + * {@code * - * <!-- XML Schema fragment --> - * <schema + * + * * - * + * } * *

    Example 3: Customize elementFormDefault

    *
    @@ -103,14 +105,15 @@ import static java.lang.annotation.RetentionPolicy.*;
      *      elementFormDefault=XmlNsForm.UNQUALIFIED
      *      ...
      *    )
    + * {@code
      *
    - *    <!-- XML Schema fragment -->
    - *    <schema
    + *    
    + *    
      *
    - * 
    + * } * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @since 1.6, JAXB 2.0 diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlSchemaType.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlSchemaType.java index a25b291df06..a1d2859eceb 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlSchemaType.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlSchemaType.java @@ -65,14 +65,15 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; * @XmlSchemaType(name="date") * public XMLGregorianCalendar date; * } + * {@code * - * <!-- Example: Local XML Schema element --> - * <xs:complexType name="USPrice"/> - * <xs:sequence> - * <xs:element name="date" type="xs:date"/> - * </sequence> - * </xs:complexType> - * + * + * + * + * + * + * + * } * *

    Example 2: Customize mapping of XMLGregorianCalendar at package * level

    diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlTransient.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlTransient.java index 055e90e3ca0..b3394d5465f 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlTransient.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlTransient.java @@ -78,14 +78,15 @@ import static java.lang.annotation.RetentionPolicy.*; * String setName() {..}; * } * + * {@code * - * <!-- Example: XML Schema fragment --> - * <xs:complexType name="USAddress"> - * <xs:sequence> - * <xs:element name="name" type="xs:string"/> - * </xs:sequence> - * </xs:complexType> - * + * + * + * + * + * + * + * } * * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @since 1.6, JAXB 2.0 diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlType.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlType.java index 42e71396338..f20d4055860 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlType.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlType.java @@ -112,7 +112,7 @@ import java.lang.annotation.Target; * The following table shows the mapping of the class to a XML Schema * complex type or simple type. The notational symbols used in the table are: *
      - *
    • -> : represents a mapping
    • + *
    • {@literal ->} : represents a mapping
    • *
    • [x]+ : one or more occurances of x
    • *
    • [ @XmlValue property ]: JavaBean property annotated with * @XmlValue
    • @@ -132,7 +132,7 @@ import java.lang.annotation.Target; * * Class * {} - * [property]+ -> elements + * [property]+ {@literal ->} elements * complexcontent
      xs:all * * @@ -140,7 +140,7 @@ import java.lang.annotation.Target; * * Class * non empty - * [property]+ -> elements + * [property]+ {@literal ->} elements * complexcontent
      xs:sequence * * @@ -148,7 +148,7 @@ import java.lang.annotation.Target; * * Class * X - * no property -> element + * no property {@literal ->} element * complexcontent
      empty sequence * * @@ -156,7 +156,7 @@ import java.lang.annotation.Target; * * Class * X - * 1 [@XmlValue property] {@literal &&}
      [property]+ -> attributes + * 1 [@XmlValue property] {@literal &&}
      [property]+ {@literal ->} attributes * simplecontent * * @@ -164,7 +164,7 @@ import java.lang.annotation.Target; * * Class * X - * 1 [@XmlValue property] {@literal &&}
      no properties -> attribute + * 1 [@XmlValue property] {@literal &&}
      no properties {@literal ->} attribute * * simpletype * @@ -208,35 +208,37 @@ import java.lang.annotation.Target; * java.math.BigDecimal getZip() {..}; * void setZip(java.math.BigDecimal) {..}; * } + * {@code * - * <!-- XML Schema mapping for USAddress --> - * <xs:complexType name="USAddress"> - * <xs:sequence> - * <xs:element name="street" type="xs:string"/> - * <xs:element name="city" type="xs:string"/> - * <xs:element name="state" type="xs:string"/> - * <xs:element name="zip" type="xs:decimal"/> - * <xs:element name="name" type="xs:string"/> - * </xs:all> - * </xs:complexType> - * + * + * + * + * + * + * + * + * + * + * + * } *

      Example 2: Map a class to a complex type with * xs:all

      *
        * @XmlType(propOrder={})
        * public class USAddress { ...}
      + * {@code
        *
      - * <!-- XML Schema mapping for USAddress -->
      - * <xs:complexType name="USAddress">
      - *   <xs:all>
      - *     <xs:element name="name" type="xs:string"/>
      - *     <xs:element name="street" type="xs:string"/>
      - *     <xs:element name="city" type="xs:string"/>
      - *     <xs:element name="state" type="xs:string"/>
      - *     <xs:element name="zip" type="xs:decimal"/>
      - *   </xs:sequence>
      - * </xs:complexType>
      - *
      + * + * + * + * + * + * + * + * + * + * + *} *

      Example 3: Map a class to a global element with an * anonymous type. *

      @@ -244,20 +246,21 @@ import java.lang.annotation.Target; * @XmlRootElement * @XmlType(name="") * public class USAddress { ...} + * {@code * - * <!-- XML Schema mapping for USAddress --> - * <xs:element name="USAddress"> - * <xs:complexType> - * <xs:sequence> - * <xs:element name="name" type="xs:string"/> - * <xs:element name="street" type="xs:string"/> - * <xs:element name="city" type="xs:string"/> - * <xs:element name="state" type="xs:string"/> - * <xs:element name="zip" type="xs:decimal"/> - * </xs:sequence> - * </xs:complexType> - * </xs:element> - * + * + * + * + * + * + * + * + * + * + * + * + * + * } * *

      Example 4: Map a property to a local element with * anonymous type. @@ -271,22 +274,23 @@ import java.lang.annotation.Target; * @XmlType(name="") * public class USAddress { ... } * } + * {@code * - * <!-- XML Schema mapping for USAddress --> - * <xs:complexType name="Invoice"> - * <xs:sequence> - * <xs:element name="addr"> - * <xs:complexType> - * <xs:element name="name", type="xs:string"/> - * <xs:element name="city", type="xs:string"/> - * <xs:element name="city" type="xs:string"/> - * <xs:element name="state" type="xs:string"/> - * <xs:element name="zip" type="xs:decimal"/> - * </xs:complexType> + * + * + * + * + * + * + * + * + * + * + * * ... - * </xs:sequence> - * </xs:complexType> - * + * + * + * } * *

      Example 5: Map a property to an attribute with * anonymous type. @@ -306,19 +310,20 @@ import java.lang.annotation.Target; * @XmlValue * public java.math.BigDecimal price; * } + * {@code * - * <!-- Example: XML Schema fragment --> - * <xs:complexType name="Item"> - * <xs:sequence> - * <xs:element name="name" type="xs:string"/> - * <xs:attribute name="price"> - * <xs:simpleType> - * <xs:restriction base="xs:decimal"/> - * </xs:simpleType> - * </xs:attribute> - * </xs:sequence> - * </xs:complexType> - * + * + * + * + * + * + * + * + * + * + * + * + * } * *

      Example 6: Define a factoryClass and factoryMethod * diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlValue.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlValue.java index 1ab10854a4f..675305b5821 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlValue.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlValue.java @@ -87,13 +87,14 @@ import static java.lang.annotation.RetentionPolicy.*; * @XmlValue * public java.math.BigDecimal price; * } + * {@code * - * <!-- Example 1: XML Schema fragment --> - * <xs:simpleType name="USPrice"> - * <xs:restriction base="xs:decimal"/> - * </xs:simpleType> + * + * + * + * * - * + * } * *

      Example 2: Map a class to XML Schema complexType with * with simpleContent.

      @@ -108,17 +109,18 @@ import static java.lang.annotation.RetentionPolicy.*; * @XmlAttribute * public String currency; * } + * {@code * - * <!-- Example 2: XML Schema fragment --> - * <xs:complexType name="InternationalPrice"> - * <xs:simpleContent> - * <xs:extension base="xs:decimal"> - * <xs:attribute name="currency" type="xs:string"/> - * </xs:extension> - * </xs:simpleContent> - * </xs:complexType> + * + * + * + * + * + * + * + * * - * + * } * * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @see XmlType diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/CollapsedStringAdapter.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/CollapsedStringAdapter.java index 9a589653c12..38865a0c32f 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/CollapsedStringAdapter.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/CollapsedStringAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2015, 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 @@ -32,7 +32,7 @@ package javax.xml.bind.annotation.adapters; * *

      * This adapter removes leading and trailing whitespaces, then truncate any - * sequnce of tab, CR, LF, and SP by a single whitespace character ' '. + * sequence of tab, CR, LF, and SP by a single whitespace character ' '. * * @author Kohsuke Kawaguchi * @since 1.6, JAXB 2.0 @@ -41,7 +41,7 @@ public class CollapsedStringAdapter extends XmlAdapter { /** * Removes leading and trailing whitespaces of the string * given as the parameter, then truncate any - * sequnce of tab, CR, LF, and SP by a single whitespace character ' '. + * sequence of tab, CR, LF, and SP by a single whitespace character ' '. */ public String unmarshal(String text) { if(text==null) return null; // be defensive diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlAdapter.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlAdapter.java index 4a500814f02..3c5bd422512 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlAdapter.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlAdapter.java @@ -75,35 +75,35 @@ package javax.xml.bind.annotation.adapters; * *

      Step 1: Determine the desired XML representation for HashMap. * - *

      - *     <hashmap>
      - *         <entry key="id123">this is a value</entry>
      - *         <entry key="id312">this is another value</entry>
      + * 
      {@code
      + *     
      + *         this is a value
      + *         this is another value
        *         ...
      - *       </hashmap>
      - * 
      + * + * }
      * *

      Step 2: Determine the schema definition that the * desired XML representation shown above should follow. * - *

      + * 
      {@code
        *
      - *     <xs:complexType name="myHashMapType">
      - *       <xs:sequence>
      - *         <xs:element name="entry" type="myHashMapEntryType"
      - *                        minOccurs = "0" maxOccurs="unbounded"/>
      - *       </xs:sequence>
      - *     </xs:complexType>
      + *     
      + *       
      + *         
      + *       
      + *     
        *
      - *     <xs:complexType name="myHashMapEntryType">
      - *       <xs:simpleContent>
      - *         <xs:extension base="xs:string">
      - *           <xs:attribute name="key" type="xs:int"/>
      - *         </xs:extension>
      - *       </xs:simpleContent>
      - *     </xs:complexType>
      + *     
      + *       
      + *         
      + *           
      + *         
      + *       
      + *     
        *
      - * 
      + * }
      * *

      Step 3: Write value types that can generate the above * schema definition. @@ -125,11 +125,11 @@ package javax.xml.bind.annotation.adapters; *

      Step 4: Write the adapter that adapts the value type, * MyHashMapType to a bound type, HashMap, used by the application. * - *

      + * 
      {@code
        *     public final class MyHashMapAdapter extends
      - *                        XmlAdapter<MyHashMapType,HashMap> { ... }
      + *                        XmlAdapter { ... }
        *
      - * 
      + * }
      * *

      Step 5: Use the adapter. * @@ -143,13 +143,13 @@ package javax.xml.bind.annotation.adapters; * * The above code fragment will map to the following schema: * - *

      - *     <xs:complexType name="Foo">
      - *       <xs:sequence>
      - *         <xs:element name="hashmap" type="myHashMapType">
      - *       </xs:sequence>
      - *     </xs:complexType>
      - * 
      + *
      {@code
      + *     
      + *       
      + *         
      + *       
      + *     
      + * }
      * * @param * The type that JAXB doesn't know how to handle. An adapter is written diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java index 6cebcf89dc9..2f1ee037750 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2015, 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 @@ -42,7 +42,7 @@ import java.lang.annotation.Target; * @XmlJavaTypeAdapters ({ @XmlJavaTypeAdapter(...),@XmlJavaTypeAdapter(...) }) * * - *

      The @XmlJavaTypeAdapters annnotation is useful for + *

      The @XmlJavaTypeAdapters annotation is useful for * defining {@link XmlJavaTypeAdapter} annotations for different types * at the package level. * diff --git a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/api/addressing/EPRHeader.java b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/api/addressing/EPRHeader.java index 3c73af04610..642dee10f70 100644 --- a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/api/addressing/EPRHeader.java +++ b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/api/addressing/EPRHeader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -119,7 +119,7 @@ final class EPRHeader extends AbstractHeaderImpl { epr.writeTo(localName, w); w.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); + DocumentBuilderFactory fac = XmlUtil.newDocumentBuilderFactory(false); fac.setNamespaceAware(true); Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement(); Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true); diff --git a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/message/stream/StreamHeader.java b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/message/stream/StreamHeader.java index 6415f1319bb..ae268e2f86f 100644 --- a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/message/stream/StreamHeader.java +++ b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/message/stream/StreamHeader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -194,7 +194,7 @@ public abstract class StreamHeader extends AbstractHeaderImpl { // TODO what about in-scope namespaces // Not very efficient consider implementing a stream buffer // processor that produces a DOM node from the buffer. - TransformerFactory tf = XmlUtil.newTransformerFactory(); + TransformerFactory tf = XmlUtil.newTransformerFactory(true); Transformer t = tf.newTransformer(); XMLStreamBufferSource source = new XMLStreamBufferSource(_mark); DOMResult result = new DOMResult(); diff --git a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/spi/db/BindingHelper.java b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/spi/db/BindingHelper.java index 86d36466e45..84047b67d24 100644 --- a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/spi/db/BindingHelper.java +++ b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/spi/db/BindingHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -36,6 +36,9 @@ import com.sun.xml.internal.bind.marshaller.SAX2DOMEx; //TODO DOMHeader DOMMessage SAAJMessage StatefulInstanceResolver import com.sun.xml.internal.bind.unmarshaller.DOMScanner; +//TODO MtomCodec +import com.sun.xml.internal.bind.v2.runtime.output.Encoded; + //TODO ExceptionBean import com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper; diff --git a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/DOMUtil.java b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/DOMUtil.java index e5f8cb7c0ad..47fb059f2c5 100644 --- a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/DOMUtil.java +++ b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/DOMUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -56,7 +56,7 @@ public class DOMUtil { synchronized (DOMUtil.class) { if (db == null) { try { - DocumentBuilderFactory dbf = XmlUtil.newDocumentBuilderFactory(); + DocumentBuilderFactory dbf = XmlUtil.newDocumentBuilderFactory(true); dbf.setNamespaceAware(true); db = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { diff --git a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/pipe/AbstractSchemaValidationTube.java b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/pipe/AbstractSchemaValidationTube.java index 6241299d41a..9a8641035bd 100644 --- a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/pipe/AbstractSchemaValidationTube.java +++ b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/pipe/AbstractSchemaValidationTube.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -92,7 +92,7 @@ public abstract class AbstractSchemaValidationTube extends AbstractFilterTubeImp super(next); this.binding = binding; feature = binding.getFeature(SchemaValidationFeature.class); - sf = allowExternalAccess(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI), "file", false); + sf = allowExternalAccess(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI), "all", false); } protected AbstractSchemaValidationTube(AbstractSchemaValidationTube that, TubeCloner cloner) { diff --git a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/version.properties b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/version.properties index b18bbc710b0..8cc250fb181 100644 --- a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/version.properties +++ b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/version.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012, 2015, 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 @@ -23,7 +23,7 @@ # questions. # -build-id=2.2.11-b150127.1410 -build-version=JAX-WS RI 2.2.11-b150127.1410 +build-id=2.2.11-b150402.1412 +build-version=JAX-WS RI 2.2.11-b150402.1412 major-version=2.2.11 -svn-revision=28121d09ed8ac02b76788709ccb4cdb66e03bbfa +svn-revision=f923291dedcf386c5f408263984a99d7cedf0012 diff --git a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/xml/XMLStreamReaderToXMLStreamWriter.java b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/xml/XMLStreamReaderToXMLStreamWriter.java index 14ad9743353..d30bb8aba62 100644 --- a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/xml/XMLStreamReaderToXMLStreamWriter.java +++ b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/xml/XMLStreamReaderToXMLStreamWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -187,14 +187,11 @@ public class XMLStreamReaderToXMLStreamWriter { protected void handleStartElement() throws XMLStreamException { String nsUri = in.getNamespaceURI(); - if(nsUri==null) - out.writeStartElement(in.getLocalName()); - else - out.writeStartElement( - fixNull(in.getPrefix()), - in.getLocalName(), - nsUri - ); + out.writeStartElement( + fixNull(in.getPrefix()), + in.getLocalName(), + fixNull(nsUri) + ); // start namespace bindings int nsCount = in.getNamespaceCount(); diff --git a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/xml/XmlUtil.java b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/xml/XmlUtil.java index 10ad6086112..18d7fcd55ed 100644 --- a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/xml/XmlUtil.java +++ b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/xml/XmlUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -231,7 +231,7 @@ public class XmlUtil { static final ContextClassloaderLocal saxParserFactory = new ContextClassloaderLocal() { @Override protected SAXParserFactory initialValue() throws Exception { - SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParserFactory factory = newSAXParserFactory(true); factory.setNamespaceAware(true); return factory; } @@ -371,57 +371,49 @@ public class XmlUtil { } }; - public static DocumentBuilderFactory newDocumentBuilderFactory() { - return newDocumentBuilderFactory(true); - } - - public static DocumentBuilderFactory newDocumentBuilderFactory(boolean secureXmlProcessing) { + public static DocumentBuilderFactory newDocumentBuilderFactory(boolean disableSecurity) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { - factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, isXMLSecurityDisabled(secureXmlProcessing)); + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !xmlSecurityDisabled(disableSecurity)); } catch (ParserConfigurationException e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support secure xml processing!", new Object[] { factory.getClass().getName() } ); } return factory; } - public static TransformerFactory newTransformerFactory(boolean secureXmlProcessingEnabled) { + public static TransformerFactory newTransformerFactory(boolean disableSecurity) { TransformerFactory factory = TransformerFactory.newInstance(); try { - factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, isXMLSecurityDisabled(secureXmlProcessingEnabled)); + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !xmlSecurityDisabled(disableSecurity)); } catch (TransformerConfigurationException e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support secure xml processing!", new Object[]{factory.getClass().getName()}); } return factory; } - public static TransformerFactory newTransformerFactory() { - return newTransformerFactory(true); - } - - public static SAXParserFactory newSAXParserFactory(boolean secureXmlProcessingEnabled) { + public static SAXParserFactory newSAXParserFactory(boolean disableSecurity) { SAXParserFactory factory = SAXParserFactory.newInstance(); try { - factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, isXMLSecurityDisabled(secureXmlProcessingEnabled)); + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !xmlSecurityDisabled(disableSecurity)); } catch (Exception e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support secure xml processing!", new Object[]{factory.getClass().getName()}); } return factory; } - public static XPathFactory newXPathFactory(boolean secureXmlProcessingEnabled) { + public static XPathFactory newXPathFactory(boolean disableSecurity) { XPathFactory factory = XPathFactory.newInstance(); try { - factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, isXMLSecurityDisabled(secureXmlProcessingEnabled)); + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !xmlSecurityDisabled(disableSecurity)); } catch (XPathFactoryConfigurationException e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support secure xml processing!", new Object[] { factory.getClass().getName() } ); } return factory; } - public static XMLInputFactory newXMLInputFactory(boolean secureXmlProcessingEnabled) { + public static XMLInputFactory newXMLInputFactory(boolean disableSecurity) { XMLInputFactory factory = XMLInputFactory.newInstance(); - if (isXMLSecurityDisabled(secureXmlProcessingEnabled)) { + if (xmlSecurityDisabled(disableSecurity)) { // TODO-Miran: are those apppropriate defaults? factory.setProperty(XMLInputFactory.SUPPORT_DTD, false); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); @@ -429,14 +421,14 @@ public class XmlUtil { return factory; } - private static boolean isXMLSecurityDisabled(boolean runtimeDisabled) { + private static boolean xmlSecurityDisabled(boolean runtimeDisabled) { return XML_SECURITY_DISABLED || runtimeDisabled; } - public static SchemaFactory allowExternalAccess(SchemaFactory sf, String value, boolean disableSecureProcessing) { + public static SchemaFactory allowExternalAccess(SchemaFactory sf, String value, boolean disableSecurity) { // if xml security (feature secure processing) disabled, nothing to do, no restrictions applied - if (isXMLSecurityDisabled(disableSecureProcessing)) { + if (xmlSecurityDisabled(disableSecurity)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Xml Security disabled, no JAXP xsd external access configuration necessary."); } diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle.properties index 427db1f466e..19f062ab0b0 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -30,10 +30,10 @@ BASEDIR_DOESNT_EXIST = \ Non-existent directory: {0} VERSION = \ - schemagen 2.2.12-b150126.1924 + schemagen 2.2.12-b150331.1824 FULLVERSION = \ - schemagen full version "2.2.12-b150126.1924" + schemagen full version "2.2.12-b150331.1824" USAGE = \ Usage: schemagen [-options ...] \n\ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_de.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_de.properties index 435ed7150a6..1de04cc98b7 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_de.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_de.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -27,8 +27,8 @@ UNEXPECTED_NGCC_TOKEN = Nicht erkanntes {0} in Zeile {1} Spalte {2} BASEDIR_DOESNT_EXIST = Nicht vorhandenes Verzeichnis: {0} -VERSION = schemagen 2.2.12-b150126.1924 +VERSION = schemagen 2.2.12-b150331.1824 -FULLVERSION = schemagen vollst\u00E4ndige Version "2.2.12-b150126.1924" +FULLVERSION = schemagen vollst\u00E4ndige Version "2.2.12-b150331.1824" USAGE = Verwendung: schemagen [-options ...] \nOptionen: \n\\ \\ \\ \\ -d : Gibt an, wo die von Prozessor und javac generierten Klassendateien gespeichert werden sollen\n\\ \\ \\ \\ -cp : Gibt an, wo die vom Benutzer angegebenen Dateien gespeichert sind\n\\ \\ \\ \\ -classpath : Gibt an, wo die vom Benutzer angegebenen Dateien gespeichert sind\n\\ \\ \\ \\ -encoding : Gibt die Codierung f\u00FCr die Annotationsverarbeitung/den javac-Aufruf an \n\\ \\ \\ \\ -episode : Generiert Episodendatei f\u00FCr separate Kompilierung\n\\ \\ \\ \\ -version : Zeigt Versionsinformation an\n\\ \\ \\ \\ -fullversion : Zeigt vollst\u00E4ndige Versionsinformationen an\n\\ \\ \\ \\ -help : Zeigt diese Verwendungsmeldung an diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_es.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_es.properties index c6d5aad27fa..015e45a1be0 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_es.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_es.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -27,8 +27,8 @@ UNEXPECTED_NGCC_TOKEN = Aparece un {0} inesperado en la l\u00EDnea {1} y la colu BASEDIR_DOESNT_EXIST = Directorio no existente: {0} -VERSION = schemagen 2.2.12-b150126.1924 +VERSION = schemagen 2.2.12-b150331.1824 -FULLVERSION = versi\u00F3n completa de schemagen "2.2.12-b150126.1924" +FULLVERSION = versi\u00F3n completa de schemagen "2.2.12-b150331.1824" USAGE = Sintaxis: schemagen [-options ...] \nOpciones: \n\\ \\ \\ \\ -d : especifique d\u00F3nde se colocan los archivos de clase generados por javac y el procesador\n\\ \\ \\ \\ -cp : especifique d\u00F3nde se encuentran los archivos especificados por el usuario\n\\ \\ \\ \\ -encoding : especifique la codificaci\u00F3n que se va a utilizar para el procesamiento de anotaciones/llamada de javac\n\\ \\ \\ \\ -episode : genera un archivo de episodio para una compilaci\u00F3n diferente\n\\ \\ \\ \\ -version : muestra la informaci\u00F3n de la versi\u00F3n\n\\ \\ \\ \\ -fullversion : muestra la informaci\u00F3n completa de la versi\u00F3n\n\\ \\ \\ \\ -help : muestra este mensaje de sintaxis diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_fr.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_fr.properties index 756a94788fa..a006426db90 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_fr.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_fr.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -27,8 +27,8 @@ UNEXPECTED_NGCC_TOKEN = Un \u00E9l\u00E9ment {0} inattendu appara\u00EEt \u00E0 BASEDIR_DOESNT_EXIST = R\u00E9pertoire {0} inexistant -VERSION = schemagen 2.2.12-b150126.1924 +VERSION = schemagen 2.2.12-b150331.1824 -FULLVERSION = version compl\u00E8te de schemagen "2.2.12-b150126.1924" +FULLVERSION = version compl\u00E8te de schemagen "2.2.12-b150331.1824" USAGE = Syntaxe : schemagen [-options ...] \nOptions : \n\ \ \ \ -d : indiquez o\u00F9 placer les fichiers de classe g\u00E9n\u00E9r\u00E9s par le processeur et le compilateur javac\n\ \ \ \ -cp : indiquez o\u00F9 trouver les fichiers sp\u00E9cifi\u00E9s par l'utilisateur\n\ \ \ \ -classpath : indiquez o\u00F9 trouver les fichiers sp\u00E9cifi\u00E9s par l'utilisateur\n\ \ \ \ -encoding : indiquez l'encodage \u00E0 utiliser pour l'appel de javac/traitement de l'annotation \n\ \ \ \ -episode : g\u00E9n\u00E9rez un fichier d'\u00E9pisode pour la compilation s\u00E9par\u00E9e\n\ \ \ \ -version : affichez les informations de version\n\ \ \ \ -fullversion : affichez les informations compl\u00E8tes de version\n\ \ \ \ -help : affichez ce message de syntaxe diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_it.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_it.properties index 992b68e2c77..ca32febc263 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_it.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_it.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -27,8 +27,8 @@ UNEXPECTED_NGCC_TOKEN = {0} imprevisto visualizzato sulla riga {1} colonna {2} BASEDIR_DOESNT_EXIST = Directory non esistente: {0} -VERSION = schemagen 2.2.12-b150126.1924 +VERSION = schemagen 2.2.12-b150331.1824 -FULLVERSION = versione completa schemagen "2.2.12-b150126.1924" +FULLVERSION = versione completa schemagen "2.2.12-b150331.1824" USAGE = Uso: schemagen [-options ...] \nOpzioni: \n\ \ \ \ -d : specifica dove posizionare il processore e i file della classe generata javac\n\ \ \ \ -cp : specifica dove trovare i file specificati dall'utente\n\ \ \ \ -classpath : specifica dove trovare i file specificati dall'utente\n\ \ \ \ -encoding : specifica la codifica da usare per l'elaborazione dell'annotazione/richiamo javac \n\ \ \ \ -episode : genera il file di episodio per la compilazione separata\n\ \ \ \ -version : visualizza le informazioni sulla versione\n\ \ \ \ -fullversion : visualizza le informazioni sulla versione completa\n\ \ \ \ -help : visualizza questo messaggio sull'uso diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_ja.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_ja.properties index bf3e933ce1c..28f152ffcbd 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_ja.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_ja.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -27,8 +27,8 @@ UNEXPECTED_NGCC_TOKEN = \u4E88\u671F\u3057\u306A\u3044{0}\u304C\u884C{1}\u3001\u BASEDIR_DOESNT_EXIST = \u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u5B58\u5728\u3057\u307E\u305B\u3093: {0} -VERSION = schemagen 2.2.12-b150126.1924 +VERSION = schemagen 2.2.12-b150331.1824 -FULLVERSION = schemagen\u30D5\u30EB\u30FB\u30D0\u30FC\u30B8\u30E7\u30F3"2.2.12-b150126.1924" +FULLVERSION = schemagen\u30D5\u30EB\u30FB\u30D0\u30FC\u30B8\u30E7\u30F3"2.2.12-b150331.1824" USAGE = \u4F7F\u7528\u65B9\u6CD5: schemagen [-options ...] \n\u30AA\u30D7\u30B7\u30E7\u30F3: \n\ \ \ \ -d : \u30D7\u30ED\u30BB\u30C3\u30B5\u304A\u3088\u3073javac\u304C\u751F\u6210\u3057\u305F\u30AF\u30E9\u30B9\u30FB\u30D5\u30A1\u30A4\u30EB\u3092\u7F6E\u304F\u4F4D\u7F6E\u3092\u6307\u5B9A\u3057\u307E\u3059\n\ \ \ \ -cp : \u30E6\u30FC\u30B6\u30FC\u304C\u6307\u5B9A\u3057\u305F\u30D5\u30A1\u30A4\u30EB\u3092\u691C\u7D22\u3059\u308B\u4F4D\u7F6E\u3092\u6307\u5B9A\u3057\u307E\u3059\n\ \ \ \ -classpath : \u30E6\u30FC\u30B6\u30FC\u304C\u6307\u5B9A\u3057\u305F\u30D5\u30A1\u30A4\u30EB\u3092\u691C\u7D22\u3059\u308B\u4F4D\u7F6E\u3092\u6307\u5B9A\u3057\u307E\u3059\n\ \ \ \ -encoding : \u6CE8\u91C8\u51E6\u7406/javac\u547C\u51FA\u3057\u306B\u4F7F\u7528\u3059\u308B\u30A8\u30F3\u30B3\u30FC\u30C7\u30A3\u30F3\u30B0\u3092\u6307\u5B9A\u3057\u307E\u3059\n\ \ \ \ -episode : \u30B3\u30F3\u30D1\u30A4\u30EB\u3054\u3068\u306B\u30A8\u30D4\u30BD\u30FC\u30C9\u30FB\u30D5\u30A1\u30A4\u30EB\u3092\u751F\u6210\u3057\u307E\u3059\n\ \ \ \ -version : \u30D0\u30FC\u30B8\u30E7\u30F3\u60C5\u5831\u3092\u8868\u793A\u3057\u307E\u3059\n\ \ \ \ -fullversion : \u30D5\u30EB\u30FB\u30D0\u30FC\u30B8\u30E7\u30F3\u60C5\u5831\u3092\u8868\u793A\u3057\u307E\u3059\n\ \ \ \ -help : \u3053\u306E\u4F7F\u7528\u4F8B\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u8868\u793A\u3057\u307E\u3059 diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_ko.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_ko.properties index 31ba0ab9637..1f7cd2ef605 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_ko.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_ko.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -27,8 +27,8 @@ UNEXPECTED_NGCC_TOKEN = \uC608\uC0C1\uCE58 \uC54A\uC740 {0}\uC774(\uAC00) {1}\uD BASEDIR_DOESNT_EXIST = \uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uB514\uB809\uD1A0\uB9AC: {0} -VERSION = schemagen 2.2.12-b150126.1924 +VERSION = schemagen 2.2.12-b150331.1824 -FULLVERSION = schemagen \uC815\uC2DD \uBC84\uC804 "2.2.12-b150126.1924" +FULLVERSION = schemagen \uC815\uC2DD \uBC84\uC804 "2.2.12-b150331.1824" USAGE = \uC0AC\uC6A9\uBC95: schemagen [-options ...] \n\uC635\uC158: \n\ \ \ \ -d : \uD504\uB85C\uC138\uC11C \uBC0F javac\uC5D0\uC11C \uC0DD\uC131\uD55C \uD074\uB798\uC2A4 \uD30C\uC77C\uC744 \uBC30\uCE58\uD560 \uC704\uCE58\uB97C \uC9C0\uC815\uD569\uB2C8\uB2E4.\n\ \ \ \ -cp : \uC0AC\uC6A9\uC790\uAC00 \uC9C0\uC815\uD55C \uD30C\uC77C\uC744 \uCC3E\uC744 \uC704\uCE58\uB97C \uC9C0\uC815\uD569\uB2C8\uB2E4.\n\ \ \ \ -classpath : \uC0AC\uC6A9\uC790\uAC00 \uC9C0\uC815\uD55C \uD30C\uC77C\uC744 \uCC3E\uC744 \uC704\uCE58\uB97C \uC9C0\uC815\uD569\uB2C8\uB2E4.\n\ \ \ \ -encoding : \uC8FC\uC11D \uCC98\uB9AC/javac \uD638\uCD9C\uC5D0 \uC0AC\uC6A9\uD560 \uC778\uCF54\uB529\uC744 \uC9C0\uC815\uD569\uB2C8\uB2E4. \n\ \ \ \ -episode : \uBCC4\uB3C4 \uCEF4\uD30C\uC77C\uC744 \uC704\uD574 episode \uD30C\uC77C\uC744 \uC0DD\uC131\uD569\uB2C8\uB2E4.\n\ \ \ \ -version : \uBC84\uC804 \uC815\uBCF4\uB97C \uD45C\uC2DC\uD569\uB2C8\uB2E4.\n\ \ \ \ -fullversion : \uC815\uC2DD \uBC84\uC804 \uC815\uBCF4\uB97C \uD45C\uC2DC\uD569\uB2C8\uB2E4.\n\ \ \ \ -help : \uC774 \uC0AC\uC6A9\uBC95 \uBA54\uC2DC\uC9C0\uB97C \uD45C\uC2DC\uD569\uB2C8\uB2E4. diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_pt_BR.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_pt_BR.properties index c2f4155d874..0596527faad 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_pt_BR.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_pt_BR.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -27,8 +27,8 @@ UNEXPECTED_NGCC_TOKEN = {0} inesperado aparece na linha {1} coluna {2} BASEDIR_DOESNT_EXIST = Diret\u00F3rio n\u00E3o existente: {0} -VERSION = gera\u00E7\u00E3o do esquema 2.2.12-b150126.1924 +VERSION = gera\u00E7\u00E3o do esquema 2.2.12-b150331.1824 -FULLVERSION = vers\u00E3o completa da gera\u00E7\u00E3o do esquema "2.2.12-b150126.1924" +FULLVERSION = vers\u00E3o completa da gera\u00E7\u00E3o do esquema "2.2.12-b150331.1824" USAGE = Uso: gera\u00E7\u00E3o do esquema [-options ...] \nOp\u00E7\u00F5es: \n\\ \\ \\ \\ -d : especificar onde colocar o processador e os arquivos da classe gerados por javac\n\\ \\ \\ \\ -cp : especificar onde localizar arquivos especificados pelo usu\u00E1rio\n\\ \\ \\ \\ -classpath : especificar onde localizar os arquivos especificados pelo usu\u00E1rio\n\\ \\ \\ \\ -encoding : especificar codifica\u00E7\u00E3o a ser usada para processamento de anota\u00E7\u00E3o/chamada javac \n\\ \\ \\ \\ -episode : gerar arquivo do epis\u00F3dio para compila\u00E7\u00E3o separada\n\\ \\ \\ \\ -version : exibir informa\u00E7\u00F5es da vers\u00E3o\n\\ \\ \\ \\ -fullversion : exibir informa\u00E7\u00F5es da vers\u00E3o completa\n\\ \\ \\ \\ -help : exibir esta mensagem de uso diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_zh_CN.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_zh_CN.properties index cec06517656..3d780676808 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_zh_CN.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_zh_CN.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -27,8 +27,8 @@ UNEXPECTED_NGCC_TOKEN = \u5728\u7B2C {1} \u884C, \u7B2C {2} \u5217\u51FA\u73B0\u BASEDIR_DOESNT_EXIST = \u4E0D\u5B58\u5728\u7684\u76EE\u5F55: {0} -VERSION = schemagen 2.2.12-b150126.1924 +VERSION = schemagen 2.2.12-b150331.1824 -FULLVERSION = schemagen \u5B8C\u6574\u7248\u672C "2.2.12-b150126.1924" +FULLVERSION = schemagen \u5B8C\u6574\u7248\u672C "2.2.12-b150331.1824" USAGE = \u7528\u6CD5: schemagen [-options ...] \n\u9009\u9879: \n\ \ \ \ -d : \u6307\u5B9A\u653E\u7F6E\u5904\u7406\u7A0B\u5E8F\u548C javac \u751F\u6210\u7684\u7C7B\u6587\u4EF6\u7684\u4F4D\u7F6E\n\ \ \ \ -cp : \u6307\u5B9A\u67E5\u627E\u7528\u6237\u6307\u5B9A\u6587\u4EF6\u7684\u4F4D\u7F6E\n\ \ \ \ -classpath : \u6307\u5B9A\u67E5\u627E\u7528\u6237\u6307\u5B9A\u6587\u4EF6\u7684\u4F4D\u7F6E\n\ \ \ \ -encoding : \u6307\u5B9A\u7528\u4E8E\u6CE8\u91CA\u5904\u7406/javac \u8C03\u7528\u7684\u7F16\u7801\n\ \ \ \ -episode : \u751F\u6210\u7247\u6BB5\u6587\u4EF6\u4EE5\u4F9B\u5355\u72EC\u7F16\u8BD1\n\ \ \ \ -version : \u663E\u793A\u7248\u672C\u4FE1\u606F\n\ \ \ \ -fullversion : \u663E\u793A\u5B8C\u6574\u7684\u7248\u672C\u4FE1\u606F\n\ \ \ \ -help : \u663E\u793A\u6B64\u7528\u6CD5\u6D88\u606F diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_zh_TW.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_zh_TW.properties index 938aef76528..1ded7446a25 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_zh_TW.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/MessageBundle_zh_TW.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -27,8 +27,8 @@ UNEXPECTED_NGCC_TOKEN = \u672A\u9810\u671F\u7684 {0} \u986F\u793A\u65BC\u884C {1 BASEDIR_DOESNT_EXIST = \u4E0D\u5B58\u5728\u7684\u76EE\u9304: {0} -VERSION = schemagen 2.2.12-b150126.1924 +VERSION = schemagen 2.2.12-b150331.1824 -FULLVERSION = schemagen \u5B8C\u6574\u7248\u672C "2.2.12-b150126.1924" +FULLVERSION = schemagen \u5B8C\u6574\u7248\u672C "2.2.12-b150331.1824" USAGE = \u7528\u6CD5: schemagen [-options ...] \n\u9078\u9805: \n\\ \\ \\ \\ -d : \u6307\u5B9A\u8655\u7406\u5668\u4EE5\u53CA javac \u7522\u751F\u7684\u985E\u5225\u6A94\u6848\u653E\u7F6E\u4F4D\u7F6E\n\\ \\ \\ \\ -cp : \u6307\u5B9A\u8981\u5C0B\u627E\u4F7F\u7528\u8005\u6307\u5B9A\u6A94\u6848\u7684\u4F4D\u7F6E\n\\ \\ \\ \\ -classpath : \u6307\u5B9A\u8981\u5C0B\u627E\u4F7F\u7528\u8005\u6307\u5B9A\u6A94\u6848\u7684\u4F4D\u7F6E\n\\ \\ \\ \\ -encoding : \u6307\u5B9A\u8981\u7528\u65BC\u8A3B\u89E3\u8655\u7406/javac \u547C\u53EB\u7684\u7DE8\u78BC \n\\ \\ \\ \\ -episode : \u7522\u751F\u7368\u7ACB\u7DE8\u8B6F\u7684\u4E8B\u4EF6 (episode) \u6A94\u6848\n\\ \\ \\ \\ -version : \u986F\u793A\u7248\u672C\u8CC7\u8A0A\n\\ \\ \\ \\ -fullversion : \u986F\u793A\u5B8C\u6574\u7248\u672C\u8CC7\u8A0A\n\\ \\ \\ \\ -help : \u986F\u793A\u6B64\u7528\u6CD5\u8A0A\u606F diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/SchemaGenerator.java b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/SchemaGenerator.java index 47d62d8e713..6a3eec71d50 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/SchemaGenerator.java +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/SchemaGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -158,7 +158,12 @@ public class SchemaGenerator { while (cl != null) { if (cl instanceof URLClassLoader) { for (URL url : ((URLClassLoader) cl).getURLs()) { - appendPath(cp, url.getPath()); + try { + appendPath(cp,new File(url.toURI()).getPath()); + } catch(URISyntaxException ex) { + /*If the URL is not properly formated - skip it*/ + LOGGER.log(Level.SEVERE, ex.getMessage(), ex); + } } } cl = cl.getParent(); diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/ap/SchemaGenerator.java b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/ap/SchemaGenerator.java index a15b1453e9f..2a8b59894fe 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/ap/SchemaGenerator.java +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/ap/SchemaGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -23,8 +23,6 @@ * questions. */ - - package com.sun.tools.internal.jxc.ap; import com.sun.tools.internal.jxc.api.JXC; @@ -89,12 +87,12 @@ public class SchemaGenerator extends AbstractProcessor { public boolean process(Set annotations, RoundEnvironment roundEnv) { final ErrorReceiverImpl errorListener = new ErrorReceiverImpl(processingEnv); - List classes = new ArrayList(); + List classesToBeBound = new ArrayList(); // simply ignore all the interface definitions, // so that users won't have to manually exclude interfaces, which is silly. - filterClass(classes, roundEnv.getRootElements()); + filterClass(classesToBeBound, roundEnv.getRootElements()); - J2SJAXBModel model = JXC.createJavaCompiler().bind(classes, Collections.emptyMap(), null, processingEnv); + J2SJAXBModel model = JXC.createJavaCompiler().bind(classesToBeBound, Collections.emptyMap(), null, processingEnv); if (model == null) return false; // error @@ -133,11 +131,17 @@ public class SchemaGenerator extends AbstractProcessor { return false; } - private void filterClass(List classes, Collection elements) { + /** + * Filter classes (note that enum is kind of class) from elements tree + * @param result list of found classes + * @param elements tree to be filtered + */ + private void filterClass(List result, Collection elements) { for (Element element : elements) { - if (element.getKind().equals(ElementKind.CLASS) || element.getKind().equals(ElementKind.ENUM)) { - classes.add(new Reference((TypeElement) element, processingEnv)); - filterClass(classes, ElementFilter.typesIn(element.getEnclosedElements())); + final ElementKind kind = element.getKind(); + if (ElementKind.CLASS.equals(kind) || ElementKind.ENUM.equals(kind)) { + result.add(new Reference((TypeElement) element, processingEnv)); + filterClass(result, ElementFilter.typesIn(element.getEnclosedElements())); } } } diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/model/nav/ApNavigator.java b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/model/nav/ApNavigator.java index 803d32973a9..359bfc4cec0 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/model/nav/ApNavigator.java +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/model/nav/ApNavigator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -30,7 +30,12 @@ import com.sun.source.util.TreePath; import com.sun.source.util.Trees; import com.sun.xml.internal.bind.v2.model.nav.Navigator; import com.sun.xml.internal.bind.v2.runtime.Location; - +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; @@ -52,12 +57,6 @@ import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Elements; import javax.lang.model.util.SimpleTypeVisitor6; import javax.lang.model.util.Types; -import java.lang.annotation.Annotation; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; /** * {@link Navigator} implementation for annotation processing. @@ -241,7 +240,7 @@ public final class ApNavigator implements Navigator elements = env.getElementUtils().getAllMembers(clazz); - Collection constants = new HashSet(); + Collection constants = new ArrayList(); for (Element element : elements) { if (element.getKind().equals(ElementKind.ENUM_CONSTANT)) { constants.add((VariableElement) element); diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle.properties index fd88f7f2d7f..de2930362f8 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -171,20 +171,20 @@ Driver.CompilingSchema = \ Driver.FailedToGenerateCode = \ Failed to produce code. -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn Driver.FilePrologComment = \ - This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.12-b150126.1924 \n\ + This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.12-b150331.1824 \n\ See http://java.sun.com/xml/jaxb \n\ Any modifications to this file will be lost upon recompilation of the source schema. \n\ Generated on: {0} \n Driver.Version = \ - xjc 2.2.12-b150126.1924 + xjc 2.2.12-b150331.1824 Driver.FullVersion = \ - xjc full version "2.2.12-b150126.1924" + xjc full version "2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_de.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_de.properties index 97271e9de79..6c30fbf39cc 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_de.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_de.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -96,14 +96,14 @@ Driver.CompilingSchema = Ein Schema wird kompiliert ... Driver.FailedToGenerateCode = Code konnte nicht erzeugt werden. -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn -Driver.FilePrologComment = Diese Datei wurde mit der JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.12-b150126.1924 generiert \nSiehe http://java.sun.com/xml/jaxb \n\u00c4nderungen an dieser Datei gehen bei einer Neukompilierung des Quellschemas verloren. \nGeneriert: {0} \n +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn +Driver.FilePrologComment = Diese Datei wurde mit der JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.12-b150331.1824 generiert \nSiehe http://java.sun.com/xml/jaxb \n\u00c4nderungen an dieser Datei gehen bei einer Neukompilierung des Quellschemas verloren. \nGeneriert: {0} \n -Driver.Version = xjc 2.2.12-b150126.1924 +Driver.Version = xjc 2.2.12-b150331.1824 -Driver.FullVersion = xjc vollst\u00E4ndige Version "2.2.12-b150126.1924" +Driver.FullVersion = xjc vollst\u00E4ndige Version "2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_es.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_es.properties index eadb52fac88..0ad71a458d2 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_es.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_es.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -96,14 +96,14 @@ Driver.CompilingSchema = Compilando un esquema... Driver.FailedToGenerateCode = Fallo al producir c\u00f3digo. -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn -Driver.FilePrologComment = Este archivo ha sido generado por la arquitectura JavaTM para la implantaci\u00f3n de la referencia de enlace (JAXB) XML v2.2.12-b150126.1924 \nVisite http://java.sun.com/xml/jaxb \nTodas las modificaciones realizadas en este archivo se perder\u00e1n si se vuelve a compilar el esquema de origen. \nGenerado el: {0} \n +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn +Driver.FilePrologComment = Este archivo ha sido generado por la arquitectura JavaTM para la implantaci\u00f3n de la referencia de enlace (JAXB) XML v2.2.12-b150331.1824 \nVisite http://java.sun.com/xml/jaxb \nTodas las modificaciones realizadas en este archivo se perder\u00e1n si se vuelve a compilar el esquema de origen. \nGenerado el: {0} \n -Driver.Version = xjc 2.2.12-b150126.1924 +Driver.Version = xjc 2.2.12-b150331.1824 -Driver.FullVersion = versi\u00F3n completa de xjc "2.2.12-b150126.1924" +Driver.FullVersion = versi\u00F3n completa de xjc "2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_fr.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_fr.properties index dd19a1687df..dab13109b69 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_fr.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_fr.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -96,14 +96,14 @@ Driver.CompilingSchema = compilation d'un sch\u00e9ma... Driver.FailedToGenerateCode = Echec de la production du code. -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn -Driver.FilePrologComment = Ce fichier a \u00e9t\u00e9 g\u00e9n\u00e9r\u00e9 par l''impl\u00e9mentation de r\u00e9f\u00e9rence JavaTM Architecture for XML Binding (JAXB), v2.2.12-b150126.1924 \nVoir http://java.sun.com/xml/jaxb \nToute modification apport\u00e9e \u00e0 ce fichier sera perdue lors de la recompilation du sch\u00e9ma source. \nG\u00e9n\u00e9r\u00e9 le : {0} \n +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn +Driver.FilePrologComment = Ce fichier a \u00e9t\u00e9 g\u00e9n\u00e9r\u00e9 par l''impl\u00e9mentation de r\u00e9f\u00e9rence JavaTM Architecture for XML Binding (JAXB), v2.2.12-b150331.1824 \nVoir http://java.sun.com/xml/jaxb \nToute modification apport\u00e9e \u00e0 ce fichier sera perdue lors de la recompilation du sch\u00e9ma source. \nG\u00e9n\u00e9r\u00e9 le : {0} \n -Driver.Version = xjc 2.2.12-b150126.1924 +Driver.Version = xjc 2.2.12-b150331.1824 -Driver.FullVersion = version compl\u00E8te xjc "2.2.12-b150126.1924" +Driver.FullVersion = version compl\u00E8te xjc "2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_it.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_it.properties index f259cb3d291..32b7221ef35 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_it.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_it.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -96,14 +96,14 @@ Driver.CompilingSchema = compilazione di uno schema in corso... Driver.FailedToGenerateCode = Produzione del codice non riuscita. -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn -Driver.FilePrologComment = Questo file \u00e8 stato generato dall''architettura JavaTM per XML Binding (JAXB) Reference Implementation, v2.2.12-b150126.1924 \nVedere http://java.sun.com/xml/jaxb \nQualsiasi modifica a questo file andr\u00e0 persa durante la ricompilazione dello schema di origine. \nGenerato il: {0} \n +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn +Driver.FilePrologComment = Questo file \u00e8 stato generato dall''architettura JavaTM per XML Binding (JAXB) Reference Implementation, v2.2.12-b150331.1824 \nVedere http://java.sun.com/xml/jaxb \nQualsiasi modifica a questo file andr\u00e0 persa durante la ricompilazione dello schema di origine. \nGenerato il: {0} \n -Driver.Version = xjc 2.2.12-b150126.1924 +Driver.Version = xjc 2.2.12-b150331.1824 -Driver.FullVersion = versione completa xjc "2.2.12-b150126.1924" +Driver.FullVersion = versione completa xjc "2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_ja.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_ja.properties index 9674081427e..366edb4becc 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_ja.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_ja.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -96,14 +96,14 @@ Driver.CompilingSchema = \u30b9\u30ad\u30fc\u30de\u306e\u30b3\u30f3\u30d1\u30a4\ Driver.FailedToGenerateCode = \u30b3\u30fc\u30c9\u306e\u751f\u6210\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002 -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn -Driver.FilePrologComment = \u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u3001JavaTM Architecture for XML Binding(JAXB) Reference Implementation\u3001v2.2.12-b150126.1924\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u307e\u3057\u305f \nhttp://java.sun.com/xml/jaxb\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044 \n\u30bd\u30fc\u30b9\u30fb\u30b9\u30ad\u30fc\u30de\u306e\u518d\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u5909\u66f4\u306f\u5931\u308f\u308c\u307e\u3059\u3002 \n\u751f\u6210\u65e5: {0} \n +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn +Driver.FilePrologComment = \u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u3001JavaTM Architecture for XML Binding(JAXB) Reference Implementation\u3001v2.2.12-b150331.1824\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u307e\u3057\u305f \nhttp://java.sun.com/xml/jaxb\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044 \n\u30bd\u30fc\u30b9\u30fb\u30b9\u30ad\u30fc\u30de\u306e\u518d\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u5909\u66f4\u306f\u5931\u308f\u308c\u307e\u3059\u3002 \n\u751f\u6210\u65e5: {0} \n -Driver.Version = xjc 2.2.12-b150126.1924 +Driver.Version = xjc 2.2.12-b150331.1824 -Driver.FullVersion = xjc\u30D5\u30EB\u30FB\u30D0\u30FC\u30B8\u30E7\u30F3"2.2.12-b150126.1924" +Driver.FullVersion = xjc\u30D5\u30EB\u30FB\u30D0\u30FC\u30B8\u30E7\u30F3"2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_ko.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_ko.properties index 3715185d805..ffb08b6952e 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_ko.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_ko.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -96,14 +96,14 @@ Driver.CompilingSchema = \uc2a4\ud0a4\ub9c8\ub97c \ucef4\ud30c\uc77c\ud558\ub294 Driver.FailedToGenerateCode = \ucf54\ub4dc \uc0dd\uc131\uc744 \uc2e4\ud328\ud588\uc2b5\ub2c8\ub2e4. -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn -Driver.FilePrologComment = \uc774 \ud30c\uc77c\uc740 JAXB(JavaTM Architecture for XML Binding) \ucc38\uc870 \uad6c\ud604 2.2.12-b150126.1924 \ubc84\uc804\uc744 \ud1b5\ud574 \uc0dd\uc131\ub418\uc5c8\uc2b5\ub2c8\ub2e4. \nhttp://java.sun.com/xml/jaxb\ub97c \ucc38\uc870\ud558\uc2ed\uc2dc\uc624. \n\uc774 \ud30c\uc77c\uc744 \uc218\uc815\ud558\uba74 \uc18c\uc2a4 \uc2a4\ud0a4\ub9c8\ub97c \uc7ac\ucef4\ud30c\uc77c\ud560 \ub54c \uc218\uc815 \uc0ac\ud56d\uc774 \uc190\uc2e4\ub429\ub2c8\ub2e4. \n\uc0dd\uc131 \ub0a0\uc9dc: {0} \n +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn +Driver.FilePrologComment = \uc774 \ud30c\uc77c\uc740 JAXB(JavaTM Architecture for XML Binding) \ucc38\uc870 \uad6c\ud604 2.2.12-b150331.1824 \ubc84\uc804\uc744 \ud1b5\ud574 \uc0dd\uc131\ub418\uc5c8\uc2b5\ub2c8\ub2e4. \nhttp://java.sun.com/xml/jaxb\ub97c \ucc38\uc870\ud558\uc2ed\uc2dc\uc624. \n\uc774 \ud30c\uc77c\uc744 \uc218\uc815\ud558\uba74 \uc18c\uc2a4 \uc2a4\ud0a4\ub9c8\ub97c \uc7ac\ucef4\ud30c\uc77c\ud560 \ub54c \uc218\uc815 \uc0ac\ud56d\uc774 \uc190\uc2e4\ub429\ub2c8\ub2e4. \n\uc0dd\uc131 \ub0a0\uc9dc: {0} \n -Driver.Version = XJC 2.2.12-b150126.1924 +Driver.Version = XJC 2.2.12-b150331.1824 -Driver.FullVersion = XJC \uC815\uC2DD \uBC84\uC804 "2.2.12-b150126.1924" +Driver.FullVersion = XJC \uC815\uC2DD \uBC84\uC804 "2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_pt_BR.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_pt_BR.properties index 9f44278b4eb..5712ddafe10 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_pt_BR.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_pt_BR.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -96,14 +96,14 @@ Driver.CompilingSchema = compilando um esquema... Driver.FailedToGenerateCode = Falha ao produzir o c\u00f3digo. -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn -Driver.FilePrologComment = Este arquivo foi gerado pela Arquitetura JavaTM para Implementa\u00e7\u00e3o de Refer\u00eancia (JAXB) de Bind XML, v2.2.12-b150126.1924 \nConsulte http://java.sun.com/xml/jaxb \nTodas as modifica\u00e7\u00f5es neste arquivo ser\u00e3o perdidas ap\u00f3s a recompila\u00e7\u00e3o do esquema de origem. \nGerado em: {0} \n +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn +Driver.FilePrologComment = Este arquivo foi gerado pela Arquitetura JavaTM para Implementa\u00e7\u00e3o de Refer\u00eancia (JAXB) de Bind XML, v2.2.12-b150331.1824 \nConsulte http://java.sun.com/xml/jaxb \nTodas as modifica\u00e7\u00f5es neste arquivo ser\u00e3o perdidas ap\u00f3s a recompila\u00e7\u00e3o do esquema de origem. \nGerado em: {0} \n -Driver.Version = xjc 2.2.12-b150126.1924 +Driver.Version = xjc 2.2.12-b150331.1824 -Driver.FullVersion = vers\u00E3o completa de xjc "2.2.12-b150126.1924" +Driver.FullVersion = vers\u00E3o completa de xjc "2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_zh_CN.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_zh_CN.properties index 11276a8352a..b5f2d8a505a 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_zh_CN.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_zh_CN.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -96,14 +96,14 @@ Driver.CompilingSchema = \u6b63\u5728\u7f16\u8bd1\u6a21\u5f0f... Driver.FailedToGenerateCode = \u65e0\u6cd5\u751f\u6210\u4ee3\u7801\u3002 -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn -Driver.FilePrologComment = \u6b64\u6587\u4ef6\u662f\u7531 JavaTM Architecture for XML Binding (JAXB) \u5f15\u7528\u5b9e\u73b0 v2.2.12-b150126.1924 \u751f\u6210\u7684\n\u8bf7\u8bbf\u95ee http://java.sun.com/xml/jaxb \n\u5728\u91cd\u65b0\u7f16\u8bd1\u6e90\u6a21\u5f0f\u65f6, \u5bf9\u6b64\u6587\u4ef6\u7684\u6240\u6709\u4fee\u6539\u90fd\u5c06\u4e22\u5931\u3002\n\u751f\u6210\u65f6\u95f4: {0} \n +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn +Driver.FilePrologComment = \u6b64\u6587\u4ef6\u662f\u7531 JavaTM Architecture for XML Binding (JAXB) \u5f15\u7528\u5b9e\u73b0 v2.2.12-b150331.1824 \u751f\u6210\u7684\n\u8bf7\u8bbf\u95ee http://java.sun.com/xml/jaxb \n\u5728\u91cd\u65b0\u7f16\u8bd1\u6e90\u6a21\u5f0f\u65f6, \u5bf9\u6b64\u6587\u4ef6\u7684\u6240\u6709\u4fee\u6539\u90fd\u5c06\u4e22\u5931\u3002\n\u751f\u6210\u65f6\u95f4: {0} \n -Driver.Version = xjc 2.2.12-b150126.1924 +Driver.Version = xjc 2.2.12-b150331.1824 -Driver.FullVersion = xjc \u5B8C\u6574\u7248\u672C "2.2.12-b150126.1924" +Driver.FullVersion = xjc \u5B8C\u6574\u7248\u672C "2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_zh_TW.properties b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_zh_TW.properties index 27227f5b5c5..d722fc105cc 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_zh_TW.properties +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/MessageBundle_zh_TW.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2015, 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 @@ -96,14 +96,14 @@ Driver.CompilingSchema = \u6b63\u5728\u7de8\u8b6f\u7db1\u8981... Driver.FailedToGenerateCode = \u7121\u6cd5\u7522\u751f\u7a0b\u5f0f\u78bc. -# DO NOT localize the 2.2.12-b150126.1924 string - it is a token for an mvn -Driver.FilePrologComment = \u6b64\u6a94\u6848\u662f\u7531 JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.12-b150126.1924 \u6240\u7522\u751f \n\u8acb\u53c3\u95b1 http://java.sun.com/xml/jaxb \n\u4e00\u65e6\u91cd\u65b0\u7de8\u8b6f\u4f86\u6e90\u7db1\u8981, \u5c0d\u6b64\u6a94\u6848\u6240\u505a\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u5c07\u6703\u907a\u5931. \n\u7522\u751f\u6642\u9593: {0} \n +# DO NOT localize the 2.2.12-b150331.1824 string - it is a token for an mvn +Driver.FilePrologComment = \u6b64\u6a94\u6848\u662f\u7531 JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.12-b150331.1824 \u6240\u7522\u751f \n\u8acb\u53c3\u95b1 http://java.sun.com/xml/jaxb \n\u4e00\u65e6\u91cd\u65b0\u7de8\u8b6f\u4f86\u6e90\u7db1\u8981, \u5c0d\u6b64\u6a94\u6848\u6240\u505a\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u5c07\u6703\u907a\u5931. \n\u7522\u751f\u6642\u9593: {0} \n -Driver.Version = xjc 2.2.12-b150126.1924 +Driver.Version = xjc 2.2.12-b150331.1824 -Driver.FullVersion = xjc \u5B8C\u6574\u7248\u672C "2.2.12-b150126.1924" +Driver.FullVersion = xjc \u5B8C\u6574\u7248\u672C "2.2.12-b150331.1824" -Driver.BuildID = 2.2.12-b150126.1924 +Driver.BuildID = 2.2.12-b150331.1824 # for JDK integration - include version in source zip jaxb.jdk.version=@@JAXB_JDK_VERSION@@ diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/addon/code_injector/PluginImpl.java b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/addon/code_injector/PluginImpl.java index 626e97232f5..2d82bab915f 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/addon/code_injector/PluginImpl.java +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/addon/code_injector/PluginImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -25,13 +25,15 @@ package com.sun.tools.internal.xjc.addon.code_injector; +import java.util.Collection; import java.util.Collections; import java.util.List; +import com.sun.istack.internal.NotNull; import com.sun.tools.internal.xjc.Options; import com.sun.tools.internal.xjc.Plugin; import com.sun.tools.internal.xjc.model.CPluginCustomization; -import com.sun.tools.internal.xjc.outline.ClassOutline; +import com.sun.tools.internal.xjc.outline.CustomizableOutline; import com.sun.tools.internal.xjc.outline.Outline; import com.sun.tools.internal.xjc.util.DOMUtils; @@ -54,7 +56,7 @@ public class PluginImpl extends Plugin { } public boolean isCustomizationTagName(String nsUri, String localName) { - return nsUri.equals(Const.NS) && localName.equals("code"); + return Const.NS.equals(nsUri) && "code".equals(localName); } public String getUsage() { @@ -62,9 +64,15 @@ public class PluginImpl extends Plugin { } // meat of the processing - public boolean run(Outline model, Options opt, ErrorHandler errorHandler) { - for( ClassOutline co : model.getClasses() ) { - CPluginCustomization c = co.target.getCustomizations().find(Const.NS,"code"); + public boolean run(@NotNull Outline model, Options opt, ErrorHandler errorHandler) { + checkAndInject(model.getClasses()); + checkAndInject(model.getEnums()); + return true; + } + + private static void checkAndInject(Collection outlines) { + for (CustomizableOutline co : outlines) { + CPluginCustomization c = co.getTarget().getCustomizations().find(Const.NS, "code"); if(c==null) continue; // no customization --- nothing to inject here @@ -74,9 +82,7 @@ public class PluginImpl extends Plugin { String codeFragment = DOMUtils.getElementText(c.element); // inject the specified code fragment into the implementation class. - co.implClass.direct(codeFragment); + co.getImplClass().direct(codeFragment); } - - return true; } } diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/ClassOutline.java b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/ClassOutline.java index 1b6e1b664d9..dde38ae363c 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/ClassOutline.java +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/ClassOutline.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -33,6 +33,7 @@ import java.util.List; import com.sun.codemodel.internal.JClass; import com.sun.codemodel.internal.JDefinedClass; import com.sun.tools.internal.xjc.model.CClassInfo; +import com.sun.tools.internal.xjc.model.CCustomizable; import com.sun.tools.internal.xjc.model.CPropertyInfo; import com.sun.istack.internal.NotNull; @@ -44,7 +45,7 @@ import com.sun.istack.internal.NotNull; * * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) */ -public abstract class ClassOutline { +public abstract class ClassOutline implements CustomizableOutline { /** * A {@link Outline} that encloses all the class outlines. @@ -122,4 +123,14 @@ public abstract class ClassOutline { if(s==null) return null; return parent().getClazz(s); } + + @Override + public JDefinedClass getImplClass() { + return implClass; + } + + @Override + public CCustomizable getTarget() { + return target; + } } diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/CustomizableOutline.java b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/CustomizableOutline.java new file mode 100644 index 00000000000..79c223d5c57 --- /dev/null +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/CustomizableOutline.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, 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.tools.internal.xjc.outline; + +import com.sun.codemodel.internal.JDefinedClass; +import com.sun.istack.internal.NotNull; +import com.sun.tools.internal.xjc.model.CCustomizable; + +/** + * This interface describes that outline class could be customized. + * It provides the bound info from {@link CCustomizable} target. And + * customization output - implementation class. + * + * @author yaroska + * @since 2.2.12 + */ +public interface CustomizableOutline { + + /** + * Provides bound information about customizable target. + * @return customizable target + */ + @NotNull CCustomizable getTarget(); + + /** + * Provides customization output. + * @return Implementation class + */ + @NotNull JDefinedClass getImplClass(); +} diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/ElementOutline.java b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/ElementOutline.java index 34609aa8fec..72d768719ba 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/ElementOutline.java +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/ElementOutline.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -26,6 +26,7 @@ package com.sun.tools.internal.xjc.outline; import com.sun.codemodel.internal.JDefinedClass; +import com.sun.tools.internal.xjc.model.CCustomizable; import com.sun.tools.internal.xjc.model.CElementInfo; /** @@ -39,7 +40,7 @@ import com.sun.tools.internal.xjc.model.CElementInfo; * * @author Kohsuke Kawaguchi */ -public abstract class ElementOutline { +public abstract class ElementOutline implements CustomizableOutline { /** * A {@link Outline} that encloses all the class outlines. @@ -69,4 +70,14 @@ public abstract class ElementOutline { this.target = target; this.implClass = implClass; } + + @Override + public CCustomizable getTarget() { + return target; + } + + @Override + public JDefinedClass getImplClass() { + return implClass; + } } diff --git a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/EnumOutline.java b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/EnumOutline.java index 9ac6b7a97d3..ae48a7212e2 100644 --- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/EnumOutline.java +++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/outline/EnumOutline.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.List; import com.sun.codemodel.internal.JDefinedClass; +import com.sun.tools.internal.xjc.model.CCustomizable; import com.sun.tools.internal.xjc.model.CEnumLeafInfo; import com.sun.istack.internal.NotNull; @@ -40,7 +41,7 @@ import com.sun.istack.internal.NotNull; * * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) */ -public abstract class EnumOutline { +public abstract class EnumOutline implements CustomizableOutline { /** * This {@link EnumOutline} holds information about this {@link CEnumLeafInfo}. @@ -74,4 +75,14 @@ public abstract class EnumOutline { this.target = target; this.clazz = clazz; } + + @Override + public JDefinedClass getImplClass() { + return clazz; + } + + @Override + public CCustomizable getTarget() { + return target; + } } diff --git a/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/version.properties b/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/version.properties index b18bbc710b0..8cc250fb181 100644 --- a/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/version.properties +++ b/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/version.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012, 2015, 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 @@ -23,7 +23,7 @@ # questions. # -build-id=2.2.11-b150127.1410 -build-version=JAX-WS RI 2.2.11-b150127.1410 +build-id=2.2.11-b150402.1412 +build-version=JAX-WS RI 2.2.11-b150402.1412 major-version=2.2.11 -svn-revision=28121d09ed8ac02b76788709ccb4cdb66e03bbfa +svn-revision=f923291dedcf386c5f408263984a99d7cedf0012 diff --git a/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/document/soap/SOAPConstants.java b/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/document/soap/SOAPConstants.java index aabf2579a43..ee1582ed285 100644 --- a/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/document/soap/SOAPConstants.java +++ b/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/document/soap/SOAPConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -25,6 +25,8 @@ package com.sun.tools.internal.ws.wsdl.document.soap; +import com.sun.xml.internal.ws.encoding.soap.streaming.SOAPNamespaceConstants; + import javax.xml.namespace.QName; /** @@ -35,9 +37,7 @@ import javax.xml.namespace.QName; public interface SOAPConstants { // namespace URIs - public static final String URI_ENVELOPE = - "http://schemas.xmlsoap.org/soap/envelope/"; - + public static final String URI_ENVELOPE = SOAPNamespaceConstants.ENVELOPE; public static final String NS_WSDL_SOAP = "http://schemas.xmlsoap.org/wsdl/soap/"; public static final String NS_SOAP_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/"; diff --git a/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/parser/Internalizer.java b/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/parser/Internalizer.java index c153cce7f68..d216e6f3608 100644 --- a/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/parser/Internalizer.java +++ b/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/parser/Internalizer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -78,7 +78,7 @@ public class Internalizer { private static final ContextClassloaderLocal xpf = new ContextClassloaderLocal() { @Override protected XPathFactory initialValue() throws Exception { - return XPathFactory.newInstance(); + return XmlUtil.newXPathFactory(true); } }; /** diff --git a/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/parser/JAXWSBindingExtensionHandler.java b/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/parser/JAXWSBindingExtensionHandler.java index 0f12222220c..6801dd9f474 100644 --- a/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/parser/JAXWSBindingExtensionHandler.java +++ b/jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wsdl/parser/JAXWSBindingExtensionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -25,10 +25,10 @@ package com.sun.tools.internal.ws.wsdl.parser; +import com.sun.tools.internal.ws.util.xml.XmlUtil; import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible; import com.sun.tools.internal.ws.api.wsdl.TWSDLExtension; import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext; -import com.sun.tools.internal.ws.util.xml.XmlUtil; import com.sun.tools.internal.ws.wsdl.document.*; import com.sun.tools.internal.ws.wsdl.document.jaxws.CustomName; import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBinding; @@ -57,7 +57,7 @@ public class JAXWSBindingExtensionHandler extends AbstractExtensionHandler { private static final ContextClassloaderLocal xpf = new ContextClassloaderLocal() { @Override protected XPathFactory initialValue() throws Exception { - return XPathFactory.newInstance(); + return XmlUtil.newXPathFactory(false); } }; From 2cbce413a0661708df47af47b1ad14f58a601665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Fri, 10 Apr 2015 14:18:31 +0200 Subject: [PATCH 238/362] 8067215: Disable dual fields when not using optimistic types Reviewed-by: attila, lagergren --- .../tools/nasgen/PrototypeGenerator.java | 2 - nashorn/docs/DEVELOPER_README | 19 ++-- .../internal/codegen/CodeGenerator.java | 15 ++- .../internal/codegen/CompilerConstants.java | 7 +- .../internal/codegen/FieldObjectCreator.java | 8 +- .../internal/codegen/FindScopeDepths.java | 2 +- .../nashorn/internal/codegen/MapCreator.java | 18 +-- .../nashorn/internal/codegen/MapTuple.java | 6 +- .../codegen/ObjectClassGenerator.java | 102 ++++++++--------- .../internal/codegen/ObjectCreator.java | 2 +- .../internal/codegen/SpillObjectCreator.java | 53 +++++---- .../jdk/nashorn/internal/objects/Global.java | 14 ++- .../internal/objects/NativeJSAdapter.java | 2 +- .../nashorn/internal/parser/JSONParser.java | 32 ++++-- .../internal/runtime/AccessorProperty.java | 37 +++---- .../internal/runtime/AllocationStrategy.java | 9 +- .../jdk/nashorn/internal/runtime/Context.java | 35 +++++- .../internal/runtime/JSONFunctions.java | 3 +- .../jdk/nashorn/internal/runtime/JSType.java | 5 - .../nashorn/internal/runtime/Property.java | 43 +++----- .../nashorn/internal/runtime/PropertyMap.java | 11 +- .../internal/runtime/ScriptObject.java | 80 ++++++-------- .../internal/runtime/SetMethodCreator.java | 8 +- .../internal/runtime/SpillProperty.java | 18 ++- .../internal/runtime/StructureLoader.java | 41 +++++-- .../internal/runtime/linker/Bootstrap.java | 13 +-- .../runtime/linker/NashornGuards.java | 3 +- .../jdk/nashorn/internal/scripts/JD.java | 88 +++++++++++++++ .../jdk/nashorn/internal/scripts/JO.java | 14 +-- nashorn/test/script/nosecurity/JDK-8067215.js | 104 ++++++++++++++++++ 30 files changed, 532 insertions(+), 262 deletions(-) create mode 100644 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/JD.java create mode 100644 nashorn/test/script/nosecurity/JDK-8067215.js diff --git a/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java b/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java index 8eb19b7d112..115e4b19f4e 100644 --- a/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java +++ b/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java @@ -124,8 +124,6 @@ public class PrototypeGenerator extends ClassGenerator { if (memberCount > 0) { // call "super(map$)" mi.getStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC); - // make sure we use duplicated PropertyMap so that original map - // stays intact and so can be used for many global. mi.invokeSpecial(PROTOTYPEOBJECT_TYPE, INIT, SCRIPTOBJECT_INIT_DESC); // initialize Function type fields initFunctionFields(mi); diff --git a/nashorn/docs/DEVELOPER_README b/nashorn/docs/DEVELOPER_README index 5550b903b1d..faff28c0bac 100644 --- a/nashorn/docs/DEVELOPER_README +++ b/nashorn/docs/DEVELOPER_README @@ -63,16 +63,19 @@ SYSTEM PROPERTY: -Dnashorn.codegen.debug.trace= See the description of the codegen logger below. -SYSTEM PROPERTY: -Dnashorn.fields.objects +SYSTEM PROPERTY: -Dnashorn.fields.objects, -Dnashorn.fields.dual -When this property is true, Nashorn will only use object fields for -AccessorProperties. This means that primitive values must be boxed -when stored in a field, which is significantly slower than using -primitive fields. +When the nashorn.fields.objects property is true, Nashorn will always +use object fields for AccessorProperties, requiring boxing for all +primitive property values. When nashorn.fields.dual is set, Nashorn +will always use dual long/object fields, which allows primitives to be +stored without boxing. When neither system property is set, Nashorn +chooses a setting depending on the optimistic types setting (dual +fields when optimistic types are enabled, object-only fields otherwise). -By default, Nashorn uses dual object and long fields. Ints are -represented as the 32 low bits of the long fields. Doubles are -represented as the doubleToLongBits of their value. This way a +With dual fields, Nashorn uses long fields to store primitive values. +Ints are represented as the 32 low bits of the long fields. Doubles +are represented as the doubleToLongBits of their value. This way a single field can be used for all primitive types. Packing and unpacking doubles to their bit representation is intrinsified by the JVM and extremely fast. diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java index fd627a6f1fb..81daa4f228f 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java @@ -43,7 +43,6 @@ import static jdk.nashorn.internal.codegen.CompilerConstants.methodDescriptor; import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup; import static jdk.nashorn.internal.codegen.CompilerConstants.typeDescriptor; import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup; -import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY; import static jdk.nashorn.internal.ir.Symbol.HAS_SLOT; import static jdk.nashorn.internal.ir.Symbol.IS_INTERNAL; import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT; @@ -305,6 +304,14 @@ final class CodeGenerator extends NodeOperatorVisitor getValueType() { - if (OBJECT_FIELDS_ONLY || value == null || paramType == null) { + if (!useDualFields() || value == null || paramType == null || paramType.isBoolean()) { return Object.class; } - return paramType.isBoolean() ? Object.class : paramType.getTypeClass(); + return paramType.getTypeClass(); } }); } @@ -2555,7 +2562,7 @@ final class CodeGenerator extends NodeOperatorVisitor valueType = (OBJECT_FIELDS_ONLY || value == null || value.getType().isBoolean()) ? Object.class : value.getType().getTypeClass(); + final Class valueType = (!useDualFields() || value == null || value.getType().isBoolean()) ? Object.class : value.getType().getTypeClass(); tuples.add(new MapTuple(key, symbol, Type.typeFor(valueType), value) { @Override public Class getValueType() { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompilerConstants.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompilerConstants.java index e84c9f0477d..a7f31d50406 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompilerConstants.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompilerConstants.java @@ -149,8 +149,11 @@ public enum CompilerConstants { /** Arguments parameter in scope object constructors; in slot 3 when present */ INIT_ARGUMENTS(null, 3), - /** prefix for all ScriptObject subclasses with fields, @see ObjectGenerator */ - JS_OBJECT_PREFIX("JO"), + /** prefix for all ScriptObject subclasses with dual object/primitive fields, see {@link ObjectClassGenerator} */ + JS_OBJECT_DUAL_FIELD_PREFIX("JD"), + + /** prefix for all ScriptObject subclasses with object fields only, see {@link ObjectClassGenerator} */ + JS_OBJECT_SINGLE_FIELD_PREFIX("JO"), /** name for allocate method in JO objects */ ALLOCATE("allocate"), diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FieldObjectCreator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FieldObjectCreator.java index 491af86f63f..25baea0ce28 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FieldObjectCreator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FieldObjectCreator.java @@ -151,7 +151,7 @@ public abstract class FieldObjectCreator extends ObjectCreator { @Override protected PropertyMap makeMap() { assert propertyMap == null : "property map already initialized"; - propertyMap = newMapCreator(fieldObjectClass).makeFieldMap(hasArguments(), fieldCount, paddedFieldCount, evalCode); + propertyMap = newMapCreator(fieldObjectClass).makeFieldMap(hasArguments(), codegen.useDualFields(), fieldCount, paddedFieldCount, evalCode); return propertyMap; } @@ -166,7 +166,7 @@ public abstract class FieldObjectCreator extends ObjectCreator { private void putField(final MethodEmitter method, final String key, final int fieldIndex, final MapTuple tuple) { method.dup(); - final Type fieldType = tuple.isPrimitive() ? PRIMITIVE_FIELD_TYPE : Type.OBJECT; + final Type fieldType = codegen.useDualFields() && tuple.isPrimitive() ? PRIMITIVE_FIELD_TYPE : Type.OBJECT; final String fieldClass = getClassName(); final String fieldName = getFieldName(fieldIndex, fieldType); final String fieldDesc = typeDescriptor(fieldType.getTypeClass()); @@ -202,8 +202,8 @@ public abstract class FieldObjectCreator extends ObjectCreator { */ private void findClass() { fieldObjectClassName = isScope() ? - ObjectClassGenerator.getClassName(fieldCount, paramCount) : - ObjectClassGenerator.getClassName(paddedFieldCount); + ObjectClassGenerator.getClassName(fieldCount, paramCount, codegen.useDualFields()) : + ObjectClassGenerator.getClassName(paddedFieldCount, codegen.useDualFields()); try { this.fieldObjectClass = Context.forStructureClass(Compiler.binaryName(fieldObjectClassName)); diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java index b45b9867116..9f9abf9c0c9 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java @@ -207,7 +207,7 @@ final class FindScopeDepths extends NodeVisitor implements Logga final RecompilableScriptFunctionData data = new RecompilableScriptFunctionData( newFunctionNode, compiler.getCodeInstaller(), - ObjectClassGenerator.createAllocationStrategy(newFunctionNode.getThisProperties()), + ObjectClassGenerator.createAllocationStrategy(newFunctionNode.getThisProperties(), compiler.getContext().useDualFields()), nestedFunctions, externalSymbolDepths.get(fnId), internalSymbols.get(fnId), diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MapCreator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MapCreator.java index ae96dc46607..be99db99c7f 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MapCreator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MapCreator.java @@ -68,17 +68,17 @@ public class MapCreator { * @param evalCode is this property map created for 'eval' code? * @return New map populated with accessor properties. */ - PropertyMap makeFieldMap(final boolean hasArguments, final int fieldCount, final int fieldMaximum, final boolean evalCode) { + PropertyMap makeFieldMap(final boolean hasArguments, final boolean dualFields, final int fieldCount, final int fieldMaximum, final boolean evalCode) { final List properties = new ArrayList<>(); assert tuples != null; for (final MapTuple tuple : tuples) { final String key = tuple.key; final Symbol symbol = tuple.symbol; - final Class initialType = tuple.getValueType(); + final Class initialType = dualFields ? tuple.getValueType() : Object.class; if (symbol != null && !isValidArrayIndex(getArrayIndex(key))) { - final int flags = getPropertyFlags(symbol, hasArguments, evalCode); + final int flags = getPropertyFlags(symbol, hasArguments, evalCode, dualFields); final Property property = new AccessorProperty( key, flags, @@ -92,7 +92,7 @@ public class MapCreator { return PropertyMap.newMap(properties, structure.getName(), fieldCount, fieldMaximum, 0); } - PropertyMap makeSpillMap(final boolean hasArguments) { + PropertyMap makeSpillMap(final boolean hasArguments, final boolean dualFields) { final List properties = new ArrayList<>(); int spillIndex = 0; assert tuples != null; @@ -100,10 +100,10 @@ public class MapCreator { for (final MapTuple tuple : tuples) { final String key = tuple.key; final Symbol symbol = tuple.symbol; - final Class initialType = tuple.getValueType(); + final Class initialType = dualFields ? tuple.getValueType() : Object.class; if (symbol != null && !isValidArrayIndex(getArrayIndex(key))) { - final int flags = getPropertyFlags(symbol, hasArguments, false); + final int flags = getPropertyFlags(symbol, hasArguments, false, dualFields); properties.add( new SpillProperty( key, @@ -124,7 +124,7 @@ public class MapCreator { * * @return flags to use for fields */ - static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode) { + static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) { int flags = 0; if (symbol.isParam()) { @@ -162,6 +162,10 @@ public class MapCreator { flags |= Property.NEEDS_DECLARATION; } + if (dualFields) { + flags |= Property.DUAL_FIELDS; + } + return flags; } } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MapTuple.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MapTuple.java index 024c3d6745e..44cdc8b2c88 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MapTuple.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MapTuple.java @@ -25,8 +25,6 @@ package jdk.nashorn.internal.codegen; -import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY; - import jdk.nashorn.internal.codegen.types.Type; import jdk.nashorn.internal.ir.Symbol; @@ -52,11 +50,11 @@ class MapTuple { } public Class getValueType() { - return OBJECT_FIELDS_ONLY ? Object.class : null; //until proven otherwise we are undefined, see NASHORN-592 int.class; + return null; //until proven otherwise we are undefined, see NASHORN-592 int.class; } boolean isPrimitive() { - return !OBJECT_FIELDS_ONLY && getValueType().isPrimitive() && getValueType() != boolean.class; + return getValueType() != null && getValueType().isPrimitive() && getValueType() != boolean.class; } @Override diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ObjectClassGenerator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ObjectClassGenerator.java index 2205044c9e5..383d2f130d4 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ObjectClassGenerator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ObjectClassGenerator.java @@ -31,7 +31,8 @@ import static jdk.nashorn.internal.codegen.CompilerConstants.INIT_ARGUMENTS; import static jdk.nashorn.internal.codegen.CompilerConstants.INIT_MAP; import static jdk.nashorn.internal.codegen.CompilerConstants.INIT_SCOPE; import static jdk.nashorn.internal.codegen.CompilerConstants.JAVA_THIS; -import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_PREFIX; +import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_DUAL_FIELD_PREFIX; +import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_SINGLE_FIELD_PREFIX; import static jdk.nashorn.internal.codegen.CompilerConstants.className; import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup; import static jdk.nashorn.internal.lookup.Lookup.MH; @@ -99,18 +100,10 @@ public final class ObjectClassGenerator implements Loggable { */ private final DebugLogger log; - /** - * Should the runtime only use java.lang.Object slots for fields? If this is false, the representation - * will be a primitive 64-bit long value used for all primitives and a java.lang.Object for references. - * This introduces a larger number of method handles in the system, as we need to have different getters - * and setters for the different fields. - * - * This is engineered to plug into the TaggedArray implementation, when it's done. - */ - public static final boolean OBJECT_FIELDS_ONLY = Options.getBooleanProperty("nashorn.fields.objects"); - - /** The field types in the system */ - private static final List FIELD_TYPES = new LinkedList<>(); + /** Field types for object-only fields */ + private static final Type[] FIELD_TYPES_OBJECT = new Type[] { Type.OBJECT }; + /** Field types for dual primitive/object fields */ + private static final Type[] FIELD_TYPES_DUAL = new Type[] { Type.LONG, Type.OBJECT }; /** What type is the primitive type in dual representation */ public static final Type PRIMITIVE_FIELD_TYPE = Type.LONG; @@ -118,33 +111,27 @@ public final class ObjectClassGenerator implements Loggable { private static final MethodHandle GET_DIFFERENT = findOwnMH("getDifferent", Object.class, Object.class, Class.class, MethodHandle.class, MethodHandle.class, int.class); private static final MethodHandle GET_DIFFERENT_UNDEFINED = findOwnMH("getDifferentUndefined", Object.class, int.class); - /** - * The list of field types that we support - one type creates one field. This is currently either - * LONG + OBJECT or just OBJECT for classic mode. - */ - static { - if (!OBJECT_FIELDS_ONLY) { - FIELD_TYPES.add(PRIMITIVE_FIELD_TYPE); - } - FIELD_TYPES.add(Type.OBJECT); - } private static boolean initialized = false; /** The context */ private final Context context; + private final boolean dualFields; + /** * Constructor * * @param context a context + * @param dualFields whether to use dual fields representation */ - public ObjectClassGenerator(final Context context) { + public ObjectClassGenerator(final Context context, final boolean dualFields) { this.context = context; + this.dualFields = dualFields; assert context != null; this.log = initLogger(context); if (!initialized) { initialized = true; - if (OBJECT_FIELDS_ONLY) { + if (!dualFields) { log.warning("Running with object fields only - this is a deprecated configuration."); } } @@ -176,16 +163,30 @@ public final class ObjectClassGenerator implements Loggable { throw new AssertionError("cannot pack" + n); } + private static String getPrefixName(final boolean dualFields) { + return dualFields ? JS_OBJECT_DUAL_FIELD_PREFIX.symbolName() : JS_OBJECT_SINGLE_FIELD_PREFIX.symbolName(); + } + + private static String getPrefixName(final String className) { + if (className.startsWith(JS_OBJECT_DUAL_FIELD_PREFIX.symbolName())) { + return getPrefixName(true); + } else if (className.startsWith(JS_OBJECT_SINGLE_FIELD_PREFIX.symbolName())) { + return getPrefixName(false); + } + throw new AssertionError("Not a structure class: " + className); + } + /** * Returns the class name for JavaScript objects with fieldCount fields. * * @param fieldCount Number of fields to allocate. - * + * @param dualFields whether to use dual fields representation * @return The class name. */ - public static String getClassName(final int fieldCount) { - return fieldCount != 0 ? SCRIPTS_PACKAGE + '/' + JS_OBJECT_PREFIX.symbolName() + fieldCount : - SCRIPTS_PACKAGE + '/' + JS_OBJECT_PREFIX.symbolName(); + public static String getClassName(final int fieldCount, final boolean dualFields) { + final String prefix = getPrefixName(dualFields); + return fieldCount != 0 ? SCRIPTS_PACKAGE + '/' + prefix + fieldCount : + SCRIPTS_PACKAGE + '/' + prefix; } /** @@ -194,22 +195,23 @@ public final class ObjectClassGenerator implements Loggable { * * @param fieldCount Number of fields to allocate. * @param paramCount Number of parameters to allocate - * + * @param dualFields whether to use dual fields representation * @return The class name. */ - public static String getClassName(final int fieldCount, final int paramCount) { - return SCRIPTS_PACKAGE + '/' + JS_OBJECT_PREFIX.symbolName() + fieldCount + SCOPE_MARKER + paramCount; + public static String getClassName(final int fieldCount, final int paramCount, final boolean dualFields) { + return SCRIPTS_PACKAGE + '/' + getPrefixName(dualFields) + fieldCount + SCOPE_MARKER + paramCount; } /** * Returns the number of fields in the JavaScript scope class. Its name had to be generated using either - * {@link #getClassName(int)} or {@link #getClassName(int, int)}. + * {@link #getClassName(int, boolean)} or {@link #getClassName(int, int, boolean)}. * @param clazz the JavaScript scope class. * @return the number of fields in the scope class. */ public static int getFieldCount(final Class clazz) { final String name = clazz.getSimpleName(); - final String prefix = JS_OBJECT_PREFIX.symbolName(); + final String prefix = getPrefixName(name); + if (prefix.equals(name)) { return 0; } @@ -238,8 +240,8 @@ public final class ObjectClassGenerator implements Loggable { * @param className name of class * @param fieldNames fields to initialize to undefined, where applicable */ - private static void initializeToUndefined(final MethodEmitter init, final String className, final List fieldNames) { - if (!OBJECT_FIELDS_ONLY) { + private void initializeToUndefined(final MethodEmitter init, final String className, final List fieldNames) { + if (dualFields) { // no need to initialize anything to undefined in the dual field world // - then we have a constant getter for undefined for any unknown type return; @@ -292,7 +294,7 @@ public final class ObjectClassGenerator implements Loggable { * @return Byte codes for generated class. */ public byte[] generate(final int fieldCount) { - final String className = getClassName(fieldCount); + final String className = getClassName(fieldCount, dualFields); final String superName = className(ScriptObject.class); final ClassEmitter classEmitter = newClassEmitter(className, superName); @@ -322,7 +324,7 @@ public final class ObjectClassGenerator implements Loggable { * @return Byte codes for generated class. */ public byte[] generate(final int fieldCount, final int paramCount) { - final String className = getClassName(fieldCount, paramCount); + final String className = getClassName(fieldCount, paramCount, dualFields); final String superName = className(FunctionScope.class); final ClassEmitter classEmitter = newClassEmitter(className, superName); final List initFields = addFields(classEmitter, fieldCount); @@ -353,11 +355,11 @@ public final class ObjectClassGenerator implements Loggable { * * @return List fields that need to be initialized. */ - private static List addFields(final ClassEmitter classEmitter, final int fieldCount) { + private List addFields(final ClassEmitter classEmitter, final int fieldCount) { final List initFields = new LinkedList<>(); - + final Type[] fieldTypes = dualFields ? FIELD_TYPES_DUAL : FIELD_TYPES_OBJECT; for (int i = 0; i < fieldCount; i++) { - for (final Type type : FIELD_TYPES) { + for (final Type type : fieldTypes) { final String fieldName = getFieldName(i, type); classEmitter.field(fieldName, type.getTypeClass()); @@ -533,13 +535,10 @@ public final class ObjectClassGenerator implements Loggable { private static MethodHandle getterForType(final Class forType, final MethodHandle primitiveGetter, final MethodHandle objectGetter) { switch (getAccessorTypeIndex(forType)) { case TYPE_INT_INDEX: - assert !OBJECT_FIELDS_ONLY : "this can only happen with dual fields"; return MH.explicitCastArguments(primitiveGetter, primitiveGetter.type().changeReturnType(int.class)); case TYPE_LONG_INDEX: - assert !OBJECT_FIELDS_ONLY : "this can only happen with dual fields"; return primitiveGetter; case TYPE_DOUBLE_INDEX: - assert !OBJECT_FIELDS_ONLY : "this can only happen with dual fields"; return MH.filterReturnValue(primitiveGetter, UNPACK_DOUBLE); case TYPE_OBJECT_INDEX: return objectGetter; @@ -557,7 +556,7 @@ public final class ObjectClassGenerator implements Loggable { final boolean isPrimitiveStorage = forType != null && forType.isPrimitive(); //which is the primordial getter - final MethodHandle getter = OBJECT_FIELDS_ONLY ? objectGetter : isPrimitiveStorage ? primitiveGetter : objectGetter; + final MethodHandle getter = primitiveGetter == null ? objectGetter : isPrimitiveStorage ? primitiveGetter : objectGetter; if (forType == null) { if (isOptimistic) { @@ -580,8 +579,7 @@ public final class ObjectClassGenerator implements Loggable { return MH.dropArguments(GET_UNDEFINED.get(ti), 0, Object.class); } - assert forType != null; - assert !OBJECT_FIELDS_ONLY || forType == Object.class : forType; + assert primitiveGetter != null || forType == Object.class : forType; if (isOptimistic) { if (fti < ti) { @@ -635,8 +633,6 @@ public final class ObjectClassGenerator implements Loggable { return tgetter; } - assert !OBJECT_FIELDS_ONLY; - //final MethodType pmt = primitiveGetter.type(); assert primitiveGetter != null; final MethodType tgetterType = tgetter.type(); switch (fti) { @@ -727,7 +723,7 @@ public final class ObjectClassGenerator implements Loggable { final int fti = getAccessorTypeIndex(forType); final int ti = getAccessorTypeIndex(type); - if (fti == TYPE_OBJECT_INDEX || OBJECT_FIELDS_ONLY) { + if (fti == TYPE_OBJECT_INDEX || primitiveSetter == null) { if (ti == TYPE_OBJECT_INDEX) { return objectSetter; } @@ -735,8 +731,6 @@ public final class ObjectClassGenerator implements Loggable { return MH.asType(objectSetter, objectSetter.type().changeParameterType(1, type)); } - assert !OBJECT_FIELDS_ONLY; - final MethodType pmt = primitiveSetter.type(); switch (fti) { @@ -832,8 +826,8 @@ public final class ObjectClassGenerator implements Loggable { * @param thisProperties number of properties assigned to "this" * @return the allocation strategy */ - static AllocationStrategy createAllocationStrategy(final int thisProperties) { + static AllocationStrategy createAllocationStrategy(final int thisProperties, final boolean dualFields) { final int paddedFieldCount = getPaddedFieldCount(thisProperties); - return new AllocationStrategy(paddedFieldCount); + return new AllocationStrategy(paddedFieldCount, dualFields); } } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ObjectCreator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ObjectCreator.java index 1a09ca62df7..782e3d27464 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ObjectCreator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ObjectCreator.java @@ -134,7 +134,7 @@ public abstract class ObjectCreator { MethodEmitter loadTuple(final MethodEmitter method, final MapTuple tuple, final boolean pack) { loadValue(tuple.value, tuple.type); - if (pack && tuple.isPrimitive()) { + if (pack && codegen.useDualFields() && tuple.isPrimitive()) { method.pack(); } else { method.convert(Type.OBJECT); diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SpillObjectCreator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SpillObjectCreator.java index 40d12dfbdc2..567edba405b 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SpillObjectCreator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SpillObjectCreator.java @@ -27,7 +27,6 @@ package jdk.nashorn.internal.codegen; import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup; import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup; -import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY; import java.util.LinkedHashSet; import java.util.List; @@ -42,6 +41,7 @@ import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptRuntime; import jdk.nashorn.internal.runtime.arrays.ArrayData; import jdk.nashorn.internal.runtime.arrays.ArrayIndex; +import jdk.nashorn.internal.scripts.JD; import jdk.nashorn.internal.scripts.JO; /** @@ -65,10 +65,13 @@ public final class SpillObjectCreator extends ObjectCreator { assert !isScope() : "spill scope objects are not currently supported"; final int length = tuples.size(); - final long[] jpresetValues = new long[ScriptObject.spillAllocationLength(length)]; - final Object[] opresetValues = new Object[ScriptObject.spillAllocationLength(length)]; + final boolean dualFields = codegen.useDualFields(); + final int spillLength = ScriptObject.spillAllocationLength(length); + final long[] jpresetValues = dualFields ? new long[spillLength] : null; + final Object[] opresetValues = new Object[spillLength]; final Set postsetValues = new LinkedHashSet<>(); final int callSiteFlags = codegen.getCallSiteFlags(); + final Class objectClass = dualFields ? JD.class : JO.class; ArrayData arrayData = ArrayData.allocate(ScriptRuntime.EMPTY_ARRAY); // Compute constant property values @@ -88,9 +91,9 @@ public final class SpillObjectCreator extends ObjectCreator { final Property property = propertyMap.findProperty(key); if (property != null) { // normal property key - property.setType(JSType.unboxedFieldType(constantValue)); + property.setType(dualFields ? JSType.unboxedFieldType(constantValue) : Object.class); final int slot = property.getSlot(); - if (!OBJECT_FIELDS_ONLY && constantValue instanceof Number) { + if (dualFields && constantValue instanceof Number) { jpresetValues[slot] = ObjectClassGenerator.pack((Number)constantValue); } else { opresetValues[slot] = constantValue; @@ -130,28 +133,32 @@ public final class SpillObjectCreator extends ObjectCreator { //assert postsetValues.isEmpty() : "test me " + postsetValues; // create object and invoke constructor - method._new(JO.class).dup(); + method._new(objectClass).dup(); codegen.loadConstant(propertyMap); //load primitive values to j spill array - codegen.loadConstant(jpresetValues); - for (final int i : postsetValues) { - final MapTuple tuple = tuples.get(i); - final Property property = propertyMap.findProperty(tuple.key); - if (property != null && tuple.isPrimitive()) { - method.dup(); - method.load(property.getSlot()); - loadTuple(method, tuple); - method.arraystore(); + if (dualFields) { + codegen.loadConstant(jpresetValues); + for (final int i : postsetValues) { + final MapTuple tuple = tuples.get(i); + final Property property = propertyMap.findProperty(tuple.key); + if (property != null && tuple.isPrimitive()) { + method.dup(); + method.load(property.getSlot()); + loadTuple(method, tuple); + method.arraystore(); + } } + } else { + method.loadNull(); } //load object values to o spill array codegen.loadConstant(opresetValues); for (final int i : postsetValues) { - final MapTuple tuple = tuples.get(i); - final Property property = propertyMap.findProperty(tuple.key); - if (property != null && !tuple.isPrimitive()) { + final MapTuple tuple = tuples.get(i); + final Property property = propertyMap.findProperty(tuple.key); + if (property != null && (!dualFields || !tuple.isPrimitive())) { method.dup(); method.load(property.getSlot()); loadTuple(method, tuple); @@ -160,7 +167,7 @@ public final class SpillObjectCreator extends ObjectCreator { } //instantiate the script object with spill objects - method.invoke(constructorNoLookup(JO.class, PropertyMap.class, long[].class, Object[].class)); + method.invoke(constructorNoLookup(objectClass, PropertyMap.class, long[].class, Object[].class)); // Set prefix array data if any if (arrayData.length() > 0) { @@ -171,8 +178,8 @@ public final class SpillObjectCreator extends ObjectCreator { // set postfix for (final int i : postsetValues) { - final MapTuple tuple = tuples.get(i); - final Property property = propertyMap.findProperty(tuple.key); + final MapTuple tuple = tuples.get(i); + final Property property = propertyMap.findProperty(tuple.key); if (property == null) { final int index = ArrayIndex.getArrayIndex(tuple.key); assert ArrayIndex.isValidArrayIndex(index); @@ -188,7 +195,9 @@ public final class SpillObjectCreator extends ObjectCreator { @Override protected PropertyMap makeMap() { assert propertyMap == null : "property map already initialized"; - propertyMap = new MapCreator<>(JO.class, tuples).makeSpillMap(false); + final boolean dualFields = codegen.useDualFields(); + final Class clazz = dualFields ? JD.class : JO.class; + propertyMap = new MapCreator<>(clazz, tuples).makeSpillMap(false, codegen.useDualFields()); return propertyMap; } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java index e6eba091c40..16ec29e1dca 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java @@ -79,6 +79,7 @@ import jdk.nashorn.internal.runtime.linker.Bootstrap; import jdk.nashorn.internal.runtime.linker.InvokeByName; import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; import jdk.nashorn.internal.runtime.regexp.RegExpResult; +import jdk.nashorn.internal.scripts.JD; import jdk.nashorn.internal.scripts.JO; import jdk.nashorn.tools.ShellFunctions; @@ -718,7 +719,7 @@ public final class Global extends ScriptObject implements Scope { private static final MethodHandle LOAD = findOwnMH_S("load", Object.class, Object.class, Object.class); private static final MethodHandle LOAD_WITH_NEW_GLOBAL = findOwnMH_S("loadWithNewGlobal", Object.class, Object.class, Object[].class); private static final MethodHandle EXIT = findOwnMH_S("exit", Object.class, Object.class, Object.class); - private static final MethodHandle LEXICAL_SCOPE_FILTER = findOwnMH_S("lexicalScopeFilter", Object.class, Object.class); + private static final MethodHandle LEXICAL_SCOPE_FILTER = findOwnMH_S("lexicalScopeFilter", Object.class, Object.class); // initialized by nasgen private static PropertyMap $nasgenmap$; @@ -750,6 +751,11 @@ public final class Global extends ScriptObject implements Scope { return context; } + @Override + protected boolean useDualFields() { + return context.useDualFields(); + } + // performs initialization checks for Global constructor and returns the // PropertyMap, if everything is fine. private static PropertyMap checkAndGetMap(final Context context) { @@ -933,7 +939,7 @@ public final class Global extends ScriptObject implements Scope { * @return the new ScriptObject */ public ScriptObject newObject() { - return new JO(getObjectPrototype(), JO.getInitialMap()); + return useDualFields() ? new JD(getObjectPrototype()) : new JO(getObjectPrototype()); } /** @@ -2744,8 +2750,8 @@ public final class Global extends ScriptObject implements Scope { */ private static class LexicalScope extends ScriptObject { - LexicalScope(final ScriptObject proto) { - super(proto, PropertyMap.newMap()); + LexicalScope(final Global global) { + super(global, PropertyMap.newMap()); } @Override diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJSAdapter.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJSAdapter.java index c5ca91010fa..c5ece8cd007 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJSAdapter.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJSAdapter.java @@ -160,7 +160,7 @@ public final class NativeJSAdapter extends ScriptObject { } private static ScriptObject wrapAdaptee(final ScriptObject adaptee) { - return new JO(adaptee, JO.getInitialMap()); + return new JO(adaptee); } @Override diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/JSONParser.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/JSONParser.java index 524381873fb..5360226a39a 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/JSONParser.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/JSONParser.java @@ -41,6 +41,7 @@ import jdk.nashorn.internal.runtime.Source; import jdk.nashorn.internal.runtime.SpillProperty; import jdk.nashorn.internal.runtime.arrays.ArrayData; import jdk.nashorn.internal.runtime.arrays.ArrayIndex; +import jdk.nashorn.internal.scripts.JD; import jdk.nashorn.internal.scripts.JO; import static jdk.nashorn.internal.parser.TokenType.STRING; @@ -54,11 +55,10 @@ public class JSONParser { final private String source; final private Global global; + final private boolean dualFields; final int length; int pos = 0; - private static PropertyMap EMPTY_MAP = PropertyMap.newMap(); - private static final int EOF = -1; private static final String TRUE = "true"; @@ -74,10 +74,11 @@ public class JSONParser { * @param source the source * @param global the global object */ - public JSONParser(final String source, final Global global ) { + public JSONParser(final String source, final Global global, final boolean dualFields) { this.source = source; this.global = global; this.length = source.length(); + this.dualFields = dualFields; } /** @@ -180,7 +181,7 @@ public class JSONParser { } private Object parseObject() { - PropertyMap propertyMap = EMPTY_MAP; + PropertyMap propertyMap = dualFields ? JD.getInitialMap() : JO.getInitialMap(); ArrayData arrayData = ArrayData.EMPTY_ARRAY; final ArrayList values = new ArrayList<>(); int state = STATE_EMPTY; @@ -241,36 +242,45 @@ public class JSONParser { return newArrayData.set(index, value, false); } - private static PropertyMap addObjectProperty(final PropertyMap propertyMap, final List values, + private PropertyMap addObjectProperty(final PropertyMap propertyMap, final List values, final String id, final Object value) { final Property oldProperty = propertyMap.findProperty(id); final PropertyMap newMap; - final Class type = ObjectClassGenerator.OBJECT_FIELDS_ONLY ? Object.class : getType(value); + final Class type; + final int flags; + if (dualFields) { + type = getType(value); + flags = Property.DUAL_FIELDS; + } else { + type = Object.class; + flags = 0; + } if (oldProperty != null) { values.set(oldProperty.getSlot(), value); - newMap = propertyMap.replaceProperty(oldProperty, new SpillProperty(id, 0, oldProperty.getSlot(), type));; + newMap = propertyMap.replaceProperty(oldProperty, new SpillProperty(id, flags, oldProperty.getSlot(), type));; } else { values.add(value); - newMap = propertyMap.addProperty(new SpillProperty(id, 0, propertyMap.size(), type)); + newMap = propertyMap.addProperty(new SpillProperty(id, flags, propertyMap.size(), type)); } return newMap; } private Object createObject(final PropertyMap propertyMap, final List values, final ArrayData arrayData) { - final long[] primitiveSpill = new long[values.size()]; + final long[] primitiveSpill = dualFields ? new long[values.size()] : null; final Object[] objectSpill = new Object[values.size()]; for (final Property property : propertyMap.getProperties()) { - if (property.getType() == Object.class) { + if (!dualFields || property.getType() == Object.class) { objectSpill[property.getSlot()] = values.get(property.getSlot()); } else { primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot())); } } - final ScriptObject object = new JO(propertyMap, primitiveSpill, objectSpill); + final ScriptObject object = dualFields ? + new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill); object.setInitialProto(global.getObjectPrototype()); object.setArray(arrayData); return object; diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AccessorProperty.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AccessorProperty.java index a9afeb93abf..6fde66b45f2 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AccessorProperty.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AccessorProperty.java @@ -25,7 +25,6 @@ package jdk.nashorn.internal.runtime; -import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY; import static jdk.nashorn.internal.codegen.ObjectClassGenerator.PRIMITIVE_FIELD_TYPE; import static jdk.nashorn.internal.codegen.ObjectClassGenerator.createGetter; import static jdk.nashorn.internal.codegen.ObjectClassGenerator.createSetter; @@ -98,7 +97,7 @@ public class AccessorProperty extends Property { objectSetters[i] = MH.asType(MH.setter(LOOKUP, structure, fieldName, typeClass), Lookup.SET_OBJECT_TYPE); } - if (!OBJECT_FIELDS_ONLY) { + if (!StructureLoader.isSingleFieldStructure(structure.getName())) { for (int i = 0; i < fieldCount; i++) { final String fieldNamePrimitive = getFieldName(i, PRIMITIVE_FIELD_TYPE); final Class typeClass = PRIMITIVE_FIELD_TYPE.getTypeClass(); @@ -211,7 +210,7 @@ public class AccessorProperty extends Property { * @param setter the property setter or null if non writable, non configurable */ private AccessorProperty(final String key, final int flags, final int slot, final MethodHandle getter, final MethodHandle setter) { - super(key, flags | IS_BUILTIN | (getter.type().returnType().isPrimitive() ? IS_NASGEN_PRIMITIVE : 0), slot); + super(key, flags | IS_BUILTIN | DUAL_FIELDS | (getter.type().returnType().isPrimitive() ? IS_NASGEN_PRIMITIVE : 0), slot); assert !isSpill(); // we don't need to prep the setters these will never be invalidated as this is a nasgen @@ -221,18 +220,15 @@ public class AccessorProperty extends Property { final Class setterType = setter == null ? null : setter.type().parameterType(1); assert setterType == null || setterType == getterType; - if (OBJECT_FIELDS_ONLY) { - primitiveGetter = primitiveSetter = null; + + if (getterType == int.class || getterType == long.class) { + primitiveGetter = MH.asType(getter, Lookup.GET_PRIMITIVE_TYPE); + primitiveSetter = setter == null ? null : MH.asType(setter, Lookup.SET_PRIMITIVE_TYPE); + } else if (getterType == double.class) { + primitiveGetter = MH.asType(MH.filterReturnValue(getter, ObjectClassGenerator.PACK_DOUBLE), Lookup.GET_PRIMITIVE_TYPE); + primitiveSetter = setter == null ? null : MH.asType(MH.filterArguments(setter, 1, ObjectClassGenerator.UNPACK_DOUBLE), Lookup.SET_PRIMITIVE_TYPE); } else { - if (getterType == int.class || getterType == long.class) { - primitiveGetter = MH.asType(getter, Lookup.GET_PRIMITIVE_TYPE); - primitiveSetter = setter == null ? null : MH.asType(setter, Lookup.SET_PRIMITIVE_TYPE); - } else if (getterType == double.class) { - primitiveGetter = MH.asType(MH.filterReturnValue(getter, ObjectClassGenerator.PACK_DOUBLE), Lookup.GET_PRIMITIVE_TYPE); - primitiveSetter = setter == null ? null : MH.asType(MH.filterArguments(setter, 1, ObjectClassGenerator.UNPACK_DOUBLE), Lookup.SET_PRIMITIVE_TYPE); - } else { - primitiveGetter = primitiveSetter = null; - } + primitiveGetter = primitiveSetter = null; } assert primitiveGetter == null || primitiveGetter.type() == Lookup.GET_PRIMITIVE_TYPE : primitiveGetter + "!=" + Lookup.GET_PRIMITIVE_TYPE; @@ -241,7 +237,7 @@ public class AccessorProperty extends Property { objectGetter = getter.type() != Lookup.GET_OBJECT_TYPE ? MH.asType(getter, Lookup.GET_OBJECT_TYPE) : getter; objectSetter = setter != null && setter.type() != Lookup.SET_OBJECT_TYPE ? MH.asType(setter, Lookup.SET_OBJECT_TYPE) : setter; - setType(OBJECT_FIELDS_ONLY ? Object.class : getterType); + setType(getterType); } /** @@ -282,6 +278,9 @@ public class AccessorProperty extends Property { objectSetter = gs.objectSetters[slot]; primitiveSetter = gs.primitiveSetters[slot]; } + + // Always use dual fields except for single field structures + assert hasDualFields() != StructureLoader.isSingleFieldStructure(structure.getName()); } /** @@ -310,7 +309,7 @@ public class AccessorProperty extends Property { */ public AccessorProperty(final String key, final int flags, final Class structure, final int slot, final Class initialType) { this(key, flags, structure, slot); - setType(OBJECT_FIELDS_ONLY ? Object.class : initialType); + setType(hasDualFields() ? initialType : Object.class); } /** @@ -347,7 +346,7 @@ public class AccessorProperty extends Property { * @param initialValue initial value */ protected final void setInitialValue(final ScriptObject owner, final Object initialValue) { - setType(JSType.unboxedFieldType(initialValue)); + setType(hasDualFields() ? JSType.unboxedFieldType(initialValue) : Object.class); if (initialValue instanceof Integer) { invokeSetter(owner, ((Integer)initialValue).intValue()); } else if (initialValue instanceof Long) { @@ -363,7 +362,7 @@ public class AccessorProperty extends Property { * Initialize the type of a property */ protected final void initializeType() { - setType(OBJECT_FIELDS_ONLY ? Object.class : null); + setType(!hasDualFields() ? Object.class : null); } private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException { @@ -670,7 +669,7 @@ public class AccessorProperty extends Property { @Override public final boolean canChangeType() { - if (OBJECT_FIELDS_ONLY) { + if (!hasDualFields()) { return false; } // Return true for currently undefined even if non-writable/configurable to allow initialization of ES6 CONST. diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AllocationStrategy.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AllocationStrategy.java index 395aee5ce4a..f25b588448a 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AllocationStrategy.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AllocationStrategy.java @@ -44,6 +44,9 @@ final public class AllocationStrategy implements Serializable { /** Number of fields in the allocated object */ private final int fieldCount; + /** Whether to use dual field representation */ + private final boolean dualFields; + /** Name of class where allocator function resides */ private transient String allocatorClassName; @@ -53,15 +56,17 @@ final public class AllocationStrategy implements Serializable { /** * Construct an allocation strategy with the given map and class name. * @param fieldCount number of fields in the allocated object + * @param dualFields whether to use dual field representation */ - public AllocationStrategy(final int fieldCount) { + public AllocationStrategy(final int fieldCount, final boolean dualFields) { this.fieldCount = fieldCount; + this.dualFields = dualFields; } private String getAllocatorClassName() { if (allocatorClassName == null) { // These classes get loaded, so an interned variant of their name is most likely around anyway. - allocatorClassName = Compiler.binaryName(ObjectClassGenerator.getClassName(fieldCount)).intern(); + allocatorClassName = Compiler.binaryName(ObjectClassGenerator.getClassName(fieldCount, dualFields)).intern(); } return allocatorClassName; } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java index 8c265c8a7ff..5c4bbd662f5 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java @@ -130,6 +130,23 @@ public final class Context { private static MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); private static MethodType CREATE_PROGRAM_FUNCTION_TYPE = MethodType.methodType(ScriptFunction.class, ScriptObject.class); + /** + * Should scripts use only object slots for fields, or dual long/object slots? The default + * behaviour is to couple this to optimistic types, using dual representation if optimistic types are enabled + * and single field representation otherwise. This can be overridden by setting either the "nashorn.fields.objects" + * or "nashorn.fields.dual" system property. + */ + private final FieldMode fieldMode; + + private static enum FieldMode { + /** Value for automatic field representation depending on optimistic types setting */ + AUTO, + /** Value for object field representation regardless of optimistic types setting */ + OBJECTS, + /** Value for dual primitive/object field representation regardless of optimistic types setting */ + DUAL + } + /** * Keeps track of which builtin prototypes and properties have been relinked * Currently we are conservative and associate the name of a builtin class with all @@ -434,7 +451,7 @@ public final class Context { * @param appLoader application class loader */ public Context(final Options options, final ErrorManager errors, final ClassLoader appLoader) { - this(options, errors, appLoader, (ClassFilter)null); + this(options, errors, appLoader, null); } /** @@ -522,6 +539,14 @@ public final class Context { getErr().println("nashorn full version " + Version.fullVersion()); } + if (Options.getBooleanProperty("nashorn.fields.dual")) { + fieldMode = FieldMode.DUAL; + } else if (Options.getBooleanProperty("nashorn.fields.objects")) { + fieldMode = FieldMode.OBJECTS; + } else { + fieldMode = FieldMode.AUTO; + } + initLoggers(); } @@ -575,6 +600,14 @@ public final class Context { return env.getErr(); } + /** + * Should scripts compiled by this context use dual field representation? + * @return true if using dual fields, false for object-only fields + */ + public boolean useDualFields() { + return fieldMode == FieldMode.DUAL || (fieldMode == FieldMode.AUTO && env._optimistic_types); + } + /** * Get the PropertyMap of the current global scope * @return the property map of the current global scope diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSONFunctions.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSONFunctions.java index 9622b59a17c..d5f3af77e09 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSONFunctions.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSONFunctions.java @@ -72,7 +72,8 @@ public final class JSONFunctions { public static Object parse(final Object text, final Object reviver) { final String str = JSType.toString(text); final Global global = Context.getGlobal(); - final JSONParser parser = new JSONParser(str, global); + final boolean dualFields = ((ScriptObject) global).useDualFields(); + final JSONParser parser = new JSONParser(str, global, dualFields); final Object value; try { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java index c7eae4f5c30..31be7d28b91 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java @@ -26,7 +26,6 @@ package jdk.nashorn.internal.runtime; import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall; -import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY; import static jdk.nashorn.internal.lookup.Lookup.MH; import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; @@ -1972,10 +1971,6 @@ public enum JSType { * @return primive type or Object.class if not primitive */ public static Class unboxedFieldType(final Object o) { - if (OBJECT_FIELDS_ONLY) { - return Object.class; - } - if (o == null) { return Object.class; } else if (o.getClass() == Integer.class) { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Property.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Property.java index 4225c251246..7d5442088cb 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Property.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Property.java @@ -96,6 +96,9 @@ public abstract class Property implements Serializable { /** Is this property an ES6 lexical binding? */ public static final int IS_LEXICAL_BINDING = 1 << 10; + /** Does this property support dual field representation? */ + public static final int DUAL_FIELDS = 1 << 11; + /** Property key. */ private final String key; @@ -286,7 +289,7 @@ public abstract class Property implements Serializable { * @return true if parameter */ public boolean isParameter() { - return (flags & IS_PARAMETER) == IS_PARAMETER; + return (flags & IS_PARAMETER) != 0; } /** @@ -294,7 +297,7 @@ public abstract class Property implements Serializable { * @return true if has arguments */ public boolean hasArguments() { - return (flags & HAS_ARGUMENTS) == HAS_ARGUMENTS; + return (flags & HAS_ARGUMENTS) != 0; } /** @@ -316,7 +319,7 @@ public abstract class Property implements Serializable { * @return true if this is a bound property */ public boolean isBound() { - return (flags & IS_BOUND) == IS_BOUND; + return (flags & IS_BOUND) != 0; } /** @@ -325,7 +328,7 @@ public abstract class Property implements Serializable { * @return true if this is a block-scoped variable */ public boolean needsDeclaration() { - return (flags & NEEDS_DECLARATION) == NEEDS_DECLARATION; + return (flags & NEEDS_DECLARATION) != 0; } /** @@ -345,16 +348,6 @@ public abstract class Property implements Serializable { return this; } - /** - * Check if a flag is set for a property - * @param property property - * @param flag flag to check - * @return true if flag is set - */ - public static boolean checkFlag(final Property property, final int flag) { - return (property.getFlags() & flag) == flag; - } - /** * Get the flags for this property * @return property flags @@ -363,16 +356,6 @@ public abstract class Property implements Serializable { return flags; } - /** - * Get the modify flags for this property. The modify flags are the ECMA 8.6.1 - * flags that decide if the Property is writable, configurable and/or enumerable. - * - * @return modify flags for property - */ - public int getModifyFlags() { - return flags & MODIFY_MASK; - } - /** * Remove property flags from the property. Properties are immutable here, * so any property change that results in a smaller flag set results in the @@ -715,7 +698,7 @@ public abstract class Property implements Serializable { * @return whether this property is a function declaration or not. */ public boolean isFunctionDeclaration() { - return (flags & IS_FUNCTION_DECLARATION) == IS_FUNCTION_DECLARATION; + return (flags & IS_FUNCTION_DECLARATION) != 0; } /** @@ -723,6 +706,14 @@ public abstract class Property implements Serializable { * @return true if this property represents a lexical binding. */ public boolean isLexicalBinding() { - return (flags & IS_LEXICAL_BINDING) == IS_LEXICAL_BINDING; + return (flags & IS_LEXICAL_BINDING) != 0; + } + + /** + * Does this property support dual fields for both primitive and object values? + * @return true if supports dual fields + */ + public boolean hasDualFields() { + return (flags & DUAL_FIELDS) != 0; } } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java index db7c5c992ce..fbc0dbbf47d 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java @@ -198,13 +198,22 @@ public final class PropertyMap implements Iterable, Serializable { return properties == null || properties.isEmpty()? newMap() : newMap(properties, JO.class.getName(), 0, 0, 0); } + /** + * Return a sharable empty map for the given object class. + * @param clazz the base object class + * @return New empty {@link PropertyMap}. + */ + public static PropertyMap newMap(final Class clazz) { + return new PropertyMap(EMPTY_HASHMAP, clazz.getName(), 0, 0, 0, false); + } + /** * Return a sharable empty map. * * @return New empty {@link PropertyMap}. */ public static PropertyMap newMap() { - return new PropertyMap(EMPTY_HASHMAP, JO.class.getName(), 0, 0, 0, false); + return newMap(JO.class); } /** diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java index 284505a9baf..daf65c23647 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java @@ -28,7 +28,6 @@ package jdk.nashorn.internal.runtime; import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup; import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCall; import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup; -import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY; import static jdk.nashorn.internal.lookup.Lookup.MH; import static jdk.nashorn.internal.runtime.ECMAErrors.referenceError; import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; @@ -146,12 +145,6 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { /** Area for reference properties added to object after instantiation, see {@link AccessorProperty} */ protected Object[] objectSpill; - /** - * Number of elements in the spill. This may be less than the spill array lengths, if not all of - * the allocated memory is in use - */ - private int spillLength; - /** Indexed array data. */ private ArrayData arrayData; @@ -171,12 +164,6 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { /** Method handle for getting the array data */ public static final Call GET_ARRAY = virtualCall(MethodHandles.lookup(), ScriptObject.class, "getArray", ArrayData.class); - /** Method handle for getting the property map - debugging purposes */ - public static final Call GET_MAP = virtualCall(MethodHandles.lookup(), ScriptObject.class, "getMap", PropertyMap.class); - - /** Method handle for setting the array data */ - public static final Call SET_ARRAY = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setArray", void.class, ArrayData.class); - /** Method handle for getting a function argument at a given index. Used from MapCreator */ public static final Call GET_ARGUMENT = virtualCall(MethodHandles.lookup(), ScriptObject.class, "getArgument", Object.class, int.class); @@ -259,8 +246,7 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { this(map); this.primitiveSpill = primitiveSpill; this.objectSpill = objectSpill; - assert primitiveSpill.length == objectSpill.length : " primitive spill pool size is not the same length as object spill pool size"; - this.spillLength = spillAllocationLength(primitiveSpill.length); + assert primitiveSpill == null || primitiveSpill.length == objectSpill.length : " primitive spill pool size is not the same length as object spill pool size"; } /** @@ -727,7 +713,7 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { setArray(getArray().ensure(longIndex)); doesNotHaveEnsureDelete(longIndex, oldLength, false); } - setArray(getArray().set(index,value, false)); + setArray(getArray().set(index, value, false)); } private void checkIntegerKey(final String key) { @@ -976,10 +962,10 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { * @param setter setter for {@link UserAccessorProperty}, null if not present or N/A */ protected final void initUserAccessors(final String key, final int propertyFlags, final ScriptFunction getter, final ScriptFunction setter) { - final int slot = spillLength; - ensureSpillSize(spillLength); //arguments=slot0, caller=slot0 - objectSpill[slot] = new UserAccessorProperty.Accessors(getter, setter); final PropertyMap oldMap = getMap(); + final int slot = oldMap.getFreeSpillSlot(); + ensureSpillSize(slot); + objectSpill[slot] = new UserAccessorProperty.Accessors(getter, setter); Property newProperty; PropertyMap newMap; do { @@ -1006,19 +992,12 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { final int slot = uc.getSlot(); assert uc.getLocalType() == Object.class; - if (slot >= spillLength) { - uc.setAccessors(this, getMap(), new UserAccessorProperty.Accessors(getter, setter)); - } else { - final UserAccessorProperty.Accessors gs = uc.getAccessors(this); //this crashes - if (gs == null) { - uc.setAccessors(this, getMap(), new UserAccessorProperty.Accessors(getter, setter)); - } else { - //reuse existing getter setter for speed - gs.set(getter, setter); - if (uc.getFlags() == propertyFlags) { - return oldProperty; - } - } + final UserAccessorProperty.Accessors gs = uc.getAccessors(this); //this crashes + assert gs != null; + //reuse existing getter setter for speed + gs.set(getter, setter); + if (uc.getFlags() == propertyFlags) { + return oldProperty; } newProperty = new UserAccessorProperty(uc.getKey(), propertyFlags, slot); } else { @@ -2053,8 +2032,6 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { protoSwitchPoint = null; } - assert OBJECT_FIELDS_ONLY || guard != null : "we always need a map guard here"; - final GuardedInvocation inv = new GuardedInvocation(mh, guard, protoSwitchPoint, exception); return inv.addSwitchPoint(findBuiltinSwitchPoint(name)); } @@ -2531,13 +2508,14 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { /** * Add a spill property for the given key. - * @param key Property key. - * @param propertyFlags Property flags. + * @param key Property key. + * @param flags Property flags. * @return Added property. */ - private Property addSpillProperty(final String key, final int propertyFlags, final Object value, final boolean hasInitialValue) { + private Property addSpillProperty(final String key, final int flags, final Object value, final boolean hasInitialValue) { final PropertyMap propertyMap = getMap(); final int fieldSlot = propertyMap.getFreeFieldSlot(); + final int propertyFlags = flags | (useDualFields() ? Property.DUAL_FIELDS : 0); Property property; if (fieldSlot > -1) { @@ -2562,7 +2540,7 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { * @return Setter method handle. */ MethodHandle addSpill(final Class type, final String key) { - return addSpillProperty(key, 0, null, false).getSetter(OBJECT_FIELDS_ONLY ? Object.class : type, getMap()); + return addSpillProperty(key, 0, null, false).getSetter(type, getMap()); } /** @@ -2649,9 +2627,9 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { final int spreadArgs = mh.type().parameterCount() - callSiteParamCount + 1; return MH.filterArguments( MH.asSpreader( - mh, - Object[].class, - spreadArgs), + mh, + Object[].class, + spreadArgs), callSiteParamCount - 1, MH.insertArguments( TRUNCATINGFILTER, @@ -3739,24 +3717,32 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable { return uc; } + /** + * Returns {@code true} if properties for this object should use dual field mode, {@code false} otherwise. + * @return {@code true} if dual fields should be used. + */ + protected boolean useDualFields() { + return !StructureLoader.isSingleFieldStructure(getClass().getName()); + } + Object ensureSpillSize(final int slot) { - if (slot < spillLength) { + final int oldLength = objectSpill == null ? 0 : objectSpill.length; + if (slot < oldLength) { return this; } final int newLength = alignUp(slot + 1, SPILL_RATE); final Object[] newObjectSpill = new Object[newLength]; - final long[] newPrimitiveSpill = OBJECT_FIELDS_ONLY ? null : new long[newLength]; + final long[] newPrimitiveSpill = useDualFields() ? new long[newLength] : null; if (objectSpill != null) { - System.arraycopy(objectSpill, 0, newObjectSpill, 0, spillLength); - if (!OBJECT_FIELDS_ONLY) { - System.arraycopy(primitiveSpill, 0, newPrimitiveSpill, 0, spillLength); + System.arraycopy(objectSpill, 0, newObjectSpill, 0, oldLength); + if (primitiveSpill != null && newPrimitiveSpill != null) { + System.arraycopy(primitiveSpill, 0, newPrimitiveSpill, 0, oldLength); } } this.primitiveSpill = newPrimitiveSpill; this.objectSpill = newObjectSpill; - this.spillLength = newLength; return this; } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/SetMethodCreator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/SetMethodCreator.java index 90bbf43c8a6..4fe1b4f5485 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/SetMethodCreator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/SetMethodCreator.java @@ -232,14 +232,18 @@ final class SetMethodCreator { } private SetMethod createNewFieldSetter(final SwitchPoint builtinSwitchPoint) { - return createNewSetter(new AccessorProperty(getName(), 0, sobj.getClass(), getMap().getFreeFieldSlot(), type), builtinSwitchPoint); + return createNewSetter(new AccessorProperty(getName(), getFlags(sobj), sobj.getClass(), getMap().getFreeFieldSlot(), type), builtinSwitchPoint); } private SetMethod createNewSpillPropertySetter(final SwitchPoint builtinSwitchPoint) { - return createNewSetter(new SpillProperty(getName(), 0, getMap().getFreeSpillSlot(), type), builtinSwitchPoint); + return createNewSetter(new SpillProperty(getName(), getFlags(sobj), getMap().getFreeSpillSlot(), type), builtinSwitchPoint); } private PropertyMap getNewMap(final Property property) { return getMap().addProperty(property); } + + private static int getFlags(final ScriptObject scriptObject) { + return scriptObject.useDualFields() ? Property.DUAL_FIELDS : 0; + } } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/SpillProperty.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/SpillProperty.java index 856504a3b0d..9019b5609f1 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/SpillProperty.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/SpillProperty.java @@ -25,7 +25,6 @@ package jdk.nashorn.internal.runtime; -import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY; import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; @@ -139,11 +138,11 @@ public class SpillProperty extends AccessorProperty { } } - private static MethodHandle primitiveGetter(final int slot) { - return OBJECT_FIELDS_ONLY ? null : Accessors.getCached(slot, true, true); + private static MethodHandle primitiveGetter(final int slot, final int flags) { + return (flags & DUAL_FIELDS) == DUAL_FIELDS ? Accessors.getCached(slot, true, true) : null; } - private static MethodHandle primitiveSetter(final int slot) { - return OBJECT_FIELDS_ONLY ? null : Accessors.getCached(slot, true, false); + private static MethodHandle primitiveSetter(final int slot, final int flags) { + return (flags & DUAL_FIELDS) == DUAL_FIELDS ? Accessors.getCached(slot, true, false) : null; } private static MethodHandle objectGetter(final int slot) { return Accessors.getCached(slot, false, true); @@ -160,8 +159,7 @@ public class SpillProperty extends AccessorProperty { * @param slot spill slot */ public SpillProperty(final String key, final int flags, final int slot) { - super(key, flags, slot, primitiveGetter(slot), primitiveSetter(slot), objectGetter(slot), objectSetter(slot)); - assert !OBJECT_FIELDS_ONLY || getLocalType() == Object.class; + super(key, flags, slot, primitiveGetter(slot, flags), primitiveSetter(slot, flags), objectGetter(slot), objectSetter(slot)); } /** @@ -173,7 +171,7 @@ public class SpillProperty extends AccessorProperty { */ public SpillProperty(final String key, final int flags, final int slot, final Class initialType) { this(key, flags, slot); - setType(OBJECT_FIELDS_ONLY ? Object.class : initialType); + setType(hasDualFields() ? initialType : Object.class); } SpillProperty(final String key, final int flags, final int slot, final ScriptObject owner, final Object initialValue) { @@ -216,8 +214,8 @@ public class SpillProperty extends AccessorProperty { @Override void initMethodHandles(final Class structure) { final int slot = getSlot(); - primitiveGetter = primitiveGetter(slot); - primitiveSetter = primitiveSetter(slot); + primitiveGetter = primitiveGetter(slot, getFlags()); + primitiveSetter = primitiveSetter(slot, getFlags()); objectGetter = objectGetter(slot); objectSetter = objectSetter(slot); } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java index 41201cde847..8324730a264 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java @@ -27,7 +27,8 @@ package jdk.nashorn.internal.runtime; import static jdk.nashorn.internal.codegen.Compiler.SCRIPTS_PACKAGE; import static jdk.nashorn.internal.codegen.Compiler.binaryName; -import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_PREFIX; +import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_DUAL_FIELD_PREFIX; +import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_SINGLE_FIELD_PREFIX; import java.security.ProtectionDomain; import jdk.nashorn.internal.codegen.ObjectClassGenerator; @@ -36,7 +37,8 @@ import jdk.nashorn.internal.codegen.ObjectClassGenerator; * Responsible for on the fly construction of structure classes. */ final class StructureLoader extends NashornLoader { - private static final String JS_OBJECT_PREFIX_EXTERNAL = binaryName(SCRIPTS_PACKAGE) + '.' + JS_OBJECT_PREFIX.symbolName(); + private static final String SINGLE_FIELD_PREFIX = binaryName(SCRIPTS_PACKAGE) + '.' + JS_OBJECT_SINGLE_FIELD_PREFIX.symbolName(); + private static final String DUAL_FIELD_PREFIX = binaryName(SCRIPTS_PACKAGE) + '.' + JS_OBJECT_DUAL_FIELD_PREFIX.symbolName(); /** * Constructor. @@ -45,14 +47,39 @@ final class StructureLoader extends NashornLoader { super(parent); } + /** + * Returns true if the class name represents a structure object with dual primitive/object fields. + * @param name a class name + * @return true if a dual field structure class + */ + private static boolean isDualFieldStructure(final String name) { + return name.startsWith(DUAL_FIELD_PREFIX); + } + + /** + * Returns true if the class name represents a structure object with single object-only fields. + * @param name a class name + * @return true if a single field structure class + */ + static boolean isSingleFieldStructure(final String name) { + return name.startsWith(SINGLE_FIELD_PREFIX); + } + + /** + * Returns true if the class name represents a Nashorn structure object. + * @param name a class name + * @return true if a structure class + */ static boolean isStructureClass(final String name) { - return name.startsWith(JS_OBJECT_PREFIX_EXTERNAL); + return isDualFieldStructure(name) || isSingleFieldStructure(name); } @Override protected Class findClass(final String name) throws ClassNotFoundException { - if (isStructureClass(name)) { - return generateClass(name, name.substring(JS_OBJECT_PREFIX_EXTERNAL.length())); + if (isDualFieldStructure(name)) { + return generateClass(name, name.substring(DUAL_FIELD_PREFIX.length()), true); + } else if (isSingleFieldStructure(name)) { + return generateClass(name, name.substring(SINGLE_FIELD_PREFIX.length()), false); } return super.findClass(name); } @@ -63,10 +90,10 @@ final class StructureLoader extends NashornLoader { * @param descriptor Layout descriptor. * @return Generated class. */ - private Class generateClass(final String name, final String descriptor) { + private Class generateClass(final String name, final String descriptor, final boolean dualFields) { final Context context = Context.getContextTrusted(); - final byte[] code = new ObjectClassGenerator(context).generate(descriptor); + final byte[] code = new ObjectClassGenerator(context, dualFields).generate(descriptor); return defineClass(name, code, 0, code.length, new ProtectionDomain(null, getPermissions(null))); } } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java index b00d3ec1f87..9cdf6d5c352 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java @@ -74,17 +74,16 @@ public final class Bootstrap { * of object fields only, it is fine. However, with dual fields, in order to get * performance on benchmarks with a lot of object instantiation and then field * reassignment, it can take slightly more relinks to become stable with type - * changes swapping out an entire proprety map and making a map guard fail. - * Therefore the relink threshold is set to 16 for dual fields (now the default). - * This doesn't seem to have any other negative performance implication. + * changes swapping out an entire property map and making a map guard fail. + * Since we need to set this value statically it must work with possibly changing + * optimistic types and dual fields settings. A higher value does not seem to have + * any other negative performance implication when running with object-only fields, + * so we choose a higher value here. * * See for example octane.gbemu, run with --log=fields:warning to study * megamorphic behavior */ - private static final int NASHORN_DEFAULT_UNSTABLE_RELINK_THRESHOLD = - ObjectClassGenerator.OBJECT_FIELDS_ONLY ? - 8 : - 16; + private static final int NASHORN_DEFAULT_UNSTABLE_RELINK_THRESHOLD = 16; // do not create me!! private Bootstrap() { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornGuards.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornGuards.java index dac36d4afb7..ca7034d139c 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornGuards.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornGuards.java @@ -33,7 +33,6 @@ import java.lang.ref.WeakReference; import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.linker.LinkRequest; import jdk.nashorn.api.scripting.JSObject; -import jdk.nashorn.internal.codegen.ObjectClassGenerator; import jdk.nashorn.internal.objects.Global; import jdk.nashorn.internal.runtime.Property; import jdk.nashorn.internal.runtime.PropertyMap; @@ -123,7 +122,7 @@ public final class NashornGuards { */ static boolean needsGuard(final Property property, final CallSiteDescriptor desc) { return property == null || property.isConfigurable() - || property.isBound() || !ObjectClassGenerator.OBJECT_FIELDS_ONLY + || property.isBound() || property.hasDualFields() || !NashornCallSiteDescriptor.isFastScope(desc) || property.canChangeType(); } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/JD.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/JD.java new file mode 100644 index 00000000000..11d6cacc4bc --- /dev/null +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/JD.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2015, 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 jdk.nashorn.internal.scripts; + +import jdk.nashorn.internal.runtime.PropertyMap; +import jdk.nashorn.internal.runtime.ScriptObject; + +/** + * Empty object class for dual primitive-object fields. + */ +public class JD extends ScriptObject { + + private static final PropertyMap map$ = PropertyMap.newMap(JD.class); + + /** + * Returns the initial property map to be used. + * @return the initial property map. + */ + public static PropertyMap getInitialMap() { + return map$; + } + + /** + * Constructor given an initial property map + * + * @param map the property map + */ + public JD(final PropertyMap map) { + super(map); + } + + /** + * Constructor given an initial prototype and the default initial property map. + * + * @param proto the prototype object + */ + public JD(final ScriptObject proto) { + super(proto, getInitialMap()); + } + + /** + * Constructor that takes a pre-initialized spill pool. Used by + * {@link jdk.nashorn.internal.codegen.SpillObjectCreator} and + * {@link jdk.nashorn.internal.parser.JSONParser} for initializing object literals + * + * @param map property map + * @param primitiveSpill primitive spill pool + * @param objectSpill reference spill pool + */ + public JD(final PropertyMap map, final long[] primitiveSpill, final Object[] objectSpill) { + super(map, primitiveSpill, objectSpill); + } + + /** + * A method handle of this method is passed to the ScriptFunction constructor. + * + * @param map the property map to use for allocatorMap + * + * @return newly allocated ScriptObject + */ + public static ScriptObject allocate(final PropertyMap map) { + return new JD(map); + } +} + diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/JO.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/JO.java index 2388a9781bd..1f9aa7ca127 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/JO.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/JO.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -29,11 +29,11 @@ import jdk.nashorn.internal.runtime.PropertyMap; import jdk.nashorn.internal.runtime.ScriptObject; /** - * Empty object class. + * Empty object class for object-only fields. */ public class JO extends ScriptObject { - private static final PropertyMap map$ = PropertyMap.newMap(); + private static final PropertyMap map$ = PropertyMap.newMap(JO.class); /** * Returns the initial property map to be used. @@ -53,13 +53,12 @@ public class JO extends ScriptObject { } /** - * Constructor given an initial prototype and an initial property map. + * Constructor given an initial prototype and the default initial property map. * * @param proto the prototype object - * @param map the property map */ - public JO(final ScriptObject proto, final PropertyMap map) { - super(proto, map); + public JO(final ScriptObject proto) { + super(proto, getInitialMap()); } /** @@ -86,3 +85,4 @@ public class JO extends ScriptObject { return new JO(map); } } + diff --git a/nashorn/test/script/nosecurity/JDK-8067215.js b/nashorn/test/script/nosecurity/JDK-8067215.js new file mode 100644 index 00000000000..12877acbf43 --- /dev/null +++ b/nashorn/test/script/nosecurity/JDK-8067215.js @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2015, 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. + * + * 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. + */ + +/** + * JDK-8067215: Disable dual fields when not using optimistic types + * + * @test + * @run + * @option -Dnashorn.debug=true + * @fork + */ + +var intType = Java.type("int"); +var doubleType = Java.type("double"); +var longType = Java.type("long"); +var objectType = Java.type("java.lang.Object"); + +var Context = Java.type("jdk.nashorn.internal.runtime.Context"); +var JSType = Java.type("jdk.nashorn.internal.runtime.JSType"); + +var context = Context.getContext(); +var dualFields = context.useDualFields(); +var optimisticTypes = context.getEnv()._optimistic_types; + +if (dualFields != optimisticTypes) { + throw new Error("Wrong dual fields setting"); +} + +function testMap(obj) { + obj.x = "foo"; + obj["y"] = 0; + Object.defineProperty(obj, "z", {value: 0.5}); + var map = Debug.map(obj); + for (var key in obj) { + var prop = map.findProperty(key); + if (prop.hasDualFields() !== dualFields) { + throw new Error("Wrong property flags: " + prop); + } + if (prop.getType() != getExpectedType(obj[key])) { + throw new Error("Wrong property type: " + prop.getType() + " // " + getExpectedType(obj[key])); + + } + } +} + +function getExpectedType(value) { + if (!dualFields) { + return objectType.class; + } + if (JSType.isRepresentableAsInt(value)) { + return intType.class; + } + if (JSType.isRepresentableAsLong(value)) { + return longType.class; + } + if (JSType.isNumber(value)) { + return doubleType.class; + } + return objectType.class; +} + +var o = { + a: 1, + b: 2.5, + c: 0x10000000000, + d: true +}; + +function C() { + this.a = 1; + this.b = 2.5; + this.c = 0x10000000000; + this.d = true; +} + +var a = 1; +var b = 2.5; +var c = 0x10000000000; +var d = true; + +testMap(o); +testMap(new C()); +testMap(JSON.parse('{ "a": 1, "b": 2.5, "c": 1099511627776, "d": true }')); +testMap(this); From 671367fd2a6fcf141956b34afab2e862435aec5f Mon Sep 17 00:00:00 2001 From: Erik Joelsson Date: Fri, 10 Apr 2015 16:32:00 +0200 Subject: [PATCH 239/362] 8073634: Improve clean targets Reviewed-by: ihse --- common/autoconf/basics.m4 | 3 + common/autoconf/basics_windows.m4 | 43 +++++++------- common/autoconf/build-performance.m4 | 7 --- common/autoconf/configure.ac | 4 +- common/autoconf/generated-configure.sh | 81 +++++++++++++++----------- common/autoconf/spec.gmk.in | 4 +- common/autoconf/toolchain_windows.m4 | 2 +- make/Main.gmk | 14 ++--- make/MainSupport.gmk | 44 +++++++++----- 9 files changed, 114 insertions(+), 88 deletions(-) diff --git a/common/autoconf/basics.m4 b/common/autoconf/basics.m4 index d9df0877703..02a096ed8c1 100644 --- a/common/autoconf/basics.m4 +++ b/common/autoconf/basics.m4 @@ -658,6 +658,8 @@ AC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR], fi OUTPUT_ROOT="$SRC_ROOT/build/${CONF_NAME}" $MKDIR -p "$OUTPUT_ROOT" + CONFIGURESUPPORT_OUTPUTDIR="$OUTPUT_ROOT/configure-support" + $MKDIR -p "$CONFIGURESUPPORT_OUTPUTDIR" if test ! -d "$OUTPUT_ROOT"; then AC_MSG_ERROR([Could not create build directory $OUTPUT_ROOT]) fi @@ -703,6 +705,7 @@ AC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR], AC_SUBST(SPEC, $OUTPUT_ROOT/spec.gmk) AC_SUBST(CONF_NAME, $CONF_NAME) AC_SUBST(OUTPUT_ROOT, $OUTPUT_ROOT) + AC_SUBST(CONFIGURESUPPORT_OUTPUTDIR) # The spec.gmk file contains all variables for the make system. AC_CONFIG_FILES([$OUTPUT_ROOT/spec.gmk:$AUTOCONF_DIR/spec.gmk.in]) diff --git a/common/autoconf/basics_windows.m4 b/common/autoconf/basics_windows.m4 index 1bcb6151486..7ce14a82d8b 100644 --- a/common/autoconf/basics_windows.m4 +++ b/common/autoconf/basics_windows.m4 @@ -383,45 +383,46 @@ AC_DEFUN_ONCE([BASIC_COMPILE_FIXPATH], if test "x$OPENJDK_BUILD_OS" = xwindows; then AC_MSG_CHECKING([if fixpath can be created]) FIXPATH_SRC="$SRC_ROOT/common/src/fixpath.c" - FIXPATH_BIN="$OUTPUT_ROOT/fixpath.exe" + FIXPATH_BIN="$CONFIGURESUPPORT_OUTPUTDIR/bin/fixpath.exe" + FIXPATH_DIR="$CONFIGURESUPPORT_OUTPUTDIR/fixpath" if test "x$OPENJDK_BUILD_OS_ENV" = xwindows.cygwin; then - FIXPATH_SRC=`$CYGPATH -m $FIXPATH_SRC` - FIXPATH_BIN=`$CYGPATH -m $FIXPATH_BIN` # Important to keep the .exe suffix on Cygwin for Hotspot makefiles - FIXPATH="$OUTPUT_ROOT/fixpath.exe -c" + FIXPATH="$FIXPATH_BIN -c" elif test "x$OPENJDK_BUILD_OS_ENV" = xwindows.msys; then - FIXPATH_SRC=`cmd //c echo $FIXPATH_SRC` - FIXPATH_BIN=`cmd //c echo $FIXPATH_BIN` - # Take all collected prefixes and turn them into a -m/c/foo@/c/bar@... command line # @ was chosen as separator to minimize risk of other tools messing around with it - all_unique_prefixes=`echo "${all_fixpath_prefixes@<:@@@:>@}" | tr ' ' '\n' | grep '^/./' | sort | uniq` + all_unique_prefixes=`echo "${all_fixpath_prefixes@<:@@@:>@}" \ + | tr ' ' '\n' | grep '^/./' | sort | uniq` fixpath_argument_list=`echo $all_unique_prefixes | tr ' ' '@'` - - FIXPATH="$OUTPUT_ROOT/fixpath -m$fixpath_argument_list" + FIXPATH="$FIXPATH_BIN -m$fixpath_argument_list" fi - rm -f $OUTPUT_ROOT/fixpath* - cd $OUTPUT_ROOT - $CC $FIXPATH_SRC -Fe$FIXPATH_BIN > $OUTPUT_ROOT/fixpath1.log 2>&1 + FIXPATH_SRC_W="$FIXPATH_SRC" + FIXPATH_BIN_W="$FIXPATH_BIN" + BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([FIXPATH_SRC_W]) + BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([FIXPATH_BIN_W]) + $RM -rf $FIXPATH_BIN $FIXPATH_DIR + $MKDIR -p $FIXPATH_DIR $CONFIGURESUPPORT_OUTPUTDIR/bin + cd $FIXPATH_DIR + $CC $FIXPATH_SRC_W -Fe$FIXPATH_BIN_W > $FIXPATH_DIR/fixpath1.log 2>&1 cd $CURDIR - if test ! -x $OUTPUT_ROOT/fixpath.exe; then + if test ! -x $FIXPATH_BIN; then AC_MSG_RESULT([no]) - cat $OUTPUT_ROOT/fixpath1.log - AC_MSG_ERROR([Could not create $OUTPUT_ROOT/fixpath.exe]) + cat $FIXPATH_DIR/fixpath1.log + AC_MSG_ERROR([Could not create $FIXPATH_BIN]) fi AC_MSG_RESULT([yes]) AC_MSG_CHECKING([if fixpath.exe works]) - cd $OUTPUT_ROOT - $FIXPATH $CC $SRC_ROOT/common/src/fixpath.c -Fe$OUTPUT_ROOT/fixpath2.exe > $OUTPUT_ROOT/fixpath2.log 2>&1 + cd $FIXPATH_DIR + $FIXPATH $CC $FIXPATH_SRC -Fe$FIXPATH_DIR/fixpath2.exe \ + > $FIXPATH_DIR/fixpath2.log 2>&1 cd $CURDIR - if test ! -x $OUTPUT_ROOT/fixpath2.exe; then + if test ! -x $FIXPATH_DIR/fixpath2.exe; then AC_MSG_RESULT([no]) - cat $OUTPUT_ROOT/fixpath2.log + cat $FIXPATH_DIR/fixpath2.log AC_MSG_ERROR([fixpath did not work!]) fi AC_MSG_RESULT([yes]) - rm -f $OUTPUT_ROOT/fixpath?.??? $OUTPUT_ROOT/fixpath.obj fi AC_SUBST(FIXPATH) diff --git a/common/autoconf/build-performance.m4 b/common/autoconf/build-performance.m4 index 5b3dbdd1fe4..b5911b789a7 100644 --- a/common/autoconf/build-performance.m4 +++ b/common/autoconf/build-performance.m4 @@ -336,11 +336,4 @@ AC_DEFUN_ONCE([BPERF_SETUP_SMART_JAVAC], AC_MSG_CHECKING([whether to use sjavac]) AC_MSG_RESULT([$ENABLE_SJAVAC]) AC_SUBST(ENABLE_SJAVAC) - - if test "x$ENABLE_SJAVAC" = xyes; then - SJAVAC_SERVER_DIR="$OUTPUT_ROOT/javacservers" - else - SJAVAC_SERVER_DIR= - fi - AC_SUBST(SJAVAC_SERVER_DIR) ]) diff --git a/common/autoconf/configure.ac b/common/autoconf/configure.ac index 29dd14662ca..560f4525b6a 100644 --- a/common/autoconf/configure.ac +++ b/common/autoconf/configure.ac @@ -261,7 +261,7 @@ CUSTOM_LATE_HOOK # We're messing a bit with internal autoconf variables to put the config.status # in the output directory instead of the current directory. -CONFIG_STATUS="$OUTPUT_ROOT/config.status" +CONFIG_STATUS="$CONFIGURESUPPORT_OUTPUTDIR/config.status" # Create the actual output files. Now the main work of configure is done. AC_OUTPUT @@ -269,7 +269,7 @@ CUSTOM_CONFIG_OUTPUT_GENERATED_HOOK # Try to move the config.log file to the output directory. if test -e ./config.log; then - $MV -f ./config.log "$OUTPUT_ROOT/config.log" 2> /dev/null + $MV -f ./config.log "$CONFIGURESUPPORT_OUTPUTDIR/config.log" 2> /dev/null fi # Make the compare script executable diff --git a/common/autoconf/generated-configure.sh b/common/autoconf/generated-configure.sh index 137ccd58d93..a7fc898624c 100644 --- a/common/autoconf/generated-configure.sh +++ b/common/autoconf/generated-configure.sh @@ -632,7 +632,6 @@ LIBOBJS CFLAGS_CCACHE CCACHE USE_PRECOMPILED_HEADER -SJAVAC_SERVER_DIR ENABLE_SJAVAC SJAVAC_SERVER_JAVA_FLAGS SJAVAC_SERVER_JAVA @@ -884,6 +883,7 @@ CHECK_TOOLSDIR_GMAKE CHECK_MAKE CHECK_GMAKE PKGHANDLER +CONFIGURESUPPORT_OUTPUTDIR OUTPUT_ROOT CONF_NAME SPEC @@ -4365,7 +4365,7 @@ VS_SDK_PLATFORM_NAME_2013= #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1428017006 +DATE_WHEN_GENERATED=1428676283 ############################################################################### # @@ -15266,6 +15266,8 @@ $as_echo "in build directory with custom name" >&6; } fi OUTPUT_ROOT="$SRC_ROOT/build/${CONF_NAME}" $MKDIR -p "$OUTPUT_ROOT" + CONFIGURESUPPORT_OUTPUTDIR="$OUTPUT_ROOT/configure-support" + $MKDIR -p "$CONFIGURESUPPORT_OUTPUTDIR" if test ! -d "$OUTPUT_ROOT"; then as_fn_error $? "Could not create build directory $OUTPUT_ROOT" "$LINENO" 5 fi @@ -15450,6 +15452,7 @@ $as_echo "$as_me: The path of OUTPUT_ROOT, which resolves as \"$path\", is inval OUTPUT_ROOT=$OUTPUT_ROOT + # The spec.gmk file contains all variables for the make system. ac_config_files="$ac_config_files $OUTPUT_ROOT/spec.gmk:$AUTOCONF_DIR/spec.gmk.in" @@ -27622,7 +27625,7 @@ $as_echo "$as_me: Rewriting VS_ENV_CMD to \"$new_complete\"" >&6;} $as_echo "$as_me: Trying to extract Visual Studio environment variables" >&6;} # We need to create a couple of temporary files. - VS_ENV_TMP_DIR="$OUTPUT_ROOT/vs-env" + VS_ENV_TMP_DIR="$CONFIGURESUPPORT_OUTPUTDIR/vs-env" $MKDIR -p $VS_ENV_TMP_DIR # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment). @@ -43136,50 +43139,69 @@ $as_echo "no" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking if fixpath can be created" >&5 $as_echo_n "checking if fixpath can be created... " >&6; } FIXPATH_SRC="$SRC_ROOT/common/src/fixpath.c" - FIXPATH_BIN="$OUTPUT_ROOT/fixpath.exe" + FIXPATH_BIN="$CONFIGURESUPPORT_OUTPUTDIR/bin/fixpath.exe" + FIXPATH_DIR="$CONFIGURESUPPORT_OUTPUTDIR/fixpath" if test "x$OPENJDK_BUILD_OS_ENV" = xwindows.cygwin; then - FIXPATH_SRC=`$CYGPATH -m $FIXPATH_SRC` - FIXPATH_BIN=`$CYGPATH -m $FIXPATH_BIN` # Important to keep the .exe suffix on Cygwin for Hotspot makefiles - FIXPATH="$OUTPUT_ROOT/fixpath.exe -c" + FIXPATH="$FIXPATH_BIN -c" elif test "x$OPENJDK_BUILD_OS_ENV" = xwindows.msys; then - FIXPATH_SRC=`cmd //c echo $FIXPATH_SRC` - FIXPATH_BIN=`cmd //c echo $FIXPATH_BIN` - # Take all collected prefixes and turn them into a -m/c/foo@/c/bar@... command line # @ was chosen as separator to minimize risk of other tools messing around with it - all_unique_prefixes=`echo "${all_fixpath_prefixes[@]}" | tr ' ' '\n' | grep '^/./' | sort | uniq` + all_unique_prefixes=`echo "${all_fixpath_prefixes[@]}" \ + | tr ' ' '\n' | grep '^/./' | sort | uniq` fixpath_argument_list=`echo $all_unique_prefixes | tr ' ' '@'` - - FIXPATH="$OUTPUT_ROOT/fixpath -m$fixpath_argument_list" + FIXPATH="$FIXPATH_BIN -m$fixpath_argument_list" fi - rm -f $OUTPUT_ROOT/fixpath* - cd $OUTPUT_ROOT - $CC $FIXPATH_SRC -Fe$FIXPATH_BIN > $OUTPUT_ROOT/fixpath1.log 2>&1 + FIXPATH_SRC_W="$FIXPATH_SRC" + FIXPATH_BIN_W="$FIXPATH_BIN" + + unix_path="$FIXPATH_SRC_W" + if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then + windows_path=`$CYGPATH -m "$unix_path"` + FIXPATH_SRC_W="$windows_path" + elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then + windows_path=`cmd //c echo $unix_path` + FIXPATH_SRC_W="$windows_path" + fi + + + unix_path="$FIXPATH_BIN_W" + if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then + windows_path=`$CYGPATH -m "$unix_path"` + FIXPATH_BIN_W="$windows_path" + elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then + windows_path=`cmd //c echo $unix_path` + FIXPATH_BIN_W="$windows_path" + fi + + $RM -rf $FIXPATH_BIN $FIXPATH_DIR + $MKDIR -p $FIXPATH_DIR $CONFIGURESUPPORT_OUTPUTDIR/bin + cd $FIXPATH_DIR + $CC $FIXPATH_SRC_W -Fe$FIXPATH_BIN_W > $FIXPATH_DIR/fixpath1.log 2>&1 cd $CURDIR - if test ! -x $OUTPUT_ROOT/fixpath.exe; then + if test ! -x $FIXPATH_BIN; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - cat $OUTPUT_ROOT/fixpath1.log - as_fn_error $? "Could not create $OUTPUT_ROOT/fixpath.exe" "$LINENO" 5 + cat $FIXPATH_DIR/fixpath1.log + as_fn_error $? "Could not create $FIXPATH_BIN" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking if fixpath.exe works" >&5 $as_echo_n "checking if fixpath.exe works... " >&6; } - cd $OUTPUT_ROOT - $FIXPATH $CC $SRC_ROOT/common/src/fixpath.c -Fe$OUTPUT_ROOT/fixpath2.exe > $OUTPUT_ROOT/fixpath2.log 2>&1 + cd $FIXPATH_DIR + $FIXPATH $CC $FIXPATH_SRC -Fe$FIXPATH_DIR/fixpath2.exe \ + > $FIXPATH_DIR/fixpath2.log 2>&1 cd $CURDIR - if test ! -x $OUTPUT_ROOT/fixpath2.exe; then + if test ! -x $FIXPATH_DIR/fixpath2.exe; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - cat $OUTPUT_ROOT/fixpath2.log + cat $FIXPATH_DIR/fixpath2.log as_fn_error $? "fixpath did not work!" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - rm -f $OUTPUT_ROOT/fixpath?.??? $OUTPUT_ROOT/fixpath.obj fi @@ -51415,13 +51437,6 @@ $as_echo_n "checking whether to use sjavac... " >&6; } $as_echo "$ENABLE_SJAVAC" >&6; } - if test "x$ENABLE_SJAVAC" = xyes; then - SJAVAC_SERVER_DIR="$OUTPUT_ROOT/javacservers" - else - SJAVAC_SERVER_DIR= - fi - - # Can the C/C++ compiler use precompiled headers? @@ -51849,7 +51864,7 @@ $as_echo "$OUTPUT_DIR_IS_LOCAL" >&6; } # We're messing a bit with internal autoconf variables to put the config.status # in the output directory instead of the current directory. -CONFIG_STATUS="$OUTPUT_ROOT/config.status" +CONFIG_STATUS="$CONFIGURESUPPORT_OUTPUTDIR/config.status" # Create the actual output files. Now the main work of configure is done. cat >confcache <<\_ACEOF @@ -53017,7 +53032,7 @@ fi # Try to move the config.log file to the output directory. if test -e ./config.log; then - $MV -f ./config.log "$OUTPUT_ROOT/config.log" 2> /dev/null + $MV -f ./config.log "$CONFIGURESUPPORT_OUTPUTDIR/config.log" 2> /dev/null fi # Make the compare script executable diff --git a/common/autoconf/spec.gmk.in b/common/autoconf/spec.gmk.in index a29e90b60d2..8ae516585e0 100644 --- a/common/autoconf/spec.gmk.in +++ b/common/autoconf/spec.gmk.in @@ -237,6 +237,8 @@ JDK_OUTPUTDIR=$(BUILD_OUTPUT)/jdk IMAGES_OUTPUTDIR=$(BUILD_OUTPUT)/images TESTMAKE_OUTPUTDIR=$(BUILD_OUTPUT)/test-make MAKESUPPORT_OUTPUTDIR=$(BUILD_OUTPUT)/make-support +# This does not get overridden in a bootcycle build +CONFIGURESUPPORT_OUTPUTDIR:=@CONFIGURESUPPORT_OUTPUTDIR@ HOTSPOT_DIST=@HOTSPOT_DIST@ @@ -258,7 +260,7 @@ MEMORY_SIZE:=@MEMORY_SIZE@ ENABLE_SJAVAC:=@ENABLE_SJAVAC@ # Store sjavac server synchronization files here, and # the sjavac server log files. -SJAVAC_SERVER_DIR:=@SJAVAC_SERVER_DIR@ +SJAVAC_SERVER_DIR=$(MAKESUPPORT_OUTPUTDIR)/javacservers # Number of parallel jobs to use for compilation JOBS?=@JOBS@ diff --git a/common/autoconf/toolchain_windows.m4 b/common/autoconf/toolchain_windows.m4 index dc1a24875c2..87850a25b2f 100644 --- a/common/autoconf/toolchain_windows.m4 +++ b/common/autoconf/toolchain_windows.m4 @@ -270,7 +270,7 @@ AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV], AC_MSG_NOTICE([Trying to extract Visual Studio environment variables]) # We need to create a couple of temporary files. - VS_ENV_TMP_DIR="$OUTPUT_ROOT/vs-env" + VS_ENV_TMP_DIR="$CONFIGURESUPPORT_OUTPUTDIR/vs-env" $MKDIR -p $VS_ENV_TMP_DIR # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment). diff --git a/make/Main.gmk b/make/Main.gmk index 9d7bed14277..221a0ca37bc 100644 --- a/make/Main.gmk +++ b/make/Main.gmk @@ -541,7 +541,7 @@ CLEAN_DIRS += hotspot jdk bootcycle-build test buildtools support \ CLEAN_DIR_TARGETS := $(addprefix clean-, $(CLEAN_DIRS)) CLEAN_TESTS += hotspot-jtreg-native jdk-jtreg-native CLEAN_TEST_TARGETS += $(addprefix clean-test-, $(CLEAN_TESTS)) -CLEAN_PHASES := gensrc java native include +CLEAN_PHASES := gensrc java native include docs CLEAN_PHASE_TARGETS := $(addprefix clean-, $(CLEAN_PHASES)) CLEAN_MODULE_TARGETS := $(addprefix clean-, $(ALL_MODULES)) # Construct targets of the form clean-$module-$phase @@ -550,7 +550,7 @@ CLEAN_MODULE_PHASE_TARGETS := $(addprefix clean-, $(foreach m, $(ALL_MODULES), \ # Remove everything, except the output from configure. clean: $(CLEAN_DIR_TARGETS) - ($(CD) $(OUTPUT_ROOT) && $(RM) -r source_tips build.log* build-trace*.log*) + ($(CD) $(OUTPUT_ROOT) && $(RM) -r build*.log*) $(ECHO) Cleaned all build artifacts. $(CLEAN_DIR_TARGETS): @@ -574,13 +574,11 @@ $(CLEAN_MODULE_PHASE_TARGETS): # while classes and touch files end up in jdk. clean-support: clean-jdk -clean-docs: clean-docstemp - -# Remove everything, including configure configuration. -# If the output directory was created by configure and now becomes empty, remove it as well. +# Remove everything, including configure configuration. If the output +# directory was created by configure and now becomes empty, remove it as well. dist-clean: clean - ($(CD) $(OUTPUT_ROOT) && $(RM) -r *spec.gmk config.* configure-arguments \ - Makefile compare.sh tmp javacservers) + ($(CD) $(OUTPUT_ROOT) && \ + $(RM) -r *spec.gmk $(CONFIGURESUPPORT_OUTPUTDIR) Makefile compare.sh ide) $(if $(filter $(CONF_NAME),$(notdir $(OUTPUT_ROOT))), \ if test "x`$(LS) $(OUTPUT_ROOT)`" != x; then \ $(ECHO) "Warning: Not removing non-empty configuration directory for '$(CONF_NAME)'" ; \ diff --git a/make/MainSupport.gmk b/make/MainSupport.gmk index aded13eef23..bbd7b817df8 100644 --- a/make/MainSupport.gmk +++ b/make/MainSupport.gmk @@ -41,46 +41,60 @@ endef # Cleans the dir given as $1 define CleanDir @$(PRINTF) "Cleaning $(strip $1) build artifacts ..." - @($(CD) $(OUTPUT_ROOT) && $(RM) -r $1) + @$(PRINTF) "\n" $(LOG_DEBUG) + ($(CD) $(OUTPUT_ROOT) && $(RM) -r $1) @$(PRINTF) " done\n" endef define CleanTest @$(PRINTF) "Cleaning test $(strip $1) ..." - @$(RM) -r $(SUPPORT_OUTPUTDIR)/test/$(strip $(subst -,/,$1)) + @$(PRINTF) "\n" $(LOG_DEBUG) + $(RM) -r $(SUPPORT_OUTPUTDIR)/test/$(strip $(subst -,/,$1)) @$(PRINTF) " done\n" endef define Clean-gensrc @$(PRINTF) "Cleaning gensrc $(if $1,for $(strip $1) )..." - @$(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc/$(strip $1) - @$(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc_no_docs/$(strip $1) + @$(PRINTF) "\n" $(LOG_DEBUG) + $(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc/$(strip $1) + $(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc_no_docs/$(strip $1) @$(PRINTF) " done\n" endef define Clean-java @$(PRINTF) "Cleaning java $(if $1,for $(strip $1) )..." - @$(RM) -r $(JDK_OUTPUTDIR)/modules/$(strip $1) - @$(RM) -r $(SUPPORT_OUTPUTDIR)/misc/$(strip $1) - @$(PRINTF) " done\n" - @$(PRINTF) "Cleaning headers $(if $1,for $(strip $1)) ..." - @$(RM) -r $(SUPPORT_OUTPUTDIR)/headers/$(strip $1) + @$(PRINTF) "\n" $(LOG_DEBUG) + $(RM) -r $(JDK_OUTPUTDIR)/modules/$(strip $1) + $(RM) -r $(SUPPORT_OUTPUTDIR)/misc/$(strip $1) + $(PRINTF) " done\n" + $(PRINTF) "Cleaning headers $(if $1,for $(strip $1)) ..." + $(RM) -r $(SUPPORT_OUTPUTDIR)/headers/$(strip $1) @$(PRINTF) " done\n" endef define Clean-native @$(PRINTF) "Cleaning native $(if $1,for $(strip $1) )..." - @$(RM) -r $(SUPPORT_OUTPUTDIR)/native/$(strip $1) - @$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1) - @$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs-stripped/$(strip $1) - @$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds/$(strip $1) - @$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds-stripped/$(strip $1) + @$(PRINTF) "\n" $(LOG_DEBUG) + $(RM) -r $(SUPPORT_OUTPUTDIR)/native/$(strip $1) + $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1) + $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs-stripped/$(strip $1) + $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds/$(strip $1) + $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds-stripped/$(strip $1) @$(PRINTF) " done\n" endef define Clean-include @$(PRINTF) "Cleaning include $(if $1,for $(strip $1) )..." - @$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_include/$(strip $1) + @$(PRINTF) "\n" $(LOG_DEBUG) + $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_include/$(strip $1) + @$(PRINTF) " done\n" +endef + +define Clean-docs + @$(PRINTF) "Cleaning docs ..." + @$(PRINTF) "\n" $(LOG_DEBUG) + $(RM) -r $(SUPPORT_OUTPUTDIR)/docs + $(RM) -r $(IMAGES_OUTPUTDIR)/docs @$(PRINTF) " done\n" endef From 060b684a5627901d2058d2bfbbc5cd129223064a Mon Sep 17 00:00:00 2001 From: James Laskey Date: Fri, 10 Apr 2015 14:21:24 -0300 Subject: [PATCH 240/362] 8077506: Simplify test JImageTest Reviewed-by: alanb --- jdk/test/jdk/internal/jimage/JImageTest.java | 121 ++++--------------- 1 file changed, 21 insertions(+), 100 deletions(-) diff --git a/jdk/test/jdk/internal/jimage/JImageTest.java b/jdk/test/jdk/internal/jimage/JImageTest.java index 9d4817e4b85..51c0bfdbf57 100644 --- a/jdk/test/jdk/internal/jimage/JImageTest.java +++ b/jdk/test/jdk/internal/jimage/JImageTest.java @@ -22,121 +22,41 @@ */ /* * @test + * @library /lib/testlibrary + * @build jdk.testlibrary.* * @summary Test to see if jimage tool extracts and recreates correctly. * @run main/timeout=360 JImageTest */ -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; + +import jdk.testlibrary.ProcessTools; + /** * Basic test for jimage tool. */ public class JImageTest { - private static Runtime runtime = Runtime.getRuntime(); - private static int errors = 0; + private static void jimage(String... jimageArgs) throws Exception { + ArrayList args = new ArrayList<>(); + args.add("-ms8m"); + args.add("jdk.tools.jimage.Main"); + args.addAll(Arrays.asList(jimageArgs)); - static class Tool { - private int exit = 0; - private String out = ""; - private String err = ""; + ProcessBuilder builder = ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()])); + int res = builder.inheritIO().start().waitFor(); - private void feedInputStream(String in, OutputStream out) { - try (OutputStreamWriter outputStream = new OutputStreamWriter(out)) { - if (in != null) { - outputStream.write(in, 0, in.length()); - } - } catch (final IOException ex) { - // Process was not expecting input. May be normal state of affairs. - } - } - - private Thread getOutputStreamThread(InputStream in, StringBuilder out) { - return new Thread(() -> { - final char buffer[] = new char[1024]; - - try (final InputStreamReader inputStream = new InputStreamReader(in)) { - for (int length; (length = inputStream.read(buffer, 0, buffer.length)) != -1; ) { - out.append(buffer, 0, length); - } - } catch (final IOException ex) { - out.append(ex.toString()); - } - }); - } - - Tool(String[] args) { - this(null, args); - } - - Tool(String in, String[] args) { - ProcessBuilder processBuilder = new ProcessBuilder(args); - exec(processBuilder, in); - } - - private void exec(ProcessBuilder processBuilder, String in) { - StringBuilder outBuilder = new StringBuilder(); - StringBuilder errBuilder = new StringBuilder(); - - try { - Process process = processBuilder.start(); - - Thread outThread = getOutputStreamThread(process.getInputStream(), outBuilder); - Thread errThread = getOutputStreamThread(process.getErrorStream(), errBuilder); - - outThread.start(); - errThread.start(); - - feedInputStream(in, process.getOutputStream()); - - exit = process.waitFor(); - outThread.join(); - errThread.join(); - } catch (IOException | InterruptedException ex) { - ex.printStackTrace(); - exit = -1; - } - - out = outBuilder.toString(); - err = errBuilder.toString(); - } - - int getExit() { - return exit; - } - - String getOut() { - return out; - } - - String getErr() { - return err; + if (res != 0) { + throw new RuntimeException("JImageTest tool FAILED"); } } - private static void exec(String... args) { - Tool tool = new Tool(args); - int exit = tool.getExit(); - - if (exit != 0) { - errors++; - System.err.println("----------Tool.out----------"); - System.err.append(tool.getOut()); - System.err.println("----------Tool.err----------"); - System.err.append(tool.getErr()); - System.err.println("----------Tool.exit----------"); - System.err.println("Error code = " + exit); - throw new RuntimeException("JImageTest FAIL"); - } - } - - public static void main(String[] args) { + public static void main(String[] args) throws Exception { final String JAVA_HOME = System.getProperty("java.home"); Path jimagePath = Paths.get(JAVA_HOME, "bin", "jimage"); Path bootimagePath = Paths.get(JAVA_HOME, "lib", "modules", "bootmodules.jimage"); @@ -147,12 +67,13 @@ public class JImageTest { String extractDir = Paths.get(".", "extract").toAbsolutePath().toString(); String recreateImage = Paths.get(".", "recreate.jimage").toAbsolutePath().toString(); - exec(new String[] {jimage, "extract", "--dir", extractDir, bootimage}); - exec(new String[] {jimage, "recreate", "--dir", extractDir, recreateImage}); + jimage("extract", "--dir", extractDir, bootimage); + jimage("recreate", "--dir", extractDir, recreateImage); System.out.println("Test successful"); } else { System.out.println("Test skipped, no module image"); } + } } From 5a24e90bdd52969ef65feba5b7dea93da82d7f05 Mon Sep 17 00:00:00 2001 From: Mark Sheppard Date: Mon, 13 Apr 2015 14:58:47 +0100 Subject: [PATCH 241/362] 8068721: RMI-IIOP communication fails when ConcurrentHashMap is passed to remote method Reviewed-by: chegar, alanb --- jdk/test/TEST.ROOT | 2 +- jdk/test/TEST.groups | 2 +- .../ConcurrentHashMapTest.java | 143 +++++++++ .../rmi/PortableRemoteObject/HelloClient.java | 98 +++++++ .../rmi/PortableRemoteObject/HelloImpl.java | 60 ++++ .../PortableRemoteObject/HelloInterface.java | 14 + .../rmi/PortableRemoteObject/HelloServer.java | 36 +++ .../javax/rmi/PortableRemoteObject/Test.java | 6 + .../PortableRemoteObject/_HelloImpl_Tie.java | 128 +++++++++ .../_HelloInterface_Stub.java | 272 ++++++++++++++++++ 10 files changed, 759 insertions(+), 2 deletions(-) create mode 100644 jdk/test/javax/rmi/PortableRemoteObject/ConcurrentHashMapTest.java create mode 100644 jdk/test/javax/rmi/PortableRemoteObject/HelloClient.java create mode 100644 jdk/test/javax/rmi/PortableRemoteObject/HelloImpl.java create mode 100644 jdk/test/javax/rmi/PortableRemoteObject/HelloInterface.java create mode 100644 jdk/test/javax/rmi/PortableRemoteObject/HelloServer.java create mode 100644 jdk/test/javax/rmi/PortableRemoteObject/Test.java create mode 100644 jdk/test/javax/rmi/PortableRemoteObject/_HelloImpl_Tie.java create mode 100644 jdk/test/javax/rmi/PortableRemoteObject/_HelloInterface_Stub.java diff --git a/jdk/test/TEST.ROOT b/jdk/test/TEST.ROOT index 0e6fa003234..cf9bdb246ff 100644 --- a/jdk/test/TEST.ROOT +++ b/jdk/test/TEST.ROOT @@ -8,7 +8,7 @@ keys=2d dnd i18n intermittent othervm.dirs=java/awt java/beans javax/accessibility javax/imageio javax/sound javax/print javax/management com/sun/awt sun/awt sun/java2d sun/pisces javax/xml/jaxp/testng/validation # Tests that cannot run concurrently -exclusiveAccess.dirs=java/rmi/Naming java/util/prefs sun/management/jmxremote sun/tools/jstatd sun/security/mscapi java/util/stream +exclusiveAccess.dirs=java/rmi/Naming java/util/prefs sun/management/jmxremote sun/tools/jstatd sun/security/mscapi java/util/stream javax/rmi # Group definitions groups=TEST.groups [closed/TEST.groups] diff --git a/jdk/test/TEST.groups b/jdk/test/TEST.groups index 94103f534b8..73ac408f90e 100644 --- a/jdk/test/TEST.groups +++ b/jdk/test/TEST.groups @@ -138,7 +138,6 @@ jdk_time = \ jdk_rmi = \ java/rmi \ - javax/rmi/ssl \ sun/rmi jdk_security1 = \ @@ -237,6 +236,7 @@ jdk_tools = \ jdk_other = \ java/sql \ javax/sql \ + javax/rmi \ javax/naming \ javax/script \ javax/smartcardio \ diff --git a/jdk/test/javax/rmi/PortableRemoteObject/ConcurrentHashMapTest.java b/jdk/test/javax/rmi/PortableRemoteObject/ConcurrentHashMapTest.java new file mode 100644 index 00000000000..382f201efaf --- /dev/null +++ b/jdk/test/javax/rmi/PortableRemoteObject/ConcurrentHashMapTest.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8068721 + * @summary test RMI-IIOP call with ConcurrentHashMap as an argument + * @library /lib/testlibrary + * @build jdk.testlibrary.* + * @build Test HelloInterface HelloServer HelloClient HelloImpl _HelloImpl_Tie _HelloInterface_Stub ConcurrentHashMapTest + * @run main/othervm -Djava.naming.provider.url=iiop://localhost:1050 -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory ConcurrentHashMapTest + */ + + +import java.io.DataInputStream; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.CountDownLatch; +import jdk.testlibrary.JDKToolFinder; +import jdk.testlibrary.JDKToolLauncher; + +public class ConcurrentHashMapTest { + + static final String ORBD = JDKToolFinder.getTestJDKTool("orbd"); + static final String JAVA = JDKToolFinder.getTestJDKTool("java"); + static final JDKToolLauncher orbdLauncher = JDKToolLauncher.createUsingTestJDK("orbd"); + static final String CLASSPATH = System.getProperty("java.class.path"); + static final int FIVE_SECONDS = 5000; + + private static Exception clientException; + private static boolean exceptionInClient; + private static Process orbdProcess; + private static Process rmiServerProcess; + + public static void main(String[] args) throws Exception { + startTestComponents(); + stopTestComponents(); + System.err.println("Test completed OK "); + } + + static void startTestComponents () throws Exception { + startOrbd(); + Thread.sleep(FIVE_SECONDS); + startRmiIiopServer(); + Thread.sleep(FIVE_SECONDS); + executeRmiIiopClient(); + } + + private static void stopTestComponents() throws Exception { + stopRmiIiopServer(); + stopOrbd(); + if (exceptionInClient) { + throw new RuntimeException(clientException); + } else if (!isResponseReceived()) { + throw new RuntimeException("Expected Response not received"); + } + } + + static void startOrbd() throws Exception { + System.out.println("\nStarting orbd on port 1050 "); + + //orbd -ORBInitialHost localhost -ORBInitialPort 1050 + orbdLauncher.addToolArg("-ORBInitialHost").addToolArg("localhost") + .addToolArg("-ORBInitialPort").addToolArg("1050"); + + System.out.println("ConcurrentHashMapTest: Executing: " + Arrays.asList(orbdLauncher.getCommand())); + ProcessBuilder pb = new ProcessBuilder(orbdLauncher.getCommand()); + pb.redirectError(ProcessBuilder.Redirect.INHERIT); + orbdProcess = pb.start(); + } + + + static void startRmiIiopServer() throws Exception { + System.out.println("\nStarting RmiServer"); + // java -cp . + // -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory + // -Djava.naming.provider.url=iiop://localhost:1050 HelloServer + List commands = new ArrayList<>(); + commands.add(ConcurrentHashMapTest.JAVA); + commands.add("-Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory"); + commands.add("-Djava.naming.provider.url=iiop://localhost:1050"); + commands.add("-cp"); + commands.add(ConcurrentHashMapTest.CLASSPATH); + commands.add("HelloServer"); + + System.out.println("ConcurrentHashMapTest: Executing: " + commands); + ProcessBuilder pb = new ProcessBuilder(commands); + pb.redirectError(ProcessBuilder.Redirect.INHERIT); + rmiServerProcess = pb.start(); + } + + static boolean isResponseReceived() { + return HelloClient.isResponseReceived(); + } + + static void stopRmiIiopServer() throws Exception { + rmiServerProcess.destroy(); + rmiServerProcess.waitFor(); + //rmiServerProcess.waitFor(30, TimeUnit.SECONDS); + System.out.println("serverProcess exitCode:" + + rmiServerProcess.exitValue()); + } + + static void stopOrbd() throws Exception { + orbdProcess.destroy(); + orbdProcess.waitFor(); + //orbdProcess.waitFor(30, TimeUnit.SECONDS); + System.out.println("orbd exitCode:" + + orbdProcess.exitValue()); + } + + static void executeRmiIiopClient() throws Exception { + try { + HelloClient.executeRmiClientCall(); + } catch (Exception ex) { + clientException = ex; + exceptionInClient = true; + } + } +} diff --git a/jdk/test/javax/rmi/PortableRemoteObject/HelloClient.java b/jdk/test/javax/rmi/PortableRemoteObject/HelloClient.java new file mode 100644 index 00000000000..d3baa64e56b --- /dev/null +++ b/jdk/test/javax/rmi/PortableRemoteObject/HelloClient.java @@ -0,0 +1,98 @@ +import java.rmi.RemoteException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.rmi.NotBoundException; +import java.util.HashMap; +import java.util.Vector; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; + +import javax.naming.NamingException; +import javax.naming.InitialContext; +import javax.naming.Context; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; +import javax.rmi.PortableRemoteObject; + +import org.omg.CORBA.Any; +import org.omg.CORBA.ORB; + +public class HelloClient implements Runnable { + static final int MAX_RETRY = 10; + static final int ONE_SECOND = 1000; + private static boolean responseReceived; + + public static void main(String args[]) throws Exception { + executeRmiClientCall(); + } + + @Override + public void run() { + try { + executeRmiClientCall(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + + public static boolean isResponseReceived () { + return responseReceived; + } + + public static void executeRmiClientCall() throws Exception { + Context ic; + Object objref; + HelloInterface helloSvc; + String response; + int retryCount = 0; + + Test test = new Test(); + System.out.println("HelloClient.main: enter ..."); + while (retryCount < MAX_RETRY) { + try { + ic = new InitialContext(); + System.out.println("HelloClient.main: HelloService lookup ..."); + // STEP 1: Get the Object reference from the Name Service + // using JNDI call. + objref = ic.lookup("HelloService"); + System.out.println("HelloClient: Obtained a ref. to Hello server."); + + // STEP 2: Narrow the object reference to the concrete type and + // invoke the method. + helloSvc = (HelloInterface) PortableRemoteObject.narrow(objref, + HelloInterface.class); + System.out.println("HelloClient: Invoking on remote server with ConcurrentHashMap parameter"); + ConcurrentHashMap testConcurrentHashMap = new ConcurrentHashMap(); + response = helloSvc.sayHelloWithHashMap(testConcurrentHashMap); + System.out.println("HelloClient: Server says: " + response); + if (!response.contains("Hello with hashMapSize ==")) { + System.out.println("HelloClient: expected response not received"); + throw new RuntimeException("Expected Response Hello with hashMapSize == 0 not received"); + } + responseReceived = true; + break; + } catch (NameNotFoundException nnfEx) { + System.err.println("NameNotFoundException Caught .... try again"); + retryCount++; + try { + Thread.sleep(ONE_SECOND); + } catch (InterruptedException e) { + e.printStackTrace(); + } + continue; + } catch (Exception e) { + System.err.println("Exception " + e + "Caught"); + e.printStackTrace(); + throw new RuntimeException(e); + } + } + System.err.println("HelloClient terminating "); + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/jdk/test/javax/rmi/PortableRemoteObject/HelloImpl.java b/jdk/test/javax/rmi/PortableRemoteObject/HelloImpl.java new file mode 100644 index 00000000000..e6b24948852 --- /dev/null +++ b/jdk/test/javax/rmi/PortableRemoteObject/HelloImpl.java @@ -0,0 +1,60 @@ +import java.net.InetAddress; +import java.rmi.RemoteException; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; + +import javax.rmi.PortableRemoteObject; + +public class HelloImpl extends PortableRemoteObject implements HelloInterface { + public HelloImpl() throws java.rmi.RemoteException { + super(); // invoke rmi linking and remote object initialization + } + + public String sayHello(String from) throws java.rmi.RemoteException { + System.out.println("Hello from " + from + "!!"); + System.out.flush(); + String reply = "Hello from us to you " + from; + return reply; + } + + @Override + public String sayHelloToTest(Test test) throws RemoteException { + return "Test says Hello"; + } + + @Override + public String sayHelloWithInetAddress(InetAddress ipAddr) + throws RemoteException { + String response = "Hello with InetAddress " + ipAddr.toString(); + return response; + } + + @Override + public String sayHelloWithHashMap(ConcurrentHashMap receivedHashMap) + throws RemoteException { + int hashMapSize = 0; + + hashMapSize = receivedHashMap.size(); + String response = "Hello with hashMapSize == " + hashMapSize; + return response; + } + + @Override + public String sayHelloWithHashMap2(HashMap receivedHashMap) + throws RemoteException { + int hashMapSize = 0; + + hashMapSize = receivedHashMap.size(); + String response = "Hello with hashMapSize == " + hashMapSize; + return response; + } + + @Override + public String sayHelloWithReentrantLock(ReentrantLock receivedLock) + throws RemoteException { + + String response = "Hello with lock == " + receivedLock.isLocked(); + return response; + } +} diff --git a/jdk/test/javax/rmi/PortableRemoteObject/HelloInterface.java b/jdk/test/javax/rmi/PortableRemoteObject/HelloInterface.java new file mode 100644 index 00000000000..0c1a1635b0f --- /dev/null +++ b/jdk/test/javax/rmi/PortableRemoteObject/HelloInterface.java @@ -0,0 +1,14 @@ +import java.net.InetAddress; +import java.rmi.Remote; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; + +public interface HelloInterface extends Remote { + public String sayHello( String from ) throws java.rmi.RemoteException; + public String sayHelloToTest( Test test ) throws java.rmi.RemoteException; + public String sayHelloWithInetAddress( InetAddress ipAddr ) throws java.rmi.RemoteException; + public String sayHelloWithHashMap(ConcurrentHashMap hashMap ) throws java.rmi.RemoteException; + public String sayHelloWithHashMap2(HashMap hashMap ) throws java.rmi.RemoteException; + public String sayHelloWithReentrantLock(ReentrantLock lock ) throws java.rmi.RemoteException; +} diff --git a/jdk/test/javax/rmi/PortableRemoteObject/HelloServer.java b/jdk/test/javax/rmi/PortableRemoteObject/HelloServer.java new file mode 100644 index 00000000000..f3ec3991531 --- /dev/null +++ b/jdk/test/javax/rmi/PortableRemoteObject/HelloServer.java @@ -0,0 +1,36 @@ +import javax.naming.InitialContext; +import javax.naming.Context; + +public class HelloServer { + + static final int MAX_RETRY = 10; + static final int ONE_SECOND = 1000; + + public static void main(String[] args) { + int retryCount = 0; + while (retryCount < MAX_RETRY) { + try { + //HelloServer.set("SETTING TEST ITL"); + // Step 1: Instantiate the Hello servant + HelloImpl helloRef = new HelloImpl(); + + // Step 2: Publish the reference in the Naming Service + // using JNDI API + Context initialNamingContext = new InitialContext(); + initialNamingContext.rebind("HelloService", helloRef); + + System.out.println("Hello Server: Ready..."); + break; + } catch (Exception e) { + System.out.println("Server initialization problem: " + e); + e.printStackTrace(); + retryCount++; + try { + Thread.sleep(ONE_SECOND); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } + } + } +} diff --git a/jdk/test/javax/rmi/PortableRemoteObject/Test.java b/jdk/test/javax/rmi/PortableRemoteObject/Test.java new file mode 100644 index 00000000000..1fc3ecf939f --- /dev/null +++ b/jdk/test/javax/rmi/PortableRemoteObject/Test.java @@ -0,0 +1,6 @@ +import java.io.Serializable; + + +public class Test implements Serializable { + +} diff --git a/jdk/test/javax/rmi/PortableRemoteObject/_HelloImpl_Tie.java b/jdk/test/javax/rmi/PortableRemoteObject/_HelloImpl_Tie.java new file mode 100644 index 00000000000..040500d8aeb --- /dev/null +++ b/jdk/test/javax/rmi/PortableRemoteObject/_HelloImpl_Tie.java @@ -0,0 +1,128 @@ +// Tie class generated by rmic, do not edit. +// Contents subject to change without notice. + +import java.io.Serializable; +import java.net.InetAddress; +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; +import javax.rmi.CORBA.Tie; +import javax.rmi.CORBA.Util; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; +import org.omg.CORBA.portable.UnknownException; +import org.omg.CORBA_2_3.portable.ObjectImpl; + + +public class _HelloImpl_Tie extends ObjectImpl implements Tie { + + private HelloImpl target = null; + + private static final String[] _type_ids = { + "RMI:HelloInterface:0000000000000000" + }; + + public void setTarget(Remote target) { + this.target = (HelloImpl) target; + } + + public Remote getTarget() { + return target; + } + + public org.omg.CORBA.Object thisObject() { + return this; + } + + public void deactivate() { + _orb().disconnect(this); + _set_delegate(null); + target = null; + } + + public ORB orb() { + return _orb(); + } + + public void orb(ORB orb) { + orb.connect(this); + } + + public String[] _ids() { + return (String[]) _type_ids.clone(); + } + + public OutputStream _invoke(String method, InputStream _in, ResponseHandler reply) throws SystemException { + try { + org.omg.CORBA_2_3.portable.InputStream in = + (org.omg.CORBA_2_3.portable.InputStream) _in; + switch (method.length()) { + case 8: + if (method.equals("sayHello")) { + String arg0 = (String) in.read_value(String.class); + String result = target.sayHello(arg0); + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply(); + out.write_value(result,String.class); + return out; + } + case 14: + if (method.equals("sayHelloToTest")) { + Test arg0 = (Test) in.read_value(Test.class); + String result = target.sayHelloToTest(arg0); + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply(); + out.write_value(result,String.class); + return out; + } + case 19: + if (method.equals("sayHelloWithHashMap")) { + ConcurrentHashMap arg0 = (ConcurrentHashMap) in.read_value(ConcurrentHashMap.class); + String result = target.sayHelloWithHashMap(arg0); + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply(); + out.write_value(result,String.class); + return out; + } + case 20: + if (method.equals("sayHelloWithHashMap2")) { + HashMap arg0 = (HashMap) in.read_value(HashMap.class); + String result = target.sayHelloWithHashMap2(arg0); + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply(); + out.write_value(result,String.class); + return out; + } + case 23: + if (method.equals("sayHelloWithInetAddress")) { + InetAddress arg0 = (InetAddress) in.read_value(InetAddress.class); + String result = target.sayHelloWithInetAddress(arg0); + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply(); + out.write_value(result,String.class); + return out; + } + case 25: + if (method.equals("sayHelloWithReentrantLock")) { + ReentrantLock arg0 = (ReentrantLock) in.read_value(ReentrantLock.class); + String result = target.sayHelloWithReentrantLock(arg0); + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply(); + out.write_value(result,String.class); + return out; + } + } + throw new BAD_OPERATION(); + } catch (SystemException ex) { + throw ex; + } catch (Throwable ex) { + throw new UnknownException(ex); + } + } +} diff --git a/jdk/test/javax/rmi/PortableRemoteObject/_HelloInterface_Stub.java b/jdk/test/javax/rmi/PortableRemoteObject/_HelloInterface_Stub.java new file mode 100644 index 00000000000..4098143151f --- /dev/null +++ b/jdk/test/javax/rmi/PortableRemoteObject/_HelloInterface_Stub.java @@ -0,0 +1,272 @@ +// Stub class generated by rmic, do not edit. +// Contents subject to change without notice. + +import java.io.Serializable; +import java.net.InetAddress; +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.UnexpectedException; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; +import javax.rmi.CORBA.Stub; +import javax.rmi.CORBA.Util; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.RemarshalException; +import org.omg.CORBA.portable.ResponseHandler; +import org.omg.CORBA.portable.ServantObject; + + +public class _HelloInterface_Stub extends Stub implements HelloInterface { + + private static final String[] _type_ids = { + "RMI:HelloInterface:0000000000000000" + }; + + public String[] _ids() { + return (String[]) _type_ids.clone(); + } + + public String sayHello(String arg0) throws java.rmi.RemoteException { + if (!Util.isLocal(this)) { + try { + org.omg.CORBA_2_3.portable.InputStream in = null; + try { + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) + _request("sayHello", true); + out.write_value(arg0,String.class); + in = (org.omg.CORBA_2_3.portable.InputStream)_invoke(out); + return (String) in.read_value(String.class); + } catch (ApplicationException ex) { + in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream(); + String $_id = in.read_string(); + throw new UnexpectedException($_id); + } catch (RemarshalException ex) { + return sayHello(arg0); + } finally { + _releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } else { + ServantObject so = _servant_preinvoke("sayHello",HelloInterface.class); + if (so == null) { + return sayHello(arg0); + } + try { + return ((HelloInterface)so.servant).sayHello(arg0); + } catch (Throwable ex) { + Throwable exCopy = (Throwable)Util.copyObject(ex,_orb()); + throw Util.wrapException(exCopy); + } finally { + _servant_postinvoke(so); + } + } + } + + public String sayHelloToTest(Test arg0) throws java.rmi.RemoteException { + if (!Util.isLocal(this)) { + try { + org.omg.CORBA_2_3.portable.InputStream in = null; + try { + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) + _request("sayHelloToTest", true); + out.write_value(arg0,Test.class); + in = (org.omg.CORBA_2_3.portable.InputStream)_invoke(out); + return (String) in.read_value(String.class); + } catch (ApplicationException ex) { + in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream(); + String $_id = in.read_string(); + throw new UnexpectedException($_id); + } catch (RemarshalException ex) { + return sayHelloToTest(arg0); + } finally { + _releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } else { + ServantObject so = _servant_preinvoke("sayHelloToTest",HelloInterface.class); + if (so == null) { + return sayHelloToTest(arg0); + } + try { + Test arg0Copy = (Test) Util.copyObject(arg0,_orb()); + return ((HelloInterface)so.servant).sayHelloToTest(arg0Copy); + } catch (Throwable ex) { + Throwable exCopy = (Throwable)Util.copyObject(ex,_orb()); + throw Util.wrapException(exCopy); + } finally { + _servant_postinvoke(so); + } + } + } + + public String sayHelloWithInetAddress(InetAddress arg0) throws java.rmi.RemoteException { + if (!Util.isLocal(this)) { + try { + org.omg.CORBA_2_3.portable.InputStream in = null; + try { + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) + _request("sayHelloWithInetAddress", true); + out.write_value(arg0,InetAddress.class); + in = (org.omg.CORBA_2_3.portable.InputStream)_invoke(out); + return (String) in.read_value(String.class); + } catch (ApplicationException ex) { + in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream(); + String $_id = in.read_string(); + throw new UnexpectedException($_id); + } catch (RemarshalException ex) { + return sayHelloWithInetAddress(arg0); + } finally { + _releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } else { + ServantObject so = _servant_preinvoke("sayHelloWithInetAddress",HelloInterface.class); + if (so == null) { + return sayHelloWithInetAddress(arg0); + } + try { + InetAddress arg0Copy = (InetAddress) Util.copyObject(arg0,_orb()); + return ((HelloInterface)so.servant).sayHelloWithInetAddress(arg0Copy); + } catch (Throwable ex) { + Throwable exCopy = (Throwable)Util.copyObject(ex,_orb()); + throw Util.wrapException(exCopy); + } finally { + _servant_postinvoke(so); + } + } + } + + public String sayHelloWithHashMap(ConcurrentHashMap arg0) throws java.rmi.RemoteException { + if (!Util.isLocal(this)) { + try { + org.omg.CORBA_2_3.portable.InputStream in = null; + try { + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) + _request("sayHelloWithHashMap", true); + out.write_value(arg0,ConcurrentHashMap.class); + in = (org.omg.CORBA_2_3.portable.InputStream)_invoke(out); + return (String) in.read_value(String.class); + } catch (ApplicationException ex) { + in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream(); + String $_id = in.read_string(); + throw new UnexpectedException($_id); + } catch (RemarshalException ex) { + return sayHelloWithHashMap(arg0); + } finally { + _releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } else { + ServantObject so = _servant_preinvoke("sayHelloWithHashMap",HelloInterface.class); + if (so == null) { + return sayHelloWithHashMap(arg0); + } + try { + ConcurrentHashMap arg0Copy = (ConcurrentHashMap) Util.copyObject(arg0,_orb()); + return ((HelloInterface)so.servant).sayHelloWithHashMap(arg0Copy); + } catch (Throwable ex) { + Throwable exCopy = (Throwable)Util.copyObject(ex,_orb()); + throw Util.wrapException(exCopy); + } finally { + _servant_postinvoke(so); + } + } + } + + public String sayHelloWithHashMap2(HashMap arg0) throws java.rmi.RemoteException { + if (!Util.isLocal(this)) { + try { + org.omg.CORBA_2_3.portable.InputStream in = null; + try { + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) + _request("sayHelloWithHashMap2", true); + out.write_value(arg0,HashMap.class); + in = (org.omg.CORBA_2_3.portable.InputStream)_invoke(out); + return (String) in.read_value(String.class); + } catch (ApplicationException ex) { + in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream(); + String $_id = in.read_string(); + throw new UnexpectedException($_id); + } catch (RemarshalException ex) { + return sayHelloWithHashMap2(arg0); + } finally { + _releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } else { + ServantObject so = _servant_preinvoke("sayHelloWithHashMap2",HelloInterface.class); + if (so == null) { + return sayHelloWithHashMap2(arg0); + } + try { + HashMap arg0Copy = (HashMap) Util.copyObject(arg0,_orb()); + return ((HelloInterface)so.servant).sayHelloWithHashMap2(arg0Copy); + } catch (Throwable ex) { + Throwable exCopy = (Throwable)Util.copyObject(ex,_orb()); + throw Util.wrapException(exCopy); + } finally { + _servant_postinvoke(so); + } + } + } + + public String sayHelloWithReentrantLock(ReentrantLock arg0) throws java.rmi.RemoteException { + if (!Util.isLocal(this)) { + try { + org.omg.CORBA_2_3.portable.InputStream in = null; + try { + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) + _request("sayHelloWithReentrantLock", true); + out.write_value(arg0,ReentrantLock.class); + in = (org.omg.CORBA_2_3.portable.InputStream)_invoke(out); + return (String) in.read_value(String.class); + } catch (ApplicationException ex) { + in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream(); + String $_id = in.read_string(); + throw new UnexpectedException($_id); + } catch (RemarshalException ex) { + return sayHelloWithReentrantLock(arg0); + } finally { + _releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } else { + ServantObject so = _servant_preinvoke("sayHelloWithReentrantLock",HelloInterface.class); + if (so == null) { + return sayHelloWithReentrantLock(arg0); + } + try { + ReentrantLock arg0Copy = (ReentrantLock) Util.copyObject(arg0,_orb()); + return ((HelloInterface)so.servant).sayHelloWithReentrantLock(arg0Copy); + } catch (Throwable ex) { + Throwable exCopy = (Throwable)Util.copyObject(ex,_orb()); + throw Util.wrapException(exCopy); + } finally { + _servant_postinvoke(so); + } + } + } +} From a0fedc85567914795fcc30b17073b92fb2b546fd Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Mon, 13 Apr 2015 11:15:41 -0700 Subject: [PATCH 242/362] 8077640: DateTimeFormatter does not parse/accept the era.toString() result from MinguoEra/ThaiBuddhistEra To parse and accept the era.toString() for era parsing in lenient/smart mode Reviewed-by: rriggs --- .../time/format/DateTimeFormatterBuilder.java | 12 +++++ .../test/java/time/format/TestTextParser.java | 50 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/jdk/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java b/jdk/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java index a8f70915012..90c6108c244 100644 --- a/jdk/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java +++ b/jdk/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java @@ -70,6 +70,7 @@ import static java.time.temporal.ChronoField.NANO_OF_SECOND; import static java.time.temporal.ChronoField.OFFSET_SECONDS; import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoField.ERA; import java.lang.ref.SoftReference; import java.math.BigDecimal; @@ -84,6 +85,7 @@ import java.time.ZoneId; import java.time.ZoneOffset; import java.time.chrono.ChronoLocalDate; import java.time.chrono.Chronology; +import java.time.chrono.Era; import java.time.chrono.IsoChronology; import java.time.format.DateTimeTextProvider.LocaleStore; import java.time.temporal.ChronoField; @@ -3131,6 +3133,16 @@ public final class DateTimeFormatterBuilder { return context.setParsedField(field, entry.getValue(), position, position + itText.length()); } } + if (field == ERA && !context.isStrict()) { + // parse the possible era name from era.toString() + List eras = chrono.eras(); + for (Era era : eras) { + String name = era.toString(); + if (context.subSequenceEquals(name, 0, parseText, position, name.length())) { + return context.setParsedField(field, era.getValue(), position, position + name.length()); + } + } + } if (context.isStrict()) { return ~position; } diff --git a/jdk/test/java/time/test/java/time/format/TestTextParser.java b/jdk/test/java/time/test/java/time/format/TestTextParser.java index 07bd2146212..a1b264a756b 100644 --- a/jdk/test/java/time/test/java/time/format/TestTextParser.java +++ b/jdk/test/java/time/test/java/time/format/TestTextParser.java @@ -68,10 +68,20 @@ import static org.testng.Assert.assertTrue; import java.text.ParsePosition; import java.time.DayOfWeek; +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.JapaneseChronology; +import java.time.chrono.HijrahDate; +import java.time.chrono.JapaneseDate; +import java.time.chrono.MinguoDate; +import java.time.chrono.ThaiBuddhistDate; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.time.format.TextStyle; +import java.time.format.SignStyle; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; +import java.time.temporal.ChronoField; import java.util.Locale; import org.testng.annotations.DataProvider; @@ -243,6 +253,8 @@ public class TestTextParser extends AbstractTestPrinterParser { }; } + + @Test(dataProvider="parseText") public void test_parseText(TemporalField field, TextStyle style, int value, String input) throws Exception { ParsePosition pos = new ParsePosition(0); @@ -433,4 +445,42 @@ public class TestTextParser extends AbstractTestPrinterParser { assertEquals(pos.getIndex(), input.length()); } + //----------------------------------------------------------------------- + @DataProvider(name="parseChronoLocalDate") + Object[][] provider_chronoLocalDate() { + return new Object[][] { + { HijrahDate.now() }, + { JapaneseDate.now() }, + { MinguoDate.now() }, + { ThaiBuddhistDate.now() }}; + } + + private static final DateTimeFormatter fmt_chrono = + new DateTimeFormatterBuilder() + .optionalStart() + .appendChronologyId() + .appendLiteral(' ') + .optionalEnd() + .optionalStart() + .appendText(ChronoField.ERA, TextStyle.SHORT) + .appendLiteral(' ') + .optionalEnd() + .appendValue(ChronoField.YEAR_OF_ERA, 1, 9, SignStyle.NORMAL) + .appendLiteral('-') + .appendValue(ChronoField.MONTH_OF_YEAR, 1, 2, SignStyle.NEVER) + .appendLiteral('-') + .appendValue(ChronoField.DAY_OF_MONTH, 1, 2, SignStyle.NEVER) + .toFormatter(); + + @Test(dataProvider="parseChronoLocalDate") + public void test_chronoLocalDate(ChronoLocalDate date) throws Exception { + System.out.printf(" %s, [fmt=%s]%n", date, fmt_chrono.format(date)); + assertEquals(date, fmt_chrono.parse(fmt_chrono.format(date), ChronoLocalDate::from)); + + DateTimeFormatter fmt = DateTimeFormatter.ofPattern("[GGG ]yyy-MM-dd") + .withChronology(date.getChronology()); + System.out.printf(" %s, [fmt=%s]%n", date.toString(), fmt.format(date)); + assertEquals(date, fmt.parse(fmt.format(date), ChronoLocalDate::from)); + } + } From 9c427df72e813821fe09a8d64e09e7efa5f70758 Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Mon, 13 Apr 2015 18:05:23 -0700 Subject: [PATCH 243/362] 8072945: Javadoc should generate valid and compliant HTML5 output Reviewed-by: jjg, ksrini --- .../com/sun/tools/doclint/Checker.java | 92 +- .../com/sun/tools/doclint/DocLint.java | 19 +- .../classes/com/sun/tools/doclint/Env.java | 8 +- .../com/sun/tools/doclint/HtmlTag.java | 248 +- .../com/sun/tools/doclint/HtmlVersion.java | 49 + .../doclint/resources/doclint.properties | 5 + .../formats/html/AbstractMemberWriter.java | 14 +- .../html/AbstractPackageIndexWriter.java | 16 +- .../html/AbstractProfileIndexWriter.java | 32 +- .../formats/html/AbstractTreeWriter.java | 24 +- .../formats/html/AllClassesFrameWriter.java | 8 +- .../html/AnnotationTypeFieldWriterImpl.java | 13 +- ...nnotationTypeOptionalMemberWriterImpl.java | 9 +- ...nnotationTypeRequiredMemberWriterImpl.java | 13 +- .../html/AnnotationTypeWriterImpl.java | 30 +- .../doclets/formats/html/ClassUseWriter.java | 78 +- .../doclets/formats/html/ClassWriterImpl.java | 31 +- .../formats/html/ConfigurationImpl.java | 32 +- .../html/ConstantsSummaryWriterImpl.java | 96 +- .../formats/html/ConstructorWriterImpl.java | 13 +- .../formats/html/DeprecatedListWriter.java | 40 +- .../formats/html/EnumConstantWriterImpl.java | 13 +- .../doclets/formats/html/FieldWriterImpl.java | 13 +- .../formats/html/FrameOutputWriter.java | 7 +- .../doclets/formats/html/HelpWriter.java | 224 +- .../formats/html/HtmlDocletWriter.java | 68 +- .../formats/html/HtmlSerialMethodWriter.java | 4 +- .../formats/html/MethodWriterImpl.java | 13 +- .../formats/html/NestedClassWriterImpl.java | 9 +- .../formats/html/PackageFrameWriter.java | 28 +- .../formats/html/PackageIndexFrameWriter.java | 26 +- .../formats/html/PackageIndexWriter.java | 59 +- .../formats/html/PackageTreeWriter.java | 38 +- .../formats/html/PackageUseWriter.java | 62 +- .../formats/html/PackageWriterImpl.java | 74 +- .../formats/html/ProfileIndexFrameWriter.java | 26 +- .../html/ProfilePackageFrameWriter.java | 28 +- .../html/ProfilePackageIndexFrameWriter.java | 34 +- .../html/ProfilePackageWriterImpl.java | 69 +- .../formats/html/ProfileWriterImpl.java | 72 +- .../formats/html/PropertyWriterImpl.java | 13 +- .../html/SerializedFormWriterImpl.java | 66 +- .../formats/html/SingleIndexWriter.java | 28 +- .../formats/html/SourceToHTMLConverter.java | 12 +- .../formats/html/SplitIndexWriter.java | 26 +- .../formats/html/SubWriterHolderWriter.java | 52 +- .../doclets/formats/html/TreeWriter.java | 40 +- .../doclets/formats/html/markup/DocType.java | 10 + .../doclets/formats/html/markup/HtmlAttr.java | 25 +- .../formats/html/markup/HtmlDocWriter.java | 6 +- .../formats/html/markup/HtmlStyle.java | 3 +- .../doclets/formats/html/markup/HtmlTag.java | 36 +- .../doclets/formats/html/markup/HtmlTree.java | 185 +- .../formats/html/markup/HtmlVersion.java | 37 + .../formats/html/markup/HtmlWriter.java | 6 +- .../html/resources/standard.properties | 2 + .../toolkit/AnnotationTypeWriter.java | 10 +- .../doclets/internal/toolkit/ClassWriter.java | 10 +- .../toolkit/ConstantsSummaryWriter.java | 31 +- .../internal/toolkit/MemberSummaryWriter.java | 14 +- .../toolkit/PackageSummaryWriter.java | 11 +- .../toolkit/ProfilePackageSummaryWriter.java | 11 +- .../toolkit/ProfileSummaryWriter.java | 10 +- .../toolkit/SerializedFormWriter.java | 10 +- .../builders/AnnotationTypeBuilder.java | 4 +- .../toolkit/builders/ClassBuilder.java | 4 +- .../builders/ConstantsSummaryBuilder.java | 17 +- .../builders/MemberSummaryBuilder.java | 4 +- .../builders/PackageSummaryBuilder.java | 4 +- .../ProfilePackageSummaryBuilder.java | 4 +- .../builders/ProfileSummaryBuilder.java | 4 +- .../builders/SerializedFormBuilder.java | 4 +- .../internal/toolkit/resources/stylesheet.css | 24 +- .../classes/com/sun/tools/javadoc/DocEnv.java | 5 +- .../com/sun/tools/javadoc/RootDocImpl.java | 5 +- .../javadoc/AccessSkipNav/AccessSkipNav.java | 10 +- .../testAnchorNames/TestAnchorNames.java | 54 +- .../TestAnnotationOptional.java | 4 +- .../javadoc/testClassTree/TestClassTree.java | 14 +- .../testConstructors/TestConstructors.java | 14 +- .../com/sun/javadoc/testHref/TestHref.java | 6 +- .../testHtmlDocument/TestHtmlDocument.java | 4 +- .../javadoc/testHtmlDocument/testMarkup.html | 2 +- .../TestHtmlTableStyles.java | 27 +- .../testHtmlTableTags/TestHtmlTableTags.java | 82 +- .../testHtmlVersion/TestHtmlVersion.java | 2158 +++++++++++++++++ .../testHtmlVersion/pkg/AnnotationType.java | 36 + .../testHtmlVersion/pkg/AnotherClass.java | 78 + .../testHtmlVersion/pkg/TestError.java | 38 + .../testHtmlVersion/pkg/TestException.java | 38 + .../testHtmlVersion/pkg/TestInterface.java | 33 + .../testHtmlVersion/pkg/package-info.java | 27 + .../pkg1/NestedInnerClass.java | 62 + .../pkg1/PrivateIncludeInnerClass.java | 62 + .../pkg1/ProtectedInnerClass.java | 59 + .../pkg1/PublicExcludeInnerClass.java | 62 + .../testHtmlVersion/pkg1/RegClass.java | 42 + .../pkg2/DeprecatedClassByAnnotation.java | 37 + .../testHtmlVersion/pkg2/Interface.java | 33 + .../pkg2/TestAnnotationType.java | 42 + .../testHtmlVersion/pkg2/TestClass.java | 50 + .../testHtmlVersion/pkg2/TestEnum.java | 35 + .../testHtmlVersion/pkg2/TestError.java | 45 + .../testHtmlVersion/pkg2/TestException.java | 45 + .../testHtmlVersion/pkg2/TestInterface.java | 45 + .../pkg3/ClassNoConstants.java | 31 + .../profile-rtjar-includes.txt | 30 + .../sun/javadoc/testJavaFX/TestJavaFX.java | 10 +- .../TestLinkToSerialForm.java | 4 +- .../testMemberSummary/TestMemberSummary.java | 6 +- .../testNavigation/TestNavigation.java | 4 +- .../javadoc/testProfiles/TestProfiles.java | 33 +- .../testTypeParams/TestTypeParameters.java | 4 +- .../javadoc/testUseOption/TestUseOption.java | 4 +- .../test/tools/doclint/DocLintTester.java | 13 +- .../test/tools/doclint/HtmlVersionTest.java | 40 + .../html/HtmlVersionTagsAttrsTest.java | 210 ++ .../html/HtmlVersionTagsAttrsTestHtml4.out | 212 ++ .../html/HtmlVersionTagsAttrsTestHtml5.out | 299 +++ 119 files changed, 5913 insertions(+), 701 deletions(-) create mode 100644 langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/HtmlVersion.java create mode 100644 langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlVersion.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/TestHtmlVersion.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg/AnnotationType.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg/AnotherClass.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg/TestError.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg/TestException.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg/TestInterface.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg/package-info.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg1/NestedInnerClass.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg1/PrivateIncludeInnerClass.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg1/ProtectedInnerClass.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg1/PublicExcludeInnerClass.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg1/RegClass.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg2/DeprecatedClassByAnnotation.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg2/Interface.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg2/TestAnnotationType.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg2/TestClass.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg2/TestEnum.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg2/TestError.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg2/TestException.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg2/TestInterface.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/pkg3/ClassNoConstants.java create mode 100644 langtools/test/com/sun/javadoc/testHtmlVersion/profile-rtjar-includes.txt create mode 100644 langtools/test/tools/doclint/HtmlVersionTest.java create mode 100644 langtools/test/tools/doclint/html/HtmlVersionTagsAttrsTest.java create mode 100644 langtools/test/tools/doclint/html/HtmlVersionTagsAttrsTestHtml4.out create mode 100644 langtools/test/tools/doclint/html/HtmlVersionTagsAttrsTestHtml5.out diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java index c1627f23f6a..03a62b2019d 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -108,6 +108,7 @@ public class Checker extends DocTreePathScanner { public enum Flag { TABLE_HAS_CAPTION, HAS_ELEMENT, + HAS_HEADING, HAS_INLINE_TAG, HAS_TEXT, REPORTED_BAD_INLINE @@ -282,6 +283,8 @@ public class Checker extends DocTreePathScanner { final HtmlTag t = HtmlTag.get(treeName); if (t == null) { env.messages.error(HTML, tree, "dc.tag.unknown", treeName); + } else if (t.allowedVersion != HtmlVersion.ALL && t.allowedVersion != env.htmlVersion) { + env.messages.error(HTML, tree, "dc.tag.not.supported", treeName); } else { boolean done = false; for (TagStackItem tsi: tagStack) { @@ -345,6 +348,12 @@ public class Checker extends DocTreePathScanner { parent.flags.add(Flag.TABLE_HAS_CAPTION); break; + case H1: case H2: case H3: case H4: case H5: case H6: + if (parent != null && (parent.tag == HtmlTag.SECTION || parent.tag == HtmlTag.ARTICLE)) { + parent.flags.add(Flag.HAS_HEADING); + } + break; + case IMG: if (!top.attrs.contains(HtmlTag.Attr.ALT)) env.messages.error(ACCESSIBILITY, tree, "dc.no.alt.attr.for.image"); @@ -460,6 +469,14 @@ public class Checker extends DocTreePathScanner { env.messages.error(ACCESSIBILITY, tree, "dc.no.summary.or.caption.for.table"); } + break; + + case SECTION: + case ARTICLE: + if (env.htmlVersion == HtmlVersion.HTML5 && !top.flags.contains(Flag.HAS_HEADING)) { + env.messages.error(HTML, tree, "dc.tag.requires.heading", treeName); + } + break; } warnIfEmpty(top, tree); tagStack.pop(); @@ -519,25 +536,21 @@ public class Checker extends DocTreePathScanner { Name name = tree.getName(); HtmlTag.Attr attr = currTag.getAttr(name); if (attr != null) { + if (env.htmlVersion == HtmlVersion.HTML4 && attr.name().contains("-")) { + env.messages.error(HTML, tree, "dc.attr.not.supported.html4", name); + } boolean first = tagStack.peek().attrs.add(attr); if (!first) env.messages.error(HTML, tree, "dc.attr.repeated", name); } AttrKind k = currTag.getAttrKind(name); - switch (k) { - case OK: + switch (env.htmlVersion) { + case HTML4: + validateHtml4Attrs(tree, name, k); break; - case INVALID: - env.messages.error(HTML, tree, "dc.attr.unknown", name); - break; - - case OBSOLETE: - env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete", name); - break; - - case USE_CSS: - env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete.use.css", name); + case HTML5: + validateHtml5Attrs(tree, name, k); break; } @@ -590,6 +603,20 @@ public class Checker extends DocTreePathScanner { } } break; + + case BORDER: + if (currTag == HtmlTag.TABLE) { + String v = getAttrValue(tree); + try { + if (env.htmlVersion == HtmlVersion.HTML5 + && (v == null || (!v.isEmpty() && Integer.parseInt(v) != 1))) { + env.messages.error(HTML, tree, "dc.attr.table.border.html5", attr); + } + } catch (NumberFormatException ex) { + env.messages.error(HTML, tree, "dc.attr.table.border.html5", attr); + } + } + break; } } } @@ -599,6 +626,45 @@ public class Checker extends DocTreePathScanner { return super.visitAttribute(tree, ignore); } + private void validateHtml4Attrs(AttributeTree tree, Name name, AttrKind k) { + switch (k) { + case ALL: + case HTML4: + break; + + case INVALID: + env.messages.error(HTML, tree, "dc.attr.unknown", name); + break; + + case OBSOLETE: + env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete", name); + break; + + case USE_CSS: + env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete.use.css", name); + break; + + case HTML5: + env.messages.error(HTML, tree, "dc.attr.not.supported.html4", name); + break; + } + } + + private void validateHtml5Attrs(AttributeTree tree, Name name, AttrKind k) { + switch (k) { + case ALL: + case HTML5: + break; + + case INVALID: + case OBSOLETE: + case USE_CSS: + case HTML4: + env.messages.error(HTML, tree, "dc.attr.not.supported.html5", name); + break; + } + } + private boolean checkAnchor(String name) { Element e = getEnclosingPackageOrClass(env.currElement); if (e == null) diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/DocLint.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/DocLint.java index e6ee1e4513b..580e3eb9e66 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/DocLint.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/DocLint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -80,6 +80,7 @@ public class DocLint implements Plugin { private static final String STATS = "-stats"; public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:"; public static final String XCUSTOM_TAGS_PREFIX = "-XcustomTags:"; + public static final String XHTML_VERSION_PREFIX = "-XhtmlVersion:"; public static final String XCHECK_PACKAGE = "-XcheckPackage:"; public static final String SEPARATOR = ","; @@ -210,6 +211,14 @@ public class DocLint implements Plugin { env.messages.setOptions(arg.substring(arg.indexOf(":") + 1)); } else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) { env.setCustomTags(arg.substring(arg.indexOf(":") + 1)); + } else if (arg.startsWith(XHTML_VERSION_PREFIX)) { + String argsVersion = arg.substring(arg.indexOf(":") + 1); + HtmlVersion htmlVersion = HtmlVersion.getHtmlVersion(argsVersion); + if (htmlVersion != null) { + env.setHtmlVersion(htmlVersion); + } else { + throw new BadArgs("dc.bad.value.for.option", arg, argsVersion); + } } else if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help") || arg.equals("-?") || arg.equals("-usage")) { needHelp = true; @@ -274,6 +283,14 @@ public class DocLint implements Plugin { env.setImplicitHeaders(Character.digit(ch, 10)); } else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) { env.setCustomTags(arg.substring(arg.indexOf(":") + 1)); + } else if (arg.startsWith(XHTML_VERSION_PREFIX)) { + String argsVersion = arg.substring(arg.indexOf(":") + 1); + HtmlVersion htmlVersion = HtmlVersion.getHtmlVersion(argsVersion); + if (htmlVersion != null) { + env.setHtmlVersion(htmlVersion); + } else { + throw new IllegalArgumentException(argsVersion); + } } else if (arg.startsWith(XCHECK_PACKAGE)) { env.setCheckPackages(arg.substring(arg.indexOf(":") + 1)); } else diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Env.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Env.java index 448e4d79c19..f7aaa5a4f01 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Env.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Env.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -99,6 +99,8 @@ public class Env { Set includePackages; Set excludePackages; + HtmlVersion htmlVersion = HtmlVersion.HTML4; + // Utility classes DocTrees trees; Elements elements; @@ -193,6 +195,10 @@ public class Env { return true; } + void setHtmlVersion(HtmlVersion version) { + htmlVersion = version; + } + /** Set the current declaration and its doc comment. */ void setCurrent(TreePath path, DocCommentTree comment) { currPath = path; diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/HtmlTag.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/HtmlTag.java index ac33290e83c..6f42b903526 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/HtmlTag.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/HtmlTag.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -51,26 +51,37 @@ import com.sun.tools.javac.util.StringUtils; * * @see HTML 4.01 Specification * @see HTML 5 Specification + * @see WAI-ARIA Specification + * @see WAI-ARIA Recommendations Table * @author Bhavesh Patel * @author Jonathan Gibbons (revised) */ public enum HtmlTag { A(BlockType.INLINE, EndKind.REQUIRED, - attrs(AttrKind.OK, HREF, TARGET, NAME)), + attrs(AttrKind.ALL, HREF, TARGET, ID), + attrs(AttrKind.HTML4, REV, CHARSET, SHAPE, COORDS, NAME)), ABBR(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), - ACRONYM(BlockType.INLINE, EndKind.REQUIRED, + ACRONYM(HtmlVersion.HTML4, BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), ADDRESS(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), + ARTICLE(HtmlVersion.HTML5, BlockType.BLOCK, EndKind.REQUIRED, + EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), + + ASIDE(HtmlVersion.HTML5, BlockType.BLOCK, EndKind.REQUIRED, + EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), + B(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), - BIG(BlockType.INLINE, EndKind.REQUIRED, + BDI(HtmlVersion.HTML5, BlockType.INLINE, EndKind.REQUIRED), + + BIG(HtmlVersion.HTML4, BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT)), BLOCKQUOTE(BlockType.BLOCK, EndKind.REQUIRED, @@ -82,9 +93,10 @@ public enum HtmlTag { attrs(AttrKind.USE_CSS, CLEAR)), CAPTION(BlockType.TABLE_ITEM, EndKind.REQUIRED, - EnumSet.of(Flag.ACCEPTS_INLINE, Flag.EXPECT_CONTENT)), + EnumSet.of(Flag.ACCEPTS_INLINE, Flag.EXPECT_CONTENT), + attrs(AttrKind.USE_CSS, ALIGN)), - CENTER(BlockType.BLOCK, EndKind.REQUIRED, + CENTER(HtmlVersion.HTML4, BlockType.BLOCK, EndKind.REQUIRED, EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), CITE(BlockType.INLINE, EndKind.REQUIRED, @@ -93,18 +105,30 @@ public enum HtmlTag { CODE(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), + COL(BlockType.TABLE_ITEM, EndKind.NONE, + attrs(AttrKind.HTML4, ALIGN, CHAR, CHAROFF, VALIGN, WIDTH)), + + COLGROUP(BlockType.TABLE_ITEM, EndKind.REQUIRED, + attrs(AttrKind.HTML4, ALIGN, CHAR, CHAROFF, VALIGN, WIDTH)) { + @Override + public boolean accepts(HtmlTag t) { + return (t == COL); + } + }, + DD(BlockType.LIST_ITEM, EndKind.OPTIONAL, EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE, Flag.EXPECT_CONTENT)), DEL(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST), - attrs(AttrKind.OK, Attr.CITE, Attr.DATETIME)), + attrs(AttrKind.ALL, Attr.CITE, Attr.DATETIME)), DFN(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), DIV(BlockType.BLOCK, EndKind.REQUIRED, - EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), + EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE), + attrs(AttrKind.USE_CSS, ALIGN)), DL(BlockType.BLOCK, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT), @@ -121,49 +145,95 @@ public enum HtmlTag { EM(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.NO_NEST)), - FONT(BlockType.INLINE, EndKind.REQUIRED, // tag itself is deprecated + FONT(HtmlVersion.HTML4, BlockType.INLINE, EndKind.REQUIRED, // tag itself is deprecated EnumSet.of(Flag.EXPECT_CONTENT), attrs(AttrKind.USE_CSS, SIZE, COLOR, FACE)), - FRAME(BlockType.OTHER, EndKind.NONE), + FOOTER(HtmlVersion.HTML5, BlockType.BLOCK, EndKind.REQUIRED, + EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)) { + @Override + public boolean accepts(HtmlTag t) { + switch (t) { + case HEADER: case FOOTER: case MAIN: + return false; + default: + return (t.blockType == BlockType.BLOCK) || (t.blockType == BlockType.INLINE); + } + } + }, - FRAMESET(BlockType.OTHER, EndKind.REQUIRED), + FIGURE(HtmlVersion.HTML5, BlockType.BLOCK, EndKind.REQUIRED, + EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), - H1(BlockType.BLOCK, EndKind.REQUIRED), - H2(BlockType.BLOCK, EndKind.REQUIRED), - H3(BlockType.BLOCK, EndKind.REQUIRED), - H4(BlockType.BLOCK, EndKind.REQUIRED), - H5(BlockType.BLOCK, EndKind.REQUIRED), - H6(BlockType.BLOCK, EndKind.REQUIRED), + FIGCAPTION(HtmlVersion.HTML5, BlockType.BLOCK, EndKind.REQUIRED), + + FRAME(HtmlVersion.HTML4, BlockType.OTHER, EndKind.NONE), + + FRAMESET(HtmlVersion.HTML4, BlockType.OTHER, EndKind.REQUIRED), + + H1(BlockType.BLOCK, EndKind.REQUIRED, + attrs(AttrKind.USE_CSS, ALIGN)), + H2(BlockType.BLOCK, EndKind.REQUIRED, + attrs(AttrKind.USE_CSS, ALIGN)), + H3(BlockType.BLOCK, EndKind.REQUIRED, + attrs(AttrKind.USE_CSS, ALIGN)), + H4(BlockType.BLOCK, EndKind.REQUIRED, + attrs(AttrKind.USE_CSS, ALIGN)), + H5(BlockType.BLOCK, EndKind.REQUIRED, + attrs(AttrKind.USE_CSS, ALIGN)), + H6(BlockType.BLOCK, EndKind.REQUIRED, + attrs(AttrKind.USE_CSS, ALIGN)), HEAD(BlockType.OTHER, EndKind.REQUIRED), + HEADER(HtmlVersion.HTML5, BlockType.BLOCK, EndKind.REQUIRED, + EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)) { + @Override + public boolean accepts(HtmlTag t) { + switch (t) { + case HEADER: case FOOTER: case MAIN: + return false; + default: + return (t.blockType == BlockType.BLOCK) || (t.blockType == BlockType.INLINE); + } + } + }, + HR(BlockType.BLOCK, EndKind.NONE, - attrs(AttrKind.OK, WIDTH)), // OK in 4.01; not allowed in 5 + attrs(AttrKind.HTML4, WIDTH), + attrs(AttrKind.USE_CSS, ALIGN, NOSHADE, SIZE)), HTML(BlockType.OTHER, EndKind.REQUIRED), I(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), + IFRAME(BlockType.OTHER, EndKind.REQUIRED), + IMG(BlockType.INLINE, EndKind.NONE, - attrs(AttrKind.OK, SRC, ALT, HEIGHT, WIDTH), + attrs(AttrKind.ALL, SRC, ALT, HEIGHT, WIDTH), + attrs(AttrKind.HTML5, CROSSORIGIN), attrs(AttrKind.OBSOLETE, NAME), attrs(AttrKind.USE_CSS, ALIGN, HSPACE, VSPACE, BORDER)), INS(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST), - attrs(AttrKind.OK, Attr.CITE, Attr.DATETIME)), + attrs(AttrKind.ALL, Attr.CITE, Attr.DATETIME)), KBD(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), LI(BlockType.LIST_ITEM, EndKind.OPTIONAL, EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE), - attrs(AttrKind.OK, VALUE)), + attrs(AttrKind.ALL, VALUE), + attrs(AttrKind.USE_CSS, TYPE)), LINK(BlockType.OTHER, EndKind.NONE), + MAIN(HtmlVersion.HTML5, BlockType.OTHER, EndKind.REQUIRED), + + MARK(HtmlVersion.HTML5, BlockType.INLINE, EndKind.REQUIRED), + MENU(BlockType.BLOCK, EndKind.REQUIRED) { @Override public boolean accepts(HtmlTag t) { @@ -173,13 +243,18 @@ public enum HtmlTag { META(BlockType.OTHER, EndKind.NONE), - NOFRAMES(BlockType.OTHER, EndKind.REQUIRED), + NAV(HtmlVersion.HTML5, BlockType.BLOCK, EndKind.REQUIRED, + EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), + + NOFRAMES(HtmlVersion.HTML4, BlockType.OTHER, EndKind.REQUIRED), NOSCRIPT(BlockType.BLOCK, EndKind.REQUIRED), OL(BlockType.BLOCK, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT), - attrs(AttrKind.OK, START, TYPE)) { + attrs(AttrKind.ALL, START, TYPE), + attrs(AttrKind.HTML5, REVERSED), + attrs(AttrKind.USE_CSS, COMPACT)) { @Override public boolean accepts(HtmlTag t) { return (t == LI); @@ -191,7 +266,8 @@ public enum HtmlTag { attrs(AttrKind.USE_CSS, ALIGN)), PRE(BlockType.BLOCK, EndKind.REQUIRED, - EnumSet.of(Flag.EXPECT_CONTENT)) { + EnumSet.of(Flag.EXPECT_CONTENT), + attrs(AttrKind.USE_CSS, WIDTH)) { @Override public boolean accepts(HtmlTag t) { switch (t) { @@ -214,13 +290,16 @@ public enum HtmlTag { SCRIPT(BlockType.OTHER, EndKind.REQUIRED), + SECTION(HtmlVersion.HTML5, BlockType.BLOCK, EndKind.REQUIRED, + EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), + SMALL(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT)), SPAN(BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT)), - STRIKE(BlockType.INLINE, EndKind.REQUIRED, + STRIKE(HtmlVersion.HTML4, BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT)), STRONG(BlockType.INLINE, EndKind.REQUIRED, @@ -234,13 +313,14 @@ public enum HtmlTag { TABLE(BlockType.BLOCK, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT), - attrs(AttrKind.OK, SUMMARY, Attr.FRAME, RULES, BORDER, - CELLPADDING, CELLSPACING, WIDTH), // width OK in 4.01; not allowed in 5 + attrs(AttrKind.ALL, BORDER), + attrs(AttrKind.HTML4, SUMMARY, CELLPADDING, CELLSPACING, Attr.FRAME, RULES, WIDTH), attrs(AttrKind.USE_CSS, ALIGN, BGCOLOR)) { @Override public boolean accepts(HtmlTag t) { switch (t) { case CAPTION: + case COLGROUP: case THEAD: case TBODY: case TFOOT: case TR: // HTML 3.2 return true; @@ -252,7 +332,8 @@ public enum HtmlTag { TBODY(BlockType.TABLE_ITEM, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT), - attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)) { + attrs(AttrKind.ALL, VALIGN), + attrs(AttrKind.HTML4, ALIGN, CHAR, CHAROFF)) { @Override public boolean accepts(HtmlTag t) { return (t == TR); @@ -261,12 +342,16 @@ public enum HtmlTag { TD(BlockType.TABLE_ITEM, EndKind.OPTIONAL, EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE), - attrs(AttrKind.OK, COLSPAN, ROWSPAN, HEADERS, SCOPE, Attr.ABBR, AXIS, - ALIGN, CHAR, CHAROFF, VALIGN), + attrs(AttrKind.ALL, COLSPAN, ROWSPAN, HEADERS, VALIGN), + attrs(AttrKind.HTML4, AXIS, Attr.ABBR, SCOPE, ALIGN, CHAR, CHAROFF), attrs(AttrKind.USE_CSS, WIDTH, BGCOLOR, HEIGHT, NOWRAP)), + TEMPLATE(HtmlVersion.HTML5, BlockType.BLOCK, EndKind.REQUIRED, + EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), + TFOOT(BlockType.TABLE_ITEM, EndKind.REQUIRED, - attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)) { + attrs(AttrKind.ALL, VALIGN), + attrs(AttrKind.HTML4, ALIGN, CHAR, CHAROFF)) { @Override public boolean accepts(HtmlTag t) { return (t == TR); @@ -275,22 +360,27 @@ public enum HtmlTag { TH(BlockType.TABLE_ITEM, EndKind.OPTIONAL, EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE), - attrs(AttrKind.OK, COLSPAN, ROWSPAN, HEADERS, SCOPE, Attr.ABBR, AXIS, - ALIGN, CHAR, CHAROFF, VALIGN), + attrs(AttrKind.ALL, COLSPAN, ROWSPAN, HEADERS, SCOPE, Attr.ABBR, + VALIGN), + attrs(AttrKind.HTML4, AXIS, ALIGN, CHAR, CHAROFF), attrs(AttrKind.USE_CSS, WIDTH, BGCOLOR, HEIGHT, NOWRAP)), THEAD(BlockType.TABLE_ITEM, EndKind.REQUIRED, - attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)) { + attrs(AttrKind.ALL, VALIGN), + attrs(AttrKind.HTML4, ALIGN, CHAR, CHAROFF)) { @Override public boolean accepts(HtmlTag t) { return (t == TR); } }, + TIME(HtmlVersion.HTML5, BlockType.INLINE, EndKind.REQUIRED), + TITLE(BlockType.OTHER, EndKind.REQUIRED), TR(BlockType.TABLE_ITEM, EndKind.OPTIONAL, - attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN), + attrs(AttrKind.ALL, VALIGN), + attrs(AttrKind.HTML4, ALIGN, CHAR, CHAROFF), attrs(AttrKind.USE_CSS, BGCOLOR)) { @Override public boolean accepts(HtmlTag t) { @@ -298,7 +388,7 @@ public enum HtmlTag { } }, - TT(BlockType.INLINE, EndKind.REQUIRED, + TT(HtmlVersion.HTML4, BlockType.INLINE, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), U(BlockType.INLINE, EndKind.REQUIRED, @@ -306,13 +396,15 @@ public enum HtmlTag { UL(BlockType.BLOCK, EndKind.REQUIRED, EnumSet.of(Flag.EXPECT_CONTENT), - attrs(AttrKind.OK, COMPACT, TYPE)) { // OK in 4.01; not allowed in 5 + attrs(AttrKind.HTML4, COMPACT, TYPE)) { @Override public boolean accepts(HtmlTag t) { return (t == LI); } }, + WBR(HtmlVersion.HTML5, BlockType.INLINE, EndKind.REQUIRED), + VAR(BlockType.INLINE, EndKind.REQUIRED); /** @@ -345,34 +437,66 @@ public enum HtmlTag { public static enum Attr { ABBR, ALIGN, + ALINK, ALT, + ARIA_ACTIVEDESCENDANT, + ARIA_CONTROLS, + ARIA_DESCRIBEDBY, + ARIA_EXPANDED, + ARIA_LABEL, + ARIA_LABELLEDBY, + ARIA_LEVEL, + ARIA_MULTISELECTABLE, + ARIA_OWNS, + ARIA_POSINSET, + ARIA_SETSIZE, + ARIA_READONLY, + ARIA_REQUIRED, + ARIA_SELECTED, + ARIA_SORT, AXIS, + BACKGROUND, BGCOLOR, BORDER, CELLSPACING, CELLPADDING, CHAR, CHAROFF, + CHARSET, CITE, CLEAR, CLASS, COLOR, COLSPAN, COMPACT, + COORDS, + CROSSORIGIN, DATETIME, FACE, FRAME, + FRAMEBORDER, HEADERS, HEIGHT, HREF, HSPACE, ID, + LINK, + LONGDESC, + MARGINHEIGHT, + MARGINWIDTH, NAME, + NOSHADE, NOWRAP, + PROFILE, + REV, REVERSED, + ROLE, ROWSPAN, RULES, + SCHEME, SCOPE, + SCROLLING, + SHAPE, SIZE, SPACE, SRC, @@ -380,14 +504,23 @@ public enum HtmlTag { STYLE, SUMMARY, TARGET, + TEXT, TYPE, VALIGN, VALUE, + VERSION, + VLINK, VSPACE, WIDTH; + private final String name; + + Attr() { + name = StringUtils.toLowerCase(name().replace("_", "-")); + } + public String getText() { - return StringUtils.toLowerCase(name()); + return name; } static final Map index = new HashMap<>(); @@ -399,10 +532,12 @@ public enum HtmlTag { } public static enum AttrKind { + HTML4, + HTML5, INVALID, OBSOLETE, USE_CSS, - OK + ALL } // This class exists to avoid warnings from using parameterized vararg type @@ -415,25 +550,52 @@ public enum HtmlTag { } + public final HtmlVersion allowedVersion; public final BlockType blockType; public final EndKind endKind; public final Set flags; private final Map attrs; HtmlTag(BlockType blockType, EndKind endKind, AttrMap... attrMaps) { - this(blockType, endKind, Collections.emptySet(), attrMaps); + this(HtmlVersion.ALL, blockType, endKind, Collections.emptySet(), attrMaps); + } + + HtmlTag(HtmlVersion allowedVersion, BlockType blockType, EndKind endKind, AttrMap... attrMaps) { + this(allowedVersion, blockType, endKind, Collections.emptySet(), attrMaps); } HtmlTag(BlockType blockType, EndKind endKind, Set flags, AttrMap... attrMaps) { + this(HtmlVersion.ALL, blockType, endKind, flags, attrMaps); + } + + HtmlTag(HtmlVersion allowedVersion, BlockType blockType, EndKind endKind, Set flags, AttrMap... attrMaps) { + this.allowedVersion = allowedVersion; this.blockType = blockType; this.endKind = endKind; this.flags = flags; this.attrs = new EnumMap<>(Attr.class); for (Map m: attrMaps) this.attrs.putAll(m); - attrs.put(Attr.CLASS, AttrKind.OK); - attrs.put(Attr.ID, AttrKind.OK); - attrs.put(Attr.STYLE, AttrKind.OK); + attrs.put(Attr.CLASS, AttrKind.ALL); + attrs.put(Attr.ID, AttrKind.ALL); + attrs.put(Attr.STYLE, AttrKind.ALL); + attrs.put(Attr.ROLE, AttrKind.HTML5); + // for now, assume that all ARIA attributes are allowed on all tags. + attrs.put(Attr.ARIA_ACTIVEDESCENDANT, AttrKind.HTML5); + attrs.put(Attr.ARIA_CONTROLS, AttrKind.HTML5); + attrs.put(Attr.ARIA_DESCRIBEDBY, AttrKind.HTML5); + attrs.put(Attr.ARIA_EXPANDED, AttrKind.HTML5); + attrs.put(Attr.ARIA_LABEL, AttrKind.HTML5); + attrs.put(Attr.ARIA_LABELLEDBY, AttrKind.HTML5); + attrs.put(Attr.ARIA_LEVEL, AttrKind.HTML5); + attrs.put(Attr.ARIA_MULTISELECTABLE, AttrKind.HTML5); + attrs.put(Attr.ARIA_OWNS, AttrKind.HTML5); + attrs.put(Attr.ARIA_POSINSET, AttrKind.HTML5); + attrs.put(Attr.ARIA_READONLY, AttrKind.HTML5); + attrs.put(Attr.ARIA_REQUIRED, AttrKind.HTML5); + attrs.put(Attr.ARIA_SELECTED, AttrKind.HTML5); + attrs.put(Attr.ARIA_SETSIZE, AttrKind.HTML5); + attrs.put(Attr.ARIA_SORT, AttrKind.HTML5); } public boolean accepts(HtmlTag t) { diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/HtmlVersion.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/HtmlVersion.java new file mode 100644 index 00000000000..cfa40ba30b9 --- /dev/null +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/HtmlVersion.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, 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.tools.doclint; + +/** + * Enum representing HTML version of the documentation comment. + * + * @author Bhavesh Patel + */ +public enum HtmlVersion { + + HTML4, + HTML5, + ALL; + + public static HtmlVersion getHtmlVersion(String argsVersion) { + switch (argsVersion) { + case "html4": + return HtmlVersion.HTML4; + case "html5": + return HtmlVersion.HTML5; + default: + return null; + } + } +} diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties index 1f47d94d3bc..03adb82aeaa 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties @@ -27,9 +27,12 @@ dc.anchor.already.defined = anchor already defined: "{0}" dc.anchor.value.missing = no value given for anchor dc.attr.lacks.value = attribute lacks value dc.attr.not.number = attribute value is not a number +dc.attr.not.supported.html4 = attribute not supported in HTML4: {0} +dc.attr.not.supported.html5 = attribute not supported in HTML5: {0} dc.attr.obsolete = attribute obsolete: {0} dc.attr.obsolete.use.css = attribute obsolete, use CSS instead: {0} dc.attr.repeated = repeated attribute: {0} +dc.attr.table.border.html5 = attribute border for table only accepts "" or "1", use CSS instead: {0} dc.attr.unknown = unknown attribute: {0} dc.bad.option = bad option: {0} dc.bad.value.for.option = bad value for option: {0} {1} @@ -63,9 +66,11 @@ dc.tag.not.allowed.inline.tag = block element not allowed within @{1}: {0} dc.tag.not.allowed.inline.other = block element not allowed here: {0} dc.tag.not.closed= element not closed: {0} dc.tag.p.in.pre= unexpected use of

      inside

       element
      +dc.tag.requires.heading = heading not found for 
       dc.tag.self.closing = self-closing element not allowed
       dc.tag.start.unmatched = end tag missing: 
       dc.tag.unknown = unknown tag: {0}
      +dc.tag.not.supported = tag not supported in the generated HTML version: {0}
       dc.text.not.allowed = text not allowed in <{0}> element
       dc.type.arg.not.allowed = type arguments not allowed here
       dc.unexpected.comment=documentation comment not expected here
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractMemberWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractMemberWriter.java
      index c42a692803f..54d8046ff1d 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractMemberWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractMemberWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1997, 2015, 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
      @@ -415,8 +415,10 @@ public abstract class AbstractMemberWriter {
           protected void addDeprecatedAPI(List deprmembers, String headingKey,
                   String tableSummary, String[] tableHeader, Content contentTree) {
               if (deprmembers.size() > 0) {
      -            Content table = HtmlTree.TABLE(HtmlStyle.deprecatedSummary, 0, 3, 0, tableSummary,
      -                writer.getTableCaption(configuration.getResource(headingKey)));
      +            Content caption = writer.getTableCaption(configuration.getResource(headingKey));
      +            Content table = (configuration.isOutputHtml5())
      +                    ? HtmlTree.TABLE(HtmlStyle.deprecatedSummary, caption)
      +                    : HtmlTree.TABLE(HtmlStyle.deprecatedSummary, tableSummary, caption);
                   table.addContent(writer.getSummaryTableHeader(tableHeader, "col"));
                   Content tbody = new HtmlTree(HtmlTag.TBODY);
                   for (int i = 0; i < deprmembers.size(); i++) {
      @@ -455,8 +457,10 @@ public abstract class AbstractMemberWriter {
               List members = mems;
               boolean printedUseTableHeader = false;
               if (members.size() > 0) {
      -            Content table = HtmlTree.TABLE(HtmlStyle.useSummary, 0, 3, 0, tableSummary,
      -                    writer.getTableCaption(heading));
      +            Content caption = writer.getTableCaption(heading);
      +            Content table = (configuration.isOutputHtml5())
      +                    ? HtmlTree.TABLE(HtmlStyle.useSummary, caption)
      +                    : HtmlTree.TABLE(HtmlStyle.useSummary, tableSummary, caption);
                   Content tbody = new HtmlTree(HtmlTag.TBODY);
                   Iterator it = members.iterator();
                   for (int i = 0; it.hasNext(); i++) {
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java
      index 76bf7aae7c8..9378865aacd 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1998, 2015, 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
      @@ -149,13 +149,17 @@ public abstract class AbstractPackageIndexWriter extends HtmlDocletWriter {
           protected void addIndexContents(Collection packages, String text,
                   String tableSummary, Content body) {
               if (!packages.isEmpty()) {
      -            HtmlTree div = new HtmlTree(HtmlTag.DIV);
      -            div.addStyle(HtmlStyle.indexHeader);
      -            addAllClassesLink(div);
      +            HtmlTree htmlTree = (configuration.allowTag(HtmlTag.NAV))
      +                    ? HtmlTree.NAV()
      +                    : new HtmlTree(HtmlTag.DIV);
      +            htmlTree.addStyle(HtmlStyle.indexNav);
      +            HtmlTree ul = new HtmlTree(HtmlTag.UL);
      +            addAllClassesLink(ul);
                   if (configuration.showProfiles) {
      -                addAllProfilesLink(div);
      +                addAllProfilesLink(ul);
                   }
      -            body.addContent(div);
      +            htmlTree.addContent(ul);
      +            body.addContent(htmlTree);
                   if (configuration.showProfiles && configuration.profilePackages.size() > 0) {
                       Content profileSummary = configuration.getResource("doclet.Profiles");
                       addProfilesList(profileSummary, body);
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractProfileIndexWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractProfileIndexWriter.java
      index c0f7ccf3976..debbdadc10b 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractProfileIndexWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractProfileIndexWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2013, 2015 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
      @@ -194,11 +194,15 @@ public abstract class AbstractProfileIndexWriter extends HtmlDocletWriter {
           protected void addIndexContents(Profiles profiles, String text,
                   String tableSummary, Content body) {
               if (profiles.getProfileCount() > 0) {
      -            HtmlTree div = new HtmlTree(HtmlTag.DIV);
      -            div.addStyle(HtmlStyle.indexHeader);
      -            addAllClassesLink(div);
      -            addAllPackagesLink(div);
      -            body.addContent(div);
      +            HtmlTree htmlTree = (configuration.allowTag(HtmlTag.NAV))
      +                    ? HtmlTree.NAV()
      +                    : new HtmlTree(HtmlTag.DIV);
      +            htmlTree.addStyle(HtmlStyle.indexNav);
      +            HtmlTree ul = new HtmlTree(HtmlTag.UL);
      +            addAllClassesLink(ul);
      +            addAllPackagesLink(ul);
      +            htmlTree.addContent(ul);
      +            body.addContent(htmlTree);
                   addProfilesList(profiles, text, tableSummary, body);
               }
           }
      @@ -215,12 +219,16 @@ public abstract class AbstractProfileIndexWriter extends HtmlDocletWriter {
            */
           protected void addProfilePackagesIndexContents(Profiles profiles, String text,
                   String tableSummary, Content body, String profileName) {
      -        HtmlTree div = new HtmlTree(HtmlTag.DIV);
      -        div.addStyle(HtmlStyle.indexHeader);
      -        addAllClassesLink(div);
      -        addAllPackagesLink(div);
      -        addAllProfilesLink(div);
      -        body.addContent(div);
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.NAV))
      +                ? HtmlTree.NAV()
      +                : new HtmlTree(HtmlTag.DIV);
      +        htmlTree.addStyle(HtmlStyle.indexNav);
      +        HtmlTree ul = new HtmlTree(HtmlTag.UL);
      +        addAllClassesLink(ul);
      +        addAllPackagesLink(ul);
      +        addAllProfilesLink(ul);
      +        htmlTree.addContent(ul);
      +        body.addContent(htmlTree);
               addProfilePackagesList(profiles, text, tableSummary, body, profileName);
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.java
      index fa02e59f692..cd4c70f47bb 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1998, 2015, 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
      @@ -53,8 +53,6 @@ public abstract class AbstractTreeWriter extends HtmlDocletWriter {
            */
           protected final ClassTree classtree;
       
      -    private static final String LI_CIRCLE  = "circle";
      -
           /**
            * Constructor initializes classtree variable. This constructor will be used
            * while generating global tree file "overview-tree.html".
      @@ -88,7 +86,7 @@ public abstract class AbstractTreeWriter extends HtmlDocletWriter {
                   Content ul = new HtmlTree(HtmlTag.UL);
                   for (ClassDoc local : list) {
                       HtmlTree li = new HtmlTree(HtmlTag.LI);
      -                li.addAttr(HtmlAttr.TYPE, LI_CIRCLE);
      +                li.addStyle(HtmlStyle.circle);
                       addPartialInfo(local, li);
                       addExtendsImplements(parent, local, li);
                       addLevelInfo(local, classtree.subs(local, isEnum),
      @@ -108,14 +106,24 @@ public abstract class AbstractTreeWriter extends HtmlDocletWriter {
            * @param heading heading for the tree
            * @param div the content tree to which the tree will be added
            */
      -    protected void addTree(SortedSet list, String heading, Content div) {
      +    protected void addTree(SortedSet list, String heading, HtmlTree div) {
               if (!list.isEmpty()) {
                   ClassDoc firstClassDoc = list.first();
                   Content headingContent = getResource(heading);
      -            div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
      -                    headingContent));
      +            Content sectionHeading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
      +                    headingContent);
      +            HtmlTree htmlTree;
      +            if (configuration.allowTag(HtmlTag.SECTION)) {
      +                htmlTree = HtmlTree.SECTION(sectionHeading);
      +            } else {
      +                div.addContent(sectionHeading);
      +                htmlTree = div;
      +            }
                   addLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null,
      -                    list, list == classtree.baseEnums(), div);
      +                    list, list == classtree.baseEnums(), htmlTree);
      +            if (configuration.allowTag(HtmlTag.SECTION)) {
      +                div.addContent(htmlTree);
      +            }
               }
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AllClassesFrameWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AllClassesFrameWriter.java
      index 71e27df0266..32f30f3331b 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AllClassesFrameWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AllClassesFrameWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1998, 2015, 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
      @@ -119,8 +119,10 @@ public class AllClassesFrameWriter extends HtmlDocletWriter {
               Content ul = new HtmlTree(HtmlTag.UL);
               // Generate the class links and add it to the tdFont tree.
               addAllClasses(ul, wantFrames);
      -        Content div = HtmlTree.DIV(HtmlStyle.indexContainer, ul);
      -        body.addContent(div);
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN))
      +                ? HtmlTree.MAIN(HtmlStyle.indexContainer, ul)
      +                : HtmlTree.DIV(HtmlStyle.indexContainer, ul);
      +        body.addContent(htmlTree);
               printHtmlDocument(null, false, body);
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeFieldWriterImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeFieldWriterImpl.java
      index 55dcd84fc64..87cf3a079dc 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeFieldWriterImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeFieldWriterImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2013, 2015 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
      @@ -74,6 +74,13 @@ public class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter
               return writer.getMemberTreeHeader();
           }
       
      +    /**
      +     * {@inheritDoc}
      +     */
      +    public void addMemberTree(Content memberSummaryTree, Content memberTree) {
      +        writer.addMemberTree(memberSummaryTree, memberTree);
      +    }
      +
           /**
            * {@inheritDoc}
            */
      @@ -156,6 +163,10 @@ public class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter
            * {@inheritDoc}
            */
           public Content getAnnotationDetails(Content annotationDetailsTree) {
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(annotationDetailsTree));
      +            return htmlTree;
      +        }
               return getMemberTree(annotationDetailsTree);
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeOptionalMemberWriterImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeOptionalMemberWriterImpl.java
      index 9a586a017f3..66f60f986d0 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeOptionalMemberWriterImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeOptionalMemberWriterImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2003, 2015, 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
      @@ -69,6 +69,13 @@ public class AnnotationTypeOptionalMemberWriterImpl extends
               return memberTree;
           }
       
      +    /**
      +     * {@inheritDoc}
      +     */
      +    public void addMemberTree(Content memberSummaryTree, Content memberTree) {
      +        writer.addMemberTree(memberSummaryTree, memberTree);
      +    }
      +
           /**
            * {@inheritDoc}
            */
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeRequiredMemberWriterImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeRequiredMemberWriterImpl.java
      index a3392011ae2..63ed9459a17 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeRequiredMemberWriterImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeRequiredMemberWriterImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2003, 2015, 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
      @@ -75,6 +75,13 @@ public class AnnotationTypeRequiredMemberWriterImpl extends AbstractMemberWriter
               return writer.getMemberTreeHeader();
           }
       
      +    /**
      +     * {@inheritDoc}
      +     */
      +    public void addMemberTree(Content memberSummaryTree, Content memberTree) {
      +        writer.addMemberTree(memberSummaryTree, memberTree);
      +    }
      +
           /**
            * {@inheritDoc}
            */
      @@ -158,6 +165,10 @@ public class AnnotationTypeRequiredMemberWriterImpl extends AbstractMemberWriter
            * {@inheritDoc}
            */
           public Content getAnnotationDetails(Content annotationDetailsTree) {
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(annotationDetailsTree));
      +            return htmlTree;
      +        }
               return getMemberTree(annotationDetailsTree);
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java
      index 1bbc147e75a..447b93bdbf1 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2003, 2015, 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
      @@ -151,9 +151,15 @@ public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
               String pkgname = (annotationType.containingPackage() != null)?
                   annotationType.containingPackage().name(): "";
               String clname = annotationType.name();
      -        Content bodyTree = getBody(true, getWindowTitle(clname));
      -        addTop(bodyTree);
      -        addNavLinks(true, bodyTree);
      +        HtmlTree bodyTree = getBody(true, getWindowTitle(clname));
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
      +                ? HtmlTree.HEADER()
      +                : bodyTree;
      +        addTop(htmlTree);
      +        addNavLinks(true, htmlTree);
      +        if (configuration.allowTag(HtmlTag.HEADER)) {
      +            bodyTree.addContent(htmlTree);
      +        }
               bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA);
               HtmlTree div = new HtmlTree(HtmlTag.DIV);
               div.addStyle(HtmlStyle.header);
      @@ -169,7 +175,11 @@ public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
                       HtmlStyle.title, headerContent);
               heading.addContent(getTypeParameterLinks(linkInfo));
               div.addContent(heading);
      -        bodyTree.addContent(div);
      +        if (configuration.allowTag(HtmlTag.MAIN)) {
      +            mainTree.addContent(div);
      +        } else {
      +            bodyTree.addContent(div);
      +        }
               return bodyTree;
           }
       
      @@ -185,8 +195,14 @@ public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
            */
           public void addFooter(Content contentTree) {
               contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA);
      -        addNavLinks(false, contentTree);
      -        addBottom(contentTree);
      +        Content htmlTree = (configuration.allowTag(HtmlTag.FOOTER))
      +                ? HtmlTree.FOOTER()
      +                : contentTree;
      +        addNavLinks(false, htmlTree);
      +        addBottom(htmlTree);
      +        if (configuration.allowTag(HtmlTag.FOOTER)) {
      +            contentTree.addContent(htmlTree);
      +        }
           }
       
           /**
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java
      index f805cc01c80..883e65795ae 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1998, 2015, 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
      @@ -90,6 +90,11 @@ public class ClassUseWriter extends SubWriterHolderWriter {
           final String methodUseTableSummary;
           final String constructorUseTableSummary;
       
      +    /**
      +     * The HTML tree for main tag.
      +     */
      +    protected HtmlTree mainTree = HtmlTree.MAIN();
      +
           /**
            * Constructor.
            *
      @@ -222,7 +227,7 @@ public class ClassUseWriter extends SubWriterHolderWriter {
            * Generate the class use list.
            */
           protected void generateClassUseFile() throws IOException {
      -        Content body = getClassUseHeader();
      +        HtmlTree body = getClassUseHeader();
               HtmlTree div = new HtmlTree(HtmlTag.DIV);
               div.addStyle(HtmlStyle.classUseContainer);
               if (pkgSet.size() > 0) {
      @@ -231,9 +236,20 @@ public class ClassUseWriter extends SubWriterHolderWriter {
                   div.addContent(getResource("doclet.ClassUse_No.usage.of.0",
                           classdoc.qualifiedName()));
               }
      -        body.addContent(div);
      -        addNavLinks(false, body);
      -        addBottom(body);
      +        if (configuration.allowTag(HtmlTag.MAIN)) {
      +            mainTree.addContent(div);
      +            body.addContent(mainTree);
      +        } else {
      +            body.addContent(div);
      +        }
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.FOOTER))
      +                ? HtmlTree.FOOTER()
      +                : body;
      +        addNavLinks(false, htmlTree);
      +        addBottom(htmlTree);
      +        if (configuration.allowTag(HtmlTag.FOOTER)) {
      +            body.addContent(htmlTree);
      +        }
               printHtmlDocument(null, true, body);
           }
       
      @@ -259,11 +275,12 @@ public class ClassUseWriter extends SubWriterHolderWriter {
            * @param contentTree the content tree to which the packages list will be added
            */
           protected void addPackageList(Content contentTree) throws IOException {
      -        Content table = HtmlTree.TABLE(HtmlStyle.useSummary, 0, 3, 0, useTableSummary,
      -                getTableCaption(configuration.getResource(
      +        Content caption = getTableCaption(configuration.getResource(
                       "doclet.ClassUse_Packages.that.use.0",
      -                getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER, classdoc
      -                )))));
      +                getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER, classdoc))));
      +        Content table = (configuration.isOutputHtml5())
      +                ? HtmlTree.TABLE(HtmlStyle.useSummary, caption)
      +                : HtmlTree.TABLE(HtmlStyle.useSummary, useTableSummary, caption);
               table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
               Content tbody = new HtmlTree(HtmlTag.TBODY);
               Iterator it = pkgSet.iterator();
      @@ -294,11 +311,13 @@ public class ClassUseWriter extends SubWriterHolderWriter {
                       pkgToPackageAnnotations.isEmpty()) {
                   return;
               }
      -        Content table = HtmlTree.TABLE(HtmlStyle.useSummary, 0, 3, 0, useTableSummary,
      -                getTableCaption(configuration.getResource(
      +        Content caption = getTableCaption(configuration.getResource(
                       "doclet.ClassUse_PackageAnnotation",
                       getLink(new LinkInfoImpl(configuration,
      -                        LinkInfoImpl.Kind.CLASS_USE_HEADER, classdoc)))));
      +                                LinkInfoImpl.Kind.CLASS_USE_HEADER, classdoc))));
      +        Content table = (configuration.isOutputHtml5())
      +                ? HtmlTree.TABLE(HtmlStyle.useSummary, caption)
      +                : HtmlTree.TABLE(HtmlStyle.useSummary, useTableSummary, caption);
               table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
               Content tbody = new HtmlTree(HtmlTag.TBODY);
               Iterator it = pkgToPackageAnnotations.iterator();
      @@ -333,15 +352,22 @@ public class ClassUseWriter extends SubWriterHolderWriter {
               HtmlTree ul = new HtmlTree(HtmlTag.UL);
               ul.addStyle(HtmlStyle.blockList);
               for (PackageDoc pkg : pkgSet) {
      -            Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(getPackageAnchorName(pkg)));
      +            Content markerAnchor = getMarkerAnchor(getPackageAnchorName(pkg));
      +            HtmlTree htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                    ? HtmlTree.SECTION(markerAnchor)
      +                    : HtmlTree.LI(HtmlStyle.blockList, markerAnchor);
                   Content link = getResource("doclet.ClassUse_Uses.of.0.in.1",
                                              getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER,
                                                                       classdoc)),
                                              getPackageLink(pkg, utils.getPackageName(pkg)));
                   Content heading = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, link);
      -            li.addContent(heading);
      -            addClassUse(pkg, li);
      -            ul.addContent(li);
      +            htmlTree.addContent(heading);
      +            addClassUse(pkg, htmlTree);
      +            if (configuration.allowTag(HtmlTag.SECTION)) {
      +                ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +            } else {
      +                ul.addContent(htmlTree);
      +            }
               }
               Content li = HtmlTree.LI(HtmlStyle.blockList, ul);
               contentTree.addContent(li);
      @@ -443,15 +469,21 @@ public class ClassUseWriter extends SubWriterHolderWriter {
            *
            * @return a content tree representing the class use header
            */
      -    protected Content getClassUseHeader() {
      +    protected HtmlTree getClassUseHeader() {
               String cltype = configuration.getText(classdoc.isInterface()?
                   "doclet.Interface":"doclet.Class");
               String clname = classdoc.qualifiedName();
               String title = configuration.getText("doclet.Window_ClassUse_Header",
                       cltype, clname);
      -        Content bodyTree = getBody(true, getWindowTitle(title));
      -        addTop(bodyTree);
      -        addNavLinks(true, bodyTree);
      +        HtmlTree bodyTree = getBody(true, getWindowTitle(title));
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
      +                ? HtmlTree.HEADER()
      +                : bodyTree;
      +        addTop(htmlTree);
      +        addNavLinks(true, htmlTree);
      +        if (configuration.allowTag(HtmlTag.HEADER)) {
      +            bodyTree.addContent(htmlTree);
      +        }
               ContentBuilder headContent = new ContentBuilder();
               headContent.addContent(getResource("doclet.ClassUse_Title", cltype));
               headContent.addContent(new HtmlTree(HtmlTag.BR));
      @@ -459,7 +491,11 @@ public class ClassUseWriter extends SubWriterHolderWriter {
               Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING,
                       true, HtmlStyle.title, headContent);
               Content div = HtmlTree.DIV(HtmlStyle.header, heading);
      -        bodyTree.addContent(div);
      +        if (configuration.allowTag(HtmlTag.MAIN)) {
      +            mainTree.addContent(div);
      +        } else {
      +            bodyTree.addContent(div);
      +        }
               return bodyTree;
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java
      index c364bd16e34..d9dafe97c23 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1997, 2015, 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
      @@ -35,6 +35,7 @@ import com.sun.tools.doclets.internal.toolkit.*;
       import com.sun.tools.doclets.internal.toolkit.builders.*;
       import com.sun.tools.doclets.internal.toolkit.taglets.*;
       import com.sun.tools.doclets.internal.toolkit.util.*;
      +
       import java.io.IOException;
       
       /**
      @@ -160,9 +161,15 @@ public class ClassWriterImpl extends SubWriterHolderWriter
               String pkgname = (classDoc.containingPackage() != null)?
                   classDoc.containingPackage().name(): "";
               String clname = classDoc.name();
      -        Content bodyTree = getBody(true, getWindowTitle(clname));
      -        addTop(bodyTree);
      -        addNavLinks(true, bodyTree);
      +        HtmlTree bodyTree = getBody(true, getWindowTitle(clname));
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
      +                ? HtmlTree.HEADER()
      +                : bodyTree;
      +        addTop(htmlTree);
      +        addNavLinks(true, htmlTree);
      +        if (configuration.allowTag(HtmlTag.HEADER)) {
      +            bodyTree.addContent(htmlTree);
      +        }
               bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA);
               HtmlTree div = new HtmlTree(HtmlTag.DIV);
               div.addStyle(HtmlStyle.header);
      @@ -194,7 +201,11 @@ public class ClassWriterImpl extends SubWriterHolderWriter
                       HtmlStyle.title, headerContent);
               heading.addContent(getTypeParameterLinks(linkInfo));
               div.addContent(heading);
      -        bodyTree.addContent(div);
      +        if (configuration.allowTag(HtmlTag.MAIN)) {
      +            mainTree.addContent(div);
      +        } else {
      +            bodyTree.addContent(div);
      +        }
               return bodyTree;
           }
       
      @@ -210,8 +221,14 @@ public class ClassWriterImpl extends SubWriterHolderWriter
            */
           public void addFooter(Content contentTree) {
               contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA);
      -        addNavLinks(false, contentTree);
      -        addBottom(contentTree);
      +        Content htmlTree = (configuration.allowTag(HtmlTag.FOOTER))
      +                ? HtmlTree.FOOTER()
      +                : contentTree;
      +        addNavLinks(false, htmlTree);
      +        addBottom(htmlTree);
      +        if (configuration.allowTag(HtmlTag.FOOTER)) {
      +            contentTree.addContent(htmlTree);
      +        }
           }
       
           /**
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java
      index 902a2709ac1..7c7882615b2 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1998, 2015, 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
      @@ -31,7 +31,7 @@ import java.util.*;
       import javax.tools.JavaFileManager;
       
       import com.sun.javadoc.*;
      -import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
      +import com.sun.tools.doclets.formats.html.markup.*;
       import com.sun.tools.doclets.internal.toolkit.*;
       import com.sun.tools.doclets.internal.toolkit.util.*;
       import com.sun.tools.doclint.DocLint;
      @@ -175,6 +175,11 @@ public class ConfigurationImpl extends Configuration {
            */
           public boolean createoverview = false;
       
      +    /**
      +     * This is the HTML version of the generated pages. HTML 4.01 is the default output version.
      +     */
      +    public HtmlVersion htmlVersion = HtmlVersion.HTML4;
      +
           /**
            * Collected set of doclint options
            */
      @@ -279,6 +284,10 @@ public class ConfigurationImpl extends Configuration {
                       nooverview = true;
                   } else if (opt.equals("-overview")) {
                       overview = true;
      +            } else if (opt.equals("-html4")) {
      +                htmlVersion = HtmlVersion.HTML4;
      +            } else if (opt.equals("-html5")) {
      +                htmlVersion = HtmlVersion.HTML5;
                   } else if (opt.equals("-xdoclint")) {
                       doclintOpts.add(null);
                   } else if (opt.startsWith("-xdoclint:")) {
      @@ -300,7 +309,8 @@ public class ConfigurationImpl extends Configuration {
               setTopFile(root);
       
               if (root instanceof RootDocImpl) {
      -            ((RootDocImpl) root).initDocLint(doclintOpts, tagletManager.getCustomTagNames());
      +            ((RootDocImpl) root).initDocLint(doclintOpts, tagletManager.getCustomTagNames(),
      +                    StringUtils.toLowerCase(htmlVersion.name()));
               }
           }
       
      @@ -336,6 +346,8 @@ public class ConfigurationImpl extends Configuration {
                   option.equals("-use") ||
                   option.equals("-nonavbar") ||
                   option.equals("-nooverview") ||
      +            option.equals("-html4") ||
      +            option.equals("-html5") ||
                   option.equals("-xdoclint") ||
                   option.startsWith("-xdoclint:")) {
                   return 1;
      @@ -470,6 +482,20 @@ public class ConfigurationImpl extends Configuration {
               return true;
           }
       
      +    /**
      +     * Return true if the generated output is HTML5.
      +     */
      +    public boolean isOutputHtml5() {
      +        return htmlVersion == HtmlVersion.HTML5;
      +    }
      +
      +    /**
      +     * Return true if the tag is allowed for this specific version of HTML.
      +     */
      +    public boolean allowTag(HtmlTag htmlTag) {
      +        return htmlTag.allowTag(this.htmlVersion);
      +    }
      +
           /**
            * {@inheritDoc}
            */
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java
      index 21f0c215038..10abd4b6cfd 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2001, 2015, 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
      @@ -62,6 +62,16 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
       
           private final String[] constantsTableHeader;
       
      +    /**
      +     * The HTML tree for main tag.
      +     */
      +    private HtmlTree mainTree = HtmlTree.MAIN();
      +
      +    /**
      +     * The HTML tree for constant values summary.
      +     */
      +    private HtmlTree summaryTree;
      +
           /**
            * Construct a ConstantsSummaryWriter.
            * @param configuration the configuration used in this run
      @@ -85,9 +95,15 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
            */
           public Content getHeader() {
               String label = configuration.getText("doclet.Constants_Summary");
      -        Content bodyTree = getBody(true, getWindowTitle(label));
      -        addTop(bodyTree);
      -        addNavLinks(true, bodyTree);
      +        HtmlTree bodyTree = getBody(true, getWindowTitle(label));
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
      +                ? HtmlTree.HEADER()
      +                : bodyTree;
      +        addTop(htmlTree);
      +        addNavLinks(true, htmlTree);
      +        if (configuration.allowTag(HtmlTag.HEADER)) {
      +            bodyTree.addContent(htmlTree);
      +        }
               return bodyTree;
           }
       
      @@ -123,7 +139,7 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
           /**
            * {@inheritDoc}
            */
      -    public Content getContentsList(Content contentListTree) {
      +    public void addContentsList(Content contentTree, Content contentListTree) {
               Content titleContent = getResource(
                       "doclet.Constants_Summary");
               Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
      @@ -131,10 +147,18 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
               Content div = HtmlTree.DIV(HtmlStyle.header, pHeading);
               Content headingContent = getResource(
                       "doclet.Contents");
      -        div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
      -                headingContent));
      -        div.addContent(contentListTree);
      -        return div;
      +        Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
      +                headingContent);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            HtmlTree section = HtmlTree.SECTION(heading);
      +            section.addContent(contentListTree);
      +            div.addContent(section);
      +            mainTree.addContent(div);
      +        } else {
      +            div.addContent(heading);
      +            div.addContent(contentListTree);
      +            contentTree.addContent(div);
      +        }
           }
       
           /**
      @@ -149,9 +173,11 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
           /**
            * {@inheritDoc}
            */
      -    public void addPackageName(PackageDoc pkg, String parsedPackageName,
      -            Content summariesTree) {
      +    public void addPackageName(String parsedPackageName, Content summariesTree, boolean first) {
               Content pkgNameContent;
      +        if (!first && configuration.allowTag(HtmlTag.SECTION)) {
      +            summariesTree.addContent(summaryTree);
      +        }
               if (parsedPackageName.length() == 0) {
                   summariesTree.addContent(getMarkerAnchor(
                           SectionName.UNNAMED_PACKAGE_ANCHOR));
      @@ -165,7 +191,11 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
               Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
                       pkgNameContent);
               heading.addContent(headingContent);
      -        summariesTree.addContent(heading);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            summaryTree = HtmlTree.SECTION(heading);
      +        } else {
      +            summariesTree.addContent(heading);
      +        }
           }
       
           /**
      @@ -177,6 +207,17 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
               return ul;
           }
       
      +    /**
      +     * {@inheritDoc}
      +     */
      +    public void addClassConstant(Content summariesTree, Content classConstantTree) {
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            summaryTree.addContent(classConstantTree);
      +        } else {
      +            summariesTree.addContent(classConstantTree);
      +        }
      +    }
      +
           /**
            * Get the table caption and header for the constant summary table
            *
      @@ -208,8 +249,10 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
            * @return the table caption and header
            */
           protected Content getClassName(Content classStr) {
      -        Content table = HtmlTree.TABLE(HtmlStyle.constantsSummary, 0, 3, 0, constantsTableSummary,
      -                getTableCaption(classStr));
      +        Content caption = getTableCaption(classStr);
      +        Content table = (configuration.isOutputHtml5())
      +                ? HtmlTree.TABLE(HtmlStyle.constantsSummary, caption)
      +                : HtmlTree.TABLE(HtmlStyle.constantsSummary, constantsTableSummary, caption);
               table.addContent(getSummaryTableHeader(constantsTableHeader, "col"));
               return table;
           }
      @@ -297,12 +340,33 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
               return HtmlTree.TD(HtmlStyle.colLast, code);
           }
       
      +    /**
      +     * {@inheritDoc}
      +     */
      +    public void addConstantSummaries(Content contentTree, Content summariesTree) {
      +        if (configuration.allowTag(HtmlTag.SECTION) && summaryTree != null) {
      +            summariesTree.addContent(summaryTree);
      +        }
      +        if (configuration.allowTag(HtmlTag.MAIN)) {
      +            mainTree.addContent(summariesTree);
      +            contentTree.addContent(mainTree);
      +        } else {
      +            contentTree.addContent(summariesTree);
      +        }
      +    }
      +
           /**
            * {@inheritDoc}
            */
           public void addFooter(Content contentTree) {
      -        addNavLinks(false, contentTree);
      -        addBottom(contentTree);
      +        Content htmlTree = (configuration.allowTag(HtmlTag.FOOTER))
      +                ? HtmlTree.FOOTER()
      +                : contentTree;
      +        addNavLinks(false, htmlTree);
      +        addBottom(htmlTree);
      +        if (configuration.allowTag(HtmlTag.FOOTER)) {
      +            contentTree.addContent(htmlTree);
      +        }
           }
       
           /**
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java
      index 989aaf95e44..d8d07632cd6 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1997, 2015, 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
      @@ -89,6 +89,13 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
               return memberTree;
           }
       
      +    /**
      +     * {@inheritDoc}
      +     */
      +    public void addMemberTree(Content memberSummaryTree, Content memberTree) {
      +        writer.addMemberTree(memberSummaryTree, memberTree);
      +    }
      +
           /**
            * {@inheritDoc}
            */
      @@ -177,6 +184,10 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
            * {@inheritDoc}
            */
           public Content getConstructorDetails(Content constructorDetailsTree) {
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(constructorDetailsTree));
      +            return htmlTree;
      +        }
               return getMemberTree(constructorDetailsTree);
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/DeprecatedListWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/DeprecatedListWriter.java
      index 63c81438956..85c6dc8ec59 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/DeprecatedListWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/DeprecatedListWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1997, 2015, 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,11 @@ public class DeprecatedListWriter extends SubWriterHolderWriter {
            */
           protected void generateDeprecatedListFile(DeprecatedAPIListBuilder deprapi)
                   throws IOException {
      -        Content body = getHeader();
      -        body.addContent(getContentsList(deprapi));
      +        HtmlTree body = getHeader();
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN))
      +                ? HtmlTree.MAIN()
      +                : body;
      +        htmlTree.addContent(getContentsList(deprapi));
               String memberTableSummary;
               String[] memberTableHeader = new String[1];
               HtmlTree div = new HtmlTree(HtmlTag.DIV);
      @@ -164,9 +167,20 @@ public class DeprecatedListWriter extends SubWriterHolderWriter {
                                   HEADING_KEYS[i], memberTableSummary, memberTableHeader, div);
                   }
               }
      -        body.addContent(div);
      -        addNavLinks(false, body);
      -        addBottom(body);
      +        if (configuration.allowTag(HtmlTag.MAIN)) {
      +            htmlTree.addContent(div);
      +            body.addContent(htmlTree);
      +        } else {
      +            body.addContent(div);
      +        }
      +        htmlTree = (configuration.allowTag(HtmlTag.FOOTER))
      +                ? HtmlTree.FOOTER()
      +                : body;
      +        addNavLinks(false, htmlTree);
      +        addBottom(htmlTree);
      +        if (configuration.allowTag(HtmlTag.FOOTER)) {
      +            body.addContent(htmlTree);
      +        }
               printHtmlDocument(null, true, body);
           }
       
      @@ -226,11 +240,17 @@ public class DeprecatedListWriter extends SubWriterHolderWriter {
            *
            * @return a content tree for the header
            */
      -    public Content getHeader() {
      +    public HtmlTree getHeader() {
               String title = configuration.getText("doclet.Window_Deprecated_List");
      -        Content bodyTree = getBody(true, getWindowTitle(title));
      -        addTop(bodyTree);
      -        addNavLinks(true, bodyTree);
      +        HtmlTree bodyTree = getBody(true, getWindowTitle(title));
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
      +                ? HtmlTree.HEADER()
      +                : bodyTree;
      +        addTop(htmlTree);
      +        addNavLinks(true, htmlTree);
      +        if (configuration.allowTag(HtmlTag.HEADER)) {
      +            bodyTree.addContent(htmlTree);
      +        }
               return bodyTree;
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/EnumConstantWriterImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/EnumConstantWriterImpl.java
      index 34a3a5027aa..82ac9748ba1 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/EnumConstantWriterImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/EnumConstantWriterImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2003, 2015, 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
      @@ -66,6 +66,13 @@ public class EnumConstantWriterImpl extends AbstractMemberWriter
               return memberTree;
           }
       
      +    /**
      +     * {@inheritDoc}
      +     */
      +    public void addMemberTree(Content memberSummaryTree, Content memberTree) {
      +        writer.addMemberTree(memberSummaryTree, memberTree);
      +    }
      +
           /**
            * {@inheritDoc}
            */
      @@ -140,6 +147,10 @@ public class EnumConstantWriterImpl extends AbstractMemberWriter
            * {@inheritDoc}
            */
           public Content getEnumConstantsDetails(Content enumConstantsDetailsTree) {
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(enumConstantsDetailsTree));
      +            return htmlTree;
      +        }
               return getMemberTree(enumConstantsDetailsTree);
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/FieldWriterImpl.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/FieldWriterImpl.java
      index 9ae2501efb9..7d1455bfad0 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/FieldWriterImpl.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/FieldWriterImpl.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1997, 2015, 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
      @@ -67,6 +67,13 @@ public class FieldWriterImpl extends AbstractMemberWriter
               return memberTree;
           }
       
      +    /**
      +     * {@inheritDoc}
      +     */
      +    public void addMemberTree(Content memberSummaryTree, Content memberTree) {
      +        writer.addMemberTree(memberSummaryTree, memberTree);
      +    }
      +
           /**
            * {@inheritDoc}
            */
      @@ -161,6 +168,10 @@ public class FieldWriterImpl extends AbstractMemberWriter
            * {@inheritDoc}
            */
           public Content getFieldDetails(Content fieldDetailsTree) {
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(fieldDetailsTree));
      +            return htmlTree;
      +        }
               return getMemberTree(fieldDetailsTree);
           }
       
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java
      index 706f0d7b6c7..037d7fa77eb 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java
      @@ -96,7 +96,12 @@ public class FrameOutputWriter extends HtmlDocletWriter {
           protected void generateFrameFile() throws IOException {
               Content frame = getFrameDetails();
               HtmlTree body = new HtmlTree(HtmlTag.BODY);
      -        body.addContent(frame);
      +        if (configuration.allowTag(HtmlTag.MAIN)) {
      +            HtmlTree main = HtmlTree.MAIN(frame);
      +            body.addContent(main);
      +        } else {
      +            body.addContent(frame);
      +        }
               if (configuration.windowtitle.length() > 0) {
                   printFramesDocument(configuration.windowtitle, configuration,
                           body);
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java
      index e1111faf9e9..d5b7c0f1b13 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1998, 2015, 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
      @@ -44,6 +44,8 @@ import com.sun.tools.doclets.internal.toolkit.util.*;
        */
       public class HelpWriter extends HtmlDocletWriter {
       
      +    HtmlTree mainTree = HtmlTree.MAIN();
      +
           /**
            * Constructor to construct HelpWriter object.
            * @param filename File to be generated.
      @@ -81,12 +83,24 @@ public class HelpWriter extends HtmlDocletWriter {
            */
           protected void generateHelpFile() throws IOException {
               String title = configuration.getText("doclet.Window_Help_title");
      -        Content body = getBody(true, getWindowTitle(title));
      -        addTop(body);
      -        addNavLinks(true, body);
      +        HtmlTree body = getBody(true, getWindowTitle(title));
      +        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
      +                ? HtmlTree.HEADER()
      +                : body;
      +        addTop(htmlTree);
      +        addNavLinks(true, htmlTree);
      +        if (configuration.allowTag(HtmlTag.HEADER)) {
      +            body.addContent(htmlTree);
      +        }
               addHelpFileContents(body);
      -        addNavLinks(false, body);
      -        addBottom(body);
      +        if (configuration.allowTag(HtmlTag.FOOTER)) {
      +            htmlTree = HtmlTree.FOOTER();
      +        }
      +        addNavLinks(false, htmlTree);
      +        addBottom(htmlTree);
      +        if (configuration.allowTag(HtmlTag.FOOTER)) {
      +            body.addContent(htmlTree);
      +        }
               printHtmlDocument(null, true, body);
           }
       
      @@ -105,26 +119,39 @@ public class HelpWriter extends HtmlDocletWriter {
               Content line2 = HtmlTree.DIV(HtmlStyle.subTitle,
                       getResource("doclet.Help_line_2"));
               div.addContent(line2);
      -        contentTree.addContent(div);
      +        if (configuration.allowTag(HtmlTag.MAIN)) {
      +            mainTree.addContent(div);
      +        } else {
      +            contentTree.addContent(div);
      +        }
      +        HtmlTree htmlTree;
               HtmlTree ul = new HtmlTree(HtmlTag.UL);
               ul.addStyle(HtmlStyle.blockList);
               if (configuration.createoverview) {
                   Content overviewHeading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.Overview"));
      -            Content liOverview = HtmlTree.LI(HtmlStyle.blockList, overviewHeading);
      +            htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                    ? HtmlTree.SECTION(overviewHeading)
      +                    : HtmlTree.LI(HtmlStyle.blockList, overviewHeading);
                   Content line3 = getResource("doclet.Help_line_3",
                           getHyperLink(DocPaths.OVERVIEW_SUMMARY,
                           configuration.getText("doclet.Overview")));
                   Content overviewPara = HtmlTree.P(line3);
      -            liOverview.addContent(overviewPara);
      -            ul.addContent(liOverview);
      +            htmlTree.addContent(overviewPara);
      +            if (configuration.allowTag(HtmlTag.SECTION)) {
      +                ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +            } else {
      +                ul.addContent(htmlTree);
      +            }
               }
               Content packageHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.Package"));
      -        Content liPackage = HtmlTree.LI(HtmlStyle.blockList, packageHead);
      +        htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                ? HtmlTree.SECTION(packageHead)
      +                : HtmlTree.LI(HtmlStyle.blockList, packageHead);
               Content line4 = getResource("doclet.Help_line_4");
               Content packagePara = HtmlTree.P(line4);
      -        liPackage.addContent(packagePara);
      +        htmlTree.addContent(packagePara);
               HtmlTree ulPackage = new HtmlTree(HtmlTag.UL);
               ulPackage.addContent(HtmlTree.LI(
                       getResource("doclet.Interfaces_Italic")));
      @@ -138,14 +165,20 @@ public class HelpWriter extends HtmlDocletWriter {
                       getResource("doclet.Errors")));
               ulPackage.addContent(HtmlTree.LI(
                       getResource("doclet.AnnotationTypes")));
      -        liPackage.addContent(ulPackage);
      -        ul.addContent(liPackage);
      +        htmlTree.addContent(ulPackage);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +        } else {
      +            ul.addContent(htmlTree);
      +        }
               Content classHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.Help_line_5"));
      -        Content liClass = HtmlTree.LI(HtmlStyle.blockList, classHead);
      +        htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                ? HtmlTree.SECTION(classHead)
      +                : HtmlTree.LI(HtmlStyle.blockList, classHead);
               Content line6 = getResource("doclet.Help_line_6");
               Content classPara = HtmlTree.P(line6);
      -        liClass.addContent(classPara);
      +        htmlTree.addContent(classPara);
               HtmlTree ul1 = new HtmlTree(HtmlTag.UL);
               ul1.addContent(HtmlTree.LI(
                       getResource("doclet.Help_line_7")));
      @@ -159,7 +192,7 @@ public class HelpWriter extends HtmlDocletWriter {
                       getResource("doclet.Help_line_11")));
               ul1.addContent(HtmlTree.LI(
                       getResource("doclet.Help_line_12")));
      -        liClass.addContent(ul1);
      +        htmlTree.addContent(ul1);
               HtmlTree ul2 = new HtmlTree(HtmlTag.UL);
               ul2.addContent(HtmlTree.LI(
                       getResource("doclet.Nested_Class_Summary")));
      @@ -169,7 +202,7 @@ public class HelpWriter extends HtmlDocletWriter {
                       getResource("doclet.Constructor_Summary")));
               ul2.addContent(HtmlTree.LI(
                       getResource("doclet.Method_Summary")));
      -        liClass.addContent(ul2);
      +        htmlTree.addContent(ul2);
               HtmlTree ul3 = new HtmlTree(HtmlTag.UL);
               ul3.addContent(HtmlTree.LI(
                       getResource("doclet.Field_Detail")));
      @@ -177,18 +210,24 @@ public class HelpWriter extends HtmlDocletWriter {
                       getResource("doclet.Constructor_Detail")));
               ul3.addContent(HtmlTree.LI(
                       getResource("doclet.Method_Detail")));
      -        liClass.addContent(ul3);
      +        htmlTree.addContent(ul3);
               Content line13 = getResource("doclet.Help_line_13");
               Content para = HtmlTree.P(line13);
      -        liClass.addContent(para);
      -        ul.addContent(liClass);
      +        htmlTree.addContent(para);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +        } else {
      +            ul.addContent(htmlTree);
      +        }
               //Annotation Types
               Content aHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.AnnotationType"));
      -        Content liAnnotation = HtmlTree.LI(HtmlStyle.blockList, aHead);
      +        htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                ? HtmlTree.SECTION(aHead)
      +                : HtmlTree.LI(HtmlStyle.blockList, aHead);
               Content aline1 = getResource("doclet.Help_annotation_type_line_1");
               Content aPara = HtmlTree.P(aline1);
      -        liAnnotation.addContent(aPara);
      +        htmlTree.addContent(aPara);
               HtmlTree aul = new HtmlTree(HtmlTag.UL);
               aul.addContent(HtmlTree.LI(
                       getResource("doclet.Help_annotation_type_line_2")));
      @@ -200,15 +239,21 @@ public class HelpWriter extends HtmlDocletWriter {
                       getResource("doclet.Annotation_Type_Optional_Member_Summary")));
               aul.addContent(HtmlTree.LI(
                       getResource("doclet.Annotation_Type_Member_Detail")));
      -        liAnnotation.addContent(aul);
      -        ul.addContent(liAnnotation);
      +        htmlTree.addContent(aul);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +        } else {
      +            ul.addContent(htmlTree);
      +        }
               //Enums
               Content enumHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.Enum"));
      -        Content liEnum = HtmlTree.LI(HtmlStyle.blockList, enumHead);
      +        htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                ? HtmlTree.SECTION(enumHead)
      +                : HtmlTree.LI(HtmlStyle.blockList, enumHead);
               Content eline1 = getResource("doclet.Help_enum_line_1");
               Content enumPara = HtmlTree.P(eline1);
      -        liEnum.addContent(enumPara);
      +        htmlTree.addContent(enumPara);
               HtmlTree eul = new HtmlTree(HtmlTag.UL);
               eul.addContent(HtmlTree.LI(
                       getResource("doclet.Help_enum_line_2")));
      @@ -218,46 +263,68 @@ public class HelpWriter extends HtmlDocletWriter {
                       getResource("doclet.Enum_Constant_Summary")));
               eul.addContent(HtmlTree.LI(
                       getResource("doclet.Enum_Constant_Detail")));
      -        liEnum.addContent(eul);
      -        ul.addContent(liEnum);
      +        htmlTree.addContent(eul);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +        } else {
      +            ul.addContent(htmlTree);
      +        }
               if (configuration.classuse) {
                   Content useHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                           getResource("doclet.Help_line_14"));
      -            Content liUse = HtmlTree.LI(HtmlStyle.blockList, useHead);
      +            htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                    ? HtmlTree.SECTION(useHead)
      +                    : HtmlTree.LI(HtmlStyle.blockList, useHead);
                   Content line15 = getResource("doclet.Help_line_15");
                   Content usePara = HtmlTree.P(line15);
      -            liUse.addContent(usePara);
      -            ul.addContent(liUse);
      +            htmlTree.addContent(usePara);
      +            if (configuration.allowTag(HtmlTag.SECTION)) {
      +                ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +            } else {
      +                ul.addContent(htmlTree);
      +            }
               }
               if (configuration.createtree) {
                   Content treeHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                           getResource("doclet.Help_line_16"));
      -            Content liTree = HtmlTree.LI(HtmlStyle.blockList, treeHead);
      +            htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                    ? HtmlTree.SECTION(treeHead)
      +                    : HtmlTree.LI(HtmlStyle.blockList, treeHead);
                   Content line17 = getResource("doclet.Help_line_17_with_tree_link",
                           getHyperLink(DocPaths.OVERVIEW_TREE,
                           configuration.getText("doclet.Class_Hierarchy")),
                           HtmlTree.CODE(new StringContent("java.lang.Object")));
                   Content treePara = HtmlTree.P(line17);
      -            liTree.addContent(treePara);
      +            htmlTree.addContent(treePara);
                   HtmlTree tul = new HtmlTree(HtmlTag.UL);
                   tul.addContent(HtmlTree.LI(
                           getResource("doclet.Help_line_18")));
                   tul.addContent(HtmlTree.LI(
                           getResource("doclet.Help_line_19")));
      -            liTree.addContent(tul);
      -            ul.addContent(liTree);
      +            htmlTree.addContent(tul);
      +            if (configuration.allowTag(HtmlTag.SECTION)) {
      +                ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +            } else {
      +                ul.addContent(htmlTree);
      +            }
               }
               if (!(configuration.nodeprecatedlist ||
                         configuration.nodeprecated)) {
                   Content dHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                           getResource("doclet.Deprecated_API"));
      -            Content liDeprecated = HtmlTree.LI(HtmlStyle.blockList, dHead);
      +            htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                    ? HtmlTree.SECTION(dHead)
      +                    : HtmlTree.LI(HtmlStyle.blockList, dHead);
                   Content line20 = getResource("doclet.Help_line_20_with_deprecated_api_link",
                           getHyperLink(DocPaths.DEPRECATED_LIST,
                           configuration.getText("doclet.Deprecated_API")));
                   Content dPara = HtmlTree.P(line20);
      -            liDeprecated.addContent(dPara);
      -            ul.addContent(liDeprecated);
      +            htmlTree.addContent(dPara);
      +            if (configuration.allowTag(HtmlTag.SECTION)) {
      +                ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +            } else {
      +                ul.addContent(htmlTree);
      +            }
               }
               if (configuration.createindex) {
                   Content indexlink;
      @@ -270,55 +337,96 @@ public class HelpWriter extends HtmlDocletWriter {
                   }
                   Content indexHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                           getResource("doclet.Help_line_21"));
      -            Content liIndex = HtmlTree.LI(HtmlStyle.blockList, indexHead);
      +            htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                    ? HtmlTree.SECTION(indexHead)
      +                    : HtmlTree.LI(HtmlStyle.blockList, indexHead);
                   Content line22 = getResource("doclet.Help_line_22", indexlink);
                   Content indexPara = HtmlTree.P(line22);
      -            liIndex.addContent(indexPara);
      -            ul.addContent(liIndex);
      +            htmlTree.addContent(indexPara);
      +            if (configuration.allowTag(HtmlTag.SECTION)) {
      +                ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +            } else {
      +                ul.addContent(htmlTree);
      +            }
               }
               Content prevHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.Help_line_23"));
      -        Content liPrev = HtmlTree.LI(HtmlStyle.blockList, prevHead);
      +        htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                ? HtmlTree.SECTION(prevHead)
      +                : HtmlTree.LI(HtmlStyle.blockList, prevHead);
               Content line24 = getResource("doclet.Help_line_24");
               Content prevPara = HtmlTree.P(line24);
      -        liPrev.addContent(prevPara);
      -        ul.addContent(liPrev);
      +        htmlTree.addContent(prevPara);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +        } else {
      +            ul.addContent(htmlTree);
      +        }
               Content frameHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.Help_line_25"));
      -        Content liFrame = HtmlTree.LI(HtmlStyle.blockList, frameHead);
      +        htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                ? HtmlTree.SECTION(frameHead)
      +                : HtmlTree.LI(HtmlStyle.blockList, frameHead);
               Content line26 = getResource("doclet.Help_line_26");
               Content framePara = HtmlTree.P(line26);
      -        liFrame.addContent(framePara);
      -        ul.addContent(liFrame);
      +        htmlTree.addContent(framePara);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +        } else {
      +            ul.addContent(htmlTree);
      +        }
               Content allclassesHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.All_Classes"));
      -        Content liAllClasses = HtmlTree.LI(HtmlStyle.blockList, allclassesHead);
      +        htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                ? HtmlTree.SECTION(allclassesHead)
      +                : HtmlTree.LI(HtmlStyle.blockList, allclassesHead);
               Content line27 = getResource("doclet.Help_line_27",
                       getHyperLink(DocPaths.ALLCLASSES_NOFRAME,
                       configuration.getText("doclet.All_Classes")));
               Content allclassesPara = HtmlTree.P(line27);
      -        liAllClasses.addContent(allclassesPara);
      -        ul.addContent(liAllClasses);
      +        htmlTree.addContent(allclassesPara);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +        } else {
      +            ul.addContent(htmlTree);
      +        }
               Content sHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.Serialized_Form"));
      -        Content liSerial = HtmlTree.LI(HtmlStyle.blockList, sHead);
      +        htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                ? HtmlTree.SECTION(sHead)
      +                : HtmlTree.LI(HtmlStyle.blockList, sHead);
               Content line28 = getResource("doclet.Help_line_28");
               Content serialPara = HtmlTree.P(line28);
      -        liSerial.addContent(serialPara);
      -        ul.addContent(liSerial);
      +        htmlTree.addContent(serialPara);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +        } else {
      +            ul.addContent(htmlTree);
      +        }
               Content constHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
                       getResource("doclet.Constants_Summary"));
      -        Content liConst = HtmlTree.LI(HtmlStyle.blockList, constHead);
      +        htmlTree = (configuration.allowTag(HtmlTag.SECTION))
      +                ? HtmlTree.SECTION(constHead)
      +                : HtmlTree.LI(HtmlStyle.blockList, constHead);
               Content line29 = getResource("doclet.Help_line_29",
                       getHyperLink(DocPaths.CONSTANT_VALUES,
                       configuration.getText("doclet.Constants_Summary")));
               Content constPara = HtmlTree.P(line29);
      -        liConst.addContent(constPara);
      -        ul.addContent(liConst);
      +        htmlTree.addContent(constPara);
      +        if (configuration.allowTag(HtmlTag.SECTION)) {
      +            ul.addContent(HtmlTree.LI(HtmlStyle.blockList, htmlTree));
      +        } else {
      +            ul.addContent(htmlTree);
      +        }
               Content divContent = HtmlTree.DIV(HtmlStyle.contentContainer, ul);
               Content line30 = HtmlTree.SPAN(HtmlStyle.emphasizedPhrase, getResource("doclet.Help_line_30"));
               divContent.addContent(line30);
      -        contentTree.addContent(divContent);
      +        if (configuration.allowTag(HtmlTag.MAIN)) {
      +            mainTree.addContent(divContent);
      +            contentTree.addContent(mainTree);
      +        } else {
      +            contentTree.addContent(divContent);
      +        }
           }
       
           /**
      diff --git a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
      index 0d8300b8a7b..9f1a0d5defa 100644
      --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
      +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1998, 2015, 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
      @@ -183,8 +183,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
            * @return a content tree for the script
            */
           public Content getAllClassesLinkScript(String id) {
      -        HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
      -        script.addAttr(HtmlAttr.TYPE, "text/javascript");
      +        HtmlTree script = HtmlTree.SCRIPT();
               String scriptCode = "\n"
                       + "",
                       // Bottom navbar 
                       "Skip navigation links",
      -                // Bottom navbar 
      -                "\n"
      +                // Bottom navbar 
      +                "\n"
                       + "\n"
                       + "");
       
      diff --git a/langtools/test/com/sun/javadoc/testAnchorNames/TestAnchorNames.java b/langtools/test/com/sun/javadoc/testAnchorNames/TestAnchorNames.java
      index f0c4a138e34..fcd5196e998 100644
      --- a/langtools/test/com/sun/javadoc/testAnchorNames/TestAnchorNames.java
      +++ b/langtools/test/com/sun/javadoc/testAnchorNames/TestAnchorNames.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2013, 2015, 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
      @@ -53,15 +53,15 @@ public class TestAnchorNames extends JavadocTester {
       
               // Test some section markers and links to these markers
               checkOutput("pkg1/RegClass.html", true,
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "");
       
               // Test some members and link to these members
      @@ -72,59 +72,59 @@ public class TestAnchorNames extends JavadocTester {
       
               // Test some fields
               checkOutput("pkg1/RegClass.html", true,
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "");
       
               checkOutput("pkg1/DeprMemClass.html", true,
      -                "",
      +                "",
                       "");
       
               // Test constructor
               checkOutput("pkg1/RegClass.html", true,
      -                "",
      +                "",
                       "");
       
               // Test some methods
               checkOutput("pkg1/RegClass.html", true,
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "",
      -                "",
      +                "",
                       "");
       
               checkOutput("pkg1/DeprMemClass.html", true,
      -                "",
      +                "",
                       "");
       
               // Test enum
               checkOutput("pkg1/RegClass.Te$t_Enum.html", true,
      -                "",
      +                "",
                       "");
       
               // Test nested class
               checkOutput("pkg1/RegClass._NestedClas$.html", true,
      -                "",
      +                "",
                       "");
       
               // Test class use page
      @@ -143,11 +143,11 @@ public class TestAnchorNames extends JavadocTester {
               // Test serialized form page
               checkOutput("serialized-form.html", true,
                       //This is the marker for the link that appears in the pkg1.RegClass.html page
      -                "");
      +                "");
       
               // Test member name index page
               checkOutput("index-all.html", true,
      -                "",
      +                "",
                       "$",
                       "_");
       
      diff --git a/langtools/test/com/sun/javadoc/testAnnotationOptional/TestAnnotationOptional.java b/langtools/test/com/sun/javadoc/testAnnotationOptional/TestAnnotationOptional.java
      index 18e8c93d0a5..6b723d0d9a4 100644
      --- a/langtools/test/com/sun/javadoc/testAnnotationOptional/TestAnnotationOptional.java
      +++ b/langtools/test/com/sun/javadoc/testAnnotationOptional/TestAnnotationOptional.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2009, 2015, 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
      @@ -47,6 +47,6 @@ public class TestAnnotationOptional extends JavadocTester {
               checkExit(Exit.OK);
       
               checkOutput("pkg/AnnotationOptional.html", true,
      -            "");
      +            "");
           }
       }
      diff --git a/langtools/test/com/sun/javadoc/testClassTree/TestClassTree.java b/langtools/test/com/sun/javadoc/testClassTree/TestClassTree.java
      index 22070488d77..90d6b405aea 100644
      --- a/langtools/test/com/sun/javadoc/testClassTree/TestClassTree.java
      +++ b/langtools/test/com/sun/javadoc/testClassTree/TestClassTree.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2004, 2015, 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
      @@ -50,22 +50,22 @@ public class TestClassTree extends JavadocTester {
       
               checkOutput("pkg/package-tree.html", true,
                       "
        \n" - + "
      • pkg.pkg.ParentClass", "

        Annotation Type Hierarchy

        \n" + "", "

        Enum Hierarchy

        \n" + "
          \n" - + "
        • java.lang.Object\n" + + "
        • java.lang.Object\n" + "
            \n" - + "
          • java.lang.Enum<E> (implements java.lang." + + "
          • java.lang.Enum<E> (implements java.lang." + "Comparable<T>, java.io.Serializable)\n" + "\n" + "
          • \n" @@ -74,7 +74,7 @@ public class TestClassTree extends JavadocTester { + "
          "); checkOutput("pkg/package-tree.html", false, - "
        • class pkg.class pkg.ParentClass
        • "); } } diff --git a/langtools/test/com/sun/javadoc/testConstructors/TestConstructors.java b/langtools/test/com/sun/javadoc/testConstructors/TestConstructors.java index c98501eda98..9fef963ee7f 100644 --- a/langtools/test/com/sun/javadoc/testConstructors/TestConstructors.java +++ b/langtools/test/com/sun/javadoc/testConstructors/TestConstructors.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -58,21 +58,21 @@ public class TestConstructors extends JavadocTester { + "" + "NestedInner(int)", "Outer()", - "", + "", "Outer(int i)", - ""); + ""); checkOutput("pkg1/Outer.Inner.html", true, "Inner()", - "", + "", "Inner(int i)", - ""); + ""); checkOutput("pkg1/Outer.Inner.NestedInner.html", true, "NestedInner()", - "", + "", "NestedInner(int i)", - ""); + ""); checkOutput("pkg1/Outer.Inner.html", false, "Outer.Inner--", diff --git a/langtools/test/com/sun/javadoc/testHref/TestHref.java b/langtools/test/com/sun/javadoc/testHref/TestHref.java index f5311674695..0bd8cac4feb 100644 --- a/langtools/test/com/sun/javadoc/testHref/TestHref.java +++ b/langtools/test/com/sun/javadoc/testHref/TestHref.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, 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 @@ -53,11 +53,11 @@ public class TestHref extends JavadocTester { //Member summary table link. "href=\"../pkg/C1.html#method-int-int-java.util.ArrayList-\"", //Anchor test. - "\n" + "\n" + "\n" + "", //Backward compatibility anchor test."pkg/C1.html", - "\n" + "\n" + "\n" + ""); diff --git a/langtools/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java b/langtools/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java index 32da20dfded..fa1cc7a7221 100644 --- a/langtools/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java +++ b/langtools/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -113,7 +113,7 @@ public class TestHtmlDocument extends JavadocTester { // Test another version of A tag. HtmlTree anchor = new HtmlTree(HtmlTag.A); anchor.addAttr(HtmlAttr.HREF, "testLink.html"); - anchor.addAttr(HtmlAttr.NAME, "Another version of a tag"); + anchor.addAttr(HtmlAttr.ID, "Another version of a tag"); p1.addContent(anchor); body.addContent(p1); // Test for empty tags. diff --git a/langtools/test/com/sun/javadoc/testHtmlDocument/testMarkup.html b/langtools/test/com/sun/javadoc/testHtmlDocument/testMarkup.html index 4dc92027917..63b228fc2d7 100644 --- a/langtools/test/com/sun/javadoc/testHtmlDocument/testMarkup.html +++ b/langtools/test/com/sun/javadoc/testHtmlDocument/testMarkup.html @@ -9,7 +9,7 @@

          This document is generated from sample source code and HTML files with examples of a wide variety of Java language constructs: packages, subclasses, subinterfaces, nested classes, nested interfaces,inheriting from other packages, constructors, fields,methods, and so forth. Click Here to <test> out a link.

          -

          +

          Test DD
          diff --git a/langtools/test/com/sun/javadoc/testHtmlTableStyles/TestHtmlTableStyles.java b/langtools/test/com/sun/javadoc/testHtmlTableStyles/TestHtmlTableStyles.java index de6f152d5a2..79d1e1cfb73 100644 --- a/langtools/test/com/sun/javadoc/testHtmlTableStyles/TestHtmlTableStyles.java +++ b/langtools/test/com/sun/javadoc/testHtmlTableStyles/TestHtmlTableStyles.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -48,37 +48,30 @@ public class TestHtmlTableStyles extends JavadocTester { checkOutput("pkg1/TestTable.html", true, "", - "
          ", - "
          ", - "
          "); checkOutput("pkg1/package-summary.html", true, - "
          "); checkOutput("pkg1/class-use/TestTable.html", true, - "
          "); + "
          "); checkOutput("overview-summary.html", true, - "
          "); + "
          "); checkOutput("deprecated-list.html", true, - "
          "); checkOutput("constant-values.html", true, - "
          "); } } diff --git a/langtools/test/com/sun/javadoc/testHtmlTableTags/TestHtmlTableTags.java b/langtools/test/com/sun/javadoc/testHtmlTableTags/TestHtmlTableTags.java index 13c9214e4d4..bd0ad241056 100644 --- a/langtools/test/com/sun/javadoc/testHtmlTableTags/TestHtmlTableTags.java +++ b/langtools/test/com/sun/javadoc/testHtmlTableTags/TestHtmlTableTags.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2015, 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 @@ -63,111 +63,85 @@ public class TestHtmlTableTags extends JavadocTester { void checkHtmlTableSummaries() { //Package summary checkOutput("pkg1/package-summary.html", true, - "
          ", - "
          "); checkOutput("pkg2/package-summary.html", true, - "
          ", - "
          "); // Class documentation checkOutput("pkg1/C1.html", true, - "
          ", - "
          "); checkOutput("pkg2/C2.html", true, - "
          ", - "
          "); checkOutput("pkg2/C2.ModalExclusionType.html", true, - "
          "); checkOutput("pkg2/C3.html", true, - "
          "); checkOutput("pkg2/C4.html", true, - "
          "); // Class use documentation checkOutput("pkg1/class-use/I1.html", true, - "
          "); + "
          "); checkOutput("pkg1/class-use/C1.html", true, - "
          ", - "
          "); + "
          ", + "
          "); checkOutput("pkg2/class-use/C2.html", true, - "
          ", - "
          "); + "
          ", + "
          "); checkOutput("pkg2/class-use/C2.ModalExclusionType.html", true, - "
          "); + "
          "); checkOutput("pkg2/class-use/C2.ModalExclusionType.html", true, - "
          "); + "
          "); // Package use documentation checkOutput("pkg1/package-use.html", true, - "
          ", - "
          "); + "
          ", + "
          "); checkOutput("pkg2/package-use.html", true, - "
          ", - "
          "); + "
          ", + "
          "); // Deprecated checkOutput("deprecated-list.html", true, - "
          ", - "
          "); // Constant values checkOutput("constant-values.html", true, - "
          "); // Overview Summary checkOutput("overview-summary.html", true, - "
          "); + "
          "); } /* diff --git a/langtools/test/com/sun/javadoc/testHtmlVersion/TestHtmlVersion.java b/langtools/test/com/sun/javadoc/testHtmlVersion/TestHtmlVersion.java new file mode 100644 index 00000000000..970ac00bd31 --- /dev/null +++ b/langtools/test/com/sun/javadoc/testHtmlVersion/TestHtmlVersion.java @@ -0,0 +1,2158 @@ +/* + * Copyright (c) 2015, 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. + * + * 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. + */ + +/* + * @test + * @bug 8072945 + * @summary Test the version of HTML generated by the javadoc tool. + * @author bpatel + * @library ../lib + * @build JavadocTester + * @run main TestHtmlVersion + */ + +public class TestHtmlVersion extends JavadocTester { + + public static void main(String... args) throws Exception { + TestHtmlVersion tester = new TestHtmlVersion(); + tester.runTests(); + } + + @Test + void test1() { + javadoc("-d", "out-1", "-private", "-linksource", "-html5", + "-Xprofilespath", testSrc("profile-rtjar-includes.txt"), + "-sourcepath", testSrc, + "-use", + "pkg", "pkg1", "pkg2", "pkg3"); + checkExit(Exit.OK); + + html5Output(); + html5NegatedOutput(); + } + + @Test + void test2() { + javadoc("-d", "out-2", "-private", "-linksource", "-html4", + "-Xprofilespath", testSrc("profile-rtjar-includes.txt"), + "-sourcepath", testSrc, + "-use", + "pkg", "pkg1", "pkg2", "pkg3"); + checkExit(Exit.OK); + + html4Output(); + html4NegatedOutput(); + } + + @Test + void test3() { + javadoc("-d", "out-3", "-private", "-linksource", + "-Xprofilespath", testSrc("profile-rtjar-includes.txt"), + "-sourcepath", testSrc, + "-use", + "pkg", "pkg1", "pkg2", "pkg3"); + checkExit(Exit.OK); + + html4Output(); + html4NegatedOutput(); + } + + @Test + void test4() { + javadoc("-d", "out-4", "-private", "-linksource", "-html5", + "-sourcepath", testSrc, + "-use", + "pkg3"); + checkExit(Exit.OK); + } + + void html5Output() { + // Test for overview-frame page + checkOutput("overview-frame.html", true, + "", + "\n" + + "
            \n" + + "
          • All Classes
          • ", + "
            \n" + + "

            Packages

            "); + + // Test for allclasses-frame page + checkOutput("allclasses-frame.html", true, + "", + "\n" + + "
              \n" + + "
            • "); + + // Test for allclasses-noframe page + checkOutput("allclasses-noframe.html", true, + "", + "\n" + + "
                \n" + + "
              • "); + + // Test for profile-overview-frame page + checkOutput("profile-overview-frame.html", true, + "", + "\n" + + "
                  \n" + + "
                • All Classes
                • ", + "
                  \n" + + "

                  Profiles

                  "); + + // Test for -frame page + checkOutput("compact1-frame.html", true, + "", + "\n" + + "
                    \n" + + "
                  • All Classes
                  • ", + "
                    \n" + + "

                    compact1 Packages

                    "); + + // Test for overview-summary page + checkOutput("overview-summary.html", true, + "", + "\n" + + "\n" + + "", + "
          \n" + + "
          ", + "
          \n" + + "