Changeset 13284
- Timestamp:
- 05/22/11 01:35:30 (11 years ago)
- Location:
- trunk/abcl/contrib/jss
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/contrib/jss/invoke.lisp
r13283 r13284 135 135 ;; function you care about. 136 136 137 (defvar *max-java-method-args* 20 "Increase if you call java methods with more than 20 arguments")138 139 (defun argvs ()140 (let ((get (load-time-value (jmethod (jclass "java.lang.ThreadLocal") "get")))141 (argvs (load-time-value (jnew (jconstructor "java.lang.ThreadLocal"))))142 (null (load-time-value (make-immediate-object nil :ref))))143 (let ((res (jcall-raw get argvs)))144 (if (equal res null)145 (let ((it (jnew-array "java.lang.Object" *max-java-method-args*)))146 (dotimes (i *max-java-method-args*)147 (setf (jarray-ref it i) (jnew-array "java.lang.Object" i)))148 (jcall (jmethod (jclass "java.lang.ThreadLocal") "set" "java.lang.Object")149 argvs it)150 it)151 res))))152 153 154 137 (eval-when (:compile-toplevel :load-toplevel :execute) 155 138 (defvar *do-auto-imports* t)) … … 157 140 (defvar *imports-resolved-classes* (make-hash-table :test 'equal)) 158 141 159 160 142 (defun find-java-class (name) 161 143 (jclass (maybe-resolve-class-against-imports name))) 162 144 163 145 (defmacro invoke-add-imports (&rest imports) 164 " push these imports onto the search path. If multiple, earlier in list take precedence"146 "Push these imports onto the search path. If multiple, earlier in list take precedence" 165 147 `(eval-when (:compile-toplevel :load-toplevel :execute) 166 148 (clrhash *imports-resolved-classes*) … … 183 165 (defvar *class-name-to-full-case-insensitive* (make-hash-table :test 'equalp)) 184 166 185 ;; This is the function that calls invoke to call your java method. The first argument is the 186 ;; method name or 'new. The second is the object you are calling it on, followed by the rest of the 187 ;; arguments. If the "object" is a symbol, then that symbol is assumed to be a java class, and 188 ;; a static method on the class is called, otherwise a regular method is called. 167 ;; This is the function that calls invoke to call your java 168 ;; method. The first argument is the method name or 'new. The second 169 ;; is the object you are calling it on, followed by the rest of the 170 ;; arguments. If the "object" is a symbol, then that symbol is assumed 171 ;; to be a java class, and a static method on the class is called, 172 ;; otherwise a regular method is called. 189 173 190 174 (defun invoke (method object &rest args) 191 175 (invoke-restargs method object args)) 192 193 (eval-when (:compile-toplevel :load-toplevel :execute)194 (defvar *invoke-methods*195 (load-time-value (jcall (jmethod "java.lang.Class" "getMethods" ) (jclass "jsint.Invoke")))))196 176 197 177 (defun invoke-restargs (method object args &optional (raw? nil)) … … 210 190 (apply #'jcall method object args)))))) 211 191 212 ;;; Method name --> Object --> jmethod 213 ;;; 192 ;;; Method name as String --> String | Symbol --> jmethod 214 193 (defvar *methods-cache* (make-hash-table :test #'equal)) 215 194 … … 423 402 ((file-directory-p s) ) 424 403 ((equal (pathname-type s) "jar") 425 (jar-import (merge-pathnames (jcall "toString" s) (format nil "~a/" (jstatic "getProperty" "java.lang.System" "user.dir")))))))426 427 (jcall "split" cp (string (jstatic "peekStatic" '|jsint.Invoke| (jclass "java.io.File") "pathSeparatorChar")))428 404 (jar-import (merge-pathnames (jcall "toString" s) 405 (format nil "~a/" (jstatic "getProperty" "java.lang.System" "user.dir"))))))) 406 (jcall "split" cp 407 (string (jfield (jclass "java.io.File") "pathSeparatorChar")))))) 429 408 (import-class-path (jcall "getClassPath" (jstatic "getRuntimeMXBean" '|java.lang.management.ManagementFactory|))) 430 409 (import-class-path (jcall "getBootClassPath" (jstatic "getRuntimeMXBean" '|java.lang.management.ManagementFactory|))) … … 487 466 collect (#"getName" (#"elementAt" classesv i)))))) 488 467 489 490 ;; Modifiy this from Java.java to add a lisp defined classloader.491 ;; private static Class classForName(String className) throws ClassNotFoundException492 ;; {493 ;; try {494 ;; return Class.forName(className);495 ;; }496 ;; catch (ClassNotFoundException e) {497 ;; return Class.forName(className, true, JavaClassLoader.getPersistentInstance());498 ;; }499 ;; }500 ;; http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth-p2.html501 502 468 (defvar *added-to-classpath* nil) 503 469 … … 525 491 526 492 (defun get-dynamic-class-path () 527 (dump-classpath) 528 #+nil 529 (map 'list (lambda(el) 530 (let ((path (#"toString" el))) 531 (if (eql (search "file:/" path) 0) 532 (subseq path 5) 533 path))) 534 (#"getPathComponents" (#"getClassPath" *classpath-manager*)))) 535 536 #+nil 537 (eval-when (:load-toplevel :execute) 538 (maybe-install-bsh-classloader)) 539 540 541 542 ; http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/MemoryMXBean.html 543 ; http://java.sun.com/docs/hotspot/gc/ 544 ; http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc-p2.html 545 ; http://java.sun.com/docs/hotspot/VMOptions.html 546 ; http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html 547 ; http://java.sun.com/docs/hotspot/gc1.4.2/faq.html 548 ; http://java.sun.com/developer/technicalArticles/Programming/turbo/ 549 ;-XX:MinFreeHeapRatio= 550 ;-XX:MaxHeapFreeRatio= 551 ;-XX:NewRatio= 552 ;-XX:SurvivorRatio= 553 ;-XX:SoftRefLRUPolicyMSPerMB=10000 554 ;-XX:+PrintTenuringDistribution 555 ;-XX:MaxLiveObjectEvacuationRatio 556 493 (rest 494 (find-if (lambda (loader) 495 (string= "org.armedbear.lisp.JavaClassLoader" 496 (jclass-name (jobject-class loader)))) 497 (dump-classpath) 498 :key #'car))) 557 499 558 500 (defun java-gc () … … 699 641 700 642 For missing methods, a dummy implementation is provided that 701 calls the method on DISPATCH-TO "643 calls the method on DISPATCH-TO." 702 644 (let ((implemented-methods 703 645 (loop for m in method-names-and-defs … … 725 667 726 668 727 (defun java-exception-report (condition)728 (if (and (typep condition 'java-exception)729 (java-exception-cause condition)730 (equal (jclass-name (jobject-class (java-exception-cause condition)))731 "jsint.BacktraceException"))732 (with-output-to-string (s)733 (let ((writer (new 'stringwriter)))734 (#"printStackTrace" (#"getBaseException"(java-exception-cause condition)) (new 'printwriter writer))735 (write-string (#"replaceFirst" (#"toString" writer) "(?s)\\s*at sun.reflect.*" "") s))736 )737 (#"replaceFirst" (princ-to-string condition) "(?s)\\\\s*at jsint.E.*" "")))738 -
trunk/abcl/contrib/jss/packages.lisp
r13283 r13284 5 5 #:*inhibit-add-to-classpath* 6 6 #:*added-to-classpath* 7 #:*do-auto-imports* 8 9 #:add-directory-jars-to-class-path 7 10 #:add-to-classpath 8 #: new11 #:find-java-class 9 12 #:need-to-add-directory-jar? 10 #:add-directory-jars-to-class-path11 13 12 ;;; compatibility 13 #:ensure-compatiblity #:*cl-user-compatibility* 14 #:get-java-field) 14 ;;; deprecated 15 #:new ; use JAVA:NEW 16 #:get-java-field ; use JAVA:JFIELD 17 18 ;;; Move to JAVA? 19 #:jclass-all-interfaces 20 21 ;;; Useful utilities to convert common Java items to Lisp counterparts 22 #:hashmap-to-hashtable 23 #:iterable-to-list 24 #:list-to-list 25 #:set-to-list 26 #:vector-to-list 27 28 ;;; Enable compatibility with jss-1.0 by placing symbols in CL-USER 29 #:ensure-compatiblity #:*cl-user-compatibility*) 15 30 (:shadow #:add-to-classpath)) 16 31
Note: See TracChangeset
for help on using the changeset viewer.