changeset 13574:a9010a9e2e11 mvt

8186715: [MVT] Value type buffering fails with "assert(c->is_valid()) failed: Sanity check"
author fparain
date Wed, 30 Aug 2017 13:25:02 -0400
parents df4d4ef05b87
children d0625b614897
files src/share/vm/memory/vtBuffer.cpp test/runtime/valhalla/valuetypes/Test8186715.java
diffstat 2 files changed, 72 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/memory/vtBuffer.cpp	Mon Aug 28 14:20:27 2017 +0100
+++ b/src/share/vm/memory/vtBuffer.cpp	Wed Aug 30 13:25:02 2017 -0400
@@ -250,13 +250,13 @@
 void dump_reloc_table(struct VT_relocation_entry* table, int nelem, bool print_new_ptr) {
   ResourceMark rm;
   for (int i = 0; i < nelem; i++) {
-	  InstanceKlass* ik = InstanceKlass::cast(((oop)table[i].old_ptr)->klass());
+          InstanceKlass* ik = InstanceKlass::cast(((oop)table[i].old_ptr)->klass());
     tty->print("%d:\t%p\t%d\t%s\t%x", i, table[i].old_ptr, table[i].chunk_index,
-    		ik->name()->as_C_string(), ik->size_helper() * HeapWordSize);
+                ik->name()->as_C_string(), ik->size_helper() * HeapWordSize);
     if (print_new_ptr) {
-    	tty->print_cr("\t%p\t%d\n", table[i].new_ptr, VTBufferChunk::chunk(table[i].new_ptr)->index());
+        tty->print_cr("\t%p\t%d\n", table[i].new_ptr, VTBufferChunk::chunk(table[i].new_ptr)->index());
     } else {
-    	tty->print_cr("");
+        tty->print_cr("");
     }
   }
 }
@@ -281,6 +281,7 @@
 oop VTBuffer::relocate_return_value(JavaThread* thread, frame current_frame, oop obj) {
   assert(!Universe::heap()->is_in_reserved(obj), "This method should never be called on Java heap allocated values");
   assert(obj->klass()->is_value(), "Sanity check");
+  if (!VTBuffer::value_belongs_to_frame(obj, &current_frame)) return obj;
   ValueKlass* vk = ValueKlass::cast(obj->klass());
   address current_ptr = (address)thread->vt_alloc_ptr();
   VTBufferChunk* current_chunk = VTBufferChunk::chunk(current_ptr);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/valhalla/valuetypes/Test8186715.java	Wed Aug 30 13:25:02 2017 -0400
@@ -0,0 +1,67 @@
+
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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 runtime.valhalla.valuetypes;
+
+/*
+ * @test Test8186715
+ * @summary test return of buffered value passed in argument by caller
+ * @library /test/lib
+ * @compile -XDenableValueTypes Test8186715.java
+ * @run main/othervm -noverify -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.Test8186715
+ * @run main/othervm -noverify -XX:+EnableValhalla runtime.valhalla.valuetypes.Test8186715
+ */
+
+public class Test8186715 {
+
+  public static void main(String[] args) {
+    MyValueType v = MyValueType.testDefault();
+
+    for (int i = 0; i < 1000000; i++)
+      MyValueType.testBranchArg1(false, v);
+  }
+}
+
+__ByValue final class MyValueType {
+  final int i;
+  final int j;
+
+  private MyValueType()
+  {
+    this.i = 0;
+    this.j = 0;
+  }
+
+  __ValueFactory static MyValueType testDefault() {
+    return __MakeDefault MyValueType();
+  }
+
+  __ValueFactory static MyValueType testBranchArg1(boolean flag, MyValueType v1) {
+    if (flag) {
+      v1.i = 3;
+      v1.j = 4;
+    }
+    return v1;
+  }
+}