Search in sources :

Example 1 with IOSThread

use of com.ibm.j9ddr.corereaders.osthread.IOSThread in project openj9 by eclipse.

the class ThreadInfoStream method readFrom.

public void readFrom(MiniDumpReader dump, IAddressSpace addressSpace, boolean is64Bit, List<IOSThread> threads) throws CorruptDataException, IOException {
    dump.seek(getLocation());
    int sizeOfHeader = 0;
    int sizeOfEntry = 0;
    int numberOfEntries = 0;
    HashMap<Long, Properties> threadInfo = new HashMap<Long, Properties>();
    // The header is 3 ULONGs, which are 32 bit.
    sizeOfHeader = dump.readInt();
    sizeOfEntry = dump.readInt();
    numberOfEntries = dump.readInt();
    // The thread info structures follow the header.
    /* Each structure is:
		 *  ULONG32 ThreadId;
  			ULONG32 DumpFlags;
  			ULONG32 DumpError;
  			ULONG32 ExitStatus;
  			ULONG64 CreateTime;
  			ULONG64 ExitTime;
  			ULONG64 KernelTime;
  			ULONG64 UserTime;
  			ULONG64 StartAddress;
  			ULONG64 Affinity;
		 */
    // We should be exactly here already but to be safe.
    dump.seek(getLocation() + sizeOfHeader);
    for (int i = 0; i < numberOfEntries; i++) {
        Properties props = new Properties();
        int threadId = dump.readInt();
        int dumpFlags = dump.readInt();
        int dumpError = dump.readInt();
        int exitStatus = dump.readInt();
        // Times stamps are in 100 nano second intervals since January 1, 1601 (UTC).
        long createTime = dump.readLong();
        long exitTime = dump.readLong();
        // Durations (also in 100 nano second intervals).
        long kernelTime = dump.readLong();
        long userTime = dump.readLong();
        long startAddress = dump.readLong();
        long affinity = dump.readLong();
        props.put("DumpFlags", String.format("0x%08X", dumpFlags));
        props.put("DumpError", String.format("0x%08X", dumpError));
        props.put("ExitStatus", String.format("0x%08X", exitStatus));
        props.put("CreateTime", Long.toString(createTime));
        props.put("ExitTime", Long.toString(exitTime));
        props.put("KernelTime", Long.toString(kernelTime));
        props.put("UserTime", Long.toString(userTime));
        props.put("StartAddress", String.format(is64Bit ? "0x%016X" : "0x%08X", startAddress));
        // CPU affinity mask, enabled bits show enabled CPUs.
        props.put("Affinity", String.format("0x%016X", affinity));
        long createTimeMillis = (createTime / 10000l) + baseMillisOffset;
        String createTimeStr = dateFormat.format(new Date(createTimeMillis));
        props.put("CreateTime_Formatted", createTimeStr);
        if (exitTime != 0) {
            long exitTimeMillis = (exitTime / 10000l) + baseMillisOffset;
            String exitTimeStr = dateFormat.format(new Date(exitTimeMillis));
            props.put("ExitTime_Formatted", exitTimeStr);
        }
        threadInfo.put(new Long(threadId), props);
    }
    /* Merge the extra properties into the thread info. */
    Iterator<IOSThread> threadIterator = threads.iterator();
    while (threadIterator.hasNext()) {
        IOSThread t = threadIterator.next();
        Properties p = threadInfo.get(t.getThreadId());
        if (p != null) {
            t.getProperties().putAll(p);
        }
    }
}
Also used : HashMap(java.util.HashMap) Properties(java.util.Properties) IOSThread(com.ibm.j9ddr.corereaders.osthread.IOSThread) Date(java.util.Date)

Example 2 with IOSThread

use of com.ibm.j9ddr.corereaders.osthread.IOSThread in project openj9 by eclipse.

the class J9DDRImageProcess method getThreadMap.

