changeset 22565:a7c7901367ed

Merge
author Christian Wimmer <christian.wimmer@oracle.com>
date Tue, 15 Sep 2015 18:13:11 -0700
parents c345ad3a1cbb (current diff) 118f9560e0ea (diff)
children 94a604f431d3
files jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/DataSection.java
diffstat 1 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/DataSection.java	Wed Sep 16 01:04:47 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/DataSection.java	Tue Sep 15 18:13:11 2015 -0700
@@ -176,11 +176,27 @@
      */
     public DataSectionReference insertData(Data data) {
         assert !finalLayout;
-        if (data.ref == null) {
-            data.ref = new DataSectionReference();
+        synchronized (data) {
+            if (data.ref == null) {
+                data.ref = new DataSectionReference();
+                dataItems.add(data);
+            }
+            return data.ref;
+        }
+    }
+
+    /**
+     * Transfers all {@link Data} from the provided other {@link DataSection} to this
+     * {@link DataSection}, and empties the other section.
+     */
+    public void addAll(DataSection other) {
+        assert !finalLayout && !other.finalLayout;
+
+        for (Data data : other.dataItems) {
+            assert data.ref != null;
             dataItems.add(data);
         }
-        return data.ref;
+        other.dataItems.clear();
     }
 
     /**
@@ -195,14 +211,16 @@
         dataItems.sort((a, b) -> a.alignment - b.alignment);
 
         int position = 0;
+        int alignment = 1;
         for (Data d : dataItems) {
-            sectionAlignment = lcm(sectionAlignment, d.alignment);
+            alignment = lcm(alignment, d.alignment);
             position = align(position, d.alignment);
 
             d.ref.setOffset(position);
             position += d.size;
         }
 
+        sectionAlignment = alignment;
         sectionSize = position;
     }