Skip to content

Commit 26f0cc5

Browse files
[GR-55199] Add option QueryIfNotInCAPCache.
PullRequest: graal/18251
2 parents 07d8cd1 + 1e0b8fd commit 26f0cc5

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/CAnnotationProcessor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.ArrayList;
3535
import java.util.List;
3636

37-
import com.oracle.svm.hosted.DeadlockWatchdog;
3837
import org.graalvm.nativeimage.ImageSingletons;
3938
import org.graalvm.nativeimage.Platform;
4039

@@ -43,6 +42,7 @@
4342
import com.oracle.svm.core.util.InterruptImageBuilding;
4443
import com.oracle.svm.core.util.UserError;
4544
import com.oracle.svm.core.util.VMError;
45+
import com.oracle.svm.hosted.DeadlockWatchdog;
4646
import com.oracle.svm.hosted.c.codegen.CCompilerInvoker;
4747
import com.oracle.svm.hosted.c.codegen.QueryCodeWriter;
4848
import com.oracle.svm.hosted.c.info.InfoTreeBuilder;
@@ -90,10 +90,9 @@ public NativeCodeInfo process(CAnnotationProcessorCache cache) {
9090
if (nativeLibs.getErrors().size() > 0) {
9191
return codeInfo;
9292
}
93-
if (CAnnotationProcessorCache.Options.UseCAPCache.getValue()) {
94-
/* If using a CAP cache, short cut the whole building/compile/execute query. */
95-
cache.get(nativeLibs, codeInfo);
96-
} else {
93+
94+
boolean cached = CAnnotationProcessorCache.Options.UseCAPCache.getValue() && cache.get(nativeLibs, codeInfo);
95+
if (!cached) {
9796
/*
9897
* Generate C source file (the "Query") that will produce the information needed (e.g.,
9998
* size of struct/union and offsets to their fields, value of enum/macros etc.).
@@ -120,8 +119,8 @@ public NativeCodeInfo process(CAnnotationProcessorCache cache) {
120119
return codeInfo;
121120
}
122121
}
123-
RawStructureLayoutPlanner.plan(nativeLibs, codeInfo);
124122

123+
RawStructureLayoutPlanner.plan(nativeLibs, codeInfo);
125124
SizeAndSignednessVerifier.verify(nativeLibs, codeInfo);
126125
return codeInfo;
127126
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/CAnnotationProcessorCache.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@
3939
import java.nio.file.attribute.BasicFileAttributes;
4040
import java.util.List;
4141

42-
import com.oracle.svm.core.SubstrateUtil;
4342
import org.graalvm.collections.UnmodifiableEconomicMap;
44-
import jdk.graal.compiler.options.Option;
43+
import org.graalvm.nativeimage.ImageSingletons;
44+
import org.graalvm.nativeimage.Platform;
4545

46+
import com.oracle.svm.core.SubstrateUtil;
4647
import com.oracle.svm.core.option.HostedOptionKey;
4748
import com.oracle.svm.core.option.SubstrateOptionsParser;
4849
import com.oracle.svm.core.util.UserError;
4950
import com.oracle.svm.hosted.c.info.NativeCodeInfo;
5051
import com.oracle.svm.hosted.c.query.QueryResultParser;
52+
53+
import jdk.graal.compiler.options.Option;
5154
import jdk.graal.compiler.options.OptionKey;
5255
import jdk.graal.compiler.options.OptionValues;
53-
import org.graalvm.nativeimage.ImageSingletons;
54-
import org.graalvm.nativeimage.Platform;
5556

5657
/**
5758
* Cache of pre-computed information for the {@link CAnnotationProcessor}. The cache is helpful to
@@ -103,6 +104,9 @@ public Boolean getValue(OptionValues values) {
103104
@Option(help = "Directory where information generated by the CAnnotation Processor are cached.")//
104105
public static final HostedOptionKey<String> CAPCacheDir = new HostedOptionKey<>("");
105106

107+
@Option(help = "Generate a query (i.e., C source code) if a CAP cache is used but the requested data is not found in the cache.")//
108+
public static final HostedOptionKey<Boolean> QueryIfNotInCAPCache = new HostedOptionKey<>(false);
109+
106110
@Option(help = "Exit image generation after C Annotation Processor Cache creation.")//
107111
public static final HostedOptionKey<Boolean> ExitAfterCAPCache = new HostedOptionKey<>(false);
108112

@@ -160,13 +164,17 @@ private static String toPath(NativeCodeInfo nativeCodeInfo) {
160164
return nativeCodeInfo.getName().replaceAll("\\W", "_").concat(FILE_EXTENSION);
161165
}
162166

163-
public void get(NativeLibraries nativeLibs, NativeCodeInfo nativeCodeInfo) {
167+
public boolean get(NativeLibraries nativeLibs, NativeCodeInfo nativeCodeInfo) {
164168
File file = new File(cache, toPath(nativeCodeInfo));
165169
try (FileInputStream fis = new FileInputStream(file)) {
166170
QueryResultParser.parse(nativeLibs, nativeCodeInfo, fis);
171+
return true;
167172
} catch (IOException e) {
168-
throw UserError.abort("Could not load CAPCache file. Ensure that options %s and %s are used on the same version of your application. Raw error: %s",
169-
Options.UseCAPCache.getName(), Options.NewCAPCache, e.getMessage());
173+
if (!CAnnotationProcessorCache.Options.QueryIfNotInCAPCache.getValue()) {
174+
throw UserError.abort("Could not load CAPCache file. Ensure that options %s and %s are used on the same version of your application. Raw error: %s",
175+
Options.UseCAPCache.getName(), Options.NewCAPCache, e.getMessage());
176+
}
177+
return false;
170178
}
171179
}
172180

0 commit comments

Comments
 (0)