private Map<Long, Object> getThreadMap() {
    Map<Long, Object> dtfjThreadMap = null;
    if (cachedThreads != null) {
        dtfjThreadMap = (Map<Long, Object>) cachedThreads.get();
    }
    /* We did not find a cache of threads, build one. */
    if (dtfjThreadMap == null) {
        Collection<? extends IOSThread> threads = null;
        long corruptId = -1;
        try {
            threads = process.getThreads();
        } catch (com.ibm.j9ddr.CorruptDataException e) {
            return Collections.singletonMap(corruptId, (Object) new J9DDRCorruptData(process, e));
        }
        // On Linux, fork/abort system dumping means we only get one thread, with an altered TID. In this case we have logic in
        // getCurrentThread that renames the dump thread. Add this thread in addition to the native thread.
        boolean forkandabort = ((process.getPlatform() == Platform.LINUX) && (threads.size() == 1));
        dtfjThreadMap = new HashMap<Long, Object>();
        if (forkandabort) {
            try {
                J9DDRBaseImageThread currentThread = (J9DDRBaseImageThread) getCurrentThread();
                if (currentThread != null) {
                    dtfjThreadMap.put(currentThread.getThreadId(), currentThread);
                }
            } catch (CorruptDataException e) {
                // A corrupt thread won't have an id but we will still return the corrupt
                // data in the list of all threads.
                dtfjThreadMap.put(corruptId--, new J9DDRCorruptData(process, e.getMessage()));
            } catch (com.ibm.j9ddr.CorruptDataException e) {
                // A corrupt thread won't have an id but we will still return the corrupt
                // data in the list of all threads.
                dtfjThreadMap.put(corruptId--, new J9DDRCorruptData(process, e.getMessage()));
            }
        }
        for (IOSThread thread : threads) {
            try {
                dtfjThreadMap.put(thread.getThreadId(), new J9DDRImageThread(process, thread));
            } catch (com.ibm.j9ddr.CorruptDataException e) {
                // In the unlikely event that we can't get the thread id, store the thread
                // without the id.
                dtfjThreadMap.put(corruptId--, new J9DDRImageThread(process, thread));
            }
        }
        cachedThreads = new WeakReference<Map<Long, Object>>(dtfjThreadMap);
    }
    return dtfjThreadMap;
}
Also used : DTFJCorruptDataException(com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) IOSThread(com.ibm.j9ddr.corereaders.osthread.IOSThread) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with IOSThread

use of com.ibm.j9ddr.corereaders.osthread.IOSThread in project openj9 by eclipse.

the class JniProcess method getThreads.

public Collection<? extends IOSThread> getThreads() throws CorruptDataException {
    List<IOSThread> threads = new ArrayList<IOSThread>(_threadEntries.size());
    /* go get a list of current thread ids */
    long[] tidList = getThreadIds();
    if (tidList == null) {
        return null;
    }
    for (long tid : tidList) {
        /* Get current registers for given thread */
        _registers.readRegisters(tid);
        /* Inflate the thread */
        IOSThread thread = new JniThread(tid, _registers, null);
        threads.add(thread);
    }
    return threads;
}
Also used : ArrayList(java.util.ArrayList) IOSThread(com.ibm.j9ddr.corereaders.osthread.IOSThread)

Example 4 with IOSThread

use of com.ibm.j9ddr.corereaders.osthread.IOSThread in project openj9 by eclipse.

the class NativeStacksCommand method run.

