Lite: Remove intermediary dynamicMethod function trampolines

These hurt performance by adding extra instructions and branches.

PiperOrigin-RevId: 684621860
pull/18747/head
Mark Hansen 2 months ago committed by Copybara-Service
parent c828b84481
commit 25724ab53e
  1. 33
      java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java

@ -86,23 +86,24 @@ public abstract class GeneratedMessageLite<
@Override @Override
@SuppressWarnings("unchecked") // Guaranteed by runtime. @SuppressWarnings("unchecked") // Guaranteed by runtime.
public final Parser<MessageType> getParserForType() { public final Parser<MessageType> getParserForType() {
return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER); return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER, null, null);
} }
@Override @Override
@SuppressWarnings("unchecked") // Guaranteed by runtime. @SuppressWarnings("unchecked") // Guaranteed by runtime.
public final MessageType getDefaultInstanceForType() { public final MessageType getDefaultInstanceForType() {
return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE); return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE, null, null);
} }
@Override @Override
@SuppressWarnings("unchecked") // Guaranteed by runtime. @SuppressWarnings("unchecked") // Guaranteed by runtime.
public final BuilderType newBuilderForType() { public final BuilderType newBuilderForType() {
return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER, null, null);
} }
@SuppressWarnings("unchecked") // Guaranteed by runtime.
MessageType newMutableInstance() { MessageType newMutableInstance() {
return (MessageType) dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); return (MessageType) dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE, null, null);
} }
/** /**
@ -202,11 +203,12 @@ public abstract class GeneratedMessageLite<
markImmutable(); markImmutable();
} }
@SuppressWarnings("unchecked") // Guaranteed by runtime.
protected final < protected final <
MessageType extends GeneratedMessageLite<MessageType, BuilderType>, MessageType extends GeneratedMessageLite<MessageType, BuilderType>,
BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>>
BuilderType createBuilder() { BuilderType createBuilder() {
return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER, null, null);
} }
protected final < protected final <
@ -224,7 +226,7 @@ public abstract class GeneratedMessageLite<
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public final BuilderType toBuilder() { public final BuilderType toBuilder() {
BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER, null, null);
return builder.mergeFrom((MessageType) this); return builder.mergeFrom((MessageType) this);
} }
@ -275,19 +277,6 @@ public abstract class GeneratedMessageLite<
Object arg0, Object arg0,
Object arg1); Object arg1);
/** Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding. */
@CanIgnoreReturnValue
protected Object dynamicMethod(
MethodToInvoke method,
Object arg0) {
return dynamicMethod(method, arg0, null);
}
/** Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding. */
protected Object dynamicMethod(MethodToInvoke method) {
return dynamicMethod(method, null, null);
}
void clearMemoizedSerializedSize() { void clearMemoizedSerializedSize() {
setMemoizedSerializedSize(UNINITIALIZED_SERIALIZED_SIZE); setMemoizedSerializedSize(UNINITIALIZED_SERIALIZED_SIZE);
} }
@ -355,7 +344,7 @@ public abstract class GeneratedMessageLite<
/** Constructs a {@link MessageInfo} for this message type. */ /** Constructs a {@link MessageInfo} for this message type. */
Object buildMessageInfo() throws Exception { Object buildMessageInfo() throws Exception {
return dynamicMethod(MethodToInvoke.BUILD_MESSAGE_INFO); return dynamicMethod(MethodToInvoke.BUILD_MESSAGE_INFO, null, null);
} }
private static Map<Class<?>, GeneratedMessageLite<?, ?>> defaultInstanceMap = private static Map<Class<?>, GeneratedMessageLite<?, ?>> defaultInstanceMap =
@ -1474,7 +1463,7 @@ public abstract class GeneratedMessageLite<
protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitialized( protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitialized(
T message, boolean shouldMemoize) { T message, boolean shouldMemoize) {
byte memoizedIsInitialized = byte memoizedIsInitialized =
(Byte) message.dynamicMethod(MethodToInvoke.GET_MEMOIZED_IS_INITIALIZED); (Byte) message.dynamicMethod(MethodToInvoke.GET_MEMOIZED_IS_INITIALIZED, null, null);
if (memoizedIsInitialized == 1) { if (memoizedIsInitialized == 1) {
return true; return true;
} }
@ -1486,7 +1475,7 @@ public abstract class GeneratedMessageLite<
// TODO: remove the unused variable // TODO: remove the unused variable
Object unused = Object unused =
message.dynamicMethod( message.dynamicMethod(
MethodToInvoke.SET_MEMOIZED_IS_INITIALIZED, isInitialized ? message : null); MethodToInvoke.SET_MEMOIZED_IS_INITIALIZED, isInitialized ? message : null, null);
} }
return isInitialized; return isInitialized;
} }

Loading…
Cancel
Save