• Home
    • View
    • Login
    This page
    • Normal
    • Export PDF
    • Page Information

    Loading...
  1. Dashboard
  2. Undefined Space
  3. Valhalla
  4. LW2

Page History

Versions Compared

Old Version 2

changes.mady.by.user David Simms

Saved on Jun 28, 2019

compared with

New Version 3

changes.mady.by.user David Simms

Saved on Jun 29, 2019

  • Previous Change: Difference between versions 1 and 2
  • Next Change: Difference between versions 3 and 4
  • View Page History

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

<Staging>

LW2 is an iteration of previous prototype, adding further language support and JDK API support for "inline-types" (formerly referred to as "value types"). There are also subtle type system, runtime and JIT changes.

Javac source support:

  • Requires source level >= JDK13 (since LW2, the prototype is based on mainline JDK, whose version string is JDK 14 at the time of writing)
  • A class declaration of inline type is made by using the "inline class" modifier, or (for IDE syntax parsing convenience) with "@__inline__" annotation (since LW2)
    • Interfaces, annotation types, enums can not be inline types
    • Top level, inner, nested, local classes may be inline types. Inline types may declare inner, nested, local types
    • Inline Types are implicitly final, so cannot be abstract
  • Inline Types may not declare an explicit super class (except Object). They implicitly extend java.lang.Object akin to enums, annotation types and interfaces
  • Inline Types may declare explicit interfaces
  • Inline Types constructors may not pass the "this" handle until all instance fields are definitely assigned.
  • All instance fields of a inline class are implicitly final
  • Inline types may not to declare fields of its own type directly.
    • There is a method to do this "indirectly" using the "?" operator, but it's value is still final. (since LW2)
  • "Indirect" projections of inline types via the "?" operator (since LW2)
    • maintains type of a field,  array element, or generic parametric argument, but they may be null
    • cast between inline type and indirect type
    • Is implicitly a "NullableType"
    • enables compatibility with current generics via erasure to null-object object references
    • Arrays subtyping relationships: InlineType[] <: IndirectType[] <: Object[] <: Object
      • Widening conversions may be carried out from in the order above
      • Narrowing from an array of IndirectType to an InlineType is not possible.
      • This array covariance enables compatibility with existing API, especially generic type erasure
  • java.lang.Object methods:
    • javac automatically generates hashCode, equals, longHashCode and toString computed solely from the instance's state and not from its identity
    • javac does not clone(), finalize(), wait*), notify*() on inline type receivers
  • javac allows comparison of inline type using ==, != (since LW2)
    • By default this implies a test in the instance state (i.e. field by field "substitutability" test), as inline type have no identity (i.e. not a reference test).
  • Inline Types can not be assigned null, null can not be cast to or compared with inline types
    • With the exception if an "indirect" reference using the "?" operator. (since LW2)
  • Indirect Types cannot be type arguments in generic type parameterizations, type witnesses in generic method invocations, wildcard bounds
    • With the exception if an "indirect" reference using the "?" operator. (since LW2) 
  • Type migration, including partial recompilation is not supported.

...

Note: Valhalla is a child of the jdk/jdk repository, to keep current with latest OpenJDK development.

Programming Model

public inline class InlineType implements Comparable<InlineType?> {
 
    int someValue;
 
    public InlineType(int value) {
        this.someValue = value;
        /*
          implicitly generates "defaultvalue" followed by "withfield" bytecodes
 
          cannot pass "this" from here
         */
    }
 
    // Since existing API can accept "null", we use the indirect projection
    public int compareTo(InlineType? other) {
        if (other == null) {
            return -1;
        }
        return someValue - other.someValue;
    }
 
    public static void main(String[] args) throws Throwable {
        InlineType def = InlineType.default;
        assert(def == new InlineType(0));
 
        InlineType[] inlineTypeArray = new InlineType[1];
        // Inline type array cannot store null
        assert(inlineTypeArray[0] == def);
 
        InlineType?[] indirectTypeArray = new InlineType?[1];
        // Indirect projection of Inline type array can store null
        assert(indirectTypeArray[0] == null);
    }
}

A note on "?" operator and indirect projects

...

Overview
Content Tools
ThemeBuilder

Terms of Use
• License: GPLv2
• Privacy • Trademarks • Contact Us

Powered by a free Atlassian Confluence Open Source Project License granted to https://www.atlassian.com/software/views/opensource-community-additional-license-offer. Evaluate Confluence today.

  • Kolekti ThemeBuilder Powered by Atlassian Confluence 8.5.23
  • Kolekti ThemeBuilder printed.by.atlassian.confluence
  • Report a bug
  • Atlassian News
Atlassian
Kolekti ThemeBuilder EngineAtlassian Confluence
{"serverDuration": 280, "requestCorrelationId": "47e1e12ba08c1f1d"}