Search in sources :

Example 1 with JVMNotFoundException

use of com.ibm.j9ddr.exceptions.JVMNotFoundException in project openj9 by eclipse.

the class VMDataFactory method getStructureDataFile.

private static ImageInputStream getStructureDataFile(IProcess process, long start) throws IOException {
    try {
        if (process.getPlatform() == Platform.ZOS) {
            return getStructureDataFileFromSymbol(process);
        } else {
            return getStructureDataFileFromRASEyecatcher(process, start);
        }
    } catch (JVMNotFoundException e) {
        String structureFileName = System.getProperty(STRUCTUREFILE_PROPERTY);
        if (structureFileName != null) {
            // for it in the blob archive
            try {
                return getStructureDataFromFile(structureFileName, process);
            } catch (Exception e1) {
                IOException ioe = new IOException();
                ioe.initCause(e);
                throw ioe;
            }
        } else if (process.getPlatform() == Platform.ZOS) {
            try {
                return getStructureDataFileFromSymbol(process);
            } catch (JVMNotFoundException e1) {
                // Check for system property to force searching for JVMs via the eyecatcher
                if (System.getProperty(SEARCHEYECATCHER_PROPERTY) != null) {
                    return getStructureDataFileFromRASEyecatcher(process, start);
                } else {
                    // no system property set so overrride
                    throw e1;
                }
            }
        } else {
            throw e;
        }
    }
}
Also used : JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) IOException(java.io.IOException) JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) CorruptStructuresException(com.ibm.j9ddr.exceptions.CorruptStructuresException) UnknownArchitectureException(com.ibm.j9ddr.exceptions.UnknownArchitectureException) IOException(java.io.IOException) JVMNotDDREnabledException(com.ibm.j9ddr.exceptions.JVMNotDDREnabledException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MissingDDRStructuresException(com.ibm.j9ddr.exceptions.MissingDDRStructuresException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with JVMNotFoundException

use of com.ibm.j9ddr.exceptions.JVMNotFoundException in project openj9 by eclipse.

the class VMDataFactory method getStructureDataFileFromRASEyecatcher.

private static ImageInputStream getStructureDataFileFromRASEyecatcher(IProcess process, long start) throws IOException {
    try {
        long address = process.findPattern(eyecatcher, 1, start);
        while (address != -1) {
            long bitPattern = process.getLongAt(address + BIT_PATTERNS_OFFSET);
            if (bitPattern == integrityCheck) {
                return foundRAS(process, address);
            }
            address = process.findPattern(eyecatcher, 1, address + eyecatcher.length);
        }
        // Can't find RAS structure, bail out
        throw new JVMNotFoundException(process, "Could not find J9RAS structure. No Java in process?");
    } catch (MemoryFault e) {
        // put the stack trace to the log
        Logger logger = Logger.getLogger(LoggerNames.LOGGER_STRUCTURE_READER);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        logger.logp(FINE, null, null, sw.toString());
        throw new IOException(e.getMessage());
    }
}
Also used : JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) MemoryFault(com.ibm.j9ddr.corereaders.memory.MemoryFault) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Logger(java.util.logging.Logger) PrintWriter(java.io.PrintWriter)

Example 3 with JVMNotFoundException

use of com.ibm.j9ddr.exceptions.JVMNotFoundException in project openj9 by eclipse.

the class VMDataFactory method getBlobFromLibrary.

/**
 * Try and determine a blob by scanning the process.
 * This can be very expensive and should be the last option tried.
 *
 * @param process process to scan
 * @return a blob if one can be identified, null if not
 */
private static ImageInputStream getBlobFromLibrary(IProcess process, StructureHeader header) throws JVMNotFoundException {
    try {
        if (header != null) {
            IBlobFactory factory = BlobFactory.getInstance();
            Platforms platform = null;
            switch(process.getPlatform()) {
                case LINUX:
                    platform = (process.bytesPerPointer() == 4) ? Platforms.xi32 : Platforms.xa64;
                    break;
                default:
                    break;
            }
            if (platform != null) {
                int[] data = header.getBlobVersionArray();
                return factory.getBlob(platform, header.getPackageID(), data[2], data[1], data[0]);
            }
        }
        return null;
    } catch (Exception e) {
        throw new JVMNotFoundException(process, e);
    }
}
Also used : JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) Platforms(com.ibm.j9ddr.blobs.IBlobFactory.Platforms) IBlobFactory(com.ibm.j9ddr.blobs.IBlobFactory) JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) CorruptStructuresException(com.ibm.j9ddr.exceptions.CorruptStructuresException) UnknownArchitectureException(com.ibm.j9ddr.exceptions.UnknownArchitectureException) IOException(java.io.IOException) JVMNotDDREnabledException(com.ibm.j9ddr.exceptions.JVMNotDDREnabledException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MissingDDRStructuresException(com.ibm.j9ddr.exceptions.MissingDDRStructuresException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with JVMNotFoundException

use of com.ibm.j9ddr.exceptions.JVMNotFoundException in project openj9 by eclipse.

the class DDRInteractive method locateRuntimes.

private void locateRuntimes(ICore reader) {
    currentCore = reader;
    Collection<? extends IAddressSpace> spaces = reader.getAddressSpaces();
    for (IAddressSpace thisSpace : spaces) {
        // indicates if a context has been allocated for the address space
        boolean hasCtxBeenAddedForAS = false;
        Collection<? extends IProcess> processes = thisSpace.getProcesses();
        for (IProcess thisProcess : processes) {
            hasCtxBeenAddedForAS = true;
            try {
                IVMData vmData = VMDataFactory.getVMData(thisProcess);
                if (vmData != null) {
                    contexts.add(new Context(thisProcess, vmData, nonVMCommands));
                } else {
                    addMissingJVMToContexts(thisProcess);
                }
            } catch (JVMNotDDREnabledException e) {
                addMissingJVMToContexts(thisProcess);
            } catch (JVMNotFoundException e) {
                addMissingJVMToContexts(thisProcess);
            } catch (MissingDDRStructuresException e) {
                addMissingJVMToContexts(thisProcess);
            } catch (IOException e) {
                System.err.println("Problem searching for VMData in process " + thisProcess);
                e.printStackTrace();
                // put the stack trace to the log
                Logger logger = Logger.getLogger(LoggerNames.LOGGER_INTERACTIVE_CONTEXT);
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);
                logger.logp(FINE, null, null, sw.toString());
            }
        }
        if (!hasCtxBeenAddedForAS) {
            ASNoProcess as = new ASNoProcess(thisSpace);
            addMissingJVMToContexts(as);
        }
    }
    if (contexts.size() == 0) {
        throw new RuntimeException("Couldn't find any address spaces in this dump");
    } else {
        // default to the first address space
        currentContext = contexts.get(0);
        for (Context ctx : contexts) {
            // but if there is one with a JVM in it, set it to that
            if (!(ctx.vmData instanceof MissingVMData)) {
                currentContext = ctx;
                break;
            }
        }
    }
}
Also used : IAddressSpace(com.ibm.j9ddr.corereaders.memory.IAddressSpace) IOException(java.io.IOException) Logger(java.util.logging.Logger) IVMData(com.ibm.j9ddr.IVMData) JVMNotDDREnabledException(com.ibm.j9ddr.exceptions.JVMNotDDREnabledException) JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) StringWriter(java.io.StringWriter) MissingDDRStructuresException(com.ibm.j9ddr.exceptions.MissingDDRStructuresException) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess) PrintWriter(java.io.PrintWriter)

