hotspot/src/share/vm/services/management.cpp
author dcubed
Tue, 23 Mar 2010 14:37:18 -0700
changeset 5091 4b7db223b9bd
parent 4571 80b553bddc26
child 5547 f4b087cbb361
permissions -rw-r--r--
6915365: 3/4 assert(false,"Unsupported VMGlobal Type") at management.cpp:1540 Summary: Remove assert to decouple JDK and HotSpot additions of known types. Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
2105
347008ce7984 6814575: Update copyright year
xdono
parents: 1676
diff changeset
     2
 * Copyright 2003-2009 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_management.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
PerfVariable* Management::_begin_vm_creation_time = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
PerfVariable* Management::_end_vm_creation_time = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
PerfVariable* Management::_vm_init_done_time = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
klassOop Management::_sensor_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
klassOop Management::_threadInfo_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
klassOop Management::_memoryUsage_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
klassOop Management::_memoryPoolMXBean_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
klassOop Management::_memoryManagerMXBean_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
klassOop Management::_garbageCollectorMXBean_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
klassOop Management::_managementFactory_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
jmmOptionalSupport Management::_optional_support = {0};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
TimeStamp Management::_stamp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
void management_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  Management::init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  ThreadService::init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  RuntimeService::init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  ClassLoadingService::init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
void Management::init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // These counters are for java.lang.management API support.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // They are created even if -XX:-UsePerfData is set and in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // that case, they will be allocated on C heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  _begin_vm_creation_time =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
            PerfDataManager::create_variable(SUN_RT, "createVmBeginTime",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                                             PerfData::U_None, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  _end_vm_creation_time =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
            PerfDataManager::create_variable(SUN_RT, "createVmEndTime",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
                                             PerfData::U_None, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  _vm_init_done_time =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
            PerfDataManager::create_variable(SUN_RT, "vmInitDoneTime",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                                             PerfData::U_None, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // Initialize optional support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _optional_support.isLowMemoryDetectionSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _optional_support.isCompilationTimeMonitoringSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _optional_support.isThreadContentionMonitoringSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  if (os::is_thread_cpu_time_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    _optional_support.isCurrentThreadCpuTimeSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    _optional_support.isOtherThreadCpuTimeSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    _optional_support.isCurrentThreadCpuTimeSupported = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    _optional_support.isOtherThreadCpuTimeSupported = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _optional_support.isBootClassPathSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _optional_support.isObjectMonitorUsageSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
#ifndef SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // This depends on the heap inspector
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  _optional_support.isSynchronizerUsageSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
#endif // SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void Management::initialize(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Start the low memory detector thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  LowMemoryDetector::initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  if (ManagementServer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    HandleMark hm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    // Load and initialize the sun.management.Agent class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    // invoke startAgent method to start the management server
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    klassOop k = SystemDictionary::resolve_or_fail(vmSymbolHandles::sun_management_Agent(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                                                   loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                                                   Handle(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
                                                   true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
                                                   CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    instanceKlassHandle ik (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    JavaCalls::call_static(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                           ik,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
                           vmSymbolHandles::startAgent_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
                           vmSymbolHandles::void_method_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
                           CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
void Management::get_optional_support(jmmOptionalSupport* support) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  memcpy(support, &_optional_support, sizeof(jmmOptionalSupport));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
klassOop Management::load_and_initialize_klass(symbolHandle sh, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  klassOop k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  instanceKlassHandle ik (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  if (ik->should_be_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    ik->initialize(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  return ik();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
void Management::record_vm_startup_time(jlong begin, jlong duration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // if the performance counter is not initialized,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // then vm initialization failed; simply return.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  if (_begin_vm_creation_time == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  _begin_vm_creation_time->set_value(begin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  _end_vm_creation_time->set_value(begin + duration);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  PerfMemory::set_accessible(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
jlong Management::timestamp() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  TimeStamp t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  t.update();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  return t.ticks() - _stamp.ticks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
void Management::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  MemoryService::oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  ThreadService::oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  f->do_oop((oop*) &_sensor_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  f->do_oop((oop*) &_threadInfo_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  f->do_oop((oop*) &_memoryUsage_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  f->do_oop((oop*) &_memoryPoolMXBean_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  f->do_oop((oop*) &_memoryManagerMXBean_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  f->do_oop((oop*) &_garbageCollectorMXBean_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  f->do_oop((oop*) &_managementFactory_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
klassOop Management::java_lang_management_ThreadInfo_klass(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if (_threadInfo_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    _threadInfo_klass = load_and_initialize_klass(vmSymbolHandles::java_lang_management_ThreadInfo(), CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  return _threadInfo_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
klassOop Management::java_lang_management_MemoryUsage_klass(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  if (_memoryUsage_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    _memoryUsage_klass = load_and_initialize_klass(vmSymbolHandles::java_lang_management_MemoryUsage(), CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  return _memoryUsage_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
klassOop Management::java_lang_management_MemoryPoolMXBean_klass(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  if (_memoryPoolMXBean_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    _memoryPoolMXBean_klass = load_and_initialize_klass(vmSymbolHandles::java_lang_management_MemoryPoolMXBean(), CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  return _memoryPoolMXBean_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
klassOop Management::java_lang_management_MemoryManagerMXBean_klass(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  if (_memoryManagerMXBean_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    _memoryManagerMXBean_klass = load_and_initialize_klass(vmSymbolHandles::java_lang_management_MemoryManagerMXBean(), CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  return _memoryManagerMXBean_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
klassOop Management::java_lang_management_GarbageCollectorMXBean_klass(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  if (_garbageCollectorMXBean_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      _garbageCollectorMXBean_klass = load_and_initialize_klass(vmSymbolHandles::java_lang_management_GarbageCollectorMXBean(), CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  return _garbageCollectorMXBean_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
klassOop Management::sun_management_Sensor_klass(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  if (_sensor_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    _sensor_klass = load_and_initialize_klass(vmSymbolHandles::sun_management_Sensor(), CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  return _sensor_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
klassOop Management::sun_management_ManagementFactory_klass(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  if (_managementFactory_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    _managementFactory_klass = load_and_initialize_klass(vmSymbolHandles::sun_management_ManagementFactory(), CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  return _managementFactory_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
static void initialize_ThreadInfo_constructor_arguments(JavaCallArguments* args, ThreadSnapshot* snapshot, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  Handle snapshot_thread(THREAD, snapshot->threadObj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  jlong contended_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  jlong waited_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  if (ThreadService::is_thread_monitoring_contention()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    contended_time = Management::ticks_to_ms(snapshot->contended_enter_ticks());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    waited_time = Management::ticks_to_ms(snapshot->monitor_wait_ticks() + snapshot->sleep_ticks());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    // set them to -1 if thread contention monitoring is disabled.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    contended_time = max_julong;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    waited_time = max_julong;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  int thread_status = snapshot->thread_status();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  assert((thread_status & JMM_THREAD_STATE_FLAG_MASK) == 0, "Flags already set in thread_status in Thread object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  if (snapshot->is_ext_suspended()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    thread_status |= JMM_THREAD_STATE_FLAG_SUSPENDED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  if (snapshot->is_in_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    thread_status |= JMM_THREAD_STATE_FLAG_NATIVE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  ThreadStackTrace* st = snapshot->get_stack_trace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  Handle stacktrace_h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  if (st != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    stacktrace_h = st->allocate_fill_stack_trace_element_array(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    stacktrace_h = Handle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  args->push_oop(snapshot_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  args->push_int(thread_status);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  args->push_oop(Handle(THREAD, snapshot->blocker_object()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  args->push_oop(Handle(THREAD, snapshot->blocker_object_owner()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  args->push_long(snapshot->contended_enter_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  args->push_long(contended_time);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  args->push_long(snapshot->monitor_wait_count() + snapshot->sleep_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  args->push_long(waited_time);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  args->push_oop(stacktrace_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
// Helper function to construct a ThreadInfo object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
instanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  klassOop k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  instanceKlassHandle ik (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  JavaCallArguments args(14);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  // First allocate a ThreadObj object and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  // push the receiver as the first argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  Handle element = ik->allocate_instance_handle(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  args.push_oop(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  // initialize the arguments for the ThreadInfo constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // Call ThreadInfo constructor with no locked monitors and synchronizers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
                          ik,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
                          vmSymbolHandles::object_initializer_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
                          vmSymbolHandles::java_lang_management_ThreadInfo_constructor_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
                          &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
                          CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  return (instanceOop) element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
instanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
                                                    objArrayHandle monitors_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
                                                    typeArrayHandle depths_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
                                                    objArrayHandle synchronizers_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
                                                    TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  klassOop k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  instanceKlassHandle ik (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  JavaCallArguments args(17);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // First allocate a ThreadObj object and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // push the receiver as the first argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  Handle element = ik->allocate_instance_handle(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  args.push_oop(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  // initialize the arguments for the ThreadInfo constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // push the locked monitors and synchronizers in the arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  args.push_oop(monitors_array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  args.push_oop(depths_array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  args.push_oop(synchronizers_array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // Call ThreadInfo constructor with locked monitors and synchronizers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
                          ik,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
                          vmSymbolHandles::object_initializer_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
                          vmSymbolHandles::java_lang_management_ThreadInfo_with_locks_constructor_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
                          &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
                          CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  return (instanceOop) element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
// Helper functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
static JavaThread* find_java_thread_from_id(jlong thread_id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  assert(Threads_lock->owned_by_self(), "Must hold Threads_lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  JavaThread* java_thread = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // Sequential search for now.  Need to do better optimization later.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    oop tobj = thread->threadObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    if (!thread->is_exiting() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
        tobj != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
        thread_id == java_lang_Thread::thread_id(tobj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      java_thread = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  return java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
static GCMemoryManager* get_gc_memory_manager_from_jobject(jobject mgr, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  if (mgr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  oop mgr_obj = JNIHandles::resolve(mgr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  instanceHandle h(THREAD, (instanceOop) mgr_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  klassOop k = Management::java_lang_management_GarbageCollectorMXBean_klass(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  if (!h->is_a(k)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
               "the object is not an instance of java.lang.management.GarbageCollectorMXBean class",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
               NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  MemoryManager* gc = MemoryService::get_memory_manager(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  if (gc == NULL || !gc->is_gc_memory_manager()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
               "Invalid GC memory manager",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
               NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  return (GCMemoryManager*) gc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
static MemoryPool* get_memory_pool_from_jobject(jobject obj, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  oop pool_obj = JNIHandles::resolve(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  assert(pool_obj->is_instance(), "Should be an instanceOop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  instanceHandle ph(THREAD, (instanceOop) pool_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  return MemoryService::get_memory_pool(ph);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
static void validate_thread_id_array(typeArrayHandle ids_ah, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  int num_threads = ids_ah->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  // should be non-empty array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  if (num_threads == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
              "Empty array of thread IDs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  // Validate input thread IDs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  for (i = 0; i < num_threads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    jlong tid = ids_ah->long_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    if (tid <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      // throw exception if invalid thread id.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
                "Invalid thread ID entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
static void validate_thread_info_array(objArrayHandle infoArray_h, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  // check if the element of infoArray is of type ThreadInfo class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  klassOop threadinfo_klass = Management::java_lang_management_ThreadInfo_klass(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  klassOop element_klass = objArrayKlass::cast(infoArray_h->klass())->element_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  if (element_klass != threadinfo_klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
              "infoArray element type is not ThreadInfo class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
static MemoryManager* get_memory_manager_from_jobject(jobject obj, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  oop mgr_obj = JNIHandles::resolve(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  assert(mgr_obj->is_instance(), "Should be an instanceOop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  instanceHandle mh(THREAD, (instanceOop) mgr_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  return MemoryService::get_memory_manager(mh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
// Returns a version string and sets major and minor version if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
// the input parameters are non-null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
JVM_LEAF(jint, jmm_GetVersion(JNIEnv *env))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  return JMM_VERSION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
// Gets the list of VM monitoring and management optional supports
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
// Returns 0 if succeeded; otherwise returns non-zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
JVM_LEAF(jint, jmm_GetOptionalSupport(JNIEnv *env, jmmOptionalSupport* support))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  if (support == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  Management::get_optional_support(support);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
// Returns a java.lang.String object containing the input arguments to the VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
JVM_ENTRY(jobject, jmm_GetInputArguments(JNIEnv *env))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  char** vm_flags = Arguments::jvm_flags_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  char** vm_args  = Arguments::jvm_args_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  int num_flags   = Arguments::num_jvm_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  int num_args    = Arguments::num_jvm_args();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  size_t length = 1; // null terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  for (i = 0; i < num_flags; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    length += strlen(vm_flags[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  for (i = 0; i < num_args; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    length += strlen(vm_args[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  // add a space between each argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  length += num_flags + num_args - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  // Return the list of input arguments passed to the VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  // and preserve the order that the VM processes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  char* args = NEW_RESOURCE_ARRAY(char, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  args[0] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  // concatenate all jvm_flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  if (num_flags > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    strcat(args, vm_flags[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    for (i = 1; i < num_flags; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      strcat(args, " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
      strcat(args, vm_flags[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  if (num_args > 0 && num_flags > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    // append a space if args already contains one or more jvm_flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    strcat(args, " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  // concatenate all jvm_args
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  if (num_args > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    strcat(args, vm_args[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    for (i = 1; i < num_args; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
      strcat(args, " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
      strcat(args, vm_args[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  Handle hargs = java_lang_String::create_from_platform_dependent_str(args, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  return JNIHandles::make_local(env, hargs());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
// Returns an array of java.lang.String object containing the input arguments to the VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
JVM_ENTRY(jobjectArray, jmm_GetInputArgumentArray(JNIEnv *env))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  char** vm_flags = Arguments::jvm_flags_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  char** vm_args = Arguments::jvm_args_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  int num_flags = Arguments::num_jvm_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  int num_args = Arguments::num_jvm_args();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
   494
  instanceKlassHandle ik (THREAD, SystemDictionary::String_klass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  objArrayOop r = oopFactory::new_objArray(ik(), num_args + num_flags, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  objArrayHandle result_h(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  for (int j = 0; j < num_flags; j++, index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    result_h->obj_at_put(index, h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  for (int i = 0; i < num_args; i++, index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    result_h->obj_at_put(index, h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  return (jobjectArray) JNIHandles::make_local(env, result_h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
// Returns an array of java/lang/management/MemoryPoolMXBean object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
// one for each memory pool if obj == null; otherwise returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
// an array of memory pools for a given memory manager if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
// it is a valid memory manager.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
JVM_ENTRY(jobjectArray, jmm_GetMemoryPools(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  int num_memory_pools;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  MemoryManager* mgr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    num_memory_pools = MemoryService::num_memory_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    mgr = get_memory_manager_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    if (mgr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    num_memory_pools = mgr->num_memory_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  // Allocate the resulting MemoryPoolMXBean[] object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  klassOop k = Management::java_lang_management_MemoryPoolMXBean_klass(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  instanceKlassHandle ik (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  objArrayOop r = oopFactory::new_objArray(ik(), num_memory_pools, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  objArrayHandle poolArray(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  if (mgr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    // Get all memory pools
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    for (int i = 0; i < num_memory_pools; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
      MemoryPool* pool = MemoryService::get_memory_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
      instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
      instanceHandle ph(THREAD, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      poolArray->obj_at_put(i, ph());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    // Get memory pools managed by a given memory manager
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    for (int i = 0; i < num_memory_pools; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
      MemoryPool* pool = mgr->get_memory_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
      instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
      instanceHandle ph(THREAD, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
      poolArray->obj_at_put(i, ph());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  return (jobjectArray) JNIHandles::make_local(env, poolArray());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
// Returns an array of java/lang/management/MemoryManagerMXBean object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
// one for each memory manager if obj == null; otherwise returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
// an array of memory managers for a given memory pool if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
// it is a valid memory pool.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
JVM_ENTRY(jobjectArray, jmm_GetMemoryManagers(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  int num_mgrs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  MemoryPool* pool = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    num_mgrs = MemoryService::num_memory_managers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    if (pool == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    num_mgrs = pool->num_memory_managers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  // Allocate the resulting MemoryManagerMXBean[] object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  klassOop k = Management::java_lang_management_MemoryManagerMXBean_klass(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  instanceKlassHandle ik (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  objArrayOop r = oopFactory::new_objArray(ik(), num_mgrs, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  objArrayHandle mgrArray(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  if (pool == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    // Get all memory managers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    for (int i = 0; i < num_mgrs; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
      MemoryManager* mgr = MemoryService::get_memory_manager(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
      instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      instanceHandle ph(THREAD, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
      mgrArray->obj_at_put(i, ph());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    // Get memory managers for a given memory pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    for (int i = 0; i < num_mgrs; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
      MemoryManager* mgr = pool->get_memory_manager(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
      instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
      instanceHandle ph(THREAD, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
      mgrArray->obj_at_put(i, ph());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  return (jobjectArray) JNIHandles::make_local(env, mgrArray());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
// Returns a java/lang/management/MemoryUsage object containing the memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
// of a given memory pool.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
JVM_ENTRY(jobject, jmm_GetMemoryPoolUsage(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  if (pool != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    MemoryUsage usage = pool->get_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    return JNIHandles::make_local(env, h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
// Returns a java/lang/management/MemoryUsage object containing the memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
// of a given memory pool.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
JVM_ENTRY(jobject, jmm_GetPeakMemoryPoolUsage(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  if (pool != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    MemoryUsage usage = pool->get_peak_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    return JNIHandles::make_local(env, h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
// Returns a java/lang/management/MemoryUsage object containing the memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
// of a given memory pool after most recent GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
JVM_ENTRY(jobject, jmm_GetPoolCollectionUsage(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  if (pool != NULL && pool->is_collected_pool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    MemoryUsage usage = pool->get_last_collection_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
    return JNIHandles::make_local(env, h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
// Sets the memory pool sensor for a threshold type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
JVM_ENTRY(void, jmm_SetPoolSensor(JNIEnv* env, jobject obj, jmmThresholdType type, jobject sensorObj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  if (obj == NULL || sensorObj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    THROW(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  klassOop sensor_klass = Management::sun_management_Sensor_klass(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  oop s = JNIHandles::resolve(sensorObj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  assert(s->is_instance(), "Sensor should be an instanceOop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  instanceHandle sensor_h(THREAD, (instanceOop) s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  if (!sensor_h->is_a(sensor_klass)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
              "Sensor is not an instance of sun.management.Sensor class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  MemoryPool* mpool = get_memory_pool_from_jobject(obj, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  assert(mpool != NULL, "MemoryPool should exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    case JMM_USAGE_THRESHOLD_HIGH:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    case JMM_USAGE_THRESHOLD_LOW:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
      // have only one sensor for threshold high and low
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      mpool->set_usage_sensor_obj(sensor_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    case JMM_COLLECTION_USAGE_THRESHOLD_HIGH:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    case JMM_COLLECTION_USAGE_THRESHOLD_LOW:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
      // have only one sensor for threshold high and low
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
      mpool->set_gc_usage_sensor_obj(sensor_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
      assert(false, "Unrecognized type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
// Sets the threshold of a given memory pool.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
// Returns the previous threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
//   pool      - the MemoryPoolMXBean object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
//   type      - threshold type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
//   threshold - the new threshold (must not be negative)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
JVM_ENTRY(jlong, jmm_SetPoolThreshold(JNIEnv* env, jobject obj, jmmThresholdType type, jlong threshold))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  if (threshold < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
               "Invalid threshold value",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
               -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
1676
d80e69372634 6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents: 1382
diff changeset
   697
  if ((size_t)threshold > max_uintx) {
d80e69372634 6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents: 1382
diff changeset
   698
    stringStream st;
d80e69372634 6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents: 1382
diff changeset
   699
    st.print("Invalid valid threshold value. Threshold value (" UINT64_FORMAT ") > max value of size_t (" SIZE_FORMAT ")", (size_t)threshold, max_uintx);
d80e69372634 6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents: 1382
diff changeset
   700
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), st.as_string(), -1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_(0L));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
  assert(pool != NULL, "MemoryPool should exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  jlong prev = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
    case JMM_USAGE_THRESHOLD_HIGH:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
      if (!pool->usage_threshold()->is_high_threshold_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
        return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
      prev = pool->usage_threshold()->set_high_threshold((size_t) threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
    case JMM_USAGE_THRESHOLD_LOW:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
      if (!pool->usage_threshold()->is_low_threshold_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
        return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
      prev = pool->usage_threshold()->set_low_threshold((size_t) threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    case JMM_COLLECTION_USAGE_THRESHOLD_HIGH:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
      if (!pool->gc_usage_threshold()->is_high_threshold_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
        return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
      // return and the new threshold is effective for the next GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
      return pool->gc_usage_threshold()->set_high_threshold((size_t) threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    case JMM_COLLECTION_USAGE_THRESHOLD_LOW:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
      if (!pool->gc_usage_threshold()->is_low_threshold_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
        return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
      // return and the new threshold is effective for the next GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
      return pool->gc_usage_threshold()->set_low_threshold((size_t) threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
      assert(false, "Unrecognized type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
      return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  // When the threshold is changed, reevaluate if the low memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  // detection is enabled.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  if (prev != threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    LowMemoryDetector::recompute_enabled_for_collected_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    LowMemoryDetector::detect_low_memory(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  return prev;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
// Returns a java/lang/management/MemoryUsage object representing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
// the memory usage for the heap or non-heap memory.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
JVM_ENTRY(jobject, jmm_GetMemoryUsage(JNIEnv* env, jboolean heap))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  // Calculate the memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  size_t total_init = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  size_t total_used = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  size_t total_committed = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  size_t total_max = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  bool   has_undefined_init_size = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  bool   has_undefined_max_size = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    MemoryPool* pool = MemoryService::get_memory_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
    if ((heap && pool->is_heap()) || (!heap && pool->is_non_heap())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
      MemoryUsage u = pool->get_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
      total_used += u.used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
      total_committed += u.committed();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
      // if any one of the memory pool has undefined init_size or max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
      // set it to -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
      if (u.init_size() == (size_t)-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
        has_undefined_init_size = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
      if (!has_undefined_init_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
        total_init += u.init_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
      if (u.max_size() == (size_t)-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
        has_undefined_max_size = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
      if (!has_undefined_max_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
        total_max += u.max_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  // In our current implementation, all pools should have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  // defined init and max size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  assert(!has_undefined_init_size, "Undefined init size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  assert(!has_undefined_max_size, "Undefined max size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
4434
4b41e5b42f81 6887571: Increase default heap config sizes
phh
parents: 2105
diff changeset
   793
  MemoryUsage usage((heap ? InitialHeapSize : total_init),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
                    total_used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
                    total_committed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
                    (heap ? Universe::heap()->max_capacity() : total_max));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  Handle obj = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  return JNIHandles::make_local(env, obj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
// Returns the boolean value of a given attribute.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
JVM_LEAF(jboolean, jmm_GetBoolAttribute(JNIEnv *env, jmmBoolAttribute att))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  switch (att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  case JMM_VERBOSE_GC:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    return MemoryService::get_verbose();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  case JMM_VERBOSE_CLASS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    return ClassLoadingService::get_verbose();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  case JMM_THREAD_CONTENTION_MONITORING:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    return ThreadService::is_thread_monitoring_contention();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  case JMM_THREAD_CPU_TIME:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    return ThreadService::is_thread_cpu_time_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    assert(0, "Unrecognized attribute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
// Sets the given boolean attribute and returns the previous value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
JVM_ENTRY(jboolean, jmm_SetBoolAttribute(JNIEnv *env, jmmBoolAttribute att, jboolean flag))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  switch (att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  case JMM_VERBOSE_GC:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
    return MemoryService::set_verbose(flag != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  case JMM_VERBOSE_CLASS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    return ClassLoadingService::set_verbose(flag != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
  case JMM_THREAD_CONTENTION_MONITORING:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    return ThreadService::set_thread_monitoring_contention(flag != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  case JMM_THREAD_CPU_TIME:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    return ThreadService::set_thread_cpu_time_enabled(flag != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    assert(0, "Unrecognized attribute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
static jlong get_gc_attribute(GCMemoryManager* mgr, jmmLongAttribute att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
  switch (att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
  case JMM_GC_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    return mgr->gc_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  case JMM_GC_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    return mgr->gc_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  case JMM_GC_EXT_ATTRIBUTE_INFO_SIZE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
    // current implementation only has 1 ext attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
    assert(0, "Unrecognized GC attribute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
class VmThreadCountClosure: public ThreadClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  int _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  VmThreadCountClosure() : _count(0) {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  void do_thread(Thread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  int count() { return _count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
void VmThreadCountClosure::do_thread(Thread* thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  // exclude externally visible JavaThreads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  _count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
static jint get_vm_thread_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  VmThreadCountClosure vmtcc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    MutexLockerEx ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
    Threads::threads_do(&vmtcc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  return vmtcc.count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
static jint get_num_flags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  // last flag entry is always NULL, so subtract 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  int nFlags = (int) Flag::numFlags - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  for (int i = 0; i < nFlags; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
    Flag* flag = &Flag::flags[i];
1382
fa3de4068282 6618726: Introduce -XX:+UnlockExperimentalVMOptions flag
ysr
parents: 1
diff changeset
   889
    // Exclude the locked (diagnostic, experimental) flags
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
    if (flag->is_unlocked() || flag->is_unlocker()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
      count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  return count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
static jlong get_long_attribute(jmmLongAttribute att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
  switch (att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  case JMM_CLASS_LOADED_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    return ClassLoadingService::loaded_class_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  case JMM_CLASS_UNLOADED_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
    return ClassLoadingService::unloaded_class_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  case JMM_THREAD_TOTAL_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    return ThreadService::get_total_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  case JMM_THREAD_LIVE_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    return ThreadService::get_live_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  case JMM_THREAD_PEAK_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
    return ThreadService::get_peak_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  case JMM_THREAD_DAEMON_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
    return ThreadService::get_daemon_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  case JMM_JVM_INIT_DONE_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
    return Management::vm_init_done_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  case JMM_COMPILE_TOTAL_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
    return Management::ticks_to_ms(CompileBroker::total_compilation_ticks());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  case JMM_OS_PROCESS_ID:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
    return os::current_process_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  // Hotspot-specific counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  case JMM_CLASS_LOADED_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
    return ClassLoadingService::loaded_class_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  case JMM_CLASS_UNLOADED_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
    return ClassLoadingService::unloaded_class_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
  case JMM_SHARED_CLASS_LOADED_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
    return ClassLoadingService::loaded_shared_class_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  case JMM_SHARED_CLASS_UNLOADED_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
    return ClassLoadingService::unloaded_shared_class_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
  case JMM_SHARED_CLASS_LOADED_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
    return ClassLoadingService::loaded_shared_class_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  case JMM_SHARED_CLASS_UNLOADED_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
    return ClassLoadingService::unloaded_shared_class_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  case JMM_TOTAL_CLASSLOAD_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
    return ClassLoader::classloader_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  case JMM_VM_GLOBAL_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
    return get_num_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  case JMM_SAFEPOINT_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
    return RuntimeService::safepoint_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
  case JMM_TOTAL_SAFEPOINTSYNC_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
    return RuntimeService::safepoint_sync_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  case JMM_TOTAL_STOPPED_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
    return RuntimeService::safepoint_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  case JMM_TOTAL_APP_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    return RuntimeService::application_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  case JMM_VM_THREAD_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    return get_vm_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  case JMM_CLASS_INIT_TOTAL_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
    return ClassLoader::class_init_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  case JMM_CLASS_INIT_TOTAL_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
    return ClassLoader::class_init_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  case JMM_CLASS_VERIFY_TOTAL_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    return ClassLoader::class_verify_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  case JMM_METHOD_DATA_SIZE_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
    return ClassLoadingService::class_method_data_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
  case JMM_OS_MEM_TOTAL_PHYSICAL_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
    return os::physical_memory();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
// Returns the long value of a given attribute.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
JVM_ENTRY(jlong, jmm_GetLongAttribute(JNIEnv *env, jobject obj, jmmLongAttribute att))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    return get_long_attribute(att);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
    GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_(0L));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    if (mgr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
      return get_gc_attribute(mgr, att);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
// Gets the value of all attributes specified in the given array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
// and sets the value in the result array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
// Returns the number of attributes found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
JVM_ENTRY(jint, jmm_GetLongAttributes(JNIEnv *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
                                      jobject obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
                                      jmmLongAttribute* atts,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
                                      jint count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
                                      jlong* result))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  int num_atts = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
    for (int i = 0; i < count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
      result[i] = get_long_attribute(atts[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
      if (result[i] != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
        num_atts++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
    GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
    for (int i = 0; i < count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
      result[i] = get_gc_attribute(mgr, atts[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
      if (result[i] != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
        num_atts++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  return num_atts;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
// Helper function to do thread dump for a specific list of threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
static void do_thread_dump(ThreadDumpResult* dump_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
                           typeArrayHandle ids_ah,  // array of thread ID (long[])
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
                           int num_threads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
                           int max_depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
                           bool with_locked_monitors,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
                           bool with_locked_synchronizers,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
                           TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  // First get an array of threadObj handles.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  // A JavaThread may terminate before we get the stack trace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
  GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    MutexLockerEx ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    for (int i = 0; i < num_threads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
      jlong tid = ids_ah->long_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
      JavaThread* jt = find_java_thread_from_id(tid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
      oop thread_obj = (jt != NULL ? jt->threadObj() : (oop)NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
      instanceHandle threadObj_h(THREAD, (instanceOop) thread_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
      thread_handle_array->append(threadObj_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  // Obtain thread dumps and thread snapshot information
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
  VM_ThreadDump op(dump_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
                   thread_handle_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
                   num_threads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
                   max_depth, /* stack depth */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
                   with_locked_monitors,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
                   with_locked_synchronizers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
// Gets an array of ThreadInfo objects. Each element is the ThreadInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
// for the thread ID specified in the corresponding entry in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
// the given array of thread IDs; or NULL if the thread does not exist
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
// or has terminated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
//   ids       - array of thread IDs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
//   maxDepth  - the maximum depth of stack traces to be dumped:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
//               maxDepth == -1 requests to dump entire stack trace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
//               maxDepth == 0  requests no stack trace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
//   infoArray - array of ThreadInfo objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
JVM_ENTRY(jint, jmm_GetThreadInfo(JNIEnv *env, jlongArray ids, jint maxDepth, jobjectArray infoArray))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  // Check if threads is null
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
  if (ids == NULL || infoArray == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
    THROW_(vmSymbols::java_lang_NullPointerException(), -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
  if (maxDepth < -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
               "Invalid maxDepth", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
  typeArrayHandle ids_ah(THREAD, ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
  oop infoArray_obj = JNIHandles::resolve_non_null(infoArray);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
  objArrayOop oa = objArrayOop(infoArray_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  objArrayHandle infoArray_h(THREAD, oa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  // validate the thread id array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  validate_thread_id_array(ids_ah, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
  // validate the ThreadInfo[] parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  validate_thread_info_array(infoArray_h, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
  // infoArray must be of the same length as the given array of thread IDs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
  int num_threads = ids_ah->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
  if (num_threads != infoArray_h->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
               "The length of the given ThreadInfo array does not match the length of the given array of thread IDs", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  if (JDK_Version::is_gte_jdk16x_version()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
    // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
    java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
  // Must use ThreadDumpResult to store the ThreadSnapshot.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
  // GC may occur after the thread snapshots are taken but before
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  // this function returns. The threadObj and other oops kept
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
  // in the ThreadSnapshot are marked and adjusted during GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
  ThreadDumpResult dump_result(num_threads);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
  if (maxDepth == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
    // no stack trace dumped - do not need to stop the world
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
      MutexLockerEx ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
      for (int i = 0; i < num_threads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
        jlong tid = ids_ah->long_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
        JavaThread* jt = find_java_thread_from_id(tid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
        ThreadSnapshot* ts;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
        if (jt == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
          // if the thread does not exist or now it is terminated,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
          // create dummy snapshot
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
          ts = new ThreadSnapshot();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
          ts = new ThreadSnapshot(jt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
        dump_result.add_thread_snapshot(ts);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
    // obtain thread dump with the specific list of threads with stack trace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
    do_thread_dump(&dump_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
                   ids_ah,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
                   num_threads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
                   maxDepth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
                   false, /* no locked monitor */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
                   false, /* no locked synchronizers */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
                   CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
  int num_snapshots = dump_result.num_snapshots();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
  assert(num_snapshots == num_threads, "Must match the number of thread snapshots");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
  for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; index++, ts = ts->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
    // For each thread, create an java/lang/management/ThreadInfo object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
    // and fill with the thread information
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
    if (ts->threadObj() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
     // if the thread does not exist or now it is terminated, set threadinfo to NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
      infoArray_h->obj_at_put(index, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
    // Create java.lang.management.ThreadInfo object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
    instanceOop info_obj = Management::create_thread_info_instance(ts, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
    infoArray_h->obj_at_put(index, info_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
// Dump thread info for the specified threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
// It returns an array of ThreadInfo objects. Each element is the ThreadInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
// for the thread ID specified in the corresponding entry in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
// the given array of thread IDs; or NULL if the thread does not exist
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
// or has terminated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
// Input parameter:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
//    ids - array of thread IDs; NULL indicates all live threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
//    locked_monitors - if true, dump locked object monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
//    locked_synchronizers - if true, dump locked JSR-166 synchronizers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
JVM_ENTRY(jobjectArray, jmm_DumpThreads(JNIEnv *env, jlongArray thread_ids, jboolean locked_monitors, jboolean locked_synchronizers))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
  if (JDK_Version::is_gte_jdk16x_version()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
    java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
  typeArrayOop ta = typeArrayOop(JNIHandles::resolve(thread_ids));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  int num_threads = (ta != NULL ? ta->length() : 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
  typeArrayHandle ids_ah(THREAD, ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  ThreadDumpResult dump_result(num_threads);  // can safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  if (ids_ah() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
    // validate the thread id array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
    validate_thread_id_array(ids_ah, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    // obtain thread dump of a specific list of threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    do_thread_dump(&dump_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
                   ids_ah,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
                   num_threads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
                   -1, /* entire stack */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
                   (locked_monitors ? true : false),      /* with locked monitors */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
                   (locked_synchronizers ? true : false), /* with locked synchronizers */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
                   CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
    // obtain thread dump of all threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
    VM_ThreadDump op(&dump_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
                     -1, /* entire stack */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
                     (locked_monitors ? true : false),     /* with locked monitors */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
                     (locked_synchronizers ? true : false) /* with locked synchronizers */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
    VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
  int num_snapshots = dump_result.num_snapshots();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
  // create the result ThreadInfo[] object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
  klassOop k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
  instanceKlassHandle ik (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
  objArrayOop r = oopFactory::new_objArray(ik(), num_snapshots, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
  objArrayHandle result_h(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
  for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; ts = ts->next(), index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    if (ts->threadObj() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
     // if the thread does not exist or now it is terminated, set threadinfo to NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
      result_h->obj_at_put(index, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    ThreadStackTrace* stacktrace = ts->get_stack_trace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
    assert(stacktrace != NULL, "Must have a stack trace dumped");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    // Create Object[] filled with locked monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    // Create int[] filled with the stack depth where a monitor was locked
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
    int num_frames = stacktrace->get_stack_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    int num_locked_monitors = stacktrace->num_jni_locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
    // Count the total number of locked monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    for (int i = 0; i < num_frames; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
      StackFrameInfo* frame = stacktrace->stack_frame_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
      num_locked_monitors += frame->num_locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
    objArrayHandle monitors_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
    typeArrayHandle depths_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
    objArrayHandle synchronizers_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
    if (locked_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
      // Constructs Object[] and int[] to contain the object monitor and the stack depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
      // where the thread locked it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
      objArrayOop array = oopFactory::new_system_objArray(num_locked_monitors, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
      objArrayHandle mh(THREAD, array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
      monitors_array = mh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
      typeArrayOop tarray = oopFactory::new_typeArray(T_INT, num_locked_monitors, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
      typeArrayHandle dh(THREAD, tarray);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
      depths_array = dh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
      int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
      int j = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
      for (int depth = 0; depth < num_frames; depth++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
        StackFrameInfo* frame = stacktrace->stack_frame_at(depth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
        int len = frame->num_locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
        GrowableArray<oop>* locked_monitors = frame->locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
        for (j = 0; j < len; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
          oop monitor = locked_monitors->at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
          assert(monitor != NULL && monitor->is_instance(), "must be a Java object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
          monitors_array->obj_at_put(count, monitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
          depths_array->int_at_put(count, depth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
          count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
      GrowableArray<oop>* jni_locked_monitors = stacktrace->jni_locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
      for (j = 0; j < jni_locked_monitors->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
        oop object = jni_locked_monitors->at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
        assert(object != NULL && object->is_instance(), "must be a Java object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
        monitors_array->obj_at_put(count, object);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
        // Monitor locked via JNI MonitorEnter call doesn't have stack depth info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
        depths_array->int_at_put(count, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
        count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
      assert(count == num_locked_monitors, "number of locked monitors doesn't match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
    if (locked_synchronizers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
      // Create Object[] filled with locked JSR-166 synchronizers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
      assert(ts->threadObj() != NULL, "Must be a valid JavaThread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
      ThreadConcurrentLocks* tcl = ts->get_concurrent_locks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
      GrowableArray<instanceOop>* locks = (tcl != NULL ? tcl->owned_locks() : NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
      int num_locked_synchronizers = (locks != NULL ? locks->length() : 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
      objArrayOop array = oopFactory::new_system_objArray(num_locked_synchronizers, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
      objArrayHandle sh(THREAD, array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
      synchronizers_array = sh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
      for (int k = 0; k < num_locked_synchronizers; k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
        synchronizers_array->obj_at_put(k, locks->at(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
    // Create java.lang.management.ThreadInfo object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
    instanceOop info_obj = Management::create_thread_info_instance(ts,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
                                                                   monitors_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
                                                                   depths_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
                                                                   synchronizers_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
                                                                   CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
    result_h->obj_at_put(index, info_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
  return (jobjectArray) JNIHandles::make_local(env, result_h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
// Returns an array of Class objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
JVM_ENTRY(jobjectArray, jmm_GetLoadedClasses(JNIEnv *env))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
  LoadedClassesEnumerator lce(THREAD);  // Pass current Thread as parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
  int num_classes = lce.num_loaded_classes();
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1324
  objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), num_classes, CHECK_0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
  objArrayHandle classes_ah(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
  for (int i = 0; i < num_classes; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
    KlassHandle kh = lce.get_klass(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
    oop mirror = Klass::cast(kh())->java_mirror();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    classes_ah->obj_at_put(i, mirror);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
  return (jobjectArray) JNIHandles::make_local(env, classes_ah());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
// Reset statistic.  Return true if the requested statistic is reset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
// Otherwise, return false.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
//  obj  - specify which instance the statistic associated with to be reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
//         For PEAK_POOL_USAGE stat, obj is required to be a memory pool object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
//         For THREAD_CONTENTION_COUNT and TIME stat, obj is required to be a thread ID.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
//  type - the type of statistic to be reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
JVM_ENTRY(jboolean, jmm_ResetStatistic(JNIEnv *env, jvalue obj, jmmStatisticType type))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
    case JMM_STAT_PEAK_THREAD_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
      ThreadService::reset_peak_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
    case JMM_STAT_THREAD_CONTENTION_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
    case JMM_STAT_THREAD_CONTENTION_TIME: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
      jlong tid = obj.j;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
      if (tid < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
        THROW_(vmSymbols::java_lang_IllegalArgumentException(), JNI_FALSE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
      // Look for the JavaThread of this given tid
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
      MutexLockerEx ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
      if (tid == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
        // reset contention statistics for all threads if tid == 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
        for (JavaThread* java_thread = Threads::first(); java_thread != NULL; java_thread = java_thread->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
          if (type == JMM_STAT_THREAD_CONTENTION_COUNT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
            ThreadService::reset_contention_count_stat(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
            ThreadService::reset_contention_time_stat(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
        // reset contention statistics for a given thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
        JavaThread* java_thread = find_java_thread_from_id(tid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
        if (java_thread == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
        if (type == JMM_STAT_THREAD_CONTENTION_COUNT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
          ThreadService::reset_contention_count_stat(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
          ThreadService::reset_contention_time_stat(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
    case JMM_STAT_PEAK_POOL_USAGE: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
      jobject o = obj.l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
      if (o == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
        THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
      oop pool_obj = JNIHandles::resolve(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
      assert(pool_obj->is_instance(), "Should be an instanceOop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
      instanceHandle ph(THREAD, (instanceOop) pool_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
      MemoryPool* pool = MemoryService::get_memory_pool(ph);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
      if (pool != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
        pool->reset_peak_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
    case JMM_STAT_GC_STAT: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
      jobject o = obj.l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
      if (o == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
        THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
      GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(o, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
      if (mgr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
        mgr->reset_gc_stat();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
      assert(0, "Unknown Statistic Type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
// Returns the fast estimate of CPU time consumed by
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
// a given thread (in nanoseconds).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
// If thread_id == 0, return CPU time for the current thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
JVM_ENTRY(jlong, jmm_GetThreadCpuTime(JNIEnv *env, jlong thread_id))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
  if (!os::is_thread_cpu_time_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
  if (thread_id < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
               "Invalid thread ID", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
  JavaThread* java_thread = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
  if (thread_id == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
    // current thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
    return os::current_thread_cpu_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
    MutexLockerEx ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
    java_thread = find_java_thread_from_id(thread_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
    if (java_thread != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
      return os::thread_cpu_time((Thread*) java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
// Returns the CPU time consumed by a given thread (in nanoseconds).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
// If thread_id == 0, CPU time for the current thread is returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
// If user_sys_cpu_time = true, user level and system CPU time of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
// a given thread is returned; otherwise, only user level CPU time
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
// is returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
JVM_ENTRY(jlong, jmm_GetThreadCpuTimeWithKind(JNIEnv *env, jlong thread_id, jboolean user_sys_cpu_time))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
  if (!os::is_thread_cpu_time_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
  if (thread_id < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
               "Invalid thread ID", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
  JavaThread* java_thread = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
  if (thread_id == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
    // current thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
    return os::current_thread_cpu_time(user_sys_cpu_time != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
    MutexLockerEx ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
    java_thread = find_java_thread_from_id(thread_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
    if (java_thread != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
      return os::thread_cpu_time((Thread*) java_thread, user_sys_cpu_time != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
// Returns a String array of all VM global flag names
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
JVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
  // last flag entry is always NULL, so subtract 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
  int nFlags = (int) Flag::numFlags - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
  // allocate a temp array
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1484
  objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
                                           nFlags, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
  objArrayHandle flags_ah(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
  int num_entries = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
  for (int i = 0; i < nFlags; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
    Flag* flag = &Flag::flags[i];
1382
fa3de4068282 6618726: Introduce -XX:+UnlockExperimentalVMOptions flag
ysr
parents: 1
diff changeset
  1490
    // Exclude the locked (experimental, diagnostic) flags
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
    if (flag->is_unlocked() || flag->is_unlocker()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
      Handle s = java_lang_String::create_from_str(flag->name, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
      flags_ah->obj_at_put(num_entries, s());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
      num_entries++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
  if (num_entries < nFlags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
    // Return array of right length
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1500
    objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
    for(int i = 0; i < num_entries; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
      res->obj_at_put(i, flags_ah->obj_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
    return (jobjectArray)JNIHandles::make_local(env, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
  return (jobjectArray)JNIHandles::make_local(env, flags_ah());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1510
// Utility function used by jmm_GetVMGlobals.  Returns false if flag type
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1511
// can't be determined, true otherwise.  If false is returned, then *global
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1512
// will be incomplete and invalid.
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1513
bool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, Flag *flag, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
  Handle flag_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
  if (name() == NULL) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1516
    flag_name = java_lang_String::create_from_str(flag->name, CHECK_false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
    flag_name = name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
  global->name = (jstring)JNIHandles::make_local(env, flag_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
  if (flag->is_bool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
    global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
    global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
  } else if (flag->is_intx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
    global->value.j = (jlong)flag->get_intx();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
    global->type = JMM_VMGLOBAL_TYPE_JLONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
  } else if (flag->is_uintx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
    global->value.j = (jlong)flag->get_uintx();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
    global->type = JMM_VMGLOBAL_TYPE_JLONG;
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1531
  } else if (flag->is_uint64_t()) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1532
    global->value.j = (jlong)flag->get_uint64_t();
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1533
    global->type = JMM_VMGLOBAL_TYPE_JLONG;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
  } else if (flag->is_ccstr()) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1535
    Handle str = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
    global->value.l = (jobject)JNIHandles::make_local(env, str());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
    global->type = JMM_VMGLOBAL_TYPE_JSTRING;
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1538
  } else {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1539
    global->type = JMM_VMGLOBAL_TYPE_UNKNOWN;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1540
    return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
  global->writeable = flag->is_writeable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
  global->external = flag->is_external();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
  switch (flag->origin) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
    case DEFAULT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
      global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
    case COMMAND_LINE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
      global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
    case ENVIRON_VAR:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
      global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
    case CONFIG_FILE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
      global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
    case MANAGEMENT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
      global->origin = JMM_VMGLOBAL_ORIGIN_MANAGEMENT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
    case ERGONOMIC:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
      global->origin = JMM_VMGLOBAL_ORIGIN_ERGONOMIC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
      global->origin = JMM_VMGLOBAL_ORIGIN_OTHER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
  }
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1567
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1568
  return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
// Fill globals array of count length with jmmVMGlobal entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
// specified by names. If names == NULL, fill globals array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
// with all Flags. Return value is number of entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
// created in globals.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
// If a Flag with a given name in an array element does not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
// exist, globals[i].name will be set to NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
JVM_ENTRY(jint, jmm_GetVMGlobals(JNIEnv *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
                                 jobjectArray names,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
                                 jmmVMGlobal *globals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
                                 jint count))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
  if (globals == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
    THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
  if (names != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
    // return the requested globals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
    objArrayOop ta = objArrayOop(JNIHandles::resolve_non_null(names));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
    objArrayHandle names_ah(THREAD, ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
    // Make sure we have a String array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
    klassOop element_klass = objArrayKlass::cast(names_ah->klass())->element_klass();
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1595
    if (element_klass != SystemDictionary::String_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
      THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
                 "Array element type is not String class", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
    int names_length = names_ah->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
    int num_entries = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
    for (int i = 0; i < names_length && i < count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
      oop s = names_ah->obj_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
      if (s == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
        THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
      Handle sh(THREAD, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
      char* str = java_lang_String::as_utf8_string(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
      Flag* flag = Flag::find_flag(str, strlen(str));
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1611
      if (flag != NULL &&
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1612
          add_global_entry(env, sh, &globals[i], flag, THREAD)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
        num_entries++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
        globals[i].name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
    return num_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
    // return all globals if names == NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
    // last flag entry is always NULL, so subtract 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
    int nFlags = (int) Flag::numFlags - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
    Handle null_h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
    int num_entries = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
    for (int i = 0; i < nFlags && num_entries < count;  i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
      Flag* flag = &Flag::flags[i];
1382
fa3de4068282 6618726: Introduce -XX:+UnlockExperimentalVMOptions flag
ysr
parents: 1
diff changeset
  1628
      // Exclude the locked (diagnostic, experimental) flags
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1629
      if ((flag->is_unlocked() || flag->is_unlocker()) &&
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1630
          add_global_entry(env, null_h, &globals[num_entries], flag, THREAD)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
        num_entries++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
    return num_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
JVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
  oop fn = JNIHandles::resolve_external_guard(flag_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
  if (fn == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
              "The flag name cannot be null.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
  char* name = java_lang_String::as_utf8_string(fn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
  Flag* flag = Flag::find_flag(name, strlen(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
  if (flag == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
              "Flag does not exist.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
  if (!flag->is_writeable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
              "This flag is not writeable.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
  bool succeed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
  if (flag->is_bool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
    bool bvalue = (new_value.z == JNI_TRUE ? true : false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
    succeed = CommandLineFlags::boolAtPut(name, &bvalue, MANAGEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
  } else if (flag->is_intx()) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1662
    intx ivalue = (intx)new_value.j;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
    succeed = CommandLineFlags::intxAtPut(name, &ivalue, MANAGEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  } else if (flag->is_uintx()) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1665
    uintx uvalue = (uintx)new_value.j;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
    succeed = CommandLineFlags::uintxAtPut(name, &uvalue, MANAGEMENT);
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1667
  } else if (flag->is_uint64_t()) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1668
    uint64_t uvalue = (uint64_t)new_value.j;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1669
    succeed = CommandLineFlags::uint64_tAtPut(name, &uvalue, MANAGEMENT);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
  } else if (flag->is_ccstr()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
    oop str = JNIHandles::resolve_external_guard(new_value.l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
    if (str == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
      THROW(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
    ccstr svalue = java_lang_String::as_utf8_string(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
    succeed = CommandLineFlags::ccstrAtPut(name, &svalue, MANAGEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
  assert(succeed, "Setting flag should succeed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
class ThreadTimesClosure: public ThreadClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
  objArrayOop _names;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
  typeArrayOop _times;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
  int _names_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
  int _times_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
  int _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
  ThreadTimesClosure(objArrayOop names, typeArrayOop times);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
  virtual void do_thread(Thread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
  int count() { return _count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
ThreadTimesClosure::ThreadTimesClosure(objArrayOop names,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
                                       typeArrayOop times) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
  assert(names != NULL, "names was NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
  assert(times != NULL, "times was NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
  _names = names;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
  _names_len = names->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
  _times = times;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
  _times_len = times->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
  _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
void ThreadTimesClosure::do_thread(Thread* thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
  Handle s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
  assert(thread != NULL, "thread was NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
  // exclude externally visible JavaThreads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
  if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
  if (_count >= _names_len || _count >= _times_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
    // skip if the result array is not big enough
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
  assert(thread->name() != NULL, "All threads should have a name");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
  s = java_lang_String::create_from_str(thread->name(), CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
  _names->obj_at_put(_count, s());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
  _times->long_at_put(_count, os::is_thread_cpu_time_supported() ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
                        os::thread_cpu_time(thread) : -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
  _count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
// Fills names with VM internal thread names and times with the corresponding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
// CPU times.  If names or times is NULL, a NullPointerException is thrown.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
// If the element type of names is not String, an IllegalArgumentException is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
// thrown.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
// If an array is not large enough to hold all the entries, only the entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
// that fit will be returned.  Return value is the number of VM internal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
// threads entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
JVM_ENTRY(jint, jmm_GetInternalThreadTimes(JNIEnv *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
                                           jobjectArray names,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
                                           jlongArray times))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
  if (names == NULL || times == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
     THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
  objArrayOop na = objArrayOop(JNIHandles::resolve_non_null(names));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
  objArrayHandle names_ah(THREAD, na);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
  // Make sure we have a String array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
  klassOop element_klass = objArrayKlass::cast(names_ah->klass())->element_klass();
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1749
  if (element_klass != SystemDictionary::String_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
               "Array element type is not String class", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
  typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(times));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
  typeArrayHandle times_ah(THREAD, ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
  ThreadTimesClosure ttc(names_ah(), times_ah());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
    MutexLockerEx ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
    Threads::threads_do(&ttc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
  return ttc.count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
static Handle find_deadlocks(bool object_monitors_only, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
  VM_FindDeadlocks op(!object_monitors_only /* also check concurrent locks? */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
  DeadlockCycle* deadlocks = op.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
  if (deadlocks == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
    // no deadlock found and return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
    return Handle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  int num_threads = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
  DeadlockCycle* cycle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
  for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
    num_threads += cycle->num_threads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1784
  objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NH);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
  objArrayHandle threads_ah(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
  for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
    GrowableArray<JavaThread*>* deadlock_threads = cycle->threads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
    int len = deadlock_threads->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
      threads_ah->obj_at_put(index, deadlock_threads->at(i)->threadObj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
      index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
  return threads_ah;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
// Finds cycles of threads that are deadlocked involved in object monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
// and JSR-166 synchronizers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
// Returns an array of Thread objects which are in deadlock, if any.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
// Otherwise, returns NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
// Input parameter:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
//    object_monitors_only - if true, only check object monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
JVM_ENTRY(jobjectArray, jmm_FindDeadlockedThreads(JNIEnv *env, jboolean object_monitors_only))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
  Handle result = find_deadlocks(object_monitors_only != 0, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
  return (jobjectArray) JNIHandles::make_local(env, result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
// Finds cycles of threads that are deadlocked on monitor locks
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
// Returns an array of Thread objects which are in deadlock, if any.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
// Otherwise, returns NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
JVM_ENTRY(jobjectArray, jmm_FindMonitorDeadlockedThreads(JNIEnv *env))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
  Handle result = find_deadlocks(true, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
  return (jobjectArray) JNIHandles::make_local(env, result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
// Gets the information about GC extension attributes including
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
// the name of the attribute, its type, and a short description.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
//   mgr   - GC memory manager
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
//   info  - caller allocated array of jmmExtAttributeInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
//   count - number of elements of the info array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
// Returns the number of GC extension attributes filled in the info array; or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
// -1 if info is not big enough
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
JVM_ENTRY(jint, jmm_GetGCExtAttributeInfo(JNIEnv *env, jobject mgr, jmmExtAttributeInfo* info, jint count))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
  // All GC memory managers have 1 attribute (number of GC threads)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
  if (count == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
  if (info == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
   THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
  info[0].name = "GcThreadCount";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
  info[0].type = 'I';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
  info[0].description = "Number of GC threads";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
  return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
// verify the given array is an array of java/lang/management/MemoryUsage objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
// of a given length and return the objArrayOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
static objArrayOop get_memory_usage_objArray(jobjectArray array, int length, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
  if (array == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
    THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
  objArrayOop oa = objArrayOop(JNIHandles::resolve_non_null(array));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
  objArrayHandle array_h(THREAD, oa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
  // array must be of the given length
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
  if (length != array_h->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
               "The length of the given MemoryUsage array does not match the number of memory pools.", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
  // check if the element of array is of type MemoryUsage class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
  klassOop usage_klass = Management::java_lang_management_MemoryUsage_klass(CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
  klassOop element_klass = objArrayKlass::cast(array_h->klass())->element_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
  if (element_klass != usage_klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
               "The element type is not MemoryUsage class", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
  return array_h();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
// Gets the statistics of the last GC of a given GC memory manager.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
//   obj     - GarbageCollectorMXBean object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
//   gc_stat - caller allocated jmmGCStat where:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
//     a. before_gc_usage - array of MemoryUsage objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
//     b. after_gc_usage  - array of MemoryUsage objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
//     c. gc_ext_attributes_values_size is set to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
//        gc_ext_attribute_values array allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
//     d. gc_ext_attribute_values is a caller allocated array of jvalue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
// On return,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
//   gc_index == 0 indicates no GC statistics available
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
//   before_gc_usage and after_gc_usage - filled with per memory pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
//      before and after GC usage in the same order as the memory pools
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
//      returned by GetMemoryPools for a given GC memory manager.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
//   num_gc_ext_attributes indicates the number of elements in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
//      the gc_ext_attribute_values array is filled; or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
//      -1 if the gc_ext_attributes_values array is not big enough
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
JVM_ENTRY(void, jmm_GetLastGCStat(JNIEnv *env, jobject obj, jmmGCStat *gc_stat))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
  if (gc_stat->gc_ext_attribute_values_size > 0 && gc_stat->gc_ext_attribute_values == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
    THROW(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
  // Get the GCMemoryManager
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
  GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
  if (mgr->last_gc_stat() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
    gc_stat->gc_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
  // Make a copy of the last GC statistics
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
  // GC may occur while constructing the last GC information
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
  int num_pools = MemoryService::num_memory_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
  GCStatInfo* stat = new GCStatInfo(num_pools);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
  stat->copy_stat(mgr->last_gc_stat());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
  gc_stat->gc_index = stat->gc_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
  gc_stat->start_time = Management::ticks_to_ms(stat->start_time());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
  gc_stat->end_time = Management::ticks_to_ms(stat->end_time());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
  // Current implementation does not have GC extension attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
  gc_stat->num_gc_ext_attributes = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
  // Fill the arrays of MemoryUsage objects with before and after GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
  // per pool memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
  objArrayOop bu = get_memory_usage_objArray(gc_stat->usage_before_gc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
                                             num_pools,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
                                             CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
  objArrayHandle usage_before_gc_ah(THREAD, bu);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
  objArrayOop au = get_memory_usage_objArray(gc_stat->usage_after_gc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
                                             num_pools,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
                                             CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
  objArrayHandle usage_after_gc_ah(THREAD, au);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
  for (int i = 0; i < num_pools; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
    Handle before_usage = MemoryService::create_MemoryUsage_obj(stat->before_gc_usage_for_pool(i), CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
    Handle after_usage;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
    MemoryUsage u = stat->after_gc_usage_for_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
    if (u.max_size() == 0 && u.used() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
      // If max size == 0, this pool is a survivor space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
      // Set max size = -1 since the pools will be swapped after GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
      MemoryUsage usage(u.init_size(), u.used(), u.committed(), (size_t)-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
      after_usage = MemoryService::create_MemoryUsage_obj(usage, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
      after_usage = MemoryService::create_MemoryUsage_obj(stat->after_gc_usage_for_pool(i), CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
    usage_before_gc_ah->obj_at_put(i, before_usage());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
    usage_after_gc_ah->obj_at_put(i, after_usage());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
  if (gc_stat->gc_ext_attribute_values_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
    // Current implementation only has 1 attribute (number of GC threads)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
    // The type is 'I'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
    gc_stat->gc_ext_attribute_values[0].i = mgr->num_gc_threads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
// Dump heap - Returns 0 if succeeds.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
JVM_ENTRY(jint, jmm_DumpHeap0(JNIEnv *env, jstring outputfile, jboolean live))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
#ifndef SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
  oop on = JNIHandles::resolve_external_guard(outputfile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
  if (on == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
               "Output file name cannot be null.", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
  char* name = java_lang_String::as_utf8_string(on);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
  if (name == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
               "Output file name cannot be null.", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
  HeapDumper dumper(live ? true : false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
  if (dumper.dump(name) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
    const char* errmsg = dumper.error_as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
    THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
#else  // SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
#endif // SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
jlong Management::ticks_to_ms(jlong ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
  assert(os::elapsed_frequency() > 0, "Must be non-zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
  return (jlong)(((double)ticks / (double)os::elapsed_frequency())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
                 * (double)1000.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
const struct jmmInterface_1_ jmm_interface = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
  NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
  NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
  jmm_GetVersion,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
  jmm_GetOptionalSupport,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
  jmm_GetInputArguments,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
  jmm_GetThreadInfo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
  jmm_GetInputArgumentArray,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
  jmm_GetMemoryPools,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
  jmm_GetMemoryManagers,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
  jmm_GetMemoryPoolUsage,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
  jmm_GetPeakMemoryPoolUsage,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
  NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
  jmm_GetMemoryUsage,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
  jmm_GetLongAttribute,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
  jmm_GetBoolAttribute,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
  jmm_SetBoolAttribute,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
  jmm_GetLongAttributes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
  jmm_FindMonitorDeadlockedThreads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
  jmm_GetThreadCpuTime,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
  jmm_GetVMGlobalNames,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
  jmm_GetVMGlobals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
  jmm_GetInternalThreadTimes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
  jmm_ResetStatistic,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
  jmm_SetPoolSensor,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
  jmm_SetPoolThreshold,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
  jmm_GetPoolCollectionUsage,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
  jmm_GetGCExtAttributeInfo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
  jmm_GetLastGCStat,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
  jmm_GetThreadCpuTimeWithKind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
  NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
  jmm_DumpHeap0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
  jmm_FindDeadlockedThreads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
  jmm_SetVMGlobal,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
  NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
  jmm_DumpThreads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
void* Management::get_jmm_interface(int version) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
  if (version == JMM_VERSION_1_0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
    return (void*) &jmm_interface;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
}