Path: blob/master/runtime/gc_verbose_java/VerboseJava.cpp
5985 views
/*******************************************************************************1* Copyright (c) 2001, 2019 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/21#include "j9.h"22#include "j9cfg.h"23#include "mmhook.h"2425#include "AtomicOperations.hpp"26#include "Base.hpp"27#include "GCExtensions.hpp"28#include "VerboseEventStream.hpp"29#include "VerboseOutputAgent.hpp"30#include "VerboseWriter.hpp"31#include "VerboseManagerJava.hpp"32#include "VerboseManagerOld.hpp"3334#include "gcutils.h"35#include "modronnls.h"3637#include <string.h>3839#include "EnvironmentBase.hpp"4041extern "C" {4243static UDATA gcDebugVerboseStartupLogging(J9JavaVM *javaVM, char* filename, UDATA numFiles, UDATA numCycles);44static void gcDebugVerboseShutdownLogging(J9JavaVM *javaVM, UDATA releaseVerboseStructures);45static void gcDumpMemorySizes(J9JavaVM *javaVM);46static UDATA configureVerbosegc(J9JavaVM *javaVM, int enable, char* filename, UDATA numFiles, UDATA numCycles);47static UDATA queryVerbosegc(J9JavaVM *javaVM);4849/**50* Verbose Function table.51*/52J9MemoryManagerVerboseInterface functionTable = {53gcDebugVerboseStartupLogging,54gcDebugVerboseShutdownLogging,55gcDumpMemorySizes,56configureVerbosegc,57queryVerbosegc58};5960/**61* Initializes the verbose function table.62*/63void64initializeVerboseFunctionTable(J9JavaVM *javaVM)65{66J9MemoryManagerVerboseInterface *mmFuncTable;67J9MemoryManagerVerboseInterface *verboseTable = &functionTable;6869mmFuncTable = (J9MemoryManagerVerboseInterface *)javaVM->memoryManagerFunctions->getVerboseGCFunctionTable(javaVM);7071mmFuncTable->gcDebugVerboseStartupLogging = verboseTable->gcDebugVerboseStartupLogging;72mmFuncTable->gcDebugVerboseShutdownLogging = verboseTable->gcDebugVerboseShutdownLogging;73mmFuncTable->gcDumpMemorySizes = verboseTable->gcDumpMemorySizes;74mmFuncTable->configureVerbosegc = verboseTable->configureVerbosegc;75mmFuncTable->queryVerbosegc = verboseTable->queryVerbosegc;76}7778static UDATA79configureVerbosegc(J9JavaVM *javaVM, int enable, char* filename, UDATA numFiles, UDATA numCycles)80{81MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);82MM_VerboseManagerBase *manager = extensions->verboseGCManager;8384if (!manager && !enable) {85/* they're turning verbosegc off, but it's never been started?! */86return 1;87}8889if (!manager) {90/* startup the verbosegc manager */91MM_EnvironmentBase env(javaVM->omrVM);92if (extensions->verboseNewFormat) {93manager = MM_VerboseManagerJava::newInstance(&env, javaVM->omrVM);94} else {95/* Used with -Xgc:verboseFormat:deprecated */96manager = MM_VerboseManagerOld::newInstance(&env, javaVM->omrVM);97}98if (manager) {99(MM_GCExtensions::getExtensions(javaVM))->verboseGCManager = manager;100} else {101return 0;102}103manager = (MM_GCExtensions::getExtensions(javaVM))->verboseGCManager;104}105106if (!manager->configureVerboseGC(javaVM->omrVM, filename, numFiles, numCycles)) {107return 0;108}109110if (enable) {111manager->enableVerboseGC();112} else {113manager->disableVerboseGC();114}115116return 1;117}118119/**120* Query whether verbosegc is currently enabled.121* Return the number of output agents that are currently enabled.122*/123static UDATA124queryVerbosegc(J9JavaVM *javaVM)125{126MM_VerboseManagerBase *manager = (MM_GCExtensions::getExtensions(javaVM))->verboseGCManager;127128if (NULL != manager) {129return manager->countActiveOutputHandlers();130}131132return 0;133}134135/**136* Allocates and initializes the verbose gc infrastructure.137* @param filename The name of the file or output stream to log to.138* @param numFiles The number of files to log to.139* @param numCycles The number of gc cycles to log to each file.140* @return 1 if successful, 0 otherwise.141*/142static UDATA143gcDebugVerboseStartupLogging(J9JavaVM *javaVM, char* filename, UDATA numFiles, UDATA numCycles)144{145return configureVerbosegc(javaVM, 1, filename, numFiles, numCycles);146}147148/**149* Bring down the verbose gc infrastructure.150* Closes the verbose gc output streams and if safe releases the infrastructure.151* @param releaseVerboseStructures Indicator of whether it is safe to free the infrastructure.152* @return Pointer to the allocated memory.153*/154static void155gcDebugVerboseShutdownLogging(J9JavaVM *javaVM, UDATA releaseVerboseStructures)156{157MM_EnvironmentBase env(javaVM->omrVM);158MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);159160if (NULL == extensions) {161return;162}163164MM_VerboseManagerBase *manager = extensions->verboseGCManager;165166if (NULL == manager) {167return;168}169170manager->closeStreams(&env);171172if (releaseVerboseStructures) {173manager->kill(&env);174extensions->verboseGCManager = NULL;175}176}177178/**179* Dump sizes with the correct qualifier.180* @param byteSize The size in bytes.181* @param optionName The name of the option.182* @param module_name The NLS module to look in183* @param message_num The message number to get from the module184*/185void186gcDumpQualifiedSize(J9PortLibrary* portLib, UDATA byteSize, const char* optionName, U_32 module_name, U_32 message_num)187{188char buffer[16] = {'\0'};189UDATA size = 0;190UDATA paramSize = 0;191const char* qualifier = NULL;192const char* optionDescription = NULL;193PORT_ACCESS_FROM_PORT(portLib);194195/* Obtain the qualified size (e.g. 2k) */196size = byteSize;197qualifiedSize(&size, &qualifier);198199/* look up the appropriate translation */200optionDescription = OMRPORT_FROM_J9PORT(PORTLIB)->nls_lookup_message(201OMRPORT_FROM_J9PORT(PORTLIB),202J9NLS_DO_NOT_APPEND_NEWLINE | J9NLS_DO_NOT_PRINT_MESSAGE_TAG,203module_name,204message_num,205NULL);206207/* Format output String */208paramSize = j9str_printf(PORTLIB, buffer, 16, "%zu%s", size, qualifier);209paramSize = 15 - paramSize;210paramSize += strlen(optionDescription);211paramSize -= strlen(optionName);212j9tty_printf(PORTLIB, " %s%s %*s\n", optionName, buffer, paramSize, optionDescription);213214return;215}216217/**218* Dump gc memory sizes.219* Output is intentionally ordered the same as "j9 -X"220*/221static void222gcDumpMemorySizes(J9JavaVM *javaVM)223{224MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);225UDATA *pageSizes = NULL;226PORT_ACCESS_FROM_JAVAVM(javaVM);227228gcDumpQualifiedSize(PORTLIB, javaVM->ramClassAllocationIncrement, "-Xmca", J9NLS_GC_VERB_SIZES_XMCA);229gcDumpQualifiedSize(PORTLIB, javaVM->romClassAllocationIncrement, "-Xmco", J9NLS_GC_VERB_SIZES_XMCO);230231#if defined(OMR_GC_COMPRESSED_POINTERS)232if (J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM)) {233gcDumpQualifiedSize(PORTLIB, extensions->suballocatorInitialSize, "-Xmcrs", J9NLS_GC_VERB_SIZES_XMCRS);234} else235#endif /* defined(OMR_GC_COMPRESSED_POINTERS) */236{237gcDumpQualifiedSize(PORTLIB, 0, "-Xmcrs", J9NLS_GC_VERB_SIZES_XMCRS);238}239240if (extensions->isVLHGC()) {241#if defined (J9VM_GC_VLHGC)242gcDumpQualifiedSize(PORTLIB, extensions->tarokIdealEdenMinimumBytes, "-Xmns", J9NLS_GC_VERB_SIZES_XMNS);243gcDumpQualifiedSize(PORTLIB, extensions->tarokIdealEdenMaximumBytes, "-Xmnx", J9NLS_GC_VERB_SIZES_XMNX);244#endif /* J9VM_GC_VLHGC */245} else if (!extensions->isMetronomeGC()) {246gcDumpQualifiedSize(PORTLIB, extensions->newSpaceSize, "-Xmns", J9NLS_GC_VERB_SIZES_XMNS);247gcDumpQualifiedSize(PORTLIB, extensions->maxNewSpaceSize, "-Xmnx", J9NLS_GC_VERB_SIZES_XMNX);248}249gcDumpQualifiedSize(PORTLIB, extensions->initialMemorySize, "-Xms", J9NLS_GC_VERB_SIZES_XMS);250if (!(extensions->isMetronomeGC())) {251gcDumpQualifiedSize(PORTLIB, extensions->oldSpaceSize, "-Xmos", J9NLS_GC_VERB_SIZES_XMOS);252gcDumpQualifiedSize(PORTLIB, extensions->maxOldSpaceSize, "-Xmox", J9NLS_GC_VERB_SIZES_XMOX);253}254255if (extensions->allocationIncrementSetByUser) {256gcDumpQualifiedSize(PORTLIB, extensions->allocationIncrement, "-Xmoi", J9NLS_GC_VERB_SIZES_XMOI);257}258gcDumpQualifiedSize(PORTLIB, extensions->memoryMax, "-Xmx", J9NLS_GC_VERB_SIZES_XMX);259260if (extensions->isStandardGC()) {261#if defined(J9VM_GC_MODRON_SCAVENGER)262gcDumpQualifiedSize(PORTLIB, extensions->rememberedSet.getGrowSize(), "-Xmr", J9NLS_GC_VERB_SIZES_XMR);263#endif /* J9VM_GC_GENERATIONAL */264}265266if (0 != extensions->softMx) {267gcDumpQualifiedSize(PORTLIB, extensions->softMx, "-Xsoftmx", J9NLS_GC_VERB_SIZES_XSOFTMX);268}269270271pageSizes = j9vmem_supported_page_sizes();272/* If entry at index 1 of supported page size array is non zero, then large pages are available */273{274const char* optionDescription = NULL;275UDATA *pageFlags = NULL;276UDATA pageIndex = 0;277UDATA size = 0;278const char *qualifier = NULL;279const char* optionName = "-Xlp:objectheap:pagesize=";280char postOption[16] = {'\0'};281282/* Obtain the qualified size (e.g. 4K) */283size = extensions->requestedPageSize;284qualifiedSize(&size, &qualifier);285286/* look up the appropriate translation */287optionDescription = j9nls_lookup_message(288J9NLS_DO_NOT_APPEND_NEWLINE | J9NLS_DO_NOT_PRINT_MESSAGE_TAG,289J9NLS_GC_VERB_SIZES_XLP,290NULL);291292if (J9PORT_VMEM_PAGE_FLAG_NOT_USED != extensions->requestedPageFlags) {293j9str_printf(PORTLIB, postOption, 16, ",%s", getPageTypeString(extensions->requestedPageFlags));294}295296j9tty_printf(PORTLIB, " %s%zu%s%s\t %s\n", optionName, size, qualifier, postOption, optionDescription);297298pageFlags = j9vmem_supported_page_flags();299300optionDescription = j9nls_lookup_message(J9NLS_DO_NOT_APPEND_NEWLINE | J9NLS_DO_NOT_PRINT_MESSAGE_TAG,301J9NLS_GC_VERB_SIZES_AVAILABLE_XLP,302NULL);303304j9tty_printf(PORTLIB, " %*s %s", 15, " ", optionDescription);305306for(pageIndex = 0; 0 != pageSizes[pageIndex]; pageIndex++) {307const char *pageTypeString = NULL;308size = pageSizes[pageIndex];309qualifiedSize(&size, &qualifier);310j9tty_printf(PORTLIB, "\n %*s %zu%s", 15, " ", size, qualifier);311if (J9PORT_VMEM_PAGE_FLAG_NOT_USED != pageFlags[pageIndex]) {312pageTypeString = getPageTypeString(pageFlags[pageIndex]);313}314if (NULL != pageTypeString) {315j9tty_printf(PORTLIB, " %s", pageTypeString);316}317}318j9tty_printf(PORTLIB, "\n");319}320321return;322}323324} /* extern "C" */325326327