Search in sources :

Example 6 with ImagePointer

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);
    }
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaClass(com.ibm.dtfj.java.JavaClass)

Example 7 with ImagePointer

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ImageSection(com.ibm.dtfj.image.ImageSection) Properties(java.util.Properties) LinkedList(java.util.LinkedList) ImagePointer(com.ibm.dtfj.image.ImagePointer) Iterator(java.util.Iterator)

Example 8 with ImagePointer

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);
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JCJavaMonitor(com.ibm.dtfj.java.javacore.JCJavaMonitor)

Example 9 with ImagePointer

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);
    }
}
Also used : JCJavaObject(com.ibm.dtfj.java.javacore.JCJavaObject) ImagePointer(com.ibm.dtfj.image.ImagePointer) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException) JCJavaClass(com.ibm.dtfj.java.javacore.JCJavaClass) JCJavaThread(com.ibm.dtfj.java.javacore.JCJavaThread)

Example 10 with ImagePointer

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");
    }
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException) JCJavaClass(com.ibm.dtfj.java.javacore.JCJavaClass)

Aggregations

ImagePointer (com.ibm.dtfj.image.ImagePointer)45 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)19 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)12 JavaClass (com.ibm.dtfj.java.JavaClass)9 JCInvalidArgumentsException (com.ibm.dtfj.java.javacore.JCInvalidArgumentsException)8 CorruptData (com.ibm.dtfj.image.j9.CorruptData)7 JavaObject (com.ibm.dtfj.java.JavaObject)7 BuilderFailureException (com.ibm.dtfj.javacore.builder.BuilderFailureException)7 Iterator (java.util.Iterator)7 JCJavaClass (com.ibm.dtfj.java.javacore.JCJavaClass)6 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)5 JCJavaObject (com.ibm.dtfj.java.javacore.JCJavaObject)4 ArrayList (java.util.ArrayList)4 Vector (java.util.Vector)4 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)3 ImageSection (com.ibm.dtfj.image.ImageSection)3 JCImageThread (com.ibm.dtfj.image.javacore.JCImageThread)3 JCJavaMonitor (com.ibm.dtfj.java.javacore.JCJavaMonitor)3 IOException (java.io.IOException)3 CorruptData (com.ibm.dtfj.image.CorruptData)2