src/hotspot/share/services/management.cpp
author gziemski
Mon, 23 Apr 2018 14:51:16 -0500
changeset 49860 ca5216a2a2cc
parent 49857 31e07291ae29
child 49902 3661f31c6df4
permissions -rw-r--r--
8202151: [BACKOUT] Split globals.hpp to factor out the Flag class Summary: Backed out JDK-8081519 Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49036
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5091
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5091
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5091
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    25
#include "precompiled.hpp"
48090
cce885f4baab 8191202: Remove duplicated jmm.h
ihse
parents: 47592
diff changeset
    26
#include "jmm.h"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    27
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    28
#include "compiler/compileBroker.hpp"
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 49192
diff changeset
    29
#include "memory/allocation.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    30
#include "memory/iterator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    31
#include "memory/oopFactory.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    32
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    33
#include "oops/klass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    34
#include "oops/objArrayKlass.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 27880
diff changeset
    35
#include "oops/objArrayOop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    36
#include "oops/oop.inline.hpp"
49036
bc92debe57e4 8197999: Accessors in typeArrayOopDesc should use new Access API
rkennke
parents: 48105
diff changeset
    37
#include "oops/typeArrayOop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    38
#include "runtime/arguments.hpp"
11254
e2dd3c32a7cb 7122880: Extend vendor-specific command interface to include manageable switches
phh
parents: 11209
diff changeset
    39
#include "runtime/globals.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    40
#include "runtime/handles.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49360
diff changeset
    41
#include "runtime/interfaceSupport.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    42
#include "runtime/javaCalls.hpp"
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49036
diff changeset
    43
#include "runtime/jniHandles.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    44
#include "runtime/os.hpp"
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    45
#include "runtime/serviceThread.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 23477
diff changeset
    46
#include "runtime/thread.inline.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
    47
#include "runtime/threadSMR.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    48
#include "services/classLoadingService.hpp"
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
    49
#include "services/diagnosticCommand.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
    50
#include "services/diagnosticFramework.hpp"
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents: 27880
diff changeset
    51
#include "services/writeableFlags.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    52
#include "services/heapDumper.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    53
#include "services/lowMemoryDetector.hpp"
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
    54
#include "services/gcNotifier.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11598
diff changeset
    55
#include "services/nmtDCmd.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    56
#include "services/management.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    57
#include "services/memoryManager.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    58
#include "services/memoryPool.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    59
#include "services/memoryService.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    60
#include "services/runtimeService.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6427
diff changeset
    61
#include "services/threadService.hpp"
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 46335
diff changeset
    62
#include "utilities/debug.hpp"
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 46335
diff changeset
    63
#include "utilities/formatBuffer.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14488
diff changeset
    64
#include "utilities/macros.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
PerfVariable* Management::_begin_vm_creation_time = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
PerfVariable* Management::_end_vm_creation_time = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
PerfVariable* Management::_vm_init_done_time = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    70
InstanceKlass* Management::_diagnosticCommandImpl_klass = NULL;
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    71
InstanceKlass* Management::_garbageCollectorExtImpl_klass = NULL;
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    72
InstanceKlass* Management::_garbageCollectorMXBean_klass = NULL;
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    73
InstanceKlass* Management::_gcInfo_klass = NULL;
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    74
InstanceKlass* Management::_managementFactoryHelper_klass = NULL;
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    75
InstanceKlass* Management::_memoryManagerMXBean_klass = NULL;
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    76
InstanceKlass* Management::_memoryPoolMXBean_klass = NULL;
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    77
InstanceKlass* Management::_memoryUsage_klass = NULL;
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    78
InstanceKlass* Management::_sensor_klass = NULL;
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
    79
InstanceKlass* Management::_threadInfo_klass = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
jmmOptionalSupport Management::_optional_support = {0};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
TimeStamp Management::_stamp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
void management_init() {
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
    85
#if INCLUDE_MANAGEMENT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  Management::init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  ThreadService::init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  RuntimeService::init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  ClassLoadingService::init();
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
    90
#else
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
    91
  ThreadService::init();
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
    92
#endif // INCLUDE_MANAGEMENT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
    95
#if INCLUDE_MANAGEMENT
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
    96
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void Management::init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // These counters are for java.lang.management API support.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // They are created even if -XX:-UsePerfData is set and in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // that case, they will be allocated on C heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  _begin_vm_creation_time =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
            PerfDataManager::create_variable(SUN_RT, "createVmBeginTime",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
                                             PerfData::U_None, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  _end_vm_creation_time =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
            PerfDataManager::create_variable(SUN_RT, "createVmEndTime",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
                                             PerfData::U_None, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  _vm_init_done_time =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
            PerfDataManager::create_variable(SUN_RT, "vmInitDoneTime",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
                                             PerfData::U_None, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Initialize optional support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  _optional_support.isLowMemoryDetectionSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  _optional_support.isCompilationTimeMonitoringSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  _optional_support.isThreadContentionMonitoringSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  if (os::is_thread_cpu_time_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    _optional_support.isCurrentThreadCpuTimeSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    _optional_support.isOtherThreadCpuTimeSupported = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    _optional_support.isCurrentThreadCpuTimeSupported = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    _optional_support.isOtherThreadCpuTimeSupported = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  }
7724
a92d706dbdd5 7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents: 7397
diff changeset
   128
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  _optional_support.isObjectMonitorUsageSupported = 1;
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
   130
#if INCLUDE_SERVICES
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // This depends on the heap inspector
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  _optional_support.isSynchronizerUsageSupported = 1;
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
   133
#endif // INCLUDE_SERVICES
7724
a92d706dbdd5 7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents: 7397
diff changeset
   134
  _optional_support.isThreadAllocatedMemorySupported = 1;
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
   135
  _optional_support.isRemoteDiagnosticCommandsSupported = 1;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
   136
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11254
diff changeset
   137
  // Registration of the diagnostic commands
11598
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11591
diff changeset
   138
  DCmdRegistrant::register_dcmds();
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11591
diff changeset
   139
  DCmdRegistrant::register_dcmds_ext();
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
   140
  uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
   141
                         | DCmd_Source_MBean;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
   142
  DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<NMTDCmd>(full_export, true, false));
1
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::initialize(TRAPS) {
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
   146
  // Start the service thread
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
   147
  ServiceThread::initialize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  if (ManagementServer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    HandleMark hm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
43400
cc18486e399f 8173608: Separate JDK management agent from java.management module
mchung
parents: 42052
diff changeset
   153
    // Load and initialize the jdk.internal.agent.Agent class
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    // invoke startAgent method to start the management server
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
43400
cc18486e399f 8173608: Separate JDK management agent from java.management module
mchung
parents: 42052
diff changeset
   156
    Klass* k = SystemDictionary::resolve_or_null(vmSymbols::jdk_internal_agent_Agent(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
                                                   loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                                                   Handle(),
23476
78871f5c479b 8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents: 21185
diff changeset
   159
                                                   THREAD);
78871f5c479b 8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents: 21185
diff changeset
   160
    if (k == NULL) {
78871f5c479b 8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents: 21185
diff changeset
   161
      vm_exit_during_initialization("Management agent initialization failure: "
43400
cc18486e399f 8173608: Separate JDK management agent from java.management module
mchung
parents: 42052
diff changeset
   162
          "class jdk.internal.agent.Agent not found.");
23476
78871f5c479b 8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents: 21185
diff changeset
   163
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    JavaCalls::call_static(&result,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   167
                           k,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   168
                           vmSymbols::startAgent_name(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   169
                           vmSymbols::void_method_signature(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
                           CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
void Management::get_optional_support(jmmOptionalSupport* support) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  memcpy(support, &_optional_support, sizeof(jmmOptionalSupport));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   178
InstanceKlass* Management::load_and_initialize_klass(Symbol* sh, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   179
  Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   180
  return initialize_klass(k, CHECK_NULL);
42052
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   181
}
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   182
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   183
InstanceKlass* Management::load_and_initialize_klass_or_null(Symbol* sh, TRAPS) {
42052
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   184
  Klass* k = SystemDictionary::resolve_or_null(sh, CHECK_NULL);
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   185
  if (k == NULL) {
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   186
     return NULL;
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   187
  }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   188
  return initialize_klass(k, CHECK_NULL);
42052
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   189
}
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   190
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   191
InstanceKlass* Management::initialize_klass(Klass* k, TRAPS) {
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   192
  InstanceKlass* ik = InstanceKlass::cast(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  if (ik->should_be_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    ik->initialize(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   196
  // If these classes change to not be owned by the boot loader, they need
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   197
  // to be walked to keep their class loader alive in oops_do.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   198
  assert(ik->class_loader() == NULL, "need to follow in oops_do");
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   199
  return ik;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
void Management::record_vm_startup_time(jlong begin, jlong duration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // if the performance counter is not initialized,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // then vm initialization failed; simply return.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  if (_begin_vm_creation_time == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  _begin_vm_creation_time->set_value(begin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  _end_vm_creation_time->set_value(begin + duration);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  PerfMemory::set_accessible(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
jlong Management::timestamp() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  TimeStamp t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  t.update();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  return t.ticks() - _stamp.ticks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
void Management::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  MemoryService::oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  ThreadService::oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   223
InstanceKlass* Management::java_lang_management_ThreadInfo_klass(TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  if (_threadInfo_klass == NULL) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   225
    _threadInfo_klass = load_and_initialize_klass(vmSymbols::java_lang_management_ThreadInfo(), CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  return _threadInfo_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   230
InstanceKlass* Management::java_lang_management_MemoryUsage_klass(TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  if (_memoryUsage_klass == NULL) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   232
    _memoryUsage_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryUsage(), CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  return _memoryUsage_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   237
InstanceKlass* Management::java_lang_management_MemoryPoolMXBean_klass(TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  if (_memoryPoolMXBean_klass == NULL) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   239
    _memoryPoolMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryPoolMXBean(), CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  return _memoryPoolMXBean_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   244
InstanceKlass* Management::java_lang_management_MemoryManagerMXBean_klass(TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  if (_memoryManagerMXBean_klass == NULL) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   246
    _memoryManagerMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryManagerMXBean(), CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  return _memoryManagerMXBean_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   251
InstanceKlass* Management::java_lang_management_GarbageCollectorMXBean_klass(TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  if (_garbageCollectorMXBean_klass == NULL) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   253
      _garbageCollectorMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_GarbageCollectorMXBean(), CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  return _garbageCollectorMXBean_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   258
InstanceKlass* Management::sun_management_Sensor_klass(TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if (_sensor_klass == NULL) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   260
    _sensor_klass = load_and_initialize_klass(vmSymbols::sun_management_Sensor(), CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  return _sensor_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   265
InstanceKlass* Management::sun_management_ManagementFactoryHelper_klass(TRAPS) {
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 30232
diff changeset
   266
  if (_managementFactoryHelper_klass == NULL) {
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 30232
diff changeset
   267
    _managementFactoryHelper_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactoryHelper(), CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  }
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 30232
diff changeset
   269
  return _managementFactoryHelper_klass;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   272
InstanceKlass* Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(TRAPS) {
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 30232
diff changeset
   273
  if (_garbageCollectorExtImpl_klass == NULL) {
42052
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   274
    _garbageCollectorExtImpl_klass =
b3a1c6c4f86e 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 38254
diff changeset
   275
                load_and_initialize_klass_or_null(vmSymbols::com_sun_management_internal_GarbageCollectorExtImpl(), CHECK_NULL);
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
   276
  }
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 30232
diff changeset
   277
  return _garbageCollectorExtImpl_klass;
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
   278
}
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
   279
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   280
InstanceKlass* Management::com_sun_management_GcInfo_klass(TRAPS) {
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
   281
  if (_gcInfo_klass == NULL) {
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
   282
    _gcInfo_klass = load_and_initialize_klass(vmSymbols::com_sun_management_GcInfo(), CHECK_NULL);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
   283
  }
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
   284
  return _gcInfo_klass;
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
   285
}
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
   286
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   287
InstanceKlass* Management::com_sun_management_internal_DiagnosticCommandImpl_klass(TRAPS) {
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
   288
  if (_diagnosticCommandImpl_klass == NULL) {
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 30232
diff changeset
   289
    _diagnosticCommandImpl_klass = load_and_initialize_klass(vmSymbols::com_sun_management_internal_DiagnosticCommandImpl(), CHECK_NULL);
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
   290
  }
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
   291
  return _diagnosticCommandImpl_klass;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
   292
}
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
   293
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
static void initialize_ThreadInfo_constructor_arguments(JavaCallArguments* args, ThreadSnapshot* snapshot, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  Handle snapshot_thread(THREAD, snapshot->threadObj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  jlong contended_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  jlong waited_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  if (ThreadService::is_thread_monitoring_contention()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    contended_time = Management::ticks_to_ms(snapshot->contended_enter_ticks());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    waited_time = Management::ticks_to_ms(snapshot->monitor_wait_ticks() + snapshot->sleep_ticks());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    // set them to -1 if thread contention monitoring is disabled.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    contended_time = max_julong;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    waited_time = max_julong;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  int thread_status = snapshot->thread_status();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  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
   310
  if (snapshot->is_ext_suspended()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    thread_status |= JMM_THREAD_STATE_FLAG_SUSPENDED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if (snapshot->is_in_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    thread_status |= JMM_THREAD_STATE_FLAG_NATIVE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  ThreadStackTrace* st = snapshot->get_stack_trace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  Handle stacktrace_h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  if (st != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    stacktrace_h = st->allocate_fill_stack_trace_element_array(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    stacktrace_h = Handle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  args->push_oop(snapshot_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  args->push_int(thread_status);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  args->push_oop(Handle(THREAD, snapshot->blocker_object()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  args->push_oop(Handle(THREAD, snapshot->blocker_object_owner()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  args->push_long(snapshot->contended_enter_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  args->push_long(contended_time);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  args->push_long(snapshot->monitor_wait_count() + snapshot->sleep_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  args->push_long(waited_time);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  args->push_oop(stacktrace_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
// Helper function to construct a ThreadInfo object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
instanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   338
  InstanceKlass* ik = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  JavaCallArguments args(14);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // First allocate a ThreadObj object and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // push the receiver as the first argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  Handle element = ik->allocate_instance_handle(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  args.push_oop(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  // initialize the arguments for the ThreadInfo constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  // Call ThreadInfo constructor with no locked monitors and synchronizers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
                          ik,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   354
                          vmSymbols::object_initializer_name(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   355
                          vmSymbols::java_lang_management_ThreadInfo_constructor_signature(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
                          &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
                          CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  return (instanceOop) element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
instanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
                                                    objArrayHandle monitors_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
                                                    typeArrayHandle depths_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
                                                    objArrayHandle synchronizers_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
                                                    TRAPS) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   367
  InstanceKlass* ik = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  JavaCallArguments args(17);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  // First allocate a ThreadObj object and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  // push the receiver as the first argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  Handle element = ik->allocate_instance_handle(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  args.push_oop(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  // initialize the arguments for the ThreadInfo constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  // push the locked monitors and synchronizers in the arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  args.push_oop(monitors_array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  args.push_oop(depths_array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  args.push_oop(synchronizers_array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  // Call ThreadInfo constructor with locked monitors and synchronizers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
                          ik,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   388
                          vmSymbols::object_initializer_name(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7724
diff changeset
   389
                          vmSymbols::java_lang_management_ThreadInfo_with_locks_constructor_signature(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
                          &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
                          CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  return (instanceOop) element();
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
static GCMemoryManager* get_gc_memory_manager_from_jobject(jobject mgr, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  if (mgr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  oop mgr_obj = JNIHandles::resolve(mgr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  instanceHandle h(THREAD, (instanceOop) mgr_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   404
  InstanceKlass* k = Management::java_lang_management_GarbageCollectorMXBean_klass(CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  if (!h->is_a(k)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
               "the object is not an instance of java.lang.management.GarbageCollectorMXBean class",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
               NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  MemoryManager* gc = MemoryService::get_memory_manager(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  if (gc == NULL || !gc->is_gc_memory_manager()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
               "Invalid GC memory manager",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
               NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  return (GCMemoryManager*) gc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
static MemoryPool* get_memory_pool_from_jobject(jobject obj, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  oop pool_obj = JNIHandles::resolve(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  assert(pool_obj->is_instance(), "Should be an instanceOop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  instanceHandle ph(THREAD, (instanceOop) pool_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  return MemoryService::get_memory_pool(ph);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
26834
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
   432
#endif // INCLUDE_MANAGEMENT
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
   433
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
static void validate_thread_id_array(typeArrayHandle ids_ah, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  int num_threads = ids_ah->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  // Validate input thread IDs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  for (i = 0; i < num_threads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    jlong tid = ids_ah->long_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    if (tid <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      // throw exception if invalid thread id.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
                "Invalid thread ID entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
26834
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
   449
#if INCLUDE_MANAGEMENT
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
   450
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
static void validate_thread_info_array(objArrayHandle infoArray_h, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  // check if the element of infoArray is of type ThreadInfo class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   453
  Klass* threadinfo_klass = Management::java_lang_management_ThreadInfo_klass(CHECK);
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13870
diff changeset
   454
  Klass* element_klass = ObjArrayKlass::cast(infoArray_h->klass())->element_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  if (element_klass != threadinfo_klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
              "infoArray element type is not ThreadInfo class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
static MemoryManager* get_memory_manager_from_jobject(jobject obj, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  oop mgr_obj = JNIHandles::resolve(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  assert(mgr_obj->is_instance(), "Should be an instanceOop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  instanceHandle mh(THREAD, (instanceOop) mgr_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  return MemoryService::get_memory_manager(mh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
// Returns a version string and sets major and minor version if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
// the input parameters are non-null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
JVM_LEAF(jint, jmm_GetVersion(JNIEnv *env))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  return JMM_VERSION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
// Gets the list of VM monitoring and management optional supports
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
// Returns 0 if succeeded; otherwise returns non-zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
JVM_LEAF(jint, jmm_GetOptionalSupport(JNIEnv *env, jmmOptionalSupport* support))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  if (support == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  Management::get_optional_support(support);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
// Returns an array of java/lang/management/MemoryPoolMXBean object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
// one for each memory pool if obj == null; otherwise returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
// an array of memory pools for a given memory manager if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
// it is a valid memory manager.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
JVM_ENTRY(jobjectArray, jmm_GetMemoryPools(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  int num_memory_pools;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  MemoryManager* mgr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    num_memory_pools = MemoryService::num_memory_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    mgr = get_memory_manager_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    if (mgr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    num_memory_pools = mgr->num_memory_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  // Allocate the resulting MemoryPoolMXBean[] object
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   510
  InstanceKlass* ik = Management::java_lang_management_MemoryPoolMXBean_klass(CHECK_NULL);
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   511
  objArrayOop r = oopFactory::new_objArray(ik, num_memory_pools, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  objArrayHandle poolArray(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  if (mgr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    // Get all memory pools
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    for (int i = 0; i < num_memory_pools; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
      MemoryPool* pool = MemoryService::get_memory_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      instanceHandle ph(THREAD, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      poolArray->obj_at_put(i, ph());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    // Get memory pools managed by a given memory manager
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    for (int i = 0; i < num_memory_pools; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
      MemoryPool* pool = mgr->get_memory_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
      instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      instanceHandle ph(THREAD, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      poolArray->obj_at_put(i, ph());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  return (jobjectArray) JNIHandles::make_local(env, poolArray());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
// Returns an array of java/lang/management/MemoryManagerMXBean object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
// one for each memory manager if obj == null; otherwise returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
// an array of memory managers for a given memory pool if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
// it is a valid memory pool.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
JVM_ENTRY(jobjectArray, jmm_GetMemoryManagers(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  int num_mgrs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  MemoryPool* pool = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    num_mgrs = MemoryService::num_memory_managers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    if (pool == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    num_mgrs = pool->num_memory_managers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  // Allocate the resulting MemoryManagerMXBean[] object
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   554
  InstanceKlass* ik = Management::java_lang_management_MemoryManagerMXBean_klass(CHECK_NULL);
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   555
  objArrayOop r = oopFactory::new_objArray(ik, num_mgrs, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  objArrayHandle mgrArray(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  if (pool == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    // Get all memory managers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    for (int i = 0; i < num_mgrs; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
      MemoryManager* mgr = MemoryService::get_memory_manager(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
      instanceHandle ph(THREAD, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      mgrArray->obj_at_put(i, ph());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    // Get memory managers for a given memory pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    for (int i = 0; i < num_mgrs; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      MemoryManager* mgr = pool->get_memory_manager(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
      instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
      instanceHandle ph(THREAD, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      mgrArray->obj_at_put(i, ph());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  return (jobjectArray) JNIHandles::make_local(env, mgrArray());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
// Returns a java/lang/management/MemoryUsage object containing the memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
// of a given memory pool.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
JVM_ENTRY(jobject, jmm_GetMemoryPoolUsage(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  if (pool != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    MemoryUsage usage = pool->get_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    return JNIHandles::make_local(env, h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
// Returns a java/lang/management/MemoryUsage object containing the memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
// of a given memory pool.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
JVM_ENTRY(jobject, jmm_GetPeakMemoryPoolUsage(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  if (pool != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    MemoryUsage usage = pool->get_peak_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    return JNIHandles::make_local(env, h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
// Returns a java/lang/management/MemoryUsage object containing the memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
// of a given memory pool after most recent GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
JVM_ENTRY(jobject, jmm_GetPoolCollectionUsage(JNIEnv* env, jobject obj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  if (pool != NULL && pool->is_collected_pool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    MemoryUsage usage = pool->get_last_collection_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    return JNIHandles::make_local(env, h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
// Sets the memory pool sensor for a threshold type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
JVM_ENTRY(void, jmm_SetPoolSensor(JNIEnv* env, jobject obj, jmmThresholdType type, jobject sensorObj))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  if (obj == NULL || sensorObj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
    THROW(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   630
  InstanceKlass* sensor_klass = Management::sun_management_Sensor_klass(CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  oop s = JNIHandles::resolve(sensorObj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  assert(s->is_instance(), "Sensor should be an instanceOop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  instanceHandle sensor_h(THREAD, (instanceOop) s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  if (!sensor_h->is_a(sensor_klass)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
              "Sensor is not an instance of sun.management.Sensor class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  MemoryPool* mpool = get_memory_pool_from_jobject(obj, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  assert(mpool != NULL, "MemoryPool should exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    case JMM_USAGE_THRESHOLD_HIGH:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    case JMM_USAGE_THRESHOLD_LOW:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
      // have only one sensor for threshold high and low
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
      mpool->set_usage_sensor_obj(sensor_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    case JMM_COLLECTION_USAGE_THRESHOLD_HIGH:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    case JMM_COLLECTION_USAGE_THRESHOLD_LOW:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
      // have only one sensor for threshold high and low
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
      mpool->set_gc_usage_sensor_obj(sensor_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
      assert(false, "Unrecognized type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
// Sets the threshold of a given memory pool.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
// Returns the previous threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
//   pool      - the MemoryPoolMXBean object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
//   type      - threshold type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
//   threshold - the new threshold (must not be negative)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
JVM_ENTRY(jlong, jmm_SetPoolThreshold(JNIEnv* env, jobject obj, jmmThresholdType type, jlong threshold))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  if (threshold < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
               "Invalid threshold value",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
               -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
1676
d80e69372634 6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents: 1382
diff changeset
   675
  if ((size_t)threshold > max_uintx) {
d80e69372634 6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents: 1382
diff changeset
   676
    stringStream st;
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31371
diff changeset
   677
    st.print("Invalid valid threshold value. Threshold value (" JLONG_FORMAT ") > max value of size_t (" UINTX_FORMAT ")", threshold, max_uintx);
1676
d80e69372634 6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents: 1382
diff changeset
   678
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), st.as_string(), -1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_(0L));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  assert(pool != NULL, "MemoryPool should exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  jlong prev = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    case JMM_USAGE_THRESHOLD_HIGH:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
      if (!pool->usage_threshold()->is_high_threshold_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
        return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
      prev = pool->usage_threshold()->set_high_threshold((size_t) threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
    case JMM_USAGE_THRESHOLD_LOW:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      if (!pool->usage_threshold()->is_low_threshold_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
        return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
      prev = pool->usage_threshold()->set_low_threshold((size_t) threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    case JMM_COLLECTION_USAGE_THRESHOLD_HIGH:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
      if (!pool->gc_usage_threshold()->is_high_threshold_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
        return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
      // return and the new threshold is effective for the next GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
      return pool->gc_usage_threshold()->set_high_threshold((size_t) threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    case JMM_COLLECTION_USAGE_THRESHOLD_LOW:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      if (!pool->gc_usage_threshold()->is_low_threshold_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
        return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
      // return and the new threshold is effective for the next GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
      return pool->gc_usage_threshold()->set_low_threshold((size_t) threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
      assert(false, "Unrecognized type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
      return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  // When the threshold is changed, reevaluate if the low memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  // detection is enabled.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  if (prev != threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    LowMemoryDetector::recompute_enabled_for_collected_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
    LowMemoryDetector::detect_low_memory(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  return prev;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
// Returns a java/lang/management/MemoryUsage object representing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
// the memory usage for the heap or non-heap memory.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
JVM_ENTRY(jobject, jmm_GetMemoryUsage(JNIEnv* env, jboolean heap))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  // Calculate the memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  size_t total_init = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
  size_t total_used = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  size_t total_committed = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  size_t total_max = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  bool   has_undefined_init_size = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  bool   has_undefined_max_size = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
    MemoryPool* pool = MemoryService::get_memory_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
    if ((heap && pool->is_heap()) || (!heap && pool->is_non_heap())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
      MemoryUsage u = pool->get_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
      total_used += u.used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
      total_committed += u.committed();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
      if (u.init_size() == (size_t)-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
        has_undefined_init_size = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
      if (!has_undefined_init_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
        total_init += u.init_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
      if (u.max_size() == (size_t)-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
        has_undefined_max_size = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
      if (!has_undefined_max_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
        total_max += u.max_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
19539
76128a1ad901 8020530: Non heap memory size calculated incorrectly
poonam
parents: 19142
diff changeset
   764
  // if any one of the memory pool has undefined init_size or max_size,
76128a1ad901 8020530: Non heap memory size calculated incorrectly
poonam
parents: 19142
diff changeset
   765
  // set it to -1
76128a1ad901 8020530: Non heap memory size calculated incorrectly
poonam
parents: 19142
diff changeset
   766
  if (has_undefined_init_size) {
76128a1ad901 8020530: Non heap memory size calculated incorrectly
poonam
parents: 19142
diff changeset
   767
    total_init = (size_t)-1;
76128a1ad901 8020530: Non heap memory size calculated incorrectly
poonam
parents: 19142
diff changeset
   768
  }
76128a1ad901 8020530: Non heap memory size calculated incorrectly
poonam
parents: 19142
diff changeset
   769
  if (has_undefined_max_size) {
76128a1ad901 8020530: Non heap memory size calculated incorrectly
poonam
parents: 19142
diff changeset
   770
    total_max = (size_t)-1;
76128a1ad901 8020530: Non heap memory size calculated incorrectly
poonam
parents: 19142
diff changeset
   771
  }
76128a1ad901 8020530: Non heap memory size calculated incorrectly
poonam
parents: 19142
diff changeset
   772
4434
4b41e5b42f81 6887571: Increase default heap config sizes
phh
parents: 2105
diff changeset
   773
  MemoryUsage usage((heap ? InitialHeapSize : total_init),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
                    total_used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
                    total_committed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
                    (heap ? Universe::heap()->max_capacity() : total_max));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  Handle obj = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  return JNIHandles::make_local(env, obj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
// Returns the boolean value of a given attribute.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
JVM_LEAF(jboolean, jmm_GetBoolAttribute(JNIEnv *env, jmmBoolAttribute att))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  switch (att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  case JMM_VERBOSE_GC:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    return MemoryService::get_verbose();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
  case JMM_VERBOSE_CLASS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
    return ClassLoadingService::get_verbose();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  case JMM_THREAD_CONTENTION_MONITORING:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    return ThreadService::is_thread_monitoring_contention();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  case JMM_THREAD_CPU_TIME:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
    return ThreadService::is_thread_cpu_time_enabled();
7724
a92d706dbdd5 7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents: 7397
diff changeset
   793
  case JMM_THREAD_ALLOCATED_MEMORY:
a92d706dbdd5 7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents: 7397
diff changeset
   794
    return ThreadService::is_thread_allocated_memory_enabled();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
    assert(0, "Unrecognized attribute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
// Sets the given boolean attribute and returns the previous value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
JVM_ENTRY(jboolean, jmm_SetBoolAttribute(JNIEnv *env, jmmBoolAttribute att, jboolean flag))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  switch (att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  case JMM_VERBOSE_GC:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    return MemoryService::set_verbose(flag != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  case JMM_VERBOSE_CLASS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
    return ClassLoadingService::set_verbose(flag != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  case JMM_THREAD_CONTENTION_MONITORING:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    return ThreadService::set_thread_monitoring_contention(flag != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  case JMM_THREAD_CPU_TIME:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
    return ThreadService::set_thread_cpu_time_enabled(flag != 0);
7724
a92d706dbdd5 7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents: 7397
diff changeset
   812
  case JMM_THREAD_ALLOCATED_MEMORY:
a92d706dbdd5 7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents: 7397
diff changeset
   813
    return ThreadService::set_thread_allocated_memory_enabled(flag != 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    assert(0, "Unrecognized attribute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
static jlong get_gc_attribute(GCMemoryManager* mgr, jmmLongAttribute att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  switch (att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  case JMM_GC_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    return mgr->gc_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
  case JMM_GC_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    return mgr->gc_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  case JMM_GC_EXT_ATTRIBUTE_INFO_SIZE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    // current implementation only has 1 ext attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    assert(0, "Unrecognized GC attribute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
class VmThreadCountClosure: public ThreadClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
  int _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  VmThreadCountClosure() : _count(0) {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  void do_thread(Thread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  int count() { return _count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
void VmThreadCountClosure::do_thread(Thread* thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  // exclude externally visible JavaThreads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  _count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
static jint get_vm_thread_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  VmThreadCountClosure vmtcc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
    MutexLockerEx ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
    Threads::threads_do(&vmtcc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  return vmtcc.count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
static jint get_num_flags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  // last flag entry is always NULL, so subtract 1
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   869
  int nFlags = (int) Flag::numFlags - 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  for (int i = 0; i < nFlags; i++) {
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   872
    Flag* flag = &Flag::flags[i];
1382
fa3de4068282 6618726: Introduce -XX:+UnlockExperimentalVMOptions flag
ysr
parents: 1
diff changeset
   873
    // Exclude the locked (diagnostic, experimental) flags
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
    if (flag->is_unlocked() || flag->is_unlocker()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
      count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  return count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
static jlong get_long_attribute(jmmLongAttribute att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  switch (att) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  case JMM_CLASS_LOADED_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
    return ClassLoadingService::loaded_class_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  case JMM_CLASS_UNLOADED_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
    return ClassLoadingService::unloaded_class_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  case JMM_THREAD_TOTAL_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
    return ThreadService::get_total_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  case JMM_THREAD_LIVE_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
    return ThreadService::get_live_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  case JMM_THREAD_PEAK_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
    return ThreadService::get_peak_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
  case JMM_THREAD_DAEMON_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
    return ThreadService::get_daemon_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  case JMM_JVM_INIT_DONE_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    return Management::vm_init_done_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
21185
9d53434b1ef5 8027294: Prepare hotspot for non TOD based uptime counter
jbachorik
parents: 20288
diff changeset
   904
  case JMM_JVM_UPTIME_MS:
9d53434b1ef5 8027294: Prepare hotspot for non TOD based uptime counter
jbachorik
parents: 20288
diff changeset
   905
    return Management::ticks_to_ms(os::elapsed_counter());
9d53434b1ef5 8027294: Prepare hotspot for non TOD based uptime counter
jbachorik
parents: 20288
diff changeset
   906
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  case JMM_COMPILE_TOTAL_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
    return Management::ticks_to_ms(CompileBroker::total_compilation_ticks());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  case JMM_OS_PROCESS_ID:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
    return os::current_process_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  // Hotspot-specific counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  case JMM_CLASS_LOADED_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
    return ClassLoadingService::loaded_class_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  case JMM_CLASS_UNLOADED_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
    return ClassLoadingService::unloaded_class_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  case JMM_SHARED_CLASS_LOADED_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
    return ClassLoadingService::loaded_shared_class_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  case JMM_SHARED_CLASS_UNLOADED_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
    return ClassLoadingService::unloaded_shared_class_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  case JMM_SHARED_CLASS_LOADED_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
    return ClassLoadingService::loaded_shared_class_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  case JMM_SHARED_CLASS_UNLOADED_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
    return ClassLoadingService::unloaded_shared_class_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
  case JMM_TOTAL_CLASSLOAD_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
    return ClassLoader::classloader_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  case JMM_VM_GLOBAL_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
    return get_num_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
  case JMM_SAFEPOINT_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
    return RuntimeService::safepoint_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  case JMM_TOTAL_SAFEPOINTSYNC_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
    return RuntimeService::safepoint_sync_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
  case JMM_TOTAL_STOPPED_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
    return RuntimeService::safepoint_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  case JMM_TOTAL_APP_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
    return RuntimeService::application_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  case JMM_VM_THREAD_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
    return get_vm_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
  case JMM_CLASS_INIT_TOTAL_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
    return ClassLoader::class_init_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  case JMM_CLASS_INIT_TOTAL_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    return ClassLoader::class_init_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  case JMM_CLASS_VERIFY_TOTAL_TIME_MS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    return ClassLoader::class_verify_time_ms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  case JMM_METHOD_DATA_SIZE_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    return ClassLoadingService::class_method_data_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  case JMM_OS_MEM_TOTAL_PHYSICAL_BYTES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
    return os::physical_memory();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
// Returns the long value of a given attribute.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
JVM_ENTRY(jlong, jmm_GetLongAttribute(JNIEnv *env, jobject obj, jmmLongAttribute att))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
    return get_long_attribute(att);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
    GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_(0L));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
    if (mgr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
      return get_gc_attribute(mgr, att);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
// Gets the value of all attributes specified in the given array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
// and sets the value in the result array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
// Returns the number of attributes found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
JVM_ENTRY(jint, jmm_GetLongAttributes(JNIEnv *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
                                      jobject obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
                                      jmmLongAttribute* atts,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
                                      jint count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
                                      jlong* result))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  int num_atts = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    for (int i = 0; i < count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
      result[i] = get_long_attribute(atts[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
      if (result[i] != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
        num_atts++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    for (int i = 0; i < count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
      result[i] = get_gc_attribute(mgr, atts[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
      if (result[i] != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
        num_atts++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  return num_atts;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
// Helper function to do thread dump for a specific list of threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
static void do_thread_dump(ThreadDumpResult* dump_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
                           typeArrayHandle ids_ah,  // array of thread ID (long[])
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
                           int num_threads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
                           int max_depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
                           bool with_locked_monitors,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
                           bool with_locked_synchronizers,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
                           TRAPS) {
30232
dc351997b749 8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents: 29083
diff changeset
  1025
  // no need to actually perform thread dump if no TIDs are specified
dc351997b749 8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents: 29083
diff changeset
  1026
  if (num_threads == 0) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  // First get an array of threadObj handles.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  // A JavaThread may terminate before we get the stack trace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
  GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1031
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1033
    // Need this ThreadsListHandle for converting Java thread IDs into
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1034
    // threadObj handles; dump_result->set_t_list() is called in the
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1035
    // VM op below so we can't use it yet.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1036
    ThreadsListHandle tlh;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
    for (int i = 0; i < num_threads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
      jlong tid = ids_ah->long_at(i);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1039
      JavaThread* jt = tlh.list()->find_JavaThread_from_java_tid(tid);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
      oop thread_obj = (jt != NULL ? jt->threadObj() : (oop)NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
      instanceHandle threadObj_h(THREAD, (instanceOop) thread_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
      thread_handle_array->append(threadObj_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
  // Obtain thread dumps and thread snapshot information
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
  VM_ThreadDump op(dump_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
                   thread_handle_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
                   num_threads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
                   max_depth, /* stack depth */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
                   with_locked_monitors,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
                   with_locked_synchronizers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
// Gets an array of ThreadInfo objects. Each element is the ThreadInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
// for the thread ID specified in the corresponding entry in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
// the given array of thread IDs; or NULL if the thread does not exist
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
// or has terminated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
//   ids       - array of thread IDs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
//   maxDepth  - the maximum depth of stack traces to be dumped:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
//               maxDepth == -1 requests to dump entire stack trace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
//               maxDepth == 0  requests no stack trace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
//   infoArray - array of ThreadInfo objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
//
7724
a92d706dbdd5 7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents: 7397
diff changeset
  1068
// QQQ - Why does this method return a value instead of void?
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
JVM_ENTRY(jint, jmm_GetThreadInfo(JNIEnv *env, jlongArray ids, jint maxDepth, jobjectArray infoArray))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
  // Check if threads is null
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
  if (ids == NULL || infoArray == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    THROW_(vmSymbols::java_lang_NullPointerException(), -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
  if (maxDepth < -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
               "Invalid maxDepth", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
  typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  typeArrayHandle ids_ah(THREAD, ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  oop infoArray_obj = JNIHandles::resolve_non_null(infoArray);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  objArrayOop oa = objArrayOop(infoArray_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  objArrayHandle infoArray_h(THREAD, oa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
  // validate the thread id array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  validate_thread_id_array(ids_ah, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
  // validate the ThreadInfo[] parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  validate_thread_info_array(infoArray_h, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  // infoArray must be of the same length as the given array of thread IDs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  int num_threads = ids_ah->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  if (num_threads != infoArray_h->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
               "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
  1099
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
25057
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 24424
diff changeset
  1101
  // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 24424
diff changeset
  1102
  java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  // Must use ThreadDumpResult to store the ThreadSnapshot.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
  // GC may occur after the thread snapshots are taken but before
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
  // this function returns. The threadObj and other oops kept
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  // in the ThreadSnapshot are marked and adjusted during GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
  ThreadDumpResult dump_result(num_threads);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
  if (maxDepth == 0) {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1111
    // No stack trace to dump so we do not need to stop the world.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1112
    // Since we never do the VM op here we must set the threads list.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1113
    dump_result.set_t_list();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1114
    for (int i = 0; i < num_threads; i++) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1115
      jlong tid = ids_ah->long_at(i);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1116
      JavaThread* jt = dump_result.t_list()->find_JavaThread_from_java_tid(tid);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1117
      ThreadSnapshot* ts;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1118
      if (jt == NULL) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1119
        // if the thread does not exist or now it is terminated,
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1120
        // create dummy snapshot
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1121
        ts = new ThreadSnapshot();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1122
      } else {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1123
        ts = new ThreadSnapshot(dump_result.t_list(), jt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
      }
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1125
      dump_result.add_thread_snapshot(ts);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
    // obtain thread dump with the specific list of threads with stack trace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
    do_thread_dump(&dump_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
                   ids_ah,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
                   num_threads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
                   maxDepth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
                   false, /* no locked monitor */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
                   false, /* no locked synchronizers */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
                   CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
  int num_snapshots = dump_result.num_snapshots();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
  assert(num_snapshots == num_threads, "Must match the number of thread snapshots");
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1140
  assert(num_snapshots == 0 || dump_result.t_list_has_been_set(), "ThreadsList must have been set if we have a snapshot");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; index++, ts = ts->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
    // For each thread, create an java/lang/management/ThreadInfo object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
    // and fill with the thread information
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
    if (ts->threadObj() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
     // if the thread does not exist or now it is terminated, set threadinfo to NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
      infoArray_h->obj_at_put(index, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
    // Create java.lang.management.ThreadInfo object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
    instanceOop info_obj = Management::create_thread_info_instance(ts, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
    infoArray_h->obj_at_put(index, info_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
// Dump thread info for the specified threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
// It returns an array of ThreadInfo objects. Each element is the ThreadInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
// for the thread ID specified in the corresponding entry in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
// the given array of thread IDs; or NULL if the thread does not exist
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
// or has terminated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
// Input parameter:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
//    ids - array of thread IDs; NULL indicates all live threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
//    locked_monitors - if true, dump locked object monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
//    locked_synchronizers - if true, dump locked JSR-166 synchronizers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
//
47592
68d46cb9be45 8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents: 47216
diff changeset
  1170
JVM_ENTRY(jobjectArray, jmm_DumpThreads(JNIEnv *env, jlongArray thread_ids, jboolean locked_monitors,
68d46cb9be45 8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents: 47216
diff changeset
  1171
                                        jboolean locked_synchronizers, jint maxDepth))
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
25057
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 24424
diff changeset
  1174
  // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 24424
diff changeset
  1175
  java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
  typeArrayOop ta = typeArrayOop(JNIHandles::resolve(thread_ids));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
  int num_threads = (ta != NULL ? ta->length() : 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  typeArrayHandle ids_ah(THREAD, ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
  ThreadDumpResult dump_result(num_threads);  // can safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
  if (ids_ah() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
    // validate the thread id array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
    validate_thread_id_array(ids_ah, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
    // obtain thread dump of a specific list of threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
    do_thread_dump(&dump_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
                   ids_ah,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
                   num_threads,
47592
68d46cb9be45 8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents: 47216
diff changeset
  1192
                   maxDepth, /* stack depth */
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
                   (locked_monitors ? true : false),      /* with locked monitors */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
                   (locked_synchronizers ? true : false), /* with locked synchronizers */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
                   CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
    // obtain thread dump of all threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    VM_ThreadDump op(&dump_result,
47592
68d46cb9be45 8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents: 47216
diff changeset
  1199
                     maxDepth, /* stack depth */
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
                     (locked_monitors ? true : false),     /* with locked monitors */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
                     (locked_synchronizers ? true : false) /* with locked synchronizers */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
    VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
  int num_snapshots = dump_result.num_snapshots();
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1206
  assert(num_snapshots == 0 || dump_result.t_list_has_been_set(), "ThreadsList must have been set if we have a snapshot");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
  // create the result ThreadInfo[] object
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
  1209
  InstanceKlass* ik = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
  1210
  objArrayOop r = oopFactory::new_objArray(ik, num_snapshots, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
  objArrayHandle result_h(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
  for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; ts = ts->next(), index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
    if (ts->threadObj() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
     // if the thread does not exist or now it is terminated, set threadinfo to NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
      result_h->obj_at_put(index, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
    ThreadStackTrace* stacktrace = ts->get_stack_trace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    assert(stacktrace != NULL, "Must have a stack trace dumped");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    // Create Object[] filled with locked monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    // Create int[] filled with the stack depth where a monitor was locked
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
    int num_frames = stacktrace->get_stack_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    int num_locked_monitors = stacktrace->num_jni_locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
    // Count the total number of locked monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
    for (int i = 0; i < num_frames; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
      StackFrameInfo* frame = stacktrace->stack_frame_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
      num_locked_monitors += frame->num_locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
    objArrayHandle monitors_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    typeArrayHandle depths_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    objArrayHandle synchronizers_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    if (locked_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
      // Constructs Object[] and int[] to contain the object monitor and the stack depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
      // where the thread locked it
8337
ccb1f3acfe94 7020992: jmm_DumpThreads should not allocate system object arrays outside the perm gen
stefank
parents: 8301
diff changeset
  1242
      objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_monitors, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
      objArrayHandle mh(THREAD, array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
      monitors_array = mh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
      typeArrayOop tarray = oopFactory::new_typeArray(T_INT, num_locked_monitors, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
      typeArrayHandle dh(THREAD, tarray);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
      depths_array = dh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
      int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
      int j = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
      for (int depth = 0; depth < num_frames; depth++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
        StackFrameInfo* frame = stacktrace->stack_frame_at(depth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
        int len = frame->num_locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
        GrowableArray<oop>* locked_monitors = frame->locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
        for (j = 0; j < len; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
          oop monitor = locked_monitors->at(j);
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 27466
diff changeset
  1258
          assert(monitor != NULL, "must be a Java object");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
          monitors_array->obj_at_put(count, monitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
          depths_array->int_at_put(count, depth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
          count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
      GrowableArray<oop>* jni_locked_monitors = stacktrace->jni_locked_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
      for (j = 0; j < jni_locked_monitors->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
        oop object = jni_locked_monitors->at(j);
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 27466
diff changeset
  1268
        assert(object != NULL, "must be a Java object");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
        monitors_array->obj_at_put(count, object);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
        // Monitor locked via JNI MonitorEnter call doesn't have stack depth info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
        depths_array->int_at_put(count, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
        count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
      assert(count == num_locked_monitors, "number of locked monitors doesn't match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
    if (locked_synchronizers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
      // Create Object[] filled with locked JSR-166 synchronizers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
      assert(ts->threadObj() != NULL, "Must be a valid JavaThread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
      ThreadConcurrentLocks* tcl = ts->get_concurrent_locks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
      GrowableArray<instanceOop>* locks = (tcl != NULL ? tcl->owned_locks() : NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
      int num_locked_synchronizers = (locks != NULL ? locks->length() : 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
8337
ccb1f3acfe94 7020992: jmm_DumpThreads should not allocate system object arrays outside the perm gen
stefank
parents: 8301
diff changeset
  1284
      objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_synchronizers, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
      objArrayHandle sh(THREAD, array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
      synchronizers_array = sh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
      for (int k = 0; k < num_locked_synchronizers; k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
        synchronizers_array->obj_at_put(k, locks->at(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
    // Create java.lang.management.ThreadInfo object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
    instanceOop info_obj = Management::create_thread_info_instance(ts,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
                                                                   monitors_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
                                                                   depths_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
                                                                   synchronizers_array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
                                                                   CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
    result_h->obj_at_put(index, info_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
  return (jobjectArray) JNIHandles::make_local(env, result_h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
// Reset statistic.  Return true if the requested statistic is reset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
// Otherwise, return false.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
//  obj  - specify which instance the statistic associated with to be reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
//         For PEAK_POOL_USAGE stat, obj is required to be a memory pool object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
//         For THREAD_CONTENTION_COUNT and TIME stat, obj is required to be a thread ID.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
//  type - the type of statistic to be reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
JVM_ENTRY(jboolean, jmm_ResetStatistic(JNIEnv *env, jvalue obj, jmmStatisticType type))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
    case JMM_STAT_PEAK_THREAD_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
      ThreadService::reset_peak_thread_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
    case JMM_STAT_THREAD_CONTENTION_COUNT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
    case JMM_STAT_THREAD_CONTENTION_TIME: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
      jlong tid = obj.j;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
      if (tid < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
        THROW_(vmSymbols::java_lang_IllegalArgumentException(), JNI_FALSE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
      // Look for the JavaThread of this given tid
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1330
      JavaThreadIteratorWithHandle jtiwh;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
      if (tid == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
        // reset contention statistics for all threads if tid == 0
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1333
        for (; JavaThread *java_thread = jtiwh.next(); ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
          if (type == JMM_STAT_THREAD_CONTENTION_COUNT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
            ThreadService::reset_contention_count_stat(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
            ThreadService::reset_contention_time_stat(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
        // reset contention statistics for a given thread
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1342
        JavaThread* java_thread = jtiwh.list()->find_JavaThread_from_java_tid(tid);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
        if (java_thread == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
        if (type == JMM_STAT_THREAD_CONTENTION_COUNT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
          ThreadService::reset_contention_count_stat(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
          ThreadService::reset_contention_time_stat(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
    case JMM_STAT_PEAK_POOL_USAGE: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
      jobject o = obj.l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
      if (o == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
        THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
      oop pool_obj = JNIHandles::resolve(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
      assert(pool_obj->is_instance(), "Should be an instanceOop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
      instanceHandle ph(THREAD, (instanceOop) pool_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
      MemoryPool* pool = MemoryService::get_memory_pool(ph);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
      if (pool != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
        pool->reset_peak_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
    case JMM_STAT_GC_STAT: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
      jobject o = obj.l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
      if (o == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
        THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
      GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(o, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
      if (mgr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
        mgr->reset_gc_stat();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
      assert(0, "Unknown Statistic Type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
// Returns the fast estimate of CPU time consumed by
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
// a given thread (in nanoseconds).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
// If thread_id == 0, return CPU time for the current thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
JVM_ENTRY(jlong, jmm_GetThreadCpuTime(JNIEnv *env, jlong thread_id))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
  if (!os::is_thread_cpu_time_supported()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
  if (thread_id < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
               "Invalid thread ID", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
  JavaThread* java_thread = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
  if (thread_id == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
    // current thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
    return os::current_thread_cpu_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
  } else {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1410
    ThreadsListHandle tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1411
    java_thread = tlh.list()->find_JavaThread_from_java_tid(thread_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
    if (java_thread != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
      return os::thread_cpu_time((Thread*) java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
// Returns a String array of all VM global flag names
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
JVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
  // last flag entry is always NULL, so subtract 1
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1422
  int nFlags = (int) Flag::numFlags - 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
  // allocate a temp array
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1424
  objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
                                           nFlags, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
  objArrayHandle flags_ah(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
  int num_entries = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
  for (int i = 0; i < nFlags; i++) {
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1429
    Flag* flag = &Flag::flags[i];
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1430
    // Exclude notproduct and develop flags in product builds.
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1431
    if (flag->is_constant_in_binary()) {
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1432
      continue;
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1433
    }
1382
fa3de4068282 6618726: Introduce -XX:+UnlockExperimentalVMOptions flag
ysr
parents: 1
diff changeset
  1434
    // Exclude the locked (experimental, diagnostic) flags
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
    if (flag->is_unlocked() || flag->is_unlocker()) {
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1436
      Handle s = java_lang_String::create_from_str(flag->_name, CHECK_0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
      flags_ah->obj_at_put(num_entries, s());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
      num_entries++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
  if (num_entries < nFlags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
    // Return array of right length
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1444
    objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
    for(int i = 0; i < num_entries; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
      res->obj_at_put(i, flags_ah->obj_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
    return (jobjectArray)JNIHandles::make_local(env, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
  return (jobjectArray)JNIHandles::make_local(env, flags_ah());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1454
// 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
  1455
// 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
  1456
// will be incomplete and invalid.
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1457
bool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, Flag *flag, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
  Handle flag_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
  if (name() == NULL) {
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1460
    flag_name = java_lang_String::create_from_str(flag->_name, CHECK_false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
    flag_name = name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
  global->name = (jstring)JNIHandles::make_local(env, flag_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
  if (flag->is_bool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
    global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
    global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 30247
diff changeset
  1469
  } else if (flag->is_int()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 30247
diff changeset
  1470
    global->value.j = (jlong)flag->get_int();
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 30247
diff changeset
  1471
    global->type = JMM_VMGLOBAL_TYPE_JLONG;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 30247
diff changeset
  1472
  } else if (flag->is_uint()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 30247
diff changeset
  1473
    global->value.j = (jlong)flag->get_uint();
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 30247
diff changeset
  1474
    global->type = JMM_VMGLOBAL_TYPE_JLONG;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
  } else if (flag->is_intx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
    global->value.j = (jlong)flag->get_intx();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
    global->type = JMM_VMGLOBAL_TYPE_JLONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
  } else if (flag->is_uintx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
    global->value.j = (jlong)flag->get_uintx();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
    global->type = JMM_VMGLOBAL_TYPE_JLONG;
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1481
  } else if (flag->is_uint64_t()) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1482
    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
  1483
    global->type = JMM_VMGLOBAL_TYPE_JLONG;
27466
36c9a91eb418 8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents: 26834
diff changeset
  1484
  } else if (flag->is_double()) {
36c9a91eb418 8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents: 26834
diff changeset
  1485
    global->value.d = (jdouble)flag->get_double();
36c9a91eb418 8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents: 26834
diff changeset
  1486
    global->type = JMM_VMGLOBAL_TYPE_JDOUBLE;
25959
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 25057
diff changeset
  1487
  } else if (flag->is_size_t()) {
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 25057
diff changeset
  1488
    global->value.j = (jlong)flag->get_size_t();
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 25057
diff changeset
  1489
    global->type = JMM_VMGLOBAL_TYPE_JLONG;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
  } else if (flag->is_ccstr()) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1491
    Handle str = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
    global->value.l = (jobject)JNIHandles::make_local(env, str());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
    global->type = JMM_VMGLOBAL_TYPE_JSTRING;
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1494
  } else {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1495
    global->type = JMM_VMGLOBAL_TYPE_UNKNOWN;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1496
    return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
  global->writeable = flag->is_writeable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
  global->external = flag->is_external();
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1501
  switch (flag->get_origin()) {
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1502
    case Flag::DEFAULT:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
      global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
      break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1505
    case Flag::COMMAND_LINE:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
      global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
      break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1508
    case Flag::ENVIRON_VAR:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
      global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
      break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1511
    case Flag::CONFIG_FILE:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
      global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
      break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1514
    case Flag::MANAGEMENT:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
      global->origin = JMM_VMGLOBAL_ORIGIN_MANAGEMENT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
      break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1517
    case Flag::ERGONOMIC:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
      global->origin = JMM_VMGLOBAL_ORIGIN_ERGONOMIC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
      break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1520
    case Flag::ATTACH_ON_DEMAND:
22200
05db8f8522fe 8031305: (hotspot) com.sun.management.VMOption is missing the ATTACH_ON_DEMAND origin
sla
parents: 22194
diff changeset
  1521
      global->origin = JMM_VMGLOBAL_ORIGIN_ATTACH_ON_DEMAND;
05db8f8522fe 8031305: (hotspot) com.sun.management.VMOption is missing the ATTACH_ON_DEMAND origin
sla
parents: 22194
diff changeset
  1522
      break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
      global->origin = JMM_VMGLOBAL_ORIGIN_OTHER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
  }
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1526
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1527
  return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
// Fill globals array of count length with jmmVMGlobal entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
// specified by names. If names == NULL, fill globals array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
// with all Flags. Return value is number of entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
// created in globals.
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1534
// If a Flag with a given name in an array element does not
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
// exist, globals[i].name will be set to NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
JVM_ENTRY(jint, jmm_GetVMGlobals(JNIEnv *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
                                 jobjectArray names,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
                                 jmmVMGlobal *globals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
                                 jint count))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
  if (globals == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
    THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
  if (names != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
    // return the requested globals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
    objArrayOop ta = objArrayOop(JNIHandles::resolve_non_null(names));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
    objArrayHandle names_ah(THREAD, ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
    // Make sure we have a String array
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13870
diff changeset
  1553
    Klass* element_klass = ObjArrayKlass::cast(names_ah->klass())->element_klass();
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1554
    if (element_klass != SystemDictionary::String_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
      THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
                 "Array element type is not String class", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
    int names_length = names_ah->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
    int num_entries = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
    for (int i = 0; i < names_length && i < count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
      oop s = names_ah->obj_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
      if (s == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
        THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
      Handle sh(THREAD, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
      char* str = java_lang_String::as_utf8_string(s);
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1569
      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
  1570
      if (flag != NULL &&
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1571
          add_global_entry(env, sh, &globals[i], flag, THREAD)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
        num_entries++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
        globals[i].name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
    return num_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
    // return all globals if names == NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
    // last flag entry is always NULL, so subtract 1
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1582
    int nFlags = (int) Flag::numFlags - 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
    Handle null_h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
    int num_entries = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
    for (int i = 0; i < nFlags && num_entries < count;  i++) {
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1586
      Flag* flag = &Flag::flags[i];
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1587
      // Exclude notproduct and develop flags in product builds.
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1588
      if (flag->is_constant_in_binary()) {
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1589
        continue;
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 19539
diff changeset
  1590
      }
1382
fa3de4068282 6618726: Introduce -XX:+UnlockExperimentalVMOptions flag
ysr
parents: 1
diff changeset
  1591
      // Exclude the locked (diagnostic, experimental) flags
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1592
      if ((flag->is_unlocked() || flag->is_unlocker()) &&
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 4434
diff changeset
  1593
          add_global_entry(env, null_h, &globals[num_entries], flag, THREAD)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
        num_entries++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
    return num_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
JVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
  oop fn = JNIHandles::resolve_external_guard(flag_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
  if (fn == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
              "The flag name cannot be null.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
  char* name = java_lang_String::as_utf8_string(fn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
38254
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents: 36508
diff changeset
  1611
  FormatBuffer<80> error_msg("%s", "");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1612
  int succeed = WriteableFlags::set_flag(name, new_value, Flag::MANAGEMENT, error_msg);
22555
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22200
diff changeset
  1613
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1614
  if (succeed != Flag::SUCCESS) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1615
    if (succeed == Flag::MISSING_VALUE) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents: 27880
diff changeset
  1616
      // missing value causes NPE to be thrown
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
      THROW(vmSymbols::java_lang_NullPointerException());
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents: 27880
diff changeset
  1618
    } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents: 27880
diff changeset
  1619
      // all the other errors are reported as IAE with the appropriate error message
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents: 27880
diff changeset
  1620
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
38254
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents: 36508
diff changeset
  1621
                error_msg.buffer());
22194
e4bef4b8cdb4 8029070: memory leak in jmm_SetVMGlobal
iignatyev
parents: 21185
diff changeset
  1622
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
  }
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
  1624
  assert(succeed == Flag::SUCCESS, "Setting flag should succeed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
class ThreadTimesClosure: public ThreadClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
 private:
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1629
  objArrayHandle _names_strings;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1630
  char **_names_chars;
19142
88fa01905ae9 8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents: 18444
diff changeset
  1631
  typeArrayHandle _times;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
  int _names_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
  int _times_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
  int _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
 public:
19142
88fa01905ae9 8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents: 18444
diff changeset
  1637
  ThreadTimesClosure(objArrayHandle names, typeArrayHandle times);
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1638
  ~ThreadTimesClosure();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
  virtual void do_thread(Thread* thread);
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1640
  void do_unlocked();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
  int count() { return _count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1644
ThreadTimesClosure::ThreadTimesClosure(objArrayHandle names,
19142
88fa01905ae9 8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents: 18444
diff changeset
  1645
                                       typeArrayHandle times) {
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1646
  assert(names() != NULL, "names was NULL");
19142
88fa01905ae9 8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents: 18444
diff changeset
  1647
  assert(times() != NULL, "times was NULL");
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1648
  _names_strings = names;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
  _names_len = names->length();
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1650
  _names_chars = NEW_C_HEAP_ARRAY(char*, _names_len, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  _times = times;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
  _times_len = times->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
  _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1656
//
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1657
// Called with Threads_lock held
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1658
//
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
void ThreadTimesClosure::do_thread(Thread* thread) {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  1660
  assert(Threads_lock->owned_by_self(), "Must hold Threads_lock");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
  assert(thread != NULL, "thread was NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
  // exclude externally visible JavaThreads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
  if (_count >= _names_len || _count >= _times_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
    // skip if the result array is not big enough
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
  EXCEPTION_MARK;
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1674
  ResourceMark rm(THREAD); // thread->name() uses ResourceArea
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
  assert(thread->name() != NULL, "All threads should have a name");
25949
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25057
diff changeset
  1677
  _names_chars[_count] = os::strdup(thread->name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
  _times->long_at_put(_count, os::is_thread_cpu_time_supported() ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
                        os::thread_cpu_time(thread) : -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
  _count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1683
// Called without Threads_lock, we can allocate String objects.
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1684
void ThreadTimesClosure::do_unlocked() {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1685
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1686
  EXCEPTION_MARK;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1687
  for (int i = 0; i < _count; i++) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1688
    Handle s = java_lang_String::create_from_str(_names_chars[i],  CHECK);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1689
    _names_strings->obj_at_put(i, s());
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1690
  }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1691
}
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1692
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1693
ThreadTimesClosure::~ThreadTimesClosure() {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1694
  for (int i = 0; i < _count; i++) {
25949
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25057
diff changeset
  1695
    os::free(_names_chars[i]);
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1696
  }
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 27471
diff changeset
  1697
  FREE_C_HEAP_ARRAY(char *, _names_chars);
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1698
}
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1699
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
// Fills names with VM internal thread names and times with the corresponding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
// CPU times.  If names or times is NULL, a NullPointerException is thrown.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
// If the element type of names is not String, an IllegalArgumentException is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
// thrown.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
// If an array is not large enough to hold all the entries, only the entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
// that fit will be returned.  Return value is the number of VM internal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
// threads entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
JVM_ENTRY(jint, jmm_GetInternalThreadTimes(JNIEnv *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
                                           jobjectArray names,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
                                           jlongArray times))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
  if (names == NULL || times == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
     THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
  objArrayOop na = objArrayOop(JNIHandles::resolve_non_null(names));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
  objArrayHandle names_ah(THREAD, na);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
  // Make sure we have a String array
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13870
diff changeset
  1717
  Klass* element_klass = ObjArrayKlass::cast(names_ah->klass())->element_klass();
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1718
  if (element_klass != SystemDictionary::String_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
               "Array element type is not String class", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
  typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(times));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
  typeArrayHandle times_ah(THREAD, ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
19142
88fa01905ae9 8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents: 18444
diff changeset
  1726
  ThreadTimesClosure ttc(names_ah, times_ah);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
    MutexLockerEx ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
    Threads::threads_do(&ttc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
  }
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents: 13728
diff changeset
  1731
  ttc.do_unlocked();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
  return ttc.count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
static Handle find_deadlocks(bool object_monitors_only, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
  VM_FindDeadlocks op(!object_monitors_only /* also check concurrent locks? */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
  DeadlockCycle* deadlocks = op.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
  if (deadlocks == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
    // no deadlock found and return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
    return Handle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
  int num_threads = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
  DeadlockCycle* cycle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
  for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    num_threads += cycle->num_threads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
  1753
  objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NH);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
  objArrayHandle threads_ah(THREAD, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
  for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
    GrowableArray<JavaThread*>* deadlock_threads = cycle->threads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
    int len = deadlock_threads->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
      threads_ah->obj_at_put(index, deadlock_threads->at(i)->threadObj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
      index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
  return threads_ah;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
// Finds cycles of threads that are deadlocked involved in object monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
// and JSR-166 synchronizers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
// Returns an array of Thread objects which are in deadlock, if any.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
// Otherwise, returns NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
// Input parameter:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
//    object_monitors_only - if true, only check object monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
JVM_ENTRY(jobjectArray, jmm_FindDeadlockedThreads(JNIEnv *env, jboolean object_monitors_only))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
  Handle result = find_deadlocks(object_monitors_only != 0, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  return (jobjectArray) JNIHandles::make_local(env, result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
// Finds cycles of threads that are deadlocked on monitor locks
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
// Returns an array of Thread objects which are in deadlock, if any.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
// Otherwise, returns NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
JVM_ENTRY(jobjectArray, jmm_FindMonitorDeadlockedThreads(JNIEnv *env))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
  Handle result = find_deadlocks(true, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
  return (jobjectArray) JNIHandles::make_local(env, result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
// Gets the information about GC extension attributes including
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
// the name of the attribute, its type, and a short description.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
//   mgr   - GC memory manager
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
//   info  - caller allocated array of jmmExtAttributeInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
//   count - number of elements of the info array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
// Returns the number of GC extension attributes filled in the info array; or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
// -1 if info is not big enough
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
JVM_ENTRY(jint, jmm_GetGCExtAttributeInfo(JNIEnv *env, jobject mgr, jmmExtAttributeInfo* info, jint count))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
  // All GC memory managers have 1 attribute (number of GC threads)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
  if (count == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
  if (info == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
   THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
  info[0].name = "GcThreadCount";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
  info[0].type = 'I';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
  info[0].description = "Number of GC threads";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
// verify the given array is an array of java/lang/management/MemoryUsage objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
// of a given length and return the objArrayOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
static objArrayOop get_memory_usage_objArray(jobjectArray array, int length, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
  if (array == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
    THROW_(vmSymbols::java_lang_NullPointerException(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
  objArrayOop oa = objArrayOop(JNIHandles::resolve_non_null(array));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
  objArrayHandle array_h(THREAD, oa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
  // array must be of the given length
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
  if (length != array_h->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
               "The length of the given MemoryUsage array does not match the number of memory pools.", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
  // check if the element of array is of type MemoryUsage class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
  1833
  Klass* usage_klass = Management::java_lang_management_MemoryUsage_klass(CHECK_0);
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13870
diff changeset
  1834
  Klass* element_klass = ObjArrayKlass::cast(array_h->klass())->element_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
  if (element_klass != usage_klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
               "The element type is not MemoryUsage class", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
  return array_h();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
// Gets the statistics of the last GC of a given GC memory manager.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
// Input parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
//   obj     - GarbageCollectorMXBean object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
//   gc_stat - caller allocated jmmGCStat where:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
//     a. before_gc_usage - array of MemoryUsage objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
//     b. after_gc_usage  - array of MemoryUsage objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
//     c. gc_ext_attributes_values_size is set to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
//        gc_ext_attribute_values array allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
//     d. gc_ext_attribute_values is a caller allocated array of jvalue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
// On return,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
//   gc_index == 0 indicates no GC statistics available
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
//   before_gc_usage and after_gc_usage - filled with per memory pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
//      before and after GC usage in the same order as the memory pools
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
//      returned by GetMemoryPools for a given GC memory manager.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
//   num_gc_ext_attributes indicates the number of elements in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
//      the gc_ext_attribute_values array is filled; or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
//      -1 if the gc_ext_attributes_values array is not big enough
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
JVM_ENTRY(void, jmm_GetLastGCStat(JNIEnv *env, jobject obj, jmmGCStat *gc_stat))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
  if (gc_stat->gc_ext_attribute_values_size > 0 && gc_stat->gc_ext_attribute_values == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
    THROW(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
  // Get the GCMemoryManager
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
  GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
  // Make a copy of the last GC statistics
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
  // GC may occur while constructing the last GC information
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
  int num_pools = MemoryService::num_memory_pools();
11591
854c0dff3844 7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents: 11441
diff changeset
  1876
  GCStatInfo stat(num_pools);
854c0dff3844 7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents: 11441
diff changeset
  1877
  if (mgr->get_last_gc_stat(&stat) == 0) {
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
  1878
    gc_stat->gc_index = 0;
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
  1879
    return;
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
  1880
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
11591
854c0dff3844 7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents: 11441
diff changeset
  1882
  gc_stat->gc_index = stat.gc_index();
854c0dff3844 7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents: 11441
diff changeset
  1883
  gc_stat->start_time = Management::ticks_to_ms(stat.start_time());
854c0dff3844 7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents: 11441
diff changeset
  1884
  gc_stat->end_time = Management::ticks_to_ms(stat.end_time());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
  // Current implementation does not have GC extension attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
  gc_stat->num_gc_ext_attributes = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
  // Fill the arrays of MemoryUsage objects with before and after GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
  // per pool memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
  objArrayOop bu = get_memory_usage_objArray(gc_stat->usage_before_gc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
                                             num_pools,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
                                             CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
  objArrayHandle usage_before_gc_ah(THREAD, bu);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
  objArrayOop au = get_memory_usage_objArray(gc_stat->usage_after_gc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
                                             num_pools,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
                                             CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
  objArrayHandle usage_after_gc_ah(THREAD, au);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
  for (int i = 0; i < num_pools; i++) {
11591
854c0dff3844 7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents: 11441
diff changeset
  1902
    Handle before_usage = MemoryService::create_MemoryUsage_obj(stat.before_gc_usage_for_pool(i), CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
    Handle after_usage;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
11591
854c0dff3844 7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents: 11441
diff changeset
  1905
    MemoryUsage u = stat.after_gc_usage_for_pool(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
    if (u.max_size() == 0 && u.used() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
      // If max size == 0, this pool is a survivor space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
      // Set max size = -1 since the pools will be swapped after GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
      MemoryUsage usage(u.init_size(), u.used(), u.committed(), (size_t)-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
      after_usage = MemoryService::create_MemoryUsage_obj(usage, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
    } else {
11591
854c0dff3844 7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents: 11441
diff changeset
  1912
      after_usage = MemoryService::create_MemoryUsage_obj(stat.after_gc_usage_for_pool(i), CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
    usage_before_gc_ah->obj_at_put(i, before_usage());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
    usage_after_gc_ah->obj_at_put(i, after_usage());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
  if (gc_stat->gc_ext_attribute_values_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
    // Current implementation only has 1 attribute (number of GC threads)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
    // The type is 'I'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
    gc_stat->gc_ext_attribute_values[0].i = mgr->num_gc_threads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
  1925
JVM_ENTRY(void, jmm_SetGCNotificationEnabled(JNIEnv *env, jobject obj, jboolean enabled))
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
  1926
  ResourceMark rm(THREAD);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
  1927
  // Get the GCMemoryManager
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
  1928
  GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
  1929
  mgr->set_notification_enabled(enabled?true:false);
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
  1930
JVM_END
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
  1931
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
// Dump heap - Returns 0 if succeeds.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
JVM_ENTRY(jint, jmm_DumpHeap0(JNIEnv *env, jstring outputfile, jboolean live))
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
  1934
#if INCLUDE_SERVICES
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
  oop on = JNIHandles::resolve_external_guard(outputfile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
  if (on == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
               "Output file name cannot be null.", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
  }
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42052
diff changeset
  1941
  Handle onhandle(THREAD, on);
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42052
diff changeset
  1942
  char* name = java_lang_String::as_platform_dependent_str(onhandle, CHECK_(-1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
  if (name == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
               "Output file name cannot be null.", -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
  HeapDumper dumper(live ? true : false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
  if (dumper.dump(name) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
    const char* errmsg = dumper.error_as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
    THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
  return 0;
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
  1953
#else  // INCLUDE_SERVICES
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
  return -1;
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
  1955
#endif // INCLUDE_SERVICES
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1958
JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env))
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1959
  ResourceMark rm(THREAD);
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  1960
  GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(DCmd_Source_MBean);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1961
  objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1962
          dcmd_list->length(), CHECK_NULL);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1963
  objArrayHandle cmd_array(THREAD, cmd_array_oop);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1964
  for (int i = 0; i < dcmd_list->length(); i++) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1965
    oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1966
    cmd_array->obj_at_put(i, cmd_name);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1967
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1968
  return (jobjectArray) JNIHandles::make_local(env, cmd_array());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1969
JVM_END
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1970
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1971
JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1972
          dcmdInfo* infoArray))
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1973
  if (cmds == NULL || infoArray == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1974
    THROW(vmSymbols::java_lang_NullPointerException());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1975
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1976
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1977
  ResourceMark rm(THREAD);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1978
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1979
  objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds));
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1980
  objArrayHandle cmds_ah(THREAD, ca);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1981
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1982
  // Make sure we have a String array
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13870
diff changeset
  1983
  Klass* element_klass = ObjArrayKlass::cast(cmds_ah->klass())->element_klass();
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1984
  if (element_klass != SystemDictionary::String_klass()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1985
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1986
               "Array element type is not String class");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1987
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1988
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  1989
  GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list(DCmd_Source_MBean);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1990
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1991
  int num_cmds = cmds_ah->length();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1992
  for (int i = 0; i < num_cmds; i++) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1993
    oop cmd = cmds_ah->obj_at(i);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1994
    if (cmd == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1995
        THROW_MSG(vmSymbols::java_lang_NullPointerException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1996
                "Command name cannot be null.");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1997
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1998
    char* cmd_name = java_lang_String::as_utf8_string(cmd);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  1999
    if (cmd_name == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2000
        THROW_MSG(vmSymbols::java_lang_NullPointerException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2001
                "Command name cannot be null.");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2002
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2003
    int pos = info_list->find((void*)cmd_name,DCmdInfo::by_name);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2004
    if (pos == -1) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2005
        THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2006
             "Unknown diagnostic command");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2007
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2008
    DCmdInfo* info = info_list->at(pos);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2009
    infoArray[i].name = info->name();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2010
    infoArray[i].description = info->description();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2011
    infoArray[i].impact = info->impact();
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2012
    JavaPermission p = info->permission();
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2013
    infoArray[i].permission_class = p._class;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2014
    infoArray[i].permission_name = p._name;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2015
    infoArray[i].permission_action = p._action;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2016
    infoArray[i].num_arguments = info->num_arguments();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2017
    infoArray[i].enabled = info->is_enabled();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2018
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2019
JVM_END
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2020
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2021
JVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2022
          jstring command, dcmdArgInfo* infoArray))
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2023
  ResourceMark rm(THREAD);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2024
  oop cmd = JNIHandles::resolve_external_guard(command);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2025
  if (cmd == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2026
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2027
              "Command line cannot be null.");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2028
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2029
  char* cmd_name = java_lang_String::as_utf8_string(cmd);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2030
  if (cmd_name == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2031
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2032
              "Command line content cannot be null.");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2033
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2034
  DCmd* dcmd = NULL;
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2035
  DCmdFactory*factory = DCmdFactory::factory(DCmd_Source_MBean, cmd_name,
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2036
                                             strlen(cmd_name));
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2037
  if (factory != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2038
    dcmd = factory->create_resource_instance(NULL);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2039
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2040
  if (dcmd == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2041
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2042
              "Unknown diagnostic command");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2043
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2044
  DCmdMark mark(dcmd);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2045
  GrowableArray<DCmdArgumentInfo*>* array = dcmd->argument_info_array();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2046
  if (array->length() == 0) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2047
    return;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2048
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2049
  for (int i = 0; i < array->length(); i++) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2050
    infoArray[i].name = array->at(i)->name();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2051
    infoArray[i].description = array->at(i)->description();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2052
    infoArray[i].type = array->at(i)->type();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2053
    infoArray[i].default_string = array->at(i)->default_string();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2054
    infoArray[i].mandatory = array->at(i)->is_mandatory();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2055
    infoArray[i].option = array->at(i)->is_option();
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2056
    infoArray[i].multiple = array->at(i)->is_multiple();
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2057
    infoArray[i].position = array->at(i)->position();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2058
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2059
  return;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2060
JVM_END
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2061
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2062
JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline))
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2063
  ResourceMark rm(THREAD);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2064
  oop cmd = JNIHandles::resolve_external_guard(commandline);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2065
  if (cmd == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2066
    THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2067
                   "Command line cannot be null.");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2068
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2069
  char* cmdline = java_lang_String::as_utf8_string(cmd);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2070
  if (cmdline == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2071
    THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2072
                   "Command line content cannot be null.");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2073
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2074
  bufferedStream output;
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2075
  DCmd::parse_and_execute(DCmd_Source_MBean, &output, cmdline, ' ', CHECK_NULL);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2076
  oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2077
  return (jstring) JNIHandles::make_local(env, result);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2078
JVM_END
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2079
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2080
JVM_ENTRY(void, jmm_SetDiagnosticFrameworkNotificationEnabled(JNIEnv *env, jboolean enabled))
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2081
  DCmdFactory::set_jmx_notification_enabled(enabled?true:false);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2082
JVM_END
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2083
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
jlong Management::ticks_to_ms(jlong ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
  assert(os::elapsed_frequency() > 0, "Must be non-zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
  return (jlong)(((double)ticks / (double)os::elapsed_frequency())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
                 * (double)1000.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
}
26834
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2089
#endif // INCLUDE_MANAGEMENT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
26834
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2091
// Gets an array containing the amount of memory allocated on the Java
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2092
// heap for a set of threads (in bytes).  Each element of the array is
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2093
// the amount of memory allocated for the thread ID specified in the
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2094
// corresponding entry in the given array of thread IDs; or -1 if the
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2095
// thread does not exist or has terminated.
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2096
JVM_ENTRY(void, jmm_GetThreadAllocatedMemory(JNIEnv *env, jlongArray ids,
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2097
                                             jlongArray sizeArray))
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2098
  // Check if threads is null
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2099
  if (ids == NULL || sizeArray == NULL) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2100
    THROW(vmSymbols::java_lang_NullPointerException());
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2101
  }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2102
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2103
  ResourceMark rm(THREAD);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2104
  typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids));
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2105
  typeArrayHandle ids_ah(THREAD, ta);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2106
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2107
  typeArrayOop sa = typeArrayOop(JNIHandles::resolve_non_null(sizeArray));
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2108
  typeArrayHandle sizeArray_h(THREAD, sa);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2109
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2110
  // validate the thread id array
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2111
  validate_thread_id_array(ids_ah, CHECK);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2112
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2113
  // sizeArray must be of the same length as the given array of thread IDs
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2114
  int num_threads = ids_ah->length();
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2115
  if (num_threads != sizeArray_h->length()) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2116
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2117
              "The length of the given long array does not match the length of "
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2118
              "the given array of thread IDs");
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2119
  }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2120
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  2121
  ThreadsListHandle tlh;
26834
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2122
  for (int i = 0; i < num_threads; i++) {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  2123
    JavaThread* java_thread = tlh.list()->find_JavaThread_from_java_tid(ids_ah->long_at(i));
26834
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2124
    if (java_thread != NULL) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2125
      sizeArray_h->long_at_put(i, java_thread->cooked_allocated_bytes());
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2126
    }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2127
  }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2128
JVM_END
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2129
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2130
// Returns the CPU time consumed by a given thread (in nanoseconds).
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2131
// If thread_id == 0, CPU time for the current thread is returned.
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2132
// If user_sys_cpu_time = true, user level and system CPU time of
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2133
// a given thread is returned; otherwise, only user level CPU time
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2134
// is returned.
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2135
JVM_ENTRY(jlong, jmm_GetThreadCpuTimeWithKind(JNIEnv *env, jlong thread_id, jboolean user_sys_cpu_time))
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2136
  if (!os::is_thread_cpu_time_supported()) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2137
    return -1;
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2138
  }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2139
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2140
  if (thread_id < 0) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2141
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2142
               "Invalid thread ID", -1);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2143
  }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2144
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2145
  JavaThread* java_thread = NULL;
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2146
  if (thread_id == 0) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2147
    // current thread
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2148
    return os::current_thread_cpu_time(user_sys_cpu_time != 0);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2149
  } else {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  2150
    ThreadsListHandle tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  2151
    java_thread = tlh.list()->find_JavaThread_from_java_tid(thread_id);
26834
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2152
    if (java_thread != NULL) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2153
      return os::thread_cpu_time((Thread*) java_thread, user_sys_cpu_time != 0);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2154
    }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2155
  }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2156
  return -1;
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2157
JVM_END
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2158
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2159
// Gets an array containing the CPU times consumed by a set of threads
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2160
// (in nanoseconds).  Each element of the array is the CPU time for the
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2161
// thread ID specified in the corresponding entry in the given array
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2162
// of thread IDs; or -1 if the thread does not exist or has terminated.
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2163
// If user_sys_cpu_time = true, the sum of user level and system CPU time
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2164
// for the given thread is returned; otherwise, only user level CPU time
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2165
// is returned.
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2166
JVM_ENTRY(void, jmm_GetThreadCpuTimesWithKind(JNIEnv *env, jlongArray ids,
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2167
                                              jlongArray timeArray,
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2168
                                              jboolean user_sys_cpu_time))
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2169
  // Check if threads is null
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2170
  if (ids == NULL || timeArray == NULL) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2171
    THROW(vmSymbols::java_lang_NullPointerException());
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2172
  }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2173
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2174
  ResourceMark rm(THREAD);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2175
  typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids));
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2176
  typeArrayHandle ids_ah(THREAD, ta);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2177
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2178
  typeArrayOop tia = typeArrayOop(JNIHandles::resolve_non_null(timeArray));
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2179
  typeArrayHandle timeArray_h(THREAD, tia);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2180
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2181
  // validate the thread id array
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2182
  validate_thread_id_array(ids_ah, CHECK);
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2183
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2184
  // timeArray must be of the same length as the given array of thread IDs
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2185
  int num_threads = ids_ah->length();
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2186
  if (num_threads != timeArray_h->length()) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2187
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2188
              "The length of the given long array does not match the length of "
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2189
              "the given array of thread IDs");
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2190
  }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2191
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  2192
  ThreadsListHandle tlh;
26834
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2193
  for (int i = 0; i < num_threads; i++) {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48090
diff changeset
  2194
    JavaThread* java_thread = tlh.list()->find_JavaThread_from_java_tid(ids_ah->long_at(i));
26834
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2195
    if (java_thread != NULL) {
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2196
      timeArray_h->long_at_put(i, os::thread_cpu_time((Thread*)java_thread,
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2197
                                                      user_sys_cpu_time != 0));
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2198
    }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2199
  }
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2200
JVM_END
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2201
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2202
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2203
41332d860d6a 8057535: add a thread extension class
sla
parents: 25960
diff changeset
  2204
#if INCLUDE_MANAGEMENT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2205
const struct jmmInterface_1_ jmm_interface = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2206
  NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2207
  NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2208
  jmm_GetVersion,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2209
  jmm_GetOptionalSupport,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2210
  jmm_GetThreadInfo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2211
  jmm_GetMemoryPools,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2212
  jmm_GetMemoryManagers,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2213
  jmm_GetMemoryPoolUsage,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2214
  jmm_GetPeakMemoryPoolUsage,
7724
a92d706dbdd5 7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents: 7397
diff changeset
  2215
  jmm_GetThreadAllocatedMemory,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2216
  jmm_GetMemoryUsage,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2217
  jmm_GetLongAttribute,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2218
  jmm_GetBoolAttribute,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2219
  jmm_SetBoolAttribute,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2220
  jmm_GetLongAttributes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2221
  jmm_FindMonitorDeadlockedThreads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2222
  jmm_GetThreadCpuTime,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2223
  jmm_GetVMGlobalNames,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2224
  jmm_GetVMGlobals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2225
  jmm_GetInternalThreadTimes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2226
  jmm_ResetStatistic,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2227
  jmm_SetPoolSensor,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2228
  jmm_SetPoolThreshold,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2229
  jmm_GetPoolCollectionUsage,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2230
  jmm_GetGCExtAttributeInfo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2231
  jmm_GetLastGCStat,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2232
  jmm_GetThreadCpuTimeWithKind,
7724
a92d706dbdd5 7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents: 7397
diff changeset
  2233
  jmm_GetThreadCpuTimesWithKind,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
  jmm_DumpHeap0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
  jmm_FindDeadlockedThreads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
  jmm_SetVMGlobal,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
  NULL,
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8337
diff changeset
  2238
  jmm_DumpThreads,
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2239
  jmm_SetGCNotificationEnabled,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2240
  jmm_GetDiagnosticCommands,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2241
  jmm_GetDiagnosticCommandInfo,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 9623
diff changeset
  2242
  jmm_GetDiagnosticCommandArgumentsInfo,
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2243
  jmm_ExecuteDiagnosticCommand,
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 17030
diff changeset
  2244
  jmm_SetDiagnosticFrameworkNotificationEnabled
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
};
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
  2246
#endif // INCLUDE_MANAGEMENT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
void* Management::get_jmm_interface(int version) {
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
  2249
#if INCLUDE_MANAGEMENT
47592
68d46cb9be45 8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents: 47216
diff changeset
  2250
  if (version == JMM_VERSION) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
    return (void*) &jmm_interface;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
  }
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13870
diff changeset
  2253
#endif // INCLUDE_MANAGEMENT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2254
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2255
}