Ejemplo n.º 1
0
 public void printError(java.io.PrintStream o) {
   if (failureMode != null) {
     failureMode.printStackTrace(o);
   } else {
     if (out != null && out.checkError()) o.println(outputFileName + ": Output write error");
   }
 }
Ejemplo n.º 2
0
 public void close() {
   if (out != null) {
     out.close();
     outputFileName = null;
     out = null;
   }
 }
Ejemplo n.º 3
0
  public boolean writeClasses(ConstantPool consts, ConstantPool sharedconsts) {
    ClassClass classes[] = ClassClass.getClassVector(classMaker);
    ClassClass.setTypes();

    // write out some constant pool stuff here,
    writeProlog();

    try {
      writeAllNativeTables(classes);
    } catch (RuntimeException e) {
      out.flush();
      System.out.println(e);
      e.printStackTrace(System.out);
      formatError = true;
    }
    writeEpilog();
    return (!formatError) && (!out.checkError());
  }
Ejemplo n.º 4
0
 protected void writeEpilog() {
   out.println();
   out.println("#endif");
 }
Ejemplo n.º 5
0
 protected void writeProlog() {
   out.println("/* This is a generated file.  Do not modify.");
   out.println(" * Generated on " + new java.util.Date());
   out.println(" */");
   out.println();
   out.println("/*");
   out.println(" *");
   out.println(" * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.");
   out.println(" * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER");
   out.println(" * ");
   out.println(" * This program is free software; you can redistribute it and/or");
   out.println(" * modify it under the terms of the GNU General Public License version");
   out.println(" * 2 only, as published by the Free Software Foundation.");
   out.println(" * ");
   out.println(" * This program is distributed in the hope that it will be useful, but");
   out.println(" * WITHOUT ANY WARRANTY; without even the implied warranty of");
   out.println(" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
   out.println(" * General Public License version 2 for more details (a copy is");
   out.println(" * included at /legal/license.txt).");
   out.println(" * ");
   out.println(" * You should have received a copy of the GNU General Public License");
   out.println(" * version 2 along with this work; if not, write to the Free Software");
   out.println(" * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA");
   out.println(" * 02110-1301 USA");
   out.println(" * ");
   out.println(" * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa");
   out.println(" * Clara, CA 95054 or visit www.sun.com if you need additional");
   out.println(" * information or have any questions.");
   out.println(" */");
   out.println();
   out.println("#include \"jvmconfig.h\"");
   out.println("#if !defined(ROMIZING) || !defined(PRODUCT)");
   out.println("#include \"NativesTable.hpp\"");
   out.println("#include \"kni.h\"");
   out.println();
   out.println();
 }
Ejemplo n.º 6
0
  protected void writeAllNativeTables(ClassClass classes[]) {
    sortClasses(classes);
    Vector nativeClasses = new Vector();

    // (1) Write all the function declarations
    for (int i = 0; i < classes.length; i++) {
      boolean classHasNatives = false;
      EVMClass cc = (EVMClass) classes[i];
      if (cc.isPrimitiveClass() || cc.isArrayClass()) {
        continue;
      }
      EVMMethodInfo m[] = cc.methods;
      sortMethods(m);
      int nmethod = (m == null) ? 0 : m.length;
      for (int j = 0; j < nmethod; j++) {
        EVMMethodInfo meth = m[j];
        MethodInfo mi = meth.method;
        if (!isNativeOrEntryFunc(cc, mi)) {
          continue;
        }
        if (!classHasNatives) {
          classHasNatives = true;
          nativeClasses.addElement(cc);
        }
        int entry;
        entry = checkEntry(cc, mi);
        if (entry < 0 || use_entries[entry].length > 4) {
          // This is a "native"
          out.println(
              "extern \"C\" " + mi.getJNIReturnType() + " " + mi.getNativeName(true) + "();");
        }
        if (entry >= 0) {
          // This is an "entry" (could also be a "native")
          out.println("extern \"C\" void " + use_entries[entry][3] + "();");
        }
      }
    }
    out.println();
    out.println();

    // (2) Write all the "_natives[]" and "_entries[]" tables for
    //     individual classes

    for (Enumeration e = nativeClasses.elements(); e.hasMoreElements(); ) {
      EVMClass cc = (EVMClass) e.nextElement();
      EVMMethodInfo m[] = cc.methods;
      int nmethod = (m == null) ? 0 : m.length;
      int num_native_methods = 0;
      int num_entry_methods = 0;

      for (int j = 0; j < nmethod; j++) {
        EVMMethodInfo meth = m[j];
        MethodInfo mi = meth.method;
        if (!isNativeOrEntryFunc(cc, mi)) {
          continue;
        }
        if (isNativeFunc(cc, mi)) {
          num_native_methods++;
        }
        if (isEntryFunc(cc, mi)) {
          num_entry_methods++;
        }
      }

      // Write the "_natives[]" struct
      if (num_native_methods > 0) {
        out.println("static const JvmNativeFunction " + cc.getNativeName() + "_natives[] = " + "{");
        for (int j = 0; j < nmethod; j++) {
          EVMMethodInfo meth = m[j];
          MethodInfo mi = meth.method;
          if (!isNativeOrEntryFunc(cc, mi)) {
            continue;
          }
          if (isNativeFunc(cc, mi)) {
            out.print(pad("  JVM_NATIVE(\"" + mi.name.string + "\",", 30));
            out.print(pad("\"" + mi.type.string + "\", ", 25));
            out.println(mi.getNativeName(true) + "),");
          }
        }
        out.println("  {(char*)0, (char*)0, (void*)0}");
        out.println("};");
        out.println();
      }

      // Write the "_entries[]" struct
      if (num_entry_methods > 0) {
        out.println("static const JvmNativeFunction " + cc.getNativeName() + "_entries[] = " + "{");
        for (int j = 0; j < nmethod; j++) {
          EVMMethodInfo meth = m[j];
          MethodInfo mi = meth.method;
          if (!isNativeOrEntryFunc(cc, mi)) {
            continue;
          }
          int entry;
          if ((entry = checkEntry(cc, mi)) >= 0) {
            out.print(
                "  JVM_ENTRY(\"" + mi.name.string + "\"," + spaces(20 - mi.name.string.length()));
            out.print("\"" + mi.type.string + "\", ");
            out.println(use_entries[entry][3] + "),");
          }
        }
        out.println("  {(char*)0, (char*)0, (void*)0}");
        out.println("};");
        out.println();
      }
    }

    // (3) Write the top-level table

    out.println("const JvmNativesTable jvm_natives_table[] = {");

    for (Enumeration e = nativeClasses.elements(); e.hasMoreElements(); ) {
      EVMClass cc = (EVMClass) e.nextElement();
      String className = cc.ci.className;
      out.println("  JVM_TABLE(\"" + className + "\",");
      EVMMethodInfo m[] = cc.methods;
      int nmethod = (m == null) ? 0 : m.length;

      int num_native_methods = 0;
      int num_entry_methods = 0;

      for (int j = 0; j < nmethod; j++) {
        EVMMethodInfo meth = m[j];
        MethodInfo mi = meth.method;
        if (!isNativeOrEntryFunc(cc, mi)) {
          continue;
        }
        if (isNativeFunc(cc, mi)) {
          num_native_methods++;
        }
        if (isEntryFunc(cc, mi)) {
          num_entry_methods++;
        }
      }

      if (num_native_methods > 0) {
        out.println(spaces(40) + cc.getNativeName() + "_natives,");
      } else {
        out.println(spaces(40) + "(JvmNativeFunction*)0,");
      }
      if (num_entry_methods > 0) {
        out.println(spaces(40) + cc.getNativeName() + "_entries),");
      } else {
        out.println(spaces(40) + "(JvmNativeFunction*)0),");
      }
    }
    out.println("  JVM_TABLE((char*)0, (JvmNativeFunction*)0, " + "(JvmNativeFunction*)0)");
    out.println("};");

    // (4) Write the jvm_native_execution_top-level table

    out.println("const JvmExecutionEntry jvm_api_entries[] = {");
    for (Enumeration e = nativeClasses.elements(); e.hasMoreElements(); ) {
      EVMClass cc = (EVMClass) e.nextElement();
      EVMMethodInfo m[] = cc.methods;
      int nmethod = (m == null) ? 0 : m.length;

      for (int j = 0; j < nmethod; j++) {
        EVMMethodInfo meth = m[j];
        MethodInfo mi = meth.method;
        int index;
        if ((index = checkEntry(cc, mi)) >= 0) {
          String entryName = use_entries[index][3];
          out.println("{(unsigned char*)&" + entryName + ",");
          out.println("(char*)\"" + entryName + "\"},");
        }
      }
    }
    out.println("{(unsigned char*)0, (char*)0}};");
  }