JVMPI changes...

Sun Apr  2 08:27:18 2000  Anthony Green  <green@redhat.com>

        * configure: Rebuilt.
	* configure.in: Add --disable-jvmpi.
        * include/config.h.in: Rebuilt.
        * acconfig.h: Add ENABLE_JVMPI.

	* include/jvm.h: Declare _Jv_DisableGC and _Jv_EnableGC.
        (_Jv_JVMPI_Notify_OBJECT_ALLOC): New define.
        (_Jv_JVMPI_Notify_THREAD_END): New define.
        (_Jv_JVMPI_Notify_THREAD_END): New define.
        * prims.cc (_Jv_JVMPI_Notify_OBJECT_ALLOC): Declare.
	(_Jv_JVMPI_Notify_THREAD_END): Declare.
        (_Jv_JVMPI_Notify_THREAD_END): Declare.

	* prims.cc (_Jv_AllocObject): Generate JVMPI object allocation
        events.

        * java/lang/natThread.cc: Include JVMPI headers if necessary.
        (finish_): Generate JVMPI thread end events.
        (run_): Generate JVMPI thread start events.
	* gnu/gcj/runtime/natFirstThread.cc (run): Call JNI_OnLoad for any
        preloaded JNI library.
        Include JVMPI headers if necessary.
        (run): Generate JVMPI thread start events.

        * boehm.cc: Define GC_disable and GC_enable.
	(_Jv_DisableGC): New function.
        (_Jv_EnableGC): New function.
        (disable_gc_mutex): Declare.
        * nogc.cc (_Jv_DisableGC): New function.
	(_Jv_EnableGC): New function.

        * jni.cc (_Jv_JNI_GetEnv): Handle JVMPI interface requests.
        (_Jv_JVMPI_Interface): Define.
        (jvmpiEnableEvent): New function.
        (_Jv_JNI_Init): Initialize _Jv_JVMPI_Interface.

        * include/jvmpi.h: New file.

From-SVN: r32866
This commit is contained in:
Anthony Green 2000-04-02 15:34:17 +00:00 committed by Anthony Green
parent 49d1b87128
commit 54c2f04ba0
12 changed files with 636 additions and 212 deletions

View File

@ -1,3 +1,43 @@
Sun Apr 2 08:27:18 2000 Anthony Green <green@redhat.com>
* configure: Rebuilt.
* configure.in: Add --disable-jvmpi.
* include/config.h.in: Rebuilt.
* acconfig.h: Add ENABLE_JVMPI.
* include/jvm.h: Declare _Jv_DisableGC and _Jv_EnableGC.
(_Jv_JVMPI_Notify_OBJECT_ALLOC): New define.
(_Jv_JVMPI_Notify_THREAD_END): New define.
(_Jv_JVMPI_Notify_THREAD_END): New define.
* prims.cc (_Jv_JVMPI_Notify_OBJECT_ALLOC): Declare.
(_Jv_JVMPI_Notify_THREAD_END): Declare.
(_Jv_JVMPI_Notify_THREAD_END): Declare.
* prims.cc (_Jv_AllocObject): Generate JVMPI object allocation
events.
* java/lang/natThread.cc: Include JVMPI headers if necessary.
(finish_): Generate JVMPI thread end events.
(run_): Generate JVMPI thread start events.
* gnu/gcj/runtime/natFirstThread.cc (run): Call JNI_OnLoad for any
preloaded JNI library.
Include JVMPI headers if necessary.
(run): Generate JVMPI thread start events.
* boehm.cc: Define GC_disable and GC_enable.
(_Jv_DisableGC): New function.
(_Jv_EnableGC): New function.
(disable_gc_mutex): Declare.
* nogc.cc (_Jv_DisableGC): New function.
(_Jv_EnableGC): New function.
* jni.cc (_Jv_JNI_GetEnv): Handle JVMPI interface requests.
(_Jv_JVMPI_Interface): Define.
(jvmpiEnableEvent): New function.
(_Jv_JNI_Init): Initialize _Jv_JVMPI_Interface.
* include/jvmpi.h: New file.
2000-03-27 Bryce McKinlay <bryce@albatross.co.nz>
* Makefile.in: New #defines and friends for Thread.h.

