From 9eb2e16b9425b0df0ef8463d1de16b41b951f630 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 14 Oct 2015 01:39:48 +0300 Subject: [PATCH] Support strings directly in JVM string table For small strings it may be beneficial to store them as is in the proto at one point instead of in a class annotation, because each annotation argument in the classfile has a constant overhead which may be significant for small strings --- .../serialization/jvm/DebugJvmProtoBuf.java | 360 ++++++++++++++---- .../serialization/jvm/JvmNameResolverTest.kt | 12 +- .../src/jvm_descriptors.proto | 3 + .../kotlin/load/kotlin/JvmNameResolver.kt | 10 +- .../kotlin/serialization/jvm/JvmProtoBuf.java | 268 +++++++++++-- 5 files changed, 538 insertions(+), 115 deletions(-) diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/jvm/DebugJvmProtoBuf.java b/compiler/tests/org/jetbrains/kotlin/serialization/jvm/DebugJvmProtoBuf.java index e03018bcafb..57ae5f484b9 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/jvm/DebugJvmProtoBuf.java +++ b/compiler/tests/org/jetbrains/kotlin/serialization/jvm/DebugJvmProtoBuf.java @@ -235,6 +235,33 @@ public final class DebugJvmProtoBuf { */ int getPredefinedIndex(); + // optional string string = 6; + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + boolean hasString(); + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + java.lang.String getString(); + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + com.google.protobuf.ByteString + getStringBytes(); + // optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; /** * optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; @@ -381,15 +408,15 @@ public final class DebugJvmProtoBuf { if (value == null) { unknownFields.mergeVarintField(3, rawValue); } else { - bitField0_ |= 0x00000004; + bitField0_ |= 0x00000008; operation_ = value; } break; } case 32: { - if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) { + if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) { substringIndex_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000008; + mutable_bitField0_ |= 0x00000010; } substringIndex_.add(input.readInt32()); break; @@ -397,9 +424,9 @@ public final class DebugJvmProtoBuf { case 34: { int length = input.readRawVarint32(); int limit = input.pushLimit(length); - if (!((mutable_bitField0_ & 0x00000008) == 0x00000008) && input.getBytesUntilLimit() > 0) { + if (!((mutable_bitField0_ & 0x00000010) == 0x00000010) && input.getBytesUntilLimit() > 0) { substringIndex_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000008; + mutable_bitField0_ |= 0x00000010; } while (input.getBytesUntilLimit() > 0) { substringIndex_.add(input.readInt32()); @@ -408,9 +435,9 @@ public final class DebugJvmProtoBuf { break; } case 40: { - if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) { + if (!((mutable_bitField0_ & 0x00000020) == 0x00000020)) { replaceChar_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000010; + mutable_bitField0_ |= 0x00000020; } replaceChar_.add(input.readInt32()); break; @@ -418,9 +445,9 @@ public final class DebugJvmProtoBuf { case 42: { int length = input.readRawVarint32(); int limit = input.pushLimit(length); - if (!((mutable_bitField0_ & 0x00000010) == 0x00000010) && input.getBytesUntilLimit() > 0) { + if (!((mutable_bitField0_ & 0x00000020) == 0x00000020) && input.getBytesUntilLimit() > 0) { replaceChar_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000010; + mutable_bitField0_ |= 0x00000020; } while (input.getBytesUntilLimit() > 0) { replaceChar_.add(input.readInt32()); @@ -428,6 +455,11 @@ public final class DebugJvmProtoBuf { input.popLimit(limit); break; } + case 50: { + bitField0_ |= 0x00000004; + string_ = input.readBytes(); + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -436,10 +468,10 @@ public final class DebugJvmProtoBuf { throw new com.google.protobuf.InvalidProtocolBufferException( e.getMessage()).setUnfinishedMessage(this); } finally { - if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) { + if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) { substringIndex_ = java.util.Collections.unmodifiableList(substringIndex_); } - if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) { + if (((mutable_bitField0_ & 0x00000020) == 0x00000020)) { replaceChar_ = java.util.Collections.unmodifiableList(replaceChar_); } this.unknownFields = unknownFields.build(); @@ -633,6 +665,61 @@ public final class DebugJvmProtoBuf { return predefinedIndex_; } + // optional string string = 6; + public static final int STRING_FIELD_NUMBER = 6; + private java.lang.Object string_; + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + public boolean hasString() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + public java.lang.String getString() { + java.lang.Object ref = string_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + string_ = s; + } + return s; + } + } + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + public com.google.protobuf.ByteString + getStringBytes() { + java.lang.Object ref = string_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + string_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + // optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; public static final int OPERATION_FIELD_NUMBER = 3; private org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.StringTableTypes.Record.Operation operation_; @@ -644,7 +731,7 @@ public final class DebugJvmProtoBuf { * */ public boolean hasOperation() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000008) == 0x00000008); } /** * optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; @@ -741,6 +828,7 @@ public final class DebugJvmProtoBuf { private void initFields() { range_ = 1; predefinedIndex_ = 0; + string_ = ""; operation_ = org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.StringTableTypes.Record.Operation.NONE; substringIndex_ = java.util.Collections.emptyList(); replaceChar_ = java.util.Collections.emptyList(); @@ -763,7 +851,7 @@ public final class DebugJvmProtoBuf { if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeInt32(2, predefinedIndex_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { + if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeEnum(3, operation_.getNumber()); } if (getSubstringIndexList().size() > 0) { @@ -780,6 +868,9 @@ public final class DebugJvmProtoBuf { for (int i = 0; i < replaceChar_.size(); i++) { output.writeInt32NoTag(replaceChar_.get(i)); } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeBytes(6, getStringBytes()); + } getUnknownFields().writeTo(output); } @@ -797,7 +888,7 @@ public final class DebugJvmProtoBuf { size += com.google.protobuf.CodedOutputStream .computeInt32Size(2, predefinedIndex_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { + if (((bitField0_ & 0x00000008) == 0x00000008)) { size += com.google.protobuf.CodedOutputStream .computeEnumSize(3, operation_.getNumber()); } @@ -829,6 +920,10 @@ public final class DebugJvmProtoBuf { } replaceCharMemoizedSerializedSize = dataSize; } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(6, getStringBytes()); + } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; @@ -949,12 +1044,14 @@ public final class DebugJvmProtoBuf { bitField0_ = (bitField0_ & ~0x00000001); predefinedIndex_ = 0; bitField0_ = (bitField0_ & ~0x00000002); - operation_ = org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.StringTableTypes.Record.Operation.NONE; + string_ = ""; bitField0_ = (bitField0_ & ~0x00000004); - substringIndex_ = java.util.Collections.emptyList(); + operation_ = org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.StringTableTypes.Record.Operation.NONE; bitField0_ = (bitField0_ & ~0x00000008); - replaceChar_ = java.util.Collections.emptyList(); + substringIndex_ = java.util.Collections.emptyList(); bitField0_ = (bitField0_ & ~0x00000010); + replaceChar_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000020); return this; } @@ -994,15 +1091,19 @@ public final class DebugJvmProtoBuf { if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } + result.string_ = string_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } result.operation_ = operation_; - if (((bitField0_ & 0x00000008) == 0x00000008)) { + if (((bitField0_ & 0x00000010) == 0x00000010)) { substringIndex_ = java.util.Collections.unmodifiableList(substringIndex_); - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000010); } result.substringIndex_ = substringIndex_; - if (((bitField0_ & 0x00000010) == 0x00000010)) { + if (((bitField0_ & 0x00000020) == 0x00000020)) { replaceChar_ = java.util.Collections.unmodifiableList(replaceChar_); - bitField0_ = (bitField0_ & ~0x00000010); + bitField0_ = (bitField0_ & ~0x00000020); } result.replaceChar_ = replaceChar_; result.bitField0_ = to_bitField0_; @@ -1027,13 +1128,18 @@ public final class DebugJvmProtoBuf { if (other.hasPredefinedIndex()) { setPredefinedIndex(other.getPredefinedIndex()); } + if (other.hasString()) { + bitField0_ |= 0x00000004; + string_ = other.string_; + onChanged(); + } if (other.hasOperation()) { setOperation(other.getOperation()); } if (!other.substringIndex_.isEmpty()) { if (substringIndex_.isEmpty()) { substringIndex_ = other.substringIndex_; - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000010); } else { ensureSubstringIndexIsMutable(); substringIndex_.addAll(other.substringIndex_); @@ -1043,7 +1149,7 @@ public final class DebugJvmProtoBuf { if (!other.replaceChar_.isEmpty()) { if (replaceChar_.isEmpty()) { replaceChar_ = other.replaceChar_; - bitField0_ = (bitField0_ & ~0x00000010); + bitField0_ = (bitField0_ & ~0x00000020); } else { ensureReplaceCharIsMutable(); replaceChar_.addAll(other.replaceChar_); @@ -1175,6 +1281,104 @@ public final class DebugJvmProtoBuf { return this; } + // optional string string = 6; + private java.lang.Object string_ = ""; + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public boolean hasString() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public java.lang.String getString() { + java.lang.Object ref = string_; + if (!(ref instanceof java.lang.String)) { + java.lang.String s = ((com.google.protobuf.ByteString) ref) + .toStringUtf8(); + string_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public com.google.protobuf.ByteString + getStringBytes() { + java.lang.Object ref = string_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + string_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public Builder setString( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + string_ = value; + onChanged(); + return this; + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public Builder clearString() { + bitField0_ = (bitField0_ & ~0x00000004); + string_ = getDefaultInstance().getString(); + onChanged(); + return this; + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public Builder setStringBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + string_ = value; + onChanged(); + return this; + } + // optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; private org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.StringTableTypes.Record.Operation operation_ = org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.StringTableTypes.Record.Operation.NONE; /** @@ -1185,7 +1389,7 @@ public final class DebugJvmProtoBuf { * */ public boolean hasOperation() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000008) == 0x00000008); } /** * optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; @@ -1208,7 +1412,7 @@ public final class DebugJvmProtoBuf { if (value == null) { throw new NullPointerException(); } - bitField0_ |= 0x00000004; + bitField0_ |= 0x00000008; operation_ = value; onChanged(); return this; @@ -1221,7 +1425,7 @@ public final class DebugJvmProtoBuf { * */ public Builder clearOperation() { - bitField0_ = (bitField0_ & ~0x00000004); + bitField0_ = (bitField0_ & ~0x00000008); operation_ = org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.StringTableTypes.Record.Operation.NONE; onChanged(); return this; @@ -1230,9 +1434,9 @@ public final class DebugJvmProtoBuf { // repeated int32 substring_index = 4 [packed = true]; private java.util.List substringIndex_ = java.util.Collections.emptyList(); private void ensureSubstringIndexIsMutable() { - if (!((bitField0_ & 0x00000008) == 0x00000008)) { + if (!((bitField0_ & 0x00000010) == 0x00000010)) { substringIndex_ = new java.util.ArrayList(substringIndex_); - bitField0_ |= 0x00000008; + bitField0_ |= 0x00000010; } } /** @@ -1330,7 +1534,7 @@ public final class DebugJvmProtoBuf { */ public Builder clearSubstringIndex() { substringIndex_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000010); onChanged(); return this; } @@ -1338,9 +1542,9 @@ public final class DebugJvmProtoBuf { // repeated int32 replace_char = 5 [packed = true]; private java.util.List replaceChar_ = java.util.Collections.emptyList(); private void ensureReplaceCharIsMutable() { - if (!((bitField0_ & 0x00000010) == 0x00000010)) { + if (!((bitField0_ & 0x00000020) == 0x00000020)) { replaceChar_ = new java.util.ArrayList(replaceChar_); - bitField0_ |= 0x00000010; + bitField0_ |= 0x00000020; } } /** @@ -1431,7 +1635,7 @@ public final class DebugJvmProtoBuf { */ public Builder clearReplaceChar() { replaceChar_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000010); + bitField0_ = (bitField0_ & ~0x00000020); onChanged(); return this; } @@ -4581,53 +4785,53 @@ public final class DebugJvmProtoBuf { "lin.serialization.jvm\0320core/deserializat" + "ion/src/ext_options.debug.proto\0320core/de" + "serialization/src/descriptors.debug.prot" + - "o\"\224\003\n\020StringTableTypes\022O\n\006record\030\001 \003(\0132?" + + "o\"\244\003\n\020StringTableTypes\022O\n\006record\030\001 \003(\0132?" + ".org.jetbrains.kotlin.serialization.jvm." + "StringTableTypes.Record\022\026\n\nlocal_name\030\005 " + - "\003(\005B\002\020\001\032\226\002\n\006Record\022\020\n\005range\030\001 \001(\005:\0011\022\030\n\020" + - "predefined_index\030\002 \001(\005\022b\n\toperation\030\003 \001(", - "\0162I.org.jetbrains.kotlin.serialization.j" + - "vm.StringTableTypes.Record.Operation:\004NO" + - "NE\022\033\n\017substring_index\030\004 \003(\005B\002\020\001\022\030\n\014repla" + - "ce_char\030\005 \003(\005B\002\020\001\"E\n\tOperation\022\010\n\004NONE\020\000" + - "\022\030\n\024INTERNAL_TO_CLASS_ID\020\001\022\024\n\020DESC_TO_CL" + - "ASS_ID\020\002\"<\n\022JvmMethodSignature\022\022\n\004name\030\001" + - " \001(\005B\004\230\265\030\001\022\022\n\004desc\030\002 \001(\005B\004\230\265\030\001\"^\n\021JvmFie" + - "ldSignature\022\022\n\004name\030\001 \001(\005B\004\230\265\030\001\022\022\n\004desc\030" + - "\002 \001(\005B\004\230\265\030\001\022!\n\022is_static_in_outer\030\003 \001(\010:" + - "\005false\"\316\002\n\024JvmPropertySignature\022H\n\005field", - "\030\001 \001(\01329.org.jetbrains.kotlin.serializat" + - "ion.jvm.JvmFieldSignature\022T\n\020synthetic_m" + - "ethod\030\002 \001(\0132:.org.jetbrains.kotlin.seria" + - "lization.jvm.JvmMethodSignature\022J\n\006gette" + - "r\030\003 \001(\0132:.org.jetbrains.kotlin.serializa" + - "tion.jvm.JvmMethodSignature\022J\n\006setter\030\004 " + - "\001(\0132:.org.jetbrains.kotlin.serialization" + - ".jvm.JvmMethodSignature:\212\001\n\025constructor_" + - "signature\022/.org.jetbrains.kotlin.seriali" + - "zation.Constructor\030d \001(\0132:.org.jetbrains", - ".kotlin.serialization.jvm.JvmMethodSigna" + - "ture:\202\001\n\020method_signature\022,.org.jetbrain" + - "s.kotlin.serialization.Function\030d \001(\0132:." + - "org.jetbrains.kotlin.serialization.jvm.J" + - "vmMethodSignature:R\n\026method_impl_class_n" + - "ame\022,.org.jetbrains.kotlin.serialization" + - ".Function\030e \001(\005B\004\230\265\030\001:\206\001\n\022property_signa" + - "ture\022,.org.jetbrains.kotlin.serializatio" + - "n.Property\030d \001(\0132<.org.jetbrains.kotlin." + - "serialization.jvm.JvmPropertySignature:T", - "\n\030property_impl_class_name\022,.org.jetbrai" + - "ns.kotlin.serialization.Property\030e \001(\005B\004" + - "\230\265\030\001:q\n\017type_annotation\022(.org.jetbrains." + - "kotlin.serialization.Type\030d \003(\0132..org.je" + - "tbrains.kotlin.serialization.Annotation:" + - "8\n\006is_raw\022(.org.jetbrains.kotlin.seriali" + - "zation.Type\030e \001(\010:A\n\005index\0222.org.jetbrai" + - "ns.kotlin.serialization.ValueParameter\030d" + - " \001(\005:s\n\020class_annotation\022).org.jetbrains" + - ".kotlin.serialization.Class\030d \003(\0132..org.", - "jetbrains.kotlin.serialization.Annotatio" + - "nB\022B\020DebugJvmProtoBuf" + "\003(\005B\002\020\001\032\246\002\n\006Record\022\020\n\005range\030\001 \001(\005:\0011\022\030\n\020" + + "predefined_index\030\002 \001(\005\022\016\n\006string\030\006 \001(\t\022b", + "\n\toperation\030\003 \001(\0162I.org.jetbrains.kotlin" + + ".serialization.jvm.StringTableTypes.Reco" + + "rd.Operation:\004NONE\022\033\n\017substring_index\030\004 " + + "\003(\005B\002\020\001\022\030\n\014replace_char\030\005 \003(\005B\002\020\001\"E\n\tOpe" + + "ration\022\010\n\004NONE\020\000\022\030\n\024INTERNAL_TO_CLASS_ID" + + "\020\001\022\024\n\020DESC_TO_CLASS_ID\020\002\"<\n\022JvmMethodSig" + + "nature\022\022\n\004name\030\001 \001(\005B\004\230\265\030\001\022\022\n\004desc\030\002 \001(\005" + + "B\004\230\265\030\001\"^\n\021JvmFieldSignature\022\022\n\004name\030\001 \001(" + + "\005B\004\230\265\030\001\022\022\n\004desc\030\002 \001(\005B\004\230\265\030\001\022!\n\022is_static" + + "_in_outer\030\003 \001(\010:\005false\"\316\002\n\024JvmPropertySi", + "gnature\022H\n\005field\030\001 \001(\01329.org.jetbrains.k" + + "otlin.serialization.jvm.JvmFieldSignatur" + + "e\022T\n\020synthetic_method\030\002 \001(\0132:.org.jetbra" + + "ins.kotlin.serialization.jvm.JvmMethodSi" + + "gnature\022J\n\006getter\030\003 \001(\0132:.org.jetbrains." + + "kotlin.serialization.jvm.JvmMethodSignat" + + "ure\022J\n\006setter\030\004 \001(\0132:.org.jetbrains.kotl" + + "in.serialization.jvm.JvmMethodSignature:" + + "\212\001\n\025constructor_signature\022/.org.jetbrain" + + "s.kotlin.serialization.Constructor\030d \001(\013", + "2:.org.jetbrains.kotlin.serialization.jv" + + "m.JvmMethodSignature:\202\001\n\020method_signatur" + + "e\022,.org.jetbrains.kotlin.serialization.F" + + "unction\030d \001(\0132:.org.jetbrains.kotlin.ser" + + "ialization.jvm.JvmMethodSignature:R\n\026met" + + "hod_impl_class_name\022,.org.jetbrains.kotl" + + "in.serialization.Function\030e \001(\005B\004\230\265\030\001:\206\001" + + "\n\022property_signature\022,.org.jetbrains.kot" + + "lin.serialization.Property\030d \001(\0132<.org.j" + + "etbrains.kotlin.serialization.jvm.JvmPro", + "pertySignature:T\n\030property_impl_class_na" + + "me\022,.org.jetbrains.kotlin.serialization." + + "Property\030e \001(\005B\004\230\265\030\001:q\n\017type_annotation\022" + + "(.org.jetbrains.kotlin.serialization.Typ" + + "e\030d \003(\0132..org.jetbrains.kotlin.serializa" + + "tion.Annotation:8\n\006is_raw\022(.org.jetbrain" + + "s.kotlin.serialization.Type\030e \001(\010:A\n\005ind" + + "ex\0222.org.jetbrains.kotlin.serialization." + + "ValueParameter\030d \001(\005:s\n\020class_annotation" + + "\022).org.jetbrains.kotlin.serialization.Cl", + "ass\030d \003(\0132..org.jetbrains.kotlin.seriali" + + "zation.AnnotationB\022B\020DebugJvmProtoBuf" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -4645,7 +4849,7 @@ public final class DebugJvmProtoBuf { internal_static_org_jetbrains_kotlin_serialization_jvm_StringTableTypes_Record_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_org_jetbrains_kotlin_serialization_jvm_StringTableTypes_Record_descriptor, - new java.lang.String[] { "Range", "PredefinedIndex", "Operation", "SubstringIndex", "ReplaceChar", }); + new java.lang.String[] { "Range", "PredefinedIndex", "String", "Operation", "SubstringIndex", "ReplaceChar", }); internal_static_org_jetbrains_kotlin_serialization_jvm_JvmMethodSignature_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_org_jetbrains_kotlin_serialization_jvm_JvmMethodSignature_fieldAccessorTable = new diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/jvm/JvmNameResolverTest.kt b/compiler/tests/org/jetbrains/kotlin/serialization/jvm/JvmNameResolverTest.kt index 9a415f8df2d..c9b8aa5a2bc 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/jvm/JvmNameResolverTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/serialization/jvm/JvmNameResolverTest.kt @@ -36,6 +36,7 @@ class JvmNameResolverTest : UsefulTestCase() { string: String?, range: Int? = null, predefinedIndex: Int? = null, + internalString: String? = null, operation: Record.Operation? = null, substringIndex: List? = null, replaceChar: List? = null @@ -43,6 +44,7 @@ class JvmNameResolverTest : UsefulTestCase() { types.addRecord(Record.newBuilder().apply { range?.let { setRange(it) } predefinedIndex?.let { setPredefinedIndex(it) } + internalString?.let { setString(it) } operation?.let { setOperation(it) } substringIndex?.let { addAllSubstringIndex(it) } replaceChar?.let { addAllReplaceChar(it.map(Char::toInt)) } @@ -60,7 +62,7 @@ class JvmNameResolverTest : UsefulTestCase() { } private fun str(string: String?, predefinedIndex: Int? = null, operation: Record.Operation? = null): String { - return create { string(string, null, predefinedIndex, operation, null, null) }.getString(0) + return create { string(string, null, predefinedIndex, null, operation, null, null) }.getString(0) } fun testSimpleString() { @@ -158,4 +160,12 @@ class JvmNameResolverTest : UsefulTestCase() { assertEquals("a.b.c", n.getString(0)) assertEquals("d.e.f", n.getString(1)) } + + fun testString() { + val n = create { + string("java", internalString = "kotlin", range = 5) + } + + (0..4).forEach { assertEquals("kotlin", n.getString(it)) } + } } diff --git a/core/descriptor.loader.java/src/jvm_descriptors.proto b/core/descriptor.loader.java/src/jvm_descriptors.proto index 6945455bc06..d42a34eea7b 100644 --- a/core/descriptor.loader.java/src/jvm_descriptors.proto +++ b/core/descriptor.loader.java/src/jvm_descriptors.proto @@ -30,6 +30,9 @@ message StringTableTypes { // Index of the predefined constant. If this field is present, the associated string is ignored optional int32 predefined_index = 2; + // A string which should be used. If this field is present, both the associated string and the predefined string index are ignored + optional string string = 6; + enum Operation { NONE = 0; diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JvmNameResolver.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JvmNameResolver.kt index 1eec26ae51e..b727be8693f 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JvmNameResolver.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JvmNameResolver.kt @@ -48,10 +48,12 @@ class JvmNameResolver( override fun getString(index: Int): String { val record = records[index] - var string = - if (record.hasPredefinedIndex() && record.predefinedIndex in PREDEFINED_STRINGS.indices) - PREDEFINED_STRINGS[record.predefinedIndex] - else strings[index] + var string = when { + record.hasString() -> record.string + record.hasPredefinedIndex() && record.predefinedIndex in PREDEFINED_STRINGS.indices -> + PREDEFINED_STRINGS[record.predefinedIndex] + else -> strings[index] + } if (record.substringIndexCount >= 2) { val (begin, end) = record.substringIndexList diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/serialization/jvm/JvmProtoBuf.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/serialization/jvm/JvmProtoBuf.java index 5084116cf98..51bf8907425 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/serialization/jvm/JvmProtoBuf.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/serialization/jvm/JvmProtoBuf.java @@ -204,6 +204,33 @@ public final class JvmProtoBuf { */ int getPredefinedIndex(); + // optional string string = 6; + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + boolean hasString(); + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + java.lang.String getString(); + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + com.google.protobuf.ByteString + getStringBytes(); + // optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; /** * optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; @@ -340,15 +367,15 @@ public final class JvmProtoBuf { int rawValue = input.readEnum(); org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.StringTableTypes.Record.Operation value = org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.StringTableTypes.Record.Operation.valueOf(rawValue); if (value != null) { - bitField0_ |= 0x00000004; + bitField0_ |= 0x00000008; operation_ = value; } break; } case 32: { - if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) { + if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) { substringIndex_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000008; + mutable_bitField0_ |= 0x00000010; } substringIndex_.add(input.readInt32()); break; @@ -356,9 +383,9 @@ public final class JvmProtoBuf { case 34: { int length = input.readRawVarint32(); int limit = input.pushLimit(length); - if (!((mutable_bitField0_ & 0x00000008) == 0x00000008) && input.getBytesUntilLimit() > 0) { + if (!((mutable_bitField0_ & 0x00000010) == 0x00000010) && input.getBytesUntilLimit() > 0) { substringIndex_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000008; + mutable_bitField0_ |= 0x00000010; } while (input.getBytesUntilLimit() > 0) { substringIndex_.add(input.readInt32()); @@ -367,9 +394,9 @@ public final class JvmProtoBuf { break; } case 40: { - if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) { + if (!((mutable_bitField0_ & 0x00000020) == 0x00000020)) { replaceChar_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000010; + mutable_bitField0_ |= 0x00000020; } replaceChar_.add(input.readInt32()); break; @@ -377,9 +404,9 @@ public final class JvmProtoBuf { case 42: { int length = input.readRawVarint32(); int limit = input.pushLimit(length); - if (!((mutable_bitField0_ & 0x00000010) == 0x00000010) && input.getBytesUntilLimit() > 0) { + if (!((mutable_bitField0_ & 0x00000020) == 0x00000020) && input.getBytesUntilLimit() > 0) { replaceChar_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000010; + mutable_bitField0_ |= 0x00000020; } while (input.getBytesUntilLimit() > 0) { replaceChar_.add(input.readInt32()); @@ -387,6 +414,11 @@ public final class JvmProtoBuf { input.popLimit(limit); break; } + case 50: { + bitField0_ |= 0x00000004; + string_ = input.readBytes(); + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -395,10 +427,10 @@ public final class JvmProtoBuf { throw new com.google.protobuf.InvalidProtocolBufferException( e.getMessage()).setUnfinishedMessage(this); } finally { - if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) { + if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) { substringIndex_ = java.util.Collections.unmodifiableList(substringIndex_); } - if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) { + if (((mutable_bitField0_ & 0x00000020) == 0x00000020)) { replaceChar_ = java.util.Collections.unmodifiableList(replaceChar_); } makeExtensionsImmutable(); @@ -553,6 +585,61 @@ public final class JvmProtoBuf { return predefinedIndex_; } + // optional string string = 6; + public static final int STRING_FIELD_NUMBER = 6; + private java.lang.Object string_; + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + public boolean hasString() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + public java.lang.String getString() { + java.lang.Object ref = string_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + string_ = s; + } + return s; + } + } + /** + * optional string string = 6; + * + *
+       * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+       * 
+ */ + public com.google.protobuf.ByteString + getStringBytes() { + java.lang.Object ref = string_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + string_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + // optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; public static final int OPERATION_FIELD_NUMBER = 3; private org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.StringTableTypes.Record.Operation operation_; @@ -564,7 +651,7 @@ public final class JvmProtoBuf { * */ public boolean hasOperation() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000008) == 0x00000008); } /** * optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; @@ -661,6 +748,7 @@ public final class JvmProtoBuf { private void initFields() { range_ = 1; predefinedIndex_ = 0; + string_ = ""; operation_ = org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.StringTableTypes.Record.Operation.NONE; substringIndex_ = java.util.Collections.emptyList(); replaceChar_ = java.util.Collections.emptyList(); @@ -683,7 +771,7 @@ public final class JvmProtoBuf { if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeInt32(2, predefinedIndex_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { + if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeEnum(3, operation_.getNumber()); } if (getSubstringIndexList().size() > 0) { @@ -700,6 +788,9 @@ public final class JvmProtoBuf { for (int i = 0; i < replaceChar_.size(); i++) { output.writeInt32NoTag(replaceChar_.get(i)); } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeBytes(6, getStringBytes()); + } } private int memoizedSerializedSize = -1; @@ -716,7 +807,7 @@ public final class JvmProtoBuf { size += com.google.protobuf.CodedOutputStream .computeInt32Size(2, predefinedIndex_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { + if (((bitField0_ & 0x00000008) == 0x00000008)) { size += com.google.protobuf.CodedOutputStream .computeEnumSize(3, operation_.getNumber()); } @@ -748,6 +839,10 @@ public final class JvmProtoBuf { } replaceCharMemoizedSerializedSize = dataSize; } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(6, getStringBytes()); + } memoizedSerializedSize = size; return size; } @@ -843,12 +938,14 @@ public final class JvmProtoBuf { bitField0_ = (bitField0_ & ~0x00000001); predefinedIndex_ = 0; bitField0_ = (bitField0_ & ~0x00000002); - operation_ = org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.StringTableTypes.Record.Operation.NONE; + string_ = ""; bitField0_ = (bitField0_ & ~0x00000004); - substringIndex_ = java.util.Collections.emptyList(); + operation_ = org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.StringTableTypes.Record.Operation.NONE; bitField0_ = (bitField0_ & ~0x00000008); - replaceChar_ = java.util.Collections.emptyList(); + substringIndex_ = java.util.Collections.emptyList(); bitField0_ = (bitField0_ & ~0x00000010); + replaceChar_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000020); return this; } @@ -883,15 +980,19 @@ public final class JvmProtoBuf { if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } + result.string_ = string_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } result.operation_ = operation_; - if (((bitField0_ & 0x00000008) == 0x00000008)) { + if (((bitField0_ & 0x00000010) == 0x00000010)) { substringIndex_ = java.util.Collections.unmodifiableList(substringIndex_); - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000010); } result.substringIndex_ = substringIndex_; - if (((bitField0_ & 0x00000010) == 0x00000010)) { + if (((bitField0_ & 0x00000020) == 0x00000020)) { replaceChar_ = java.util.Collections.unmodifiableList(replaceChar_); - bitField0_ = (bitField0_ & ~0x00000010); + bitField0_ = (bitField0_ & ~0x00000020); } result.replaceChar_ = replaceChar_; result.bitField0_ = to_bitField0_; @@ -906,13 +1007,18 @@ public final class JvmProtoBuf { if (other.hasPredefinedIndex()) { setPredefinedIndex(other.getPredefinedIndex()); } + if (other.hasString()) { + bitField0_ |= 0x00000004; + string_ = other.string_; + + } if (other.hasOperation()) { setOperation(other.getOperation()); } if (!other.substringIndex_.isEmpty()) { if (substringIndex_.isEmpty()) { substringIndex_ = other.substringIndex_; - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000010); } else { ensureSubstringIndexIsMutable(); substringIndex_.addAll(other.substringIndex_); @@ -922,7 +1028,7 @@ public final class JvmProtoBuf { if (!other.replaceChar_.isEmpty()) { if (replaceChar_.isEmpty()) { replaceChar_ = other.replaceChar_; - bitField0_ = (bitField0_ & ~0x00000010); + bitField0_ = (bitField0_ & ~0x00000020); } else { ensureReplaceCharIsMutable(); replaceChar_.addAll(other.replaceChar_); @@ -1053,6 +1159,104 @@ public final class JvmProtoBuf { return this; } + // optional string string = 6; + private java.lang.Object string_ = ""; + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public boolean hasString() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public java.lang.String getString() { + java.lang.Object ref = string_; + if (!(ref instanceof java.lang.String)) { + java.lang.String s = ((com.google.protobuf.ByteString) ref) + .toStringUtf8(); + string_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public com.google.protobuf.ByteString + getStringBytes() { + java.lang.Object ref = string_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + string_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public Builder setString( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + string_ = value; + + return this; + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public Builder clearString() { + bitField0_ = (bitField0_ & ~0x00000004); + string_ = getDefaultInstance().getString(); + + return this; + } + /** + * optional string string = 6; + * + *
+         * A string which should be used. If this field is present, both the associated string and the predefined string index are ignored
+         * 
+ */ + public Builder setStringBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + string_ = value; + + return this; + } + // optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; private org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.StringTableTypes.Record.Operation operation_ = org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.StringTableTypes.Record.Operation.NONE; /** @@ -1063,7 +1267,7 @@ public final class JvmProtoBuf { * */ public boolean hasOperation() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000008) == 0x00000008); } /** * optional .org.jetbrains.kotlin.serialization.jvm.StringTableTypes.Record.Operation operation = 3 [default = NONE]; @@ -1086,7 +1290,7 @@ public final class JvmProtoBuf { if (value == null) { throw new NullPointerException(); } - bitField0_ |= 0x00000004; + bitField0_ |= 0x00000008; operation_ = value; return this; @@ -1099,7 +1303,7 @@ public final class JvmProtoBuf { * */ public Builder clearOperation() { - bitField0_ = (bitField0_ & ~0x00000004); + bitField0_ = (bitField0_ & ~0x00000008); operation_ = org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.StringTableTypes.Record.Operation.NONE; return this; @@ -1108,9 +1312,9 @@ public final class JvmProtoBuf { // repeated int32 substring_index = 4 [packed = true]; private java.util.List substringIndex_ = java.util.Collections.emptyList(); private void ensureSubstringIndexIsMutable() { - if (!((bitField0_ & 0x00000008) == 0x00000008)) { + if (!((bitField0_ & 0x00000010) == 0x00000010)) { substringIndex_ = new java.util.ArrayList(substringIndex_); - bitField0_ |= 0x00000008; + bitField0_ |= 0x00000010; } } /** @@ -1208,7 +1412,7 @@ public final class JvmProtoBuf { */ public Builder clearSubstringIndex() { substringIndex_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000010); return this; } @@ -1216,9 +1420,9 @@ public final class JvmProtoBuf { // repeated int32 replace_char = 5 [packed = true]; private java.util.List replaceChar_ = java.util.Collections.emptyList(); private void ensureReplaceCharIsMutable() { - if (!((bitField0_ & 0x00000010) == 0x00000010)) { + if (!((bitField0_ & 0x00000020) == 0x00000020)) { replaceChar_ = new java.util.ArrayList(replaceChar_); - bitField0_ |= 0x00000010; + bitField0_ |= 0x00000020; } } /** @@ -1309,7 +1513,7 @@ public final class JvmProtoBuf { */ public Builder clearReplaceChar() { replaceChar_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000010); + bitField0_ = (bitField0_ & ~0x00000020); return this; }