Skip to content

Commit

Permalink
Merge pull request #1987 from Ailloviee/DDRCommands_v1
Browse files Browse the repository at this point in the history
Add new DDR commands for modularity__Command 1 and 2
  • Loading branch information
keithc-ca authored Jun 12, 2018
2 parents 2e0f8b0 + a1a647c commit d78af3b
Show file tree
Hide file tree
Showing 6 changed files with 374 additions and 51 deletions.
100 changes: 99 additions & 1 deletion debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/j9/ObjectModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2017 IBM Corp. and others
* Copyright (c) 1991, 2018 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 @@ -24,11 +24,18 @@
import static com.ibm.j9ddr.vm29.events.EventManager.raiseCorruptDataEvent;

import com.ibm.j9ddr.CorruptDataException;
import com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor;
import com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionIterator;
import com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionManager;
import com.ibm.j9ddr.vm29.j9.gc.GCObjectModel;
import com.ibm.j9ddr.vm29.pointer.AbstractPointer;
import com.ibm.j9ddr.vm29.pointer.VoidPointer;
import com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer;
import com.ibm.j9ddr.vm29.pointer.generated.J9IndexableObjectPointer;
import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer;
import com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer;
import com.ibm.j9ddr.vm29.pointer.generated.MM_GCExtensionsPointer;
import com.ibm.j9ddr.vm29.pointer.generated.MM_HeapRegionManagerPointer;
import com.ibm.j9ddr.vm29.types.I32;
import com.ibm.j9ddr.vm29.types.U32;
import com.ibm.j9ddr.vm29.types.UDATA;
Expand Down Expand Up @@ -358,8 +365,99 @@ public static UDATA getHeaderSize(J9ObjectPointer object) throws CorruptDataExce
return gcObjectModel.getHeaderSize(object);
}

/**
* Returns the address of an element.
* @param indexableObjectPointer Pointer to a J9 indexable object
* @param elementIndex Index of the element
* @param elementSize Size of the element
* @return The address of an element.
* @throws CorruptDataException
*/
public static VoidPointer getElementAddress(J9IndexableObjectPointer indexableObjectPointer, int elementIndex, int elementSize) throws CorruptDataException
{
return gcObjectModel.getElementAddress(indexableObjectPointer, elementIndex, elementSize);
}

/**
* Returns the heap region of a pointer.
* @param javaVM J9JavaVMPointer
* @param hrm The gc heap region manager
* @param pointer Any abstract pointer
* @param region A gc heap region descriptor
* @return The heap region descriptor of the given pointer.
*/
public static GCHeapRegionDescriptor findRegionForPointer(J9JavaVMPointer javaVM, GCHeapRegionManager hrm, AbstractPointer pointer, GCHeapRegionDescriptor region)
{
GCHeapRegionDescriptor regionDesc = null;

if (region != null && region.isAddressInRegion(pointer)) {
return region;
}

regionDesc = regionForAddress(javaVM, hrm, pointer);
if (null != regionDesc) {
return regionDesc;
}

// TODO kmt : this is tragically slow
try {
GCHeapRegionIterator iterator = GCHeapRegionIterator.from();
while (iterator.hasNext()) {
regionDesc = GCHeapRegionDescriptor.fromHeapRegionDescriptor(iterator.next());
if (isPointerInRegion(pointer, regionDesc)) {
return regionDesc;
}
}
} catch (CorruptDataException e) {
}
return null;
}

/**
* Returns the heap region for address of a pointer.
* @param javaVM J9JavaVMPointer
* @param hrm The gc heap region manager
* @param pointer Any abstract pointer
* @return The heap region descriptor for address of a pointer.
*/
public static GCHeapRegionDescriptor regionForAddress(J9JavaVMPointer javaVM, GCHeapRegionManager hrm, AbstractPointer pointer)
{
try {
if (null == hrm) {
MM_HeapRegionManagerPointer hrmPtr = MM_GCExtensionsPointer.cast(javaVM.gcExtensions())
.heapRegionManager();
hrm = GCHeapRegionManager.fromHeapRegionManager(hrmPtr);
}
return hrm.regionDescriptorForAddress(pointer);
} catch (CorruptDataException cde) {
}
return null;
}

/**
* Returns true if a pointer is in stored in specified region.
* @param pointer Any abstract pointer
* @param region Descriptor for a region in heap
* @return If the AbstractPointer pointer is in stored in the given region in heap.
*/
public static boolean isPointerInRegion(AbstractPointer pointer, GCHeapRegionDescriptor region)
{
return pointer.gte(region.getLowAddress()) && pointer.lt(region.getHighAddress());
}

