¤¿¤Þ¤Ë¤Ã¤¡£ / 2005-09-22
| Æü | ·î | ²Ð | ¿å | ÌÚ | ¶â | ÅÚ |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 |
2005-09-22 Thu
¢£ EXESEQ ưŪ¥Ð¡¼¥¹¥Þ¡¼¥¯ for Java
¤Õ¤È»×¤¤¤Ä¤¤¤Æ¸½¼ÂƨÈò¤Ë¡¤JVMPI ¤ò»È¤Ã¤Æ¡¤EXESEQ ưŪ¥Ð¡¼¥¹¥Þ¡¼¥¯ ¤òÃê½Ð¤¹¤ë¥³¡¼¥É¤ò½ñ¤¤¤Æ¤ß¤¿¡¥hprof ¤Î¥½¡¼¥¹¤ò»²¾È¤Ë¤¹¤ë¤È´Êñ¤Ë½ñ¤±¤¿¡¥
J2SDK 1.4 ÍÑ¡¥µ¤¤¬¸þ¤±¤Ð JDK 5.0 ÍÑ¤Ë JVMTI ¤ò»È¤Ã¤Æ½ñ¤¯¤È»×¤¦¡¥
$ cat extb.cc
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <jvmpi.h>
typedef struct _method_list_item{
jmethodID method_id;
char *class_name;
char *method_name;
char *method_signature;
struct _method_list_item *next;
} method_list_item;
// global jvmpi interface pointer
static JVMPI_Interface *jvmpi_interface;
method_list_item *first = NULL;
void add_list(const char *class_name, JVMPI_Method method){
method_list_item* m;
m = (method_list_item *)malloc(sizeof(method_list_item));
m->method_id = method.method_id;
m->class_name = (char *)malloc(sizeof(char) * (strlen(class_name) + 1));
strcpy(m->class_name, class_name);
m->method_name = (char *)malloc(sizeof(char) * (strlen(method.method_name) + 1));
strcpy(m->method_name, method.method_name);
m->method_signature = (char *)malloc(sizeof(char) * (strlen(method.method_signature) + 1));
strcpy(m->method_signature, method.method_signature);
m->next = first;
first = m;
}
method_list_item *find_list(jmethodID method_id){
method_list_item *m;
method_list_item *prev = NULL;
for(m = first; m != NULL; prev = m, m = m->next){
if(m->method_id == method_id){
if(prev != NULL){ // ¸«ÉÕ¤«¤Ã¤¿¤é°ìÈÖÁ°¤Ø
prev->next = m->next;
m->next = first;
first = m;
}
return m;
}
}
return NULL;
}
// function for handling event notification
void notifyEvent(JVMPI_Event *event){
method_list_item *item;
int i;
switch(event->event_type) {
case JVMPI_EVENT_METHOD_ENTRY2:
item = find_list(event->u.method_entry2.method_id);
if(item == NULL){
fprintf(stderr, "birthmark> \n");
}
else{
fprintf(stderr, "birthmark> %s %s %s\n", item->class_name,
item->method_name, item->method_signature);
}
break;
case JVMPI_EVENT_JVM_SHUT_DOWN:
for(item = first; item != NULL; ){
method_list_item *m;
m = item;
item = item->next;
free(m->class_name);
free(m->method_name);
free(m->method_signature);
free(m);
}
break;
case JVMPI_EVENT_CLASS_LOAD:
for(i = 0; i < event->u.class_load.num_methods; i++){
add_list(event->u.class_load.class_name, event->u.class_load.methods[i]);
}
break;
}
}
// profiler agent entry point
extern "C" {
JNIEXPORT jint JNICALL JVM_OnLoad(JavaVM *jvm, char *options, void *reserved) {
// get jvmpi interface pointer
if ((jvm->GetEnv((void **)&jvmpi_interface, JVMPI_VERSION_1)) < 0) {
fprintf(stderr, "birthmark> error in obtaining jvmpi interface pointer\n");
return JNI_ERR;
}
// initialize jvmpi interface
jvmpi_interface->NotifyEvent = notifyEvent;
// enabling class load event notification
jvmpi_interface->EnableEvent(JVMPI_EVENT_JVM_SHUT_DOWN, NULL);
jvmpi_interface->EnableEvent(JVMPI_EVENT_METHOD_ENTRY2, NULL);
jvmpi_interface->EnableEvent(JVMPI_EVENT_CLASS_LOAD, NULL);
return JNI_OK;
}
}
$ gcc -mdll -Wl,--enable-auto-import -Wl,--add-stdcall-alias \
-mrtd -g -O3 -Wall -I /usr/local/java/j2sdk1.4.2_04/include/ \
-I /usr/local/java/j2sdk1.4.2_04/include/win32/ -mno-cygwin \
-o extb.dll extb.cc
$ java -Xrunextb HelloWorld
¢£ Java¤ÇɬÍפʤΤϼþÊմͤÎÃμ±
¡ÖJava¤ò³Ð¤¨¤ì¤ÐJava¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤òºî¤ë¤³¤È¤¬¤Ç¤¤ë¡ª¡×¡£Åö¤¿¤êÁ°¤Î¤³¤È¤Î¤è¤¦¤Ç¤¹¤¬¡¢¼Â¤ÏȾʬÀµ²ò¤ÇȾʬ¸í¤ê¤Ç¤¹¡£
¤À¤Ê¡¥J2EE ʬÌ¤ã¤Ê¤¯¤Æ¤â¡¤¤Á¤ç¤Ã¤È¶Å¤Ã¤¿¤³¤È¤ò¤·¤è¤¦¤È»×¤¦¤È³ÈÄ¥¥é¥¤¥Ö¥é¥ê»È¤¦¤Î¤ÏÅö¤¿¤êÁ°¤À¤Ê¤¡¡¥
¢£ ºÇ½é¤ÎPentium Mac¤Ï2006ǯ6·î¤ËÅоì
¤Á¤ç¤Ã¤ÈÃÙ¤¤¤Ê¤¡¡¥
¢£ ¡Ö¥ì¥³¡¼¥É²ñ¼Ò¤Ï¶¯Íߡפȥ¹¥Æ¥£¡¼¥Ö¡¦¥¸¥ç¥Ö¥º»á
¢£ °¦ÃÎËüÇî¥Þ¥¹¥³¥Ã¥È¤Îµ¶ÊªÅо졡¸ý¥³¥ß¤Ç¹¤¬¤ë
via ¥¥ê¥¾¡¼¡õ¥â¥Ã¥³¥í, ¥¥ê¥¾¡¼¡õ¥â¥Ã¥³¥í¹¶·â
ËüÇ²ñ¤Ï¡Ö¿Íµ¤¤¬Á´¹ñ¶è¤Ë¤Ê¤Ã¤¿¾Ú¤·¡£¼Â³²¤â¤Ê¤¯¡¢Ìܤ¯¤¸¤é¤òΩ¤Æ¤ë¤Û¤É¤Ç¤â¤Ê¤¤¡×¡£
²û¤Î¿¼¤µ¤¬¥«¥Ã¥³¥¤¥¤¡¥
2008 : 01 02 03 04 05 06 07 08 09 10 11 12
2007 : 01 02 03 04 05 06 07 08 09 10 11 12
2006 : 01 02 03 04 05 06 07 08 09 10 11 12
2005 : 01 02 03 04 05 06 07 08 09 10 11 12
2004 : 01 02 03 04 05 06 07 08 09 10 11 12
2003 : 01 02 03 04 05 06 07 08 09 10 11 12
2002 : 01 02 03 04 05 06 07 08 09 10 11 12
2001 : 01 02 03 04 05 06 07 08 09 10 11 12
ºÇ½ª¹¹¿·»þ´Ö: 2008-09-04 19:19





