changeset 17249:c13f423bd4ed

coalesce DataSection entries
author Lukas Stadler <lukas.stadler@oracle.com>
date Mon, 29 Sep 2014 16:22:07 +0200
parents 03826360967b
children 9f001294893d
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/data/DataSection.java
diffstat 1 files changed, 29 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/data/DataSection.java	Mon Sep 29 14:14:01 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/data/DataSection.java	Mon Sep 29 16:22:07 2014 +0200
@@ -56,6 +56,8 @@
         int patchCount = 0;
         List<DataPatch> externalDataList = new ArrayList<>();
 
+        Map<Data, Integer> dataMap = new HashMap<>();
+
         // find all external data items and determine total size of data section
         for (Site site : sites) {
             if (site instanceof DataPatch) {
@@ -64,12 +66,16 @@
                 if (dataPatch.inline) {
                     assert d instanceof PatchedData : "unnecessary data patch";
                 } else {
-                    size = NumUtil.roundUp(size, d.getAlignment());
-                    size += d.getSize(target);
+                    Integer existingPos = dataMap.get(d);
+                    if (existingPos == null) {
+                        size = NumUtil.roundUp(size, d.getAlignment());
+                        size += d.getSize(target);
+                        if (d instanceof PatchedData) {
+                            patchCount++;
+                        }
+                        dataMap.put(d, externalDataList.size());
+                    }
                     externalDataList.add(dataPatch);
-                    if (d instanceof PatchedData) {
-                        patchCount++;
-                    }
                 }
             }
         }
@@ -82,23 +88,29 @@
         int alignment = 0;
 
         // build data section
-        for (DataPatch dataPatch : externalDataList) {
+        for (int i = 0; i < externalDataList.size(); i++) {
+            DataPatch dataPatch = externalDataList.get(i);
             assert !dataPatch.inline;
             Data d = dataPatch.data;
 
-            alignment = Math.max(alignment, d.getAlignment());
-            index = NumUtil.roundUp(index, d.getAlignment());
-            buffer.position(index);
+            Integer existingPos = dataMap.get(d);
+            if (existingPos == i) {
+                alignment = Math.max(alignment, d.getAlignment());
+                index = NumUtil.roundUp(index, d.getAlignment());
+                buffer.position(index);
 
-            DataSectionReference reference = new DataSectionReference(index);
-            if (d instanceof PatchedData) {
-                // record patch location
-                patches[patchIndex++] = new DataPatch(index, d, true);
+                DataSectionReference reference = new DataSectionReference(index);
+                if (d instanceof PatchedData) {
+                    // record patch location
+                    patches[patchIndex++] = new DataPatch(index, d, true);
+                }
+                dataPatch.data = reference;
+
+                index += d.getSize(target);
+                d.emit(target, buffer);
+            } else {
+                dataPatch.data = externalDataList.get(existingPos).data;
             }
-            dataPatch.data = reference;
-
-            index += d.getSize(target);
-            d.emit(target, buffer);
         }
 
         this.sectionAlignment = alignment;