/**
* Returns true if a pointer is in stored in heap.
* @param javaVM J9JavaVMPointer
* @param pointer Any abstract pointer
* @return If the AbstractPointer pointer is in stored in heap.
*/
public static boolean isPointerInHeap(J9JavaVMPointer javaVM, AbstractPointer pointer)
{
if (findRegionForPointer(javaVM, null, pointer, null) != null) {
return true;
} else {
return false;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
import com.ibm.j9ddr.vm29.tools.ddrinteractive.commands.DumpSegregatedStatsCommand;
import com.ibm.j9ddr.vm29.tools.ddrinteractive.commands.DumpStringTableCommand;
import com.ibm.j9ddr.vm29.tools.ddrinteractive.commands.ExtendedMethodFlagInfoCommand;
import com.ibm.j9ddr.vm29.tools.ddrinteractive.commands.FindAllModulesCommand;
import com.ibm.j9ddr.vm29.tools.ddrinteractive.commands.FindMethodFromPcCommand;
import com.ibm.j9ddr.vm29.tools.ddrinteractive.commands.FindModuleByNameCommand;
import com.ibm.j9ddr.vm29.tools.ddrinteractive.commands.FindOverlappingSegmentsCommand;
import com.ibm.j9ddr.vm29.tools.ddrinteractive.commands.FindPatternCommand;
import com.ibm.j9ddr.vm29.tools.ddrinteractive.commands.FindStackValueCommand;
Expand Down Expand Up @@ -175,6 +177,8 @@ public void run(IVMData vmData, Object[] userData)
toPassBack.add(new ObjectSizeInfo());
toPassBack.add(new DumpContendedLoadTable());
toPassBack.add(new CPDescriptionCommand());
toPassBack.add(new FindAllModulesCommand());
toPassBack.add(new FindModuleByNameCommand());

loadPlugins(toPassBack, loader);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2018, 2018 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 com.ibm.j9ddr.vm29.tools.ddrinteractive;

import java.io.PrintStream;

import com.ibm.j9ddr.CorruptDataException;
import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer;
import com.ibm.j9ddr.vm29.types.UDATA;

/**
* JavaVersionHelper helps check if the JVM version is new enough
*/
public class JavaVersionHelper
{
public final static int J2SE_SERVICE_RELEASE_MASK = 0xFFFF;
public final static int J2SE_19 = 9;
public final static int J2SE_JAVA_SPEC_VERSION_SHIFT = 8;

/**
* Returns true if the Java version is Java9 and up.
* @param vm J9JavaVMPointer
* @param out The output print stream
* @return if the Java version is Java9 and up or not.
* @throws CorruptDataException
*/
public static boolean ensureJava9AndUp(J9JavaVMPointer vm, PrintStream out) throws CorruptDataException
{
int javaVersion = vm.j2seVersion().bitAnd(J2SE_SERVICE_RELEASE_MASK).intValue() >> J2SE_JAVA_SPEC_VERSION_SHIFT;
if (javaVersion < J2SE_19) {
out.printf("This command only works with core file created by VM with Java version 9 or higher%n"
+ "The current VM Java version is: %s%n", javaVersion);
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright (c) 2018, 2018 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 com.ibm.j9ddr.vm29.tools.ddrinteractive.commands;

import java.io.PrintStream;

import com.ibm.j9ddr.CorruptDataException;
import com.ibm.j9ddr.tools.ddrinteractive.Command;
import com.ibm.j9ddr.tools.ddrinteractive.Context;
import com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException;
import com.ibm.j9ddr.vm29.j9.DataType;
import com.ibm.j9ddr.vm29.j9.ObjectModel;
import com.ibm.j9ddr.vm29.j9.Pool;
import com.ibm.j9ddr.vm29.j9.SlotIterator;
import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer;
import com.ibm.j9ddr.vm29.pointer.generated.J9ModulePointer;
import com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer;
import com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer;
import com.ibm.j9ddr.vm29.pointer.helper.J9ObjectHelper;
import com.ibm.j9ddr.vm29.pointer.helper.J9RASHelper;
import com.ibm.j9ddr.vm29.tools.ddrinteractive.JavaVersionHelper;

/**
* FindAllModules command displays all the modules loaded by the runtime
*
* Example:
* !findallmodules
* Example output:
* jdk.javadoc !j9module 0x000001305F474498
* jdk.attach !j9module 0x000001305F478798
* java.prefs !j9module 0x000001305F478928
* .....(A list of every module loaded by the runtime)
*/
public class FindAllModulesCommand extends Command
{
public FindAllModulesCommand()
{
addCommand("findallmodules", "", "Outputs all the modules loaded by the runtime");
}

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException
{
try {
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
if (JavaVersionHelper.ensureJava9AndUp(vm, out)) {
J9PoolPointer pool = vm.modularityPool();
Pool<J9ModulePointer> modulePool = Pool.fromJ9Pool(pool, J9ModulePointer.class);
SlotIterator<J9ModulePointer> poolIterator = modulePool.iterator();
J9ModulePointer modulePtr = null;
J9ObjectPointer moduleNameObjPtr = null;
while (poolIterator.hasNext()) {
modulePtr = poolIterator.next();
moduleNameObjPtr = modulePtr.moduleName();
/*
* Since both packages and modules could be in the pool, the
* iterator checks on the region and make sure that it is
* pointing to a module. (For modules, the first field must
* be in heap since it is an object while for j9package it
* is a J9UTF8.)
*/
if (ObjectModel.isPointerInHeap(vm, moduleNameObjPtr)) {
String moduleName = J9ObjectHelper.stringValue(moduleNameObjPtr);
String hexAddress = modulePtr.getHexAddress();
out.printf("%-30s !j9module %s%n", moduleName, hexAddress);
}
}
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}

}
}

Loading

0 comments on commit d78af3b

Please sign in to comment.