Mercurial > hg > graal-jvmci-8
changeset 22564:118f9560e0ea
Allow merging of DataSection, provide basic thread safety for adding Data to DataSection
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Tue, 15 Sep 2015 18:12:33 -0700 |
parents | f9a6a2f0b414 |
children | a7c7901367ed |
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 Fri Aug 28 11:23:51 2015 -0700 +++ b/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/DataSection.java Tue Sep 15 18:12:33 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; }