JDK 17 jdk.jlink.jmod - JLink Tool

JDK 17 jdk.jlink.jmod is the JMOD file for JDK 17 JLink tool, which can be invoked by the "jlink" command.

JDK 17 JLink tool compiled class files are stored in \fyicenter\jdk-17.0.5\jmods\jdk.jlink.jmod.

JDK 17 JLink tool compiled class files are also linked and stored in the \fyicenter\jdk-17.0.5\lib\modules JImage file.

JDK 17 JLink tool source code files are stored in \fyicenter\jdk-17.0.5\lib\src.zip\jdk.jlink.

You can click and view the content of each source code file in the list below.

✍: FYIcenter

jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java

/*
 * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

package jdk.tools.jlink.internal.plugins;

import java.util.Map;

import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassVisitor;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;

/**
 * Base plugin to update a static field in java.lang.VersionProps
 *
 * Fields to be updated must not be final such that values are not constant
 * replaced at compile time and initialization code is generated.
 * We assume that the initialization code only has ldcs, method calls and
 * field instructions.
 */
abstract class VersionPropsPlugin extends AbstractPlugin {

    private static final String VERSION_PROPS_CLASS
        = "/java.base/java/lang/VersionProps.class";

    private final String field;
    private String value;

    /**
     * @param field The name of the java.lang.VersionProps field to be redefined
     * @param option The option name
     */
    protected VersionPropsPlugin(String field, String option) {
        super(option);
        this.field = field;
    }

    /**
     * Shorthand constructor for when the option name can be derived from the
     * name of the field.
     *
     * @param field The name of the java.lang.VersionProps field to be redefined
     */
    protected VersionPropsPlugin(String field) {
        this(field, field.toLowerCase().replace('_', '-'));
    }

    @Override
    public Category getType() {
        return Category.TRANSFORMER;
    }

    @Override
    public boolean hasArguments() {
        return true;
    }

    @Override
    public boolean hasRawArgument() {
        return true;
    }

    @Override
    public void configure(Map<String, String> config) {
        var v = config.get(getName());
        if (v == null)
            throw new AssertionError();
        value = v;
    }

    private boolean redefined = false;

    private byte[] redefine(byte[] classFile) {

        var cr = new ClassReader(classFile);
        var cw = new ClassWriter(0);

        cr.accept(new ClassVisitor(Opcodes.ASM7, cw) {

                @Override
                public MethodVisitor visitMethod(int access,
                                                 String name,
                                                 String desc,
                                                 String sig,
                                                 String[] xs)
                {
                    if (name.equals("<clinit>"))
                        return new MethodVisitor(Opcodes.ASM7,
                                                 super.visitMethod(access,
                                                                   name,
                                                                   desc,
                                                                   sig,
                                                                   xs))
                            {
                                private Object pendingLDC = null;

                                private void flushPendingLDC() {
                                    if (pendingLDC != null) {
                                        super.visitLdcInsn(pendingLDC);
                                        pendingLDC = null;
                                    }
                                }

                                @Override
                                public void visitLdcInsn(Object value) {
                                    flushPendingLDC();
                                    pendingLDC = value;
                                }

                                @Override
                                public void visitMethodInsn(int opcode,
                                                            String owner,
                                                            String name,
                                                            String descriptor,
                                                            boolean isInterface) {
                                    flushPendingLDC();
                                    super.visitMethodInsn(opcode, owner, name,
                                                          descriptor, isInterface);
                                }

                                @Override
                                public void visitFieldInsn(int opcode,
                                                           String owner,
                                                           String name,
                                                           String desc)
                                {
                                    if (opcode == Opcodes.PUTSTATIC
                                        && name.equals(field))
                                    {
                                        // assert that there is a pending ldc
                                        // for the old value
                                        if (pendingLDC == null) {
                                            throw new AssertionError("No load " +
                                                "instruction found for field " + field +
                                                " in static initializer of " +
                                                VERSION_PROPS_CLASS);
                                        }
                                        // forget about it
                                        pendingLDC = null;
                                        // and add an ldc for the new value
                                        super.visitLdcInsn(value);
                                        redefined = true;
                                    } else {
                                        flushPendingLDC();
                                    }
                                    super.visitFieldInsn(opcode, owner,
                                                         name, desc);
                                }

                        };
                    else
                        return super.visitMethod(access, name, desc, sig, xs);
                }

            }, 0);

        return cw.toByteArray();

    }

    @Override
    public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
        in.transformAndCopy(res -> {
                if (res.type().equals(ResourcePoolEntry.Type.CLASS_OR_RESOURCE)) {
                    if (res.path().equals(VERSION_PROPS_CLASS)) {
                        return res.copyWithContent(redefine(res.contentBytes()));
                    }
                }
                return res;
            }, out);
        if (!redefined)
            throw new AssertionError(field);
        return out.build();
    }

}

jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java

 

Or download all of them as a single archive file:

File name: jdk.jlink-17.0.5-src.zip
File size: 164180 bytes
Release date: 2022-09-13
Download 

 

JDK 17 jdk.jpackage.jmod - JPackage Tool

JDK 17 jdk.jfr.jmod - JFR Module

JDK 17 JMod/Module Files

⇑⇑ FAQ for JDK (Java Development Kit) 17

2023-08-03, ≈21🔥, 0💬