CACAO
jvmti.c
Go to the documentation of this file.
1 /* src/native/jvmti/jvmti.c - implementation of the Java Virtual Machine
2  Tool Interface functions
3 
4  Copyright (C) 1996-2013
5  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 
7  This file is part of CACAO.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2, or (at
12  your option) any later version.
13 
14  This program is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  02110-1301, USA.
23 
24 */
25 
26 
27 #include "config.h"
28 
29 #include <assert.h>
30 #include <string.h>
31 #include <linux/unistd.h>
32 #include <sys/time.h>
33 #include <stdlib.h>
34 #include <sys/types.h>
35 #include <ltdl.h>
36 #include <unistd.h>
37 #include <sched.h>
38 
39 #include "native/jni.hpp"
40 #include "native/native.hpp"
41 #include "native/jvmti/cacaodbg.h"
42 #include "native/jvmti/jvmti.h"
43 #include "vm/jit/stacktrace.hpp"
44 #include "vm/global.hpp"
45 #include "vm/loader.hpp"
46 #include "vm/jit/builtin.hpp"
47 #include "vm/jit/asmpart.hpp"
48 #include "vm/class.hpp"
49 #include "vm/classcache.hpp"
50 #include "mm/gc.hpp"
51 #include "toolbox/logging.hpp"
52 #include "vm/options.hpp"
53 #include "vm/string.hpp"
54 #include "mm/memory.hpp"
55 #include "threads/mutex.h"
56 #include "threads/thread.hpp"
57 #include "threads/lock.hpp"
58 #include "vm/exceptions.hpp"
59 #include "native/include/java_io_PrintStream.h"
60 #include "native/include/java_io_InputStream.h"
61 #include "native/include/java_lang_Cloneable.h"
62 #include "native/include/java_lang_ThreadGroup.h"
63 #include "native/include/java_lang_VMObject.h"
64 #include "native/include/java_lang_VMSystem.h"
65 #include "native/include/java_lang_VMClass.h"
66 #include "vm/suck.hpp"
67 #include "boehm-gc/include/gc.h"
68 
69 #if defined(ENABLE_THREADS)
70 #include <sched.h>
71 #include <pthread.h>
72 #endif
73 
74 #include "dbg.h"
75 
76 
77 typedef struct _environment environment;
78 static environment *envs=NULL;
79 mutex_t dbgcomlock;
80 
81 extern const struct JNIInvokeInterface _Jv_JNIInvokeInterface;
82 
83 static jvmtiPhase phase;
89 };
90 
94  void *data;
96 };
97 
98 struct _environment {
102  /* table for enabled/disabled jvmtiEvents - first element contains global
103  behavior */
108 };
109 
112 static lt_ptr unload;
113 
114 #define CHECK_PHASE_START if (!(false
115 #define CHECK_PHASE(chkphase) || (phase == chkphase)
116 #define CHECK_PHASE_END )) return JVMTI_ERROR_WRONG_PHASE
117 #define CHECK_CAPABILITY(env,CAP) if(((environment*) \
118  env)->capabilities.CAP == 0) \
119  return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
120 #define CHECK_THREAD_IS_ALIVE(t) if(check_thread_is_alive(t) == \
121  JVMTI_ERROR_THREAD_NOT_ALIVE) \
122  return JVMTI_ERROR_THREAD_NOT_ALIVE;
123 
124 
125 
126 
127 /* check_thread_is_alive *******************************************************
128 
129  checks if the given thread is alive
130 
131 *******************************************************************************/
133  if(t == NULL) return JVMTI_ERROR_THREAD_NOT_ALIVE;
134  if(((java_lang_Thread*) t)->vmThread == NULL)
136  return JVMTI_ERROR_NONE;
137 }
138 
139 /* execute_callback ************************************************************
140 
141  executes the registerd callbacks for the given jvmti event with parameter
142  in the data structure.
143 
144 *******************************************************************************/
147  JNIEnv* jni_env = (JNIEnv*)_Jv_env;
148 
149  fprintf(stderr,"execcallback called (event: %d)\n",e);
150 
151  switch (e) {
152  case JVMTI_EVENT_VM_INIT:
153  if (phase != JVMTI_PHASE_LIVE) return;
157  ((jvmtiEventThreadStart)ec)(data->jvmti_env,jni_env,data->thread);
158  break;
159 
161  if ((phase == JVMTI_PHASE_START) ||
162  (phase == JVMTI_PHASE_LIVE) ||
164  ((jvmtiEventClassFileLoadHook)ec) (data->jvmti_env,
165  jni_env,
166  data->klass,
167  data->object,
168  data->name,
169  data->protection_domain,
170  data->jint1,
171  data->class_data,
172  data->new_class_data_len,
173  data->new_class_data);
174 
175  /* if class data has been modified use it as class data for other agents
176  waiting for the same event */
177  if (data->new_class_data != NULL) {
178  data->jint1 = *(data->new_class_data_len);
179  data->class_data = *(data->new_class_data);
180  }
181  break;
182 
183 
187  ((jvmtiEventClassLoad)ec) (data->jvmti_env, jni_env,
188  data->thread, data->klass);
189  break;
190 
192  if (phase != JVMTI_PHASE_LIVE) return;
193  case JVMTI_EVENT_VM_START:
195  ((jvmtiEventVMStart)ec) (data->jvmti_env, jni_env);
196  break;
197 
199  if ((phase == JVMTI_PHASE_START) ||
200  (phase == JVMTI_PHASE_LIVE) ||
202  ((jvmtiEventNativeMethodBind)ec) (data->jvmti_env, jni_env,
203  data->thread,
204  data->method,
205  data->address,
206  data->new_address_ptr);
207  break;
208 
209 
211  if ((phase == JVMTI_PHASE_START) ||
212  (phase == JVMTI_PHASE_LIVE) ||
214  ((jvmtiEventDynamicCodeGenerated)ec) (data->jvmti_env,
215  data->name,
216  data->address,
217  data->jint1);
218  break;
219 
220 
221 
222  default:
223  if (phase != JVMTI_PHASE_LIVE) return;
224  switch (e) {
225  case JVMTI_EVENT_EXCEPTION:
226  ((jvmtiEventException)ec) (data->jvmti_env, jni_env,
227  data->thread,
228  data->method,
229  data->location,
230  data->object,
231  data->catch_method,
232  data->catch_location);
233  break;
234 
236  ((jvmtiEventExceptionCatch)ec) (data->jvmti_env, jni_env,
237  data->thread,
238  data->method,
239  data->location,
240  data->object);
241  break;
242 
245  ((jvmtiEventSingleStep)ec) (data->jvmti_env, jni_env,
246  data->thread,
247  data->method,
248  data->location);
249  break;
250 
252  ((jvmtiEventFramePop)ec) (data->jvmti_env, jni_env,
253  data->thread,
254  data->method,
255  data->b);
256  break;
257 
258 
260  ((jvmtiEventFieldAccess)ec) (data->jvmti_env, jni_env,
261  data->thread,
262  data->method,
263  data->location,
264  data->klass,
265  data->object,
266  data->field);
267  break;
268 
270 
271  ((jvmtiEventFieldModification)ec) (data->jvmti_env, jni_env,
272  data->thread,
273  data->method,
274  data->location,
275  data->klass,
276  data->object,
277  data->field,
278  data->signature_type,
279  data->value);
280  break;
281 
283  ((jvmtiEventMethodEntry)ec) (data->jvmti_env, jni_env,
284  data->thread,
285  data->method);
286  break;
287 
289  ((jvmtiEventMethodExit)ec) (data->jvmti_env, jni_env,
290  data->thread,
291  data->method,
292  data->b,
293  data->value);
294  break;
295 
297  ((jvmtiEventCompiledMethodLoad)ec) (data->jvmti_env,
298  data->method,
299  data->jint1,
300  data->address,
301  data->jint2,
302  data->map,
303  data->compile_info);
304  break;
305 
307  ((jvmtiEventCompiledMethodUnload)ec) (data->jvmti_env,
308  data->method,
309  data->address);
310  break;
311 
315  ((jvmtiEventDataDumpRequest)ec) (data->jvmti_env);
316  break;
317 
319  ((jvmtiEventMonitorWait)ec) (data->jvmti_env, jni_env,
320  data->thread,
321  data->object,
322  data->jlong);
323  break;
324 
326  ((jvmtiEventMonitorWaited)ec) (data->jvmti_env, jni_env,
327  data->thread,
328  data->object,
329  data->b);
330  break;
331 
332 
335  ((jvmtiEventMonitorContendedEnter)ec) (data->jvmti_env, jni_env,
336  data->thread,
337  data->object);
338  break;
339 
341  ((jvmtiEventObjectFree)ec) (data->jvmti_env, data->jlong);
342  break;
343 
345  ((jvmtiEventVMObjectAlloc)ec) (data->jvmti_env, jni_env,
346  data->thread,
347  data->object,
348  data->klass,
349  data->jlong);
350  break;
351  default:
352  log_text ("unknown event");
353  }
354  break;
355  }
356 }
357 
358 
359 /* dofireEvent ******************************************************************
360 
361  sends event if it is enabled either globally or for some threads
362 
363 *******************************************************************************/
365  environment* env;
366  jvmtiEventModeLL *evm;
367  functionptr ec;
368 
369  env = envs;
370  while (env != NULL) {
372  evm = env->events[e-JVMTI_EVENT_START_ENUM].next;
373  /* test if the event is enable for some threads */
374  while (evm != NULL) {
375  if (evm->mode == JVMTI_ENABLE) {
376  ec = ((functionptr*)
377  (&env->callbacks))[e-JVMTI_EVENT_START_ENUM];
378  if (ec != NULL) {
379  data->jvmti_env=&env->env;
380  execute_callback(e, ec, data);
381  }
382  }
383  evm=evm->next;
384  }
385  } else { /* event enabled globally */
386  data->jvmti_env=&env->env;
387  ec = ((functionptr*)(&env->callbacks))[e-JVMTI_EVENT_START_ENUM];
388  if (ec != NULL) execute_callback(e, ec, data);
389  }
390 
391  env=env->next;
392  }
393 }
394 
395 
396 /* fireEvent ******************************************************************
397 
398  fire event callback with data arguments. This function mainly fills the
399  missing EventData.
400 
401 *******************************************************************************/
403  jthread thread;
404  /* XXX todo : respect event order JVMTI-Spec:Multiple Co-located Events */
405 
406  if (d->ev == JVMTI_EVENT_VM_START)
407  thread = NULL;
408  else
409  thread = jvmti_get_current_thread();
410 
411 
412  d->thread = thread;
413  dofireEvent(d->ev,d);
414 }
415 
416 
417 /* SetEventNotificationMode ****************************************************
418 
419  Control the generation of events
420 
421 *******************************************************************************/
422 
423 static jvmtiError
426 {
427  environment* cacao_env;
428  jvmtiEventModeLL *ll;
429 
434 
435  if(event_thread != NULL) {
436  if (!builtin_instanceof(event_thread,class_java_lang_Thread))
438  CHECK_THREAD_IS_ALIVE(event_thread);
439  }
440 
441  cacao_env = (environment*) env;
442  if ((mode != JVMTI_ENABLE) && (mode != JVMTI_DISABLE))
444 
445  switch (event_type) { /* check capability and set system breakpoint */
448  CHECK_CAPABILITY(env,can_generate_exception_events)
449  break;
451  CHECK_CAPABILITY(env,can_generate_single_step_events)
452  break;
454  CHECK_CAPABILITY(env,can_generate_frame_pop_events)
455  break;
457  CHECK_CAPABILITY(env,can_generate_breakpoint_events)
458  break;
460  CHECK_CAPABILITY(env,can_generate_field_access_events)
461  break;
463  CHECK_CAPABILITY(env,can_generate_field_modification_events)
464  break;
466  CHECK_CAPABILITY(env,can_generate_method_entry_events)
467  break;
469  CHECK_CAPABILITY(env, can_generate_method_exit_events)
470  break;
472  CHECK_CAPABILITY(env, can_generate_native_method_bind_events)
473  break;
476  CHECK_CAPABILITY(env,can_generate_compiled_method_load_events)
477  break;
482  CHECK_CAPABILITY(env,can_generate_monitor_events)
483  break;
486  CHECK_CAPABILITY(env,can_generate_garbage_collection_events)
487  break;
489  CHECK_CAPABILITY(env,can_generate_object_free_events)
490  break;
492  CHECK_CAPABILITY(env,can_generate_vm_object_alloc_events)
493  break;
494  default:
495  /* all other events are required */
496  if ((event_type < JVMTI_EVENT_START_ENUM) ||
497  (event_type > JVMTI_EVENT_END_ENUM))
499  break;
500  }
501 
502 
503  if (event_thread != NULL) {
504  /* thread level control */
505  if ((JVMTI_EVENT_VM_INIT == mode) ||
506  (JVMTI_EVENT_VM_DEATH == mode) ||
507  (JVMTI_EVENT_VM_START == mode) ||
508  (JVMTI_EVENT_THREAD_START == mode) ||
514  ll = &(cacao_env->events[event_type-JVMTI_EVENT_START_ENUM]);
515  while (ll->next != NULL) {
516  ll = ll->next;
517  if (ll->event_thread == event_thread) {
518  ll->mode=mode;
519  return JVMTI_ERROR_NONE;
520  }
521  }
522  ll->next = heap_allocate(sizeof(jvmtiEventModeLL),true,NULL);
523  ll->next->mode=mode;
524  } else {
525  /* global control */
526  cacao_env->events[event_type-JVMTI_EVENT_START_ENUM].mode=mode;
527  }
528 
529 
530  return JVMTI_ERROR_NONE;
531 }
532 
533 /* GetAllThreads ***************************************************************
534 
535  Get all live threads
536 
537 *******************************************************************************/
538 
539 static jvmtiError
541  jthread ** threads_ptr)
542 {
543  threadobject** threads;
544  int i;
545  jvmtiError retval;
546 
550 
551  if ((threads_count_ptr == NULL) || (threads_ptr == NULL))
553 
554  retval=jvmti_get_all_threads(threads_count_ptr, &threads);
555  if (retval != JVMTI_ERROR_NONE) return retval;
556 
557  *threads_ptr =
558  heap_allocate(sizeof(jthread*)* (*threads_count_ptr),true,NULL);
559 
560  for (i=0; i<*threads_count_ptr; i++)
561  (*threads_ptr)[i] = threads[i]->o.thread;
562 
563  return JVMTI_ERROR_NONE;
564 }
565 
566 
567 /* SuspendThread ***************************************************************
568 
569  Suspend specified thread
570 
571 *******************************************************************************/
572 
573 static jvmtiError
575 {
579  CHECK_CAPABILITY(env,can_suspend);
580 
581  if(thread == NULL) return JVMTI_ERROR_INVALID_THREAD;
584  CHECK_THREAD_IS_ALIVE(thread);
585 
586  /* threads_suspend_thread will implement suspend
587  threads_suspend_thread (
588  (threadobject*)((java_lang_Thread*) thread)->vmThread))*/
589 
590  return JVMTI_ERROR_NONE;
591 }
592 
593 /* ResumeThread ***************************************************************
594 
595  Resume a suspended thread
596 
597 *******************************************************************************/
598 
599 static jvmtiError
601 {
605  CHECK_CAPABILITY(env,can_suspend);
606 
607  if(thread == NULL) return JVMTI_ERROR_INVALID_THREAD;
610  CHECK_THREAD_IS_ALIVE(thread);
611 
612  /* threads_resume_thread will implement resume
613  threads_resume_thread (
614  (threadobject*)((java_lang_Thread*) thread)->vmThread))*/
615 
616  return JVMTI_ERROR_NONE;
617 }
618 
619 /* StopThread *****************************************************************
620 
621  Send asynchronous exception to the specified thread. Similar to
622  java.lang.Thread.stop(). Used to kill thread.
623 
624 *******************************************************************************/
625 
626 static jvmtiError
628 {
632  CHECK_CAPABILITY(env,can_signal_thread);
633 
634  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
636 
637  return JVMTI_ERROR_NONE;
638 }
639 
640 /* InterruptThread ************************************************************
641 
642  Interrupt specified thread. Similar to java.lang.Thread.interrupt()
643 
644 *******************************************************************************/
645 
646 static jvmtiError
648 {
652  CHECK_CAPABILITY(env,can_signal_thread)
653 
654 #if defined(ENABLE_THREADS)
657 
658  CHECK_THREAD_IS_ALIVE(thread);
659 
660  threads_thread_interrupt(((java_lang_Thread *) thread)->vmThread);
661 
662 
663  return JVMTI_ERROR_NONE;
664 #else
666 #endif
667 }
668 
669 /* GetThreadInfo ***************************************************************
670 
671  Get thread information. Details of the specified thread are stored in the
672  jvmtiThreadInfo structure.
673 
674 *******************************************************************************/
675 
676 static jvmtiError
678 {
679  utf *name;
681 
682 
686 
687  info_ptr->priority=(jint)th->priority;
688  info_ptr->is_daemon=(jboolean)th->daemon;
689  info_ptr->thread_group=(jthreadGroup)th->group;
690  info_ptr->context_class_loader=(jobject)th->contextClassLoader;
691 
692  name = JavaString(th->name).to_utf8();
693  info_ptr->name=(char*)heap_allocate(sizeof(char)*(UTF_SIZE(name)+1),true,NULL);
694  utf_sprint_convert_to_latin1(info_ptr->name, name);
695 
696  return JVMTI_ERROR_NONE;
697 }
698 
699 /* GetOwnedMonitorInfo *********************************************************
700 
701  Gets all monitors owned by the specified thread
702 
703 *******************************************************************************/
704 
705 static jvmtiError
709 {
710  int i,j,size=20;
711  java_objectheader **om;
712  lock_record_pool_t* lrp;
713  threadobject* t;
714 
718  CHECK_CAPABILITY(env,can_get_owned_monitor_info);
719 
720  if ((owned_monitors_ptr == NULL)||(owned_monitor_count_ptr == NULL))
722 
723  if (thread == NULL) {
725  } else {
728 
729  CHECK_THREAD_IS_ALIVE(thread);
730  t = (threadobject*) thread;
731  }
732 
733 #if defined(ENABLE_THREADS)
734 
735  om=MNEW(java_objectheader*,size);
736 
737  mutex_lock(&lock_global_pool_lock);
738  lrp=lock_global_pool;
739 
740  /* iterate over all lock record pools */
741  while (lrp != NULL) {
742  /* iterate over every lock record in a pool */
743  for (j=0; j<lrp->header.size; j++) {
744  /* if the lock record is owned by the given thread add it to
745  the result array */
746  if(lrp->lr[j].owner == t) {
747  if (i >= size) {
748  MREALLOC(om, java_objectheader*, size, size * 2);
749  size = size * 2;
750  }
751  om[i] = lrp->lr[j].obj;
752  i++;
753  }
754  }
755  lrp=lrp->header.next;
756  }
757 
758  mutex_unlock(&lock_global_pool_lock);
759 
760  *owned_monitors_ptr =
761  heap_allocate(sizeof(java_objectheader*) * i, true, NULL);
762  memcpy(*owned_monitors_ptr, om, i * sizeof(java_objectheader*));
763  MFREE(om, java_objectheader*, size);
764 
765  *owned_monitor_count_ptr = i;
766 
767 #endif
768 
769  return JVMTI_ERROR_NONE;
770 }
771 
772 /* GetCurrentContendedMonitor *************************************************
773 
774  Get the object the specified thread waits for.
775 
776 *******************************************************************************/
777 
778 static jvmtiError
781 {
782  int j;
783  lock_record_pool_t* lrp;
784  threadobject* t;
785  lock_waiter_t* waiter;
786 
790  CHECK_CAPABILITY(env, can_get_current_contended_monitor)
791 
792  if (monitor_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
793  *monitor_ptr=NULL;
794 
795  if (thread == NULL) {
797  } else {
800 
801  CHECK_THREAD_IS_ALIVE(thread);
802  t = (threadobject*) thread;
803  }
804 
805 #if defined(ENABLE_THREADS)
806 
807  mutex_lock(&lock_global_pool_lock);
808 
809  lrp=lock_global_pool;
810 
811  /* iterate over all lock record pools */
812  while ((lrp != NULL) && (*monitor_ptr == NULL)) {
813  /* iterate over every lock record in a pool */
814  for (j=0; j<lrp->header.size; j++) {
815  /* iterate over every thread that is wait on this lock record */
816  waiter = lrp->lr[j].waiters;
817  while (waiter != NULL)
818  /* if the waiting thread equals to the given thread we are
819  done. Stop iterateting. */
820  if(waiter->waiter == t) {
821  *monitor_ptr=lrp->lr[j].obj;
822  break;
823  }
824  }
825  lrp=lrp->header.next;
826  }
827 
828  mutex_unlock(&lock_global_pool_lock);
829 
830 
831 #endif
832  return JVMTI_ERROR_NONE;
833 }
834 
835 typedef struct {
836  jvmtiStartFunction sf;
838  void* arg;
839 } runagentparam;
840 
841 
842 static void *threadstartup(void *t) {
843  runagentparam *rap = (runagentparam*)t;
844  rap->sf(rap->jvmti_env,(JNIEnv*)&_Jv_JNINativeInterface,rap->arg);
845  return NULL;
846 }
847 
848 /* RunAgentThread *************************************************************
849 
850  Starts the execution of an agent thread of the specified native function
851  within the specified thread
852 
853 *******************************************************************************/
854 
855 static jvmtiError
856 RunAgentThread (jvmtiEnv * env, jthread thread, jvmtiStartFunction proc,
857  const void *arg, jint priority)
858 {
859  pthread_attr_t threadattr;
860  struct sched_param sp;
861  runagentparam rap;
862 
866 
867  if((thread != NULL)&&(!builtin_instanceof(thread,class_java_lang_Thread)))
869  if (proc == NULL) return JVMTI_ERROR_NULL_POINTER;
870  if ((priority < JVMTI_THREAD_MIN_PRIORITY) ||
871  (priority > JVMTI_THREAD_MAX_PRIORITY))
873 
874  /* XXX: Threads started with this function should not be visible to
875  Java programming language queries but are included in JVM TI queries */
876 
877  rap.sf = proc;
878  rap.arg = (void*)arg;
879  rap.jvmti_env = env;
880 
881 #if defined(ENABLE_THREADS)
882  pthread_attr_init(&threadattr);
883  pthread_attr_setdetachstate(&threadattr, PTHREAD_CREATE_DETACHED);
884  if (priority == JVMTI_THREAD_MIN_PRIORITY) {
885  sp.__sched_priority = sched_get_priority_min(SCHED_FIFO);
886  }
887  if (priority == JVMTI_THREAD_MAX_PRIORITY) {
888  sp.__sched_priority = sched_get_priority_min(SCHED_FIFO);
889  }
890  pthread_attr_setschedparam(&threadattr,&sp);
891  if (pthread_create(&((threadobject*)
892  thread)->impl.tid, &threadattr, &threadstartup, &rap)) {
893  log_text("pthread_create failed");
894  assert(0);
895  }
896 #endif
897 
898  return JVMTI_ERROR_NONE;
899 }
900 
901 
902 /* GetTopThreadGroups *********************************************************
903 
904  Get all top-level thread groups in the VM.
905 
906 *******************************************************************************/
907 
908 static jvmtiError
909 GetTopThreadGroups (jvmtiEnv * env, jint * group_count_ptr,
910  jthreadGroup ** groups_ptr)
911 {
912  jint threads_count_ptr;
913  threadobject *threads_ptr;
914  int i,j,x,size=20;
915  jthreadGroup **tg,*ttgp;
916 
920 
921  if ((groups_ptr == NULL) || (group_count_ptr == NULL))
923 
924 #if defined(ENABLE_THREADS)
925  tg = MNEW(jthreadGroup*,size);
926  x = 0;
927  if (JVMTI_ERROR_NONE!=GetAllThreads(env,&threads_count_ptr,(jthread**)&threads_ptr))
928  return JVMTI_ERROR_INTERNAL;
929 
930  for (i=0;i<threads_count_ptr;i++){
931  if (threads_ptr[i].o.thread->group == NULL) {
932  log_text("threadgroup not set");
933  return JVMTI_ERROR_INTERNAL;
934  }
935  ttgp = (jthreadGroup*)((java_lang_ThreadGroup*)threads_ptr[i].o.thread->group)->parent;
936  if (ttgp == NULL) {
937  j=0;
938  while((j<x)&&(tg[j]!=ttgp)) { /* unique ? */
939  j++;
940  }
941  if (j == x) {
942  if (x >= size){
943  MREALLOC(tg,jthreadGroup*,size,size*2);
944  size=size*2;
945  }
946  tg[x]=ttgp;
947  x++;
948  }
949  }
950  }
951 
952  *groups_ptr = heap_allocate(sizeof(jthreadGroup*)*x,true,NULL);
953  memcpy(*groups_ptr,tg,x*sizeof(jthreadGroup*));
954  MFREE(tg,jthreadGroup*,size);
955 
956  *group_count_ptr = x;
957 
958 #else
960 #endif
961  return JVMTI_ERROR_NONE;
962 }
963 
964 
965 /* GetThreadGroupInfo *********************************************************
966 
967  Get information about the specified thread group.
968 
969 *******************************************************************************/
970 
971 static jvmtiError
973  jvmtiThreadGroupInfo * info_ptr)
974 {
975  int size;
976  char* name;
977  java_lang_ThreadGroup* grp;
978 
982 
983  if (info_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
986 
987  grp = (java_lang_ThreadGroup*)group;
988 
989  info_ptr->parent = (jthreadGroup)
991  (jclass)grp->header.vftbl->class,
992  (java_lang_Cloneable*) &grp->parent);
993 
994  name = JavaString((java_objectheader*)grp->name).to_chars();
995  size = strlen(name);
996  info_ptr->name=heap_allocate(size*sizeof(char),true,NULL);
997  strncpy(info_ptr->name,name,size);
998  info_ptr->max_priority= (jint)grp->maxpri;
999  info_ptr->is_daemon= (jboolean)grp->daemon_flag;
1000 
1001  return JVMTI_ERROR_NONE;
1002 }
1003 
1004 
1005 /* GetThreadGroupChildren *****************************************************
1006 
1007  Get the live threads and active subgroups in this thread group.
1008 
1009 *******************************************************************************/
1010 
1011 static jvmtiError
1013  jint * thread_count_ptr, jthread ** threads_ptr,
1014  jint * group_count_ptr, jthreadGroup ** groups_ptr)
1015 {
1016  java_lang_ThreadGroup* tgp;
1017 
1021 
1022  if ((thread_count_ptr == NULL) || (threads_ptr == NULL) ||
1023  (group_count_ptr == NULL) || (groups_ptr == NULL))
1024  return JVMTI_ERROR_NULL_POINTER;
1025 
1028 
1029  tgp = (java_lang_ThreadGroup*)group;
1030 
1031  *thread_count_ptr = (jint)tgp->threads->elementCount;
1032 
1033  *threads_ptr =
1034  heap_allocate(sizeof(jthread)*(*thread_count_ptr),true,NULL);
1035 
1036  memcpy(*threads_ptr, &tgp->threads->elementData,
1037  (*thread_count_ptr)*sizeof(java_objectarray*));
1038 
1039  *group_count_ptr = (jint) tgp->groups->elementCount;
1040 
1041  *groups_ptr =
1042  heap_allocate(sizeof(jthreadGroup)*(*group_count_ptr),true,NULL);
1043 
1044  memcpy(*groups_ptr, &tgp->threads->elementData,
1045  (*group_count_ptr)*sizeof(jthreadGroup*));
1046 
1047  return JVMTI_ERROR_NONE;
1048 }
1049 
1050 
1051 /* getcacaostacktrace *********************************************************
1052 
1053  Helper function that retrives stack trace for specified thread.
1054 
1055 *******************************************************************************/
1056 
1057 static jvmtiError getcacaostacktrace(stacktracebuffer** trace, jthread thread) {
1058  threadobject *t;
1059  bool resume;
1060 
1061  if (thread == NULL) {
1063  *trace = stacktrace_create(t);
1064  } else {
1065  t = (threadobject*)((java_lang_Thread*)thread)->vmThread;
1066 /* if (t != jvmti_get_current_thread())
1067  resume = threads_suspend_thread_if_running(thread);
1068 
1069  *trace = stacktrace_create(thread );
1070 
1071  if (resume)
1072  threads_resume_thread ( thread );*/
1073  }
1074 
1075  return JVMTI_ERROR_NONE;
1076 }
1077 
1078 
1079 /* GetFrameCount **************************************************************
1080 
1081 
1082  Get the number of frames in the specified thread's stack. Calling function
1083  has to take care of suspending/resuming thread.
1084 
1085 *******************************************************************************/
1086 
1087 static jvmtiError
1088 GetFrameCount (jvmtiEnv * env, jthread thread, jint * count_ptr)
1089 {
1090  stacktracebuffer* trace;
1091  jvmtiError er;
1092 
1096 
1097  if (thread != NULL){
1100 
1101  CHECK_THREAD_IS_ALIVE(thread);
1102  }
1103 
1104  if(count_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
1105 
1106  er = getcacaostacktrace(&trace, thread);
1107  if (er == JVMTI_ERROR_NONE) {
1108  heap_free(trace);
1109  return er;
1110  }
1111 
1112  *count_ptr = trace->used;
1113 
1114  heap_free(trace);
1115  return JVMTI_ERROR_NONE;
1116 }
1117 
1118 
1119 /* GetThreadState **************************************************************
1120 
1121  Get the state of a thread.
1122 
1123 *******************************************************************************/
1124 
1125 static jvmtiError
1126 GetThreadState (jvmtiEnv * env, jthread thread, jint * thread_state_ptr)
1127 {
1128  java_lang_Thread* th = (java_lang_Thread*)thread;
1129  threadobject* t = (threadobject*)th->vmThread;
1130 
1134 
1137 
1138  if (thread_state_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
1139 
1140  *thread_state_ptr = 0;
1141 #if defined(ENABLE_THREADS)
1142  if((th->vmThread == NULL)&&(th->group == NULL)) { /* alive ? */
1143  /* not alive */
1144  if (((threadobject*)th->vmThread)->tid == 0)
1145  *thread_state_ptr = JVMTI_THREAD_STATE_TERMINATED;
1146  } else {
1147  /* alive */
1148  *thread_state_ptr = JVMTI_THREAD_STATE_ALIVE;
1149  if (t->interrupted) *thread_state_ptr |= JVMTI_THREAD_STATE_INTERRUPTED;
1150  /* XXX todo - info not available */
1151  if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_SUSPENDED;
1152  if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_IN_NATIVE;
1153  if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_RUNNABLE;
1154  if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
1155  if (false /* t->ee.waiting ? */) *thread_state_ptr |= JVMTI_THREAD_STATE_WAITING;
1156  if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
1157  if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
1158  if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_IN_OBJECT_WAIT;
1159  if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_PARKED;
1160  if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_SLEEPING;
1161  }
1162 #else
1163  return JVMTI_ERROR_INTERNAL;
1164 #endif
1165 
1166  return JVMTI_ERROR_NONE;
1167 }
1168 
1169 
1170 /* GetFrameLocation ************************************************************
1171 
1172  Get the location of the instruction currently executing
1173 
1174 *******************************************************************************/
1175 
1176 static jvmtiError
1178  jmethodID * method_ptr, jlocation * location_ptr)
1179 {
1180  stackframeinfo_t *sfi;
1181  int i;
1182  threadobject* th;
1183 
1187 
1188  if (thread == NULL) {
1189  th = jvmti_get_current_thread();
1190  } else {
1193 
1194  CHECK_THREAD_IS_ALIVE(thread);
1195  th = (threadobject*) ((java_lang_Thread*)thread)->vmThread;
1196  }
1197 
1198  if (depth < 0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1199 
1200  if ((method_ptr == NULL)&&(location_ptr == NULL))
1201  return JVMTI_ERROR_NULL_POINTER;
1202 
1203  sfi = th->_stackframeinfo;
1204 
1205  i = 0;
1206  while ((sfi != NULL) && (i<depth)) {
1207  sfi = sfi->prev;
1208  i++;
1209  }
1210 
1211  if (i>depth) return JVMTI_ERROR_NO_MORE_FRAMES;
1212 
1213  *method_ptr=(jmethodID)sfi->code->m;
1214  *location_ptr = 0; /* todo: location MachinePC not avilable - Linenumber not expected */
1215 
1216  return JVMTI_ERROR_NONE;
1217 }
1218 
1219 
1220 /* NotifyFramePop *************************************************************
1221 
1222 
1223 
1224 *******************************************************************************/
1225 
1226 static jvmtiError
1228 {
1232  CHECK_CAPABILITY(env,can_generate_frame_pop_events)
1233 
1234  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
1235  return JVMTI_ERROR_NONE;
1236 }
1237 
1238 /* GetLocalObject *************************************************************
1239 
1240 
1241 
1242 *******************************************************************************/
1243 
1244 static jvmtiError
1246  jthread thread, jint depth, jint slot, jobject * value_ptr)
1247 {
1251  CHECK_CAPABILITY(env,can_access_local_variables)
1252 
1253  log_text ("JVMTI-Call: TBD-OPTIONAL IMPLEMENT ME!!!");
1254  return JVMTI_ERROR_NONE;
1255 }
1256 
1257 /* GetLocalInt ****************************************************************
1258 
1259 
1260 
1261 *******************************************************************************/
1262 
1263 static jvmtiError
1265  jthread thread, jint depth, jint slot, jint * value_ptr)
1266 {
1270  CHECK_CAPABILITY(env,can_access_local_variables)
1271  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1272  return JVMTI_ERROR_NONE;
1273 }
1274 
1275 /* *****************************************************************************
1276 
1277 
1278 
1279 *******************************************************************************/
1280 
1281 static jvmtiError
1283  jlong * value_ptr)
1284 {
1288  CHECK_CAPABILITY(env,can_access_local_variables)
1289 
1290  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1291  return JVMTI_ERROR_NONE;
1292 }
1293 
1294 
1295 /* *****************************************************************************
1296 
1297 
1298 
1299 *******************************************************************************/
1300 
1301 static jvmtiError
1303  jfloat * value_ptr)
1304 {
1308  CHECK_CAPABILITY(env,can_access_local_variables)
1309 
1310  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1311  return JVMTI_ERROR_NONE;
1312 }
1313 
1314 
1315 /* *****************************************************************************
1316 
1317 
1318 
1319 *******************************************************************************/
1320 
1321 static jvmtiError
1323  jdouble * value_ptr)
1324 {
1328  CHECK_CAPABILITY(env,can_access_local_variables)
1329 
1330  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1331  return JVMTI_ERROR_NONE;
1332 }
1333 
1334 
1335 /* *****************************************************************************
1336 
1337 
1338 
1339 *******************************************************************************/
1340 
1341 static jvmtiError
1343  jobject value)
1344 {
1348  CHECK_CAPABILITY(env,can_access_local_variables)
1349 
1350  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1351  return JVMTI_ERROR_NONE;
1352 }
1353 
1354 
1355 /* *****************************************************************************
1356 
1357 
1358 
1359 *******************************************************************************/
1360 
1361 static jvmtiError
1363  jint value)
1364 {
1368  CHECK_CAPABILITY(env,can_access_local_variables)
1369 
1370  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1371  return JVMTI_ERROR_NONE;
1372 }
1373 
1374 
1375 /* *****************************************************************************
1376 
1377 
1378 
1379 *******************************************************************************/
1380 
1381 static jvmtiError
1383  jlong value)
1384 {
1388  CHECK_CAPABILITY(env,can_access_local_variables)
1389 
1390  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1391  return JVMTI_ERROR_NONE;
1392 }
1393 
1394 
1395 /* *****************************************************************************
1396 
1397 
1398 
1399 *******************************************************************************/
1400 
1401 static jvmtiError
1403  jfloat value)
1404 {
1408  CHECK_CAPABILITY(env,can_access_local_variables)
1409 
1410  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1411  return JVMTI_ERROR_NONE;
1412 }
1413 
1414 
1415 /* *****************************************************************************
1416 
1417 
1418 
1419 *******************************************************************************/
1420 
1421 static jvmtiError
1423  jdouble value)
1424 {
1428  CHECK_CAPABILITY(env,can_access_local_variables)
1429 
1430  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1431  return JVMTI_ERROR_NONE;
1432 }
1433 
1434 
1435 /* CreateRawMonitor ***********************************************************
1436 
1437  This function creates a new raw monitor.
1438 
1439 *******************************************************************************/
1440 
1441 static jvmtiError
1442 CreateRawMonitor (jvmtiEnv * env, const char *name,
1443  jrawMonitorID * monitor_ptr)
1444 {
1445  struct _jrawMonitorID *monitor = (struct _jrawMonitorID*) monitor_ptr;
1446 
1451 
1452  if ((name == NULL) || (monitor_ptr == NULL))
1453  return JVMTI_ERROR_NULL_POINTER;
1454 
1455 #if defined(ENABLE_THREADS)
1456  monitor->name = JavaString::from_utf8(name);
1457 #else
1458  log_text ("CreateRawMonitor not supported");
1459 #endif
1460 
1461  return JVMTI_ERROR_NONE;
1462 }
1463 
1464 
1465 /* DestroyRawMonitor **********************************************************
1466 
1467  This function destroys a raw monitor.
1468 
1469 *******************************************************************************/
1470 
1471 static jvmtiError
1473 {
1478 
1479  if (!builtin_instanceof((java_objectheader*)monitor->name,class_java_lang_String))
1481 
1482 #if defined(ENABLE_THREADS)
1483  if (!lock_is_held_by_current_thread((java_objectheader*)monitor->name))
1485 
1486  lock_monitor_exit((java_objectheader *) monitor->name);
1487 
1488  heap_free(monitor);
1489 #else
1490  log_text ("DestroyRawMonitor not supported");
1491 #endif
1492 
1493  return JVMTI_ERROR_NONE;
1494 }
1495 
1496 
1497 /* RawMonitorEnter ************************************************************
1498 
1499  Gain exclusive ownership of a raw monitor
1500 
1501 *******************************************************************************/
1502 
1503 static jvmtiError
1505 {
1506  if (!builtin_instanceof((java_objectheader*)monitor->name,class_java_lang_String))
1508 
1509 #if defined(ENABLE_THREADS)
1510  lock_monitor_enter((java_objectheader *) monitor->name);
1511 #else
1512  log_text ("RawMonitorEnter not supported");
1513 #endif
1514 
1515  return JVMTI_ERROR_NONE;
1516 }
1517 
1518 
1519 /* RawMonitorExit *************************************************************
1520 
1521  Release raw monitor
1522 
1523 *******************************************************************************/
1524 
1525 static jvmtiError
1527 {
1528  if (!builtin_instanceof((java_objectheader*)monitor->name,class_java_lang_String))
1530 
1531 #if defined(ENABLE_THREADS)
1532  /* assure current thread owns this monitor */
1533  if (!lock_is_held_by_current_thread((java_objectheader*)monitor->name))
1535 
1536  lock_monitor_exit((java_objectheader *) monitor->name);
1537 #else
1538  log_text ("RawMonitorExit not supported");
1539 #endif
1540 
1541  return JVMTI_ERROR_NONE;
1542 }
1543 
1544 
1545 /* RawMonitorWait *************************************************************
1546 
1547  Wait for notification of the raw monitor.
1548 
1549 *******************************************************************************/
1550 
1551 static jvmtiError
1552 RawMonitorWait (jvmtiEnv * env, jrawMonitorID monitor, jlong millis)
1553 {
1554  if (!builtin_instanceof((java_objectheader*)monitor->name,class_java_lang_String))
1556 
1557 #if defined(ENABLE_THREADS)
1558  /* assure current thread owns this monitor */
1559  if (!lock_is_held_by_current_thread((java_objectheader*)monitor->name))
1561 
1562  lock_wait_for_object(&monitor->name->header, millis,0);
1563  if (builtin_instanceof((java_objectheader*)exceptionptr, load_class_bootstrap(Utf8String::from_utf8("java/lang/InterruptedException"))))
1564  return JVMTI_ERROR_INTERRUPT;
1565 
1566 #else
1567  log_text ("RawMonitorWait not supported");
1568 #endif
1569 
1570  return JVMTI_ERROR_NONE;
1571 }
1572 
1573 
1574 /* RawMonitorNotify ***********************************************************
1575 
1576  Notify one thread waiting on the given monitor.
1577 
1578 *******************************************************************************/
1579 
1580 static jvmtiError
1582 {
1583  if (!builtin_instanceof((java_objectheader*)monitor->name,class_java_lang_String))
1585 
1586 #if defined(ENABLE_THREADS)
1587  /* assure current thread owns this monitor */
1588  if (!lock_is_held_by_current_thread((java_objectheader*)monitor->name))
1590 
1591  lock_notify_object((java_objectheader*)&monitor->name);
1592 #else
1593  log_text ("RawMonitorNotify not supported");
1594 #endif
1595 
1596  return JVMTI_ERROR_NONE;
1597 }
1598 
1599 
1600 /* RawMonitorNotifyAll *********************************************************
1601 
1602  Notify all threads waiting on the given monitor.
1603 
1604 *******************************************************************************/
1605 
1606 static jvmtiError
1608 {
1609  if (!builtin_instanceof((java_objectheader*)monitor->name,class_java_lang_String))
1611 
1612 #if defined(ENABLE_THREADS)
1613  /* assure current thread owns this monitor */
1614  if (!lock_is_held_by_current_thread((java_objectheader*)monitor->name))
1616 
1617  lock_notify_all_object((java_objectheader*)&monitor->name);
1618 #else
1619  log_text ("RawMonitorNotifyAll not supported");
1620 #endif
1621 
1622  return JVMTI_ERROR_NONE;
1623 }
1624 
1625 
1626 /* SetBreakpoint **************************************************************
1627 
1628 
1629 
1630 *******************************************************************************/
1631 
1632 static jvmtiError
1634 {
1638  CHECK_CAPABILITY(env,can_generate_breakpoint_events)
1639 
1640  /* addbrkpt */
1641  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1642  return JVMTI_ERROR_NONE;
1643 }
1644 
1645 
1646 /* *****************************************************************************
1647 
1648 
1649 
1650 *******************************************************************************/
1651 
1652 static jvmtiError
1654 {
1658  CHECK_CAPABILITY(env,can_generate_breakpoint_events)
1659 
1660  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1661  return JVMTI_ERROR_NONE;
1662 }
1663 
1664 
1665 /* SetFieldAccessWatch ********************************************************
1666 
1667 
1668 
1669 *******************************************************************************/
1670 
1671 static jvmtiError
1673 {
1677  CHECK_CAPABILITY(env,can_generate_field_access_events)
1678 
1679  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1680  return JVMTI_ERROR_NONE;
1681 }
1682 
1683 
1684 /* *****************************************************************************
1685 
1686 
1687 
1688 *******************************************************************************/
1689 
1690 static jvmtiError
1692 {
1696  CHECK_CAPABILITY(env,can_generate_field_access_events)
1697 
1698  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1699  return JVMTI_ERROR_NONE;
1700 }
1701 
1702 
1703 /* *****************************************************************************
1704 
1705 
1706 
1707 *******************************************************************************/
1708 
1709 static jvmtiError
1711 {
1715  CHECK_CAPABILITY(env,can_generate_field_modification_events)
1716 
1717  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1718  return JVMTI_ERROR_NONE;
1719 }
1720 
1721 
1722 /* *****************************************************************************
1723 
1724 
1725 
1726 *******************************************************************************/
1727 
1728 static jvmtiError
1730 {
1734  CHECK_CAPABILITY(env,can_generate_field_modification_events)
1735 
1736  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
1737  return JVMTI_ERROR_NONE;
1738 }
1739 
1740 
1741 /* Allocate ********************************************************************
1742 
1743  Allocate an area of memory through the JVM TI allocator. The allocated
1744  memory should be freed with Deallocate
1745 
1746 *******************************************************************************/
1747 
1748 static jvmtiError
1749 Allocate (jvmtiEnv * env, jlong size, unsigned char **mem_ptr)
1750 {
1751 
1752  if (mem_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
1753  if (size < 0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1754 
1755  *mem_ptr = heap_allocate(sizeof(size),true,NULL);
1756  if (*mem_ptr == NULL)
1758  else
1759  return JVMTI_ERROR_NONE;
1760 
1761 }
1762 
1763 
1764 /* Deallocate ******************************************************************
1765 
1766  Deallocate mem using the JVM TI allocator.
1767 
1768 *******************************************************************************/
1769 
1770 static jvmtiError
1771 Deallocate (jvmtiEnv * env, unsigned char *mem)
1772 {
1773  /* let Boehm GC do the job */
1774  heap_free(mem);
1775  return JVMTI_ERROR_NONE;
1776 }
1777 
1778 
1779 /* GetClassSignature ************************************************************
1780 
1781  For the class indicated by klass, return the JNI type signature and the
1782  generic signature of the class.
1783 
1784 *******************************************************************************/
1785 
1786 static jvmtiError
1787 GetClassSignature (jvmtiEnv * env, jclass klass, char **signature_ptr,
1788  char **generic_ptr)
1789 {
1794 
1795  if (klass == NULL) return JVMTI_ERROR_INVALID_CLASS;
1798 
1799  if (signature_ptr != NULL) {
1800  *signature_ptr = (char*)
1801  heap_allocate(sizeof(char) *
1802  UTF_SIZE(((classinfo*)klass)->name)+1,true,NULL);
1803 
1804  utf_sprint_convert_to_latin1(*signature_ptr,((classinfo*)klass)->name);
1805  }
1806 
1807  if (generic_ptr!= NULL)
1808  *generic_ptr = NULL;
1809 
1810  return JVMTI_ERROR_NONE;
1811 }
1812 
1813 /* GetClassStatus *************************************************************
1814 
1815  Get status of the class.
1816 
1817 *******************************************************************************/
1818 
1819 static jvmtiError
1820 GetClassStatus (jvmtiEnv * env, jclass klass, jint * status_ptr)
1821 {
1822  classinfo *c;
1827 
1828  if (!builtin_instanceof((java_objectheader*)klass,class_java_lang_Class))
1829  return JVMTI_ERROR_INVALID_CLASS;
1830 
1831  if (status_ptr == NULL)
1832  return JVMTI_ERROR_NULL_POINTER;
1833 
1834  c = (classinfo*)klass;
1835  *status_ptr = 0;
1836 
1837 /* if (c) *status_ptr = *status_ptr | JVMTI_CLASS_STATUS_VERIFIED; ? */
1838  if (c->state & CLASS_LINKED)
1839  *status_ptr = *status_ptr | JVMTI_CLASS_STATUS_PREPARED;
1840 
1841  if (c->state & CLASS_INITIALIZED)
1842  *status_ptr = *status_ptr | JVMTI_CLASS_STATUS_INITIALIZED;
1843 
1844  if (c->state & CLASS_ERROR)
1845  *status_ptr = *status_ptr | JVMTI_CLASS_STATUS_ERROR;
1846 
1847  if (c->vftbl->arraydesc != NULL)
1848  *status_ptr = *status_ptr | JVMTI_CLASS_STATUS_ARRAY;
1849 
1850  if (Java_java_lang_VMClass_isPrimitive(NULL,NULL,(struct java_lang_Class*)c))
1851  *status_ptr = *status_ptr | JVMTI_CLASS_STATUS_PRIMITIVE;
1852 
1853  return JVMTI_ERROR_NONE;
1854 }
1855 
1856 
1857 /* GetSourceFileName **********************************************************
1858 
1859  For the class indicated by klass, return the source file name.
1860 
1861 *******************************************************************************/
1862 
1863 static jvmtiError
1864 GetSourceFileName (jvmtiEnv * env, jclass klass, char **source_name_ptr)
1865 {
1866  int size;
1867 
1872  CHECK_CAPABILITY(env,can_get_source_file_name)
1873 
1874  if ((klass == NULL)||(source_name_ptr == NULL))
1875  return JVMTI_ERROR_NULL_POINTER;
1876 
1877  size = UTF_SIZE(((classinfo*)klass)->sourcefile)+1;
1878 
1879  *source_name_ptr = (char*) heap_allocate(sizeof(char)* size,true,NULL);
1880 
1881  memcpy(*source_name_ptr,(UTF_TEXT((classinfo*)klass)->sourcefile), size);
1882  (*source_name_ptr)[size]='\0';
1883 
1884  return JVMTI_ERROR_NONE;
1885 }
1886 
1887 
1888 /* GetClassModifiers **********************************************************
1889 
1890  For class klass return the access flags
1891 
1892 *******************************************************************************/
1893 
1894 static jvmtiError
1895 GetClassModifiers (jvmtiEnv * env, jclass klass, jint * modifiers_ptr)
1896 {
1901 
1902  if (modifiers_ptr == NULL)
1903  return JVMTI_ERROR_NULL_POINTER;
1904 
1905  if (!builtin_instanceof((java_objectheader*)klass,class_java_lang_Class))
1907 
1908  *modifiers_ptr = (jint) ((classinfo*)klass)->flags;
1909 
1910  return JVMTI_ERROR_NONE;
1911 }
1912 
1913 
1914 /* GetClassMethods *************************************************************
1915 
1916  For class klass return a count of methods and a list of method IDs
1917 
1918 *******************************************************************************/
1919 
1920 static jvmtiError
1921 GetClassMethods (jvmtiEnv * env, jclass klass, jint * method_count_ptr,
1922  jmethodID ** methods_ptr)
1923 {
1924  int i;
1925 
1930 
1931  if ((klass == NULL)||(methods_ptr == NULL)||(method_count_ptr == NULL))
1932  return JVMTI_ERROR_NULL_POINTER;
1933 
1934  if (!builtin_instanceof((java_objectheader*)klass,class_java_lang_Class))
1936 
1937  *method_count_ptr = (jint)((classinfo*)klass)->methodscount;
1938  *methods_ptr = (jmethodID*)
1939  heap_allocate(sizeof(jmethodID) * (*method_count_ptr),true,NULL);
1940 
1941  for (i=0; i<*method_count_ptr;i++)
1942  (*methods_ptr)[i]=(jmethodID) &(((classinfo*)klass)->methods[i]);
1943 
1944  return JVMTI_ERROR_NONE;
1945 }
1946 
1947 
1948 /* GetClassFields *************************************************************
1949 
1950  For the class indicated by klass, return a count of fields and a list of
1951  field IDs.
1952 
1953 *******************************************************************************/
1954 
1955 static jvmtiError
1956 GetClassFields (jvmtiEnv * env, jclass klass, jint * field_count_ptr,
1957  jfieldID ** fields_ptr)
1958 {
1963 
1964  if ((klass == NULL)||(fields_ptr == NULL)||(field_count_ptr == NULL))
1965  return JVMTI_ERROR_NULL_POINTER;
1966 
1967  *field_count_ptr = (jint)((classinfo*)klass)->fieldscount;
1968  *fields_ptr = (jfieldID*)
1969  heap_allocate(sizeof(jfieldID) * (*field_count_ptr),true,NULL);
1970 
1971  memcpy (*fields_ptr, ((classinfo*)klass)->fields,
1972  sizeof(jfieldID) * (*field_count_ptr));
1973 
1974  return JVMTI_ERROR_NONE;
1975 }
1976 
1977 
1978 /* GetImplementedInterfaces ***************************************************
1979 
1980  Return the direct super-interfaces of this class.
1981 
1982 *******************************************************************************/
1983 
1984 static jvmtiError
1986  jint * interface_count_ptr,
1987  jclass ** interfaces_ptr)
1988 {
1989  int i;
1990  classref_or_classinfo *interfaces;
1991  classinfo *tmp;
1992 
1997 
1998  if ((interfaces_ptr == NULL) || (interface_count_ptr == NULL))
1999  return JVMTI_ERROR_NULL_POINTER;
2000 
2001  if (!builtin_instanceof((java_objectheader*)klass,class_java_lang_Class))
2003 
2004 
2005  *interface_count_ptr = (jint)((classinfo*)klass)->interfacescount;
2006  *interfaces_ptr = heap_allocate(sizeof(jclass*) * (*interface_count_ptr),true,NULL);
2007 
2008  interfaces = ((classinfo*)klass)->interfaces;
2009  for (i=0; i<*interface_count_ptr; i++) {
2010  if (interfaces[i].is_classref())
2011  tmp = load_class_bootstrap(interfaces[i].ref->name);
2012  else
2013  tmp = interfaces[i].cls;
2014 
2015  *interfaces_ptr[i]=tmp;
2016  }
2017 
2018  return JVMTI_ERROR_NONE;
2019 }
2020 
2021 
2022 /* IsInterface ****************************************************************
2023 
2024  Determines whether a class object reference represents an interface.
2025 
2026 *******************************************************************************/
2027 
2028 static jvmtiError
2029 IsInterface (jvmtiEnv * env, jclass klass, jboolean * is_interface_ptr)
2030 {
2035 
2036  if ((klass == NULL)||(is_interface_ptr == NULL))
2037  return JVMTI_ERROR_NULL_POINTER;
2038 
2039  *is_interface_ptr = (((classinfo*)klass)->flags & ACC_INTERFACE);
2040 
2041  return JVMTI_ERROR_NONE;
2042 }
2043 
2044 /* IsArrayClass ***************************************************************
2045 
2046  Determines whether a class object reference represents an array.
2047 
2048 *******************************************************************************/
2049 
2050 static jvmtiError
2051 IsArrayClass (jvmtiEnv * env, jclass klass, jboolean * is_array_class_ptr)
2052 {
2057 
2058  if (is_array_class_ptr == NULL)
2059  return JVMTI_ERROR_NULL_POINTER;
2060 
2061  *is_array_class_ptr = ((classinfo*)klass)->vftbl->arraydesc != NULL;
2062 
2063  return JVMTI_ERROR_NONE;
2064 }
2065 
2066 
2067 /* GetClassLoader *************************************************************
2068 
2069  For the class indicated by klass, return via classloader_ptr a reference to
2070  the class loader for the class.
2071 
2072 *******************************************************************************/
2073 
2074 static jvmtiError
2075 GetClassLoader (jvmtiEnv * env, jclass klass, jobject * classloader_ptr)
2076 {
2081 
2082  if ((klass == NULL)||(classloader_ptr == NULL))
2083  return JVMTI_ERROR_NULL_POINTER;
2084 
2085  *classloader_ptr = (jobject)((classinfo*)klass)->classloader;
2086 
2087  return JVMTI_ERROR_NONE;
2088 }
2089 
2090 
2091 /* GetObjectHashCode **********************************************************
2092 
2093  Return hash code for object object
2094 
2095 *******************************************************************************/
2096 
2097 static jvmtiError
2098 GetObjectHashCode (jvmtiEnv * env, jobject object, jint * hash_code_ptr)
2099 {
2104 
2105  if (hash_code_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
2108 
2109  *hash_code_ptr = Java_java_lang_VMSystem_identityHashCode(NULL,NULL,(struct java_lang_Object*)object);
2110 
2111  return JVMTI_ERROR_NONE;
2112 }
2113 
2114 
2115 /* *****************************************************************************
2116 
2117 
2118 
2119 *******************************************************************************/
2120 
2121 static jvmtiError
2123  jvmtiMonitorUsage * info_ptr)
2124 {
2128  CHECK_CAPABILITY(env,can_get_monitor_info)
2129 
2130  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
2131  return JVMTI_ERROR_NONE;
2132 }
2133 
2134 
2135 /* GetFieldName ***************************************************************
2136 
2137  For the field indicated by klass and field, return the field name and
2138  signature.
2139 
2140 *******************************************************************************/
2141 
2142 static jvmtiError
2144  char **name_ptr, char **signature_ptr, char **generic_ptr)
2145 {
2146  int size;
2147 
2152 
2153  if (klass == NULL)
2155  else
2158  if (field == NULL) return JVMTI_ERROR_INVALID_FIELDID;
2159 
2160  if (name_ptr != NULL) {
2161  size = UTF_SIZE(((fieldinfo*)field)->name)+1;
2162  *name_ptr = (char*) heap_allocate(sizeof(char)* size,true,NULL);
2163  utf_sprint_convert_to_latin1(*name_ptr, ((fieldinfo*)field)->name);
2164  }
2165 
2166  if (signature_ptr != NULL) {
2167  size = UTF_SIZE(((fieldinfo*)field)->descriptor)+1;
2168  *signature_ptr = (char*) heap_allocate(sizeof(char)* size,true,NULL);
2169  utf_sprint_convert_to_latin1(*signature_ptr,
2170  ((fieldinfo*)field)->descriptor);
2171  }
2172 
2173  if (generic_ptr != NULL)
2174  *generic_ptr = NULL;
2175 
2176  return JVMTI_ERROR_NONE;
2177 }
2178 
2179 
2180 /* GetFieldDeclaringClass *****************************************************
2181 
2182  For the field indicated by klass and field return the class that defined it
2183  The declaring class will either be klass, a superclass, or an implemented
2184  interface.
2185 
2186 *******************************************************************************/
2187 
2188 static jvmtiError
2190  jclass * declaring_class_ptr)
2191 {
2196 
2197  if (klass == NULL)
2199  else
2202 
2203  if (field == NULL) return JVMTI_ERROR_INVALID_FIELDID;
2204 
2205  if (declaring_class_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
2206 
2207  *declaring_class_ptr = (jclass) ((fieldinfo*)field)->class;
2208 
2209  return JVMTI_ERROR_NONE;
2210 }
2211 
2212 
2213 /* GetFieldModifiers **********************************************************
2214 
2215  Return access flags of field field
2216 
2217 *******************************************************************************/
2218 
2219 static jvmtiError
2221  jint * modifiers_ptr)
2222 {
2227 
2228  if (klass == NULL)
2230  else
2233 
2234  if (field == NULL) return JVMTI_ERROR_INVALID_FIELDID;
2235 
2236  if (modifiers_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
2237 
2238  *modifiers_ptr = ((fieldinfo*)field)->flags;
2239 
2240  return JVMTI_ERROR_NONE;
2241 }
2242 
2243 
2244 /* IsFieldSynthetic ***********************************************************
2245 
2246 
2247 
2248 *******************************************************************************/
2249 
2250 static jvmtiError
2252  jboolean * is_synthetic_ptr)
2253 {
2258  CHECK_CAPABILITY(env,can_get_synthetic_attribute)
2259 
2260  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
2261  return JVMTI_ERROR_NONE;
2262 }
2263 
2264 
2265 /* GetMethodName ***************************************************************
2266 
2267  For the method indicated by method, return the method name via name_ptr and
2268  method signature via signature_ptr.
2269 
2270 *******************************************************************************/
2271 
2272 static jvmtiError
2273 GetMethodName (jvmtiEnv * env, jmethodID method, char **name_ptr,
2274  char **signature_ptr, char **generic_ptr)
2275 {
2276  methodinfo* m = (methodinfo*)method;
2277 
2282 
2283 
2284  if (method == NULL) return JVMTI_ERROR_INVALID_METHODID;
2285 
2286  if (name_ptr != NULL) {
2287  *name_ptr = (char*)
2288  heap_allocate(sizeof(char) * (UTF_SIZE(m->name)+1),true,NULL);
2289  utf_sprint_convert_to_latin1(*name_ptr, m->name);
2290  }
2291 
2292  if (signature_ptr != NULL) {
2293  *signature_ptr = (char*)
2294  heap_allocate(sizeof(char)*(UTF_SIZE(m->descriptor)+1),true,NULL);
2295  utf_sprint_convert_to_latin1(*signature_ptr, m->descriptor);
2296  }
2297 
2298  if (generic_ptr != NULL) {
2299  /* there is no generic signature attribute */
2300  *generic_ptr = NULL;
2301  }
2302 
2303  return JVMTI_ERROR_NONE;
2304 }
2305 
2306 
2307 /* GetMethodDeclaringClass *****************************************************
2308 
2309  For the method indicated by method, return the class that defined it.
2310 
2311 *******************************************************************************/
2312 
2313 static jvmtiError
2315  jclass * declaring_class_ptr)
2316 {
2321 
2322  if ((method == NULL) || (declaring_class_ptr == NULL))
2323  return JVMTI_ERROR_NULL_POINTER;
2324 
2325  *declaring_class_ptr = (jclass)((methodinfo*)method)->class;
2326 
2327  return JVMTI_ERROR_NONE;
2328 }
2329 
2330 
2331 /* GetMethodModifiers **********************************************************
2332 
2333  For the method indicated by method, return the access flags.
2334 
2335 *******************************************************************************/
2336 
2337 static jvmtiError
2338 GetMethodModifiers (jvmtiEnv * env, jmethodID method, jint * modifiers_ptr)
2339 {
2344 
2345  if ((method == NULL) || (modifiers_ptr == NULL))
2346  return JVMTI_ERROR_NULL_POINTER;
2347 
2348  *modifiers_ptr = (jint) (((methodinfo*)method)->flags);
2349 
2350  return JVMTI_ERROR_NONE;
2351 }
2352 
2353 
2354 /* GetMaxLocals ****************************************************************
2355 
2356  For the method indicated by method, return the number of local variable slots
2357  used by the method, including the local variables used to pass parameters to
2358  the method on its invocation.
2359 
2360 *******************************************************************************/
2361 
2362 static jvmtiError
2363 GetMaxLocals (jvmtiEnv * env, jmethodID method, jint * max_ptr)
2364 {
2369 
2370  if ((method == NULL)||(max_ptr == NULL))
2371  return JVMTI_ERROR_NULL_POINTER;
2372 
2373  if (((methodinfo*)method)->flags & ACC_NATIVE)
2375 
2376  *max_ptr = (jint) ((methodinfo*)method)->maxlocals;
2377 
2378  return JVMTI_ERROR_NONE;
2379 }
2380 
2381 
2382 
2383 /* GetArgumentsSize ************************************************************
2384 
2385  Return the number of local variable slots used by the method's arguments.
2386 
2387 *******************************************************************************/
2388 
2389 static jvmtiError
2390 GetArgumentsSize (jvmtiEnv * env, jmethodID method, jint * size_ptr)
2391 {
2396 
2397  if ((method == NULL)||(size_ptr == NULL))
2398  return JVMTI_ERROR_NULL_POINTER;
2399 
2400  if (((methodinfo*)method)->flags & ACC_NATIVE)
2402 
2403  *size_ptr = (jint)((methodinfo*)method)->parseddesc->paramslots;
2404  return JVMTI_ERROR_NONE;
2405 }
2406 
2407 
2408 
2409 /* GetLineNumberTable **********************************************************
2410 
2411  Return table of source line number entries for a given method
2412 
2413 *******************************************************************************/
2414 
2415 static jvmtiError
2417  jint * entry_count_ptr, jvmtiLineNumberEntry ** table_ptr)
2418 {
2419  int i;
2420 
2425  CHECK_CAPABILITY(env,can_get_line_numbers)
2426 
2427  if ((method == NULL) || (entry_count_ptr == NULL) || (table_ptr == NULL))
2428  return JVMTI_ERROR_NULL_POINTER;
2429 
2430  if (((methodinfo*)method)->flags & ACC_NATIVE)
2432 
2433  if (((methodinfo*)method)->linenumbers == NULL)
2435 
2436  *entry_count_ptr= (jint)((methodinfo*)method)->linenumbercount;
2437  *table_ptr = (jvmtiLineNumberEntry*) heap_allocate(
2438  sizeof(jvmtiLineNumberEntry) * (*entry_count_ptr),true,NULL);
2439 
2440 
2441  for (i=0; i < *entry_count_ptr; i++) {
2442  (*table_ptr)[i].start_location =
2443  (jlocation) ((methodinfo*)method)->linenumbers[i].start_pc;
2444  (*table_ptr)[i].line_number =
2445  (jint) ((methodinfo*)method)->linenumbers[i].line_number;
2446  }
2447 
2448  return JVMTI_ERROR_NONE;
2449 }
2450 
2451 
2452 /* GetMethodLocation ***********************************************************
2453 
2454  For the method indicated by method, return the beginning and ending addresses
2455  through start_location_ptr and end_location_ptr. In cacao this points to
2456  entry point in machine code and length of machine code
2457 
2458 *******************************************************************************/
2459 
2460 static jvmtiError
2462  jlocation * start_location_ptr,
2463  jlocation * end_location_ptr)
2464 {
2465  methodinfo* m = (methodinfo*)method;
2466 
2471 
2472  if (method == NULL) return JVMTI_ERROR_INVALID_METHODID;
2473 
2474  if (((methodinfo*)method)->flags & ACC_NATIVE)
2476 
2477  if ((start_location_ptr == NULL) || (end_location_ptr == NULL))
2478  return JVMTI_ERROR_NULL_POINTER;
2479 
2480  /* XXX we return the location of the most recent code. Don't know
2481  * if there is a way to teach jvmti that a method can have more
2482  * than one location. -Edwin */
2483 
2484  /* XXX Don't know if that's the right way to deal with not-yet-
2485  * compiled methods. -Edwin */
2486 
2487  fprintf(stderr,"GetMethodLocation *** XXX todo \n");
2488 
2489 
2490  /* -1 states location information is not available */
2491  *start_location_ptr = (jlocation)-1;
2492  *end_location_ptr = (jlocation)-1;
2493 
2494 /*
2495  *start_location_ptr = (jlocation)m->code->mcode;
2496  *end_location_ptr = (jlocation)(m->code->mcode)+m->code->mcodelength;*/
2497  return JVMTI_ERROR_NONE;
2498 }
2499 
2500 
2501 /* GetLocalVariableTable *******************************************************
2502 
2503  Return local variable information.
2504 
2505 *******************************************************************************/
2506 
2507 static jvmtiError
2509  jint * entry_count_ptr,
2510  jvmtiLocalVariableEntry ** table_ptr)
2511 {
2515  CHECK_CAPABILITY(env,can_access_local_variables)
2516 
2517  log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
2518 
2519  return JVMTI_ERROR_NONE;
2520 }
2521 
2522 
2523 /* GetBytecode *****************************************************************
2524 
2525  For the method indicated by method, return the byte codes that implement the
2526  method.
2527 
2528 *******************************************************************************/
2529 
2530 static jvmtiError
2531 GetBytecodes (jvmtiEnv * env, jmethodID method,
2532  jint * bytecode_count_ptr, unsigned char **bytecodes_ptr)
2533 {
2534  methodinfo* m = (methodinfo*)method;;
2535 
2540  CHECK_CAPABILITY(env,can_get_bytecodes)
2541 
2542  if ((method == NULL) || (bytecode_count_ptr == NULL) ||
2543  (bytecodes_ptr == NULL)) return JVMTI_ERROR_NULL_POINTER;
2544 
2545  *bytecode_count_ptr = m->jcodelength;
2546  *bytecodes_ptr = (unsigned char*)heap_allocate(m->jcodelength,true,NULL);
2547  memcpy(*bytecodes_ptr, m->jcode, m->jcodelength);
2548 
2549  return JVMTI_ERROR_NONE;
2550 }
2551 
2552 
2553 /* IsMethodNative **************************************************************
2554 
2555  For the method indicated by method, return a value indicating whether the
2556  method is a native function
2557 
2558 *******************************************************************************/
2559 
2560 static jvmtiError
2561 IsMethodNative (jvmtiEnv * env, jmethodID method, jboolean * is_native_ptr)
2562 {
2567 
2568  if ((method == NULL)||(is_native_ptr == NULL))
2569  return JVMTI_ERROR_NULL_POINTER;
2570 
2571  if (((methodinfo*)method)->flags & ACC_NATIVE)
2572  *is_native_ptr = JNI_TRUE;
2573  else
2574  *is_native_ptr = JNI_FALSE;
2575 
2576  return JVMTI_ERROR_NONE;
2577 }
2578 
2579 
2580 /* IsMethodSynthetic ***********************************************************
2581 
2582  return a value indicating whether the method is synthetic. Synthetic methods
2583  are generated by the compiler but not present in the original source code.
2584 
2585 *******************************************************************************/
2586 
2587 static jvmtiError
2589  jboolean * is_synthetic_ptr)
2590 {
2595  CHECK_CAPABILITY(env,can_get_synthetic_attribute)
2596 
2597  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
2598  return JVMTI_ERROR_NONE;
2599 }
2600 
2601 
2602 /* GetLoadedClasses ************************************************************
2603 
2604  Return an array of all classes loaded in the virtual machine.
2605 
2606 *******************************************************************************/
2607 
2608 static jvmtiError
2609 GetLoadedClasses (jvmtiEnv * env, jint * class_count_ptr, jclass ** classes_ptr)
2610 {
2614 
2615  if (class_count_ptr == NULL)
2616  return JVMTI_ERROR_NULL_POINTER;
2617 
2618  if (classes_ptr == NULL)
2619  return JVMTI_ERROR_NULL_POINTER;
2620 
2621  classcache_jvmti_GetLoadedClasses(class_count_ptr, classes_ptr);
2622 
2623  return JVMTI_ERROR_NONE;
2624 }
2625 
2626 
2627 /* GetClassLoaderClasses *******************************************************
2628 
2629  Returns an array of those classes for which this class loader has been
2630  recorded as an initiating loader.
2631 
2632 *******************************************************************************/
2633 
2634 static jvmtiError
2635 GetClassLoaderClasses (jvmtiEnv * env, jobject initiating_loader,
2636  jint * class_count_ptr, jclass ** classes_ptr)
2637 {
2638  log_text("GetClassLoaderClasses called");
2639 
2643 
2644  if ((class_count_ptr == NULL) || (classes_ptr == NULL))
2645  return JVMTI_ERROR_NULL_POINTER;
2646 
2647  /* behave like jdk 1.1 and make no distinction between initiating and
2648  defining class loaders */
2649 
2650  return GetLoadedClasses(env, class_count_ptr, classes_ptr);
2651 }
2652 
2653 
2654 /* PopFrame *******************************************************************
2655 
2656 
2657 
2658 *******************************************************************************/
2659 
2660 static jvmtiError
2662 {
2666  CHECK_CAPABILITY(env,can_pop_frame)
2667 
2668  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
2669  return JVMTI_ERROR_NONE;
2670 }
2671 
2672 
2673 /* RedefineClasses ************************************************************
2674 
2675 
2676 
2677 *******************************************************************************/
2678 
2679 static jvmtiError
2680 RedefineClasses (jvmtiEnv * env, jint class_count,
2681  const jvmtiClassDefinition * class_definitions)
2682 {
2687  CHECK_CAPABILITY(env,can_redefine_classes)
2688  CHECK_CAPABILITY(env,can_redefine_any_class)
2689 
2690  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
2691  return JVMTI_ERROR_NONE;
2692 }
2693 
2694 
2695 /* GetVersionNumber ***********************************************************
2696 
2697  Return the JVM TI version identifier.
2698 
2699 *******************************************************************************/
2700 
2701 static jvmtiError
2702 GetVersionNumber (jvmtiEnv * env, jint * version_ptr)
2703 {
2704  if (version_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
2705 
2706  *version_ptr = JVMTI_VERSION;
2707 
2708  return JVMTI_ERROR_NONE;
2709 }
2710 
2711 
2712 /* GetCapabilities ************************************************************
2713 
2714  Returns the optional JVM TI features which this environment currently
2715  possesses.
2716 
2717 *******************************************************************************/
2718 
2719 static jvmtiError
2720 GetCapabilities (jvmtiEnv * env, jvmtiCapabilities * capabilities_ptr)
2721 {
2722  if (capabilities_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
2723 
2724  memcpy(capabilities_ptr, &(((environment*) env)->capabilities), sizeof(JVMTI_Capabilities));
2725 
2726  return JVMTI_ERROR_NONE;
2727 }
2728 
2729 
2730 /* *****************************************************************************
2731 
2732 
2733 
2734 *******************************************************************************/
2735 
2736 static jvmtiError
2738  char **source_debug_extension_ptr)
2739 {
2744  CHECK_CAPABILITY(env,can_get_source_debug_extension)
2745 
2746  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
2747  return JVMTI_ERROR_NONE;
2748 }
2749 
2750 
2751 /* IsMethodObsolete ************************************************************
2752 
2753  Determine if a method ID refers to an obsolete method version.
2754 
2755 *******************************************************************************/
2756 
2757 static jvmtiError
2759  jboolean * is_obsolete_ptr)
2760 {
2765  CHECK_CAPABILITY(env,can_redefine_classes)
2766 
2767  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
2768  return JVMTI_ERROR_NONE;
2769 }
2770 
2771 
2772 /* SuspendThreadList **********************************************************
2773 
2774  Suspend all threads in the request list.
2775 
2776 *******************************************************************************/
2777 
2778 static jvmtiError
2779 SuspendThreadList (jvmtiEnv * env, jint request_count,
2780  const jthread * request_list, jvmtiError * results)
2781 {
2782  int i;
2783  int suspendme = -1;
2784  jthread me;
2785 
2790  CHECK_CAPABILITY(env,can_suspend);
2791 
2792  if (request_count<0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2793  if ((request_list == NULL) || (results == NULL))
2794  return JVMTI_ERROR_NULL_POINTER;
2795 
2796  me = jvmti_get_current_thread();
2797 
2798  for (i=0;i<request_count;i++) {
2799  if (request_list[i] == me)
2800  suspendme = i;
2801  else
2802  results[i]=SuspendThread(env, request_list[i]);
2803  }
2804 
2805  if (suspendme != -1)
2806  results[suspendme]=SuspendThread(env, request_list[suspendme]);
2807 
2808  return JVMTI_ERROR_NONE;
2809 }
2810 
2811 
2812 /* ResumeThreadList ***********************************************************
2813 
2814  Resumes all threads in the request list.
2815 
2816 *******************************************************************************/
2817 
2818 static jvmtiError
2819 ResumeThreadList (jvmtiEnv * env, jint request_count,
2820  const jthread * request_list, jvmtiError * results)
2821 {
2822  int i;
2823 
2827  CHECK_CAPABILITY(env,can_suspend);
2828 
2829  if (request_count<0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2830  if ((request_list == NULL) || (results == NULL))
2831  return JVMTI_ERROR_NULL_POINTER;
2832 
2833  for (i=0;i<request_count;i++)
2834  results[i]=ResumeThread(env, request_list[i]);
2835 
2836  return JVMTI_ERROR_NONE;
2837 }
2838 
2839 
2840 /* GetStackTrace **************************************************************
2841 
2842  Get information about the stack of a thread
2843 
2844 *******************************************************************************/
2845 
2846 static jvmtiError
2847 GetStackTrace (jvmtiEnv * env, jthread thread, jint start_depth,
2848  jint max_frame_count, jvmtiFrameInfo * frame_buffer,
2849  jint * count_ptr)
2850 {
2851  stacktracebuffer* trace;
2852  jvmtiError er;
2853  int i,j;
2854 
2858 
2859  if (thread != NULL){
2862 
2863  CHECK_THREAD_IS_ALIVE(thread);
2864  }
2865 
2866  if((count_ptr == NULL)||(frame_buffer == NULL))
2867  return JVMTI_ERROR_NULL_POINTER;
2868 
2869  if (max_frame_count <0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2870 
2871  er = getcacaostacktrace(&trace, thread);
2872  if (er == JVMTI_ERROR_NONE) {
2873  heap_free(trace);
2874  return er;
2875  }
2876 
2877  if ((trace->used >= start_depth) || ((trace->used * -1) > start_depth))
2879 
2880  for (i=start_depth, j=0;i<trace->used;i++,j++) {
2881  frame_buffer[j].method = (jmethodID)trace->entries[i].method;
2882  /* XXX todo: location BCI/MachinePC not avilable - Linenumber not expected */
2883  frame_buffer[j].location = 0;
2884  }
2885 
2886  heap_free(trace);
2887 
2888  return JVMTI_ERROR_NONE;
2889 }
2890 
2891 
2892 /* GetThreadListStackTraces ***************************************************
2893 
2894  Get information about the stacks of the supplied threads.
2895 
2896 *******************************************************************************/
2897 
2898 static jvmtiError
2899 GetThreadListStackTraces (jvmtiEnv * env, jint thread_count,
2900  const jthread * thread_list,
2901  jint max_frame_count,
2902  jvmtiStackInfo ** stack_info_ptr)
2903 {
2904  int i;
2905  jvmtiError er;
2906 
2910 
2911  if ((stack_info_ptr == NULL)||(thread_list == NULL))
2912  return JVMTI_ERROR_NULL_POINTER;
2913 
2914  if (thread_count < 0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2915 
2916  if (max_frame_count < 0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2917 
2918  *stack_info_ptr = (jvmtiStackInfo*)
2919  heap_allocate(sizeof(jvmtiStackInfo) * thread_count, true, NULL);
2920 
2921  for(i=0; i<thread_count; i++) { /* fill in stack info sturcture array */
2922  (*stack_info_ptr)[i].thread=thread_list[i];
2923  GetThreadState(env,thread_list[i],&((*stack_info_ptr)[i].state));
2924  (*stack_info_ptr)[i].frame_buffer =
2925  heap_allocate(sizeof(jvmtiFrameInfo) * max_frame_count,true,NULL);
2926  er = GetStackTrace(env,thread_list[i],0,max_frame_count,
2927  (*stack_info_ptr)[i].frame_buffer,
2928  &((*stack_info_ptr)[i].frame_count));
2929 
2930  if (er != JVMTI_ERROR_NONE) return er;
2931  }
2932 
2933  return JVMTI_ERROR_NONE;
2934 }
2935 
2936 
2937 /* GetAllStackTraces **********************************************************
2938 
2939  Get stack traces of all live threads
2940 
2941 *******************************************************************************/
2942 
2943 static jvmtiError
2944 GetAllStackTraces (jvmtiEnv * env, jint max_frame_count,
2945  jvmtiStackInfo ** stack_info_ptr, jint * thread_count_ptr)
2946 {
2947  jthread *threads_ptr;
2948  jvmtiError er;
2949 
2953 
2954  if (thread_count_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
2955 
2956  if (JVMTI_ERROR_NONE!=GetAllThreads(env,thread_count_ptr,&threads_ptr))
2957  return JVMTI_ERROR_INTERNAL;
2958 
2959  GetThreadListStackTraces(env, *thread_count_ptr, threads_ptr,
2960  max_frame_count, stack_info_ptr);
2961 
2962  if (er != JVMTI_ERROR_NONE) return er;
2963 
2964  return JVMTI_ERROR_NONE;
2965 }
2966 
2967 
2968 /* GetThreadLocalStorage ******************************************************
2969 
2970  Get the value of the JVM TI thread-local storage.
2971 
2972 *******************************************************************************/
2973 
2974 static jvmtiError
2976 {
2978 
2983 
2984  if(thread == NULL)
2985  thread = (jthread) THREADOBJECT;
2986  else {
2989  CHECK_THREAD_IS_ALIVE(thread);
2990  }
2991 
2992  if(data_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
2993 
2994  tls = ((environment*)env)->tls;
2995  while ((tls->thread != thread) && (tls != NULL)) {
2996  tls = tls->next;
2997  }
2998 
2999  if (tls == NULL) return JVMTI_ERROR_INTERNAL; /* env/thread pair not found */
3000 
3001  *data_ptr = tls->data;
3002 
3003  return JVMTI_ERROR_NONE;
3004 }
3005 
3006 
3007 /* SetThreadLocalStorage *******************************************************
3008 
3009  Stores a pointer value associated with each environment-thread pair. The
3010  value is NULL unless set with this function. Agents can allocate memory in
3011  which they store thread specific information
3012 
3013 *******************************************************************************/
3014 
3015 jvmtiError
3016 SetThreadLocalStorage (jvmtiEnv * jenv, jthread thread, const void *data)
3017 {
3018  jvmtiThreadLocalStorage *tls, *pre;
3019  environment* env = (environment*)jenv;
3020 
3025 
3026  if(thread == NULL)
3027  thread = (jthread) THREADOBJECT;
3028  else {
3031  CHECK_THREAD_IS_ALIVE(thread);
3032  }
3033 
3034  if (env->tls == NULL) {
3035  tls = env->tls = heap_allocate(sizeof(jvmtiThreadLocalStorage),true,NULL);
3036  } else {
3037  tls = env->tls;
3038  while ((tls->thread != thread) && (tls->next != NULL)) {
3039  tls = tls->next;
3040  }
3041  if (tls->thread != thread) {
3042  tls->next = heap_allocate(sizeof(jvmtiThreadLocalStorage),true,NULL);
3043  tls = tls->next;
3044  }
3045  }
3046 
3047  if (data != NULL) {
3048  tls->data = (void*)data;
3049  } else {
3050  /* remove current tls */
3051  pre = env->tls;
3052  while (pre->next == tls) pre = pre->next;
3053  pre->next = tls->next;
3054  }
3055  return JVMTI_ERROR_NONE;
3056 }
3057 
3058 
3059 /* *****************************************************************************
3060 
3061 
3062 
3063 *******************************************************************************/
3064 
3065 static jvmtiError
3066 GetTag (jvmtiEnv * env, jobject object, jlong * tag_ptr)
3067 {
3072  CHECK_CAPABILITY(env,can_tag_objects)
3073 
3074  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3075  return JVMTI_ERROR_NONE;
3076 }
3077 
3078 /* *****************************************************************************
3079 
3080 
3081 
3082 *******************************************************************************/
3083 
3084 static jvmtiError
3085 SetTag (jvmtiEnv * env, jobject object, jlong tag)
3086 {
3091  CHECK_CAPABILITY(env,can_tag_objects)
3092 
3093  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3094  return JVMTI_ERROR_NONE;
3095 }
3096 
3097 
3098 /* ForceGarbageCollection *****************************************************
3099 
3100  Force boehm-gc to perform a garbage collection
3101 
3102 *******************************************************************************/
3103 
3104 static jvmtiError
3106 {
3110 
3111  gc_call();
3112 
3113  return JVMTI_ERROR_NONE;
3114 }
3115 
3116 
3117 /* IterateOverObjectsReachableFromObject **************************************
3118 
3119 
3120 
3121 *******************************************************************************/
3122 
3123 static jvmtiError
3125  jvmtiObjectReferenceCallback
3126  object_reference_callback,
3127  void *user_data)
3128 {
3132  CHECK_CAPABILITY(env,can_tag_objects)
3133 
3134  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3135  return JVMTI_ERROR_NONE;
3136 }
3137 
3138 
3139 /* IterateOverReachableObjects ************************************************
3140 
3141 
3142 
3143 *******************************************************************************/
3144 
3145 static jvmtiError
3146 IterateOverReachableObjects (jvmtiEnv * env, jvmtiHeapRootCallback
3147  heap_root_callback,
3148  jvmtiStackReferenceCallback
3149  stack_ref_callback,
3150  jvmtiObjectReferenceCallback
3151  object_ref_callback, void *user_data)
3152 {
3156  CHECK_CAPABILITY(env,can_tag_objects)
3157 
3158  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3159  return JVMTI_ERROR_NONE;
3160 }
3161 
3162 
3163 /* IterateOverHeap ************************************************************
3164 
3165 
3166 
3167 *******************************************************************************/
3168 
3169 static jvmtiError
3171  jvmtiHeapObjectCallback heap_object_callback,
3172  void *user_data)
3173 {
3177  CHECK_CAPABILITY(env,can_tag_objects)
3178 
3179  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3180  return JVMTI_ERROR_NONE;
3181 }
3182 
3183 
3184 /* IterateOverInstancesOfClass ************************************************
3185 
3186 
3187 
3188 *******************************************************************************/
3189 
3190 static jvmtiError
3192  jvmtiHeapObjectFilter object_filter,
3193  jvmtiHeapObjectCallback
3194  heap_object_callback, void *user_data)
3195 {
3199  CHECK_CAPABILITY(env,can_tag_objects)
3200 
3201  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3202  return JVMTI_ERROR_NONE;
3203 }
3204 
3205 
3206 /* *****************************************************************************
3207 
3208 
3209 
3210 *******************************************************************************/
3211 
3212 static jvmtiError
3213 GetObjectsWithTags (jvmtiEnv * env, jint tag_count, const jlong * tags,
3214  jint * count_ptr, jobject ** object_result_ptr,
3215  jlong ** tag_result_ptr)
3216 {
3220  CHECK_CAPABILITY(env,can_tag_objects)
3221 
3222  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3223  return JVMTI_ERROR_NONE;
3224 }
3225 
3226 
3227 /* SetJNIFunctionTable **********************************************************
3228 
3229  Set the JNI function table in all current and future JNI environments
3230 
3231 *******************************************************************************/
3232 
3233 static jvmtiError
3235  const jniNativeInterface * function_table)
3236 {
3240  CHECK_PHASE_END;;
3241 
3242  if (function_table == NULL) return JVMTI_ERROR_NULL_POINTER;
3243  _Jv_env->env = (void*)heap_allocate(sizeof(jniNativeInterface),true,NULL);
3244  memcpy((void*)_Jv_env->env, function_table, sizeof(jniNativeInterface));
3245  return JVMTI_ERROR_NONE;
3246 }
3247 
3248 
3249 /* GetJNIFunctionTable *********************************************************
3250 
3251  Get the JNI function table. The JNI function table is copied into allocated
3252  memory.
3253 
3254 *******************************************************************************/
3255 
3256 static jvmtiError
3258 {
3263 
3264  if (function_table == NULL) return JVMTI_ERROR_NULL_POINTER;
3265  *function_table = (jniNativeInterface*)
3266  heap_allocate(sizeof(jniNativeInterface),true,NULL);
3267  memcpy(*function_table, _Jv_env->env, sizeof(jniNativeInterface));
3268  return JVMTI_ERROR_NONE;
3269 }
3270 
3271 
3272 /* SetEventCallbacks **********************************************************
3273 
3274  Set the functions to be called for each event. The callbacks are specified
3275  by supplying a replacement function table.
3276 
3277 *******************************************************************************/
3278 
3279 static jvmtiError
3282  jint size_of_callbacks)
3283 {
3288 
3289  if (size_of_callbacks < 0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
3290 
3291 
3292  if (callbacks == NULL) { /* remove the existing callbacks */
3293  memset(&(((environment* )env)->callbacks), 0,
3294  sizeof(jvmtiEventCallbacks));
3295  }
3296 
3297  memcpy (&(((environment* )env)->callbacks),callbacks,size_of_callbacks);
3298 
3299  return JVMTI_ERROR_NONE;
3300 }
3301 
3302 
3303 /* GenerateEvents *************************************************************
3304 
3305  Generate events (CompiledMethodLoad and DynamicCodeGenerated) to represent
3306  the current state of the VM.
3307 
3308 *******************************************************************************/
3309 
3310 static jvmtiError
3312 {
3316  CHECK_CAPABILITY(env,can_generate_compiled_method_load_events);
3317 
3318  return JVMTI_ERROR_NONE;
3319 }
3320 
3321 
3322 /* GetExtensionFunctions ******************************************************
3323 
3324  Returns the set of extension functions.
3325 
3326 *******************************************************************************/
3327 
3328 static jvmtiError
3329 GetExtensionFunctions (jvmtiEnv * env, jint * extension_count_ptr,
3330  jvmtiExtensionFunctionInfo ** extensions)
3331 {
3336 
3337  if ((extension_count_ptr == NULL)||(extensions == NULL))
3338  return JVMTI_ERROR_NULL_POINTER;
3339 
3340  /* cacao has no extended functions yet */
3341  *extension_count_ptr = 0;
3342 
3343  return JVMTI_ERROR_NONE;
3344 }
3345 
3346 
3347 /* GetExtensionEvents *********************************************************
3348 
3349  Returns the set of extension events.
3350 
3351 *******************************************************************************/
3352 
3353 static jvmtiError
3354 GetExtensionEvents (jvmtiEnv * env, jint * extension_count_ptr,
3355  jvmtiExtensionEventInfo ** extensions)
3356 {
3361 
3362  if ((extension_count_ptr == NULL)||(extensions == NULL))
3363  return JVMTI_ERROR_NULL_POINTER;
3364 
3365  /* cacao has no extended events yet */
3366  *extension_count_ptr = 0;
3367 
3368  return JVMTI_ERROR_NONE;
3369 }
3370 
3371 
3372 /* SetExtensionEventCallback **************************************************
3373 
3374  Sets the callback function for an extension event and enables the event.
3375 
3376 *******************************************************************************/
3377 
3378 static jvmtiError
3379 SetExtensionEventCallback (jvmtiEnv * env, jint extension_event_index,
3380  jvmtiExtensionEvent callback)
3381 {
3386 
3387  /* cacao has no extended events yet */
3389 }
3390 
3391 
3392 /* DisposeEnvironment **********************************************************
3393 
3394  Shutdown a JVM TI connection created with JNI GetEnv.
3395 
3396 *******************************************************************************/
3397 
3398 static jvmtiError
3400 {
3401  environment* cacao_env = (environment*)env;
3402  environment* tenvs = envs;
3403  jvmtiThreadLocalStorage *jtls, *tjtls;
3404 
3405  if (tenvs != cacao_env) {
3406  while (tenvs->next != cacao_env) {
3407  tenvs = tenvs->next;
3408  }
3409  tenvs->next = cacao_env->next;
3410  } else
3411  envs = NULL;
3412 
3413  cacao_env->env=NULL;
3414  memset(&(cacao_env->callbacks),0,sizeof(jvmtiEventCallbacks)*
3416  memset(cacao_env->events,0,sizeof(jvmtiEventModeLL)*
3418  cacao_env->EnvironmentLocalStorage = NULL;
3419 
3420  jtls = cacao_env->tls;
3421  while (jtls != NULL) {
3422  tjtls = jtls;
3423  jtls = jtls->next;
3424  tjtls->next = NULL;
3425  }
3426  cacao_env->tls = NULL;
3427 
3428 
3430 
3431  /* let the GC do the rest */
3432  return JVMTI_ERROR_NONE;
3433 }
3434 
3435 
3436 /* GetErrorName ***************************************************************
3437 
3438  Return the symbolic name for an error code.
3439 
3440 *******************************************************************************/
3441 
3442 #define COPY_RESPONSE(name_ptr,str) *name_ptr = (char*) heap_allocate(sizeof(str),true,NULL); \
3443  memcpy(*name_ptr, &str, sizeof(str)); \
3444  break
3445 
3446 static jvmtiError
3447 GetErrorName (jvmtiEnv * env, jvmtiError error, char **name_ptr)
3448 {
3449  if (name_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
3450 
3451  switch (error) {
3452  case JVMTI_ERROR_NONE :
3453  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_NONE");
3454  case JVMTI_ERROR_NULL_POINTER :
3455  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_NULL_POINTER");
3457  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_OUT_OF_MEMORY");
3459  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_ACCESS_DENIED");
3461  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_UNATTACHED_THREAD");
3463  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_ENVIRONMENT");
3464  case JVMTI_ERROR_WRONG_PHASE :
3465  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_WRONG_PHASE");
3466  case JVMTI_ERROR_INTERNAL :
3467  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INTERNAL");
3469  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_PRIORITY");
3471  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_THREAD_NOT_SUSPENDED");
3473  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_THREAD_SUSPENDED");
3475  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_THREAD_NOT_ALIVE");
3477  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_CLASS_NOT_PREPARED");
3479  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_NO_MORE_FRAMES");
3480  case JVMTI_ERROR_OPAQUE_FRAME :
3481  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_OPAQUE_FRAME");
3482  case JVMTI_ERROR_DUPLICATE :
3483  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_DUPLICATE");
3484  case JVMTI_ERROR_NOT_FOUND :
3485  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_NOT_FOUND");
3487  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_NOT_MONITOR_OWNER");
3488  case JVMTI_ERROR_INTERRUPT :
3489  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INTERRUPT");
3491  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_UNMODIFIABLE_CLASS");
3493  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_NOT_AVAILABLE");
3495  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_ABSENT_INFORMATION");
3497  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_EVENT_TYPE");
3499  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_NATIVE_METHOD");
3501  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_THREAD");
3503  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_FIELDID");
3505  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_METHODID");
3507  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_LOCATION");
3509  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_OBJECT");
3511  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_CLASS");
3513  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_TYPE_MISMATCH");
3514  case JVMTI_ERROR_INVALID_SLOT :
3515  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_SLOT");
3517  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_MUST_POSSESS_CAPABILITY");
3519  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_THREAD_GROUP");
3521  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_MONITOR");
3523  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_ILLEGAL_ARGUMENT");
3525  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_TYPESTATE");
3527  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_UNSUPPORTED_VERSION");
3529  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_INVALID_CLASS_FORMAT");
3531  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION");
3533  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED");
3535  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED");
3537  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_FAILS_VERIFICATION");
3539  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED");
3541  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED");
3543  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_NAMES_DONT_MATCH");
3545  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED");
3547  COPY_RESPONSE (name_ptr, "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED");
3548  default:
3550  }
3551  return JVMTI_ERROR_NONE;
3552 }
3553 
3554 /* GetJLocationFormat **********************************************************
3555 
3556  This function describes the representation of jlocation used in this VM.
3557 
3558 *******************************************************************************/
3559 
3560 static jvmtiError
3562 {
3563  *format_ptr = JVMTI_JLOCATION_OTHER;
3564  return JVMTI_ERROR_NONE;
3565 }
3566 
3567 
3568 /* GetSystemProperties ********************************************************
3569 
3570  The list of VM system property keys which may be used with GetSystemProperty
3571  is returned.
3572 
3573 *******************************************************************************/
3574 
3575 static jvmtiError
3576 GetSystemProperties (jvmtiEnv * env, jint * count_ptr, char ***property_ptr)
3577 {
3578  jmethodID mid, moremid;
3579  classinfo *sysclass, *propclass, *enumclass;
3580  java_objectheader *sysprop, *keys, *obj;
3581  char* ch;
3582  int i;
3583 
3588 
3589  if ((count_ptr == NULL) || (property_ptr == NULL))
3590  return JVMTI_ERROR_NULL_POINTER;
3591 
3592  sysclass = load_class_from_sysloader(Utf8String::from_utf8("java/lang/System"));
3593 
3594  if (!sysclass) throw_main_exception_exit();
3595 
3596  mid = (jmethodID)class_resolvemethod(sysclass,
3597  Utf8String::from_utf8("getProperties"),
3598  Utf8String::from_utf8("()Ljava/util/Properties;"));
3599  if (!mid) throw_main_exception_exit();
3600 
3601 
3602  sysprop = _Jv_JNINativeInterface.CallStaticObjectMethod(NULL, sysclass, mid);
3603  if (!sysprop) throw_main_exception_exit();
3604 
3605  propclass = sysprop->vftbl->class;
3606 
3607  mid = (jmethodID)class_resolvemethod(propclass,
3608  Utf8String::from_utf8("size"),
3609  Utf8String::from_utf8("()I"));
3610  if (!mid) throw_main_exception_exit();
3611 
3612  *count_ptr =
3613  _Jv_JNINativeInterface.CallIntMethod(NULL, sysprop, mid);
3614  *property_ptr = heap_allocate(sizeof(char*) * (*count_ptr) ,true,NULL);
3615 
3616  mid = (jmethodID)class_resolvemethod(propclass,
3617  Utf8String::from_utf8("keys"),
3618  Utf8String::from_utf8("()Ljava/util/Enumeration;"));
3619  if (!mid) throw_main_exception_exit();
3620 
3621  keys = _Jv_JNINativeInterface.CallObjectMethod(NULL, sysprop, mid);
3622  enumclass = keys->vftbl->class;
3623 
3624  moremid = (jmethodID)class_resolvemethod(enumclass,
3625  Utf8String::from_utf8("hasMoreElements"),
3626  Utf8String::from_utf8("()Z"));
3627  if (!moremid) throw_main_exception_exit();
3628 
3629  mid = (jmethodID)class_resolvemethod(propclass,
3630  Utf8String::from_utf8("nextElement"),
3631  Utf8String::from_utf8("()Ljava/lang/Object;"));
3632  if (!mid) throw_main_exception_exit();
3633 
3634  i = 0;
3635  while (_Jv_JNINativeInterface.CallBooleanMethod(NULL,keys,(jmethodID)moremid)) {
3636  obj = _Jv_JNINativeInterface.CallObjectMethod(NULL, keys, mid);
3637  ch = JavaString(obj).to_chars();
3638  *property_ptr[i] = heap_allocate(sizeof(char*) * strlen (ch),true,NULL);
3639  memcpy(*property_ptr[i], ch, strlen (ch));
3640  MFREE(ch,char,strlen(ch)+1);
3641  i++;
3642  }
3643 
3644  return JVMTI_ERROR_NONE;
3645 }
3646 
3647 
3648 /* GetSystemProperty **********************************************************
3649 
3650  Return a VM system property value given the property key.
3651 
3652 *******************************************************************************/
3653 
3654 static jvmtiError
3655 GetSystemProperty (jvmtiEnv * env, const char *property, char **value_ptr)
3656 {
3657  jmethodID mid;
3658  classinfo *sysclass, *propclass;
3659  java_objectheader *sysprop, *obj;
3660  char* ch;
3661 
3666 
3667  if ((value_ptr == NULL) || (property == NULL))
3668  return JVMTI_ERROR_NULL_POINTER;
3669 
3670  sysclass = load_class_from_sysloader(Utf8String::from_utf8("java/lang/System"));
3671  if (!sysclass) throw_main_exception_exit();
3672 
3673  mid = (jmethodID)class_resolvemethod(sysclass,
3674  Utf8String::from_utf8("getProperties"),
3675  Utf8String::from_utf8("()Ljava/util/Properties;"));
3676  if (!mid) throw_main_exception_exit();
3677 
3678  sysprop = _Jv_JNINativeInterface.CallStaticObjectMethod(NULL, (jclass)sysclass, mid);
3679 
3680  propclass = sysprop->vftbl->class;
3681 
3682  mid = (jmethodID)class_resolvemethod(propclass,
3683  Utf8String::from_utf8("getProperty"),
3684  Utf8String::from_utf8("(Ljava/lang/String;)Ljava/lang/String;"));
3685  if (!mid) throw_main_exception_exit();
3686 
3687  obj = (java_objectheader*)_Jv_JNINativeInterface.CallObjectMethod(
3688  NULL, sysprop, mid, JavaString::from_utf8(property));
3689  if (!obj) return JVMTI_ERROR_NOT_AVAILABLE;
3690 
3691  ch = JavaString(obj).to_chars();
3692  *value_ptr = heap_allocate(sizeof(char*) * strlen (ch),true,NULL);
3693  memcpy(*value_ptr, ch, strlen (ch));
3694  MFREE(ch,char,strlen(ch)+1);
3695 
3696  return JVMTI_ERROR_NONE;
3697 }
3698 
3699 
3700 /* SetSystemProperty **********************************************************
3701 
3702  Set a VM system property value.
3703 
3704 *******************************************************************************/
3705 
3706 static jvmtiError
3707 SetSystemProperty (jvmtiEnv * env, const char *property, const char *value)
3708 {
3709  jmethodID mid;
3710  classinfo *sysclass, *propclass;
3711  java_objectheader *sysprop;
3712 
3716 
3717  if (property == NULL) return JVMTI_ERROR_NULL_POINTER;
3718  if (value == NULL) return JVMTI_ERROR_NOT_AVAILABLE;
3719 
3720  sysclass = load_class_from_sysloader(Utf8String::from_utf8("java/lang/System"));
3721  if (!sysclass) throw_main_exception_exit();
3722 
3723  mid = (jmethodID)class_resolvemethod(sysclass,
3724  Utf8String::from_utf8("getProperties"),
3725  Utf8String::from_utf8("()Ljava/util/Properties;"));
3726  if (!mid) throw_main_exception_exit();
3727 
3728  sysprop = _Jv_JNINativeInterface.CallStaticObjectMethod(NULL, (jclass)sysclass, mid);
3729 
3730  propclass = sysprop->vftbl->class;
3731 
3732  mid = (jmethodID)class_resolvemethod(propclass,
3733  Utf8String::from_utf8("setProperty"),
3734  Utf8String::from_utf8("(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"));
3735  if (!mid) throw_main_exception_exit();
3736 
3737  _Jv_JNINativeInterface.CallObjectMethod(NULL,
3738  sysprop,
3739  mid,
3740  JavaString::from_utf8(property),
3741  JavaString::from_utf8(value));
3742 
3743  return JVMTI_ERROR_NONE;
3744 }
3745 
3746 /* GetPhase ********************************************************************
3747 
3748  Return the current phase of VM execution
3749 
3750 *******************************************************************************/
3751 
3752 static jvmtiError
3753 GetPhase (jvmtiEnv * env, jvmtiPhase * phase_ptr)
3754 {
3755  if (phase_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
3756 
3757  *phase_ptr = phase;
3758 
3759  return JVMTI_ERROR_NONE;
3760 }
3761 
3762 /* GetCurrentThreadCpuTimerInfo ************************************************
3763 
3764 
3765 
3766 *******************************************************************************/
3767 
3768 static jvmtiError
3770 {
3775  CHECK_CAPABILITY(env,can_get_current_thread_cpu_time)
3776 
3777  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3778 
3779  return JVMTI_ERROR_NONE;
3780 }
3781 
3782 /* GetCurrentThreadCpuTime ****************************************************
3783 
3784 
3785 
3786 *******************************************************************************/
3787 
3788 static jvmtiError
3789 GetCurrentThreadCpuTime (jvmtiEnv * env, jlong * nanos_ptr)
3790 {
3795  CHECK_CAPABILITY(env,can_get_current_thread_cpu_time)
3796 
3797  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3798  return JVMTI_ERROR_NONE;
3799 }
3800 
3801 /* GetThreadCpuTimerInfo ******************************************************
3802 
3803 
3804 
3805 *******************************************************************************/
3806 
3807 static jvmtiError
3809 {
3814  CHECK_CAPABILITY(env,can_get_thread_cpu_time)
3815 
3816  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3817  return JVMTI_ERROR_NONE;
3818 }
3819 
3820 /* GetThreadCpuTime ***********************************************************
3821 
3822 
3823 
3824 *******************************************************************************/
3825 
3826 static jvmtiError
3827 GetThreadCpuTime (jvmtiEnv * env, jthread thread, jlong * nanos_ptr)
3828 {
3832  CHECK_CAPABILITY(env,can_get_thread_cpu_time)
3833  log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!");
3834  return JVMTI_ERROR_NONE;
3835 }
3836 
3837 /* GetTimerInfo ***************************************************************
3838 
3839  Get information about the GetTime timer.
3840 
3841 *******************************************************************************/
3842 
3843 static jvmtiError
3845 {
3846  if (info_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
3847 
3848  info_ptr->max_value = !0x0;
3849  info_ptr->may_skip_forward = true;
3850  info_ptr->may_skip_backward = true;
3851  info_ptr->kind = JVMTI_TIMER_TOTAL_CPU;
3852 
3853  return JVMTI_ERROR_NONE;
3854 }
3855 
3856 /* GetTime ********************************************************************
3857 
3858  Return the current value of the system timer, in nanoseconds
3859 
3860 *******************************************************************************/
3861 
3862 static jvmtiError
3863 GetTime (jvmtiEnv * env, jlong * nanos_ptr)
3864 {
3865  /* Note: this implementation copied directly from Japhar's, by Chris Toshok. */
3866  struct timeval tp;
3867 
3868  if (nanos_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
3869 
3870  if (gettimeofday (&tp, NULL) == -1)
3871  _Jv_JNINativeInterface.FatalError (NULL, "gettimeofday call failed.");
3872 
3873  *nanos_ptr = (jlong) tp.tv_sec;
3874  *nanos_ptr *= 1000;
3875  *nanos_ptr += (tp.tv_usec / 1000);
3876 
3877  return JVMTI_ERROR_NONE;
3878 }
3879 
3880 /* GetPotentialCapabilities ***************************************************
3881 
3882  Returns the JVM TI features that can potentially be possessed by this
3883  environment at this time.
3884 
3885 *******************************************************************************/
3886 
3887 static jvmtiError
3889 {
3894 
3895  if (capabilities_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
3896 
3897  memcpy(capabilities_ptr, &JVMTI_Capabilities, sizeof(JVMTI_Capabilities));
3898 
3899  return JVMTI_ERROR_NONE;
3900 }
3901 
3902 
3903 #define CHECK_ADD_CAPABILITY(env,CAN) \
3904  if (capabilities_ptr->CAN == 1) { \
3905  if (JVMTI_Capabilities.CAN == 0) \
3906  return JVMTI_ERROR_NOT_AVAILABLE; \
3907  else \
3908  env->capabilities.CAN = 1; \
3909  }
3910 
3911 /* AddCapabilities ************************************************************
3912 
3913  Set new capabilities by adding the capabilities pointed to by
3914  capabilities_ptr. All previous capabilities are retained.
3915 
3916 *******************************************************************************/
3917 
3918 static jvmtiError
3919 AddCapabilities (jvmtiEnv * env, const jvmtiCapabilities * capabilities_ptr)
3920 {
3921  environment* cacao_env;
3922 
3927 
3928  if ((env == NULL) || (capabilities_ptr == NULL))
3929  return JVMTI_ERROR_NULL_POINTER;
3930 
3931  cacao_env = (environment*)env;
3932 
3933  CHECK_ADD_CAPABILITY(cacao_env,can_tag_objects)
3934  CHECK_ADD_CAPABILITY(cacao_env,can_generate_field_modification_events)
3935  CHECK_ADD_CAPABILITY(cacao_env,can_generate_field_access_events)
3936  CHECK_ADD_CAPABILITY(cacao_env,can_get_bytecodes)
3937  CHECK_ADD_CAPABILITY(cacao_env,can_get_synthetic_attribute)
3938  CHECK_ADD_CAPABILITY(cacao_env,can_get_owned_monitor_info)
3939  CHECK_ADD_CAPABILITY(cacao_env,can_get_current_contended_monitor)
3940  CHECK_ADD_CAPABILITY(cacao_env,can_get_monitor_info)
3941  CHECK_ADD_CAPABILITY(cacao_env,can_pop_frame)
3942  CHECK_ADD_CAPABILITY(cacao_env,can_redefine_classes)
3943  CHECK_ADD_CAPABILITY(cacao_env,can_signal_thread)
3944  CHECK_ADD_CAPABILITY(cacao_env,can_get_source_file_name)
3945  CHECK_ADD_CAPABILITY(cacao_env,can_get_line_numbers)
3946  CHECK_ADD_CAPABILITY(cacao_env,can_get_source_debug_extension)
3947  CHECK_ADD_CAPABILITY(cacao_env,can_access_local_variables)
3948  CHECK_ADD_CAPABILITY(cacao_env,can_maintain_original_method_order)
3949  CHECK_ADD_CAPABILITY(cacao_env,can_generate_single_step_events)
3950  CHECK_ADD_CAPABILITY(cacao_env,can_generate_exception_events)
3951  CHECK_ADD_CAPABILITY(cacao_env,can_generate_frame_pop_events)
3952  CHECK_ADD_CAPABILITY(cacao_env,can_generate_breakpoint_events)
3953  CHECK_ADD_CAPABILITY(cacao_env,can_suspend)
3954  CHECK_ADD_CAPABILITY(cacao_env,can_redefine_any_class)
3955  CHECK_ADD_CAPABILITY(cacao_env,can_get_current_thread_cpu_time)
3956  CHECK_ADD_CAPABILITY(cacao_env,can_get_thread_cpu_time)
3957  CHECK_ADD_CAPABILITY(cacao_env,can_generate_method_entry_events)
3958  CHECK_ADD_CAPABILITY(cacao_env,can_generate_method_exit_events)
3959  CHECK_ADD_CAPABILITY(cacao_env,can_generate_all_class_hook_events)
3960  CHECK_ADD_CAPABILITY(cacao_env,can_generate_compiled_method_load_events)
3961  CHECK_ADD_CAPABILITY(cacao_env,can_generate_monitor_events)
3962  CHECK_ADD_CAPABILITY(cacao_env,can_generate_vm_object_alloc_events)
3963  CHECK_ADD_CAPABILITY(cacao_env,can_generate_native_method_bind_events)
3964  CHECK_ADD_CAPABILITY(cacao_env,can_generate_garbage_collection_events)
3965  CHECK_ADD_CAPABILITY(cacao_env,can_generate_object_free_events)
3966 
3967 
3968  return JVMTI_ERROR_NONE;
3969 }
3970 
3971 
3972 #define CHECK_DEL_CAPABILITY(env,CAN) \
3973  if (capabilities_ptr->CAN == 1) \
3974  env->capabilities.CAN = 0;
3975 
3976 /* RelinquishCapabilities *****************************************************
3977 
3978  Relinquish the capabilities pointed to by capabilities_ptr.
3979 
3980 *******************************************************************************/
3981 
3982 static jvmtiError
3984  const jvmtiCapabilities * capabilities_ptr)
3985 {
3986  environment* cacao_env;
3987 
3992 
3993  if ((env == NULL) || (capabilities_ptr == NULL))
3994  return JVMTI_ERROR_NULL_POINTER;
3995 
3996  cacao_env = (environment*)env;
3997 
3998  CHECK_DEL_CAPABILITY(cacao_env,can_tag_objects)
3999  CHECK_DEL_CAPABILITY(cacao_env,can_generate_field_modification_events)
4000  CHECK_DEL_CAPABILITY(cacao_env,can_generate_field_access_events)
4001  CHECK_DEL_CAPABILITY(cacao_env,can_get_bytecodes)
4002  CHECK_DEL_CAPABILITY(cacao_env,can_get_synthetic_attribute)
4003  CHECK_DEL_CAPABILITY(cacao_env,can_get_owned_monitor_info)
4004  CHECK_DEL_CAPABILITY(cacao_env,can_get_current_contended_monitor)
4005  CHECK_DEL_CAPABILITY(cacao_env,can_get_monitor_info)
4006  CHECK_DEL_CAPABILITY(cacao_env,can_pop_frame)
4007  CHECK_DEL_CAPABILITY(cacao_env,can_redefine_classes)
4008  CHECK_DEL_CAPABILITY(cacao_env,can_signal_thread)
4009  CHECK_DEL_CAPABILITY(cacao_env,can_get_source_file_name)
4010  CHECK_DEL_CAPABILITY(cacao_env,can_get_line_numbers)
4011  CHECK_DEL_CAPABILITY(cacao_env,can_get_source_debug_extension)
4012  CHECK_DEL_CAPABILITY(cacao_env,can_access_local_variables)
4013  CHECK_DEL_CAPABILITY(cacao_env,can_maintain_original_method_order)
4014  CHECK_DEL_CAPABILITY(cacao_env,can_generate_single_step_events)
4015  CHECK_DEL_CAPABILITY(cacao_env,can_generate_exception_events)
4016  CHECK_DEL_CAPABILITY(cacao_env,can_generate_frame_pop_events)
4017  CHECK_DEL_CAPABILITY(cacao_env,can_generate_breakpoint_events)
4018  CHECK_DEL_CAPABILITY(cacao_env,can_suspend)
4019  CHECK_DEL_CAPABILITY(cacao_env,can_redefine_any_class)
4020  CHECK_DEL_CAPABILITY(cacao_env,can_get_current_thread_cpu_time)
4021  CHECK_DEL_CAPABILITY(cacao_env,can_get_thread_cpu_time)
4022  CHECK_DEL_CAPABILITY(cacao_env,can_generate_method_entry_events)
4023  CHECK_DEL_CAPABILITY(cacao_env,can_generate_method_exit_events)
4024  CHECK_DEL_CAPABILITY(cacao_env,can_generate_all_class_hook_events)
4025  CHECK_DEL_CAPABILITY(cacao_env,can_generate_compiled_method_load_events)
4026  CHECK_DEL_CAPABILITY(cacao_env,can_generate_monitor_events)
4027  CHECK_DEL_CAPABILITY(cacao_env,can_generate_vm_object_alloc_events)
4028  CHECK_DEL_CAPABILITY(cacao_env,can_generate_native_method_bind_events)
4029  CHECK_DEL_CAPABILITY(cacao_env,can_generate_garbage_collection_events)
4030  CHECK_DEL_CAPABILITY(cacao_env,can_generate_object_free_events)
4031 
4032  return JVMTI_ERROR_NONE;
4033 }
4034 
4035 /* GetAvailableProcessors *****************************************************
4036 
4037  Get number of processors available to the virtual machine.
4038 
4039 *******************************************************************************/
4040 
4041 static jvmtiError
4042 GetAvailableProcessors (jvmtiEnv * env, jint * processor_count_ptr)
4043 {
4048 
4049  if (processor_count_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
4050 
4051  log_text ("GetAvailableProcessors IMPLEMENT ME!!!");
4052 
4053  *processor_count_ptr = 1; /* where do I get this ?*/
4054 
4055  return JVMTI_ERROR_NONE;
4056 }
4057 
4058 /* GetEnvironmentLocalStorage **************************************************
4059 
4060  Called by the agent to get the value of the JVM TI environment-local storage.
4061 
4062 *******************************************************************************/
4063 
4064 static jvmtiError
4065 GetEnvironmentLocalStorage (jvmtiEnv * env, void **data_ptr)
4066 {
4067  if ((env == NULL) || (data_ptr == NULL)) return JVMTI_ERROR_NULL_POINTER;
4068 
4069  *data_ptr = ((environment*)env)->EnvironmentLocalStorage;
4070 
4071  return JVMTI_ERROR_NONE;
4072 }
4073 
4074 /* SetEnvironmentLocalStorage **************************************************
4075 
4076  The VM stores a pointer value associated with each environment. Agents can
4077  allocate memory in which they store environment specific information.
4078 
4079 *******************************************************************************/
4080 
4081 static jvmtiError
4082 SetEnvironmentLocalStorage (jvmtiEnv * env, const void *data)
4083 {
4084  if (env == NULL) return JVMTI_ERROR_NULL_POINTER;
4085 
4086  ((environment*)env)->EnvironmentLocalStorage = (void*) data;
4087 
4088  return JVMTI_ERROR_NONE;
4089 }
4090 
4091 /* AddToBootstrapClassLoaderSearch ********************************************
4092 
4093  After the bootstrap class loader unsuccessfully searches for a class, the
4094  specified platform-dependent search path segment will be searched as well.
4095 
4096 *******************************************************************************/
4097 
4098 static jvmtiError
4099 AddToBootstrapClassLoaderSearch (jvmtiEnv * env, const char *segment)
4100 {
4101  char* tmp_bcp;
4102  int ln;
4103 
4107 
4108  if (segment == NULL) return JVMTI_ERROR_NULL_POINTER;
4109 
4110  ln = strlen(bootclasspath) + strlen(":") + strlen(segment);
4111  tmp_bcp = MNEW(char, ln);
4112  strcat(tmp_bcp, bootclasspath);
4113  strcat(tmp_bcp, ":");
4114  strcat(tmp_bcp, segment);
4115  MFREE(bootclasspath,char,ln);
4116  bootclasspath = tmp_bcp;
4117 
4118  return JVMTI_ERROR_NONE;
4119 }
4120 
4121 /* SetVerboseFlag *************************************************************
4122 
4123  Control verbose output. This is the output which typically is sent to stderr
4124 
4125 *******************************************************************************/
4126 
4127 static jvmtiError
4128 SetVerboseFlag (jvmtiEnv * env, jvmtiVerboseFlag flag, jboolean value)
4129 {
4130  switch (flag) {
4131  case JVMTI_VERBOSE_OTHER:
4132  /* where is this defined ?
4133  runverbose = value;
4134  */
4135  break;
4136  case JVMTI_VERBOSE_GC:
4137  opt_verbosegc = value;
4138  break;
4139  case JVMTI_VERBOSE_CLASS:
4140  loadverbose = value;
4141  break;
4142  case JVMTI_VERBOSE_JNI:
4143  break;
4144  default:
4146  }
4147  return JVMTI_ERROR_NONE;
4148 }
4149 
4150 /* GetObjectSize **************************************************************
4151 
4152  For the object object return the size.
4153 
4154 *******************************************************************************/
4155 
4156 static jvmtiError
4157 GetObjectSize (jvmtiEnv * env, jobject object, jlong * size_ptr)
4158 {
4163 
4164  if (size_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
4167 
4168  *size_ptr = ((java_objectheader*)object)->vftbl->class->instancesize;
4169 
4170  return JVMTI_ERROR_NONE;
4171 }
4172 
4173 
4174 /* *****************************************************************************
4175 
4176  Environment variables
4177 
4178 *******************************************************************************/
4179 
4180 static jvmtiCapabilities JVMTI_Capabilities = {
4181  0, /* can_tag_objects */
4182  0, /* can_generate_field_modification_events */
4183  0, /* can_generate_field_access_events */
4184  1, /* can_get_bytecodes */
4185  0, /* can_get_synthetic_attribute */
4186 
4187 #if defined(ENABLE_THREADS)
4188  1, /* can_get_owned_monitor_info */
4189  1, /* can_get_current_contended_monitor */
4190 #else
4191  0, /* can_get_owned_monitor_info */
4192  0, /* can_get_current_contended_monitor */
4193 #endif
4194 
4195  0, /* can_get_monitor_info */
4196  0, /* can_pop_frame */
4197  0, /* can_redefine_classes */
4198  0, /* can_signal_thread */
4199  1, /* can_get_source_file_name */
4200  1, /* can_get_line_numbers */
4201  0, /* can_get_source_debug_extension */
4202  0, /* can_access_local_variables */
4203  0, /* can_maintain_original_method_order */
4204  0, /* can_generate_single_step_events */
4205  1, /* can_generate_exception_events */
4206  0, /* can_generate_frame_pop_events */
4207  1, /* can_generate_breakpoint_events */
4208  1, /* can_suspend */
4209  0, /* can_redefine_any_class */
4210  0, /* can_get_current_thread_cpu_time */
4211  0, /* can_get_thread_cpu_time */
4212  1, /* can_generate_method_entry_events */
4213  0, /* can_generate_method_exit_events */
4214  0, /* can_generate_all_class_hook_events */
4215  0, /* can_generate_compiled_method_load_events */
4216  1, /* can_generate_monitor_events */
4217  0, /* can_generate_vm_object_alloc_events */
4218  0, /* can_generate_native_method_bind_events */
4219  0, /* can_generate_garbage_collection_events */
4220  0, /* can_generate_object_free_events */
4221 };
4222 
4223 static struct jvmtiEnv_struct JVMTI_EnvTable = {
4224  NULL,
4226  NULL,
4227  &GetAllThreads,
4228  &SuspendThread,
4229  &ResumeThread,
4230  &StopThread,
4231  &InterruptThread,
4232  &GetThreadInfo,
4235  &RunAgentThread,
4239  &GetFrameCount,
4240  &GetThreadState,
4241  NULL,
4243  &NotifyFramePop,
4244  &GetLocalObject,
4245  &GetLocalInt,
4246  &GetLocalLong,
4247  &GetLocalFloat,
4248  &GetLocalDouble,
4249  &SetLocalObject,
4250  &SetLocalInt,
4251  &SetLocalLong,
4252  &SetLocalFloat,
4253  &SetLocalDouble,
4256  &RawMonitorEnter,
4257  &RawMonitorExit,
4258  &RawMonitorWait,
4261  &SetBreakpoint,
4262  &ClearBreakpoint,
4263  NULL,
4268  NULL,
4269  &Allocate,
4270  &Deallocate,
4272  &GetClassStatus,
4275  &GetClassMethods,
4276  &GetClassFields,
4278  &IsInterface,
4279  &IsArrayClass,
4280  &GetClassLoader,
4283  &GetFieldName,
4286  &IsFieldSynthetic,
4287  &GetMethodName,
4290  NULL,
4291  &GetMaxLocals,
4292  &GetArgumentsSize,
4296  NULL,
4297  NULL,
4298  &GetBytecodes,
4299  &IsMethodNative,
4301  &GetLoadedClasses,
4303  &PopFrame,
4304  NULL,
4305  NULL,
4306  NULL,
4307  NULL,
4308  NULL,
4309  NULL,
4310  &RedefineClasses,
4311  &GetVersionNumber,
4312  &GetCapabilities,
4314  &IsMethodObsolete,
4316  &ResumeThreadList,
4317  NULL,
4318  NULL,
4319  NULL,
4320  NULL,
4321  NULL,
4322  NULL,
4327  &GetStackTrace,
4328  NULL,
4329  &GetTag,
4330  &SetTag,
4334  &IterateOverHeap,
4336  NULL,
4338  NULL,
4339  NULL,
4340  NULL,
4341  NULL,
4342  NULL,
4346  &GenerateEvents,
4351  &GetErrorName,
4356  &GetPhase,
4360  &GetThreadCpuTime,
4361  &GetTimerInfo,
4362  &GetTime,
4364  NULL,
4365  &AddCapabilities,
4368  NULL,
4369  NULL,
4373  &SetVerboseFlag,
4374  NULL,
4375  NULL,
4376  NULL,
4377  &GetObjectSize
4378 };
4379 
4380 /* jvmti_set_phase ************************************************************
4381 
4382  sets a new jvmti phase a fires an apropriate event.
4383 
4384 *******************************************************************************/
4385 
4387  genericEventData d;
4388 
4389  fprintf (stderr,"set JVMTI phase %d\n",p);
4390  fflush(stderr);
4391 
4392  switch (p) {
4393  case JVMTI_PHASE_ONLOAD:
4394  phase = p;
4395  return;
4397  phase = p;
4398  return;
4399  case JVMTI_PHASE_START:
4400  phase = p;
4402  break;
4403  case JVMTI_PHASE_LIVE:
4404  phase = p;
4405  d.ev = JVMTI_EVENT_VM_INIT;
4406  jvmti_fireEvent(&d);
4407  /* thread start event for main thread */
4409  break;
4410  case JVMTI_PHASE_DEAD:
4411  phase = p;
4413  break;
4414  default:
4415  log_text("wrong jvmti phase to be set");
4416  exit(1);
4417  }
4418 
4419  jvmti_fireEvent(&d);
4420 }
4421 
4422 
4423 /* jvmti_new_environment ******************************************************
4424 
4425  creates a new JVMTI environment
4426 
4427 *******************************************************************************/
4428 
4430  environment* env;
4431 
4432  if (envs == NULL) {
4433  envs = heap_allocate(sizeof(environment),true,NULL);
4434  env = envs;
4435  } else {
4436  env = envs;
4437  while (env->next != NULL) env = env->next;
4438  env->next = heap_allocate(sizeof(environment),true,NULL);
4439  env = env->next;
4440  }
4441 
4442  env->env = heap_allocate(sizeof(struct jvmtiEnv_struct),true,NULL);
4443  memcpy(env->env,&JVMTI_EnvTable,sizeof(struct jvmtiEnv_struct));
4445  sizeof(jvmtiEventModeLL));
4446  /* To possess a capability, the agent must add the capability.*/
4447  memset(&(env->capabilities), 0, sizeof(jvmtiCapabilities));
4448  RelinquishCapabilities(&(env->env),&(env->capabilities));
4449  env->EnvironmentLocalStorage = NULL;
4450  env->tls = NULL;
4451 
4452  /* initialize cacao debugging facilities */
4454 
4455  return (jvmtiEnv*)env;
4456 }
4457 
4458 /* jvmti_agentload ************************************************************
4459 
4460  loads the indicated shared library containing the jvmti agent and calls the
4461  Agent_OnLoad function.
4462 
4463 *******************************************************************************/
4464 
4465 void jvmti_agentload(char* opt_arg, bool agentbypath, lt_dlhandle *handle, char **libname) {
4466  lt_ptr onload;
4467  char *arg;
4468  int i=0,len;
4469  jint retval;
4470 
4471  len = strlen(opt_arg);
4472 
4473  /* separate arguments */
4474 
4475  while ((opt_arg[i] != '=') && (i < len))
4476  i++;
4477 
4478  opt_arg[i] = '\0';
4479 
4480  if (i < len)
4481  arg = &opt_arg[i + 1];
4482  else
4483  arg = "";
4484 
4485  if (agentbypath) {
4486  /* -agentpath */
4487 
4488  *libname = GCMNEW(char, i);
4489 
4490  strcpy(*libname, opt_arg);
4491  }
4492  else {
4493  /* -agentlib */
4494 
4495  len = strlen("lib") + i + strlen(".so") + strlen("0");
4496 
4497  *libname = GCMNEW(char, len);
4498 
4499  strcpy(*libname, "lib");
4500  strcat(*libname, opt_arg);
4501  strcat(*libname, ".so");
4502  }
4503 
4504  /* try to open the library */
4505  lt_dlinit();
4506  if (!(*handle = lt_dlopen(*libname))) {
4507  fprintf(stderr,"Could not find agent library: %s (%s)\n",*libname,lt_dlerror());
4508  vm_shutdown(1);
4509  }
4510 
4511  /* resolve Agent_OnLoad function */
4512  if (!(onload = lt_dlsym(*handle, "Agent_OnLoad"))) {
4513  fprintf(stderr,"unable to load Agent_OnLoad function in %s (%s)\n",*libname,lt_dlerror());
4514  vm_shutdown(1);
4515  }
4516 
4517  /* resolve Agent_UnLoad function */
4518  unload = lt_dlsym(*handle, "Agent_Unload");
4519 
4520  retval =
4521  ((JNIEXPORT jint JNICALL (*) (JavaVM *vm, char *options, void *reserved))
4522  onload) ((JavaVM *) _Jv_jvm, arg, NULL);
4523 
4524  if (retval != 0) exit (retval);
4525 }
4526 
4527 /* jvmti_agentunload **********************************************************
4528 
4529  calls the Agent_UnLoad function in the jvmti agent if present.
4530 
4531 *******************************************************************************/
4532 
4534  if (unload != NULL) {
4535  ((JNIEXPORT void JNICALL (*) (JavaVM *vm)) unload)
4537  }
4538 }
4539 
4540 
4541 /*
4542  * These are local overrides for various environment variables in Emacs.
4543  * Please do not remove this and leave it at the end of the file, where
4544  * Emacs will automagically detect them.
4545  * ---------------------------------------------------------------------
4546  * Local variables:
4547  * mode: c
4548  * indent-tabs-mode: t
4549  * c-basic-offset: 4
4550  * tab-width: 4
4551  * End:
4552  * vim:noexpandtab:sw=4:ts=4:
4553  */
static jvmtiError SetLocalObject(jvmtiEnv *env, jthread thread, jint depth, jint slot, jobject value)
Definition: jvmti.c:1342
static jvmtiError RunAgentThread(jvmtiEnv *env, jthread thread, jvmtiStartFunction proc, const void *arg, jint priority)
Definition: jvmti.c:856
mutex_t dbgcomlock
Definition: jvmti.c:79
char signature_type
Definition: cacaodbg.h:45
void gc_call(void)
Definition: gc.c:492
#define JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT
Definition: jvmti.h:1155
jthreadGroup parent
Definition: jvmti.h:409
bool builtin_instanceof(java_handle_t *o, classinfo *c)
Definition: builtin.cpp:403
Utf8String name
Definition: method.hpp:71
jboolean b
Definition: cacaodbg.h:47
jlong jlong jlong jlong jint jmethodID jint slot
Definition: jvmti.h:497
char * opt_arg
Definition: options.cpp:47
static jvmtiError GetMethodModifiers(jvmtiEnv *env, jmethodID method, jint *modifiers_ptr)
Definition: jvmti.c:2338
static jvmtiError GetObjectsWithTags(jvmtiEnv *env, jint tag_count, const jlong *tags, jint *count_ptr, jobject **object_result_ptr, jlong **tag_result_ptr)
Definition: jvmti.c:3213
#define GCMNEW(type, num)
Definition: memory.hpp:118
static jvmtiError IsMethodNative(jvmtiEnv *env, jmethodID method, jboolean *is_native_ptr)
Definition: jvmti.c:2561
jobject object
Definition: cacaodbg.h:43
classinfo * class_java_lang_ThreadGroup
Definition: globals.cpp:42
struct JNINativeInterface jniNativeInterface
Definition: jvmti.h:197
#define CHECK_PHASE_END
Definition: jvmti.c:116
static jvmtiError IsArrayClass(jvmtiEnv *env, jclass klass, jboolean *is_array_class_ptr)
Definition: jvmti.c:2051
jlong jlong jlong jlong jint void * user_data
Definition: jvmti.h:481
JNIEnv jthread jmethodID jlocation jclass jobject jfieldID field
Definition: jvmti.h:221
JNIEXPORT jint JNICALL Java_java_lang_VMSystem_identityHashCode(JNIEnv *env, jclass clazz, jobject obj)
jfieldID field
Definition: cacaodbg.h:44
codeinfo * code
Definition: stacktrace.hpp:50
jvmtiStartFunction sf
Definition: jvmti.c:836
java_lang_String * name
Definition: cacaodbg.h:68
void threads_thread_interrupt(threadobject *t)
const JNIInvokeInterface_ _Jv_JNIInvokeInterface
Definition: jni.cpp:3841
static jvmtiError GetExtensionEvents(jvmtiEnv *env, jint *extension_count_ptr, jvmtiExtensionEventInfo **extensions)
Definition: jvmti.c:3354
void jvmti_cacaodbgserver_quit()
Definition: cacaodbg.c:211
s4 jcodelength
Definition: method.hpp:85
static jvmtiError GetMethodLocation(jvmtiEnv *env, jmethodID method, jlocation *start_location_ptr, jlocation *end_location_ptr)
Definition: jvmti.c:2461
static jvmtiError NotifyFramePop(jvmtiEnv *env, jthread thread, jint depth)
Definition: jvmti.c:1227
static jvmtiError GetThreadState(jvmtiEnv *env, jthread thread, jint *thread_state_ptr)
Definition: jvmti.c:1126
void jvmti_set_phase(jvmtiPhase p)
Definition: jvmti.c:4386
static jvmtiError Allocate(jvmtiEnv *env, jlong size, unsigned char **mem_ptr)
Definition: jvmti.c:1749
Utf8String to_utf8() const
Definition: string.cpp:437
static jvmtiError GetLocalObject(jvmtiEnv *env, jthread thread, jint depth, jint slot, jobject *value_ptr)
Definition: jvmti.c:1245
static jvmtiError RedefineClasses(jvmtiEnv *env, jint class_count, const jvmtiClassDefinition *class_definitions)
Definition: jvmti.c:2680
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
classinfo * load_class_from_sysloader(Utf8String name)
Definition: loader.cpp:1012
static jvmtiError GetSourceDebugExtension(jvmtiEnv *env, jclass klass, char **source_debug_extension_ptr)
Definition: jvmti.c:2737
static jvmtiError SetLocalInt(jvmtiEnv *env, jthread thread, jint depth, jint slot, jint value)
Definition: jvmti.c:1362
#define JVMTI_CLASS_STATUS_PRIMITIVE
Definition: jvmti.h:1175
#define JVMTI_CLASS_STATUS_PREPARED
Definition: jvmti.h:1171
jvmtiThreadLocalStorage * next
Definition: jvmti.c:95
static jvmtiPhase phase
Definition: jvmti.c:83
jvmtiVerboseFlag
Definition: jvmti.h:184
static jvmtiError SetLocalFloat(jvmtiEnv *env, jthread thread, jint depth, jint slot, jfloat value)
Definition: jvmti.c:1402
static jvmtiError GetStackTrace(jvmtiEnv *env, jthread thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo *frame_buffer, jint *count_ptr)
Definition: jvmti.c:2847
static jvmtiError GetThreadLocalStorage(jvmtiEnv *env, jthread thread, void **data_ptr)
Definition: jvmti.c:2975
static JavaString from_utf8(Utf8String)
Definition: string.cpp:184
static jvmtiError GetFieldModifiers(jvmtiEnv *env, jclass klass, jfieldID field, jint *modifiers_ptr)
Definition: jvmti.c:2220
static jvmtiError DisposeEnvironment(jvmtiEnv *env)
Definition: jvmti.c:3399
static jvmtiError SetEventCallbacks(jvmtiEnv *env, const jvmtiEventCallbacks *callbacks, jint size_of_callbacks)
Definition: jvmti.c:3280
jvmtiEventMode jvmtiEvent jthread event_thread
Definition: jvmti.h:721
JNIEXPORT jboolean JNICALL Java_java_lang_VMClass_isPrimitive(JNIEnv *env, jclass clazz, jclass klass)
void heap_free(void *p)
Definition: heap.c:366
s4 state
Definition: class.hpp:115
jvmtiEnv env
Definition: jvmti.c:99
static jvmtiError InterruptThread(jvmtiEnv *env, jthread thread)
Definition: jvmti.c:647
static struct jvmtiEnv_struct JVMTI_EnvTable
Definition: jvmti.c:110
jlocation start_location
Definition: jvmti.h:172
jthread const void * data
Definition: jvmti.h:1026
#define JVMTI_THREAD_STATE_SLEEPING
Definition: jvmti.h:1156
jobject jthreadGroup
Definition: jvmti.h:43
static jvmtiError DestroyRawMonitor(jvmtiEnv *env, jrawMonitorID monitor)
Definition: jvmti.c:1472
static jvmtiError PopFrame(jvmtiEnv *env, jthread thread)
Definition: jvmti.c:2661
jvmtiError SetThreadLocalStorage(jvmtiEnv *jenv, jthread thread, const void *data)
Definition: jvmti.c:3016
jlocation catch_location
Definition: cacaodbg.h:51
static jvmtiError GetThreadInfo(jvmtiEnv *env, jthread t, jvmtiThreadInfo *info_ptr)
Definition: jvmti.c:677
_Jv_JavaVM JavaVM
Definition: jni.hpp:114
static jvmtiError GetClassModifiers(jvmtiEnv *env, jclass klass, jint *modifiers_ptr)
Definition: jvmti.c:1895
bool lock_monitor_exit(java_handle_t *o)
Definition: lock.cpp:900
void * arg
Definition: jvmti.c:838
#define UTF_SIZE(u)
Definition: utf8.hpp:251
jvmtiEnv * jvmti_env
Definition: cacaodbg.h:38
static jvmtiError GetClassFields(jvmtiEnv *env, jclass klass, jint *field_count_ptr, jfieldID **fields_ptr)
Definition: jvmti.c:1956
#define COPY_RESPONSE(name_ptr, str)
Definition: jvmti.c:3442
jthread jvmtiThreadInfo * info_ptr
Definition: jvmti.h:739
static jvmtiError StopThread(jvmtiEnv *env, jthread thread, jobject exception)
Definition: jvmti.c:627
jclass klass
Definition: cacaodbg.h:42
#define JVMTI_CLASS_STATUS_ARRAY
Definition: jvmti.h:1174
unsigned char * class_data
Definition: cacaodbg.h:56
classinfo * load_class_bootstrap(Utf8String name)
Definition: loader.cpp:1276
jvmtiAddrLocationMap * map
Definition: cacaodbg.h:59
static jvmtiError RawMonitorWait(jvmtiEnv *env, jrawMonitorID monitor, jlong millis)
Definition: jvmti.c:1552
JNIEnv jthread jclass klass
Definition: jvmti.h:300
jvmtiEventMode mode
Definition: jvmti.h:721
#define JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER
Definition: jvmti.h:1152
static jvmtiError GetEnvironmentLocalStorage(jvmtiEnv *env, void **data_ptr)
Definition: jvmti.c:4065
static jvmtiError GetAvailableProcessors(jvmtiEnv *env, jint *processor_count_ptr)
Definition: jvmti.c:4042
jvmtiEventCallbacks callbacks
Definition: jvmti.c:101
jvmtiThreadLocalStorage * tls
Definition: jvmti.c:107
static jvmtiError SetEventNotificationMode(jvmtiEnv *env, jvmtiEventMode mode, jvmtiEvent event_type, jthread event_thread,...)
Definition: jvmti.c:424
static jvmtiError ForceGarbageCollection(jvmtiEnv *env)
Definition: jvmti.c:3105
void * address
Definition: cacaodbg.h:48
JNIEnv jclass jobject const char * name
Definition: jvmti.h:312
static jvmtiError GetJLocationFormat(jvmtiEnv *env, jvmtiJlocationFormat *format_ptr)
Definition: jvmti.c:3561
classinfo * class_java_lang_Object
Definition: globals.cpp:28
static jvmtiError GetMethodDeclaringClass(jvmtiEnv *env, jmethodID method, jclass *declaring_class_ptr)
Definition: jvmti.c:2314
static jvmtiError RelinquishCapabilities(jvmtiEnv *env, const jvmtiCapabilities *capabilities_ptr)
Definition: jvmti.c:3983
static jvmtiError IsInterface(jvmtiEnv *env, jclass klass, jboolean *is_interface_ptr)
Definition: jvmti.c:2029
static jvmtiError GetFieldDeclaringClass(jvmtiEnv *env, jclass klass, jfieldID field, jclass *declaring_class_ptr)
Definition: jvmti.c:2189
jlong jlong jlong * tag_ptr
Definition: jvmti.h:481
JNIEnv jthread jobject jclass jlong size
Definition: jvmti.h:387
jobject jthread
Definition: jvmti.h:42
static jvmtiError SetFieldAccessWatch(jvmtiEnv *env, jclass klass, jfieldID field)
Definition: jvmti.c:1672
static jvmtiError Deallocate(jvmtiEnv *env, unsigned char *mem)
Definition: jvmti.c:1771
void vm_shutdown()
Hook point before the VM is actually destroyed.
Definition: hook.hpp:168
void ** new_address_ptr
Definition: cacaodbg.h:49
static jvmtiError CreateRawMonitor(jvmtiEnv *env, const char *name, jrawMonitorID *monitor_ptr)
Definition: jvmti.c:1442
jthread jvmti_get_current_thread()
Definition: cacaodbg.c:95
static jvmtiError GetTime(jvmtiEnv *env, jlong *nanos_ptr)
Definition: jvmti.c:3863
static jvmtiError GetLocalLong(jvmtiEnv *env, jthread thread, jint depth, jint slot, jlong *value_ptr)
Definition: jvmti.c:1282
void(* functionptr)(void)
Definition: global.hpp:39
methodinfo * m
Definition: code.hpp:75
jmethodID catch_method
Definition: cacaodbg.h:50
jvmtiEnv * jvmti_new_environment()
Definition: jvmti.c:4429
static jvmtiError SuspendThreadList(jvmtiEnv *env, jint request_count, const jthread *request_list, jvmtiError *results)
Definition: jvmti.c:2779
static jvmtiError check_thread_is_alive(jthread t)
Definition: jvmti.c:132
static jvmtiError GetClassSignature(jvmtiEnv *env, jclass klass, char **signature_ptr, char **generic_ptr)
Definition: jvmti.c:1787
jlong max_value
Definition: jvmti.h:572
jthread event_thread
Definition: jvmti.c:87
void lock_notify_all_object(java_handle_t *o)
Definition: lock.cpp:1359
java_handle_t * jclass
Definition: jni.hpp:88
jvmtiEnv * jvmti_env
Definition: jvmti.c:837
jthreadGroup thread_group
Definition: jvmti.h:180
JNINativeInterface_ _Jv_JNINativeInterface
Definition: jni.cpp:3856
jlong jlong jlong jlong jint depth
Definition: jvmti.h:497
char * to_chars() const
Definition: string.cpp:413
jvmtiError
Definition: jvmti.h:49
static jvmtiError GetMethodName(jvmtiEnv *env, jmethodID method, char **name_ptr, char **signature_ptr, char **generic_ptr)
Definition: jvmti.c:2273
JNIEnv jthread jmethodID jlocation jobject exception
Definition: jvmti.h:272
Utf8String descriptor
Definition: method.hpp:72
JNIEnv void * arg
Definition: jvmti.h:405
static jvmtiError IterateOverReachableObjects(jvmtiEnv *env, jvmtiHeapRootCallback heap_root_callback, jvmtiStackReferenceCallback stack_ref_callback, jvmtiObjectReferenceCallback object_ref_callback, void *user_data)
Definition: jvmti.c:3146
static jvmtiError GetOwnedMonitorInfo(jvmtiEnv *env, jthread thread, jint *owned_monitor_count_ptr, jobject **owned_monitors_ptr)
Definition: jvmti.c:706
jvmtiEventMode
Definition: jvmti.h:630
jthread jobject * monitor_ptr
Definition: jvmti.h:746
static jvmtiError GetThreadCpuTime(jvmtiEnv *env, jthread thread, jlong *nanos_ptr)
Definition: jvmti.c:3827
static jvmtiError GetLocalDouble(jvmtiEnv *env, jthread thread, jint depth, jint slot, jdouble *value_ptr)
Definition: jvmti.c:1322
static jvmtiError SuspendThread(jvmtiEnv *env, jthread thread)
Definition: jvmti.c:574
void jvmti_fireEvent(genericEventData *data)
Definition: jvmti.c:402
jboolean may_skip_backward
Definition: jvmti.h:574
java/lang/Object
static jvmtiCapabilities JVMTI_Capabilities
Definition: jvmti.c:111
jvmtiEventModeLL * next
Definition: jvmti.c:88
JNIEXPORT jobject JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, jclass clazz, jobject _this)
void jvmti_cacao_debug_init()
Definition: cacaodbg.c:272
static lt_ptr unload
Definition: jvmti.c:112
static jvmtiError RawMonitorNotify(jvmtiEnv *env, jrawMonitorID monitor)
Definition: jvmti.c:1581
static jvmtiError GenerateEvents(jvmtiEnv *env, jvmtiEvent event_type)
Definition: jvmti.c:3311
static jvmtiError GetThreadCpuTimerInfo(jvmtiEnv *env, jvmtiTimerInfo *info_ptr)
Definition: jvmti.c:3808
JNIEnv jthread jmethodID method
Definition: jvmti.h:207
static jvmtiError IsMethodSynthetic(jvmtiEnv *env, jmethodID method, jboolean *is_synthetic_ptr)
Definition: jvmti.c:2588
static jvmtiError ClearFieldAccessWatch(jvmtiEnv *env, jclass klass, jfieldID field)
Definition: jvmti.c:1691
Instruction::InstID tmp[]
Definition: Matcher.cpp:55
static jvmtiError GetObjectMonitorUsage(jvmtiEnv *env, jobject object, jvmtiMonitorUsage *info_ptr)
Definition: jvmti.c:2122
#define JVMTI_THREAD_STATE_INTERRUPTED
Definition: jvmti.h:1160
static jvmtiError GetPotentialCapabilities(jvmtiEnv *env, jvmtiCapabilities *capabilities_ptr)
Definition: jvmti.c:3888
static jvmtiError GetSystemProperty(jvmtiEnv *env, const char *property, char **value_ptr)
Definition: jvmti.c:3655
static JNINativeMethod methods[]
static vm_calls_t callbacks
Definition: hpi.cpp:45
jlocation location
Definition: cacaodbg.h:41
static jvmtiError GetSystemProperties(jvmtiEnv *env, jint *count_ptr, char ***property_ptr)
Definition: jvmti.c:3576
#define JVMTI_VERSION
Definition: jvmti.h:39
static jvmtiError GetAllThreads(jvmtiEnv *env, jint *threads_count_ptr, jthread **threads_ptr)
Definition: jvmti.c:540
void lock_notify_object(java_handle_t *o)
Definition: lock.cpp:1340
static jvmtiError SetEnvironmentLocalStorage(jvmtiEnv *env, const void *data)
Definition: jvmti.c:4082
classinfo * class_java_lang_Class
Definition: globals.cpp:35
methodinfo * class_resolvemethod(classinfo *c, Utf8String name, Utf8String desc)
Definition: class.cpp:1145
static jvmtiError GetFieldName(jvmtiEnv *env, jclass klass, jfieldID field, char **name_ptr, char **signature_ptr, char **generic_ptr)
Definition: jvmti.c:2143
char * name
Definition: jvmti.h:177
#define JNI_TRUE
Definition: jni.hpp:108
#define CHECK_PHASE(chkphase)
Definition: jvmti.c:115
#define CHECK_THREAD_IS_ALIVE(t)
Definition: jvmti.c:120
jint jthread ** threads_ptr
Definition: jvmti.h:727
jvmtiError jvmti_get_all_threads(jint *threads_count_ptr, threadobject ***threads_ptr)
Definition: cacaodbg.c:52
bool interrupted
Definition: thread.hpp:119
static jvmtiError AddCapabilities(jvmtiEnv *env, const jvmtiCapabilities *capabilities_ptr)
Definition: jvmti.c:3919
JNIEnv jthread thread
Definition: jvmti.h:207
#define JVMTI_CLASS_STATUS_ERROR
Definition: jvmti.h:1173
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
jlong tag
Definition: jvmti.h:395
u1 * jcode
Definition: method.hpp:86
static jvmtiError GetLocalFloat(jvmtiEnv *env, jthread thread, jint depth, jint slot, jfloat *value_ptr)
Definition: jvmti.c:1302
static jvmtiError GetSourceFileName(jvmtiEnv *env, jclass klass, char **source_name_ptr)
Definition: jvmti.c:1864
MIIterator i
void utf_sprint_convert_to_latin1(char *buffer, Utf8String u)
Definition: utf8.cpp:584
static jvmtiError GetCurrentThreadCpuTime(jvmtiEnv *env, jlong *nanos_ptr)
Definition: jvmti.c:3789
jboolean may_skip_forward
Definition: jvmti.h:573
bool opt_verbosegc
Definition: options.cpp:74
#define JVMTI_THREAD_STATE_WAITING
Definition: jvmti.h:1153
#define JVMTI_THREAD_STATE_IN_NATIVE
Definition: jvmti.h:1161
static jvmtiError GetExtensionFunctions(jvmtiEnv *env, jint *extension_count_ptr, jvmtiExtensionFunctionInfo **extensions)
Definition: jvmti.c:3329
static jvmtiError SetLocalLong(jvmtiEnv *env, jthread thread, jint depth, jint slot, jlong value)
Definition: jvmti.c:1382
#define JVMTI_THREAD_STATE_ALIVE
Definition: jvmti.h:1149
static jvmtiError GetLocalVariableTable(jvmtiEnv *env, jmethodID method, jint *entry_count_ptr, jvmtiLocalVariableEntry **table_ptr)
Definition: jvmti.c:2508
jvmtiCapabilities capabilities
Definition: jvmti.c:105
#define JVMTI_THREAD_STATE_SUSPENDED
Definition: jvmti.h:1159
java_handle_t * jobject
Definition: jni.hpp:87
JNIEnv * jni_env
Definition: jvmti.h:207
static jvmtiError GetObjectSize(jvmtiEnv *env, jobject object, jlong *size_ptr)
Definition: jvmti.c:4157
static jvmtiError IterateOverInstancesOfClass(jvmtiEnv *env, jclass klass, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, void *user_data)
Definition: jvmti.c:3191
static jvmtiError GetCapabilities(jvmtiEnv *env, jvmtiCapabilities *capabilities_ptr)
Definition: jvmti.c:2720
static jvmtiError SetLocalDouble(jvmtiEnv *env, jthread thread, jint depth, jint slot, jdouble value)
Definition: jvmti.c:1422
static jvmtiError GetPhase(jvmtiEnv *env, jvmtiPhase *phase_ptr)
Definition: jvmti.c:3753
jvmtiEventModeLL events[JVMTI_EVENT_END_ENUM-JVMTI_EVENT_START_ENUM]
Definition: jvmti.c:104
#define JVMTI_THREAD_STATE_WAITING_INDEFINITELY
Definition: jvmti.h:1154
static jvmtiError GetImplementedInterfaces(jvmtiEnv *env, jclass klass, jint *interface_count_ptr, jclass **interfaces_ptr)
Definition: jvmti.c:1985
static void * threadstartup(void *t)
Definition: jvmti.c:842
void lock_wait_for_object(java_handle_t *o, s8 millis, s4 nanos)
Definition: lock.cpp:1321
static jvmtiError GetCurrentContendedMonitor(jvmtiEnv *env, jthread thread, jobject *monitor_ptr)
Definition: jvmti.c:779
static jvmtiError GetLoadedClasses(jvmtiEnv *env, jint *class_count_ptr, jclass **classes_ptr)
Definition: jvmti.c:2609
static jvmtiError SetBreakpoint(jvmtiEnv *env, jmethodID method, jlocation location)
Definition: jvmti.c:1633
static void execute_callback(jvmtiEvent e, functionptr ec, genericEventData *data)
Definition: jvmti.c:145
void jvmti_agentunload()
Definition: jvmti.c:4533
static jvmtiError SetJNIFunctionTable(jvmtiEnv *env, const jniNativeInterface *function_table)
Definition: jvmti.c:3234
arraydescriptor * arraydesc
Definition: vftbl.hpp:101
static jvmtiError SetSystemProperty(jvmtiEnv *env, const char *property, const char *value)
Definition: jvmti.c:3707
static jvmtiError GetErrorName(jvmtiEnv *env, jvmtiError error, char **name_ptr)
Definition: jvmti.c:3447
static jvmtiError GetObjectHashCode(jvmtiEnv *env, jobject object, jint *hash_code_ptr)
Definition: jvmti.c:2098
MIIterator e
static jvmtiError RawMonitorNotifyAll(jvmtiEnv *env, jrawMonitorID monitor)
Definition: jvmti.c:1607
static jvmtiError IsFieldSynthetic(jvmtiEnv *env, jclass klass, jfieldID field, jboolean *is_synthetic_ptr)
Definition: jvmti.c:2251
jvmtiTimerKind kind
Definition: jvmti.h:575
void * EnvironmentLocalStorage
Definition: jvmti.c:106
static jvmtiError GetTag(jvmtiEnv *env, jobject object, jlong *tag_ptr)
Definition: jvmti.c:3066
static jvmtiError IterateOverHeap(jvmtiEnv *env, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, void *user_data)
Definition: jvmti.c:3170
static jvmtiError GetClassLoaderClasses(jvmtiEnv *env, jobject initiating_loader, jint *class_count_ptr, jclass **classes_ptr)
Definition: jvmti.c:2635
static jvmtiError ResumeThreadList(jvmtiEnv *env, jint request_count, const jthread *request_list, jvmtiError *results)
Definition: jvmti.c:2819
static jvmtiError IterateOverObjectsReachableFromObject(jvmtiEnv *env, jobject object, jvmtiObjectReferenceCallback object_reference_callback, void *user_data)
Definition: jvmti.c:3124
vftbl_t * vftbl
Definition: class.hpp:121
classinfo * class_java_lang_String
Definition: globals.cpp:39
jlong jlocation
Definition: jvmti.h:44
#define JVMTI_THREAD_STATE_RUNNABLE
Definition: jvmti.h:1151
static jvmtiError GetBytecodes(jvmtiEnv *env, jmethodID method, jint *bytecode_count_ptr, unsigned char **bytecodes_ptr)
Definition: jvmti.c:2531
static jvmtiError RawMonitorExit(jvmtiEnv *env, jrawMonitorID monitor)
Definition: jvmti.c:1526
jvmtiEvent
Definition: jvmti.h:635
static jvmtiError GetThreadListStackTraces(jvmtiEnv *env, jint thread_count, const jthread *thread_list, jint max_frame_count, jvmtiStackInfo **stack_info_ptr)
Definition: jvmti.c:2899
jint * new_class_data_len
Definition: cacaodbg.h:57
jboolean is_daemon
Definition: jvmti.h:179
jvmtiHeapObjectFilter
Definition: jvmti.h:445
jint priority
Definition: jvmti.h:178
#define MNEW(type, num)
Definition: memory.hpp:96
static jvmtiError SetExtensionEventCallback(jvmtiEnv *env, jint extension_event_index, jvmtiExtensionEvent callback)
Definition: jvmti.c:3379
jvmtiPhase
Definition: jvmti.h:156
static jvmtiError GetFrameCount(jvmtiEnv *env, jthread thread, jint *count_ptr)
Definition: jvmti.c:1088
#define JVMTI_THREAD_MIN_PRIORITY
Definition: jvmti.h:1166
jvmtiEventMode mode
Definition: jvmti.c:86
static void dofireEvent(jvmtiEvent e, genericEventData *data)
Definition: jvmti.c:364
static jvmtiError IsMethodObsolete(jvmtiEnv *env, jmethodID method, jboolean *is_obsolete_ptr)
Definition: jvmti.c:2758
bool lock_is_held_by_current_thread(java_handle_t *o)
Definition: lock.cpp:1280
stackframeinfo_t * prev
Definition: stacktrace.hpp:49
#define CHECK_PHASE_START
Definition: jvmti.c:114
#define JVMTI_THREAD_STATE_TERMINATED
Definition: jvmti.h:1150
jobject context_class_loader
Definition: jvmti.h:181
static jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv *env, jvmtiTimerInfo *info_ptr)
Definition: jvmti.c:3769
static jvmtiError GetTopThreadGroups(jvmtiEnv *env, jint *group_count_ptr, jthreadGroup **groups_ptr)
Definition: jvmti.c:909
#define JNI_FALSE
Definition: jni.hpp:109
unsigned char ** new_class_data
Definition: cacaodbg.h:58
jvmtiJlocationFormat
Definition: jvmti.h:165
static jvmtiError GetLocalInt(jvmtiEnv *env, jthread thread, jint depth, jint slot, jint *value_ptr)
Definition: jvmti.c:1264
jthread jint * owned_monitor_count_ptr
Definition: jvmti.h:742
jvmtiEvent ev
Definition: cacaodbg.h:37
static jvmtiError GetVersionNumber(jvmtiEnv *env, jint *version_ptr)
Definition: jvmti.c:2702
#define JVMTI_THREAD_STATE_PARKED
Definition: jvmti.h:1158
#define CHECK_ADD_CAPABILITY(env, CAN)
Definition: jvmti.c:3903
static jvmtiError GetClassStatus(jvmtiEnv *env, jclass klass, jint *status_ptr)
Definition: jvmti.c:1820
static jvmtiError RawMonitorEnter(jvmtiEnv *env, jrawMonitorID monitor)
Definition: jvmti.c:1504
static jvmtiError GetClassLoader(jvmtiEnv *env, jclass klass, jobject *classloader_ptr)
Definition: jvmti.c:2075
static jvmtiError GetClassMethods(jvmtiEnv *env, jclass klass, jint *method_count_ptr, jmethodID **methods_ptr)
Definition: jvmti.c:1921
#define JVMTI_THREAD_MAX_PRIORITY
Definition: jvmti.h:1168
static jvmtiError SetFieldModificationWatch(jvmtiEnv *env, jclass klass, jfieldID field)
Definition: jvmti.c:1710
jlocation location
Definition: jvmti.h:435
GNU Classpath java/lang/Thread.
jvmtiEventMode jvmtiEvent event_type
Definition: jvmti.h:721
bool loadverbose
Definition: options.cpp:70
#define CHECK_DEL_CAPABILITY(env, CAN)
Definition: jvmti.c:3972
stackframeinfo_t * _stackframeinfo
Definition: thread.hpp:129
static jvmtiError GetLineNumberTable(jvmtiEnv *env, jmethodID method, jint *entry_count_ptr, jvmtiLineNumberEntry **table_ptr)
Definition: jvmti.c:2416
classinfo * class_java_lang_Thread
Definition: globals.cpp:41
bool lock_monitor_enter(java_handle_t *o)
Definition: lock.cpp:786
static jvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv *env, const char *segment)
Definition: jvmti.c:4099
jint * threads_count_ptr
Definition: jvmti.h:727
static jvmtiError ClearBreakpoint(jvmtiEnv *env, jmethodID method, jlocation location)
Definition: jvmti.c:1653
static jvmtiError GetTimerInfo(jvmtiEnv *env, jvmtiTimerInfo *info_ptr)
Definition: jvmti.c:3844
jboolean is_daemon
Definition: jvmti.h:412
#define MREALLOC(ptr, type, num1, num2)
Definition: memory.hpp:99
static jvmtiError ResumeThread(jvmtiEnv *env, jthread thread)
Definition: jvmti.c:600
static jvmtiError GetArgumentsSize(jvmtiEnv *env, jmethodID method, jint *size_ptr)
Definition: jvmti.c:2390
static jvmtiError ClearFieldModificationWatch(jvmtiEnv *env, jclass klass, jfieldID field)
Definition: jvmti.c:1729
jthread thread
Definition: jvmti.h:439
GNU Classpath java/lang/Class.
void jvmti_agentload(char *opt_arg, bool agentbypath, lt_dlhandle *handle, char **libname)
Definition: jvmti.c:4465
JNIEnv jthread jmethodID jlocation location
Definition: jvmti.h:207
jvalue value
Definition: cacaodbg.h:46
#define JVMTI_THREAD_STATE_IN_OBJECT_WAIT
Definition: jvmti.h:1157
void * compile_info
Definition: cacaodbg.h:60
#define log_text(s)
Definition: logging.hpp:170
static jvmtiError GetJNIFunctionTable(jvmtiEnv *env, jniNativeInterface **function_table)
Definition: jvmti.c:3257
#define MFREE(ptr, type, num)
Definition: memory.hpp:97
static environment * envs
Definition: jvmti.c:78
#define THREADOBJECT
Definition: thread-none.hpp:47
LoopTreeGraph * parent
jobject protection_domain
Definition: cacaodbg.h:53
static jvmtiError SetVerboseFlag(jvmtiEnv *env, jvmtiVerboseFlag flag, jboolean value)
Definition: jvmti.c:4128
environment * next
Definition: jvmti.c:100
#define CHECK_CAPABILITY(env, CAP)
Definition: jvmti.c:117
static jvmtiError GetFrameLocation(jvmtiEnv *env, jthread thread, jint depth, jmethodID *method_ptr, jlocation *location_ptr)
Definition: jvmti.c:1177
static jvmtiError GetMaxLocals(jvmtiEnv *env, jmethodID method, jint *max_ptr)
Definition: jvmti.c:2363
jthread jint jobject ** owned_monitors_ptr
Definition: jvmti.h:742
static jvmtiError getcacaostacktrace(stacktracebuffer **trace, jthread thread)
Definition: jvmti.c:1057
jmethodID method
Definition: cacaodbg.h:40
#define JVMTI_CLASS_STATUS_INITIALIZED
Definition: jvmti.h:1172
static jvmtiError GetAllStackTraces(jvmtiEnv *env, jint max_frame_count, jvmtiStackInfo **stack_info_ptr, jint *thread_count_ptr)
Definition: jvmti.c:2944
static jvmtiError GetThreadGroupChildren(jvmtiEnv *env, jthreadGroup group, jint *thread_count_ptr, jthread **threads_ptr, jint *group_count_ptr, jthreadGroup **groups_ptr)
Definition: jvmti.c:1012
static jvmtiError GetThreadGroupInfo(jvmtiEnv *env, jthreadGroup group, jvmtiThreadGroupInfo *info_ptr)
Definition: jvmti.c:972
static jvmtiError SetTag(jvmtiEnv *env, jobject object, jlong tag)
Definition: jvmti.c:3085
jmethodID method
Definition: jvmti.h:434
jthread thread
Definition: cacaodbg.h:39