use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class PHDJavaClassLoader method prepareToMove.
/**
* Get reader to move a class from one loader to another, including the array refs.
* @param from
* @param j1
*/
void prepareToMove(PHDJavaClassLoader from, JavaClass j1) {
setLoader(j1);
ImagePointer ip = j1.getID();
if (ip != null) {
long address = ip.getAddress();
JavaClass j2 = from.arrayClasses.get(address);
if (j2 != null)
setLoader(j2);
}
}
use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class InfoMmapCommand method run.
public void run(String command, String[] args, IContext context, PrintStream out) throws CommandException {
boolean verbose = false;
ImagePointer addressPointer = null;
Comparator<ImageSection> sortOrder = null;
if (initCommand(command, args, context, out)) {
// processing already handled by super class
return;
}
for (String arg : args) {
if (Utils.SORT_BY_SIZE_FLAG.equals(arg)) {
sortOrder = new SizeComparator();
} else if (Utils.SORT_BY_ADDRESS_FLAG.equals(arg)) {
sortOrder = new AddressComparator();
} else if (Utils.VERBOSE_FLAG.equals(arg)) {
verbose = true;
} else {
// longFromString will return a Long or null if we couldn't parse
// the argument as a number.
Long address = Utils.longFromString(arg);
if (address == null) {
out.println("\"info mmap\" -unknown parameter " + arg);
return;
} else {
addressPointer = ctx.getAddressSpace().getPointer(address);
}
}
}
List<ImageSection> sortedSections = new LinkedList<ImageSection>();
Iterator<ImageSection> imageSections = ctx.getAddressSpace().getImageSections();
while (imageSections.hasNext()) {
sortedSections.add(imageSections.next());
}
if (sortOrder != null) {
Collections.sort(sortedSections, sortOrder);
}
int addrSize = ctx.getProcess().getPointerSize() == 64 ? 16 : 8;
// Width for decimals can vary as we use the locales format (via %,d)
int decWidth = 0;
int hexWidth = 0;
if (addrSize == 16) {
hexWidth = String.format("%016x", Long.MAX_VALUE).length();
decWidth = String.format("(%,d)", Long.MAX_VALUE).length();
} else {
hexWidth = String.format("%08x", Integer.MAX_VALUE).length();
decWidth = String.format("(%,d)", Integer.MAX_VALUE).length();
}
out.printf("%-" + hexWidth + "s\t%-" + hexWidth + "s\t%-" + hexWidth + "s\t%-" + decWidth + "s\tRead/Write/Execute", "Start Address", "End Address", "Size", "Size");
out.println();
long totalSize = 0;
long totalSizeRwx = 0;
Iterator sortedIterator = sortedSections.iterator();
while (sortedIterator.hasNext()) {
ImageSection imageSection = (ImageSection) sortedIterator.next();
if (addressPointer != null) {
if (imageSection.getBaseAddress().getAddress() <= addressPointer.getAddress() && imageSection.getBaseAddress().add(imageSection.getSize()).getAddress() > addressPointer.getAddress()) {
// Print this address
} else {
continue;
}
}
long startAddress = imageSection.getBaseAddress().getAddress();
long size = imageSection.getSize();
long endAddress = startAddress + size - 1;
totalSize += size;
String decSize = String.format("(%,d)", size);
out.printf("0x%0" + hexWidth + "x\t0x%0" + hexWidth + "x\t0x%0" + hexWidth + "x\t%-" + decWidth + "s\t", startAddress, endAddress, size, decSize);
Properties props = imageSection.getProperties();
if (props != null) {
boolean rwx = false;
if (Boolean.TRUE.toString().equals(props.get("readable"))) {
out.print("R");
rwx = true;
}
if (Boolean.TRUE.toString().equals(props.get("writable"))) {
out.print("W");
rwx = true;
}
if (Boolean.TRUE.toString().equals(props.get("executable"))) {
out.print("X");
rwx = true;
}
if (rwx) {
totalSizeRwx += size;
}
}
if (verbose || addressPointer != null) {
out.println();
out.println("Name:\t" + imageSection.getName());
String[] keys = props.keySet().toArray(new String[0]);
ArrayList<String> table = new ArrayList<String>(keys.length);
int maxLen = 0;
Arrays.sort(keys);
// We may have a lot of properties so print them out in two columns.
for (String key : keys) {
String formatted = String.format("%s=%s", key, props.get(key));
table.add(formatted);
maxLen = Math.max(maxLen, formatted.length());
}
Iterator<String> tableIterator = table.iterator();
String tableFormatString = "\t%-" + maxLen + "s\t%-" + maxLen + "s\n";
while (tableIterator.hasNext()) {
out.printf(tableFormatString, tableIterator.next(), tableIterator.hasNext() ? tableIterator.next() : "");
}
out.println();
} else {
out.println();
}
}
if (addressPointer == null) {
if (totalSizeRwx > 0 && totalSize != totalSizeRwx) {
out.printf("Total size (Readable, Writable or Executable): 0x%1$x (%1$,d) bytes\n", totalSizeRwx);
}
out.printf("Total size: 0x%1$x (%1$,d) bytes\n", totalSize);
}
}
use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class JavaRuntimeBuilder method addBlockedThread.
/**
*/
public void addBlockedThread(JavaMonitor monitor, long threadID) throws BuilderFailureException {
JCJavaMonitor jmonitor = (JCJavaMonitor) monitor;
ImagePointer pointer = fAddressSpace.getPointer(threadID);
jmonitor.addEnterWaiter(pointer);
}
use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class JavaRuntimeBuilder method addJavaThread.
/**
* If successfully added a JavaThread, or updated an existing JavaThread, return the javathread, or otherwise
* throw an exception. Note that a javathread cannot be successfully added if no valid threadID is passed.
* <br><br>
* REQUIREMENT: Thread Id must be valid to properly create a Java Thread, or exception is thrown.
*
* @throws BuilderFailureException if arguments lead to an invalid DTFJ object, particularly an invalid threadID
* @return a non null JavaThread that was successfully added or updated.
*/
public JavaThread addJavaThread(ImageThread imageThread, String name, long tid, long j9thread_t, long javaObjID, long jniEnv, String state, int priority, long blockingObject, String blockingObjectClass) throws BuilderFailureException {
try {
if (j9thread_t != IBuilderData.NOT_AVAILABLE && jniEnv != IBuilderData.NOT_AVAILABLE) {
// Save the JNIEnv for later
ImagePointer pointer = fAddressSpace.getPointer(jniEnv);
j9ThreadToJNIEnv.put(new Long(j9thread_t), pointer);
}
if (!fAddressSpace.isValidAddressID(tid)) {
throw new JCInvalidArgumentsException("Must pass a valid thread id");
}
JCJavaThread javaThread = getJavaRuntime().findJavaThread(tid);
if (javaThread == null) {
ImagePointer pointer = fAddressSpace.getPointer(tid);
javaThread = new JCJavaThread(getJavaRuntime(), pointer);
}
javaThread.setName(name);
javaThread.setPriority(priority);
javaThread.setState(state);
javaThread.setImageThread((JCImageThread) imageThread);
if (jniEnv == IBuilderData.NOT_AVAILABLE) {
// Retrieve the JNIEnv
ImagePointer pointer = (ImagePointer) j9ThreadToJNIEnv.get(new Long(j9thread_t));
if (pointer != null) {
// Set it for 1.4.2
javaThread.setJNIEnv(pointer);
} else {
// Else TID for J9 seems to be JNIEnv
javaThread.setJNIEnv(javaThread.getThreadID());
}
}
/*
* Add the object only if the object ID is valid.
*/
if (fAddressSpace.isValidAddressID(javaObjID)) {
// Make the type just java.lang.Thread - later we can do better if there is a stack trace.
JCJavaClass jClass = generateJavaClass(getJavaRuntime(), "java/lang/Thread", IBuilderData.NOT_AVAILABLE);
ImagePointer pointerObjectID = fAddressSpace.getPointer(javaObjID);
JCJavaObject jobject = new JCJavaObject(pointerObjectID, jClass);
javaThread.setObject(jobject);
}
if (fAddressSpace.isValidAddressID(blockingObject)) {
JCJavaClass jClass = generateJavaClass(getJavaRuntime(), blockingObjectClass, IBuilderData.NOT_AVAILABLE);
ImagePointer pointerObjectID = fAddressSpace.getPointer(javaObjID);
JCJavaObject jobject = new JCJavaObject(pointerObjectID, jClass);
javaThread.setBlockingObject(jobject);
}
return javaThread;
} catch (JCInvalidArgumentsException e) {
throw new BuilderFailureException(e);
}
}
use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class JavaRuntimeBuilder method generateJavaClass.
/**
* Either retrieves an existing java class registered with the java runtime or it creates one and it fills in missing information,
* if the latter is available.
* <br><br>
* A valid runtime and class name must be passed in order to successfully generate a java class. An invalid argument exception is
* thrown if either one of them is invalid.
* <br><br>
* A null value should not be returned, as this indicates an error was encountered. Instead, throw the
* appropriate exception.
*
* @param runtime required
* @param name required
* @param classID optional
* @return added or updated JavaClass, or exception thrown if invalid arguments passed.
* @throws JCInvalidArgumentsException
*/
private JCJavaClass generateJavaClass(JCJavaRuntime runtime, String name, long classID) throws JCInvalidArgumentsException {
if (name != null) {
if (fAddressSpace.isValidAddressID(classID)) {
JCJavaClass jClass = runtime.findJavaClass(classID);
if (jClass == null) {
jClass = runtime.findJavaClass(name);
if (jClass != null) {
ImagePointer ip = jClass.getID();
if (ip == null) {
jClass.setID(classID);
} else {
jClass = new JCJavaClass(runtime, name);
jClass.setID(classID);
}
} else {
jClass = new JCJavaClass(runtime, name);
jClass.setID(classID);
}
}
return jClass;
}
JCJavaClass jClass = runtime.findJavaClass(name);
if (jClass == null) {
jClass = new JCJavaClass(runtime, name);
}
if (fAddressSpace.isValidAddressID(classID)) {
jClass.setID(classID);
}
return jClass;
} else {
throw new JCInvalidArgumentsException("Failed to add class. Null class name");
}
}
Aggregations