On Fri, 14 Nov 2025 11:25:05 GMT, Matthias Baesken <[email protected]> wrote:

> The dead_strip linker option on macOS removes functions and data that are 
> unreachable by the entry point or exported symbols.
> Setting it can reduce the size of some binaries we generate quite a lot, for 
> example (product build, Xcode 15 is used) :
> (before -> after setting the option)
> 
> 1.4M -> 1.1M images/jdk/lib/libfontmanager.dylib
> 264K -> 248K images/jdk/lib/libjavajpeg.dylib
> 152K -> 132K images/jdk/lib/libjli.dylib
> 388K -> 296K images/jdk/lib/liblcms.dylib
> 164K -> 128K images/jdk/lib/libzip.dylib
> 
> 
> and libjvm :
> 
> 20M -> 18M images/jdk/lib/server/libjvm.dylib
> 146M -> 137M images/jdk/lib/server/libjvm.dylib.dSYM

SA is throwing an exception on the following:

`      Klass classLoaderKlass = vm.getSystemDictionary().getClassLoaderKlass();`

This looks to be the first thing it is doing that involves looking up a hotspot 
symbol. Possibly the issue is with symbols in general being stripped, or maybe 
just this one was. The fact that only 3 tests failed makes me think it is some 
very selective dead stripping of symbols that is the problem. Most SA 
functionality does not use SystemDictionary().getClassLoaderKlass(), so if just 
this one symbol was missing, that would explain why for the most part SA is 
working.

On the assumption that it is just this one symbol, Hotspot declares an array of 
InstanceKlass* for some critical classes:


InstanceKlass* vmClasses::_klasses[static_cast<int>(vmClassID::LIMIT)]
                                                 =  { nullptr /*, nullptr...*/ 
};


In SA, the failed SystemDictionary.initialize() part of the stacktrace shows an 
attempt to access this array for the ClassLoader InstanceKlass*

`    classLoaderKlassField = 
type.getAddressField(VM_CLASS_AT("ClassLoader_klass"));`


  private static String VM_CLASS_AT(String name) {
    return "_klasses[static_cast<int>(" + VM_CLASS_ID(name) + ")]";
  }


And in vmStructs we have:

`     static_field(vmClasses,                   VM_CLASS_AT(ClassLoader_klass), 
                  InstanceKlass*)                     `

I think this vmStructs static field is getting dead stripped.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/28319#issuecomment-3549555596

Reply via email to