8324657: Intermittent OOME on exception message create

Reviewed-by: lancea, iris, naoto
This commit is contained in:
Roger Riggs 2024-01-25 14:51:50 +00:00
parent e709842eae
commit ffe3bb6763

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -1987,9 +1987,8 @@ public class ObjectInputStream
resolveEx = ex; resolveEx = ex;
} catch (IllegalAccessError aie) { } catch (IllegalAccessError aie) {
throw new InvalidClassException(aie.getMessage(), aie); throw new InvalidClassException(aie.getMessage(), aie);
} catch (OutOfMemoryError memerr) { } catch (OutOfMemoryError oome) {
throw new InvalidObjectException("Proxy interface limit exceeded: " + throw genInvalidObjectException(oome, ifaces);
Arrays.toString(ifaces), memerr);
} }
// Call filterCheck on the class before reading anything else // Call filterCheck on the class before reading anything else
@ -2001,9 +2000,8 @@ public class ObjectInputStream
totalObjectRefs++; totalObjectRefs++;
depth++; depth++;
desc.initProxy(cl, resolveEx, readClassDesc(false)); desc.initProxy(cl, resolveEx, readClassDesc(false));
} catch (OutOfMemoryError memerr) { } catch (OutOfMemoryError oome) {
throw new InvalidObjectException("Proxy interface limit exceeded: " + throw genInvalidObjectException(oome, ifaces);
Arrays.toString(ifaces), memerr);
} finally { } finally {
depth--; depth--;
} }
@ -2013,6 +2011,14 @@ public class ObjectInputStream
return desc; return desc;
} }
// Generate an InvalidObjectException for an OutOfMemoryError
// Use String.concat() to avoid string formatting invoke dynamic
private static InvalidObjectException genInvalidObjectException(OutOfMemoryError oome,
String[] ifaces) {
return new InvalidObjectException("Proxy interface limit exceeded: "
.concat(Arrays.toString(ifaces)), oome);
}
/** /**
* Reads in and returns class descriptor for a class that is not a dynamic * Reads in and returns class descriptor for a class that is not a dynamic
* proxy class. Sets passHandle to class descriptor's assigned handle. If * proxy class. Sets passHandle to class descriptor's assigned handle. If