Path: blob/master/runtime/gc_trace/TgcExtensions.cpp
5985 views
/*******************************************************************************1* Copyright (c) 1991, 2018 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*******************************************************************************/2122/**23* @file24* @ingroup GC_Trace25*/2627#include "TgcExtensions.hpp"2829#include <stdarg.h>3031#include "GCExtensions.hpp"3233MM_TgcExtensions *34MM_TgcExtensions::newInstance(MM_GCExtensions *extensions)35{36MM_TgcExtensions * tgcExtensions = (MM_TgcExtensions *) extensions->getForge()->allocate(sizeof(MM_TgcExtensions), MM_AllocationCategory::DIAGNOSTIC, J9_GET_CALLSITE());37if (NULL != tgcExtensions) {38memset((void *)tgcExtensions, 0, sizeof(MM_TgcExtensions));39new(tgcExtensions) MM_TgcExtensions(extensions);40}41return tgcExtensions;42}4344void45MM_TgcExtensions::tearDown(MM_GCExtensions *extensions)46{47if (J9PORT_TTY_ERR != _outputFile) {48PORT_ACCESS_FROM_PORT(getPortLibrary());49j9file_close(_outputFile);50_outputFile = J9PORT_TTY_ERR;51}52}5354void55MM_TgcExtensions::kill(MM_GCExtensions *extensions)56{57tearDown(extensions);58extensions->getForge()->free(this);59}6061MM_TgcExtensions::MM_TgcExtensions(MM_GCExtensions *extensions)62: MM_BaseNonVirtual()63, _portLibrary(((J9JavaVM *)(extensions->getOmrVM()->_language_vm))->portLibrary)64, _outputFile(J9PORT_TTY_ERR)65{66_typeId = __FUNCTION__;67}6869void70MM_TgcExtensions::vprintf(const char *format, va_list args)71{72PORT_ACCESS_FROM_PORT(getPortLibrary());73j9file_vprintf(_outputFile, format, args);74}7576void77MM_TgcExtensions::printf(const char *format, ...)78{79va_list args;80va_start(args, format);81vprintf(format, args);82va_end(args);83}8485bool86MM_TgcExtensions::setOutputFile(const char* filename)87{88bool result = true;89PORT_ACCESS_FROM_PORT(getPortLibrary());90IDATA fd = j9file_open(filename, EsOpenCreate | EsOpenTruncate | EsOpenWrite, 0666);91if (-1 == fd) {92result = false;93} else {94_outputFile = fd;95}96return result;97}9899100