Skip to content

Commit

Permalink
Automatic merge of master into galahad
Browse files Browse the repository at this point in the history
  • Loading branch information
OracleLabsAutomation committed Dec 19, 2024
2 parents 71a020d + 64ddb47 commit 1997ea6
Show file tree
Hide file tree
Showing 20 changed files with 472 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ public static void ensureInitialized() {
public static final Symbol<Name> HIDDEN_INTERNAL_TYPE = StaticSymbols.putName("0HIDDEN_INTERNAL_TYPE");
public static final Symbol<Name> rawType = StaticSymbols.putName("rawType");

public static final Symbol<Name> espresso_polyglot = StaticSymbols.putName("espresso.polyglot");

// Class redefinition plugin helpers
public static final Symbol<Name> flushFromCaches = StaticSymbols.putName("flushFromCaches");
public static final Symbol<Name> generateProxyClass = StaticSymbols.putName("generateProxyClass");
Expand Down
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;
}
}
}
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.espresso.classfile.tables;

package com.oracle.truffle.espresso.impl;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Objects;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.function.Consumer;

import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
Expand All @@ -45,9 +43,16 @@ protected EntryTable(ReadWriteLock lock) {
}

@SuppressWarnings("try")
public Collection<T> values() {
public void collectValues(Consumer<T> consumer) {
try (BlockLock block = read()) {
entries.values().forEach(consumer);
}
}

@SuppressWarnings({"try", "unchecked", "rawtypes"})
public Symbol<Name>[] getKeys() {
try (BlockLock block = read()) {
return Collections.unmodifiableCollection(entries.values());
return entries.keySet().toArray(new Symbol[entries.size()]);
}
}

Expand Down Expand Up @@ -88,27 +93,27 @@ protected NamedEntry(Symbol<Name> name) {

protected final Symbol<Name> name;

public Symbol<Name> getName() {
public final Symbol<Name> getName() {
return name;
}

public String getNameAsString() {
public final String getNameAsString() {
if (name == null) {
return "unnamed";
}
return name.toString();
}

@Override
public int hashCode() {
public final int hashCode() {
if (name == null) {
return 0;
}
return name.hashCode();
}

@Override
public boolean equals(Object obj) {
public final boolean equals(Object obj) {
if (obj instanceof NamedEntry) {
return Objects.equals(((NamedEntry) obj).getName(), this.getName());
}
Expand Down
Loading

0 comments on commit 1997ea6

Please sign in to comment.