View File

@ -137,3 +137,6 @@
/* Define if you have working iconv() function. */
#undef HAVE_ICONV
/* Define if you are using JVMPI. */
#undef ENABLE_JVMPI

View File

@ -69,6 +69,9 @@ static ptr_t *obj_free_list;
// Freelist used for Java arrays.
static ptr_t *array_free_list;
// Lock used to protect access to Boehm's GC_enable/GC_disable functions.
static _Jv_Mutex_t disable_gc_mutex;
// This is called by the GC during the mark phase. It marks a Java
@ -391,6 +394,26 @@ _Jv_GCSetMaximumHeapSize (size_t size)
GC_set_max_heap_size ((GC_word) size);
}
// From boehm's misc.c
extern "C" void GC_enable();
extern "C" void GC_disable();
void
_Jv_DisableGC (void)
{
_Jv_MutexLock (&disable_gc_mutex);
GC_disable();
_Jv_MutexUnlock (&disable_gc_mutex);
}
void
_Jv_EnableGC (void)
{
_Jv_MutexLock (&disable_gc_mutex);
GC_enable();
_Jv_MutexUnlock (&disable_gc_mutex);
}
void
_Jv_InitGC (void)
{
@ -443,6 +466,8 @@ _Jv_InitGC (void)
GC_obj_kinds[array_kind_x].ok_relocate_descr = FALSE;
GC_obj_kinds[array_kind_x].ok_init = TRUE;
_Jv_MutexInit (&disable_gc_mutex);
UNLOCK ();
ENABLE_SIGNALS ();
}

476
libjava/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -127,6 +127,14 @@ if test "$enable_java_net" = no; then
AC_DEFINE(DISABLE_JAVA_NET)
fi
dnl See if the user wants to disable JVMPI support.
AC_ARG_ENABLE(jvmpi,
[ --disable-jvmpi disable JVMPI support])
if test "$enable_jvmpi" != no; then
AC_DEFINE(ENABLE_JVMPI)
fi
dnl If the target is an eCos system, use the appropriate eCos
dnl I/O routines.
dnl FIXME: this should not be a local option but a global target

View File

