debug of Mosaic_Dispatch
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Thu, 19 Dec 2024 11:33:42 +0000 (11:33 +0000)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Thu, 19 Dec 2024 11:33:42 +0000 (11:33 +0000)
.idea/runConfigurations/Dispatch_0.xml [new file with mode: 0644]
.idea/runConfigurations/debug_0.xml [new file with mode: 0644]
developer/javac🖉/Mosaic_Dispatcher.java
release/Mosaic.jar
tester/javac🖉/Dispatch_0.java
tester/javac🖉/TestClasses_0.java

diff --git a/.idea/runConfigurations/Dispatch_0.xml b/.idea/runConfigurations/Dispatch_0.xml
new file mode 100644 (file)
index 0000000..0f3fa0d
--- /dev/null
@@ -0,0 +1,17 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="Dispatch_0" type="ShConfigurationType" singleton="false">
+    <option name="SCRIPT_TEXT" value="" />
+    <option name="INDEPENDENT_SCRIPT_PATH" value="true" />
+    <option name="SCRIPT_PATH" value="$PROJECT_DIR$/../RT-project-share/release/bash/env_run" />
+    <option name="SCRIPT_OPTIONS" value="env_tester:developer jdwp_server/Dispatch_0" />
+    <option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
+    <option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+    <option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
+    <option name="INTERPRETER_PATH" value="/bin/bash" />
+    <option name="INTERPRETER_OPTIONS" value="" />
+    <option name="EXECUTE_IN_TERMINAL" value="true" />
+    <option name="EXECUTE_SCRIPT_FILE" value="true" />
+    <envs />
+    <method v="2" />
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/.idea/runConfigurations/debug_0.xml b/.idea/runConfigurations/debug_0.xml
new file mode 100644 (file)
index 0000000..b60e910
--- /dev/null
@@ -0,0 +1,18 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="debug_0" type="Remote" singleton="true" show_console_on_std_err="true" show_console_on_std_out="true">
+    <output_file path="$PROJECT_DIR$/tester/log/console" is_save="true" />
+    <log_file alias="$PROJECT_DIR$/tester/log/test" path="$PROJECT_DIR$/tester/log/test" />
+    <module name="tester" />
+    <option name="USE_SOCKET_TRANSPORT" value="true" />
+    <option name="SERVER_MODE" value="false" />
+    <option name="SHMEM_ADDRESS" />
+    <option name="HOST" value="localhost" />
+    <option name="PORT" value="5005" />
+    <option name="AUTO_RESTART" value="false" />
+    <RunnerSettings RunnerId="Debug">
+      <option name="DEBUG_PORT" value="5005" />
+      <option name="LOCAL" value="false" />
+    </RunnerSettings>
+    <method v="2" />
+  </configuration>
+</component>
\ No newline at end of file
index e47c0c9..c3822b4 100644 (file)
@@ -211,143 +211,90 @@ class MethodSignature_To_Handle_Map{
       map.put(key ,value);
     }
 
