Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated creation of type systems can exhaust JVM metaspace #371

Closed
reckart opened this issue Jul 11, 2024 · 0 comments
Closed

Repeated creation of type systems can exhaust JVM metaspace #371

reckart opened this issue Jul 11, 2024 · 0 comments
Assignees
Labels
🦟 Bug Something isn't working
Milestone

Comments

@reckart
Copy link
Member

reckart commented Jul 11, 2024

Describe the bug
When repeatedly creating type system instances with lots of classes on a Java 17+ system, it appears that the JVM class metaspace can be exhausted.

To Reproduce
Steps to reproduce the behavior:

  1. Create a large type system description
  2. Repeatedly create type systems from that description
  3. Monitor class metaspace

Diagnosis so far: it appears that TypeSystemImpl.computeAdjustedFeatureOffsets() will always initialize the type2jcci map of the TypeSystemImpl instance. As part of this, FSClassRegistry.createJCasClassInfo() is repeatedly called which creates new generator callsites (lambdas) that start clogging up the metaspace.

The problem happens in particular if CASes are created using a ResourceManager with a custom extension classpath.

  @Test
  void provokeMetaspaceExhaustion() throws Exception {
    tsd.addType(Sentence._TypeName, "", CAS.TYPE_NAME_ANNOTATION);

    for (int i = 0; i < 100_000_000l; i++) {
      var resMgr = new ResourceManager_impl();
      resMgr.setExtensionClassPath(".", false);
      createCas(tsd, null, null, null, resMgr).getJCas();
      // To make sure the consolidated type system is evicted from the weak hashmap cache
      // Alternatively disable type system consolidation
      System.gc(); 
    }
  }
Screenshot 2024-07-11 at 16 06 39

Expected behavior
A solution might be to use the global JCCI cache maintained in FSClassRegistry when populating the TypeSystemImpl.type2jcci maps to avoid repeatedly creating the generator lambdas.

Please complete the following information:

  • Version: 3.5.0

References

  • JEP 371 introduces the concept of hidden classes and defines their relation to classloaders and loading/unloading
  • It seems this may be related to JDK-8302154 - before Java 15 apparently these callsites could be easily garbage collected and now this is more difficult.
@reckart reckart added the 🦟 Bug Something isn't working label Jul 11, 2024
@reckart reckart added this to the 3.5.1 milestone Jul 11, 2024
@reckart reckart self-assigned this Jul 11, 2024
reckart added a commit that referenced this issue Aug 15, 2024
- Adding a "test case" - actually needs manual observation at the moment
reckart added a commit that referenced this issue Aug 15, 2024
reckart added a commit that referenced this issue Aug 16, 2024
- Deprecated various methods that should get differnent signatures or visibility scopes
- Added a cache for generators
- Always use the lookup of the JCas wrapper class itself
reckart added a commit that referenced this issue Aug 16, 2024
- Deprecated various methods that should get differnent signatures or visibility scopes
- Added a cache for generators
- Always use the lookup of the JCas wrapper class itself
reckart added a commit that referenced this issue Aug 28, 2024
…ype-systems-can-exhaust-JVM-metaspace

Issue #371: Repeated creation of type systems can exhaust JVM metaspace
@reckart reckart closed this as completed Aug 28, 2024
reckart added a commit that referenced this issue Aug 28, 2024
…ns-a-JCAS-class-that-is-used-as-a-feature-range-outside-the-PEAR

* release/3.5.x:
  Issue #371: Repeated creation of type systems can exhaust JVM metaspace
  Issue #371: Repeated creation of type systems can exhaust JVM metaspace

% Conflicts:
%	uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
reckart added a commit that referenced this issue Aug 28, 2024
* release/3.5.x:
  Issue #382: Warning when PEAR contains a JCAS class that is used as a feature range outside the PEAR
  Issue #382: Warning when PEAR contains a JCAS class that is used as a feature range outside the PEAR
  Issue #382: Warning when PEAR contains a JCAS class that is used as a feature range outside the PEAR
  Issue #382: Warning when PEAR contains a JCAS class that is used as a feature range outside the PEAR
  Issue #371: Repeated creation of type systems can exhaust JVM metaspace
  Issue #371: Repeated creation of type systems can exhaust JVM metaspace
reckart added a commit that referenced this issue Aug 28, 2024
* main:
  Issue #382: Warning when PEAR contains a JCAS class that is used as a feature range outside the PEAR
  Issue #382: Warning when PEAR contains a JCAS class that is used as a feature range outside the PEAR
  Issue #382: Warning when PEAR contains a JCAS class that is used as a feature range outside the PEAR
  Issue #382: Warning when PEAR contains a JCAS class that is used as a feature range outside the PEAR
  Issue #371: Repeated creation of type systems can exhaust JVM metaspace
  Issue #371: Repeated creation of type systems can exhaust JVM metaspace

% Conflicts:
%	uimaj-core/src/main/java/org/apache/uima/cas/CASRuntimeException.java
%	uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
@reckart reckart modified the milestones: 3.6.1, 3.6.0 Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦟 Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant