Merge JDK-8200758-branch
authorherrick
Thu, 25 Jul 2019 15:47:00 -0400
branchJDK-8200758-branch
changeset 57552 abd51a0c612c
parent 57532 eb0bd96672f4 (current diff)
parent 57536 67cce1b84a9a (diff)
child 57553 96335b232d4d
Merge
--- a/src/hotspot/share/gc/shenandoah/shenandoahClosures.hpp	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/shenandoahClosures.hpp	Thu Jul 25 15:47:00 2019 -0400
@@ -79,6 +79,16 @@
   inline void do_oop_work(T* p);
 };
 
+class ShenandoahEvacUpdateOopStorageRootsClosure : public BasicOopIterateClosure {
+private:
+  ShenandoahHeap* _heap;
+  Thread* _thread;
+public:
+  inline ShenandoahEvacUpdateOopStorageRootsClosure();
+  inline void do_oop(oop* p);
+  inline void do_oop(narrowOop* p);
+};
+
 #ifdef ASSERT
 class ShenandoahAssertNotForwardedClosure : public OopClosure {
 private:
--- a/src/hotspot/share/gc/shenandoah/shenandoahClosures.inline.hpp	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/shenandoahClosures.inline.hpp	Thu Jul 25 15:47:00 2019 -0400
@@ -107,6 +107,31 @@
   do_oop_work(p);
 }
 
+ShenandoahEvacUpdateOopStorageRootsClosure::ShenandoahEvacUpdateOopStorageRootsClosure() :
+  _heap(ShenandoahHeap::heap()), _thread(Thread::current()) {
+}
+
+void ShenandoahEvacUpdateOopStorageRootsClosure::do_oop(oop* p) {
+  assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress");
+
+  oop obj = RawAccess<>::oop_load(p);
+  if (! CompressedOops::is_null(obj)) {
+    if (_heap->in_collection_set(obj)) {
+      shenandoah_assert_marked(p, obj);
+      oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
+      if (oopDesc::equals_raw(resolved, obj)) {
+        resolved = _heap->evacuate_object(obj, _thread);
+      }
+
+      Atomic::cmpxchg(resolved, p, obj);
+    }
+  }
+}
+
+void ShenandoahEvacUpdateOopStorageRootsClosure::do_oop(narrowOop* p) {
+  ShouldNotReachHere();
+}
+
 #ifdef ASSERT
 template <class T>
 void ShenandoahAssertNotForwardedClosure::do_oop_work(T* p) {
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Thu Jul 25 15:47:00 2019 -0400
@@ -1593,12 +1593,19 @@
 
   void work(uint worker_id) {
     ShenandoahEvacOOMScope oom;
-    ShenandoahEvacuateUpdateRootsClosure cl;
-    CLDToOopClosure clds(&cl, ClassLoaderData::_claim_strong);
-
-    _jni_roots.oops_do<ShenandoahEvacuateUpdateRootsClosure>(&cl);
-    _cld_roots.cld_do(&clds);
-    _weak_roots.oops_do<ShenandoahEvacuateUpdateRootsClosure>(&cl);
+    {
+      // jni_roots and weak_roots are OopStorage backed roots, concurrent iteration
+      // may race against OopStorage::release() calls.
+      ShenandoahEvacUpdateOopStorageRootsClosure cl;
+      _jni_roots.oops_do<ShenandoahEvacUpdateOopStorageRootsClosure>(&cl);
+      _weak_roots.oops_do<ShenandoahEvacUpdateOopStorageRootsClosure>(&cl);
+    }
+
+    {
+      ShenandoahEvacuateUpdateRootsClosure cl;
+      CLDToOopClosure clds(&cl, ClassLoaderData::_claim_strong);
+      _cld_roots.cld_do(&clds);
+    }
   }
 };
 
