-
Notifications
You must be signed in to change notification settings - Fork 722
/
mminit.cpp
3557 lines (3144 loc) · 135 KB
/
mminit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright IBM Corp. and others 1991
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
/**
* @file
* @ingroup GC_Modron_Startup
*/
#if defined (J9VM_GC_VLHGC)
#include <math.h>
#endif /* J9VM_GC_VLHGC */
#include <string.h>
#include "gcmspace.h"
#include "gcutils.h"
#include "j2sever.h"
#include "j9.h"
#include "j9cfg.h"
#include "j9comp.h"
#include "j9consts.h"
#include "j9modron.h"
#include "j9port.h"
#include "j9protos.h"
#include "jni.h"
#include "jvminit.h"
#include "mminit.h"
#include "mminitcore.h"
#include "mmparse.h"
#include "modronnls.h"
#include "omr.h"
#if defined(J9VM_GC_MODRON_TRACE) && !defined(J9VM_GC_REALTIME)
#include "Tgc.hpp"
#endif /* J9VM_GC_MODRON_TRACE && !defined(J9VM_GC_REALTIME) */
#if defined (J9VM_GC_HEAP_CARD_TABLE)
#include "CardTable.hpp"
#endif /* defined (J9VM_GC_HEAP_CARD_TABLE) */
#include "CollectorLanguageInterfaceImpl.hpp"
#if defined(OMR_GC_MODRON_CONCURRENT_MARK)
#include "ConcurrentCardTable.hpp"
#include "ConcurrentGC.hpp"
#endif /* OMR_GC_MODRON_CONCURRENT_MARK */
#include "Configuration.hpp"
#if defined(J9VM_GC_MODRON_STANDARD)
#include "ConfigurationFlat.hpp"
#include "ConfigurationGenerational.hpp"
#endif /* J9VM_GC_MODRON_STANDARD */
#if defined(J9VM_GC_VLHGC)
#include "ConfigurationIncrementalGenerational.hpp"
#endif /* J9VM_GC_VLHGC */
#if defined(J9VM_GC_REALTIME)
#include "ConfigurationRealtime.hpp"
#endif /* J9VM_GC_REALTIME */
#include "ClassLoaderManager.hpp"
#include "Debug.hpp"
#include "EnvironmentBase.hpp"
#if defined(J9VM_GC_FINALIZATION)
#include "FinalizeListManager.hpp"
#endif /* J9VM_GC_FINALIZATION */
#include "GCExtensions.hpp"
#include "GlobalAllocationManager.hpp"
#include "GlobalCollector.hpp"
#include "HeapRegionDescriptor.hpp"
#include "HeapRegionManager.hpp"
#include "LargeObjectAllocateStats.hpp"
#include "Math.hpp"
#include "MemorySpace.hpp"
#include "MemorySubSpace.hpp"
#include "ModronAssertions.h"
#include "ObjectAccessBarrier.hpp"
#include "ObjectAllocationInterface.hpp"
#include "OMRVMInterface.hpp"
#include "OMRVMThreadInterface.hpp"
#include "ParallelDispatcher.hpp"
#if defined(J9VM_GC_VLHGC)
#include "RememberedSetCardList.hpp"
#endif /* J9VM_GC_VLHGC */
#if defined(J9VM_GC_SEGRGATED_HEAP)
#include "ObjectHeapIteratorSegregated.hpp"
#include "SizeClasses.hpp"
#endif /* J9VM_GC_SEGRGATED_HEAP */
#if defined(J9VM_GC_REALTIME)
#include "RememberedSetSATB.hpp"
#endif /* J9VM_GC_REALTIME */
#include "Scavenger.hpp"
#include "StringTable.hpp"
#include "Validator.hpp"
#if defined(OMR_GC_IDLE_HEAP_MANAGER)
#include "IdleGCManager.hpp"
#endif
/**
* If we fail to allocate heap structures with the default Xmx value,
* we will try again with a smaller value. These parameters define
* the percentage by which to reduce the Xmx value.
*/
#define DEFAULT_XMX_REDUCTION_NUMERATOR 4
#define DEFAULT_XMX_REDUCTION_DENOMINATOR 5
#define NONE ((UDATA) 0x0)
#define XMS ((UDATA) 0x1)
#define XMOS ((UDATA) 0x2)
#define XMNS ((UDATA) 0x4)
#define XMDX ((UDATA) 0x8)
#define XMS_XMOS ((UDATA) XMS | XMOS)
#define XMOS_XMNS ((UDATA) XMOS | XMNS)
#define XMDX_XMS ((UDATA) XMDX | XMS)
#define ROUND_TO(granularity, number) (((UDATA)(number) + (granularity) - 1) & ~((UDATA)(granularity) - 1))
extern "C" {
extern J9MemoryManagerFunctions MemoryManagerFunctions;
extern void initializeVerboseFunctionTableWithDummies(J9MemoryManagerVerboseInterface *table);
static void hookValidatorVMThreadCrash(J9HookInterface * * hookInterface, UDATA eventNum, void * eventData, void * userData);
static bool gcInitializeVMHooks(MM_GCExtensionsBase *extensions);
static void gcCleanupVMHooks(MM_GCExtensionsBase *extensions);
static const char * displayXmxOrMaxRAMPercentage(IDATA* memoryParameters);
static const char * displayXmsOrInitialRAMPercentage(IDATA* memoryParameters);
/**
* Initialize the threads mutator information (RS pointers, reference list pointers etc) for GC/MM purposes.
*
* @note vmThread MAY NOT be initialized completely from an execution model perspective.
* @return 0 if OK, or non 0 if error
*/
IDATA
initializeMutatorModelJava(J9VMThread* vmThread)
{
if (0 != initializeMutatorModel(vmThread->omrVMThread)) {
return -1;
}
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(vmThread);
vmThread->gcExtensions = vmThread->omrVMThread->_gcOmrVMThreadExtensions;
if (extensions->isStandardGC()) {
if (extensions->isConcurrentScavengerEnabled()) {
/* Ensure that newly created threads invoke VM access using slow path, so that the associated hook is invoked.
* GC will register to the hook to enable local thread resources if a thread happens to be created in a middle of Concurrent Scavenge */
setEventFlag(vmThread, J9_PUBLIC_FLAGS_DISABLE_INLINE_VM_ACCESS);
}
#if defined(J9VM_GC_GENERATIONAL)
vmThread->gcRememberedSet.fragmentCurrent = NULL;
vmThread->gcRememberedSet.fragmentTop = NULL;
vmThread->gcRememberedSet.fragmentSize = OMR_SCV_REMSET_FRAGMENT_SIZE;
#endif /* J9VM_GC_GENERATIONAL */
void *lowAddress = extensions->heapBaseForBarrierRange0;
void *highAddress = (void *)((UDATA)extensions->heapBaseForBarrierRange0 + extensions->heapSizeForBarrierRange0);
// todo: dagar lowTenureAddress, highTenureAddress, heapBaseForBarrierRange0, heapSizeForBarrierRange0 are duplicated
vmThread->lowTenureAddress = lowAddress;
vmThread->highTenureAddress = highAddress;
/* replacement values for lowTenureAddress and highTenureAddress */
// todo: dagar remove duplicate fields
vmThread->heapBaseForBarrierRange0 = extensions->heapBaseForBarrierRange0;
vmThread->heapSizeForBarrierRange0 = extensions->heapSizeForBarrierRange0;
#if defined (J9VM_GC_HEAP_CARD_TABLE)
if (NULL != extensions->cardTable) {
vmThread->activeCardTableBase = extensions->cardTable->getCardTableStart();
}
#endif /* J9VM_GC_HEAP_CARD_TABLE */
} else if(extensions->isVLHGC()) {
MM_Heap *heap = extensions->getHeap();
void *heapBase = heap->getHeapBase();
void *heapTop = heap->getHeapTop();
/* replacement values for lowTenureAddress and highTenureAddress */
vmThread->heapBaseForBarrierRange0 = heapBase;
vmThread->heapSizeForBarrierRange0 = (UDATA)heapTop - (UDATA)heapBase;
/* lowTenureAddress and highTenureAddress are actually supposed to be the low and high addresses of the heap for which card
* dirtying is required (the JIT uses this as a range check to determine if it needs to dirty a card when writing into an
* object). Setting these for Tarok is just a work-around until a more generic solution is implemented
*/
vmThread->lowTenureAddress = heapBase;
vmThread->highTenureAddress = heapTop;
#if defined (J9VM_GC_HEAP_CARD_TABLE)
vmThread->activeCardTableBase = extensions->cardTable->getCardTableStart();
#endif /* J9VM_GC_HEAP_CARD_TABLE */
}
return 0;
}
/**
* Cleanup Mutator specific resources (TLH, thread extension, etc) on shutdown.
*/
void
cleanupMutatorModelJava(J9VMThread* vmThread)
{
MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(vmThread->omrVMThread);
if (NULL != env) {
J9JavaVM *vm = vmThread->javaVM;
J9VMDllLoadInfo *loadInfo = getGCDllLoadInfo(vm);
/* cleanupMutatorModelJava is called as part of the main vmThread shutdown, which happens after
* gcCleanupHeapStructures has been called. We should therefore only flush allocation caches
* if there is still a heap.
*/
if (!IS_STAGE_COMPLETED(loadInfo->completedBits, HEAP_STRUCTURES_FREED)) {
/* this can only be called if the heap still exists since it will ask the TLH chunk to be abandoned with crashes if the heap is deallocated */
GC_OMRVMThreadInterface::flushCachesForGC(env);
}
}
cleanupMutatorModel(vmThread->omrVMThread, 0);
vmThread->gcExtensions = NULL;
}
/**
* Triggers hook for deleting private heap.
* @param memorySpace pointer to the list (pool) of memory spaces
*/
static void
reportPrivateHeapDelete(J9JavaVM * javaVM, void * memorySpace)
{
MM_EnvironmentBase env(javaVM->omrVM);
MM_MemorySpace *modronMemorySpace = (MM_MemorySpace *)memorySpace;
if (modronMemorySpace) {
if (!(javaVM->runtimeFlags & J9_RUNTIME_SHUTDOWN)) {
TRIGGER_J9HOOK_MM_PRIVATE_HEAP_DELETE(
MM_GCExtensions::getExtensions(javaVM)->privateHookInterface,
env.getOmrVMThread(),
modronMemorySpace);
}
}
}
/**
* Cleanup passive heap structures
*/
void
gcCleanupHeapStructures(J9JavaVM * vm)
{
/* If shutdown occurs early (due to command line parsing errors, for example) there may not be
* a J9VMThread, so allocate a fake environment.
*/
MM_EnvironmentBase env(vm->omrVM);
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(vm);
/* remove hooks installed by Validator */
gcCleanupVMHooks(extensions);
/* Flush any allocation contexts so that their memory is returned to the memory spaces before we tear down the memory spaces */
MM_GlobalAllocationManager *gam = extensions->globalAllocationManager;
if (NULL != gam) {
gam->flushAllocationContextsForShutdown(&env);
}
if (!IS_RESTORE_RUN(vm)) {
if (NULL != vm->memorySegments) {
vm->internalVMFunctions->freeMemorySegmentList(vm, vm->memorySegments);
}
if (NULL != vm->classMemorySegments) {
vm->internalVMFunctions->freeMemorySegmentList(vm, vm->classMemorySegments);
}
}
#if defined(J9VM_GC_FINALIZATION)
if (extensions->finalizeListManager) {
extensions->finalizeListManager->kill(&env);
extensions->finalizeListManager = NULL;
}
#endif /* J9VM_GC_FINALIZATION */
if (vm->mainThread && vm->mainThread->threadObject) {
/* main thread has not been deallocated yet, but heap has gone */
vm->mainThread->threadObject = NULL;
#if JAVA_SPEC_VERSION >= 19
vm->mainThread->carrierThreadObject = NULL;
#endif /* JAVA_SPEC_VERSION >= 19 */
}
return;
}
/**
* Initialized passive and active heap components
*/
IDATA
j9gc_initialize_heap(J9JavaVM *vm, IDATA *memoryParameterTable, UDATA heapBytesRequested)
{
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(vm);
MM_EnvironmentBase env(vm->omrVM);
MM_GlobalCollector *globalCollector;
PORT_ACCESS_FROM_JAVAVM(vm);
J9VMDllLoadInfo *loadInfo = getGCDllLoadInfo(vm);
if (J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_PORTABLE_SHARED_CACHE)) {
extensions->shouldForceLowMemoryHeapCeilingShiftIfPossible = true;
}
#if defined(J9VM_GC_BATCH_CLEAR_TLH)
/* Record batch clear state in VM so inline allocates can decide correct initialization procedure */
vm->initializeSlotsOnTLHAllocate = (extensions->batchClearTLH == 0) ? 1 : 0;
#endif /* J9VM_GC_BATCH_CLEAR_TLH */
extensions->heap = extensions->configuration->createHeap(&env, heapBytesRequested);
if (NULL == extensions->heap) {
const char *splitFailure = NULL;
/* If error reason was not explicitly set use general error message */
if(MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_NO_ERROR == extensions->heapInitializationFailureReason) {
extensions->heapInitializationFailureReason = MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_CAN_NOT_INSTANTIATE_HEAP;
}
switch(extensions->heapInitializationFailureReason) {
/* see if we set the split-heap specific error since we want to be more verbose in that case */
case MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_CAN_NOT_INSTANTIATE_SPLIT_HEAP_OLD_SPACE:
splitFailure = j9nls_lookup_message(J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE, J9NLS_GC_FAILED_TO_ALLOCATE_OLD_SPACE, "Failed to allocate old space");
break;
case MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_CAN_NOT_INSTANTIATE_SPLIT_HEAP_NEW_SPACE:
splitFailure = j9nls_lookup_message(J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE, J9NLS_GC_FAILED_TO_ALLOCATE_NEW_SPACE, "Failed to allocate new space");
break;
case MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_CAN_NOT_INSTANTIATE_SPLIT_HEAP_GEOMETRY:
splitFailure = j9nls_lookup_message(J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE, J9NLS_GC_SPLIT_HEAP_ENTEXTS_WRONG_ORDER, "Required split heap memory geometry could not be allocated");
break;
/* failed an attempt to allocate low memory reserve */
case MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_CAN_NOT_ALLOCATE_LOW_MEMORY_RESERVE:
{
/* Obtain the qualified size (e.g. 2k) */
UDATA size = extensions->suballocatorInitialSize;
const char* qualifier = NULL;
qualifiedSize(&size, &qualifier);
const char *format = j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_INSTANTIATE_LOW_MEMORY_RESERVE_SIZE_REQUESTED,
"Failed to instantiate compressed references metadata; %zu%s requested");
UDATA formatLength = strlen(format) + 32; /* 2^64 is 20 digits, so have a few extra */
char *buffer = (char *)j9mem_allocate_memory(formatLength, OMRMEM_CATEGORY_MM);
if (NULL != buffer) {
j9str_printf(PORTLIB, buffer, formatLength, format, size, qualifier);
}
vm->internalVMFunctions->setErrorJ9dll(PORTLIB, loadInfo, buffer, TRUE);
break;
}
/* general error message - can not instantiate heap */
case MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_CAN_NOT_INSTANTIATE_HEAP:
{
/* Obtain the qualified size (e.g. 2k) */
UDATA size = heapBytesRequested;
const char* qualifier = NULL;
qualifiedSize(&size, &qualifier);
const char *format = j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_INSTANTIATE_HEAP_SIZE_REQUESTED,
"Failed to instantiate heap; %zu%s requested");
UDATA formatLength = strlen(format) + 32; /* 2^64 is 20 digits, so have a few extra */
char *buffer = (char *)j9mem_allocate_memory(formatLength, OMRMEM_CATEGORY_MM);
if (NULL != buffer) {
j9str_printf(PORTLIB, buffer, formatLength, format, size, qualifier);
}
vm->internalVMFunctions->setErrorJ9dll(PORTLIB, loadInfo, buffer, TRUE);
break;
}
/* general error message - can not instantiate heap */
case MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_CAN_NOT_SATISFY_REQUESTED_PAGE_SIZE:
{
/* Obtain the qualified size (e.g. 2k) */
UDATA heapSize = extensions->memoryMax;
const char* heapSizeQualifier = NULL;
qualifiedSize(&heapSize, &heapSizeQualifier);
UDATA pageSize = extensions->requestedPageSize;
const char* pageSizeQualifier = NULL;
qualifiedSize(&pageSize, &pageSizeQualifier);
const char *format = j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_OPTIONS_XLP_PAGE_NOT_AVAILABLE_STRICT,
"Unable to satisfy heap size %zu%s with page size %zu%s. Heap size can be specified with -Xmx");
UDATA formatLength = strlen(format) + 32; /* 2^64 is 20 digits, so have a few extra */
char *buffer = (char *)j9mem_allocate_memory(formatLength, OMRMEM_CATEGORY_MM);
if (NULL != buffer) {
j9str_printf(PORTLIB, buffer, formatLength, format, heapSize, heapSizeQualifier, pageSize, pageSizeQualifier);
}
vm->internalVMFunctions->setErrorJ9dll(PORTLIB, loadInfo, buffer, TRUE);
extensions->largePageFailedToSatisfy = true;
break;
}
case MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_NO_ERROR:
case MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_METRONOME_DOES_NOT_SUPPORT_4BIT_SHIFT:
default:
Assert_MM_unreachable();
break;
}
/* Handle split heap failures cases */
if (NULL != splitFailure) {
const char *format = j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_INSTANTIATE_SPLIT_HEAP,
"Failed to instantiate split heap: %s (new size %zu%s, old size %zu%s)");
UDATA oldSpaceSize = extensions->oldSpaceSize;
const char* oldQualifier = NULL;
qualifiedSize(&oldSpaceSize, &oldQualifier);
UDATA newSpaceSize = extensions->newSpaceSize;
const char* newQualifier = NULL;
qualifiedSize(&newSpaceSize, &newQualifier);
UDATA formatLength = j9str_printf(PORTLIB, NULL, 0, format, splitFailure, newSpaceSize, newQualifier, oldSpaceSize, oldQualifier);
char *buffer = (char *)j9mem_allocate_memory(formatLength, OMRMEM_CATEGORY_MM);
if (NULL != buffer) {
j9str_printf(PORTLIB, buffer, formatLength, format, splitFailure, newSpaceSize, newQualifier, oldSpaceSize, oldQualifier);
}
vm->internalVMFunctions->setErrorJ9dll(PORTLIB, loadInfo, buffer, TRUE);
}
/* failed to generate error string - use default */
if (NULL == loadInfo->fatalErrorStr) {
vm->internalVMFunctions->setErrorJ9dll(
PORTLIB,
loadInfo,
j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_INSTANTIATE_HEAP,
"Failed to instantiate heap."),
FALSE);
}
goto error_no_memory;
}
extensions->dispatcher = extensions->configuration->createParallelDispatcher(&env, (omrsig_handler_fn)vm->internalVMFunctions->structuredSignalHandlerVM, vm, vm->defaultOSStackSize);
if (NULL == extensions->dispatcher) {
vm->internalVMFunctions->setErrorJ9dll(
PORTLIB,
loadInfo,
j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_INSTANTIATE_TASK_DISPATCHER,
"Failed to instantiate task dispatcher."),
FALSE);
goto error_no_memory;
}
/* Initialize VM interface extensions */
GC_OMRVMInterface::initializeExtensions(extensions);
/* Initialize the global collector */
globalCollector = extensions->configuration->createCollectors(&env);
if (NULL == globalCollector) {
if(MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_METRONOME_DOES_NOT_SUPPORT_4BIT_SHIFT == extensions->heapInitializationFailureReason) {
j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTION_OVERFLOW, displayXmxOrMaxRAMPercentage(memoryParameterTable));
}
vm->internalVMFunctions->setErrorJ9dll(
PORTLIB,
loadInfo,
j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_INSTANTIATE_GLOBAL_GARBAGE_COLLECTOR,
"Failed to instantiate global garbage collector."),
FALSE);
goto error_no_memory;
}
/* Mark this collector as a global collector so that we will check for excessive gc after it collects */
globalCollector->setGlobalCollector(true);
extensions->setGlobalCollector(globalCollector);
/* Create the environments pool */
extensions->environments = extensions->configuration->createEnvironmentPool(&env);
if (NULL == extensions->environments) {
goto error_no_memory;
}
extensions->classLoaderManager = MM_ClassLoaderManager::newInstance(&env, globalCollector);
if (NULL == extensions->classLoaderManager) {
goto error_no_memory;
}
extensions->stringTable = MM_StringTable::newInstance(&env, extensions->dispatcher->threadCountMaximum());
if (NULL == extensions->stringTable) {
goto error_no_memory;
}
/* Initialize statistic locks */
if (omrthread_monitor_init_with_name(&extensions->gcStatsMutex, 0, "MM_GCExtensions::gcStats")) {
vm->internalVMFunctions->setErrorJ9dll(
PORTLIB,
loadInfo,
j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_INITIALIZE_MUTEX,
"Failed to initialize mutex for GC statistics."),
FALSE);
goto error_no_memory;
}
#if defined(OMR_GC_IDLE_HEAP_MANAGER)
if (extensions->gcOnIdle) {
/* Enable idle tuning only for gencon policy */
if (gc_policy_gencon == extensions->configurationOptions._gcPolicy) {
extensions->idleGCManager = MM_IdleGCManager::newInstance(&env);
if (NULL == extensions->idleGCManager) {
goto error_no_memory;
}
}
}
#endif
return JNI_OK;
error_no_memory:
extensions->handleInitializeHeapError(vm, loadInfo->fatalErrorStr);
return JNI_ENOMEM;
}
/**
* Creates and initialized VM owned structures related to the heap
* Calls low level heap initialization function
* @return J9VMDLLMAIN_OK or J9VMDLLMAIN_FAILED
*/
jint
gcInitializeHeapStructures(J9JavaVM *vm)
{
PORT_ACCESS_FROM_JAVAVM(vm);
MM_EnvironmentBase env(vm->omrVM);
MM_MemorySpace *defaultMemorySpace;
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(vm);
J9VMDllLoadInfo *loadInfo = getGCDllLoadInfo(vm);
/* By this point during a restore run, the memory segments are already allocated
* and initialized.
*/
if (!IS_RESTORE_RUN(vm)) {
/* For now, set the number of segments to a default (= 10) in the pool. */
U_32 defaultSegments = 10;
vm->memorySegments = vm->internalVMFunctions->allocateMemorySegmentList(vm, defaultSegments, OMRMEM_CATEGORY_VM);
if (NULL == vm->memorySegments) {
vm->internalVMFunctions->setErrorJ9dll(
PORTLIB,
loadInfo,
j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_ALLOCATE_VM_MEMORY_SEGMENTS,
"Failed to allocate VM memory segments."),
FALSE);
goto error;
}
vm->classMemorySegments = vm->internalVMFunctions->allocateMemorySegmentListWithFlags(vm, defaultSegments, MEMORY_SEGMENT_LIST_FLAG_SORT, J9MEM_CATEGORY_CLASSES);
if (NULL == vm->classMemorySegments) {
vm->internalVMFunctions->setErrorJ9dll(
PORTLIB,
loadInfo,
j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_ALLOCATE_VM_CLASS_MEMORY_SEGMENTS,
"Failed to allocate VM class memory segments."),
FALSE);
goto error;
}
}
/* j9gc_initialize_heap is now called from gcInitializeDefaults */
/* Create and initialize the default memory space */
defaultMemorySpace = internalAllocateMemorySpaceWithMaximum(vm, extensions->initialMemorySize, extensions->minNewSpaceSize, extensions->newSpaceSize, extensions->maxNewSpaceSize, extensions->minOldSpaceSize, extensions->oldSpaceSize, extensions->maxOldSpaceSize, extensions->maxSizeDefaultMemorySpace, 0, MEMORY_TYPE_DISCARDABLE);
if (defaultMemorySpace == NULL) {
vm->internalVMFunctions->setErrorJ9dll(
PORTLIB,
loadInfo,
j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_ALLOCATE_DEFAULT_MEMORY_SPACE,
"Failed to allocate default memory space."),
FALSE);
goto error;
}
extensions->configuration->defaultMemorySpaceAllocated(extensions, defaultMemorySpace);
#if defined(J9VM_GC_FINALIZATION)
if(!(extensions->finalizeListManager = GC_FinalizeListManager::newInstance(&env))) {
vm->internalVMFunctions->setErrorJ9dll(
PORTLIB,
loadInfo,
j9nls_lookup_message(
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_INITIALIZE_FINALIZER_MANAGEMENT,
"Failed to initialize finalizer management."),
FALSE);
goto error;
}
#endif /* J9VM_GC_FINALIZATION */
/* install hooks for the Validator */
if (!gcInitializeVMHooks(extensions)) {
goto error;
}
vm->defaultMemorySpace = defaultMemorySpace;
return J9VMDLLMAIN_OK;
error:
return J9VMDLLMAIN_FAILED;
}
/**
* Starts the Finalizer and the Heap management components
* @return 0 if OK, non zero if error
*/
int
gcStartupHeapManagement(J9JavaVM *javaVM)
{
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
int result = 0;
#if defined(J9VM_GC_FINALIZATION)
#if JAVA_SPEC_VERSION >= 18
if (J9_ARE_ANY_BITS_SET(javaVM->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_DISABLE_FINALIZATION)) {
/* Finalization is disabled */
} else
#endif /* JAVA_SPEC_VERSION >= 18 */
{
result = j9gc_finalizer_startup(javaVM);
if (JNI_OK != result) {
PORT_ACCESS_FROM_JAVAVM(javaVM);
j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_FAILED_TO_INITIALIZE_FINALIZE_SUPPORT);
return result;
}
}
#endif /* J9VM_GC_FINALIZATION */
/* Kickoff secondary initialization for the global collector */
if (!extensions->getGlobalCollector()->collectorStartup(extensions)) {
result = JNI_ENOMEM;
}
if (!extensions->dispatcher->startUpThreads()) {
extensions->dispatcher->shutDownThreads();
result = JNI_ENOMEM;
}
if (JNI_OK != result) {
PORT_ACCESS_FROM_JAVAVM(javaVM);
extensions->getGlobalCollector()->collectorShutdown(extensions);
j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_FAILED_TO_STARTUP_GARBAGE_COLLECTOR);
return result;
}
return result;
}
void j9gc_jvmPhaseChange(J9VMThread *currentThread, UDATA phase)
{
J9JavaVM *vm = currentThread->javaVM;
MM_GCExtensions *ext = MM_GCExtensions::getExtensions(vm);
MM_EnvironmentBase env(currentThread->omrVMThread);
if (J9VM_PHASE_NOT_STARTUP == phase) {
if ((NULL != vm->sharedClassConfig) && ext->useGCStartupHints && (ext->initialMemorySize != ext->memoryMax)) {
if (ext->isStandardGC()) {
/* read old values from SC */
uintptr_t hintDefaultOld = 0;
uintptr_t hintTenureOld = 0;
vm->sharedClassConfig->findGCHints(currentThread, &hintDefaultOld, &hintTenureOld);
/* Nothing to do if read fails, we'll just assume the old values are 0 */
/* Get the current heap size values.
* Default/Tenure MemorySubSpace is of type Generic (which is MemoryPool owner, while the parents are of type Flat/SemiSpace).
* For SemiSpace the latter (parent) ones are what we want to deal with (expand), since it's what includes both Allocate And Survivor children.
* For Flat it would probably make no difference if we used parent or child, but let's be consistent and use parent, too.
*/
MM_MemorySubSpace *defaultMemorySubSpace = ext->heap->getDefaultMemorySpace()->getDefaultMemorySubSpace()->getParent();
MM_MemorySubSpace *tenureMemorySubspace = ext->heap->getDefaultMemorySpace()->getTenureMemorySubSpace()->getParent();
uintptr_t hintDefault = defaultMemorySubSpace->getActiveMemorySize();
uintptr_t hintTenure = 0;
/* Standard GCs always have Default MSS (which is equal to Tenure for flat heap configuration).
* So the simplest is always fetch Default, regardless if's generational haep configuration or not.
* We fetch Tenure only if only not equal to Default (which implies it's generational) */
if (defaultMemorySubSpace != tenureMemorySubspace) {
hintTenure = tenureMemorySubspace->getActiveMemorySize();
}
/* Gradually learn, by averaging new values with old values - it may take a few restarts before hint converge to stable values */
hintDefault = (uintptr_t)MM_Math::weightedAverage((float)hintDefaultOld, (float)hintDefault, (1.0f - ext->heapSizeStartupHintWeightNewValue));
hintTenure = (uintptr_t)MM_Math::weightedAverage((float)hintTenureOld, (float)hintTenure, (1.0f - ext->heapSizeStartupHintWeightNewValue));
vm->sharedClassConfig->storeGCHints(currentThread, hintDefault, hintTenure, true);
/* Nothing to do if store fails, storeGCHints already issues a trace point */
}
}
}
}
void
gcExpandHeapOnStartup(J9JavaVM *javaVM)
{
J9SharedClassConfig *sharedClassConfig = javaVM->sharedClassConfig;
MM_GCExtensions *ext = MM_GCExtensions::getExtensions(javaVM);
J9VMThread *currentThread = javaVM->internalVMFunctions->currentVMThread(javaVM);
MM_EnvironmentBase env(currentThread->omrVMThread);
if ((NULL != sharedClassConfig) && ext->useGCStartupHints && (ext->initialMemorySize != ext->memoryMax)) {
if (ext->isStandardGC()) {
uintptr_t hintDefault = 0;
uintptr_t hintTenure = 0;
if (0 == sharedClassConfig->findGCHints(currentThread, &hintDefault, &hintTenure)) {
/* Default/Tenure MemorySubSpace is of type Generic (which is MemoryPool owner, while the parents are of type Flat/SemiSpace).
* For SemiSpace the latter (parent) ones are what we want to deal with (expand), since it's what includes both Allocate And Survivor children.
* For Flat it would probably make no difference if we used parent or child, but let's be consistent and use parent, too.
*/
MM_MemorySubSpace *defaultMemorySubSpace = ext->heap->getDefaultMemorySpace()->getDefaultMemorySubSpace()->getParent();
MM_MemorySubSpace *tenureMemorySubspace = ext->heap->getDefaultMemorySpace()->getTenureMemorySubSpace()->getParent();
/* Standard GCs always have Default MSS (which is equal to Tenure for flat heap configuration).
* So the simplest is always deal with Default, regardless if's generational heap configuration or not.
* We deal with Tenure only if only not equal to Default (which implies it's generational)
* We are a bit conservative and aim for slightly lower values that historically recorded by hints.
*/
uintptr_t hintDefaultAdjusted = (uintptr_t)(hintDefault * ext->heapSizeStartupHintConservativeFactor);
uintptr_t defaultCurrent = defaultMemorySubSpace->getActiveMemorySize();
if (hintDefaultAdjusted > defaultCurrent) {
ext->heap->getResizeStats()->setLastExpandReason(HINT_PREVIOUS_RUNS);
defaultMemorySubSpace->expand(&env, hintDefaultAdjusted - defaultCurrent);
}
if (defaultMemorySubSpace != tenureMemorySubspace) {
uintptr_t hintTenureAdjusted = (uintptr_t)(hintTenure * ext->heapSizeStartupHintConservativeFactor);
uintptr_t tenureCurrent = tenureMemorySubspace->getActiveMemorySize();
if (hintTenureAdjusted > tenureCurrent) {
ext->heap->getResizeStats()->setLastExpandReason(HINT_PREVIOUS_RUNS);
tenureMemorySubspace->expand(&env, hintTenureAdjusted - tenureCurrent);
}
}
}
/* Nothing to do if findGCHints failed. It already issues a trace point - no need to duplicate it here */
}
/* todo: Balanced GC */
}
}
/**
* Cleanup Finalizer and Heap components
*/
void
gcShutdownHeapManagement(J9JavaVM *javaVM)
{
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
MM_Collector *globalCollector = extensions->getGlobalCollector();
#if defined(J9VM_GC_FINALIZATION)
/* wait for finalizer shutdown */
j9gc_finalizer_shutdown(javaVM);
#endif /* J9VM_GC_FINALIZATION */
if (extensions->dispatcher) {
extensions->dispatcher->shutDownThreads();
}
/* Kickoff shutdown of global collector */
if (NULL != globalCollector) {
globalCollector->collectorShutdown(extensions);
}
}
/**
* Free any resources allocated by gcInitializeWithDefaultValues
*/
void
gcCleanupInitializeDefaults(OMR_VM* omrVM)
{
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(omrVM);
MM_EnvironmentBase env(omrVM);
J9JavaVM *vm = (J9JavaVM*) omrVM->_language_vm;
if (NULL == extensions) {
return;
}
if (vm->defaultMemorySpace) {
reportPrivateHeapDelete(vm, vm->defaultMemorySpace);
}
/* defaultMemorySpace is cleared as part of configuration tear down */
if (NULL != extensions->configuration) {
extensions->configuration->kill(&env);
}
extensions->kill(&env);
omrVM->_gcOmrVMExtensions = NULL;
((J9JavaVM*)omrVM->_language_vm)->gcExtensions = NULL;
}
static UDATA
normalizeParameter(UDATA parameter, UDATA numerator, UDATA denominator, UDATA max, UDATA min, UDATA roundTo)
{
UDATA value = (parameter / denominator) * numerator;
value = MM_Math::roundToCeiling(roundTo, value);
value = (value > max) ? max : value;
value = (value < min) ? min : value;
return value;
}
/**
* Calculate the memory parameter value.
* Calculate and store memory parameters in destinationStruct based on the data found in sourceStruct
* @param parameterInfo pointer to parameter info structure
* @param memoryParameters array of parameter values
*/
static void
gcCalculateAndStoreMemoryParameter(MM_GCExtensions *destinationStruct, MM_GCExtensions *sourceStruct, const J9GcMemoryParameter *parameterInfo, IDATA *memoryParameters)
{
if (-1 == memoryParameters[parameterInfo->optionName]) {
/* Only parameters not specified by the user may be massaged based on other values. */
destinationStruct->*(parameterInfo->fieldOffset) =
normalizeParameter(sourceStruct->*(parameterInfo->valueBaseOffset),
parameterInfo->scaleNumerator,
parameterInfo->scaleDenominator,
parameterInfo->valueMax,
parameterInfo->valueMin,
parameterInfo->valueRound);
}
}
/**
* Calculate memory parameter values.
* Only parameters not specified by the user may be massaged based on other values.
* @param memoryParameters array of parameter values
*/
static jint
gcInitializeCalculatedValues(J9JavaVM *javaVM, IDATA* memoryParameters)
{
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
jint result = JNI_OK;
/* Set initial Xms value: 8M
*
* Note: Will need to verify Xms/Xmos/Xmns fit in user provided values of Xmx.
* This used to be for free, calculations based on Xmx, now it is a manual check
* in setConfigurationSpecificMemoryParameters
*/
UDATA initialXmsValueMax = 8 * 1024 * 1024;
UDATA initialXmsValueMin = 8 * 1024 * 1024;
if (extensions->isSegregatedHeap() || extensions->isMetronomeGC()) {
/* TODO aryoung: eventually segregated heaps will allow heap expansion, although metronome
* itself will still require a fully expanded heap on startup
*/
initialXmsValueMax = J9_MEMORY_MAX;
initialXmsValueMin = UDATA_MAX;
} else if (J9_ARE_ANY_BITS_SET(javaVM->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_TUNE_THROUGHPUT)) {
/* For -Xtune:throughput we want to set Xms=Xmx */
initialXmsValueMax = extensions->memoryMax;
initialXmsValueMin = extensions->memoryMax;
}
/**
* GC memory parameters to be store in GCExtensions
* opt_Xms will be set to initialXmsValue due to valueMax and valueMin being set
* opt_Xmns will be 50% of Xms
* opt_Xmos will be 50% of Xms
*
* Note: MM_GCExtensions::newSpaceSize should be set here based on opt_Xmns option
*/
const struct J9GcMemoryParameter GCExtensionsParameterTable [] = {
{ &MM_GCExtensions::initialMemorySize, opt_Xms, initialXmsValueMax, initialXmsValueMin, &MM_GCExtensions::maxSizeDefaultMemorySpace, 1, 1, extensions->regionSize },
{ &MM_GCExtensions::minNewSpaceSize, opt_Xmns, (UDATA)-1, 2*MINIMUM_NEW_SPACE_SIZE, &MM_GCExtensions::initialMemorySize, 1, 4, 2*extensions->regionSize },
{ &MM_GCExtensions::newSpaceSize, opt_Xmns, (UDATA)-1, 2*MINIMUM_NEW_SPACE_SIZE, &MM_GCExtensions::initialMemorySize, 1, 4, 2*extensions->regionSize },
{ &MM_GCExtensions::maxNewSpaceSize, opt_Xmnx, (UDATA)-1, 2*MINIMUM_NEW_SPACE_SIZE, &MM_GCExtensions::maxSizeDefaultMemorySpace, 1, 4, 2*extensions->regionSize },
{ &MM_GCExtensions::minOldSpaceSize, opt_Xmos, initialXmsValueMax, MINIMUM_OLD_SPACE_SIZE, &MM_GCExtensions::initialMemorySize, 3, 4, extensions->regionSize },
{ &MM_GCExtensions::oldSpaceSize, opt_Xmos, initialXmsValueMax, MINIMUM_OLD_SPACE_SIZE, &MM_GCExtensions::initialMemorySize, 3, 4, extensions->regionSize },
{ &MM_GCExtensions::maxOldSpaceSize, opt_Xmox, (UDATA)-1, MINIMUM_OLD_SPACE_SIZE, &MM_GCExtensions::maxSizeDefaultMemorySpace, 1, 1, extensions->regionSize },
{ &MM_GCExtensions::allocationIncrement, opt_Xmoi, J9_ALLOCATION_INCREMENT_MAX, J9_ALLOCATION_INCREMENT_MIN, &MM_GCExtensions::maxSizeDefaultMemorySpace, J9_ALLOCATION_INCREMENT_NUMERATOR, J9_ALLOCATION_INCREMENT_DENOMINATOR, extensions->regionSize },
{ &MM_GCExtensions::fixedAllocationIncrement, opt_none, J9_FIXED_SPACE_SIZE_MAX, J9_FIXED_SPACE_SIZE_MIN, &MM_GCExtensions::maxSizeDefaultMemorySpace, J9_FIXED_SPACE_SIZE_NUMERATOR, J9_FIXED_SPACE_SIZE_DENOMINATOR, extensions->regionSize },
};
const IDATA GCExtensionsParameterTableSize = (sizeof(GCExtensionsParameterTable) / sizeof(struct J9GcMemoryParameter));
IDATA tableIndex;
/* Set the values which live in the JavaVM since they can't use the common GCExtensions member pointer approach */
if (-1 == memoryParameters[opt_Xmca]) {
javaVM->ramClassAllocationIncrement = normalizeParameter(extensions->maxSizeDefaultMemorySpace, J9_RAM_CLASS_ALLOCATION_INCREMENT_NUMERATOR, J9_RAM_CLASS_ALLOCATION_INCREMENT_DENOMINATOR, J9_RAM_CLASS_ALLOCATION_INCREMENT_MAX, J9_RAM_CLASS_ALLOCATION_INCREMENT_MIN, J9_RAM_CLASS_ALLOCATION_INCREMENT_ROUND_TO);
}
if (-1 == memoryParameters[opt_Xmco]) {
javaVM->romClassAllocationIncrement = normalizeParameter(extensions->maxSizeDefaultMemorySpace, J9_ROM_CLASS_ALLOCATION_INCREMENT_NUMERATOR, J9_ROM_CLASS_ALLOCATION_INCREMENT_DENOMINATOR, J9_ROM_CLASS_ALLOCATION_INCREMENT_MAX, J9_ROM_CLASS_ALLOCATION_INCREMENT_MIN, J9_ROM_CLASS_ALLOCATION_INCREMENT_ROUND_TO);
}
/* Walk the dependency table fixing unspecified parameters to calculated defaults (mapping GCExtensions values to other GCExtensions values) */
for(tableIndex=0; tableIndex < GCExtensionsParameterTableSize; tableIndex++) {
gcCalculateAndStoreMemoryParameter(extensions, extensions, &(GCExtensionsParameterTable[tableIndex]), memoryParameters);
}
#if defined (J9VM_GC_VLHGC)
if (0 == extensions->tarokRememberedSetCardListSize) {
uintptr_t cardSize = MM_RememberedSetCard::cardSize(extensions->compressObjectReferences());
/* 4% of region size is allocated for region's RSCL memory */
extensions->tarokRememberedSetCardListSize = extensions->regionSize * 4 / 100 / cardSize;
}
if (0 == extensions->tarokRememberedSetCardListMaxSize) {
/* Individual RSCL can grow up to 8x of its memory size */
extensions->tarokRememberedSetCardListMaxSize = 8 * extensions->tarokRememberedSetCardListSize;
}
#endif /* defined (J9VM_GC_VLHGC) */
/* Number of GC threads must be initialized at this point */
Assert_MM_true(0 < extensions->gcThreadCount);
/* initialize the size of Local Object Buffer */
if (0 == extensions->objectListFragmentCount) {
extensions->objectListFragmentCount = (4 * extensions->gcThreadCount) + 4;
}
return result;
}
/**
* Verify memory parameters.
*
* Some configurations do not honour all memory parameters provided by the user. Set these
* parameters to default values and make it appear the user did not specify any values for these
* parameters. A routine that thus checks for user provided input will not validate these
* parameters. Routines that modify configuration specific parameters will need to ensure
* they do not modify these same parameters.
*
* For a flat configuration -Xmn is ignored:
* -Xmn/-Xmns are set to 0
* -Xmnx is set to -Xmx
* memoryParameters structure is modified to make it look like the user did not specify these values.
*
* @param memoryParameters array of parameter values
* @return JNI_OK on success, JNI_ERR on failure
*/
jint
setConfigurationSpecificMemoryParameters(J9JavaVM *javaVM, IDATA* memoryParameters, bool flatConfiguration)
{
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
bool opt_XmsSet = (-1 != memoryParameters[opt_Xms]);
bool opt_XmnsSet = (-1 != memoryParameters[opt_Xmns]);
bool opt_XmosSet = (-1 != memoryParameters[opt_Xmos]);
bool opt_XmnxSet = (-1 != memoryParameters[opt_Xmnx]);
if (flatConfiguration) {
/* Xmns = 0, override fact user may have provided a value */
extensions->minNewSpaceSize = 0;
extensions->newSpaceSize = 0;
extensions->maxNewSpaceSize = 0;
memoryParameters[opt_Xmns] = memoryParameters[opt_Xmnx] = memoryParameters[opt_Xmn] = -1;
extensions->absoluteMinimumOldSubSpaceSize = MINIMUM_VM_SIZE;
}
/* Emulation of sovereign behaviour results in Xmx, and Xms being hardcoded. If a value smaller than
* the hardcoded minimum for Xmx is supplied, and this value is less than the hardcoded value of Xms
* then Xms, Xmns and Xmos need to be re-calculated.
*/