@ -1,6 +1,6 @@
// natFirstThread.cc - Implementation of FirstThread native methods.
/* Copyright (C) 1998, 1999 Free Software Foundation
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
This file is part of libgcj.
@ -14,6 +14,7 @@ details. */
#include <gcj/cni.h>
#include <jvm.h>
#include <jni.h>
#include <gnu/gcj/runtime/FirstThread.h>
#include <java/lang/Class.h>
@ -22,16 +23,56 @@ details. */
#include <java/lang/reflect/Modifier.h>
#include <java/io/PrintStream.h>
#ifdef ENABLE_JVMPI
#include <jvmpi.h>
#include <java/lang/ThreadGroup.h>
#include <java/lang/UnsatisfiedLinkError.h>
#endif
#define DIE(Message) die (JvNewStringLatin1 (Message))
typedef void main_func (jobject);
#ifdef WITH_JVMPI
extern void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
#endif
/* This will be non-NULL if the user has preloaded a JNI library, or
linked one into the executable. */
extern "C"
{
#pragma weak JNI_OnLoad
extern jint JNI_OnLoad (JavaVM *, void *) __attribute__((weak));
}
void
gnu::gcj::runtime::FirstThread::run (void)
{
Utf8Const* main_signature = _Jv_makeUtf8Const ("([Ljava.lang.String;)V", 22);
Utf8Const* main_name = _Jv_makeUtf8Const ("main", 4);
/* Some systems let you preload shared libraries before running a
program. Under Linux, this is done by setting the LD_PRELOAD
environment variable. We take advatage of this here to allow for
dynamically loading a JNI library into a fully linked executable. */
if (JNI_OnLoad != NULL)
{
JavaVM *vm = _Jv_GetJavaVM ();
if (vm == NULL)
{
// FIXME: what?
return;
}
jint vers = JNI_OnLoad (vm, NULL);
if (vers != JNI_VERSION_1_1 && vers != JNI_VERSION_1_2)
{
// FIXME: unload the library.
_Jv_Throw (new java::lang::UnsatisfiedLinkError (JvNewStringLatin1 ("unrecognized version from preloaded JNI_OnLoad")));
}
}
if (klass == NULL)
{
klass = java::lang::Class::forName (klass_name);
@ -48,6 +89,60 @@ gnu::gcj::runtime::FirstThread::run (void)
if (! java::lang::reflect::Modifier::isPublic(meth->accflags))
DIE ("`main' must be public");
#ifdef WITH_JVMPI
if (_Jv_JVMPI_Notify_THREAD_START)
{
JVMPI_Event event;
jstring thread_name = getName ();
jstring group_name = NULL, parent_name = NULL;
java::lang::ThreadGroup *group = getThreadGroup ();
if (group)
{
group_name = group->getName ();
group = group->getParent ();
if (group)
parent_name = group->getName ();
}
int thread_len = thread_name ? JvGetStringUTFLength (thread_name) : 0;
int group_len = group_name ? JvGetStringUTFLength (group_name) : 0;
int parent_len = parent_name ? JvGetStringUTFLength (parent_name) : 0;
char thread_chars[thread_len + 1];
char group_chars[group_len + 1];
char parent_chars[parent_len + 1];
if (thread_name)
JvGetStringUTFRegion (thread_name, 0,
thread_name->length(), thread_chars);
if (group_name)
JvGetStringUTFRegion (group_name, 0,
group_name->length(), group_chars);
if (parent_name)
JvGetStringUTFRegion (parent_name, 0,
parent_name->length(), parent_chars);
thread_chars[thread_len] = '\0';
group_chars[group_len] = '\0';
parent_chars[parent_len] = '\0';
event.event_type = JVMPI_EVENT_THREAD_START;
event.env_id = NULL;
event.u.thread_start.thread_name = thread_chars;
event.u.thread_start.group_name = group_chars;
event.u.thread_start.parent_name = parent_chars;
event.u.thread_start.thread_id = (jobjectID) this;
event.u.thread_start.thread_env_id = _Jv_GetCurrentJNIEnv ();
_Jv_DisableGC ();
(*_Jv_JVMPI_Notify_THREAD_START) (&event);
_Jv_EnableGC ();
}
#endif
main_func *real_main = (main_func *) meth->ncode;
(*real_main) (args);
}

View File

@ -152,6 +152,12 @@
/* Define if g++ has a bug preventing us from inlining math routines. */
#undef __NO_MATH_INLINES
/* Define if you are using JVMPI. */
#undef ENABLE_JVMPI
/* The number of bytes in a void *. */
#undef SIZEOF_VOID_P
/* Define if you have the access function. */
#undef HAVE_ACCESS

View File

@ -82,6 +82,9 @@ void _Jv_RunFinalizers (void);
void _Jv_RunAllFinalizers (void);
/* Perform a GC. */
void _Jv_RunGC (void);
/* Disable and enable GC. */
void _Jv_DisableGC (void);
void _Jv_EnableGC (void);
/* Return approximation of total size of heap. */
long _Jv_GCTotalMemory (void);
@ -216,4 +219,12 @@ void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *);
struct _Jv_JavaVM;
_Jv_JavaVM *_Jv_GetJavaVM ();
#ifdef ENABLE_JVMPI
#include "jvmpi.h"
extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
extern void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
extern void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
#endif
#endif /* __JAVA_JVM_H__ */

