# HG changeset patch # User Lukas Stadler # Date 1412000527 -7200 # Node ID c13f423bd4ed567af1352ceb3ef0f3f7a29fc41a # Parent 03826360967bc1237fd77861077fead10d1f6eea coalesce DataSection entries diff -r 03826360967b -r c13f423bd4ed graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/data/DataSection.java --- 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 externalDataList = new ArrayList<>(); + Map 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;