Skip to content

Commit

Permalink
[GR-9480] Dissallow ZipFile in the boot image heap.
Browse files Browse the repository at this point in the history
PullRequest: graal/1380
  • Loading branch information
cstancu committed Apr 23, 2018
2 parents 72e041b + 20faa01 commit 6fac95a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.util.AnalysisError;

import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
Expand Down Expand Up @@ -110,6 +111,11 @@ protected final void scanField(AnalysisField field, JavaConstant receiver, Objec
try {
JavaConstant fieldValue = bb.getConstantReflectionProvider().readFieldValue(field, receiver);

if (fieldValue == null) {
throw AnalysisError.shouldNotReachHere("Could not find field " + field.format("%H.%n") +
(receiver == null ? "" : " on " + bb.getSnippetReflectionProvider().asObject(Object.class, receiver).getClass()));
}

if (fieldValue.getJavaKind() == JavaKind.Object && bb.getHostVM().isRelocatedPointer(bb.getSnippetReflectionProvider().asObject(Object.class, fieldValue))) {
forRelocatedPointerFieldValue(receiver, field, fieldValue);
} else if (fieldValue.isNull()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ public String lookupUtf8(int cpi) {
public Object lookupConstant(int cpi) {
Object con = wrapped.lookupConstant(cpi);
if (con instanceof JavaType) {
return universe.lookup((ResolvedJavaType) con);
if (con instanceof ResolvedJavaType) {
return universe.lookup((ResolvedJavaType) con);
} else {
/* The caller takes care of unresolved types. */
return con;
}
} else if (con instanceof JavaConstant) {
return universe.lookup((JavaConstant) con);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,32 @@ public void duringSetup(DuringSetupAccess access) {
}

private static Object replacer(Object original) {
String message = "This is not supported. The object was reached from a static initializer. " +
"All static class initialization is done during native image construction, " +
"thus a static initializer cannot contain code that captures state dependent on the build machine. " +
"Write your own initialization methods and call them explicitly from your main entry point.";

/* Started Threads can not be in the image heap. */
if (original instanceof Thread) {
final Thread asThread = (Thread) original;
if (asThread.getState() != Thread.State.NEW) {
throw new UnsupportedFeatureException("Must not have a started Thread in the image heap.");
throw new UnsupportedFeatureException("Detected a started Thread in the image heap. " + message);
}
}
/* FileDescriptors can not be in the image heap. */
if (original instanceof FileDescriptor) {
final FileDescriptor asFileDescriptor = (FileDescriptor) original;
/* Except for a few well-known FileDescriptors. */
if (!((asFileDescriptor == FileDescriptor.in) || (asFileDescriptor == FileDescriptor.out) || (asFileDescriptor == FileDescriptor.err) || (!asFileDescriptor.valid()))) {
throw new UnsupportedFeatureException("Must not have a FileDescriptor in the image heap.");
throw new UnsupportedFeatureException("Detected a FileDescriptor in the image heap. " + message);
}
}

/* ZipFiles can not be in the image heap. */
if (original instanceof java.util.zip.ZipFile) {
throw new UnsupportedFeatureException("Detected a ZipFile object in the image heap. " + message);
}

return original;
}
}

0 comments on commit 6fac95a

Please sign in to comment.