src/jdk.dynalink/share/classes/module-info.java
author hannesw
Tue, 10 Sep 2019 15:30:23 +0200
changeset 58071 8a066d872553
parent 47216 71c04702a3d5
permissions -rw-r--r--
8230766: Changed message in IllegalMonitorStateException Reviewed-by: attila, jlaskey
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36517
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
    25
42380
180839e7d68a 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36517
diff changeset
    26
/**
45538
3391b408f58a 8181639: Add tool and services information to module summary
mchung
parents: 44554
diff changeset
    27
 * Defines the API for dynamic linking of high-level operations on objects.
43016
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    28
 * <p>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    29
 * Dynalink is a library for dynamic linking of high-level operations on objects.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    30
 * These operations include "read a property",
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    31
 * "write a property", "invoke a function" and so on. Dynalink is primarily
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    32
 * useful for implementing programming languages where at least some expressions
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    33
 * have dynamic types (that is, types that can not be decided statically), and
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    34
 * the operations on dynamic types are expressed as
45788
2ddc93e42974 8182776: Fix typos in module declarations
mr
parents: 45538
diff changeset
    35
 * {@linkplain java.lang.invoke.CallSite call sites}. These call sites will be
2ddc93e42974 8182776: Fix typos in module declarations
mr
parents: 45538
diff changeset
    36
 * linked to appropriate target {@linkplain java.lang.invoke.MethodHandle method handles}
43016
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    37
 * at run time based on actual types of the values the expressions evaluated to.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    38
 * These can change between invocations, necessitating relinking the call site
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    39
 * multiple times to accommodate new types; Dynalink handles all that and more.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    40
 * <p>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    41
 * Dynalink supports implementation of programming languages with object models
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    42
 * that differ (even radically) from the JVM's class-based model and have their
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    43
 * custom type conversions.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    44
 * <p>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    45
 * Dynalink is closely related to, and relies on, the {@link java.lang.invoke}
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    46
 * package.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    47
 * <p>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    48
 *
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    49
 * While {@link java.lang.invoke} provides a low level API for dynamic linking
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    50
 * of {@code invokedynamic} call sites, it does not provide a way to express
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    51
 * higher level operations on objects, nor methods that implement them. These
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    52
 * operations are the usual ones in object-oriented environments: property
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    53
 * access, access of elements of collections, invocation of methods and
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    54
 * constructors (potentially with multiple dispatch, e.g. link- and run-time
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    55
 * equivalents of Java overloaded method resolution). These are all functions
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    56
 * that are normally desired in a language on the JVM. If a language is
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    57
 * statically typed and its type system matches that of the JVM, it can
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    58
 * accomplish this with use of the usual invocation, field access, etc.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    59
 * instructions (e.g. {@code invokevirtual}, {@code getfield}). However, if the
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    60
 * language is dynamic (hence, types of some expressions are not known until
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    61
 * evaluated at run time), or its object model or type system don't match
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    62
 * closely that of the JVM, then it should use {@code invokedynamic} call sites
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    63
 * instead and let Dynalink manage them.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    64
 * <h2>Example</h2>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    65
 * Dynalink is probably best explained by an example showing its use. Let's
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    66
 * suppose you have a program in a language where you don't have to declare the
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    67
 * type of an object and you want to access a property on it:
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    68
 * <pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    69
 * var color = obj.color;
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    70
 * </pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    71
 * If you generated a Java class to represent the above one-line program, its
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    72
 * bytecode would look something like this:
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    73
 * <pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    74
 * aload 2 // load "obj" on stack
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    75
 * invokedynamic "GET:PROPERTY:color"(Object)Object // invoke property getter on object of unknown type
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    76
 * astore 3 // store the return value into local variable "color"
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    77
 * </pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    78
 * In order to link the {@code invokedynamic} instruction, we need a bootstrap
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    79
 * method. A minimalist bootstrap method with Dynalink could look like this:
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    80
 * <pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    81
 * import java.lang.invoke.*;
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    82
 * import jdk.dynalink.*;
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    83
 * import jdk.dynalink.support.*;
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    84
 *
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    85
 * class MyLanguageRuntime {
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    86
 *     private static final DynamicLinker dynamicLinker = new DynamicLinkerFactory().createLinker();
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    87
 *
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    88
 *     public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type) {
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    89
 *         return dynamicLinker.link(
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    90
 *             new SimpleRelinkableCallSite(
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    91
 *                 new CallSiteDescriptor(lookup, parseOperation(name), type)));
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    92
 *     }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    93
 *
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    94
 *     private static Operation parseOperation(String name) {
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    95
 *         ...
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    96
 *     }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    97
 * }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    98
 * </pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
    99
 * There are several objects of significance in the above code snippet:
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   100
 * <ul>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   101
 * <li>{@link jdk.dynalink.DynamicLinker} is the main object in Dynalink, it
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   102
 * coordinates the linking of call sites to method handles that implement the
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   103
 * operations named in them. It is configured and created using a
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   104
 * {@link jdk.dynalink.DynamicLinkerFactory}.</li>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   105
 * <li>When the bootstrap method is invoked, it needs to create a
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   106
 * {@link java.lang.invoke.CallSite} object. In Dynalink, these call sites need
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   107
 * to additionally implement the {@link jdk.dynalink.RelinkableCallSite}
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   108
 * interface. "Relinkable" here alludes to the fact that if the call site
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   109
 * encounters objects of different types at run time, its target will be changed
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   110
 * to a method handle that can perform the operation on the newly encountered
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   111
 * type. {@link jdk.dynalink.support.SimpleRelinkableCallSite} and
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   112
 * {@link jdk.dynalink.support.ChainedCallSite} (not used in the above example)
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   113
 * are two implementations already provided by the library.</li>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   114
 * <li>Dynalink uses {@link jdk.dynalink.CallSiteDescriptor} objects to
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   115
 * preserve the parameters to the bootstrap method: the lookup and the method type,
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   116
 * as it will need them whenever it needs to relink a call site.</li>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   117
 * <li>Dynalink uses {@link jdk.dynalink.Operation} objects to express
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   118
 * dynamic operations. It does not prescribe how would you encode the operations
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   119
 * in your call site, though. That is why in the above example the
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   120
 * {@code parseOperation} function is left empty, and you would be expected to
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   121
 * provide the code to parse the string {@code "GET:PROPERTY:color"}
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   122
 * in the call site's name into a named property getter operation object as
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   123
 * {@code StandardOperation.GET.withNamespace(StandardNamespace.PROPERTY).named("color")}.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   124
 * </ul>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   125
 * <p>What can you already do with the above setup? {@code DynamicLinkerFactory}
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   126
 * by default creates a {@code DynamicLinker} that can link Java objects with the
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   127
 * usual Java semantics. If you have these three simple classes:
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   128
 * <pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   129
 * public class A {
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   130
 *     public String color;
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   131
 *     public A(String color) { this.color = color; }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   132
 * }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   133
 *
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   134
 * public class B {
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   135
 *     private String color;
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   136
 *     public B(String color) { this.color = color; }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   137
 *     public String getColor() { return color; }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   138
 * }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   139
 *
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   140
 * public class C {
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   141
 *     private int color;
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   142
 *     public C(int color) { this.color = color; }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   143
 *     public int getColor() { return color; }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   144
 * }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   145
 * </pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   146
 * and you somehow create their instances and pass them to your call site in your
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   147
 * programming language:
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   148
 * <pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   149
 * for each(var obj in [new A("red"), new B("green"), new C(0x0000ff)]) {
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   150
 *     print(obj.color);
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   151
 * }
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   152
 * </pre>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   153
 * then on first invocation, Dynalink will link the {@code .color} getter
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   154
 * operation to a field getter for {@code A.color}, on second invocation it will
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   155
 * relink it to {@code B.getColor()} returning a {@code String}, and finally on
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   156
 * third invocation it will relink it to {@code C.getColor()} returning an {@code int}.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   157
 * The {@code SimpleRelinkableCallSite} we used above only remembers the linkage
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   158
 * for the last encountered type (it implements what is known as a <i>monomorphic
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   159
 * inline cache</i>). Another already provided implementation,
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   160
 * {@link jdk.dynalink.support.ChainedCallSite} will remember linkages for
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   161
 * several different types (it is a <i>polymorphic inline cache</i>) and is
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   162
 * probably a better choice in serious applications.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   163
 * <h2>Dynalink and bytecode creation</h2>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   164
 * {@code CallSite} objects are usually created as part of bootstrapping
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   165
 * {@code invokedynamic} instructions in bytecode. Hence, Dynalink is typically
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   166
 * used as part of language runtimes that compile programs into Java
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   167
 * {@code .class} bytecode format. Dynalink does not address the aspects of
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   168
 * either creating bytecode classes or loading them into the JVM. That said,
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   169
 * Dynalink can also be used without bytecode compilation (e.g. in language
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   170
 * interpreters) by creating {@code CallSite} objects explicitly and associating
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   171
 * them with representations of dynamic operations in the interpreted program
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   172
 * (e.g. a typical representation would be some node objects in a syntax tree).
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   173
 * <h2>Available operations</h2>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   174
 * Dynalink defines several standard operations in its
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   175
 * {@link jdk.dynalink.StandardOperation} class. The linker for Java
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   176
 * objects can link all of these operations, and you are encouraged to at
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   177
 * minimum support and use these operations in your language too. The
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   178
 * standard operations {@code GET} and {@code SET} need to be combined with
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   179
 * at least one {@link jdk.dynalink.Namespace} to be useful, e.g. to express a
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   180
 * property getter, you'd use {@code StandardOperation.GET.withNamespace(StandardNamespace.PROPERTY)}.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   181
 * Dynalink defines three standard namespaces in the {@link jdk.dynalink.StandardNamespace} class.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   182
 * To associate a fixed name with an operation, you can use
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   183
 * {@link jdk.dynalink.NamedOperation} as in the previous example:
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   184
 * {@code StandardOperation.GET.withNamespace(StandardNamespace.PROPERTY).named("color")}
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   185
 * expresses a getter for the property named "color".
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   186
 * <h2>Operations on multiple namespaces</h2>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   187
 * Some languages might not have separate namespaces on objects for
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   188
 * properties, elements, and methods, and a source language construct might
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   189
 * address several of them at once. Dynalink supports specifying multiple
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   190
 * {@link jdk.dynalink.Namespace} objects with {@link jdk.dynalink.NamespaceOperation}.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   191
 * <h2>Language-specific linkers</h2>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   192
 * Languages that define their own object model different than the JVM
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   193
 * class-based model and/or use their own type conversions will need to create
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   194
 * their own language-specific linkers. See the {@link jdk.dynalink.linker}
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   195
 * package and specifically the {@link jdk.dynalink.linker.GuardingDynamicLinker}
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   196
 * interface to get started.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   197
 * <h2>Dynalink and Java objects</h2>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   198
 * The {@code DynamicLinker} objects created by {@code DynamicLinkerFactory} by
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   199
 * default contain an internal instance of
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   200
 * {@code BeansLinker}, which is a language-specific linker
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   201
 * that implements the usual Java semantics for all of the above operations and
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   202
 * can link any Java object that no other language-specific linker has managed
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   203
 * to link. This way, all language runtimes have built-in interoperability with
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   204
 * ordinary Java objects. See {@link jdk.dynalink.beans.BeansLinker} for details
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   205
 * on how it links the various operations.
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   206
 * <h2>Cross-language interoperability</h2>
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   207
 * A {@code DynamicLinkerFactory} can be configured with a
45788
2ddc93e42974 8182776: Fix typos in module declarations
mr
parents: 45538
diff changeset
   208
 * {@linkplain jdk.dynalink.DynamicLinkerFactory#setClassLoader(ClassLoader) class
43016
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   209
 * loader}. It will try to instantiate all
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   210
 * {@link jdk.dynalink.linker.GuardingDynamicLinkerExporter} classes visible to
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   211
 * that class loader and compose the linkers they provide into the
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   212
 * {@code DynamicLinker} it creates. This allows for interoperability between
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   213
 * languages: if you have two language runtimes A and B deployed in your JVM and
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   214
 * they export their linkers through the above mechanism, language runtime A
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   215
 * will have a language-specific linker instance from B and vice versa inside
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   216
 * their {@code DynamicLinker} objects. This means that if an object from
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   217
 * language runtime B gets passed to code from language runtime A, the linker
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   218
 * from B will get a chance to link the call site in A when it encounters the
f78ab1eafdb9 8172183: Provide a javadoc description for jdk.dynalink module
sundar
parents: 42380
diff changeset
   219
 * object from B.
43742
abd8bc4c4c9d 8174699: Fix @since in module-info.java in dev/nashorn repo
mli
parents: 43016
diff changeset
   220
 *
45538
3391b408f58a 8181639: Add tool and services information to module summary
mchung
parents: 44554
diff changeset
   221
 * @uses jdk.dynalink.linker.GuardingDynamicLinkerExporter
3391b408f58a 8181639: Add tool and services information to module summary
mchung
parents: 44554
diff changeset
   222
 *
44554
32d5c25b2951 8178286: Missing @moduleGraph in javadoc
mchung
parents: 43742
diff changeset
   223
 * @moduleGraph
43742
abd8bc4c4c9d 8174699: Fix @since in module-info.java in dev/nashorn repo
mli
parents: 43016
diff changeset
   224
 * @since 9
42380
180839e7d68a 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36517
diff changeset
   225
 */
36517
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   226
module jdk.dynalink {
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   227
    requires java.logging;
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   228
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   229
    exports jdk.dynalink;
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   230
    exports jdk.dynalink.beans;
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   231
    exports jdk.dynalink.linker;
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   232
    exports jdk.dynalink.linker.support;
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    exports jdk.dynalink.support;
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   234
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   235
    uses jdk.dynalink.linker.GuardingDynamicLinkerExporter;
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   236
}
41a1c20eb619 8142968: Module System implementation
alanb
parents:
diff changeset
   237