public void run(String cmd, String[] args, Context ctx, PrintStream out) throws DDRInteractiveCommandException {
    Set<Long> threadIds = null;
    for (String arg : args) {
        if (threadIds == null) {
            threadIds = new HashSet<Long>();
        }
        Long tid = CommandUtils.parseNumber(arg).longValue();
        threadIds.add(tid);
    }
    try {
        Collection<? extends IOSThread> threads = ctx.process.getThreads();
        for (IOSThread t : threads) {
            if (threadIds == null || threadIds.contains(t.getThreadId())) {
                try {
                    out.printf("Thread id: %d (0x%X)\n", t.getThreadId(), t.getThreadId());
                    int frameId = 0;
                    if (threadIds != null) {
                        threadIds.remove(t.getThreadId());
                    }
                    for (IOSStackFrame f : t.getStackFrames()) {
                        String symbol = ctx.process.getProcedureNameForAddress(f.getInstructionPointer());
                        if (ctx.process.bytesPerPointer() == 8) {
                            out.printf("#%d bp:0x%016X ip:0x%016X %s\n", frameId++, f.getBasePointer(), f.getInstructionPointer(), symbol);
                        } else {
                            out.printf("#%d bp:0x%08X ip:0x%08X %s\n", frameId++, f.getBasePointer(), f.getInstructionPointer(), symbol);
                        }
                    }
                } catch (DataUnavailableException e) {
                    out.printf("DataUnavailableException reading stack for thread %d\n", t.getThreadId());
                } catch (CorruptDataException e) {
                    out.printf("CorruptDataException reading stack for thread %d\n", t.getThreadId());
                }
                out.println("----------");
            }
        }
        if (threadIds != null && !threadIds.isEmpty()) {
            out.print("Unable to find native thread for id(s): ");
            for (long tid : threadIds) {
                out.print(tid);
            }
            out.println();
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : DataUnavailableException(com.ibm.j9ddr.DataUnavailableException) IOSStackFrame(com.ibm.j9ddr.corereaders.osthread.IOSStackFrame) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) IOSThread(com.ibm.j9ddr.corereaders.osthread.IOSThread)

Example 5 with IOSThread

use of com.ibm.j9ddr.corereaders.osthread.IOSThread in project openj9 by eclipse.

the class J9DDRImageProcess method getCurrentThread.

/**
 * This method returns the ImageThread that matches the TID stored in the J9RAS data structure,
 *  or
 *  case 1: if no J9RAS structure available return null
 *  case 2: if J9RAS structure available but no TID field (old JVMs, old jextract behaviour)
 *  		- return the first thread, or null if no threads
 *  case 3: if J9RAS structure available with TID field but TID is zero (eg dump triggered outside JVM)
 *  		- platform specific code if core readers have identified a current thread, else...
 *  case 4: if J9RAS structure available with TID field but no match (eg Linux), return a stub ImageThread
 *
 * @return ImageThread
 * @throws {@link CorruptDataException}
 */
public ImageThread getCurrentThread() throws CorruptDataException {
    try {
        checkFailureInfo();
        if (j9rasProcessData != null) {
            long currentThreadId;
            try {
                currentThreadId = j9rasProcessData.tid();
            } catch (DataUnavailable e) {
                // JExtract currently just takes first thread as we do here
                for (IOSThread thread : process.getThreads()) {
                    return new J9DDRImageThread(process, thread);
                }
                return null;
            }
            for (IOSThread thread : process.getThreads()) {
                if (thread.getThreadId() == currentThreadId) {
                    return new J9DDRImageThread(process, thread);
                }
            }
            if (currentThreadId == 0) {
                // for a thread with a non-zero Task Completion Code. There may be more we can do here for Win/Linux/AIX
                if (process.getPlatform() == Platform.ZOS) {
                    for (IOSThread thread : process.getThreads()) {
                        Properties threadProps = thread.getProperties();
                        String tcc = threadProps.getProperty("Task Completion Code");
                        if (tcc != null && !tcc.equals("0x0")) {
                            return new J9DDRImageThread(process, thread);
                        }
                    }
                }
            }
            // We cannot match the native thread at this point, so provide a stub based on the information in the RAS structure.
            return new J9DDRStubImageThread(process, currentThreadId);
        } else {
            return null;
        }
    } catch (com.ibm.j9ddr.CorruptDataException e) {
        throw new DTFJCorruptDataException(process, e);
    }
}
Also used : DTFJCorruptDataException(com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) IOSThread(com.ibm.j9ddr.corereaders.osthread.IOSThread) Properties(java.util.Properties)

Aggregations

IOSThread (com.ibm.j9ddr.corereaders.osthread.IOSThread)6 DTFJCorruptDataException (com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)1 CorruptDataException (com.ibm.j9ddr.CorruptDataException)1 DataUnavailableException (com.ibm.j9ddr.DataUnavailableException)1 IOSStackFrame (com.ibm.j9ddr.corereaders.osthread.IOSStackFrame)1 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TreeMap (java.util.TreeMap)1