View File

@ -27,6 +27,10 @@ details. */
#include <jni.h>
#ifdef ENABLE_JVMPI
#include <jvmpi.h>
#endif
// This structure is used to represent all the data the native side
@ -173,6 +177,21 @@ java::lang::Thread::finish_ ()
natThread *nt = (natThread *) data;
group->remove (this);
#ifdef ENABLE_JVMPI
if (_Jv_JVMPI_Notify_THREAD_END)
{
JVMPI_Event event;
event.event_type = JVMPI_EVENT_THREAD_END;
event.env_id = _Jv_GetCurrentJNIEnv ();
_Jv_DisableGC ();
(*_Jv_JVMPI_Notify_THREAD_END) (&event);
_Jv_EnableGC ();
}
#endif
group = NULL;
// Signal any threads that are waiting to join() us.
@ -188,6 +207,60 @@ java::lang::Thread::run_ (jobject obj)
java::lang::Thread *thread = (java::lang::Thread *) obj;
try
{
#ifdef ENABLE_JVMPI
if (_Jv_JVMPI_Notify_THREAD_START)
{
JVMPI_Event event;
jstring thread_name = thread->getName ();
jstring group_name = NULL, parent_name = NULL;
java::lang::ThreadGroup *group = thread->getThreadGroup ();
if (group)
{
group_name = group->getName ();
group = group->getParent ();
if (group)
parent_name = group->getName ();
}
int thread_len = thread_name ? JvGetStringUTFLength (thread_name) : 0;
int group_len = group_name ? JvGetStringUTFLength (group_name) : 0;
int parent_len = parent_name ? JvGetStringUTFLength (parent_name) : 0;
char thread_chars[thread_len + 1];
char group_chars[group_len + 1];
char parent_chars[parent_len + 1];
if (thread_name)
JvGetStringUTFRegion (thread_name, 0,
thread_name->length(), thread_chars);
if (group_name)
JvGetStringUTFRegion (group_name, 0,
group_name->length(), group_chars);
if (parent_name)
JvGetStringUTFRegion (parent_name, 0,
parent_name->length(), parent_chars);
thread_chars[thread_len] = '\0';
group_chars[group_len] = '\0';
parent_chars[parent_len] = '\0';
event.event_type = JVMPI_EVENT_THREAD_START;
event.env_id = NULL;
event.u.thread_start.thread_name = thread_chars;
event.u.thread_start.group_name = group_chars;
event.u.thread_start.parent_name = parent_chars;
event.u.thread_start.thread_id = (jobjectID) thread;
event.u.thread_start.thread_env_id = _Jv_GetCurrentJNIEnv ();
_Jv_DisableGC ();
(*_Jv_JVMPI_Notify_THREAD_START) (&event);
_Jv_EnableGC ();
}
#endif
thread->run ();
}
catch (java::lang::Throwable *t)

View File

