MetaClassLoader top-level property

ClassLoader MetaClassLoader
final

The default system implementation of ClassLoader with comprehensive caching.

Provides efficient class loading and caching for the JetLeaf reflection system. This implementation uses multiple specialized caches to optimize different types of reflection queries and maintains detailed statistics for monitoring.

Cache Architecture

The DefaultClassLoader employs a multi-tier caching strategy:

Primary Caches

  • Class Cache: Maps qualified names to Class instances
  • Subclass Cache: Maps parent classes to their direct classes
  • Interface Cache: Maps classes to their implemented interfaces
  • Mixin Cache: Maps classes to their applied mixins

Declared Caches (Non-transitive)

  • Declared Interface Cache: Direct interface implementations only
  • Declared Mixin Cache: Direct mixin applications only

Performance Characteristics

  • Class Loading: O(1) for cached, O(log n) for new classes
  • Hierarchy Queries: O(1) for cached relationships
  • Memory Usage: Configurable with automatic cleanup
  • Thread Safety: Full concurrent access support

Example Usage

// Create system class loader
final loader = DefaultClassLoader();

// Load classes with caching
final stringClass = await loader.loadClass<String>('dart:core/string.dart.String');
final listClass = await loader.loadClass<List>('dart:core/list.dart.List');

// Query relationships (cached)
final classes = await loader.findSubclasses(stringClass);
final interfaces = await loader.findInterfaces(listClass);

// Monitor performance
final stats = loader.getCacheStats();
print('Hit rate: ${stats.hitRate}');

// Cleanup
await loader.flush(); // Clear caches
await loader.close(); // Release resources

Configuration Options

The loader supports various configuration parameters:

  • Max Cache Size: Prevents unbounded memory growth
  • Auto-flush Threshold: Automatic cache cleanup triggers
  • Statistics Collection: Detailed performance monitoring
  • Security Domains: Fine-grained access control

Thread Safety

All operations are thread-safe and support concurrent access:

  • Multiple threads can load classes simultaneously
  • Cache updates are atomic and consistent
  • Statistics are accurately maintained under concurrency
  • Resource cleanup is coordinated across threads

Implementation

final ClassLoader MetaClassLoader = DefaultClassLoader();