--- a/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/SubSystem.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/SubSystem.java	Thu Jul 25 15:47:00 2019 -0400
@@ -132,7 +132,7 @@
             retval = Long.parseLong(strval);
         } catch (NumberFormatException e) {
             // For some properties (e.g. memory.limit_in_bytes) we may overflow the range of signed long.
-            // In this case, return Long.max
+            // In this case, return Long.MAX_VALUE
             BigInteger b = new BigInteger(strval);
             if (b.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
                 return Long.MAX_VALUE;
--- a/src/java.base/macosx/native/libjava/java_props_macosx.c	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/java.base/macosx/native/libjava/java_props_macosx.c	Thu Jul 25 15:47:00 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
  * 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,18 +91,22 @@
 
             if (hyphenPos == NULL || // languageString contains ISO639 only, e.g., "en"
                 languageString + langStrLen - hyphenPos == 5) { // ISO639-ScriptCode, e.g., "en-Latn"
-                CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
-                               localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding());
-                char *underscorePos = strrchr(localeString, '_');
-                char *region = NULL;
+                CFLocaleRef cflocale = CFLocaleCopyCurrent();
+                if (cflocale != NULL) {
+                    CFStringGetCString(CFLocaleGetIdentifier(cflocale),
+                                   localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding());
+                    char *underscorePos = strrchr(localeString, '_');
+                    char *region = NULL;
 
-                if (underscorePos != NULL) {
-                    region = underscorePos + 1;
-                }
+                    if (underscorePos != NULL) {
+                        region = underscorePos + 1;
+                    }
 
-                if (region != NULL) {
-                    strcat(languageString, "-");
-                    strcat(languageString, region);
+                    if (region != NULL) {
+                        strcat(languageString, "-");
+                        strcat(languageString, region);
+                    }
+                    CFRelease(cflocale);
                 }
             }
 
@@ -112,12 +116,19 @@
 
     default:
         {
-            if (!CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
-                                    localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
+            CFLocaleRef cflocale = CFLocaleCopyCurrent();
+            if (cflocale != NULL) {
+                if (!CFStringGetCString(CFLocaleGetIdentifier(cflocale),
+                                        localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
+                    CFRelease(cflocale);
+                    return NULL;
+                }
+
+                retVal = localeString;
+                CFRelease(cflocale);
+            } else {
                 return NULL;
             }
-
-            retVal = localeString;
         }
         break;
     }
--- a/src/java.base/windows/classes/sun/nio/ch/Iocp.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/java.base/windows/classes/sun/nio/ch/Iocp.java	Thu Jul 25 15:47:00 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -317,7 +317,7 @@
                         myGroupAndInvokeCount.resetInvokeCount();
 
                     // wait for I/O completion event
-                    // A error here is fatal (thread will not be replaced)
+                    // An error here is fatal (thread will not be replaced)
                     replaceMe = false;
                     try {
                         getQueuedCompletionStatus(port, ioResult);
--- a/src/java.base/windows/classes/sun/nio/ch/PendingIoCache.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/java.base/windows/classes/sun/nio/ch/PendingIoCache.java	Thu Jul 25 15:47:00 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -143,7 +143,6 @@
         // simulate the failure of all pending I/O operations.
         for (Long ov: pendingIoMap.keySet()) {
             PendingFuture<?,?> result = pendingIoMap.get(ov);
-            assert !result.isDone();
 
             // make I/O port aware of the stale OVERLAPPED structure
             Iocp iocp = (Iocp)((Groupable)result.channel()).group();
--- a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java	Thu Jul 25 15:47:00 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -228,7 +228,6 @@
         @Override
         public void run() {
             long overlapped = 0L;
-            boolean pending = false;
             try {
                 begin();
 
@@ -242,7 +241,6 @@
                                      overlapped);
                     if (n == IOStatus.UNAVAILABLE) {
                         // I/O is pending
-                        pending = true;
                         return;
                     }
                     // acquired lock immediately
@@ -253,9 +251,9 @@
                 // lock failed or channel closed
                 removeFromFileLockTable(fli);
                 result.setFailure(toIOException(x));
+                if (overlapped != 0L)
+                    ioCache.remove(overlapped);
             } finally {
-                if (!pending && overlapped != 0L)
-                    ioCache.remove(overlapped);
                 end();
             }
 
@@ -448,13 +446,12 @@
             } catch (Throwable x) {
                 // failed to initiate read
                 result.setFailure(toIOException(x));
+                if (overlapped != 0L)
+                    ioCache.remove(overlapped);
             } finally {
-                if (!pending) {
+                if (!pending)
                     // release resources
-                    if (overlapped != 0L)
-                        ioCache.remove(overlapped);
                     releaseBufferIfSubstituted();
-                }
                 end();
             }
 
@@ -628,9 +625,9 @@
                 result.setFailure(toIOException(x));
 
                 // release resources
+                releaseBufferIfSubstituted();
                 if (overlapped != 0L)
                     ioCache.remove(overlapped);
-                releaseBufferIfSubstituted();
 
             } finally {
                 end();
--- a/src/java.base/windows/native/libnio/ch/WindowsAsynchronousFileChannelImpl.c	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/java.base/windows/native/libnio/ch/WindowsAsynchronousFileChannelImpl.c	Thu Jul 25 15:47:00 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -115,7 +115,7 @@
         if (error == ERROR_IO_PENDING) {
             return IOS_UNAVAILABLE;
         }
-        JNU_ThrowIOExceptionWithLastError(env, "WriteFile failed");
+        JNU_ThrowIOExceptionWithLastError(env, "LockFile failed");
         return IOS_THROWN;
     }
     return 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/nio/channels/AsynchronousFileChannel/LockReadWriteStressTest.java	Thu Jul 25 15:47:00 2019 -0400
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * 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 8184157
+ * @summary Ensure that correct PendingFuture is used in Iocp completion status event handler
+ * @requires (os.family == "windows")
+ */
+
+import java.nio.ByteBuffer;
+import java.nio.channels.AsynchronousFileChannel;
+import java.nio.channels.FileLock;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static java.nio.file.StandardOpenOption.*;
+
+public class LockReadWriteStressTest {
+    public static void main(String[] args) throws Exception {
+        Path path = Path.of("blah");
+        ByteBuffer buf = ByteBuffer.allocate(16);
+        for (int i=0; i < 1000; i++) {
+            try (AsynchronousFileChannel ch = AsynchronousFileChannel.open(path,READ, WRITE, CREATE)) {
+                FileLock lock = ch.lock().get();
+                ch.read(buf, 0).get();
+                buf.rewind();
+                ch.write(buf, 0).get();
+                lock.release();
+                buf.clear();
+            }
+        }
+    }
+}
--- a/test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java	Thu Jul 25 15:47:00 2019 -0400
@@ -26,6 +26,7 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.math.BigInteger;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -157,7 +158,24 @@
 
     private static long getLongValueFromFile(SubSystem subSystem, String fileName) {
         String data = getFileContents(subSystem, fileName);
-        return data.isEmpty() ? 0L : Long.parseLong(data);
+        return data.isEmpty() ? 0L : convertStringToLong(data);
+    }
+
+    private static long convertStringToLong(String strval) {
+        long retval = 0;
+        if (strval == null) return 0L;
+
+        try {
+            retval = Long.parseLong(strval);
+        } catch (NumberFormatException e) {
+            // For some properties (e.g. memory.limit_in_bytes) we may overflow the range of signed long.
+            // In this case, return Long.MAX_VALUE
+            BigInteger b = new BigInteger(strval);
+            if (b.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
+                return Long.MAX_VALUE;
+            }
+        }
+        return retval;
     }
 
     private static long getLongValueFromFile(SubSystem subSystem, String metric, String subMetric) {
@@ -165,7 +183,8 @@
         String[] tokens = stats.split("[\\r\\n]+");
         for (int i = 0; i < tokens.length; i++) {
             if (tokens[i].startsWith(subMetric)) {
-                return Long.parseLong(tokens[i].split("\\s+")[1]);
+                String strval = tokens[i].split("\\s+")[1];
+                return convertStringToLong(strval);
             }
         }
         return 0L;