Work on Java JIT Error

We seem to be prone to a weird bug in our Java environment. We now had two cases of the same “cannot be” exception; in one case, the problem occurred 42,551 times during 48 minutes in the process, and then spontaneously cleared.

The failed code is triggered by this line:

return String.format("%1d%XY%d", source, System.currentTimeMillis(), quoteID);

where int source = 0and long quoteID = 44386874(for example).

The exception is:

java.util.UnknownFormatConversionException: Conversion = 'd'
        at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2605)
        at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2633)
        at java.util.Formatter.parse(Formatter.java:2479)
        at java.util.Formatter.format(Formatter.java:2413)
        at java.util.Formatter.format(Formatter.java:2366)
        at java.lang.String.format(String.java:2770)

Code validation 'd'should never raise this exception.

The best explanation we came up with is that the JIT compiler generates bad bytecode, but in the subsequent re-JIT it writes good code.

Does anyone have any experience on how to work around / diagnose such a problem?

Roger.

+3
6

, JIT.

, ?

, JIT?

, , , :

private char java.util.Formatter.FormatSpecifier.conversion(String s) {
    c = s.charAt(0);
    if (!dt) {
    if (!Conversion.isValid(c))
        throw new UnknownFormatConversionException(String.valueOf(c));

        ///////..........
}

:

static boolean java.util.Formatter.Conversion.isValid(char c) {
    return (isGeneral(c) || isInteger(c) || isFloat(c) || isText(c)
        || c == 't' || c == 'c');
}

d - , isValid() True.

, , . /. , . , , JVM.

- JIT.

+7

, JIT, - . JIT, , :

for (int i = 0; i < 100000; i++) {
        String.format("%1d%XY%d", source, System.currentTimeMillis(), quoteID);
    }
+1

! . memtest86+. Ubuntu cd.

+1

, , java.util.Formatter , - , 'd'. Java ?

0

:

final long time;

time = System.currentTimeMillis();

try
{
    return String.format("%1d%XY%d", source, time, quoteID);
}
catch(final UnknownFormatConversionExceptio ex)
{
    // log the source
    // log the time
    // log the quoteID
    throw ex;
}

, String.format , , ( , , , , ).

, , . , ( , , ...).

0
source

Are you sure that the “d” in this code is really ASCII d, and not some Unicode character that looks like d?

(A long shot, but something strange happened.)

0
source

Source: https://habr.com/ru/post/1723899/


All Articles