27
27
import java .nio .ByteBuffer ;
28
28
import java .util .List ;
29
29
30
+ import org .graalvm .nativeimage .ImageInfo ;
30
31
import org .graalvm .word .UnsignedWord ;
31
32
32
33
import com .oracle .svm .core .SubstrateOptions ;
41
42
import com .oracle .svm .core .image .ImageHeapLayoutInfo ;
42
43
import com .oracle .svm .core .image .ImageHeapLayouter ;
43
44
import com .oracle .svm .core .image .ImageHeapObject ;
45
+ import com .oracle .svm .core .option .SubstrateOptionsParser ;
46
+ import com .oracle .svm .core .util .UserError ;
44
47
import com .oracle .svm .core .util .VMError ;
45
48
46
49
import jdk .graal .compiler .core .common .NumUtil ;
@@ -75,6 +78,8 @@ public class ChunkedImageHeapLayouter implements ImageHeapLayouter {
75
78
private static final int READ_ONLY_HUGE = WRITABLE_HUGE + 1 ;
76
79
private static final int PARTITION_COUNT = READ_ONLY_HUGE + 1 ;
77
80
81
+ private static final String ALIGNED_HEAP_CHUNK_OPTION = SubstrateOptionsParser .commandArgument (SerialAndEpsilonGCOptions .AlignedHeapChunkSize , "<2^n>" );
82
+
78
83
private final ChunkedImageHeapPartition [] partitions ;
79
84
private final ImageHeapInfo heapInfo ;
80
85
private final long startOffset ;
@@ -120,15 +125,21 @@ private ChunkedImageHeapPartition choosePartition(ImageHeapObject info, boolean
120
125
if (patched ) {
121
126
return getWritablePatched ();
122
127
} else if (immutable ) {
123
- if (hasRelocatables ) {
124
- VMError .guarantee (info .getSize () < hugeObjectThreshold , "Objects with relocatable pointers cannot be huge objects" );
125
- return getReadOnlyRelocatable ();
126
- }
127
128
if (info .getSize () >= hugeObjectThreshold ) {
128
- VMError .guarantee (info .getObjectClass () != DynamicHub .class , "Class metadata (dynamic hubs) cannot be huge objects" );
129
+ if (hasRelocatables ) {
130
+ if (info .getObjectClass () == DynamicHub .class ) {
131
+ throw reportHugeObjectError (info , "Class metadata (dynamic hubs) cannot be huge objects: the dynamic hub %s" , info .getObject ().toString ());
132
+ }
133
+ throw reportHugeObjectError (info , "Objects in image heap with relocatable pointers cannot be huge objects. Detected an object of type %s" ,
134
+ info .getObject ().getClass ().getTypeName ());
135
+ }
129
136
return getReadOnlyHuge ();
130
137
}
131
- return getReadOnlyRegular ();
138
+ if (hasRelocatables ) {
139
+ return getReadOnlyRelocatable ();
140
+ } else {
141
+ return getReadOnlyRegular ();
142
+ }
132
143
} else {
133
144
assert info .getObjectClass () != DynamicHub .class : "Class metadata (dynamic hubs) cannot be writable" ;
134
145
if (info .getSize () >= hugeObjectThreshold ) {
@@ -138,6 +149,16 @@ private ChunkedImageHeapPartition choosePartition(ImageHeapObject info, boolean
138
149
}
139
150
}
140
151
152
+ private Error reportHugeObjectError (ImageHeapObject info , String objectTypeMsg , String objectText ) {
153
+ String msg = String .format (objectTypeMsg + " with size %d B and the limit is %d B. Use '%s' to increase GC chunk size to be larger than the object." ,
154
+ objectText , info .getSize (), hugeObjectThreshold , ALIGNED_HEAP_CHUNK_OPTION );
155
+ if (ImageInfo .inImageBuildtimeCode ()) {
156
+ throw UserError .abort (msg );
157
+ } else {
158
+ throw VMError .shouldNotReachHere (msg );
159
+ }
160
+ }
161
+
141
162
@ Override
142
163
public ImageHeapLayoutInfo layout (ImageHeap imageHeap , int pageSize ) {
143
164
int objectAlignment = ConfigurationValues .getObjectLayout ().getAlignment ();
0 commit comments