Path: blob/master/runtime/gc_modron_startup/mmhelpers.cpp
5985 views
1/*******************************************************************************2* Copyright (c) 1991, 2020 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/2223/**24* @file25* @ingroup GC_Modron_Startup26*/2728#include <string.h>2930#include "j9.h"31#include "j9cfg.h"32#include "j9comp.h"33#include "j9consts.h"34#include "j9modron.h"35#include "ModronAssertions.h"36#include "omr.h"37#include "omrcfg.h"38#include "VerboseGCInterface.h"3940#if defined(J9VM_GC_FINALIZATION)41#include "FinalizeListManager.hpp"42#endif /* J9VM_GC_FINALIZATION */43#include "GCExtensions.hpp"44#include "GlobalCollector.hpp"45#include "Heap.hpp"46#include "HeapRegionManager.hpp"47#if defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD)48#include "HeapRegionStateTable.hpp"49#endif /* defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD) */50#include "MemorySpace.hpp"51#include "MemorySubSpace.hpp"5253extern "C" {54extern J9MemoryManagerFunctions MemoryManagerFunctions;55extern void initializeVerboseFunctionTableWithDummies(J9MemoryManagerVerboseInterface *table);5657/**58* sets the mode where TLH pages are zeroed59* @param flag if non zero, TLH page zeroing will be enabled60*/61#if defined(J9VM_GC_BATCH_CLEAR_TLH)62void63allocateZeroedTLHPages(J9JavaVM *javaVM, UDATA flag)64{65MM_GCExtensions::getExtensions(javaVM)->batchClearTLH = (flag != 0) ? 1 : 0;66}6768/**69* checks if zeroing TLH pages is enabled70*/71UDATA72isAllocateZeroedTLHPagesEnabled(J9JavaVM *javaVM)73{74return MM_GCExtensions::getExtensions(javaVM)->batchClearTLH;75}76#endif /* J9VM_GC_BATCH_CLEAR_TLH */7778UDATA79isStaticObjectAllocateFlags(J9JavaVM *javaVM)80{81return 1;82}8384/**85* Depending on the configuration (scav or not) returns the object allocate flags86* @return OBJECT_HEADER_OLD or 087*/88UDATA89getStaticObjectAllocateFlags(J9JavaVM *javaVM)90{91MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);92UDATA result = extensions->heap->getDefaultMemorySpace()->getDefaultMemorySubSpace()->getObjectFlags();9394/* No static flags supposed to be set for flags in clazz slot */95Assert_MM_true(0 == result);9697return result;98}99100/**101* Query JIT string de-duplication strategy102*/103I_32104j9gc_get_jit_string_dedup_policy(J9JavaVM *javaVM)105{106MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);107if (MM_GCExtensions::J9_JIT_STRING_DEDUP_POLICY_UNDEFINED == extensions->stringDedupPolicy) {108MM_GCExtensions::JitStringDeDupPolicy result = MM_GCExtensions::J9_JIT_STRING_DEDUP_POLICY_DISABLED;109if (extensions->isStandardGC()) {110result = MM_GCExtensions::J9_JIT_STRING_DEDUP_POLICY_FAVOUR_LOWER;111#if defined(J9VM_GC_MODRON_SCAVENGER)112if (extensions->scavengerEnabled) {113if (!extensions->dynamicNewSpaceSizing) {114result = MM_GCExtensions::J9_JIT_STRING_DEDUP_POLICY_FAVOUR_HIGHER;115}116}117#endif /* J9VM_GC_MODRON_SCAVENGER */118}119return (I_32) result;120} else {121return (I_32) extensions->stringDedupPolicy;122}123}124125/**126* Query if scavenger is enabled127* @return 1 if scavenger enabled, 0 otherwise128*/129UDATA130j9gc_scavenger_enabled(J9JavaVM *javaVM)131{132#if defined(J9VM_GC_MODRON_SCAVENGER)133MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);134return extensions->scavengerEnabled ? 1 : 0;135#else /* J9VM_GC_MODRON_SCAVENGER */136return 0;137#endif /* J9VM_GC_MODRON_SCAVENGER */138}139140UDATA141j9gc_concurrent_scavenger_enabled(J9JavaVM *javaVM)142{143return MM_GCExtensions::getExtensions(javaVM)->isConcurrentScavengerEnabled() ? 1 : 0;144}145146UDATA147j9gc_software_read_barrier_enabled(J9JavaVM *javaVM)148{149return MM_GCExtensions::getExtensions(javaVM)->isSoftwareRangeCheckReadBarrierEnabled() ? 1 : 0;150}151152/**153* Query if hot reference field is reqired for scavenger dynamicBreadthFirstScanOrdering154* @return true if scavenger dynamicBreadthFirstScanOrdering is enabled, 0 otherwise155*/156BOOLEAN157j9gc_hot_reference_field_required(J9JavaVM *javaVM)158{159#if defined(J9VM_GC_MODRON_SCAVENGER) || defined(OMR_GC_VLHGC)160return MM_GCExtensions::OMR_GC_SCAVENGER_SCANORDERING_DYNAMIC_BREADTH_FIRST == MM_GCExtensions::getExtensions(javaVM)->scavengerScanOrdering;161#else /* J9VM_GC_MODRON_SCAVENGER || OMR_GC_VLHGC */162return FALSE;163#endif /* defined(J9VM_GC_MODRON_SCAVENGER) || defined(OMR_GC_VLHGC) */164}165166/**167* Query for the max hot field list length that a class is allowed to have.168* Valid if dynamicBreadthFirstScanOrdering is enabled.169*/170uint32_t171j9gc_max_hot_field_list_length(J9JavaVM *javaVM)172{173return MM_GCExtensions::getExtensions(javaVM)->maxHotFieldListLength;174}175176/**177* Depending on the configuration (scav vs concurr etc) returns the type of the write barrier178* @return write barrier type179*/180UDATA181j9gc_modron_getWriteBarrierType(J9JavaVM *javaVM)182{183Assert_MM_true(j9gc_modron_wrtbar_illegal != javaVM->gcWriteBarrierType);184return javaVM->gcWriteBarrierType;185}186187/**188* Depending on the configuration returns the type of the read barrier189* @return read barrier type190*/191UDATA192j9gc_modron_getReadBarrierType(J9JavaVM *javaVM)193{194Assert_MM_true(j9gc_modron_readbar_illegal != javaVM->gcReadBarrierType);195return javaVM->gcReadBarrierType;196}197198/**199* Is the JIT allowed to inline allocations?200* @return non-zero if inline allocation is allowed, 0 otherwise201*/202UDATA203j9gc_jit_isInlineAllocationSupported(J9JavaVM *javaVM)204{205return 1;206}207208#if defined(J9VM_GC_FINALIZATION)209/**210* Return the number of objects currently on the finalize queue.211* This is to support a Java 5.0 API that allows java code to query this number.212* @return number of objects pending finalization213*/214UDATA215j9gc_get_objects_pending_finalization_count(J9JavaVM *javaVM)216{217return MM_GCExtensions::getExtensions(javaVM)->finalizeListManager->getJobCount();218}219#endif /* J9VM_GC_FINALIZATION */220221UDATA222j9gc_ext_is_marked(J9JavaVM *javaVM, J9Object *objectPtr)223{224return MM_GCExtensions::getExtensions(javaVM)->getGlobalCollector()->isMarked(objectPtr);225}226227UDATA228j9gc_modron_isFeatureSupported(J9JavaVM *javaVM, UDATA feature)229{230J9GCFeatureType typedFeature = (J9GCFeatureType) feature;231UDATA featureSupported = FALSE;232MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);233234if (j9gc_modron_feature_inline_reference_get == typedFeature) {235if (extensions->isMetronomeGC()) {236featureSupported = FALSE;237} else {238featureSupported = TRUE;239}240}241return featureSupported;242}243244/**245* Used for checking the value of some piece of externally visible information (instead of adding new API to request every kind of246* information when each would have roughly the same shape). The key parameter is of type "J9GCConfigurationKey" (presented as247* UDATA due to Builder compatibility fears). If the given key is found, the resulting value is stored into "value" as whatever248* type the key defines and TRUE is returned. FALSE is returned and value is untouched if the key is invalid for this configuration249* and an unreachable assertion is thrown if the key is unknown.250* @param javaVM[in] The JavaVM251* @param key[in] An enumerated constant representing the configuration key to query252* @param value[out] The value the configuration holds for the given key (actual pointer type is key-defined)253* @return TRUE if the key was found and value was populated, FALSE if the key is invalid for this configuration and an unreachable254* assertion is thrown if the key is unknown255*/256UDATA257j9gc_modron_getConfigurationValueForKey(J9JavaVM *javaVM, UDATA key, void *value)258{259UDATA keyFound = FALSE;260MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);261262switch (key) {263case j9gc_modron_configuration_none:264/* this is the "safe" invalid value - just return false */265keyFound = FALSE;266break;267case j9gc_modron_configuration_heapAddressToCardAddressShift:268#if defined (J9VM_GC_HEAP_CARD_TABLE)269if (NULL != extensions->cardTable) {270*((UDATA *)value) = CARD_SIZE_SHIFT;271keyFound = TRUE;272} else {273/* this is an invalid (but understood) call if there is no card table */274keyFound = FALSE;275}276#else /* defined (J9VM_GC_HEAP_CARD_TABLE) */277keyFound = FALSE;278#endif /* defined (J9VM_GC_HEAP_CARD_TABLE) */279break;280case j9gc_modron_configuration_heapBaseForBarrierRange0_isVariable:281if (extensions->isVLHGC()) {282*((UDATA *)value) = FALSE;283keyFound = TRUE;284} else if (extensions->isStandardGC()) {285*((UDATA *)value) = FALSE;286keyFound = TRUE;287} else {288keyFound = FALSE;289}290break;291case j9gc_modron_configuration_activeCardTableBase_isVariable:292if (extensions->isVLHGC()) {293*((UDATA *)value) = FALSE;294keyFound = TRUE;295} else if (extensions->isStandardGC()) {296*((UDATA *)value) = FALSE;297keyFound = TRUE;298} else {299keyFound = FALSE;300}301break;302case j9gc_modron_configuration_heapSizeForBarrierRange0_isVariable:303if (extensions->isVLHGC()) {304*((UDATA *)value) = FALSE;305keyFound = TRUE;306} else if (extensions->isStandardGC()) {307if (extensions->minOldSpaceSize == extensions->maxOldSpaceSize) {308*((UDATA *)value) = FALSE;309} else {310*((UDATA *)value) = TRUE;311}312keyFound = TRUE;313} else {314keyFound = FALSE;315}316break;317case j9gc_modron_configuration_minimumObjectSize:318#if defined(J9VM_GC_MINIMUM_OBJECT_SIZE)319*((UDATA *)value) = J9_GC_MINIMUM_OBJECT_SIZE;320keyFound = TRUE;321#else322keyFound = FALSE;323#endif /* defined(J9VM_GC_MINIMUM_OBJECT_SIZE) */324break;325case j9gc_modron_configuration_objectAlignment:326*((UDATA *)value) = extensions->getObjectAlignmentInBytes();327keyFound = TRUE;328break;329case j9gc_modron_configuration_allocationType:330Assert_MM_true(j9gc_modron_allocation_type_illegal != javaVM->gcAllocationType);331*((UDATA *)value) = javaVM->gcAllocationType;332keyFound = TRUE;333break;334case j9gc_modron_configuration_discontiguousArraylets:335*((UDATA *)value) = (UDATA_MAX != extensions->getOmrVM()->_arrayletLeafSize) ? TRUE : FALSE;336keyFound = TRUE;337break;338case j9gc_modron_configuration_gcThreadCount:339*((UDATA *)value) = extensions->gcThreadCount;340keyFound = TRUE;341break;342case j9gc_modron_configuration_compressObjectReferences:343*((UDATA *)value) = extensions->compressObjectReferences();344keyFound = TRUE;345break;346case j9gc_modron_configuration_heapRegionShift:347if (extensions->isVLHGC()) {348*((UDATA *)value) = extensions->heapRegionManager->getRegionShift();349keyFound = TRUE;350} else {351*((UDATA *)value) = 0;352keyFound = FALSE;353}354break;355case j9gc_modron_configuration_heapRegionStateTable:356#if defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD)357if (extensions->isConcurrentCopyForwardEnabled()) {358*((UDATA *)value) = (UDATA) extensions->heapRegionStateTable->getTable();359keyFound = TRUE;360} else {361*((UDATA *)value) = 0;362keyFound = FALSE;363}364#else /* defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD) */365*((UDATA *)value) = 0;366keyFound = FALSE;367#endif /* defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD) */368369break;370default:371/* key is either invalid or unknown for this configuration - should not have been requested */372Assert_MM_unreachable();373}374return keyFound;375}376377} /* extern "C" */378379380