< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java

Print this page

  1 /*
  2  * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

209     public final Type inheritedType;
210     public final Type profileType;
211     public final Type proprietaryType;
212     public final Type systemType;
213     public final Type autoCloseableType;
214     public final Type trustMeType;
215     public final Type lambdaMetafactory;
216     public final Type stringConcatFactory;
217     public final Type repeatableType;
218     public final Type documentedType;
219     public final Type elementTypeType;
220     public final Type functionalInterfaceType;
221     public final Type previewFeatureType;
222     public final Type previewFeatureInternalType;
223     public final Type restrictedType;
224     public final Type restrictedInternalType;
225     public final Type typeDescriptorType;
226     public final Type recordType;
227     public final Type switchBootstrapsType;
228     public final Type constantBootstrapsType;
229     public final Type valueBasedType;
230     public final Type valueBasedInternalType;
231     public final Type requiresIdentityType;
232     public final Type requiresIdentityInternalType;
233     public final Type classDescType;
234     public final Type enumDescType;
235 
236     // For serialization lint checking
237     public final Type objectStreamFieldType;
238     public final Type objectInputStreamType;
239     public final Type objectOutputStreamType;
240     public final Type ioExceptionType;
241     public final Type objectStreamExceptionType;
242     // For externalization lint checking
243     public final Type externalizableType;
244     public final Type objectInputType;
245     public final Type objectOutputType;
246 









247     /** The symbol representing the length field of an array.
248      */
249     public final VarSymbol lengthVar;
250 
251     /** The symbol representing the final finalize method on enums */
252     public final MethodSymbol enumFinalFinalize;
253 
254     /** The symbol representing the close method on TWR AutoCloseable type */
255     public final MethodSymbol autoCloseableClose;
256 
257     /** The predefined type that belongs to a tag.
258      */
259     public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
260 
261     /** The name of the class that belongs to a basic type tag.
262      */
263     public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()];
264 
265     /** A hashtable containing the encountered top-level and member classes,
266      *  indexed by flat names. The table does not contain local classes.

525 
526         // Enter symbols for basic types.
527         scope.enter(byteType.tsym);
528         scope.enter(shortType.tsym);
529         scope.enter(charType.tsym);
530         scope.enter(intType.tsym);
531         scope.enter(longType.tsym);
532         scope.enter(floatType.tsym);
533         scope.enter(doubleType.tsym);
534         scope.enter(booleanType.tsym);
535         scope.enter(errType.tsym);
536 
537         // Enter symbol for the errSymbol
538         scope.enter(errSymbol);
539 
540         // Get the initial completer for ModuleSymbols from Modules
541         moduleCompleter = Modules.instance(context).getCompleter();
542 
543         // Enter predefined classes. All are assumed to be in the java.base module.
544         objectType = enterClass("java.lang.Object");






545         objectMethodsType = enterClass("java.lang.runtime.ObjectMethods");
546         exactConversionsSupportType = enterClass("java.lang.runtime.ExactConversionsSupport");
547         objectsType = enterClass("java.util.Objects");
548         classType = enterClass("java.lang.Class");
549         stringType = enterClass("java.lang.String");
550         stringBufferType = enterClass("java.lang.StringBuffer");
551         stringBuilderType = enterClass("java.lang.StringBuilder");
552         cloneableType = enterClass("java.lang.Cloneable");
553         throwableType = enterClass("java.lang.Throwable");
554         serializableType = enterClass("java.io.Serializable");
555         serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
556         varHandleType = enterClass("java.lang.invoke.VarHandle");
557         methodHandleType = enterClass("java.lang.invoke.MethodHandle");
558         methodHandlesType = enterClass("java.lang.invoke.MethodHandles");
559         methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
560         methodTypeType = enterClass("java.lang.invoke.MethodType");
561         errorType = enterClass("java.lang.Error");
562         illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
563         interruptedExceptionType = enterClass("java.lang.InterruptedException");
564         exceptionType = enterClass("java.lang.Exception");
565         runtimeExceptionType = enterClass("java.lang.RuntimeException");
566         classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
567         noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
568         noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
569         assertionErrorType = enterClass("java.lang.AssertionError");
570         incompatibleClassChangeErrorType = enterClass("java.lang.IncompatibleClassChangeError");
571         cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");
572         matchExceptionType = enterClass("java.lang.MatchException");
573         annotationType = enterClass("java.lang.annotation.Annotation");

601         autoCloseableClose = new MethodSymbol(PUBLIC,
602                              names.close,
603                              new MethodType(List.nil(), voidType,
604                                             List.of(exceptionType), methodClass),
605                              autoCloseableType.tsym);
606         trustMeType = enterClass("java.lang.SafeVarargs");
607         nativeHeaderType = enterClass("java.lang.annotation.Native");
608         lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
609         stringConcatFactory = enterClass("java.lang.invoke.StringConcatFactory");
610         functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
611         previewFeatureType = enterClass("jdk.internal.javac.PreviewFeature");
612         previewFeatureInternalType = enterSyntheticAnnotation("jdk.internal.PreviewFeature+Annotation");
613         restrictedType = enterClass("jdk.internal.javac.Restricted");
614         restrictedInternalType = enterSyntheticAnnotation("jdk.internal.javac.Restricted+Annotation");
615         typeDescriptorType = enterClass("java.lang.invoke.TypeDescriptor");
616         recordType = enterClass("java.lang.Record");
617         switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps");
618         constantBootstrapsType = enterClass("java.lang.invoke.ConstantBootstraps");
619         valueBasedType = enterClass("jdk.internal.ValueBased");
620         valueBasedInternalType = enterSyntheticAnnotation("jdk.internal.ValueBased+Annotation");


621         requiresIdentityType = enterClass("jdk.internal.RequiresIdentity");
622         requiresIdentityInternalType = enterSyntheticAnnotation(names.requiresIdentityInternal);
623         classDescType = enterClass("java.lang.constant.ClassDesc");
624         enumDescType = enterClass("java.lang.Enum$EnumDesc");
625         // For serialization lint checking
626         objectStreamFieldType = enterClass("java.io.ObjectStreamField");
627         objectInputStreamType = enterClass("java.io.ObjectInputStream");
628         objectOutputStreamType = enterClass("java.io.ObjectOutputStream");
629         ioExceptionType = enterClass("java.io.IOException");
630         objectStreamExceptionType = enterClass("java.io.ObjectStreamException");
631         externalizableType = enterClass("java.io.Externalizable");
632         objectInputType  = enterClass("java.io.ObjectInput");
633         objectOutputType = enterClass("java.io.ObjectOutput");
634         synthesizeEmptyInterfaceIfMissing(autoCloseableType);
635         synthesizeEmptyInterfaceIfMissing(cloneableType);
636         synthesizeEmptyInterfaceIfMissing(serializableType);
637         synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
638         synthesizeEmptyInterfaceIfMissing(serializedLambdaType);
639         synthesizeEmptyInterfaceIfMissing(stringConcatFactory);
640         synthesizeBoxTypeIfMissing(doubleType);
641         synthesizeBoxTypeIfMissing(floatType);
642         synthesizeBoxTypeIfMissing(voidType);
643 


644         // Enter a synthetic class that is used to mark internal
645         // proprietary classes in ct.sym.  This class does not have a
646         // class file.
647         proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
648 
649         // Enter a synthetic class that is used to provide profile info for
650         // classes in ct.sym.  This class does not have a class file.
651         profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
652         MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
653         profileType.tsym.members().enter(m);
654 
655         // Enter a class for arrays.
656         // The class implements java.lang.Cloneable and java.io.Serializable.
657         // It has a final length field and a clone method.
658         ClassType arrayClassType = (ClassType)arrayClass.type;
659         arrayClassType.supertype_field = objectType;
660         arrayClassType.interfaces_field = List.of(cloneableType, serializableType);
661         arrayClass.members_field = WriteableScope.create(arrayClass);
662         lengthVar = new VarSymbol(
663             PUBLIC | FINAL,

  1 /*
  2  * Copyright (c) 1999, 2026, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

209     public final Type inheritedType;
210     public final Type profileType;
211     public final Type proprietaryType;
212     public final Type systemType;
213     public final Type autoCloseableType;
214     public final Type trustMeType;
215     public final Type lambdaMetafactory;
216     public final Type stringConcatFactory;
217     public final Type repeatableType;
218     public final Type documentedType;
219     public final Type elementTypeType;
220     public final Type functionalInterfaceType;
221     public final Type previewFeatureType;
222     public final Type previewFeatureInternalType;
223     public final Type restrictedType;
224     public final Type restrictedInternalType;
225     public final Type typeDescriptorType;
226     public final Type recordType;
227     public final Type switchBootstrapsType;
228     public final Type constantBootstrapsType;


229     public final Type requiresIdentityType;
230     public final Type requiresIdentityInternalType;
231     public final Type classDescType;
232     public final Type enumDescType;
233 
234     // For serialization lint checking
235     public final Type objectStreamFieldType;
236     public final Type objectInputStreamType;
237     public final Type objectOutputStreamType;
238     public final Type ioExceptionType;
239     public final Type objectStreamExceptionType;
240     // For externalization lint checking
241     public final Type externalizableType;
242     public final Type objectInputType;
243     public final Type objectOutputType;
244 
245     // valhalla
246     public final Type valueBasedType;
247     public final Type valueBasedInternalType;
248     public final Type migratedValueClassType;
249     public final Type migratedValueClassInternalType;
250     /** The symbol representing the finalize method on Object */
251     public final MethodSymbol objectFinalize;
252     public final Type numberType;
253 
254     /** The symbol representing the length field of an array.
255      */
256     public final VarSymbol lengthVar;
257 
258     /** The symbol representing the final finalize method on enums */
259     public final MethodSymbol enumFinalFinalize;
260 
261     /** The symbol representing the close method on TWR AutoCloseable type */
262     public final MethodSymbol autoCloseableClose;
263 
264     /** The predefined type that belongs to a tag.
265      */
266     public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
267 
268     /** The name of the class that belongs to a basic type tag.
269      */
270     public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()];
271 
272     /** A hashtable containing the encountered top-level and member classes,
273      *  indexed by flat names. The table does not contain local classes.

532 
533         // Enter symbols for basic types.
534         scope.enter(byteType.tsym);
535         scope.enter(shortType.tsym);
536         scope.enter(charType.tsym);
537         scope.enter(intType.tsym);
538         scope.enter(longType.tsym);
539         scope.enter(floatType.tsym);
540         scope.enter(doubleType.tsym);
541         scope.enter(booleanType.tsym);
542         scope.enter(errType.tsym);
543 
544         // Enter symbol for the errSymbol
545         scope.enter(errSymbol);
546 
547         // Get the initial completer for ModuleSymbols from Modules
548         moduleCompleter = Modules.instance(context).getCompleter();
549 
550         // Enter predefined classes. All are assumed to be in the java.base module.
551         objectType = enterClass("java.lang.Object");
552         throwableType = enterClass("java.lang.Throwable");
553         objectFinalize = new MethodSymbol(PROTECTED,
554                 names.finalize,
555                 new MethodType(List.nil(), voidType,
556                         List.of(throwableType), methodClass),
557                 objectType.tsym);
558         objectMethodsType = enterClass("java.lang.runtime.ObjectMethods");
559         exactConversionsSupportType = enterClass("java.lang.runtime.ExactConversionsSupport");
560         objectsType = enterClass("java.util.Objects");
561         classType = enterClass("java.lang.Class");
562         stringType = enterClass("java.lang.String");
563         stringBufferType = enterClass("java.lang.StringBuffer");
564         stringBuilderType = enterClass("java.lang.StringBuilder");
565         cloneableType = enterClass("java.lang.Cloneable");

566         serializableType = enterClass("java.io.Serializable");
567         serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
568         varHandleType = enterClass("java.lang.invoke.VarHandle");
569         methodHandleType = enterClass("java.lang.invoke.MethodHandle");
570         methodHandlesType = enterClass("java.lang.invoke.MethodHandles");
571         methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
572         methodTypeType = enterClass("java.lang.invoke.MethodType");
573         errorType = enterClass("java.lang.Error");
574         illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
575         interruptedExceptionType = enterClass("java.lang.InterruptedException");
576         exceptionType = enterClass("java.lang.Exception");
577         runtimeExceptionType = enterClass("java.lang.RuntimeException");
578         classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
579         noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
580         noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
581         assertionErrorType = enterClass("java.lang.AssertionError");
582         incompatibleClassChangeErrorType = enterClass("java.lang.IncompatibleClassChangeError");
583         cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");
584         matchExceptionType = enterClass("java.lang.MatchException");
585         annotationType = enterClass("java.lang.annotation.Annotation");

613         autoCloseableClose = new MethodSymbol(PUBLIC,
614                              names.close,
615                              new MethodType(List.nil(), voidType,
616                                             List.of(exceptionType), methodClass),
617                              autoCloseableType.tsym);
618         trustMeType = enterClass("java.lang.SafeVarargs");
619         nativeHeaderType = enterClass("java.lang.annotation.Native");
620         lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
621         stringConcatFactory = enterClass("java.lang.invoke.StringConcatFactory");
622         functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
623         previewFeatureType = enterClass("jdk.internal.javac.PreviewFeature");
624         previewFeatureInternalType = enterSyntheticAnnotation("jdk.internal.PreviewFeature+Annotation");
625         restrictedType = enterClass("jdk.internal.javac.Restricted");
626         restrictedInternalType = enterSyntheticAnnotation("jdk.internal.javac.Restricted+Annotation");
627         typeDescriptorType = enterClass("java.lang.invoke.TypeDescriptor");
628         recordType = enterClass("java.lang.Record");
629         switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps");
630         constantBootstrapsType = enterClass("java.lang.invoke.ConstantBootstraps");
631         valueBasedType = enterClass("jdk.internal.ValueBased");
632         valueBasedInternalType = enterSyntheticAnnotation("jdk.internal.ValueBased+Annotation");
633         migratedValueClassType = enterClass("jdk.internal.MigratedValueClass");
634         migratedValueClassInternalType = enterSyntheticAnnotation("jdk.internal.MigratedValueClass+Annotation");
635         requiresIdentityType = enterClass("jdk.internal.RequiresIdentity");
636         requiresIdentityInternalType = enterSyntheticAnnotation(names.requiresIdentityInternal);
637         classDescType = enterClass("java.lang.constant.ClassDesc");
638         enumDescType = enterClass("java.lang.Enum$EnumDesc");
639         // For serialization lint checking
640         objectStreamFieldType = enterClass("java.io.ObjectStreamField");
641         objectInputStreamType = enterClass("java.io.ObjectInputStream");
642         objectOutputStreamType = enterClass("java.io.ObjectOutputStream");
643         ioExceptionType = enterClass("java.io.IOException");
644         objectStreamExceptionType = enterClass("java.io.ObjectStreamException");
645         externalizableType = enterClass("java.io.Externalizable");
646         objectInputType  = enterClass("java.io.ObjectInput");
647         objectOutputType = enterClass("java.io.ObjectOutput");
648         synthesizeEmptyInterfaceIfMissing(autoCloseableType);
649         synthesizeEmptyInterfaceIfMissing(cloneableType);
650         synthesizeEmptyInterfaceIfMissing(serializableType);
651         synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
652         synthesizeEmptyInterfaceIfMissing(serializedLambdaType);
653         synthesizeEmptyInterfaceIfMissing(stringConcatFactory);
654         synthesizeBoxTypeIfMissing(doubleType);
655         synthesizeBoxTypeIfMissing(floatType);
656         synthesizeBoxTypeIfMissing(voidType);
657 
658         numberType = enterClass("java.lang.Number");
659 
660         // Enter a synthetic class that is used to mark internal
661         // proprietary classes in ct.sym.  This class does not have a
662         // class file.
663         proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
664 
665         // Enter a synthetic class that is used to provide profile info for
666         // classes in ct.sym.  This class does not have a class file.
667         profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
668         MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
669         profileType.tsym.members().enter(m);
670 
671         // Enter a class for arrays.
672         // The class implements java.lang.Cloneable and java.io.Serializable.
673         // It has a final length field and a clone method.
674         ClassType arrayClassType = (ClassType)arrayClass.type;
675         arrayClassType.supertype_field = objectType;
676         arrayClassType.interfaces_field = List.of(cloneableType, serializableType);
677         arrayClass.members_field = WriteableScope.create(arrayClass);
678         lengthVar = new VarSymbol(
679             PUBLIC | FINAL,
< prev index next >