mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 02:24:40 +02:00
8261160: Add a deserialization JFR event
Co-authored-by: Sean Coffey <coffeys@openjdk.org> Co-authored-by: Chris Hegarty <chegar@openjdk.org> Reviewed-by: coffeys, rriggs, dfuchs, egahlin
This commit is contained in:
parent
a305743cfa
commit
3dc6f52a89
12 changed files with 615 additions and 22 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -48,6 +48,7 @@ import java.util.concurrent.ConcurrentMap;
|
|||
import static java.io.ObjectStreamClass.processQueue;
|
||||
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.event.DeserializationEvent;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
import sun.reflect.misc.ReflectUtil;
|
||||
import sun.security.action.GetBooleanAction;
|
||||
|
@ -1323,9 +1324,12 @@ public class ObjectInputStream
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoke the serialization filter if non-null.
|
||||
* Invokes the serialization filter if non-null.
|
||||
*
|
||||
* If the filter rejects or an exception is thrown, throws InvalidClassException.
|
||||
*
|
||||
* Logs and/or commits a {@code DeserializationEvent}, if configured.
|
||||
*
|
||||
* @param clazz the class; may be null
|
||||
* @param arrayLength the array length requested; use {@code -1} if not creating an array
|
||||
* @throws InvalidClassException if it rejected by the filter or
|
||||
|
@ -1333,11 +1337,12 @@ public class ObjectInputStream
|
|||
*/
|
||||
private void filterCheck(Class<?> clazz, int arrayLength)
|
||||
throws InvalidClassException {
|
||||
// Info about the stream is not available if overridden by subclass, return 0
|
||||
long bytesRead = (bin == null) ? 0 : bin.getBytesRead();
|
||||
RuntimeException ex = null;
|
||||
ObjectInputFilter.Status status = null;
|
||||
|
||||
if (serialFilter != null) {
|
||||
RuntimeException ex = null;
|
||||
ObjectInputFilter.Status status;
|
||||
// Info about the stream is not available if overridden by subclass, return 0
|
||||
long bytesRead = (bin == null) ? 0 : bin.getBytesRead();
|
||||
try {
|
||||
status = serialFilter.checkInput(new FilterValues(clazz, arrayLength,
|
||||
totalObjectRefs, depth, bytesRead));
|
||||
|
@ -1355,12 +1360,24 @@ public class ObjectInputStream
|
|||
status, clazz, arrayLength, totalObjectRefs, depth, bytesRead,
|
||||
Objects.toString(ex, "n/a"));
|
||||
}
|
||||
if (status == null ||
|
||||
status == ObjectInputFilter.Status.REJECTED) {
|
||||
InvalidClassException ice = new InvalidClassException("filter status: " + status);
|
||||
ice.initCause(ex);
|
||||
throw ice;
|
||||
}
|
||||
}
|
||||
DeserializationEvent event = new DeserializationEvent();
|
||||
if (event.shouldCommit()) {
|
||||
event.filterConfigured = serialFilter != null;
|
||||
event.filterStatus = status != null ? status.name() : null;
|
||||
event.type = clazz;
|
||||
event.arrayLength = arrayLength;
|
||||
event.objectReferences = totalObjectRefs;
|
||||
event.depth = depth;
|
||||
event.bytesRead = bytesRead;
|
||||
event.exceptionType = ex != null ? ex.getClass() : null;
|
||||
event.exceptionMessage = ex != null ? ex.getMessage() : null;
|
||||
event.commit();
|
||||
}
|
||||
if (serialFilter != null && (status == null || status == ObjectInputFilter.Status.REJECTED)) {
|
||||
InvalidClassException ice = new InvalidClassException("filter status: " + status);
|
||||
ice.initCause(ex);
|
||||
throw ice;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.internal.event;
|
||||
|
||||
/**
|
||||
* Event details relating to deserialization.
|
||||
*/
|
||||
|
||||
public final class DeserializationEvent extends Event {
|
||||
public boolean filterConfigured;
|
||||
public String filterStatus;
|
||||
public Class<?> type;
|
||||
public int arrayLength;
|
||||
public long objectReferences;
|
||||
public long depth;
|
||||
public long bytesRead;
|
||||
public Class<?> exceptionType;
|
||||
public String exceptionMessage;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue