Skip to content

Commit

Permalink
Merge pull request #4677 from jason-hall/metronome7
Browse files Browse the repository at this point in the history
Modify MetronomeAlarmThread for moving into OMR
  • Loading branch information
dmitripivkine authored Feb 12, 2019
2 parents a7c819d + ac130f0 commit 04c7eb7
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 45 deletions.
3 changes: 2 additions & 1 deletion runtime/gc_glue_java/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
################################################################################
# Copyright (c) 2017, 2018 IBM Corp. and others
# Copyright (c) 2017, 2019 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -37,6 +37,7 @@ target_sources(j9vm_gc_glue
${CMAKE_CURRENT_SOURCE_DIR}/MarkingDelegate.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MarkingSchemeRootClearer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MarkingSchemeRootMarker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MetronomeAlarmThreadDelegate.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MixedObjectModel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ObjectModel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ObjectModelDelegate.cpp
Expand Down
78 changes: 78 additions & 0 deletions runtime/gc_glue_java/MetronomeAlarmThreadDelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
*
* 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] http://openjdk.java.net/legal/assembly-exception.html
*
* 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-exception
*******************************************************************************/

#include "MetronomeAlarmThreadDelegate.hpp"

#if defined(J9VM_GC_REALTIME)

#include "omr.h"
#include "EnvironmentRealtime.hpp"
#include "GCExtensions.hpp"
#include "MetronomeAlarmThread.hpp"

uintptr_t
MM_MetronomeAlarmThreadDelegate::signalProtectedFunction(J9PortLibrary *privatePortLibrary, void* userData)
{
MM_MetronomeAlarmThread *alarmThread = (MM_MetronomeAlarmThread *)userData;
J9JavaVM *javaVM = (J9JavaVM *)alarmThread->getScheduler()->_extensions->getOmrVM()->_language_vm;
J9VMThread *vmThread = NULL;
MM_EnvironmentRealtime *env = NULL;

if (JNI_OK != (javaVM->internalVMFunctions->attachSystemDaemonThread(javaVM, &vmThread, "GC Alarm"))) {
return 0;
}

env = MM_EnvironmentRealtime::getEnvironment(vmThread);

alarmThread->run(env);

javaVM->internalVMFunctions->DetachCurrentThread((JavaVM*)javaVM);

return 0;
}

/**
* C entrypoint for the newly created alarm thread.
*/
int J9THREAD_PROC
MM_MetronomeAlarmThreadDelegate::metronomeAlarmThreadWrapper(void* userData)
{
MM_MetronomeAlarmThread *alarmThread = (MM_MetronomeAlarmThread *)userData;
J9JavaVM *javaVM = (J9JavaVM *)alarmThread->getScheduler()->_extensions->getOmrVM()->_language_vm;
PORT_ACCESS_FROM_JAVAVM(javaVM);
uintptr_t rc;

j9sig_protect(MM_MetronomeAlarmThreadDelegate::signalProtectedFunction, (void*)userData,
javaVM->internalVMFunctions->structuredSignalHandlerVM, javaVM,
J9PORT_SIG_FLAG_SIGALLSYNC | J9PORT_SIG_FLAG_MAY_CONTINUE_EXECUTION,
&rc);

omrthread_monitor_enter(alarmThread->_mutex);
alarmThread->_alarmThreadActive = MM_MetronomeAlarmThread::AlarmThradActive::ALARM_THREAD_SHUTDOWN;
omrthread_monitor_notify(alarmThread->_mutex);
omrthread_exit(alarmThread->_mutex);

return 0;
}

#endif /* defined(J9VM_GC_REALTIME) */

44 changes: 44 additions & 0 deletions runtime/gc_glue_java/MetronomeAlarmThreadDelegate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
*
* 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] http://openjdk.java.net/legal/assembly-exception.html
*
* 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-exception
*******************************************************************************/

#if !defined(METRONOMEALARMTHREADDELEGATE_HPP_)
#define METRONOMEALARMTHREADDELEGATE_HPP_

#include "j9.h"
#include "j9cfg.h"

#if defined(J9VM_GC_REALTIME)

#include "BaseNonVirtual.hpp"

class MM_MetronomeAlarmThreadDelegate : public MM_BaseNonVirtual
{
private:
public:
static int J9THREAD_PROC metronomeAlarmThreadWrapper(void* userData);
static uintptr_t signalProtectedFunction(J9PortLibrary *privatePortLibrary, void* userData);
};

#endif /* defined(J9VM_GC_REALTIME) */

#endif /* defined(METRONOMEALARMTHREADDELEGATE_HPP_) */

47 changes: 7 additions & 40 deletions runtime/gc_realtime/MetronomeAlarmThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
* @file
*/

#include "omrutil.h"

#include "MetronomeAlarmThread.hpp"
#include "MetronomeAlarmThreadDelegate.hpp"
#include "OSInterface.hpp"
#include "RealtimeGC.hpp"
#include "Timer.hpp"
Expand Down Expand Up @@ -107,49 +110,13 @@ MM_MetronomeAlarmThread::initialize(MM_EnvironmentBase *env)
return true;
}

UDATA
MM_MetronomeAlarmThread::signalProtectedFunction(J9PortLibrary* privatePortLibrary, void* userData)
{
MM_MetronomeAlarmThread *alarmThread = (MM_MetronomeAlarmThread *)userData;
J9JavaVM *javaVM = (J9JavaVM *)alarmThread->getScheduler()->_extensions->getOmrVM()->_language_vm;
J9VMThread *vmThread = NULL;
MM_EnvironmentRealtime *env = NULL;

if (JNI_OK != (javaVM->internalVMFunctions->attachSystemDaemonThread(javaVM, &vmThread, "GC Alarm"))) {
return 0;
}

env = MM_EnvironmentRealtime::getEnvironment(vmThread);

alarmThread->run(env);

javaVM->internalVMFunctions->DetachCurrentThread((JavaVM*)javaVM);

return 0;
}

/**
* C entrypoint for the newly created alarm thread.
*/
int J9THREAD_PROC
MM_MetronomeAlarmThread::metronomeAlarmThreadWrapper(void* userData)
{
MM_MetronomeAlarmThread *alarmThread = (MM_MetronomeAlarmThread *)userData;
J9JavaVM *javaVM = (J9JavaVM *)alarmThread->getScheduler()->_extensions->getOmrVM()->_language_vm;
PORT_ACCESS_FROM_JAVAVM(javaVM);
UDATA rc;

j9sig_protect(MM_MetronomeAlarmThread::signalProtectedFunction, (void*)userData,
javaVM->internalVMFunctions->structuredSignalHandlerVM, javaVM,
J9PORT_SIG_FLAG_SIGALLSYNC | J9PORT_SIG_FLAG_MAY_CONTINUE_EXECUTION,
&rc);

omrthread_monitor_enter(alarmThread->_mutex);
alarmThread->_alarmThreadActive = ALARM_THREAD_SHUTDOWN;
omrthread_monitor_notify(alarmThread->_mutex);
omrthread_exit(alarmThread->_mutex);

return 0;
return MM_MetronomeAlarmThreadDelegate::metronomeAlarmThreadWrapper(userData);
}

/**
Expand All @@ -163,13 +130,12 @@ MM_MetronomeAlarmThread::metronomeAlarmThreadWrapper(void* userData)
bool
MM_MetronomeAlarmThread::startThread(MM_EnvironmentBase *env)
{
J9JavaVM *vm = (J9JavaVM *)env->getLanguageVM();
UDATA startPriority;
uintptr_t startPriority;
bool retCode;

startPriority = J9THREAD_PRIORITY_MAX;

if (0 != vm->internalVMFunctions->createThreadWithCategory(
if (J9THREAD_SUCCESS != createThreadWithCategory(
&_thread,
64 * 1024,
startPriority,
Expand Down Expand Up @@ -214,3 +180,4 @@ MM_MetronomeAlarmThread::run(MM_EnvironmentRealtime *env)
}
omrthread_monitor_exit(_mutex);
}

9 changes: 5 additions & 4 deletions runtime/gc_realtime/MetronomeAlarmThread.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*******************************************************************************
* Copyright (c) 1991, 2014 IBM Corp. and others
* Copyright (c) 1991, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -28,8 +28,8 @@
#if !defined(METRONOMEALARMTHREAD_HPP_)
#define METRONOMEALARMTHREAD_HPP_

#include "j9.h"
#include "j9cfg.h"
#include "omr.h"
#include "omrcfg.h"

#include "ProcessorInfo.hpp"
#include "MetronomeAlarm.hpp"
Expand Down Expand Up @@ -63,7 +63,6 @@ class MM_MetronomeAlarmThread : public MM_BaseVirtual
*/
private:
static int J9THREAD_PROC metronomeAlarmThreadWrapper(void* userData);
static UDATA signalProtectedFunction(J9PortLibrary* portLib, void* userData);

protected:
void tearDown(MM_EnvironmentBase *env);
Expand Down Expand Up @@ -94,6 +93,8 @@ class MM_MetronomeAlarmThread : public MM_BaseVirtual
* Friends
*/
friend class MM_Scheduler;
friend class MM_MetronomeAlarmThreadDelegate;
};

#endif /* METRONOMEALARMTHREAD_HPP_ */

0 comments on commit 04c7eb7

Please sign in to comment.