Example 5 with JVMNotFoundException

use of com.ibm.j9ddr.exceptions.JVMNotFoundException in project openj9 by eclipse.

the class VMDataFactory method getAllVMData.

// TODO - fix this for z/OS which will require noting which RAS symbols have already been found in the core
/**
 * Finds all of the blobs in a given process and wraps them in a IVMData structure.
 *
 * @param process process to scan
 * @return all located blobs
 * @throws IOException re-throws IOExceptions
 */
public static synchronized List<IVMData> getAllVMData(IProcess process) throws IOException {
    List<IVMData> cachedVMData = vmDataCache.get(process);
    if (cachedVMData != null) {
        return cachedVMData;
    }
    // nothing in the cache for this process, so need to scan
    // Get an ImageInputStream on the Structure Offset Data.  This may or may not be in the core file itself.
    List<IVMData> data = new ArrayList<IVMData>();
    ImageInputStream in = null;
    // End Of Memory
    boolean EOM = false;
    long address = 0;
    j9RASAddress = 0;
    while (!EOM) {
        try {
            address = j9RASAddress + 1;
            in = getStructureDataFile(process, address);
            if (in != null) {
                EOM = !(in instanceof IMemoryImageInputStream);
                IVMData vmdata = getVMData(process, in);
                data.add(vmdata);
                if (vmdata.getClassLoader().getHeader().getCoreVersion() == 1) {
                    // version 1 does not support multiple blobs
                    EOM = true;
                    break;
                }
            } else {
                EOM = true;
            }
        } catch (JVMNotFoundException e) {
            // no more JVMs were found
            EOM = true;
        } catch (JVMNotDDREnabledException e) {
            // an older JVM was found, so ignore that and carry on looking
            // on z/OS a failure with the j9ras symbol resolution aborts the scan
            EOM = EOM | (process.getPlatform() == Platform.ZOS);
            continue;
        } catch (MissingDDRStructuresException e) {
            // cannot process as the structures are missing
            // on z/OS a failure with the j9ras symbol resolution aborts the scan
            EOM = EOM | (process.getPlatform() == Platform.ZOS);
            continue;
        } catch (CorruptStructuresException e) {
            // cannot process as the structures are corrupt and cannot be read
            // on z/OS a failure with the j9ras symbol resolution aborts the scan
            EOM = EOM | (process.getPlatform() == Platform.ZOS);
            continue;
        } catch (IOException e) {
            continue;
        }
    }
    // scan is switched off for Java-only applications (specifically jdmpview) via a system property.
    if ((System.getProperty(NOEXTRASEARCHFORNODE_PROPERTY) == null) && (data.size() == 0)) {
        StructureHeader header = null;
        try {
            header = findNodeVersion(process);
        } catch (Exception e) {
            if (e instanceof IOException) {
                throw (IOException) e;
            } else {
                IOException ioe = new IOException();
                // avoid use of IOException(throwable) to be compatible with J5
                ioe.initCause(e);
                throw ioe;
            }
        }
        if (header != null) {
            in = getBlobFromLibrary(process, header);
            if (in != null) {
                IVMData vmdata = getVMData(process, in);
                data.add(vmdata);
            }
        }
    }
    vmDataCache.put(process, data);
    return data;
}
Also used : MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) IMemoryImageInputStream(com.ibm.j9ddr.corereaders.memory.IMemoryImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) CorruptStructuresException(com.ibm.j9ddr.exceptions.CorruptStructuresException) UnknownArchitectureException(com.ibm.j9ddr.exceptions.UnknownArchitectureException) IOException(java.io.IOException) JVMNotDDREnabledException(com.ibm.j9ddr.exceptions.JVMNotDDREnabledException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MissingDDRStructuresException(com.ibm.j9ddr.exceptions.MissingDDRStructuresException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JVMNotDDREnabledException(com.ibm.j9ddr.exceptions.JVMNotDDREnabledException) JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) IMemoryImageInputStream(com.ibm.j9ddr.corereaders.memory.IMemoryImageInputStream) CorruptStructuresException(com.ibm.j9ddr.exceptions.CorruptStructuresException) MissingDDRStructuresException(com.ibm.j9ddr.exceptions.MissingDDRStructuresException)

Aggregations

JVMNotFoundException (com.ibm.j9ddr.exceptions.JVMNotFoundException)5 IOException (java.io.IOException)5 JVMNotDDREnabledException (com.ibm.j9ddr.exceptions.JVMNotDDREnabledException)4 MissingDDRStructuresException (com.ibm.j9ddr.exceptions.MissingDDRStructuresException)4 CorruptStructuresException (com.ibm.j9ddr.exceptions.CorruptStructuresException)3 UnknownArchitectureException (com.ibm.j9ddr.exceptions.UnknownArchitectureException)3 FileNotFoundException (java.io.FileNotFoundException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Logger (java.util.logging.Logger)2 IVMData (com.ibm.j9ddr.IVMData)1 IBlobFactory (com.ibm.j9ddr.blobs.IBlobFactory)1 Platforms (com.ibm.j9ddr.blobs.IBlobFactory.Platforms)1 IAddressSpace (com.ibm.j9ddr.corereaders.memory.IAddressSpace)1 IMemoryImageInputStream (com.ibm.j9ddr.corereaders.memory.IMemoryImageInputStream)1 IProcess (com.ibm.j9ddr.corereaders.memory.IProcess)1 MemoryFault (com.ibm.j9ddr.corereaders.memory.MemoryFault)1 ArrayList (java.util.ArrayList)1