* configure.ac (CACAO_LIBDIR): Added.
authortwisti <none@none>
Mon, 17 Jul 2006 15:11:15 +0000 (15:11 +0000)
committertwisti <none@none>
Mon, 17 Jul 2006 15:11:15 +0000 (15:11 +0000)
* src/vm/classcache.c [ENABLE_JVMTI] (lock_hashtable_classcache):
Don't export it.
(classcache_jvmti_GetLoadedClasses): New method.

* src/vm/classcache.h (CLASSCACHE_LOCK): Don't define it.
(CLASSCACHE_UNLOCK): Likewise.
(lock_hashtable_classcache): Don't export it.
(classcache_jvmti_GetLoadedClasses): Added.

* src/vm/vm.c (vm_create): Use CACAO_LIBDIR in OPT_XRUNJDWP.

* src/native/jvmti/jvmti.c (GetLoadedClasses): Use
classcache_jvmti_GetLoadedClasses.
(jvmti_agentload): Some code cleanup.

configure.ac
src/native/jvmti/jvmti.c
src/vm/classcache.c
src/vm/classcache.h
src/vm/vm.c

index 7e76c2520377e8e6354b0f27647f886258a716a6..31b0e0e5be5b42d6460d6daaf941e1b2ed7a4730 100644 (file)
@@ -192,6 +192,17 @@ fi
 AC_DEFINE_UNQUOTED([CACAO_PREFIX], "${CACAO_PREFIX}", [installation prefix])
 AC_SUBST(CACAO_PREFIX)
 
+dnl define libdir prefix
+if test "x$libdir" = "xNONE"; then
+    CACAO_LIBDIR=$ac_default_libdir
+else
+    CACAO_LIBDIR=$libdir
+fi
+dnl expand CACAO_LIBDIR to something that is usable in C code
+AS_AC_EXPAND([CACAO_LIBDIR], ${CACAO_LIBDIR})
+AC_DEFINE_UNQUOTED([CACAO_LIBDIR], "${CACAO_LIBDIR}", [library installation prefix])
+AC_SUBST(CACAO_LIBDIR)
+
 
 dnl Features
 
index 9d88713cb9427d118284f1d723abb4a684bce55d..358b0da167d9c0150bb6bfb0e1e6a65a39d42928 100644 (file)
 
    Changes: Edwin Steiner
             Samuel Vinson
-
+            Christan Thalinger
    
-   $Id: jvmti.c 5141 2006-07-16 15:58:21Z twisti $
+   $Id: jvmti.c 5147 2006-07-17 15:11:15Z twisti $
 
 */
 
+
+#include "config.h"
+
 #include <assert.h>
+#include <string.h>
+#include <linux/unistd.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <ltdl.h>
+#include <unistd.h>
+#include <sched.h>
 
 #include "native/jni.h"
 #include "native/native.h"
 #include "vm/suck.h"
 #include "boehm-gc/include/gc.h"
 
-#include <string.h>
-#include <linux/unistd.h>
-#include <sys/time.h>
-#include "toolbox/logging.h"
-#include <stdlib.h>
-#include <sys/types.h>
-#include <ltdl.h>
-#include <unistd.h>
-#include <sched.h>
-
 #if defined(ENABLE_THREADS)
 #include "threads/native/threads.h"
 #include <sched.h>
@@ -2621,49 +2622,17 @@ IsMethodSynthetic (jvmtiEnv * env, jmethodID method,
 static jvmtiError
 GetLoadedClasses (jvmtiEnv * env, jint * class_count_ptr, jclass ** classes_ptr)
 {
-       int i,j=0;
-       classcache_name_entry *nameentry;
-       classcache_class_entry *classentry;
-
     CHECK_PHASE_START
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
 
-    if (class_count_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
-    if (classes_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
-
-       CLASSCACHE_LOCK();
-       *classes_ptr = 
-               heap_allocate(sizeof(jclass)*(hashtable_classcache.entries),true,NULL);
-       
-       /*      look in every slot of the hashtable */
-       for (i=0; i<hashtable_classcache.size; i++) {
-               nameentry = hashtable_classcache.ptr[i];
-               while (nameentry != NULL) { /* iterate over hashlink */
-
-                       /* filter pseudo classes $NEW$,$NULL$,$ARRAYSTUB$ out */
-                       if (nameentry->name->text[0] == '$')
-                       {
-                               *class_count_ptr -= 1;
-                               break;
-                       }
+    if (class_count_ptr == NULL)
+               return JVMTI_ERROR_NULL_POINTER;
 
-                       classentry = nameentry->classes;
-                       while (classentry != NULL){ /* iterate over classes with same name */
-                               if (classentry->classobj != NULL) { /*get only loaded classes */
-                                        assert(j<hashtable_classcache.entries);
-                                       (*classes_ptr)[j]=classentry->classobj;
-                                       j++;
-                               }
-                               classentry = classentry->next;
-                       }
-                       nameentry = nameentry->hashlink;
-               }
-       }
-       CLASSCACHE_UNLOCK();
+    if (classes_ptr == NULL)
+               return JVMTI_ERROR_NULL_POINTER;
 
-       *class_count_ptr = j;
+       classcache_jvmti_GetLoadedClasses(class_count_ptr, classes_ptr);
 
     return JVMTI_ERROR_NONE;
 }
@@ -4513,24 +4482,35 @@ void jvmti_agentload(char* opt_arg, bool agentbypath, lt_dlhandle  *handle, char
 
        len = strlen(opt_arg);
        
-       /* separate argumtents */
-       while ((opt_arg[i] != '=') && (i<len)) i++;
-       if (i<len)
-               arg = &opt_arg[i+1];
+       /* separate arguments */
+
+       while ((opt_arg[i] != '=') && (i < len))
+               i++;
+
+       opt_arg[i] = '\0';
+
+       if (i < len)
+               arg = &opt_arg[i + 1];
        else
                arg = "";
 
        if (agentbypath) {
                /* -agentpath */
-               *libname=heap_allocate(sizeof(char)*i,true,NULL);
-               strncpy(*libname,opt_arg,i);
-               (*libname)[i]='\0';
-       } else {
+
+               *libname = GCMNEW(char, i);
+
+               strcpy(*libname, opt_arg);
+       }
+       else {
                /* -agentlib */
-               *libname=heap_allocate(sizeof(char)*(i+7),true,NULL);
-               strncpy(*libname,"lib",3);
-               strncpy(&(*libname)[3],opt_arg,i);
-               strncpy(&(*libname)[i+3],".so",3);
+
+               len = strlen("lib") + i + strlen(".so") + strlen("0");
+
+               *libname = GCMNEW(char, len);
+
+               strcpy(*libname, "lib");
+               strcat(*libname, opt_arg);
+               strcat(*libname, ".so");
        }
 
        /* try to open the library */
index 4e59a906c738ca925e9247064a2f2640024c1097..896978c480e92623f362980a0cb27aa934c043a2 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Christian Thalinger
 
-   $Id: classcache.c 5123 2006-07-12 21:45:34Z twisti $
+   $Id: classcache.c 5147 2006-07-17 15:11:15Z twisti $
 
 */
 
@@ -232,12 +232,8 @@ void classcache_print_statistics(FILE *file) {
 hashtable hashtable_classcache;
 
 #if defined(ENABLE_THREADS)
-#if defined(ENABLE_JVMTI)
-java_objectheader *lock_hashtable_classcache;
-#else
 static java_objectheader *lock_hashtable_classcache;
 #endif
-#endif
 
 
 /*============================================================================*/
@@ -1334,6 +1330,59 @@ bool classcache_add_constraints_for_params(classloader * a,
 }
 #endif /* defined(ENABLE_VERIFIER) */
 
+
+/* classcache_jvmti_GetLoadedClasses *******************************************
+
+   
+*******************************************************************************/
+
+#if defined(ENABLE_JVMTI)
+void classcache_jvmti_GetLoadedClasses(jint *class_count_ptr,
+                                                                          jclass **classes_ptr)
+{
+       classcache_name_entry  *en;
+       classcache_class_entry *clsen;
+       s4                      i;
+       s4                      j;
+
+       CLASSCACHE_LOCK();
+
+       *classes_ptr = GCMNEW(jclass, hashtable_classcache.entries);
+       
+       /* look in every slot of the hashtable */
+
+       for (i = 0, j = 0; i < hashtable_classcache.size; i++) {
+               /* iterate over hashlink */
+
+               for (en = hashtable_classcache.ptr[i]; en != NULL; en = en->hashlink) {
+                       /* filter pseudo classes $NEW$, $NULL$, $ARRAYSTUB$ out */
+
+                       if (en->name->text[0] == '$') {
+                               *class_count_ptr -= 1;
+                               break;
+                       }
+
+                       /* iterate over classes with same name */
+
+                       for (clsen = en->classes; clsen != NULL; clsen = clsen->next) {
+                               /* get only loaded classes */
+
+                               if (clsen->classobj != NULL) {
+                                       assert(j < hashtable_classcache.entries);
+                                       (*classes_ptr)[j] = clsen->classobj;
+                                       j++;
+                               }
+                       }
+               }
+       }
+       CLASSCACHE_UNLOCK();
+
+       *class_count_ptr = j;
+}
+#endif /* defined(ENABLE_JVMTI) */
+
+
 /*============================================================================*/
 /* DEBUG DUMPS                                                                */
 /*============================================================================*/
index ec0dcc3f5da0298c17a5a1566bbd435dcb4ed480..a43210ac4cbfd0ca87a6815c7c6eb4fbf4cd9f74 100644 (file)
@@ -26,9 +26,9 @@
 
    Authors: Edwin Steiner
 
-   Changes:
+   Changes: Christian Thalinger
 
-   $Id: classcache.h 4957 2006-05-26 11:48:10Z edwin $
+   $Id: classcache.h 5147 2006-07-17 15:11:15Z twisti $
 
 */
 
 
 #include <stdio.h>  /* for FILE */
 
+#if defined(ENABLE_JVMTI)
+# include "native/jni.h"
+#endif
+
 #include "vm/hashtable.h"
 #include "vm/references.h"
 
@@ -57,17 +61,6 @@ typedef java_objectheader classloader;
 
 extern hashtable hashtable_classcache;
 
-#if defined(ENABLE_JVMTI)
-#if defined(ENABLE_THREADS)
-# define CLASSCACHE_LOCK()      builtin_monitorenter(lock_hashtable_classcache)
-# define CLASSCACHE_UNLOCK()    builtin_monitorexit(lock_hashtable_classcache)
-#else
-# define CLASSCACHE_LOCK()
-# define CLASSCACHE_UNLOCK()
-#endif
-
-extern java_objectheader *lock_hashtable_classcache;
-#endif 
 
 /* structs ********************************************************************/
 
@@ -150,6 +143,11 @@ bool classcache_add_constraints_for_params(classloader *a,classloader *b,
                                                                                   methodinfo *m);
 #endif
 
+#if defined(ENABLE_JVMTI)
+void classcache_jvmti_GetLoadedClasses(jint *class_count_ptr,
+                                                                          jclass **classes_ptr);
+#endif
+
 #ifndef NDEBUG
 void classcache_debug_dump(FILE *file,utf *only);
 #endif
index f52cea54fa7fa18ef672731354ee0d143fdf0c5f..39de283129b8bc4a704dc91a7e409a11c66bc1f9 100644 (file)
@@ -549,7 +549,7 @@ static void fullversion(void)
 bool vm_create(JavaVMInitArgs *vm_args)
 {
        char *cp;
-       s4    cplen;
+       s4    len;
        s4    opt;
        s4    i, j, k;
        bool  opt_version;
@@ -598,12 +598,12 @@ bool vm_create(JavaVMInitArgs *vm_args)
                strcpy(bootclasspath, cp);
 
        } else {
-               cplen = strlen(CACAO_VM_ZIP) +
+               len = strlen(CACAO_VM_ZIP) +
                        strlen(":") +
                        strlen(CLASSPATH_GLIBJ_ZIP) +
                        strlen("0");
 
-               bootclasspath = MNEW(char, cplen);
+               bootclasspath = MNEW(char, len);
                strcat(bootclasspath, CACAO_VM_ZIP);
                strcat(bootclasspath, ":");
                strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP);
@@ -714,12 +714,12 @@ bool vm_create(JavaVMInitArgs *vm_args)
                case OPT_BOOTCLASSPATH_A:
                        /* append to end of bootclasspath */
 
-                       cplen = strlen(bootclasspath);
+                       len = strlen(bootclasspath);
 
                        bootclasspath = MREALLOC(bootclasspath,
                                                                         char,
-                                                                        cplen,
-                                                                        cplen + strlen(":") +
+                                                                        len,
+                                                                        len + strlen(":") +
                                                                         strlen(opt_arg) + strlen("0"));
 
                        strcat(bootclasspath, ":");
@@ -730,16 +730,16 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        /* prepend in front of bootclasspath */
 
                        cp = bootclasspath;
-                       cplen = strlen(cp);
+                       len = strlen(cp);
 
                        bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
-                                                                cplen + strlen("0"));
+                                                                len + strlen("0"));
 
                        strcpy(bootclasspath, opt_arg);
                        strcat(bootclasspath, ":");
                        strcat(bootclasspath, cp);
 
-                       MFREE(cp, char, cplen);
+                       MFREE(cp, char, len);
                        break;
 
                case OPT_GLIBJ:
@@ -747,12 +747,12 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
                        MFREE(bootclasspath, char, strlen(bootclasspath));
 
-                       cplen = strlen(CACAO_VM_ZIP) +
+                       len = strlen(CACAO_VM_ZIP) +
                                strlen(":") +
                                strlen(opt_arg) +
                                strlen("0");
 
-                       bootclasspath = MNEW(char, cplen);
+                       bootclasspath = MNEW(char, len);
 
                        strcpy(bootclasspath, CACAO_VM_ZIP);
                        strcat(bootclasspath, ":");
@@ -763,21 +763,35 @@ bool vm_create(JavaVMInitArgs *vm_args)
                case OPT_DEBUG:
                        /* this option exists only for compatibility reasons */
                        break;
+
                case OPT_NOAGENT:
                        /* I don't know yet what Xnoagent should do. This is only for 
                           compatiblity with eclipse - motse */
                        break;
+
                case OPT_XRUNJDWP:
-                       agentbypath=jvmti=jdwp=true;
-                       i = strlen(opt_arg)+33;
-                       agentarg = MNEW(char,i);
-                       /* XXX how can I get the <prefix>/lib directory ? */
-                       snprintf(agentarg,i,"/usr/local/cacao/lib/libjdwp.so=%s",&opt_arg[1]);
+                       agentbypath = true;
+                       jvmti       = true;
+                       jdwp        = true;
+
+                       len =
+                               strlen(CACAO_LIBDIR) +
+                               strlen("/libjdwp.so=") +
+                               strlen(opt_arg) +
+                               strlen("0");
+
+                       agentarg = MNEW(char, len);
+
+                       strcpy(agentarg, CACAO_LIBDIR);
+                       strcat(agentarg, "/libjdwp.so=");
+                       strcat(agentarg, &opt_arg[1]);
                        break;
+
                case OPT_AGENTPATH:
                        agentbypath = true;
+
                case OPT_AGENTLIB:
-                       jvmti=true;
+                       jvmti = true;
                        agentarg = opt_arg;
                        break;
 #endif
@@ -1143,7 +1157,10 @@ bool vm_create(JavaVMInitArgs *vm_args)
        if (jvmti) {
                jvmti_set_phase(JVMTI_PHASE_ONLOAD);
                jvmti_agentload(agentarg, agentbypath, &handle, &libname);
-               if (jdwp) MFREE(agentarg,char,strlen(agentarg));
+
+               if (jdwp)
+                       MFREE(agentarg, char, strlen(agentarg));
+
                jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
        }