-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic merge of master into galahad
- Loading branch information
Showing
20 changed files
with
472 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...resso.classfile/src/com/oracle/truffle/espresso/classfile/tables/AbstractModuleTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* Copyright (c) 2018, 2024, 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 com.oracle.truffle.espresso.classfile.tables; | ||
|
||
import java.util.ArrayList; | ||
import java.util.concurrent.locks.ReadWriteLock; | ||
|
||
import com.oracle.truffle.espresso.classfile.descriptors.Symbol; | ||
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name; | ||
|
||
public abstract class AbstractModuleTable<M, ME extends AbstractModuleTable.AbstractModuleEntry<M>> extends EntryTable<ME, AbstractModuleTable.ModuleData<M>> { | ||
public AbstractModuleTable(ReadWriteLock lock) { | ||
super(lock); | ||
} | ||
|
||
public ME createAndAddEntry(Symbol<Name> name, String version, String location, boolean isOpen, M module) { | ||
return createAndAddEntry(name, new ModuleData<>(version, location, module, isOpen)); | ||
} | ||
|
||
public ME createUnnamedModuleEntry(M module) { | ||
ME result = createEntry(null, new ModuleData<>(null, null, module, true)); | ||
result.setCanReadAllUnnamed(); | ||
return result; | ||
} | ||
|
||
public static final class ModuleData<M> { | ||
private final String version; | ||
private final String location; | ||
private final boolean isOpen; | ||
private final M module; | ||
|
||
public ModuleData(String version, String location, M module, boolean isOpen) { | ||
this.version = version; | ||
this.location = location; | ||
this.isOpen = isOpen; | ||
this.module = module; | ||
} | ||
} | ||
|
||
public abstract static class AbstractModuleEntry<M> extends EntryTable.NamedEntry { | ||
private final boolean isOpen; | ||
private M module; | ||
private String version; | ||
private String location; | ||
private boolean canReadAllUnnamed; | ||
private ArrayList<AbstractModuleEntry<M>> reads; | ||
|
||
protected AbstractModuleEntry(Symbol<Name> name, ModuleData<M> data) { | ||
super(name); | ||
this.version = data.version; | ||
this.location = data.location; | ||
this.isOpen = data.isOpen; | ||
this.module = data.module; | ||
} | ||
|
||
public void addReads(AbstractModuleEntry<M> from) { | ||
if (!isNamed()) { | ||
return; | ||
} | ||
synchronized (this) { | ||
if (from == null) { | ||
setCanReadAllUnnamed(); | ||
return; | ||
} | ||
if (reads == null) { | ||
reads = new ArrayList<>(); | ||
} | ||
if (!contains(from)) { | ||
reads.add(from); | ||
} | ||
} | ||
} | ||
|
||
public boolean canRead(AbstractModuleEntry<M> m, boolean mIsJavaBase) { | ||
if (!isNamed() || mIsJavaBase) { | ||
return true; | ||
} | ||
/* | ||
* Acceptable access to a type in an unnamed module. Note that since unnamed modules can | ||
* read all unnamed modules, this also handles the case where module_from is also | ||
* unnamed but in a different class loader. | ||
*/ | ||
if (!m.isNamed() && canReadAllUnnamed) { | ||
return true; | ||
} | ||
synchronized (this) { | ||
if (hasReads()) { | ||
return contains(m); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
private boolean contains(AbstractModuleEntry<M> from) { | ||
return reads.contains(from); | ||
} | ||
|
||
public void setModule(M module) { | ||
assert this.module == null; | ||
this.module = module; | ||
} | ||
|
||
public M module() { | ||
return module; | ||
} | ||
|
||
public String version() { | ||
return version; | ||
} | ||
|
||
public String location() { | ||
return location; | ||
} | ||
|
||
public void setCanReadAllUnnamed() { | ||
canReadAllUnnamed = true; | ||
} | ||
|
||
public boolean isOpen() { | ||
return isOpen; | ||
} | ||
|
||
public boolean isNamed() { | ||
return getName() != null; | ||
} | ||
|
||
public boolean hasReads() { | ||
return reads != null && !reads.isEmpty(); | ||
} | ||
|
||
public void setVersionAndLocation(String moduleVersion, String moduleLocation) { | ||
assert version == null && location == null; | ||
this.version = moduleVersion; | ||
this.location = moduleLocation; | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
...esso.classfile/src/com/oracle/truffle/espresso/classfile/tables/AbstractPackageTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2018, 2024, 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 com.oracle.truffle.espresso.classfile.tables; | ||
|
||
import java.util.ArrayList; | ||
import java.util.concurrent.locks.ReadWriteLock; | ||
|
||
import com.oracle.truffle.espresso.classfile.descriptors.Symbol; | ||
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name; | ||
|
||
public abstract class AbstractPackageTable<M, PE extends AbstractPackageTable.AbstractPackageEntry<M, ME>, ME extends AbstractModuleTable.AbstractModuleEntry<M>> extends EntryTable<PE, ME> { | ||
public AbstractPackageTable(ReadWriteLock lock) { | ||
super(lock); | ||
} | ||
|
||
public abstract static class AbstractPackageEntry<M, ME extends AbstractModuleTable.AbstractModuleEntry<M>> extends EntryTable.NamedEntry { | ||
protected AbstractPackageEntry(Symbol<Name> name, ME module) { | ||
super(name); | ||
this.module = module; | ||
} | ||
|
||
private final ME module; | ||
private ArrayList<ME> exports; | ||
private boolean isUnqualifiedExported; | ||
private boolean isExportedAllUnnamed; | ||
private String bootClasspathLocation; | ||
|
||
public void addExports(ME m) { | ||
if (isUnqualifiedExported()) { | ||
return; | ||
} | ||
synchronized (this) { | ||
if (m == null) { | ||
setUnqualifiedExports(); | ||
} | ||
if (exports == null) { | ||
exports = new ArrayList<>(); | ||
} | ||
if (!contains(m)) { | ||
exports.add(m); | ||
} | ||
} | ||
} | ||
|
||
public boolean isQualifiedExportTo(ME m) { | ||
if (isExportedAllUnnamed() && !m.isNamed()) { | ||
return true; | ||
} | ||
if (isUnqualifiedExported() || exports == null) { | ||
return false; | ||
} | ||
return contains(m); | ||
} | ||
|
||
public boolean isUnqualifiedExported() { | ||
return module().isOpen() || isUnqualifiedExported; | ||
} | ||
|
||
public void setUnqualifiedExports() { | ||
if (isUnqualifiedExported()) { | ||
return; | ||
} | ||
isUnqualifiedExported = true; | ||
isExportedAllUnnamed = true; | ||
exports = null; | ||
} | ||
|
||
public boolean isExportedAllUnnamed() { | ||
return module().isOpen() || isExportedAllUnnamed; | ||
} | ||
|
||
public void setExportedAllUnnamed() { | ||
if (isExportedAllUnnamed()) { | ||
return; | ||
} | ||
synchronized (this) { | ||
isExportedAllUnnamed = true; | ||
} | ||
} | ||
|
||
public boolean contains(ME m) { | ||
return exports.contains(m); | ||
} | ||
|
||
public ME module() { | ||
return module; | ||
} | ||
|
||
public void setBootClasspathLocation(String bootClasspathLocation) { | ||
this.bootClasspathLocation = bootClasspathLocation; | ||
} | ||
|
||
public String getBootClasspathLocation() { | ||
return bootClasspathLocation; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.