make/src/classes/build/tools/x11wrappergen/WrapperGenerator.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


 824 
 825 
 826         pw.println("class " + stp.getJavaClassName() + "AccessorImpl"  + " extends " + stp.getJavaClassName() + "Accessor  {");
 827         pw.println("/*\nThis class serves as a Wrapper for the following X Struct \nsThe offsets here are calculated based on actual compiler.\n\n" +stp.getDescription() + "\n\n */");
 828 
 829         writeAccessorImpls(stp, pw);
 830 
 831         pw.println("\n\n } \n\n");
 832     }
 833 
 834     public void writeWrapper(String outputDir, StructType stp)
 835     {
 836         if (stp.getNumFields() > 0) {
 837 
 838             try {
 839                 FileOutputStream fs =  new FileOutputStream(outputDir + "/"+stp.getJavaClassName()+".java");
 840                 PrintWriter pw = new PrintWriter(fs);
 841                 pw.println("// This file is an automatically generated file, please do not edit this file, modify the WrapperGenerator.java file instead !\n" );
 842 
 843                 pw.println("package "+package_name+";\n");
 844                 pw.println("import sun.misc.*;\n");
 845                 pw.println("import sun.util.logging.PlatformLogger;");
 846                 String baseClass = stp.getBaseClass();
 847                 if (baseClass == null) {
 848                     baseClass = defaultBaseClass;
 849                 }
 850                 if (stp.getIsInterface()) {
 851                     pw.print("public interface ");
 852                     pw.print(stp.getJavaClassName());
 853                 } else {
 854                     pw.print("public class ");
 855                     pw.print(stp.getJavaClassName() + " extends " + baseClass);
 856                 }
 857                 if (stp.getInterfaces() != null) {
 858                     pw.print(" implements " + stp.getInterfaces());
 859                 }
 860                 pw.println(" { ");
 861                 if (!stp.getIsInterface()) {
 862                     pw.println("\tprivate Unsafe unsafe = XlibWrapper.unsafe; ");
 863                     pw.println("\tprivate final boolean should_free_memory;");
 864                     pw.println("\tpublic static int getSize() { return " + stp.getSize() + "; }");


 924                         sizeTable64bit.put(splits[0],splits[1]);
 925                     } else {
 926                         sizeTable32bit.put(splits[0],splits[1]);
 927                     }
 928                 }
 929             }
 930             return true;
 931         } catch (Exception e) {
 932             e.printStackTrace();
 933             return false;
 934         }
 935     }
 936 
 937     public void writeFunctionCallWrapper(String outputDir, FunctionType ft) {
 938         try {
 939             FileOutputStream fs =  new FileOutputStream(outputDir + "/" + ft.getName()+".java");
 940             PrintWriter pw = new PrintWriter(fs);
 941             pw.println("// This file is an automatically generated file, please do not edit this file, modify the WrapperGenerator.java file instead !\n" );
 942 
 943             pw.println("package "+package_name+";\n");
 944             pw.println("import sun.misc.Unsafe;\n");
 945             pw.println("class " + ft.getName() + " {");
 946             pw.println("\tprivate static Unsafe unsafe = XlibWrapper.unsafe;");
 947             pw.println("\tprivate boolean __executed = false;");
 948             pw.println("\tprivate boolean __disposed = false;");
 949             Iterator iter = ft.getArguments().iterator();
 950             while (iter.hasNext()) {
 951                 AtomicType at = (AtomicType)iter.next();
 952                 if (at.isIn()) {
 953                     pw.println("\t" + at.getJavaType() + " _" + at.getName() + ";");
 954                 } else {
 955                     pw.println("\tlong " + at.getName() + "_ptr = unsafe.allocateMemory(Native.get" + at.getTypeUpperCase() + "Size());");
 956                 }
 957             }
 958             pw.println("\tpublic " + ft.getName() + "(");
 959             iter = ft.getArguments().iterator();
 960             boolean first = true;
 961             while (iter.hasNext()) {
 962                 AtomicType at = (AtomicType)iter.next();
 963                 if (at.isIn() || at.isInOut()) {
 964                     if (!first) {




 824 
 825 
 826         pw.println("class " + stp.getJavaClassName() + "AccessorImpl"  + " extends " + stp.getJavaClassName() + "Accessor  {");
 827         pw.println("/*\nThis class serves as a Wrapper for the following X Struct \nsThe offsets here are calculated based on actual compiler.\n\n" +stp.getDescription() + "\n\n */");
 828 
 829         writeAccessorImpls(stp, pw);
 830 
 831         pw.println("\n\n } \n\n");
 832     }
 833 
 834     public void writeWrapper(String outputDir, StructType stp)
 835     {
 836         if (stp.getNumFields() > 0) {
 837 
 838             try {
 839                 FileOutputStream fs =  new FileOutputStream(outputDir + "/"+stp.getJavaClassName()+".java");
 840                 PrintWriter pw = new PrintWriter(fs);
 841                 pw.println("// This file is an automatically generated file, please do not edit this file, modify the WrapperGenerator.java file instead !\n" );
 842 
 843                 pw.println("package "+package_name+";\n");
 844                 pw.println("import jdk.internal.misc.Unsafe;\n");
 845                 pw.println("import sun.util.logging.PlatformLogger;");
 846                 String baseClass = stp.getBaseClass();
 847                 if (baseClass == null) {
 848                     baseClass = defaultBaseClass;
 849                 }
 850                 if (stp.getIsInterface()) {
 851                     pw.print("public interface ");
 852                     pw.print(stp.getJavaClassName());
 853                 } else {
 854                     pw.print("public class ");
 855                     pw.print(stp.getJavaClassName() + " extends " + baseClass);
 856                 }
 857                 if (stp.getInterfaces() != null) {
 858                     pw.print(" implements " + stp.getInterfaces());
 859                 }
 860                 pw.println(" { ");
 861                 if (!stp.getIsInterface()) {
 862                     pw.println("\tprivate Unsafe unsafe = XlibWrapper.unsafe; ");
 863                     pw.println("\tprivate final boolean should_free_memory;");
 864                     pw.println("\tpublic static int getSize() { return " + stp.getSize() + "; }");


 924                         sizeTable64bit.put(splits[0],splits[1]);
 925                     } else {
 926                         sizeTable32bit.put(splits[0],splits[1]);
 927                     }
 928                 }
 929             }
 930             return true;
 931         } catch (Exception e) {
 932             e.printStackTrace();
 933             return false;
 934         }
 935     }
 936 
 937     public void writeFunctionCallWrapper(String outputDir, FunctionType ft) {
 938         try {
 939             FileOutputStream fs =  new FileOutputStream(outputDir + "/" + ft.getName()+".java");
 940             PrintWriter pw = new PrintWriter(fs);
 941             pw.println("// This file is an automatically generated file, please do not edit this file, modify the WrapperGenerator.java file instead !\n" );
 942 
 943             pw.println("package "+package_name+";\n");
 944             pw.println("import jdk.internal.misc.Unsafe;\n");
 945             pw.println("class " + ft.getName() + " {");
 946             pw.println("\tprivate static Unsafe unsafe = XlibWrapper.unsafe;");
 947             pw.println("\tprivate boolean __executed = false;");
 948             pw.println("\tprivate boolean __disposed = false;");
 949             Iterator iter = ft.getArguments().iterator();
 950             while (iter.hasNext()) {
 951                 AtomicType at = (AtomicType)iter.next();
 952                 if (at.isIn()) {
 953                     pw.println("\t" + at.getJavaType() + " _" + at.getName() + ";");
 954                 } else {
 955                     pw.println("\tlong " + at.getName() + "_ptr = unsafe.allocateMemory(Native.get" + at.getTypeUpperCase() + "Size());");
 956                 }
 957             }
 958             pw.println("\tpublic " + ft.getName() + "(");
 959             iter = ft.getArguments().iterator();
 960             boolean first = true;
 961             while (iter.hasNext()) {
 962                 AtomicType at = (AtomicType)iter.next();
 963                 if (at.isIn() || at.isInOut()) {
 964                     if (!first) {