Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Unsafe references to packed storage can be wrapped up in safe object handles, and this is one implementation technique for native-code-friendly "arrays". The unsafe-allocated data can be managed in a finalizer for the safe handle; if there are no references to the safe handle, then it is safe to deallocate the packed storage. It would be useful (perhaps more efficient) to designate the safe handles as value objects so that the overhead of heap allocation for new safe handles can be avoided for what would be just "pointer arithmetic" in other languages. One idiomatic way around this would be to use a non-value memory management object that had a finalizer, and include a reference to the memory management object in the safe object handles in addition to the unsafe reference. However, since the memory management object will go unused, dead code elimination might not actually include it in the generated code, which would undermine the intent of the idiom.

Legacy code might expect reference semantics

Legacy code may make use of types that are later used for value objects, but expect them to have reference semantics.

No Format

class Legacy extends Thread {

  private final Float teamLock;
  public Legacy(Float team_lock) {
     teamLock = team_lock;
  }
  
  public void run() {
     ...
     synchronized(teamLock) {
        ...
     }
     ...
  }
}

Such code would not compile in the new value-objects, but the class files could still be referenced from either old or new code. The call to Float.valueOf will run the new-code factory for Float value objects, but it will be seen by old code.

No Format

...
Float team_lock = Float.valueOf(42.0);
LegacyThread t1 = new LegacyThread(team_lock);
LegacyThread t2 = new LegacyThread(team_lock);
...