Commit f39e3e9f authored by Vít Kabele's avatar Vít Kabele

Agent protobuf

parent c740918b
......@@ -63,7 +63,7 @@ SOURCES = common.c jvmtiutil.c config.c \
shared/blockingqueue.c \
shared/threadlocal.c shared/messagetype.c \
tagger.c sender.c dislreagent.c pbmanager.c redispatcher.c netref.c \
globalbuffer.c tlocalbuffer.c freehandler.c
globalbuffer.c tlocalbuffer.c freehandler.c shvm.pb-c.c protobuf-c.c
HEADERS = $(wildcard *.h)
GENSRCS =
......
/*
* common.h
*
* Contains macros and definitions used in the whole project.
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#define _POSIX_C_SOURCE 200809L
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdarg.h>
......
......@@ -24,14 +24,19 @@
#include "config.h"
#include "jvmtiutil.h"
/*
* jvmti_callback_class_file_load()
*
* Handle the class load event.
*/
static void JNICALL
jvmti_callback_class_file_load (
jvmtiEnv * jvmti, JNIEnv * jni, jclass class_being_redefined,
jobject loader, const char * name, jobject protection_domain,
jint class_data_len, const unsigned char * class_data,
jint * new_class_data_len, unsigned char ** new_class_data
) {
)
{
#ifdef DEBUG
printf ("Sending new class (thread %ld)\n", tld_get ()->id);
#endif
......@@ -52,7 +57,8 @@ jvmti_callback_class_file_load (
static void JNICALL
jvmti_callback_class_prepare (
jvmtiEnv * jvmti, JNIEnv * jni, jthread thread, jclass klass
) {
)
{
static long registedFlag = 0;
if (registedFlag) {
......@@ -81,7 +87,8 @@ jvmti_callback_class_prepare (
static void JNICALL
jvmti_callback_vm_start (jvmtiEnv * jvmti, JNIEnv * jni) {
jvmti_callback_vm_start (jvmtiEnv * jvmti, JNIEnv * jni)
{
//
// Notify the tagger thread that the JVM has reached the START phase.
// The JVMTI calls to SetTag() and GetTag() are legal at this point.
......@@ -91,7 +98,8 @@ jvmti_callback_vm_start (jvmtiEnv * jvmti, JNIEnv * jni) {
static void JNICALL
jvmti_callback_vm_init (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread) {
jvmti_callback_vm_init (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread)
{
//
// The JVM has reached the LIVE phase. Start the tagger thread.
// The tagger thread attaches itself to the JVM.
......@@ -103,25 +111,29 @@ jvmti_callback_vm_init (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread) {
static void JNICALL
jvmti_callback_object_free (jvmtiEnv * jvmti, jlong tag) {
jvmti_callback_object_free (jvmtiEnv * jvmti, jlong tag)
{
redispatcher_object_free (tag);
}
static void JNICALL
jvmti_callback_thread_start (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread) {
jvmti_callback_thread_start (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread)
{
/* nothing at the moment */
}
static void JNICALL
jvmti_callback_thread_end (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread) {
jvmti_callback_thread_end (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread)
{
redispatcher_thread_end ();
}
static void JNICALL
jvmti_callback_vm_death (jvmtiEnv * jvmti, JNIEnv * jni) {
jvmti_callback_vm_death (jvmtiEnv * jvmti, JNIEnv * jni)
{
redispatcher_vm_death ();
// TODO ! suspend all *other* marked threads (they should no be in native code)
// and send their buffers
......@@ -153,7 +165,8 @@ jvmti_callback_vm_death (jvmtiEnv * jvmti, JNIEnv * jni) {
// ******************* JVMTI entry method *******************
static jvmtiEnv *
__jvm_get_jvmti (JavaVM * jvm) {
__jvm_get_jvmti (JavaVM * jvm)
{
jvmtiEnv * jvmti = NULL;
jint result = (*jvm)->GetEnv (jvm, (void **) &jvmti, JVMTI_VERSION_1_0);
......@@ -178,7 +191,8 @@ __jvm_get_jvmti (JavaVM * jvm) {
static void
__jvmti_add_capabilities (jvmtiEnv * jvmti, const jvmtiCapabilities * caps) {
__jvmti_add_capabilities (jvmtiEnv * jvmti, const jvmtiCapabilities * caps)
{
jvmtiError error = (*jvmti)->AddCapabilities (jvmti, caps);
check_jvmti_error (jvmti, error, "failed to add JVMTI capabilities");
}
......@@ -187,14 +201,16 @@ __jvmti_add_capabilities (jvmtiEnv * jvmti, const jvmtiCapabilities * caps) {
static void
__jvmti_register_callbacks (
jvmtiEnv * jvmti, const jvmtiEventCallbacks * callbacks, size_t size
) {
)
{
jvmtiError error = (*jvmti)->SetEventCallbacks (jvmti, callbacks, (jint) size);
check_jvmti_error (jvmti, error, "failed to register event callbacks");
}
static void
__jvmti_enable_events (jvmtiEnv * jvmti, jvmtiEvent * events, size_t count) {
__jvmti_enable_events (jvmtiEnv * jvmti, jvmtiEvent * events, size_t count)
{
for (unsigned int i = 0; i < count; i++) {
jvmtiEvent event = events [i];
jvmtiError error = (*jvmti)->SetEventNotificationMode (
......@@ -207,7 +223,8 @@ __jvmti_enable_events (jvmtiEnv * jvmti, jvmtiEvent * events, size_t count) {
JNIEXPORT jint JNICALL VISIBLE
Agent_OnLoad (JavaVM * jvm, char * options, void * reserved) {
Agent_OnLoad (JavaVM * jvm, char * options, void * reserved)
{
#ifdef DEBUG
setvbuf (stdout, NULL, _IONBF, 0);
setvbuf (stderr, NULL, _IONBF, 0);
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,6 +2,7 @@
#include "shared/blockingqueue.h"
#include "shared/messagetype.h"
#include "shared/bufferpack.h"
#include "pbmanager.h"
......@@ -74,10 +75,14 @@ static volatile int stop_sender_thread = 0;
static void *
sender_loop (void * arg) {
sender_loop (void * arg)
{
ldebug ("sender thread 0x%lx started\n", pthread_self ());
int sockfd = open_connection ();
buffer_t temp_buffer;
buffer_init(&temp_buffer, BUFFER_INITIAL_CAPACITY);
// exit when the jvm is terminated and there are no msg to process
while (!stop_sender_thread || bq_length (&send_q) != 0) {
ldebug (
......@@ -94,9 +99,30 @@ sender_loop (void * arg) {
ldebug ("obtained a buffer %p from send queue\n", pb);
// first send command buffer - contains new class or object ids,...
// This is the buffer previously called new_obj_buffer in
// objtag_thread_loop(). This buffer is also empty, when the pb struct
// is holding the object free events
send_data (sockfd, pb->command_buff);
// send analysis buffer
send_data (sockfd, pb->analysis_buff);
// In the case of object free pb, the object free events are here.
switch (pb->analysis_buff->bytes[0])
{
case MSG_ANALYZE:
printf("Attempting to repack analysis\n");
buffer_repack_analysis(pb->analysis_buff, &temp_buffer);
send_data(sockfd, &temp_buffer);
buffer_clear(&temp_buffer);
break;
case MSG_OBJ_FREE:
printf("Attempting to repack objfree\n");
buffer_repack_objfree(pb->analysis_buff, &temp_buffer);
send_data(sockfd, &temp_buffer);
buffer_clear(&temp_buffer);
break;
default:
send_data (sockfd, pb->analysis_buff);
}
// release (enqueue) buffer according to the type
if (pb->owner_id == PB_UTILITY) {
......@@ -115,8 +141,14 @@ sender_loop (void * arg) {
void
sender_init () {
sender_init ()
{
ldebug ("initializing sender and send queue\n");
// Check the size of data types used to transport
_Static_assert(sizeof (int64_t) >= sizeof (jlong),
"Transport type must be bigger than transported type");
bq_create (&send_q, BQ_BUFFERS + BQ_UTILITY, sizeof (process_buffs *));
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -7,6 +7,18 @@
//
#define MSG_CLOSE 0 // closing connection
#define MSG_ANALYZE 1 // sending analysis
#define MSG_OBJ_FREE 2 // sending object free
#define MSG_NEW_CLASS 3 // sending new class
#define MSG_CLASS_INFO 4 // sending class info
#define MSG_STRING_INFO 5 // sending string info
#define MSG_REG_ANALYSIS 6 // sending registration for analysis method
#define MSG_THREAD_INFO 7 // sending thread info
#define MSG_THREAD_END 8 // sending thread end message
//
void messager_close (buffer_t * buff);
size_t messager_analyze_header (buffer_t * buffer, jlong ordering_id);
......
This diff is collapsed.
This diff is collapsed.
# Protocol buffers definition for SHVM
This folder contains protocol buffers definitions for SHVM agent and SHVM
server and simple script to generate required c/java files from provided
definition.
## Requirements
To re-compile the header/source files from definition, you need to have
installed [protoc-c](https://github.com/protobuf-c/protobuf-c) first, and
protocol buffers javalite.
The java suporting library is defined as dependency, so you only need to
compile with `protoc --javalite_out`
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment