Skip to content

Commit

Permalink
Merge pull request #6589 from pdbain-ibm/jcmd
Browse files Browse the repository at this point in the history
Move dump natives to java.base
  • Loading branch information
keithc-ca authored Aug 4, 2019
2 parents 6c48b2c + 6577a3c commit 4baf3d7
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 37 deletions.
2 changes: 1 addition & 1 deletion jcl/src/java.base/share/classes/module-info.java.extra
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exports com.ibm.sharedclasses.spi to openj9.sharedclasses, java.management, java
exports com.ibm.oti.vm to java.management, jdk.attach, jdk.management, openj9.jvm, openj9.sharedclasses;
exports com.ibm.oti.util to java.management, jdk.attach, jdk.jcmd, jdk.management, openj9.sharedclasses;
exports com.ibm.tools.attach.target to jdk.attach, jdk.jcmd, jdk.management;
exports openj9.management.internal to java.management;
exports openj9.management.internal to java.management, openj9.jvm;
exports openj9.tools.attach.diagnostics.base to jdk.attach, jdk.jcmd;
exports jdk.internal.org.objectweb.asm to openj9.dtfj, openj9.dtfjview;
// Following allows dtfj/dtfjview modules invoke module addReads & addExports programmatically via reflection APIs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

package openj9.management.internal;

