Skip to content

Commit

Permalink
[GR-21414] Omit HostedOptionKey options from libgraal.
Browse files Browse the repository at this point in the history
PullRequest: graal/5522
  • Loading branch information
dougxc committed Feb 20, 2020
2 parents ff17497 + 6319e23 commit 0380bc4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
Expand All @@ -22,25 +22,30 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.graal.hotspot.libgraal;
package org.graalvm.compiler.options;

import org.graalvm.compiler.options.OptionDescriptors;
import java.util.Iterator;

import com.oracle.svm.hosted.NativeImageGenerator;
import org.graalvm.collections.EconomicMap;

/**
* Only a subset of {@link OptionDescriptors} available on the image class loader class path are
* applicable to libgraal. Until the {@link NativeImageGenerator} runs on a class path isolated from
* that used by the image class loader (GR-14237), we need to filter the non-applicable
* {@link OptionDescriptors}.
* A {@link OptionDescriptor} implementation that wraps an existing map from {@link String}s to
* {@link OptionDescriptor}s.
*/
public class OptionDescriptorsFilter {
public final class OptionDescriptorsMap implements OptionDescriptors {
private final EconomicMap<String, OptionDescriptor> map;

public static boolean shouldIncludeDescriptors(Class<? extends OptionDescriptors> clazz) {
if (clazz.getName().contains("SVMJUnitRunner")) {
// Avoids trying to include com/oracle/mxtool/junit/MxJUnitRequest$Builder
return false;
}
return true;
public OptionDescriptorsMap(EconomicMap<String, OptionDescriptor> map) {
this.map = map;
}

@Override
public OptionDescriptor get(String key) {
return map.get(key);
}

@Override
public Iterator<OptionDescriptor> iterator() {
return map.getValues().iterator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -76,7 +76,9 @@
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
import org.graalvm.compiler.options.OptionDescriptor;
import org.graalvm.compiler.options.OptionDescriptors;
import org.graalvm.compiler.options.OptionDescriptorsMap;
import org.graalvm.compiler.options.OptionKey;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.options.OptionsParser;
Expand Down Expand Up @@ -109,6 +111,7 @@
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
import com.oracle.svm.core.graal.snippets.NodeLoweringProvider;
import com.oracle.svm.core.jni.JNIRuntimeAccess;
import com.oracle.svm.core.option.HostedOptionKey;
import com.oracle.svm.core.option.RuntimeOptionValues;
import com.oracle.svm.core.option.XOptions;
import com.oracle.svm.core.snippets.KnownIntrinsics;
Expand Down Expand Up @@ -169,20 +172,21 @@ public void duringSetup(DuringSetupAccess access) {
ImageClassLoader imageClassLoader = ((DuringSetupAccessImpl) access).getImageClassLoader();
registerJNIConfiguration(registry, imageClassLoader);

List<OptionDescriptors> descriptors = new ArrayList<>();
EconomicMap<String, OptionDescriptor> descriptors = EconomicMap.create();
for (Class<? extends OptionDescriptors> optionsClass : imageClassLoader.findSubclasses(OptionDescriptors.class, false)) {
if (!OptionDescriptorsFilter.shouldIncludeDescriptors(optionsClass)) {
continue;
}
if (!Modifier.isAbstract(optionsClass.getModifiers())) {
if (!Modifier.isAbstract(optionsClass.getModifiers()) && !OptionDescriptorsMap.class.isAssignableFrom(optionsClass)) {
try {
descriptors.add(optionsClass.getDeclaredConstructor().newInstance());
for (OptionDescriptor d : optionsClass.getDeclaredConstructor().newInstance()) {
if (!(d.getOptionKey() instanceof HostedOptionKey)) {
descriptors.put(d.getName(), d);
}
}
} catch (ReflectiveOperationException ex) {
throw VMError.shouldNotReachHere(ex);
}
}
}
OptionsParser.setCachedOptionDescriptors(descriptors);
OptionsParser.setCachedOptionDescriptors(Collections.singletonList(new OptionDescriptorsMap(descriptors)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.graalvm.collections.EconomicSet;
import org.graalvm.compiler.options.OptionDescriptor;
import org.graalvm.compiler.options.OptionDescriptors;
import org.graalvm.compiler.options.OptionDescriptorsMap;
import org.graalvm.compiler.options.OptionKey;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.nativeimage.Platforms;
Expand All @@ -64,7 +65,7 @@ public HostedOptionParser(ImageClassLoader imageClassLoader) {
public static void collectOptions(List<Class<? extends OptionDescriptors>> optionsClasses, SortedMap<String, OptionDescriptor> allHostedOptions,
SortedMap<String, OptionDescriptor> allRuntimeOptions) {
for (Class<? extends OptionDescriptors> optionsClass : optionsClasses) {
if (Modifier.isAbstract(optionsClass.getModifiers())) {
if (Modifier.isAbstract(optionsClass.getModifiers()) || OptionDescriptorsMap.class.isAssignableFrom(optionsClass)) {
continue;
}

Expand Down

0 comments on commit 0380bc4

Please sign in to comment.