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