changeset 53207:b1c6d4d7f801

8215724: Epsilon: ArrayStoreExceptionTest.java fails; missing arraycopy check Reviewed-by: eosterlund, lkorinth
author shade
date Wed, 09 Jan 2019 15:53:56 +0100
parents b58517f0ea0e
children 40187283e6eb
files src/hotspot/share/gc/shared/barrierSet.hpp src/hotspot/share/gc/shared/barrierSet.inline.hpp src/hotspot/share/oops/access.inline.hpp test/hotspot/jtreg/gc/epsilon/TestArraycopyCheckcast.java
diffstat 4 files changed, 151 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shared/barrierSet.hpp	Wed Jan 09 06:18:33 2019 -0800
+++ b/src/hotspot/share/gc/shared/barrierSet.hpp	Wed Jan 09 15:53:56 2019 +0100
@@ -275,11 +275,7 @@
     template <typename T>
     static bool oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
                                       arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
-                                      size_t length) {
-      return Raw::oop_arraycopy(src_obj, src_offset_in_bytes, src_raw,
-                                dst_obj, dst_offset_in_bytes, dst_raw,
-                                length);
-    }
+                                      size_t length);
 
     // Off-heap oop accesses. These accessors get resolved when
     // IN_HEAP is not set (e.g. when using the NativeAccess API), it is
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/barrierSet.inline.hpp	Wed Jan 09 15:53:56 2019 +0100
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
+ * 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_SHARED_BARRIERSET_INLINE_HPP
+#define SHARE_VM_GC_SHARED_BARRIERSET_INLINE_HPP
+
+#include "gc/shared/barrierSet.hpp"
+#include "oops/accessDecorators.hpp"
+#include "oops/arrayOop.hpp"
+#include "oops/compressedOops.inline.hpp"
+#include "oops/objArrayOop.inline.hpp"
+#include "oops/oop.hpp"
+
+template <DecoratorSet decorators, typename BarrierSetT>
+template <typename T>
+inline bool BarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
+                                                                                      arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
+                                                                                      size_t length) {
+  T* src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
+  T* dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
+
+  if (!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
+    // Covariant, copy without checks
+    return Raw::oop_arraycopy(NULL, 0, src, NULL, 0, dst, length);
+  }
+
+  // Copy each element with checking casts
+  Klass* const dst_klass = objArrayOop(dst_obj)->element_klass();
+  for (const T* const end = src + length; src < end; src++, dst++) {
+    const T elem = *src;
+    if (!oopDesc::is_instanceof_or_null(CompressedOops::decode(elem), dst_klass)) {
+      return false;
+    }
+    *dst = elem;
+  }
+
+  return true;
+}
+
+#endif // SHARE_VM_GC_SHARED_BARRIERSET_INLINE_HPP
--- a/src/hotspot/share/oops/access.inline.hpp	Wed Jan 09 06:18:33 2019 -0800
+++ b/src/hotspot/share/oops/access.inline.hpp	Wed Jan 09 15:53:56 2019 +0100
@@ -25,6 +25,7 @@
 #ifndef SHARE_OOPS_ACCESS_INLINE_HPP
 #define SHARE_OOPS_ACCESS_INLINE_HPP
 
+#include "gc/shared/barrierSet.inline.hpp"
 #include "gc/shared/barrierSetConfig.inline.hpp"
 #include "oops/access.hpp"
 #include "oops/accessBackend.inline.hpp"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/gc/epsilon/TestArraycopyCheckcast.java	Wed Jan 09 15:53:56 2019 +0100
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
+ * 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 TestArraycopyCheckcast
+ * @key gc
+ * @requires vm.gc.Epsilon & !vm.graal.enabled
+ * @summary Epsilon is able to handle checkcasted array copies
+ * @library /test/lib
+ * @bug 8215724
+ *
+ * @run main/othervm -Xmx1g                                        -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestArraycopyCheckcast
+ * @run main/othervm -Xmx1g -Xint                                  -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestArraycopyCheckcast
+ * @run main/othervm -Xmx1g -Xbatch -Xcomp                         -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestArraycopyCheckcast
+ * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestArraycopyCheckcast
+ * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-TieredCompilation  -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestArraycopyCheckcast
+ */
+
+import java.util.Random;
+
+public class TestArraycopyCheckcast {
+
+  static int COUNT = Integer.getInteger("count", 1000);
+
+  public static void main(String[] args) throws Exception {
+    Object[] src = new Object[COUNT];
+    Object[] dst = new B[COUNT];
+
+    // Test 1. Copy nulls, should succeed
+    try {
+      System.arraycopy(src, 0, dst, 0, COUNT);
+    } catch (ArrayStoreException e) {
+      throw new IllegalStateException("Should have completed");
+    }
+
+    // Test 2. Copying incompatible type, should fail
+    for (int c = 0; c < COUNT; c++) {
+      src[c] = new A();
+    }
+
+    try {
+      System.arraycopy(src, 0, dst, 0, COUNT);
+      throw new IllegalStateException("Should have failed with ArrayStoreException");
+    } catch (ArrayStoreException e) {
+      // Expected
+    }
+
+    // Test 3. Copying compatible type, should succeeded
+    for (int c = 0; c < COUNT; c++) {
+      src[c] = new C();
+    }
+
+    try {
+      System.arraycopy(src, 0, dst, 0, COUNT);
+    } catch (ArrayStoreException e) {
+      throw new IllegalStateException("Should have completed");
+    }
+
+    for (int c = 0; c < COUNT; c++) {
+      if (src[c] != dst[c]) {
+        throw new IllegalStateException("Copy failed at index " + c);
+      }
+    }
+  }
+
+  static class A {}
+  static class B extends A {}
+  static class C extends B {}
+}