Search in sources :

Example 1 with ParserException

use of com.ibm.dtfj.javacore.parser.framework.parser.ParserException 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 ParserException

use of com.ibm.dtfj.javacore.parser.framework.parser.ParserException in project openj9 by eclipse.

the class EnvironmentSectionParser method parseVersion.

/**
 * Parse the version information (1CIJAVAVERSION, and lines)
 * @throws ParserException
 */
private void parseVersion() throws ParserException {
    IAttributeValueMap results = null;
    // Process the version lines
    if ((results = processTagLineOptional(T_1CIJAVAVERSION)) != null) {
        int pointerSize = results.getIntValue(ICommonTypes.POINTER_SIZE);
        if (pointerSize != IBuilderData.NOT_AVAILABLE) {
            fImageProcessBuilder.setPointerSize(pointerSize);
        }
        String javaversion = results.getTokenValue(ARG_STRING);
        String checkString = "j2re 1.";
        // check that the core we are processing is from Java 5 or later
        if ((javaversion.toLowerCase().startsWith(checkString)) && (javaversion.length() > (checkString.length() + 1))) {
            String number = javaversion.substring(checkString.length(), javaversion.indexOf('.', checkString.length() + 1));
            try {
                int version = Integer.parseInt(number);
                if (version <= 4) {
                    throw new ParserException("Javacore files earlier than 1.5.0 are not supported");
                }
            } catch (NumberFormatException e) {
                handleError("Error determining Java version", e);
            }
        }
        results = processTagLineOptional(T_1CIVMVERSION);
        if (results != null) {
            javaversion = buildVersionString(javaversion, results);
        }
        results = processTagLineOptional(T_1CIJITVERSION);
        if (results != null) {
            javaversion = buildVersionString(javaversion, results);
        }
        results = processTagLineOptional(T_1CIGCVERSION);
        if (results != null) {
            javaversion = buildVersionString(javaversion, results);
        }
        if (javaversion != null) {
            fRuntimeBuilder.setJavaVersion(javaversion);
        }
    } else {
        processTagLineOptional(T_1CIVMVERSION);
        processTagLineOptional(T_1CIJITVERSION);
        processTagLineOptional(T_1CIGCVERSION);
    }
    results = processTagLineOptional(T_1CIJITMODES);
    if (results != null) {
        IParserToken token = results.getToken(JIT_MODE);
        if (token != null) {
            String value = token.getValue().trim();
            if (value.toLowerCase().startsWith("unavailable")) {
                // JIT was disabled with -Xint
                fRuntimeBuilder.setJITEnabled(false);
            } else {
                // JIT was operational but still could be disabled if -Xnojit was specified
                fRuntimeBuilder.setJITEnabled(true);
                String[] props = value.split(",");
                for (int i = 0; i < props.length; i++) {
                    // trim any white space
                    String item = props[i].trim();
                    int index = item.indexOf(' ');
                    if (index == -1) {
                        fRuntimeBuilder.addJITProperty(props[i], "<default value>");
                    } else {
                        String name = item.substring(0, index);
                        String pvalue = item.substring(index + 1);
                        fRuntimeBuilder.addJITProperty(name, pvalue);
                    }
                }
            }
        }
    }
    processTagLineOptional(T_1CIRUNNINGAS);
    // 1CISTARTTIME   JVM start time: 2015/07/17 at 13:31:04:547
    if ((results = processTagLineOptional(T_1CISTARTTIME)) != null) {
        String dateTimeString = results.getTokenValue(START_TIME);
        if (dateTimeString != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd 'at' HH:mm:ss:SSS");
            Date startDate = sdf.parse(dateTimeString, new ParsePosition(0));
            if (startDate != null) {
                fRuntimeBuilder.setStartTime(startDate.getTime());
            }
        }
    }
    // 1CISTARTNANO   JVM start nanotime: 3534023113503
    if ((results = processTagLineOptional(T_1CISTARTNANO)) != null) {
        String nanoTimeString = results.getTokenValue(START_NANO);
        if (nanoTimeString != null) {
            fRuntimeBuilder.setStartTimeNanos(Long.parseLong(nanoTimeString));
        }
    }
    if ((results = processTagLineOptional(T_1CIPROCESSID)) != null) {
        String pidStr = results.getTokenValue(PID_STRING);
        if (pidStr != null) {
            fImageBuilder.getCurrentAddressSpaceBuilder().getCurrentImageProcessBuilder().setID(pidStr);
        }
    }
    String cmdLine = null;
    if ((results = processTagLineOptional(T_1CICMDLINE)) != null) {
        cmdLine = results.getTokenValue(CMD_LINE);
        if ("[not available]".equals(cmdLine)) {
            cmdLine = null;
        } else {
            fImageProcessBuilder.setCommandLine(cmdLine);
        }
    }
    String home = null;
    if ((results = processTagLineOptional(T_1CIJAVAHOMEDIR)) != null) {
        ;
        home = results.getTokenValue(ARG_STRING);
    }
    String dlldir = null;
    if ((results = processTagLineOptional(T_1CIJAVADLLDIR)) != null) {
        ;
        dlldir = results.getTokenValue(ARG_STRING);
    }
    if (cmdLine != null) {
        if (dlldir != null) {
            // See if the command line starts with part of Java directory - if so add rest of path
            // Find position of first path separator
            int min1 = cmdLine.indexOf('/') + 1;
            if (min1 == 0)
                min1 = cmdLine.length();
            int min2 = cmdLine.indexOf('\\') + 1;
            if (min2 == 0)
                min2 = cmdLine.length();
            int min = Math.min(min1, min2);
            for (int i = cmdLine.length(); i > min; --i) {
                String prefix = cmdLine.substring(0, i);
                int j = dlldir.indexOf(prefix);
                if (j >= 0) {
                    cmdLine = dlldir.substring(0, j) + cmdLine;
                    break;
                }
            }
        }
        // Allow for spaces in the path by skipping over spaces in javadlldir
        int i = 0;
        if (dlldir != null) {
            for (i = dlldir.length(); i >= 0; --i) {
                if (cmdLine.startsWith(dlldir.substring(0, i))) {
                    break;
                }
            }
        }
        // Look for the rest of the command line
        int sp = cmdLine.indexOf(' ', i);
        String exec;
        if (sp >= 0) {
            exec = cmdLine.substring(0, sp);
        } else {
            exec = cmdLine;
        }
        ImageModule execMod = fImageProcessBuilder.addLibrary(exec);
        fImageProcessBuilder.setExecutable(execMod);
    }
    processTagLineOptional(T_1CISYSCP);
}
Also used : ParserException(com.ibm.dtfj.javacore.parser.framework.parser.ParserException) IAttributeValueMap(com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap) IParserToken(com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ImageModule(com.ibm.dtfj.image.ImageModule) ParsePosition(java.text.ParsePosition)

Example 3 with ParserException

use of com.ibm.dtfj.javacore.parser.framework.parser.ParserException in project openj9 by eclipse.

the class JavaCoreReader method generateImage.

/**
 * @param input
 *
 * @throws UnsupportedSourceException
 * @throws ParserException
 * @throws IOException
 */
public Image generateImage(InputStream input) throws IOException {
    try {
        byte[] head = new byte[256];
        input.read(head);
        ByteArrayInputStream headByteStream = new ByteArrayInputStream(head);
        Charset cs = getJavaCoreCodePage(headByteStream);
        SequenceInputStream stream = new SequenceInputStream(headByteStream, input);
        // Use default charset if none found
        // Charset.defaultCharset is 5.0, so not usable for 1.4
        Reader reader = cs != null ? new InputStreamReader(stream, cs) : new InputStreamReader(stream);
        List frameworkSections = new DTFJComponentLoader().loadSections();
        IParserController parserController = new ParserController(frameworkSections, fImageBuilderFactory);
        parserController.addErrorListener(new IErrorListener() {

            private Logger logger = Logger.getLogger(ImageFactory.DTFJ_LOGGER_NAME);

            public void handleEvent(String msg) {
                // map errors onto Level.FINE so that DTFJ is silent unless explicitly changed
                logger.fine(msg);
            }
        });
        J9TagManager tagManager = J9TagManager.getCurrent();
        return parserController.parse(fComponents.getScannerManager(reader, tagManager));
    } catch (ParserException e) {
        IOException e1 = new IOException("Error parsing Javacore");
        e1.initCause(e);
        throw e1;
    }
}
Also used : ParserException(com.ibm.dtfj.javacore.parser.framework.parser.ParserException) IParserController(com.ibm.dtfj.javacore.parser.framework.parser.IParserController) InputStreamReader(java.io.InputStreamReader) Charset(java.nio.charset.Charset) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Logger(java.util.logging.Logger) IParserController(com.ibm.dtfj.javacore.parser.framework.parser.IParserController) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IErrorListener(com.ibm.dtfj.javacore.parser.framework.parser.IErrorListener) List(java.util.List)

Example 4 with ParserException

use of com.ibm.dtfj.javacore.parser.framework.parser.ParserException in project openj9 by eclipse.

the class NativeMemorySectionParser method topLevelRule.

protected void topLevelRule() throws ParserException {
    IImageProcessBuilder fImageProcessBuilder = fImageBuilder.getCurrentAddressSpaceBuilder().getCurrentImageProcessBuilder();
    IJavaRuntimeBuilder fRuntimeBuilder = fImageProcessBuilder.getCurrentJavaRuntimeBuilder();
    IAttributeValueMap results = null;
    Stack categoryStack = new Stack();
    processTagLineOptional(T_0MEMUSER);
    while ((results = processMemUserLine()) != null) {
        String name = results.getTokenValue(A_NAME);
        /* If no name available, this is a spacing line */
        if (name == null) {
            continue;
        }
        int depth = results.getIntValue(A_DEPTH);
        while (categoryStack.size() >= depth) {
            categoryStack.pop();
        }
        long deepBytes = parseCommaDelimitedLong(results.getTokenValue(A_DEEP_BYTES));
        long deepAllocations = parseCommaDelimitedLong(results.getTokenValue(A_DEEP_ALLOCATIONS));
        JavaRuntimeMemoryCategory parent = null;
        if (categoryStack.size() > 0) {
            parent = (JavaRuntimeMemoryCategory) categoryStack.peek();
        }
        if (name.equals(OTHER_CATEGORY)) {
            if (parent == null) {
                throw new ParserException("Parse error: Unexpected NULL parent category for \"Other\" memory category");
            }
            fRuntimeBuilder.setShallowCountersForCategory(parent, deepBytes, deepAllocations);
        } else {
            JavaRuntimeMemoryCategory category = fRuntimeBuilder.addMemoryCategory(name, deepBytes, deepAllocations, parent);
            categoryStack.push(category);
        }
    }
}
Also used : ParserException(com.ibm.dtfj.javacore.parser.framework.parser.ParserException) IAttributeValueMap(com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap) JavaRuntimeMemoryCategory(com.ibm.dtfj.java.JavaRuntimeMemoryCategory) IJavaRuntimeBuilder(com.ibm.dtfj.javacore.builder.IJavaRuntimeBuilder) IImageProcessBuilder(com.ibm.dtfj.javacore.builder.IImageProcessBuilder) Stack(java.util.Stack)

Aggregations

ParserException (com.ibm.dtfj.javacore.parser.framework.parser.ParserException)4 IParserToken (com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken)2 IAttributeValueMap (com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)2 IOException (java.io.IOException)2 ImageModule (com.ibm.dtfj.image.ImageModule)1 JavaRuntimeMemoryCategory (com.ibm.dtfj.java.JavaRuntimeMemoryCategory)1 BuilderFailureException (com.ibm.dtfj.javacore.builder.BuilderFailureException)1 IImageBuilder (com.ibm.dtfj.javacore.builder.IImageBuilder)1 IImageProcessBuilder (com.ibm.dtfj.javacore.builder.IImageProcessBuilder)1 IJavaRuntimeBuilder (com.ibm.dtfj.javacore.builder.IJavaRuntimeBuilder)1 IErrorListener (com.ibm.dtfj.javacore.parser.framework.parser.IErrorListener)1 ILookAheadBuffer (com.ibm.dtfj.javacore.parser.framework.parser.ILookAheadBuffer)1 IParserController (com.ibm.dtfj.javacore.parser.framework.parser.IParserController)1 ISectionParser (com.ibm.dtfj.javacore.parser.framework.parser.ISectionParser)1 ScannerException (com.ibm.dtfj.javacore.parser.framework.scanner.ScannerException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 SequenceInputStream (java.io.SequenceInputStream)1 Charset (java.nio.charset.Charset)1