Search in sources :

Example 11 with IParserToken

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

the class LineRule method addAllCharactersAsTokenAndConsumeFirstMatch.

/**
 * Grabs all characters up to the first match specified by the matcher, and adds
 * the latter as a token of a argument-specified type to the internal token list. All the aforementioned characters
 * as well as the first pattern matched are removed from the source buffer. The matched pattern
 * is not included in the token.
 *
 * <br><br>
 * If the token type already exists in the token map, it overwrites the value with the new token.
 * @param type
 * @param matcher
 * @return generated token if match found, or null otherwise
 */
protected IParserToken addAllCharactersAsTokenAndConsumeFirstMatch(String type, Matcher matcher) {
    matcher.reset(fSource);
    IParserToken token = null;
    if (matcher.find()) {
        int startIndex = matcher.start();
        int matchLength = matcher.end() - startIndex;
        token = addAllCharactersAsTokenUntilIndex(type, startIndex, false);
        fSource.delete(0, matchLength);
    }
    return token;
}
Also used : IParserToken(com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken)

Example 12 with IParserToken

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

the class LineRule method addAllCharactersAsTokenUntilFirstMatch.

/**
 * Grabs all characters up to but excluding the first match specified by the matcher,
 * and adds the latter as a token of an argument-specified type.
 *
 * <br><br>
 * If the token type already exists in the token map, it overwrites the value with the new token.
 * @param type
 * @param matcher
 * @return generated token if match found, or null otherwise
 */
protected IParserToken addAllCharactersAsTokenUntilFirstMatch(String type, Matcher matcher) {
    matcher.reset(fSource);
    IParserToken token = null;
    if (matcher.find()) {
        token = addAllCharactersAsTokenUntilIndex(type, matcher.start(), false);
    }
    return token;
}
Also used : IParserToken(com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken)

Example 13 with IParserToken

use of com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken 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 14 with IParserToken

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

the class ParserController method processUnknownData.

/**
 * Will consume unknown data until a recognised section tag is reached. Common tags are also consumed.
 *
 * @param lookAheadBuffer
 * @throws ScannerException
 */
private void processUnknownData(ILookAheadBuffer lookAheadBuffer) throws IOException, ScannerException {
    J9TagManager tagManager = J9TagManager.getCurrent();
    boolean stop = false;
    while (!lookAheadBuffer.allConsumed() && !stop) {
        IParserToken token = lookAheadBuffer.lookAhead(1);
        if (token != null) {
            String type = token.getType();
            if (!tagManager.hasTag(type) || tagManager.isTagInSection(type, ICommonTypes.COMMON)) {
                lookAheadBuffer.consume();
            } else {
                stop = true;
            }
        } else {
            lookAheadBuffer.consume();
        }
    }
}
Also used : IParserToken(com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken)

Example 15 with IParserToken

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

the class JavaCoreAttributeValueMap method getIntValue.

public int getIntValue(String tokenType) {
    IParserToken token = getToken(tokenType);
    int value = IBuilderData.NOT_AVAILABLE;
    if (token != null) {
        value = Integer.decode(token.getValue()).intValue();
    }
    return value;
}
Also used : IParserToken(com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken)

Aggregations

IParserToken (com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken)19 IAttributeValueMap (com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)3 ParserException (com.ibm.dtfj.javacore.parser.framework.parser.ParserException)2 ImageModule (com.ibm.dtfj.image.ImageModule)1 BuilderFailureException (com.ibm.dtfj.javacore.builder.BuilderFailureException)1 IImageBuilder (com.ibm.dtfj.javacore.builder.IImageBuilder)1 ILookAheadBuffer (com.ibm.dtfj.javacore.parser.framework.parser.ILookAheadBuffer)1 ISectionParser (com.ibm.dtfj.javacore.parser.framework.parser.ISectionParser)1 ScannerException (com.ibm.dtfj.javacore.parser.framework.scanner.ScannerException)1 ILineRule (com.ibm.dtfj.javacore.parser.framework.tag.ILineRule)1 LineRule (com.ibm.dtfj.javacore.parser.framework.tag.LineRule)1 IOException (java.io.IOException)1 ParsePosition (java.text.ParsePosition)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 Matcher (java.util.regex.Matcher)1