Search in sources :

Example 1 with BuilderFailureException

use of com.ibm.dtfj.javacore.builder.BuilderFailureException in project openj9 by eclipse.

the class ParserController method parse.

/**
 * Support for one image builder parsing javacore data for only one runtime.
 * Multiple runtime support will require overriding this method in a subclass.
 */
public Image parse(IScannerManager scannerManager) throws ParserException {
    ILookAheadBuffer lookAhead = scannerManager.getLookAheadBuffer();
    // For error reporting
    StringBuffer sb = new StringBuffer();
    try {
        for (int i = 1; i <= 2 && i <= lookAhead.maxDepth(); ++i) {
            IParserToken token = lookAhead.lookAhead(i);
            if (token != null) {
                sb.append(token.getValue());
            }
        }
    } catch (IOException e) {
    } catch (IndexOutOfBoundsException e) {
    } catch (ScannerException e) {
        throw new ParserException(e);
    }
    // Don't get too much data
    sb.setLength(Math.min(300, sb.length()));
    String first = sb.toString();
    IImageBuilder imageBuilder = null;
    try {
        imageBuilder = generateImageBuilder();
    } catch (BuilderFailureException e) {
        throw new ParserException(e);
    }
    boolean anyMatched = false;
    try {
        lookAhead.init();
        for (Iterator it = fFramework.iterator(); it.hasNext(); ) {
            processUnknownData(lookAhead);
            ISectionParser sectionParser = (ISectionParser) it.next();
            sectionParser.readIntoDTFJ(lookAhead, imageBuilder);
            /*
				 * Retrieve the error log.
				 */
            Iterator errors = sectionParser.getErrors();
            if ((fListener != null) && errors.hasNext()) {
                while (errors.hasNext()) {
                    fListener.handleEvent(errors.next().toString());
                }
            }
            anyMatched |= sectionParser.anyMatched();
        }
    } catch (IOException e) {
        /*
			 * If IO exception encountered, parser may have reached a non-recoverable state, so for now no
			 * point in continuing the parsing process.
			 */
        e.printStackTrace();
    } catch (RuntimeException e) {
        /*
			 * For internal tracing purposes (Eclipse catches runtime exceptions,
			 * and they get hard to track even with the eclipse error log view).
			 */
        e.printStackTrace();
        throw e;
    } catch (ScannerException e) {
        throw new ParserException(e);
    }
    if (!anyMatched) {
        throw new ParserException("Not a javacore file. First line: " + first);
    }
    return imageBuilder.getImage();
}
Also used : ParserException(com.ibm.dtfj.javacore.parser.framework.parser.ParserException) ISectionParser(com.ibm.dtfj.javacore.parser.framework.parser.ISectionParser) ILookAheadBuffer(com.ibm.dtfj.javacore.parser.framework.parser.ILookAheadBuffer) IOException(java.io.IOException) ScannerException(com.ibm.dtfj.javacore.parser.framework.scanner.ScannerException) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) IParserToken(com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken) Iterator(java.util.Iterator) IImageBuilder(com.ibm.dtfj.javacore.builder.IImageBuilder)

Example 2 with BuilderFailureException

use of com.ibm.dtfj.javacore.builder.BuilderFailureException in project openj9 by eclipse.

the class ClassLoaderSectionParser method processClassLoaders.

/**
 * Grammar subsection 2CLTEXTCLLOAD
 * Although classes must be associated with classloaders in DTFJ, if a class loader
 * is not built due to corruption of data, yet a class list still exists for it,
 * the parser still has to process the class data from the buffer any way,
 * even though it may not be added to
 * DTFJ by the builder.
 */
private void processClassLoaders(IAttributeValueMap results) throws ParserException {
    JavaClassLoader loader = null;
    String cl_name = results.getTokenValue(CL_ATT__NAME);
    long cl_address = results.getLongValue(CL_ATT_ADDRESS);
    try {
        loader = fRuntimeBuilder.addClassLoader(cl_name, cl_address, cl_address);
    } catch (BuilderFailureException e) {
        handleError("Failed to add class loader: " + cl_name + " " + cl_address + " ", e);
    }
    while ((results = processTagLineOptional(T_3CLTEXTCLASS)) != null) {
        String className = results.getTokenValue(CLASS_ATT_NAME);
        long classID = results.getLongValue(CLASS_ATT_ADDRESS);
        try {
            fRuntimeBuilder.addClass(loader, className, classID, IBuilderData.NOT_AVAILABLE, null);
        } catch (BuilderFailureException e) {
            handleError("Failed to add class: " + className + " " + classID + " ", e);
        }
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException)

Example 3 with BuilderFailureException

use of com.ibm.dtfj.javacore.builder.BuilderFailureException in project openj9 by eclipse.

the class MonitorSectionParser method monitorsInUse.

/**
 * Will create monitor objects for each 2LKMONINUSE encountered.
 * <br>
 * <br>
 * For every one of these tags encountered, a valid monitor ID must be parsed
 * in order to create a valid monitor object. If a valid monitor ID is not
 * encountered for a particular 2LKMONINUSE tag, an exception is caught and
 * handled by the error handler. However the operation does not stop until
 * all 2LKMONINUSE tags are parsed, whether a valid monitor object is created or not,
 * unless the error handler decides to.
 * <br>
 * @throws ParserException
 */
private void monitorsInUse() throws ParserException {
    IAttributeValueMap results = null;
    while ((results = processTagLineOptional(T_2LKMONINUSE)) != null) {
        // Ignore inflated monitor for now, use system monitor as the monitor ID
        long monitorID = results.getLongValue(SYSTEM_MONITOR);
        long objectID = IBuilderData.NOT_AVAILABLE;
        String className = null;
        long monitorThreadID = IBuilderData.NOT_AVAILABLE;
        if ((results = processTagLineRequired(T_3LKMONOBJECT)) != null) {
            className = results.getTokenValue(MONITOR_OBJECT_FULL_JAVA_NAME);
            className = fixMonitorClassName(className);
            objectID = results.getLongValue(MONITOR_OBJECT_ADDRESS);
            monitorThreadID = results.getLongValue(MONITOR_THREAD_ID);
        }
        try {
            /*
				 * A monitor object must be created if the 2LKMONINUSE tag is encountered, else an 
				 * error encountered.
				 */
            generateMonitor(null, monitorID, objectID, className, monitorThreadID);
        } catch (BuilderFailureException e) {
            handleError("Could not add monitor to builder: " + monitorID, e);
        }
    }
}
Also used : BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) IAttributeValueMap(com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)

Example 4 with BuilderFailureException

use of com.ibm.dtfj.javacore.builder.BuilderFailureException in project openj9 by eclipse.

the class MonitorSovSectionParserPart method computeSovRule.

public void computeSovRule(String sovRuleID, ILookAheadBuffer lookAheadBuffer) throws ParserException {
    setLookAheadBuffer(lookAheadBuffer);
    setTagManager(J9TagManager.getCurrent());
    if (sovRuleID.equals(T_1LKREGMONDUMP)) {
        IAttributeValueMap results;
        if ((results = processTagLineOptional(LK_FLAT_MON_DUMP)) != null) {
            HashMap threads = new HashMap();
            while ((results = processTagLineOptional(LK_FLAT_MON)) != null) {
                int flatid = results.getIntValue(MONITOR_FLAT_ID);
                String name = results.getTokenValue(MONITOR_THREAD_NAME);
                // Remove quotes
                if (name != null && name.length() >= 2) {
                    name = name.substring(1, name.length() - 1);
                }
                long tid = results.getLongValue(MONITOR_THREAD_ID);
                long ee = results.getLongValue(MONITOR_THREAD_EE);
                // Remember the flat thread id for later
                threads.put(new Integer(flatid), new Long(tid));
                try {
                    fRuntimeBuilder.addJavaThread(null, name, IBuilderData.NOT_AVAILABLE, tid, IBuilderData.NOT_AVAILABLE, ee, "", IBuilderData.NOT_AVAILABLE, 0, null);
                } catch (BuilderFailureException e) {
                // Expect a failure, but the JNIEnv will be remembered
                }
            }
            results = processTagLineRequired(LK_OBJ_MON_DUMP);
            do {
                if ((results = processTagLineOptional(LK_INFLATED_MON)) != null) {
                    processTagLineRequired(LK_INFL_DETAILS);
                } else {
                    if ((results = processTagLineOptional(LK_FLAT_LOCKED)) != null) {
                        String className = results.getTokenValue(MONITOR_OBJECT_FULL_JAVA_NAME);
                        className = MonitorSectionParser.fixMonitorClassName(className);
                        long objectID = results.getLongValue(MONITOR_OBJECT_ADDRESS);
                        long monitorID = results.getLongValue(MONITOR_OBJECT_ADDRESS);
                        results = processTagLineRequired(LK_FLAT_DETAILS);
                        int flatid = results.getIntValue(MONITOR_FLAT_ID);
                        Object p = threads.get(new Integer(flatid));
                        long threadID = p instanceof Long ? ((Long) p).longValue() : IBuilderData.NOT_AVAILABLE;
                        try {
                            if (monitorID != IBuilderData.NOT_AVAILABLE) {
                                // A valid monitor ID is required to build a monitor
                                fRuntimeBuilder.addJavaMonitor(null, monitorID, objectID, className, threadID);
                            }
                        } catch (BuilderFailureException e) {
                            handleError("Could not add monitor to builder: " + objectID, e);
                        }
                    }
                }
            } while (results != null);
        }
    }
}
Also used : BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) IAttributeValueMap(com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap) HashMap(java.util.HashMap)

Example 5 with BuilderFailureException

use of com.ibm.dtfj.javacore.builder.BuilderFailureException in project openj9 by eclipse.

the class EnvironmentSectionParser method parseUserArgs.

/**
 * Parse the user args information (1CIUSERARGS and 2CIUSERARG lines)
 * @throws ParserException
 */
private void parseUserArgs() throws ParserException {
    IAttributeValueMap results = null;
    if ((results = processTagLineRequired(T_1CIUSERARGS)) != null) {
        boolean added = false;
        while ((results = processTagLineOptional(T_2CIUSERARG)) != null) {
            if (!added) {
                // Delay creating init args until we find some args
                added = true;
                try {
                    fRuntimeBuilder.addVMInitArgs();
                } catch (BuilderFailureException e) {
                    handleError("Failed to add JavaVMInitArgs to builder: ", e);
                }
            }
            String argString = results.getTokenValue(ARG_STRING);
            long extraInfo = results.getLongValue(ARG_EXTRA);
            try {
                if (extraInfo == IBuilderData.NOT_AVAILABLE) {
                    if (argString != null) {
                        fRuntimeBuilder.addVMOption(argString);
                    }
                } else {
                    fRuntimeBuilder.addVMOption(argString, extraInfo);
                }
            } catch (BuilderFailureException e) {
                handleError("Failed to add VM option to builder: " + argString + " ", e);
            }
        }
    }
}
Also used : BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) IAttributeValueMap(com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)

Aggregations

BuilderFailureException (com.ibm.dtfj.javacore.builder.BuilderFailureException)13 ImagePointer (com.ibm.dtfj.image.ImagePointer)7 JCInvalidArgumentsException (com.ibm.dtfj.java.javacore.JCInvalidArgumentsException)7 JCJavaClass (com.ibm.dtfj.java.javacore.JCJavaClass)5 JCJavaObject (com.ibm.dtfj.java.javacore.JCJavaObject)4 IAttributeValueMap (com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)4 Iterator (java.util.Iterator)3 JCJavaClassLoader (com.ibm.dtfj.java.javacore.JCJavaClassLoader)2 JCJavaThread (com.ibm.dtfj.java.javacore.JCJavaThread)2 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 ImageRegister (com.ibm.dtfj.image.ImageRegister)1 ImageSection (com.ibm.dtfj.image.ImageSection)1 ImageThread (com.ibm.dtfj.image.ImageThread)1 JCImageRegister (com.ibm.dtfj.image.javacore.JCImageRegister)1 JCImageThread (com.ibm.dtfj.image.javacore.JCImageThread)1 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 JavaThread (com.ibm.dtfj.java.JavaThread)1 JCJavaLocation (com.ibm.dtfj.java.javacore.JCJavaLocation)1 JCJavaMethod (com.ibm.dtfj.java.javacore.JCJavaMethod)1