/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "jni.h"
#include "jvmti.h"
#include "agent_util.h"
#include "Monitor.hpp"
#include "Thread.hpp"
#include "Agent.hpp"
/* Implementation of the Agent class */
/* Given a jvmtiEnv* and jthread, find the Thread instance */
Thread *
{
Thread *t;
/* This should always be in the Thread Local Storage */
t = NULL;
if ( t == NULL ) {
/* This jthread has never been seen before? */
stdout_message("WARNING: Never before seen jthread?\n");
}
return t;
}
/* Given a jvmtiEnv* and jobject, find the Monitor instance or create one */
Monitor *
{
Monitor *m;
m = NULL;
/*LINTED*/
if ( m == NULL ) {
/* Save monitor on list */
if (monitor_count == monitor_list_size) {
(monitor_list_size)*(int)sizeof(Monitor*));
}
monitor_list[monitor_count] = m;
m->set_slot(monitor_count);
/*LINTED*/
}
return m;
}
/* VM initialization and VM death calls to Agent */
{
stdout_message("Agent created..\n");
stdout_message("VMInit...\n");
/* Start monitor list */
monitor_count = 0;
monitor_list = (Monitor**)
}
{
stdout_message("Agent reclaimed..\n");
}
{
/* Delete all Monitors we allocated */
for ( int i = 0; i < (int)monitor_count; i++ ) {
delete monitor_list[i];
}
/* Print death message */
stdout_message("VMDeath...\n");
}
/* Thread start event, setup a new thread */
{
Thread *t;
/* Allocate a new Thread instance, put it in the Thread Local
* Storage for easy access later.
*/
}
/* Thread end event, we need to reclaim the space */
{
Thread *t;
/* Find the thread */
/* Clear out the Thread Local Storage */
/* Reclaim the C++ object space */
delete t;
}
/* Monitor contention begins for a thread. */
{
}
/* Monitor contention ends for a thread. */
{
/* Do nothing for now */
}
/* Monitor wait begins for a thread. */
{
}
/* Monitor wait ends for a thread. */
{
if ( timed_out ) {
}
}
/* A tagged object has been freed */
{
/* We just cast the tag to a C++ pointer and delete it.
* we know it can only be a Monitor *.
*/
Monitor *m;
/*LINTED*/
if (monitor_count > 1) {
/* Move the last element to this Monitor's slot */
}
delete m;
}