1 /* 2 * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 #include "precompiled.hpp" 25 #include "logging/logAsyncFlusher.hpp" 26 #include "logging/logHandle.hpp" 27 #include "logging/logMessageBuffer.hpp" 28 29 LogAsyncFlusher::~LogAsyncFlusher() { 30 disenroll(); 31 flush(); 32 } 33 34 void LogAsyncFlusher::task() { 35 LinkedListImpl<AsyncLogMessage, ResourceObj::C_HEAP, mtLogging> logs; 36 { 37 MutexLocker ml(&_lock, Mutex::_no_safepoint_check_flag); 38 _fifo.pop_all(&logs); 39 } 40 41 LinkedListIterator<AsyncLogMessage> it(logs.head()); 42 while (!it.is_empty()) { 43 AsyncLogMessage* e = it.next(); 44 LogTagSet* tagset = e->tagset(); 45 LogMessageBuffer* buf = e->buffer(); 46 Arena* arena; 47 if (buf != NULL) { 48 tagset->log(*buf); 49 arena = buf->arena(); 50 delete buf; 51 delete arena; 52 } 53 } 54 } 55 56 void LogAsyncFlusher::enqueue(LogTagSet* tagset, LogMessageBuffer* buf) { 57 MutexLocker ml(&_lock, Mutex::_no_safepoint_check_flag); 58 _fifo.push(AsyncLogMessage::create(tagset, buf)); 59 } 60 61 LogAsyncFlusher* LogAsyncFlusher::_instance = NULL; 62 63 void LogAsyncFlusher::initialize() { 64 if (!_instance) { 65 _instance = new (mtLogging)LogAsyncFlusher(LogAsyncInterval); 66 } 67 } 68 69 void LogAsyncFlusher::cleanup() { 70 if (_instance != NULL) { 71 delete _instance; 72 _instance = NULL; 73 } 74 } 75 76 LogAsyncFlusher* LogAsyncFlusher::instance() { 77 return _instance; 78 }