/**
* This exception is thrown when the dump configuration cannot be
* updated through the methods on com.ibm.jvm.Dump because it is
* in use.
*/
public class DumpConfigurationUnavailableExceptionBase extends Exception {

private static final long serialVersionUID = -4576359433734094169L;
/**
* @param message description of error
*/
public DumpConfigurationUnavailableExceptionBase(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

package openj9.management.internal;

/**
* This exception is thrown when an invalid option is passed
* to methods on the com.ibm.jvm.Dump class.
*/
public class InvalidDumpOptionExceptionBase extends Exception {
private static final long serialVersionUID = 2015896235978447610L;

/**
* @param message description of error
*/
public InvalidDumpOptionExceptionBase(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.ibm.oti.vm.VM;
import com.ibm.tools.attach.target.IPC;

import openj9.management.internal.InvalidDumpOptionExceptionBase;
import openj9.management.internal.LockInfoBase;
import openj9.management.internal.ThreadInfoBase;

Expand Down Expand Up @@ -126,6 +127,7 @@ public static String makeJcmdCommand(String[] options, int skip) {
}

private static native String getHeapClassStatisticsImpl();
private static native String triggerDumpsImpl(String dumpOptions, String event) throws InvalidDumpOptionExceptionBase;

/**
* Run a diagnostic command and return the result in a properties file
Expand Down
69 changes: 45 additions & 24 deletions jcl/src/openj9.jvm/share/classes/com/ibm/jvm/Dump.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*[INCLUDE-IF Sidecar16]*/
package com.ibm.jvm;

/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2006, 2018 IBM Corp. and others
* Copyright (c) 2006, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -23,6 +21,11 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

package com.ibm.jvm;

import openj9.management.internal.DumpConfigurationUnavailableExceptionBase;
import openj9.management.internal.InvalidDumpOptionExceptionBase;

/**
* This class is used to trigger and configure the options used to produce different
* types of diagnostic dumps available from the OpenJ9 JVM.
Expand Down Expand Up @@ -99,6 +102,7 @@
* configuration.
*/
public class Dump {
@SuppressWarnings("nls")
private static final String SystemRequestPrefix = "z/OS".equalsIgnoreCase(System.getProperty("os.name")) ? "system:dsn=" : "system:file=";

/**
Expand Down Expand Up @@ -153,13 +157,10 @@ public static void SystemDump() {
/*
* Dump should not be instantiated.
*/
private Dump() {
private Dump() {
/* empty */
}

private static native int JavaDumpImpl();
private static native int HeapDumpImpl();
private static native int SystemDumpImpl();

/**
* Trigger a snap dump. The snap dump format is not human-readable
* and must be processed using the trace formatting tool supplied
Expand All @@ -177,13 +178,15 @@ public static void SnapDump() {
SnapDumpImpl();
}

private static native int SnapDumpImpl();

private static final DumpPermission DUMP_PERMISSION = new DumpPermission();
private static final ToolDumpPermission TOOL_DUMP_PERMISSION = new ToolDumpPermission();
private static final String LEGACY_DUMP_PERMISSION_PROPERTY = "com.ibm.jvm.enableLegacyDumpSecurity"; //$NON-NLS-1$

private static final class DumpOptionsLock {}
private static final class DumpOptionsLock {
DumpOptionsLock() {
super();
}
}
private static final DumpOptionsLock dumpLock = new DumpOptionsLock();

/**
Expand Down Expand Up @@ -373,7 +376,7 @@ public static String systemDumpToFile(String fileNamePattern) throws InvalidDump
if( fileNamePattern != null ) {
// Check no-one has tried to sneak options onto the end.
checkForExtraOptions(fileNamePattern);
request = SystemRequestPrefix + fileNamePattern; //$NON-NLS-1$
request = SystemRequestPrefix + fileNamePattern;
} else {
// This is equivalent the to SystemDump() call.
request = "system"; //$NON-NLS-1$
Expand Down Expand Up @@ -486,7 +489,7 @@ public static String snapDumpToFile() {

private static void checkForExtraOptions(String fileNamePattern) throws InvalidDumpOptionException {
// Check no-one has tried to sneak options onto the end of a filename.
if( fileNamePattern.contains(",")) { //$NON-NLS-1$
if (fileNamePattern.contains(",")) { //$NON-NLS-1$
throw new InvalidDumpOptionException("Invalid dump filename specified."); //$NON-NLS-1$
}
}
Expand Down Expand Up @@ -553,7 +556,7 @@ public static String triggerDump(String dumpOptions) throws InvalidDumpOptionExc
throw new NullPointerException();
}
// All the other permissions will be checked in triggerDump(dumpSettings, event);
if( isToolDump(dumpOptions) ) {
if (isToolDump(dumpOptions)) {
checkToolSecurityPermssion();
}
return triggerDump(dumpOptions, "triggerDump"); //$NON-NLS-1$
Expand All @@ -564,7 +567,11 @@ private static String triggerDump(String dumpSettings, String event) throws Inva
/* Check the caller is allowed to trigger a dump. */
checkDumpSecurityPermssion();

return triggerDumpsImpl(dumpSettings, event);
try {
return triggerDumpsImpl(dumpSettings, event);
} catch (InvalidDumpOptionExceptionBase e) {
throw new InvalidDumpOptionException(e);
}
}

/**
Expand Down Expand Up @@ -595,7 +602,7 @@ public static void setDumpOptions(String dumpOptions) throws InvalidDumpOptionEx
/* Check the caller is allowed to trigger a dump. */
checkDumpSecurityPermssion();

if( isToolDump(dumpOptions) ) {
if (isToolDump(dumpOptions)) {
checkToolSecurityPermssion();
}

Expand All @@ -608,8 +615,14 @@ public static void setDumpOptions(String dumpOptions) throws InvalidDumpOptionEx
* A DumpConfigurationUnavailableException can still be thrown if a dump was in
* progress and the dump configuration could not be updated.
*/
synchronized (dumpLock) {
setDumpOptionsImpl(dumpOptions);
try {
synchronized (dumpLock) {
setDumpOptionsImpl(dumpOptions);
}
} catch (InvalidDumpOptionExceptionBase e) {
throw new InvalidDumpOptionException(e);
} catch (DumpConfigurationUnavailableExceptionBase e) {
throw new DumpConfigurationUnavailableException(e);
}
}

Expand Down Expand Up @@ -666,14 +679,22 @@ public static void resetDumpOptions() throws DumpConfigurationUnavailableExcepti
* setDumpOptions is also synchronised in this way.
* A DumpConfigurationUnavailableException can still be thrown if a dump was in
* progress and the dump configuration could not be updated. */
synchronized (dumpLock) {
resetDumpOptionsImpl();
try {
synchronized (dumpLock) {
resetDumpOptionsImpl();
}
} catch (DumpConfigurationUnavailableExceptionBase e) {
throw new DumpConfigurationUnavailableException(e);
}
}

private static native void setDumpOptionsImpl(String options) throws InvalidDumpOptionException, DumpConfigurationUnavailableException;
private static native int JavaDumpImpl();
private static native int HeapDumpImpl();
private static native int SnapDumpImpl();
private static native int SystemDumpImpl();
private static native void setDumpOptionsImpl(String options) throws InvalidDumpOptionExceptionBase, DumpConfigurationUnavailableExceptionBase;
private static native String queryDumpOptionsImpl();
private static native void resetDumpOptionsImpl() throws DumpConfigurationUnavailableException;
private static native String triggerDumpsImpl(String dumpOptions, String event) throws InvalidDumpOptionException;
private static native void resetDumpOptionsImpl() throws DumpConfigurationUnavailableExceptionBase;
private static native String triggerDumpsImpl(String dumpOptions, String event) throws InvalidDumpOptionExceptionBase;
private static native boolean isToolDump(String dumpOptions);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
package com.ibm.jvm;

/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2012, 2014 IBM Corp. and others
* Copyright (c) 2012, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -23,6 +21,10 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

package com.ibm.jvm;

import openj9.management.internal.DumpConfigurationUnavailableExceptionBase;

/**
* This exception is thrown when the dump configuration cannot be
* updated through the methods on com.ibm.jvm.Dump because it is
Expand All @@ -38,5 +40,12 @@ public class DumpConfigurationUnavailableException extends Exception {
public DumpConfigurationUnavailableException(String message) {
super(message);
}


/**
* @param cause root exception
*/
public DumpConfigurationUnavailableException(DumpConfigurationUnavailableExceptionBase cause) {
super(cause.getMessage(), cause);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
package com.ibm.jvm;

/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2012, 2014 IBM Corp. and others
* Copyright (c) 2012, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -23,6 +21,10 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

package com.ibm.jvm;

import openj9.management.internal.InvalidDumpOptionExceptionBase;

/**
* This exception is thrown when an invalid option is passed
* to methods on the com.ibm.jvm.Dump class.
Expand All @@ -31,8 +33,18 @@ public class InvalidDumpOptionException extends Exception {

private static final long serialVersionUID = -507148799087920306L;

/**
* @param message description of error
*/
public InvalidDumpOptionException(String message) {
super(message);
}

/**
* @param cause root exception
*/
public InvalidDumpOptionException(InvalidDumpOptionExceptionBase cause) {
super(cause.getMessage(), cause);
}

}
12 changes: 9 additions & 3 deletions runtime/jcl/common/dump.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1998, 2018 IBM Corp. and others
* Copyright (c) 1998, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -283,6 +283,12 @@ Java_com_ibm_jvm_Dump_triggerDumpsImpl (JNIEnv *env, jclass clazz, jstring jopts
#endif
}

jstring JNICALL
Java_openj9_tools_attach_diagnostics_base_DiagnosticUtils_triggerDumpsImpl(JNIEnv *env, jclass clazz, jstring jopts, jstring jevent)
{
return Java_com_ibm_jvm_Dump_triggerDumpsImpl(env, clazz, jopts, jevent);
}

void JNICALL
Java_com_ibm_jvm_Dump_setDumpOptionsImpl (JNIEnv *env, jclass clazz, jstring jopts)
{
Expand Down Expand Up @@ -446,7 +452,7 @@ raiseExceptionFor(JNIEnv *env, omr_error_t result)

switch (result) {
case OMR_ERROR_INTERNAL:
exceptionClass = (*env)->FindClass(env, "com/ibm/jvm/InvalidDumpOptionException");
exceptionClass = (*env)->FindClass(env, "openj9/management/internal/InvalidDumpOptionExceptionBase");
if (exceptionClass != NULL) {
(*env)->ThrowNew(env, exceptionClass, "Error in dump options.");
}
Expand All @@ -460,7 +466,7 @@ raiseExceptionFor(JNIEnv *env, omr_error_t result)
/* Just return if we can't load the exception class. */
break;
case OMR_ERROR_NOT_AVAILABLE:
exceptionClass = (*env)->FindClass(env, "com/ibm/jvm/DumpConfigurationUnavailableException");
exceptionClass = (*env)->FindClass(env, "openj9/management/internal/DumpConfigurationUnavailableExceptionBase");
if (exceptionClass != NULL) {
(*env)->ThrowNew(env, exceptionClass, "Dump configuration cannot be changed while a dump is in progress.");
}
Expand Down
1 change: 1 addition & 0 deletions runtime/jcl/exports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ omr_add_exports(jclse
Java_com_ibm_lang_management_internal_UnixExtendedOperatingSystem_getOpenFileDescriptorCountImpl
Java_openj9_tools_attach_diagnostics_base_DiagnosticUtils_getHeapClassStatisticsImpl
Java_openj9_tools_attach_diagnostics_base_DiagnosticUtils_dumpAllThreadsImpl
Java_openj9_tools_attach_diagnostics_base_DiagnosticUtils_triggerDumpsImpl
Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsDataImpl__Ljava_lang_Class_2
Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsData__Ljava_lang_reflect_Constructor_2
Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsData__Ljava_lang_reflect_Field_2
Expand Down
1 change: 1 addition & 0 deletions runtime/jcl/uma/se6_vm-side_natives_exports.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
<export name="Java_com_ibm_java_lang_management_internal_ThreadMXBeanImpl_getMultiThreadInfoImpl" />
<export name="Java_com_ibm_java_lang_management_internal_ThreadMXBeanImpl_dumpAllThreadsImpl" />
<export name="Java_openj9_tools_attach_diagnostics_base_DiagnosticUtils_getHeapClassStatisticsImpl" />
<export name="Java_openj9_tools_attach_diagnostics_base_DiagnosticUtils_triggerDumpsImpl" />
<export name="Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsData__Ljava_lang_reflect_Field_2" />
<export name="Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsData__Ljava_lang_reflect_Constructor_2" />
<export name="Java_com_ibm_oti_reflect_AnnotationParser_getAnnotationsData__Ljava_lang_reflect_Method_2" />
Expand Down
Loading

0 comments on commit 4baf3d7

Please sign in to comment.