-    public void add_class(Class<?> class_metadata){
+    public void add_methods(Class<?> class_metadata){
       try{
-        test_print("adding public methods");
-        add_methods_public(class_metadata);
+        MethodHandles.Lookup lookup = MethodHandles.lookup();
+        MethodHandles.Lookup private_lookup = MethodHandles.privateLookupIn(class_metadata,lookup);
 
-        test_print("adding private methods");
-        add_methods_private(class_metadata);
-
-        test_print("adding constructors");
-        add_constructors(class_metadata);
-
-        /*
-        test_print("adding static methods");
-        add_methods_static(class_metadata);
-        */
-
-      }catch(Throwable t){
-        System.out.println("MethodSignature_To_Handle_Map::add_class exception: ");
-        t.printStackTrace();
-      }
-    }
+        for(Method method:class_metadata.getDeclaredMethods()){
+          try{
+            Class<?>[] parameter_type_list=method.getParameterTypes();
+            MethodSignature signature=new MethodSignature(
+              method.getReturnType(),
+              class_metadata.getName(),
+              method.getName(),
+              parameter_type_list
+            );
 
-    public void add_methods_public(Class<?> class_metadata){
-      MethodHandles.Lookup lookup = MethodHandles.lookup();
+            MethodType method_type=MethodType.methodType(method.getReturnType(),parameter_type_list);
+            MethodHandle method_handle;
+
+            if((method.getModifiers() & Modifier.STATIC) != 0){
+              if((method.getModifiers() & Modifier.PRIVATE) != 0){
+                // Private static method
+                method_handle = private_lookup.findStatic(class_metadata, method.getName(), method_type);
+              }else{
+                // Public or protected static method
+                method_handle = lookup.findStatic(class_metadata, method.getName(), method_type);
+              }
+            }else if((method.getModifiers() & Modifier.PRIVATE) != 0){
+              // Private instance method
+              method_handle = private_lookup.findSpecial(class_metadata, method.getName(), method_type, class_metadata);
+            }else{
+              // Public or protected instance method
+              method_handle = lookup.findVirtual(class_metadata, method.getName(), method_type);
+            }
 
-      for( Method method : class_metadata.getDeclaredMethods() ){
-        try{
-          if((method.getModifiers() & Modifier.PRIVATE) == 0){ // Skip private methods
-            Class<?>[] parameter_type_list = method.getParameterTypes();
-            MethodType method_type = MethodType.methodType(method.getReturnType() ,parameter_type_list);
-            MethodHandle method_handle = lookup.findVirtual(class_metadata ,method.getName() ,method_type);
+            add_entry(signature,method_handle);
 
-            MethodSignature signature = new MethodSignature
-              (
-               method.getReturnType()
-               ,class_metadata.getName()
-               ,method.getName()
-               ,parameter_type_list
-               );
-            add_entry(signature ,method_handle);
+          }catch(IllegalAccessException|NoSuchMethodException e){
+            System.err.println("Mosaic_Dispatcher::add_methods unexpectedly failed to register method: "+method.getName());
+            e.printStackTrace();
           }
-        }catch(NoSuchMethodException e){
-          System.err.println("Skipping public/protected method: " + method);
-          e.printStackTrace();
-        }catch(Throwable t){
-          t.printStackTrace();
         }
+
+      }catch(IllegalAccessException e){
+        System.err.println("Mosaic_Dispatcher::add_methods unexpectedly failed to initialize lookup for class: "+class_metadata.getName());
+        e.printStackTrace();
       }
     }
 
-   public void add_methods_private(Class<?> class_metadata) throws IllegalAccessException{
-     MethodHandles.Lookup lookup = MethodHandles.lookup();
-     MethodHandles.Lookup private_lookup = MethodHandles.privateLookupIn(class_metadata ,lookup);
 
-     for(Method method : class_metadata.getDeclaredMethods()){
-       try{
-         if((method.getModifiers() & Modifier.PRIVATE) != 0){ // Only private methods
-           Class<?>[] parameter_type_list = method.getParameterTypes();
-           MethodType method_type = MethodType.methodType(method.getReturnType() ,parameter_type_list);
-           MethodHandle method_handle = private_lookup.findSpecial(
-             class_metadata ,method.getName() ,method_type ,class_metadata
-           );
+    public void add_constructors(Class<?> class_metadata){
+      try{
 
-           MethodSignature signature = new MethodSignature
-             (
-              method.getReturnType()
-              ,class_metadata.getName()
-              ,method.getName()
-              ,parameter_type_list
-              );
-           add_entry(signature ,method_handle);
-         }
-       }catch(NoSuchMethodException e){
-         System.err.println("Skipping private method: " + method);
-       }catch(Throwable t){
-         t.printStackTrace();
-       }
-     }
-   }
-
-    public void add_constructors(Class<?> class_metadata) throws IllegalAccessException{
-      MethodHandles.Lookup lookup = MethodHandles.lookup();
-      MethodHandles.Lookup private_lookup = MethodHandles.privateLookupIn(class_metadata ,lookup);
-
-      for( Constructor<?> constructor : class_metadata.getDeclaredConstructors() ){
-        try{
-          Class<?>[] parameter_type_list = constructor.getParameterTypes();
-          MethodType method_type = MethodType.methodType(void.class, parameter_type_list);
-          MethodHandle constructor_handle = private_lookup.findConstructor(class_metadata ,method_type);
-
-          // Signature for constructors: <init> with parameter types
-          MethodSignature signature = new MethodSignature
-            (
-             void.class
-             ,class_metadata.getName() 
-             ,"<init>" 
-             ,parameter_type_list
-             );
-          add_entry(signature ,constructor_handle);
-
-        }catch(NoSuchMethodException e){
-          System.err.println("Skipping constructor: " + constructor);
-        }catch(Throwable t){
-          t.printStackTrace();
-        }
-      }
-    }
+        MethodHandles.Lookup lookup = MethodHandles.lookup();
+        MethodHandles.Lookup private_lookup = MethodHandles.privateLookupIn(class_metadata ,lookup);
 
-    public void add_methods_static(Class<?> class_metadata) {
-      MethodHandles.Lookup lookup = MethodHandles.lookup();
+        for( Constructor<?> constructor : class_metadata.getDeclaredConstructors() ){
+          try{
 
-      for (Method method : class_metadata.getDeclaredMethods()) {
-        try {
-          if (Modifier.isStatic(method.getModifiers())) { // Only static methods
-            Class<?>[] parameter_type_list = method.getParameterTypes();
-            MethodType method_type = MethodType.methodType(method.getReturnType(), parameter_type_list);
-            MethodHandle method_handle = lookup.findStatic(class_metadata, method.getName(), method_type);
+            Class<?>[] parameter_type_list = constructor.getParameterTypes();
+            MethodType method_type = MethodType.methodType(void.class, parameter_type_list);
+            MethodHandle constructor_handle = private_lookup.findConstructor(class_metadata ,method_type);
 
-            MethodSignature signature = new MethodSignature(
-              method.getReturnType(),
-              class_metadata.getName(),
-              method.getName(),
-              parameter_type_list
-            );
+            // Signature for constructors: <init> with parameter types
+            MethodSignature signature = new MethodSignature
+              (
+               void.class
+               ,class_metadata.getName() 
+               ,"<init>" 
+               ,parameter_type_list
+               );
+            add_entry(signature ,constructor_handle);
 
-            add_entry(signature, method_handle);
+          }catch(IllegalAccessException|NoSuchMethodException e){
+            System.err.println("Mosaic_Dispatcher::add_methods unexpectedly failed to register constructor: " + class_metadata.getName());
+            e.printStackTrace();
           }
-        } catch (NoSuchMethodException e) {
-          System.err.println("Skipping static method: " + method);
-          e.printStackTrace();
-        } catch (Throwable t) {
-          t.printStackTrace();
         }
+
+      }catch(IllegalAccessException e){
+        System.err.println("Mosaic_Dispatcher::add_methods unexpectedly failed to initialize lookup for class: " + class_metadata.getName());
+        e.printStackTrace();
       }
     }
 
-
   // methods for looking up handles
   //
     public MethodHandle lookup(MethodSignature s){
@@ -361,7 +308,7 @@ class MethodSignature_To_Handle_Map{
       StringBuilder sb = new StringBuilder();
       sb.append("MethodSignature_To_Handle_Map:{").append(System.lineSeparator());
 
-      for (Map.Entry<MethodSignature ,MethodHandle> entry : map.entrySet()){
+      for(Map.Entry<MethodSignature ,MethodHandle> entry : map.entrySet()){
         sb.append("  ")
           .append(entry.getKey().toString()) // MethodSignature's toString
           .append(" -> ")
@@ -385,17 +332,17 @@ public class Mosaic_Dispatcher{
   //
     private static boolean test = false;
     public static void test_switch(boolean test){
-      if (Mosaic_Dispatcher.test && !test){
+      if(Mosaic_Dispatcher.test && !test){
         test_print("Mosaic_Dispatcher:: test messages off");
       }
-      if (!Mosaic_Dispatcher.test && test){
+      if(!Mosaic_Dispatcher.test && test){
         test_print("Mosaic_Dispatcher:: test messages on");
         MethodSignature_To_Handle_Map.test_switch(true);
       }
       Mosaic_Dispatcher.test = test;
     }
-    private static void test_print(String message){
-      if (test){
+    public static void test_print(String message){
+      if(test){
         System.out.println(message);
       }
     }
@@ -428,19 +375,17 @@ public class Mosaic_Dispatcher{
       this.map = new MethodSignature_To_Handle_Map();
       this.target = target;
       test_print("Mosaic_Dispatcher:: mapping methods given class_metadata object: " + to_string_target());
-      this.map.add_class(target);
+      this.map.add_methods(target);
+      this.map.add_constructors(target);
     }
 
     // Constructor accepting a fully qualified class name of the target class
     public Mosaic_Dispatcher(String fully_qualified_class_name) throws ClassNotFoundException{
       this.map = new MethodSignature_To_Handle_Map();
-      try{
-        this.target = Class.forName(fully_qualified_class_name);
-        test_print("Mosaic_Dispatcher:: mapping methods from class specified by string:" + to_string_target());
-        this.map.add_class(target);
-      }catch(ClassNotFoundException e){
-        throw new ClassNotFoundException("Class not found: " + fully_qualified_class_name ,e);
-      }
+      this.target = Class.forName(fully_qualified_class_name);
+      test_print("Mosaic_Dispatcher:: mapping methods from class specified by string:" + to_string_target());
+      this.map.add_methods(target);
+      this.map.add_constructors(target);
     }
 
   // methods unique to the class
index 4acbf18..a7c41b7 100644 (file)
Binary files a/release/Mosaic.jar and b/release/Mosaic.jar differ
index 9847c46..51d9a5c 100644 (file)
@@ -12,6 +12,10 @@ public class Dispatch_0{
   static{
     // Initialize the dispatcher for TestClasses_0
     Mosaic_Dispatcher.test_switch(true);
+  }
+
+  public Dispatch_0(){
+    Mosaic_Dispatcher.test_print("making map for TestClasses_0");
     dispatcher = new Mosaic_Dispatcher(TestClasses_0.class);
   }
 
@@ -73,7 +77,6 @@ public class Dispatch_0{
     try{
       boolean result = true;
 
-      /*
       System.out.println("");
       System.out.println("running test: publicClass_publicMethod");
       if (Boolean.TRUE.equals(test_publicClass_publicMethod())){
@@ -82,7 +85,6 @@ public class Dispatch_0{
         System.out.println("FAILED");
         result = false;
       }
-      */
 
       System.out.println("");
       System.out.println("running test: make_0");
@@ -93,7 +95,6 @@ public class Dispatch_0{
         result = false;
       }
 
-      /*
       System.out.println("");
       System.out.println("running test: publicStaticMethod_7");
       if (Boolean.TRUE.equals(test_publicStaticMethod_7())){
@@ -111,7 +112,6 @@ public class Dispatch_0{
         System.out.println("FAILED");
         result = false;
       }
-      */
 
       System.out.println("");
       return result;
@@ -125,6 +125,7 @@ public class Dispatch_0{
 
   public static void main(String[] args){
     // Execute the run method and return its result as the exit code
+    new Dispatch_0();
     if( run() ) 
       System.exit(0);
     else
index edf975f..b147eac 100644 (file)
@@ -37,7 +37,6 @@ public class TestClasses_0{
     }
   }
 
-  /*
   public static boolean a_public_static_method_7(){
     return true;
   }
@@ -45,7 +44,6 @@ public class TestClasses_0{
   private static boolean a_private_static_method_9(){
     return true;
   }
-  */
 
 }