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 ;
@@ -120,14 +123,19 @@ private ChunkedImageHeapPartition choosePartition(ImageHeapObject info, boolean
120
123
if (patched ) {
121
124
return getWritablePatched ();
122
125
} 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
126
if (info .getSize () >= hugeObjectThreshold ) {
128
- VMError .guarantee (info .getObjectClass () != DynamicHub .class , "Class metadata (dynamic hubs) cannot be huge objects" );
127
+ if (info .getObjectClass () == DynamicHub .class ) {
128
+ throw reportHugeObjectError (info , "Class metadata (dynamic hubs) cannot be huge objects. The dynamic hub %s" , info .getObject ().toString ());
129
+ }
130
+ if (hasRelocatables ) {
131
+ throw reportHugeObjectError (info , "Objects in image heap with relocatable pointers cannot be huge objects. Detected an object of type %s" ,
132
+ info .getObject ().getClass ().getTypeName ());
133
+ }
129
134
return getReadOnlyHuge ();
130
135
}
136
+ if (hasRelocatables ) {
137
+ return getReadOnlyRelocatable ();
138
+ }
131
139
return getReadOnlyRegular ();
132
140
} else {
133
141
assert info .getObjectClass () != DynamicHub .class : "Class metadata (dynamic hubs) cannot be writable" ;
@@ -138,6 +146,26 @@ private ChunkedImageHeapPartition choosePartition(ImageHeapObject info, boolean
138
146
}
139
147
}
140
148
149
+ private Error reportHugeObjectError (ImageHeapObject info , String objectTypeMsg , String objectText ) {
150
+ String msg = String .format (
151
+ objectTypeMsg + " with size %d B and the limit is %d B. Use '%s' to increase GC chunk size to be larger than the object." ,
152
+ objectText , info .getSize (), hugeObjectThreshold ,
153
+ SubstrateOptionsParser .commandArgument (SerialAndEpsilonGCOptions .AlignedHeapChunkSize , "<2^n>" ));
154
+ if (ImageInfo .inImageBuildtimeCode ()) {
155
+ throw UserError .abort (msg );
156
+ } else {
157
+ throw VMError .shouldNotReachHere (msg );
158
+ }
159
+ }
160
+
161
+ private static void reportError (String msg ) {
162
+ if (ImageInfo .inImageBuildtimeCode ()) {
163
+ UserError .abort (msg );
164
+ } else {
165
+ VMError .shouldNotReachHere (msg );
166
+ }
167
+ }
168
+
141
169
@ Override
142
170
public ImageHeapLayoutInfo layout (ImageHeap imageHeap , int pageSize ) {
143
171
int objectAlignment = ConfigurationValues .getObjectLayout ().getAlignment ();
0 commit comments