@ -20,6 +20,9 @@ details. */
#include <jvm.h>
#include <java-assert.h>
#include <jni.h>
#ifdef ENABLE_JVMPI
#include <jvmpi.h>
#endif
#include <java/lang/Class.h>
#include <java/lang/ClassLoader.h>
@ -105,12 +108,66 @@ static java::util::Hashtable *ref_table;
// The only VM.
static JavaVM *the_vm;
#ifdef ENABLE_JVMPI
// The only JVMPI interface description.
static JVMPI_Interface _Jv_JVMPI_Interface;
static jint
jvmpiEnableEvent (jint event_type, void *)
{
switch (event_type)
{
case JVMPI_EVENT_OBJECT_ALLOC:
_Jv_JVMPI_Notify_OBJECT_ALLOC = _Jv_JVMPI_Interface.NotifyEvent;
break;
case JVMPI_EVENT_THREAD_START:
_Jv_JVMPI_Notify_THREAD_START = _Jv_JVMPI_Interface.NotifyEvent;
break;
case JVMPI_EVENT_THREAD_END:
_Jv_JVMPI_Notify_THREAD_END = _Jv_JVMPI_Interface.NotifyEvent;
break;
default:
return JVMPI_NOT_AVAILABLE;
}
return JVMPI_SUCCESS;
}
static jint
jvmpiDisableEvent (jint event_type, void *)
{
switch (event_type)
{
case JVMPI_EVENT_OBJECT_ALLOC:
_Jv_JVMPI_Notify_OBJECT_ALLOC = NULL;
break;
default:
return JVMPI_NOT_AVAILABLE;
}
return JVMPI_SUCCESS;
}
#endif
void
_Jv_JNI_Init (void)
{
ref_table = new java::util::Hashtable;
#ifdef ENABLE_JVMPI
_Jv_JVMPI_Interface.version = 1;
_Jv_JVMPI_Interface.EnableEvent = &jvmpiEnableEvent;
_Jv_JVMPI_Interface.DisableEvent = &jvmpiDisableEvent;
_Jv_JVMPI_Interface.EnableGC = &_Jv_EnableGC;
_Jv_JVMPI_Interface.DisableGC = &_Jv_DisableGC;
_Jv_JVMPI_Interface.RunGC = &_Jv_RunGC;
#endif
}
// Tell the GC that a certain pointer is live.
@ -1868,6 +1925,15 @@ _Jv_JNI_GetEnv (JavaVM *, void **penv, jint version)
return JNI_EDETACHED;
}
#ifdef ENABLE_JVMPI
// Handle JVMPI requests.
if (version == JVMPI_VERSION_1)
{
*penv = (void *) &_Jv_JVMPI_Interface;
return 0;
}
#endif
// FIXME: do we really want to support 1.1?
if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_1)
{

View File

@ -1,6 +1,6 @@
// nogc.cc - Code to implement no GC.
/* Copyright (C) 1998, 1999 Free Software Foundation
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
This file is part of libgcj.
@ -85,6 +85,16 @@ _Jv_GCSetMaximumHeapSize (size_t size)
{
}
void
_Jv_DisableGC (void)
{
}
void
_Jv_EnableGC (void)
{
}
void
_Jv_InitGC (void)
{

View File

@ -34,6 +34,10 @@ details. */
#include <java-signal.h>
#include <java-threads.h>
#ifdef ENABLE_JVMPI
#include <jvmpi.h>
#endif
#ifndef DISABLE_GETENV_PROPERTIES
#include <ctype.h>
#include <java-props.h>
@ -83,6 +87,12 @@ property_pair *_Jv_Environment_Properties;
// The name of this executable.
static char * _Jv_execName;
#ifdef ENABLE_JVMPI
// Pointer to JVMPI notification functions.
void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
#endif
#ifdef HANDLE_SEGV
@ -326,6 +336,27 @@ _Jv_AllocObject (jclass c, jint size)
if (c->vtable->method[1] != ObjectClass.vtable->method[1])
_Jv_RegisterFinalizer (obj, _Jv_FinalizeObject);
#ifdef ENABLE_JVMPI
// Service JVMPI request.
if (_Jv_JVMPI_Notify_OBJECT_ALLOC)
{
JVMPI_Event event;
event.event_type = JVMPI_EVENT_OBJECT_ALLOC;
event.env_id = NULL;
event.u.obj_alloc.arena_id = 0;
event.u.obj_alloc.class_id = (jobjectID) c;
event.u.obj_alloc.is_array = 0;
event.u.obj_alloc.size = size;
event.u.obj_alloc.obj_id = (jobjectID) obj;
_Jv_DisableGC ();
(*_Jv_JVMPI_Notify_OBJECT_ALLOC) (&event);
_Jv_EnableGC ();
}
#endif
return obj;
}