[ 
https://issues.apache.org/jira/browse/HBASE-26773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17498548#comment-17498548
 ] 

Duo Zhang commented on HBASE-26773:
-----------------------------------

This is my code for generating the HBaseUnsafe and HBaseUnsafe0 code.

{code}
package com.github.apache9.unsafe;

import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Generator {

    private static final Pattern METHOD = Pattern.compile("public (final 
)?(native )?(\\S+)\\s+(\\S+)\\((.*)\\)");

    public static void main(String[] args) throws Exception {
        try (PrintWriter pw = new 
PrintWriter("/home/zhangduo/hbase/HBaseUnsafe0")) {
            for (String line : 
Files.readAllLines(Paths.get("/home/zhangduo/hbase/all_methods"))) {
                Matcher m = METHOD.matcher(line);
                if (m.find()) {
                    String returnType = m.group(3);
                    String name = m.group(4);
                    String params = m.group(5);
                    pw.println("public static " + returnType + " " + name + "(" 
+ params + ") {");
                    if (!returnType.equals("void")) {
                        pw.print("return ");
                    }
                    pw.print("HBaseUnsafe0." + name + "(");
                    if (params.trim().length() > 0) {
                        String[] typeAndNames = params.split(",\\s*");
                        String str = Stream.of(typeAndNames).map(typeAndName -> 
typeAndName.split("\\s+")[1])
                                .collect(Collectors.joining(", "));
                        pw.print(str);
                    }
                    pw.println(");");
                    pw.println("}");
                    pw.println();
                } else {
                    System.out.println("error: " + line);
                }
            }
        }
    }
}
{code}

https://github.com/Apache9/TempCode/blob/master/src/main/java/com/github/apache9/unsafe/Generator.java

First you need get a file with all the public methods of Unsafe. This is not 
very hard, just use grep and some manual work.

> [hbase-thirdparty] Introduce a hbase-unsafe module in hbase-thirdparty to 
> remove the direct references of Unsafe in our main code base
> --------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HBASE-26773
>                 URL: https://issues.apache.org/jira/browse/HBASE-26773
>             Project: HBase
>          Issue Type: Improvement
>          Components: compatibility, thirdparty
>            Reporter: Duo Zhang
>            Assignee: Duo Zhang
>            Priority: Major
>
> For java 9+, sun.misc.Unsafe is in the module jdk.unsupported. When compiling 
> with java 11 --release 8, these symbols will not be exported and lead to 
> compile errors.
> There is a jdk issue
> https://bugs.openjdk.java.net/browse/JDK-8214165
> But seems the jdk team does not want to fix it. So if we want to move up to 
> java 11 but still keep the java 8 compatibility, a possible choice is to 
> remove the direct reference of sun.misc.Unsafe so at compile time there will 
> be no problem, and at runtime we export the jdk.unsupported so there will be 
> no problem too.
> For more details, please see the discussion of this thread on the dev mailing 
> list.
> https://lists.apache.org/thread/w5lrxkhswlonj09xf9hcwgvck3nsjdfx



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to