星期四, 三月 18, 2004

The Memory Management Reference: Full Bibliography关于java object refefence理论解释.

The Memory Management Reference: Full Bibliography

very good

These are all available details on all books and papers in this bibliography.
Each entry lists some or all of the following:




  • Author or authors (linked to summary by author);


  • Publication date;

  • Title;

  • Publisher (linked to web site, if known);

  • Publisher's identifier (ISBN for books);

  • URL of document online or ordering information (if known).



Entries are ordered by first author and publication date.




Ole Agesen, David L. Detlefs. 1997. Finding References in JavaTM Stacks. Sun Labs. OOPSLA97 Workshop on Garbage Collection and Memory Management. Abstract. Online.




Ole Agesen, David L. Detlefs, J. Eliot B. Moss. 1998. Garbage Collection and Local Variable Type-precision and Liveness in JavaTM Virtual Machines . ACM. Proceedings of the ACM SIGPLAN '98 conference on Programming language design and implementation, pages 269-279. Abstract. Online. Online.




Andrew Appel, John R. Ellis, Kai Li. 1988. Real-time Concurrent Collection on Stock Multiprocessors. ACM, SIGPLAN. ACM PLDI 88, SIGPLAN Notices 23, 7 (July 88), pp. 11-20. Abstract. Online.




Apple Computer, Inc.. 1994. Inside Macintosh: Memory. Addison-Wesley. ISBN 0-201-63240-3. Abstract. Online.



Giuseppe Attardi, Tito Flagella. 1994. A Customisable Memory Management Framework. TR-94-010. Abstract. Online.




Giuseppe Attardi, Tito Flagella, Pietro Iglio. 1998. A customisable memory management framework for C++. Software -- Practice and Experience. 28(11), 1143-1183. Abstract. Online.



Alain Azagury, Elliot K. Kolodner, Erez Petrank, Zvi Yehudai. 1998. Combining Card Marking with Remembered Sets: How to Save Scanning Time. ACM. ISMM'98 pp.10--19. Abstract. Online.




Henry G. Baker, Carl Hewitt. 1977. The Incremental Garbage Collection of Processes. Abstract. Online.



Henry G. Baker. 1978. List Processing in Real Time on a Serial Computer. ACM. Communications of the ACM 21, 4 (April 1978), pp. 280-294. Abstract. Online.




Henry G. Baker. 1979. Optimizing Allocation and Garbage Collection of Spaces. Abstract. Online.



Henry G. Baker. 1991. Cache-Conscious Copying Collectors. Abstract. Online.




Henry G. Baker. 1992. Lively Linear Lisp -- 'Look Ma, No Garbage!'. Abstract. Online.



Henry G. Baker. 1992. The Treadmill: Real-Time Garbage Collection Without Motion Sickness. Abstract. Online.




Henry G. Baker. 1992. CONS Should not CONS its Arguments, or, a Lazy Alloc is a Smart Alloc. Abstract. Online.



Henry G. Baker. 1992. NREVERSAL of Fortune -- The Thermodynamics of Garbage Collection. Springer-Verlag. LNCS Vol. 637, pp. ?. Abstract. Online.




Henry G. Baker. 1993. 'Infant Mortality' and Generational Garbage Collection. Abstract. Online.



Henry G. Baker. 1993. Equal Rights for Functional Objects or, The More Things Change, The More They Are the Same. ACM. ACM OOPS Messenger 4, 4 (October 1993), pp. 2-27. Abstract. Online.




Henry G. Baker. 1994. Minimizing Reference Count Updating with Deferred and Anchored Pointers for Functional Data Structures. Abstract. Online.



Henry G. Baker. 1994. Thermodynamics and Garbage Collection. ACM. ACM Sigplan Notices 29,4 (April 1994), 58-63.. Abstract. Online.




Henry G. Baker. 1995. 'Use-Once' Variables and Linear Objects -- Storage Management, Reflection and Multi-Threading. SIGPLAN. AMC SIGPLAN Notices 30(1). Abstract. Online.



Henry G. Baker. 1995. Memory Management: International Workshop IWMM'95. Springer-Verlag. ISBN 3-540-60368-9. Abstract. Online.




Nick Barnes, Richard Brooksby, David Jones, Gavin Matthews, Pekka P. Pirinen, Nick Dalton, P. Tucker Withington. 1997. A Proposal for a Standard Memory Management Interface. OOPSLA97 Workshop on Garbage Collection and Memory Management. Online.




David A. Barrett, Benjamin Zorn. 1993. Using Lifetime Predictors to Improve Memory Allocation Performance. ACM, SIGPLAN. SIGPLAN'93 Conference on Programming Language Design and Implementation, pp. 187-196. Abstract.



David A. Barrett, Benjamin Zorn. 1995. Garbage Collection using a Dynamic Threatening Boundary. SIGPLAN. ACM SIGPLAN'95 Conference on Programming Language Design and Implementation, pp301-314. Abstract. Online.




Joel F. Bartlett. 1988. Compacting Garbage Collection with Ambiguous Roots. Digital Equipment Corporation. Abstract. Online.



Joel F. Bartlett. 1989. Mostly-Copying Garbage Collection Picks Up Generations and C++. Digital Equipment Corporation. Abstract. Online.




Yves Bekkers, Jacques Cohen. 1992. Memory Management, International Workshop IWMM 92. Springer-Verlag. LNCS Vol. 637, ISBN 3-540-55940-X. Online.



Emery D. Berger, Robert D. Blumofe. 1999. Hoard: A Fast, Scalable, and Memory-Efficient Allocator for Shared-Memory Multiprocessors. University of Texas at Austin. UTCS TR99-22. Abstract. Online.




Hans-J. Boehm, Mark Weiser. 1988. Garbage collection in an uncooperative environment. Software -- Practice and Experience. 18(9):807-820. Abstract.



Hans-J. Boehm, Alan J. Demers, Scott Shenker. 1991. Mostly Parallel Garbage Collection. Xerox PARC. ACM PLDI 91, SIGPLAN Notices 26, 6 (June 1991), pp. 157-164. Abstract. Online.




Hans-J. Boehm, David Chase. 1992. A Proposal for Garbage-Collector-Safe C Compilation. Journal of C Language Translation. vol. 4, 2 (December 1992), pp. 126-141. Online.



Hans-J. Boehm. 1993. Space Efficient Conservative Garbage Collection. ACM, SIGPLAN. Proceedings of the ACM SIGPLAN '91 Conference on Programming Language Design and Implementation, SIGPLAN Notices 28, 6, pp 197-206. Abstract. Online.




Hans-J. Boehm. 2000. Reducing Garbage Collector Cache Misses. ACM. ISMM'00 pp. 59-64. Abstract.



P. Branquart, J. Lewi. 1972. A scheme of storage allocation and garbage collection for ALGOL 68. Elsevier/North-Holland. ALGOL 68 Implementation -- Proceedings of the IFIP Working Conference on ALGOL 68 Implementation, July 1970.




Brad Calder, Dirk Grunwald, Benjamin Zorn. 1994. Quantifying Behavioral Differences Between C and C++ Programs. Journal of Programming Languages. 2(4):313-351. Abstract. Online.



Dante J. Cannarozzi, Michael P. Plezbert, Ron K. Cytron. 2000. Contaminated garbage collection. ACM. Proceedings of the ACM SIGPLAN '00 conference on on Programming language design and implementation, pp. 264-273. Online.




Patrick J. Caudill, Allen Wirfs-Brock. 1986. A Third-Generation Smalltalk-80 Implementation. SIGPLAN Notices. 21(11), OOPSLA'86 ACM Conference on Object-Oriented Systems, Languages and Applications.



C. J. Cheney. 1970. A non-recursive list compacting algorithm. CACM. 13-11 pp677--678.



Perry Cheng, Robert Harper, Peter Lee. 1998. Generational stack collection and profile-driven pretenuring. ACM. Proceedings of SIGPLAN'98 Conference on Programming Language Design and Implementation, pp. 162-173. Online. Online.




Trishul M. Chilimbi, James R. Larus. 1998. Using Generational Garbage Collection To Implement Cache-Conscious Data Placement. ACM. ISMM'98 pp.37--48. Abstract. Online.



William D Clinger, Lars T Hansen. 1997. Generational Garbage Collection and the Radioactive Decay Model. ACM. Proceedings of PLDI 1997. Abstract.




Jacques Cohen. 1981. Garbage collection of linked data structures. Computing Surveys. Vol. 13, no. 3. Abstract.



Dominique Colnet, Philippe Coucaud, Olivier Zendra. 1998. Compiler Support to Customize the Mark and Sweep Algorithm. ACM. ISMM'98 pp.154-165. Abstract. Online.




Jonathan E. Cook, Alexander L. Wolf, Benjamin Zorn. 1994. Partition Selection Policies in Object Database Garbage Collection. ACM, SIGMOD. International Conference on the Management of Data (SIGMOD'94), pp. 371-382. Abstract.



Jonathan E. Cook, Artur Klauser, Alexander L. Wolf, Benjamin Zorn. 1996. Semi-automatic, Self-adaptive Control of Garbage Collection Rates in Object Databases. ACM, SIGMOD. International Conference on the Management of Data (SIGMOD'96), pp377-388.




Eric Cooper, Scott Nettles, Indira Subramanian. 1992. Improving the Performance of SML Garbage Collection using Application-Specific Virtual Memory Management. ACM. Abstract.



Michael C. Daconta. 1993. C Pointers and Dynamic Memory Management. Wiley. ISBN 0-471-56152-5.




Michael C. Daconta. 1995. C++ Pointers and Dynamic Memory Management. Wiley. ISBN 0-471-04998-0. Abstract.



O.-J. Dahl. 1963. The SIMULA Storage Allocation Scheme. Norsk Regnesentral. NCC Document no. 162.



P. J. Denning. 1968. Thrashing: Its Causes and Prevention. Proceedings AFIPS,1968 Fall Joint Computer Conference, vol. 33, pp. 915-922.




P. J. Denning. 1970. Virtual Memory. ACM. ACM Computing Surveys, vol. 2, no. 3, pp. 153-190, Sept. 1970.



P. J. Denning, S. C. Schwartz. 1972. Properties of the Working-set Model. CACM. CACM, vol. 15, no. 3, pp. 191-198.



David L. Detlefs. 1992. Garbage collection and runtime typing as a C++ library. USENIX. USENIX C++ Conference.




David L. Detlefs, Al Dosser, Benjamin Zorn. 1994. Memory Allocation Costs in Large C and C++ Programs. Software -- Practice and Experience. 24(6):527-542. Abstract. Online.



L. Peter Deutsch, Daniel G. Bobrow. 1976. An Efficient, Incremental, Automatic Garbage Collector. CACM. CACM, vol. 19, no. 9, pp. 522-526.




E. W. Dijkstra, Leslie Lamport, A. J. Martin, C. S. Scholten, E. F. M. Steffens. 1976. On-the-fly Garbage Collection: An Exercise in Cooperation. Springer-Verlag. Lecture Notes in Computer Science, Vol. 46.



Amer Diwan, Richard L. Hudson, J. Eliot B. Moss. 1992. Compiler Support for Garbage Collection in a Statically Typed Language. ACM. Proceedings of the 5th ACM SIGPLAN conference on Programming language design and implementation, pages 273-282. Abstract. Online.




Amer Diwan, David Tarditi, J. Eliot B. Moss. 1993. Memory Subsystem Performance of Programs with Intensive Heap Allocation. Carnegie Mellon University. CMU-CS-93-227. Abstract. Online.



Amer Diwan, David Tarditi, J. Eliot B. Moss. 1994. Memory Subsystem Performance of Programs Using Copying Garbage Collection. ACM. CMU-CS-93-210, also in POPL '94. Abstract.




Damien Doligez, Xavier Leroy. 1993. A concurrent, generational garbage collector for a multithreaded implementation of ML. ACM. POPL '93, 113-123. Abstract. Online.



Damien Doligez, Georges Gonthier. 1994. Portable, unobtrusive garbage collection for multiprocessor systems. ACM. POPL '94, 70-83. Abstract. Online.




R. Kent Dybvig, Carl Bruggeman, David Eby. 1993. Guardians in a Generation-Based Garbage Collector. SIGPLAN. Proceedings of the ACM SIGPLAN '93 Conference on Programming Language Design and Implementation, June 1993. Abstract. Online.



Daniel R. Edelson. 1992. Smart pointers: They're smart, but they're not pointers. USENIX. USENIX C++ Conference.




Daniel R. Edelson. 1992. Comparing Two Garbage Collectors for C++. University of California at Santa Cruz. Technical Report UCSC-CRL-93-20.



Daniel J. Edwards. n.d. Lisp II Garbage Collector. MIT. AI Memo 19 (AIM-19). Abstract. Online.




John R. Ellis, David L. Detlefs. 1993. Safe, Efficient Garbage Collection for C++. Abstract.



Paulo Ferreira. 1996. Larchant: garbage collection in a cached distributed shared store with persistence by reachability. Université Paris VI. Thése de doctorat. Abstract. Online.




Paulo Ferreira, Marc Shapiro. 1998. Modelling a Distributed Cached Store for Garbage Collection. Springer-Verlag. Proceedings of 12th European Conference on Object-Oriented Programming, ECOOP98, LNCS 1445. Online.



Daniel P Friedman, David S. Wise. 1976. Garbage collecting a heap which includes a scatter table. Information Processing Letters. 5, 6 (December 1976): 161-164.




Daniel P Friedman, David S. Wise. 1977. The One-Bit Reference Count. BIT. (17)3: 351-359. Abstract.



Daniel P Friedman, David S. Wise. 1979. Reference counting can manage the circular environments of mutual recursion. Information Processing Letters. 8, 1 (January 1979): 41--45.




Dirk Grunwald, Benjamin Zorn, R. Henderson. 1993. Improving the Cache Locality of Memory Allocation. SIGPLAN. SIGPLAN '93, Conference on PLDI, June 1993, Albuquerque, New Mexico. Abstract. Online.



Dirk Grunwald, Benjamin Zorn. 1993. CustoMalloc: Efficient Synthesized Memory Allocators. Software -- Practice and Experience. 23(8):851-869. Abstract.




David Gudeman. 1993. Representing Type Information in Dynamically Typed Languages. University of Arizona at Tucson. Technical Report TR 93-27. Abstract. Online.



Timothy Harris. 1999. Early storage reclamation in a tracing garbage collector. ACM. ACM SIG-PLAN Notices 34:4, pp. 46-53. Abstract. Online.




Roger Henriksson. 1994. Scheduling Real Time Garbage Collection. Department of Computer Science at Lund University. LU-CS-TR:94-129. Abstract. Online.



Roger Henriksson. 1996. Adaptive Scheduling of Incremental Copying Garbage Collection for Interactive Applications. NWPER96. Abstract. Online.




Roger Henriksson. 1998. Scheduling Garbage Collection in Embedded Systems. Department of Computer Science at Lund University. Ph.D. thesis. Abstract. Online.



Antony L. Hosking. 1991. Main memory management for persistence. ACM. Proceedings of the ACM OOPSLA'91 Workshop on Garbage Collection. Online.




Antony L. Hosking, J. Eliot B. Moss, Darko Stefanovic. 1992. A comparative performance evaluation of write barrier implementations. ACM. OOPSLA'92 Conference Proceedings, ACM SIGPLAN Notices 27(10), pp 92-109. Online.



Antony L. Hosking, Richard L. Hudson. 1993. Remembered sets can also play cards. ACM. Proceedings of the ACM OOPSLA'93 Workshop on Memory Management and Garbage Collection. Online.




Antony L. Hosking, J. Eliot B. Moss. 1993. Protection traps and alternatives for memory management of an object-oriented language. ACM. Proceedings of the Fourteenth ACM Symposium on Operating Systems Principles, ACM Operating Systems Review 27(5), pp 106-119. Online.



Richard L. Hudson, J. Eliot B. Moss, Amer Diwan, Christopher F. Weight. 1991. A Language-Independent Garbage Collector Toolkit. University of Massachusetts at Amherst. COINS Technical Report 91-47. Abstract.




Richard L. Hudson, J. Eliot B. Moss. 1992. Incremental Collection of Mature Objects. Springer-Verlag. LNCS #637 International Workshop on Memory Management, St. Malo, France, Sept. 1992, pp. 388-403. Abstract. Online.



Richard L. Hudson, Ron Morrison, J. Eliot B. Moss, David S. Munro. 1997. Garbage Collecting the World: One Car at a Time. ACM. Proc. OOPSLA 97, pp.162-175. Abstract. Online.




Jin-Soo Kim, Xiaohan Qin, Yarsun Hsu. 1998. Memory Characterization of a Parallel Data Mining Workload. IEEE. Proc. Workload Characterization: Methodology and Case Studies, pp. . Abstract. Online.



Jin-Soo Kim, Yarsun Hsu. 2000. Memory system behavior of Java programs: methodology and analysis. ACM. Proc. International conference on measurements and modeling of computer systems, pp. 264-274. Online.




Mark S. Johnstone. 1997. Non-Compacting Memory Allocation and Real-Time Garbage Collection. University of Texas at Austin. Abstract. Online.



Mark S. Johnstone, Paul R. Wilson. 1998. The Memory Fragmentation Problem: Solved?. ACM. ISMM'98 pp.26-36. Abstract. Online.




Richard E. Jones. 1992. Tail recursion without space leaks. Journal of Functional Programming. 2(1):73-79.



Richard E. Jones, Rafael Lins. 1992. Cyclic weighted reference counting without delay. Computing Laboratory, The University of Kent at Canterbury. Technical Report 28-92. Abstract. Online.




Richard E. Jones, Rafael Lins. 1996. Garbage Collection: Algorithms for Automatic Dynamic Memory Management. Wiley. ISBN 0-471-94148-4. Abstract. Online.



Richard E. Jones. 1998. ISMM'98 International Symposium on Memory Management. ACM. ISBN 1-58113-114-3. Abstract. Online.




Bob Kanefsky. 1989. Recursive Memory Allocation. Bob Kanefsky. Songworm 3, p.?. Online.



Elliot K. Kolodner. 1992. Atomic Incremental Garbage Collection and Recovery for a Large Stable Heap. Laboratory for Computer Science at MIT. MIT-LCS-TR-534. Abstract.



Per-Åke Larson, Murali Krishnan. 1998. Memory Allocation for Long-Running Server Applications. ACM. ISMM'98 pp.176--185. Abstract. Online.




Henry Lieberman, Carl Hewitt. 1983. A real-time garbage collector based on the lifetimes of objects. ACM. 26(6):419-429.



J. McCarthy, M. L. Minsky. 1959. Artificial Intelligence, Quarterly Progress Report no. 53. Research Laboratory of Electronics at MIT.




J. McCarthy. 1960. Recursive Functions of Symbolic Expressions and Their Computation by Machine. CACM. Abstract. Online.



Veljko Milutinovic, Jelica Protic, Milo Tomasevic. 1997. Distributed shared memory: concepts and systems. IEEE Computer Society Press. ISBN 0-8186-7737-6. Abstract. Online.




M. L. Minsky. 1963. A LISP Garbage Collector Algorithm Using Serial Secondary Storage. MIT. Memorandum MAC-M-129, Artificial Intelligence Project, Memo 58 (revised).



David Moon. 1984. Garbage Collection in a Large Lisp System. ACM. Symposium on Lisp and Functional Programming, August 1984.



David Moon. 1985. Architecture of the Symbolics 3600. IEEE. 12th International Symposium on Computer Architecture, pp. 76-83.




David Moon. 1990. Symbolics Architecture. Wiley. Chapter 3 of "Computers for Artificial Intelligence Processing", ISBN 0-471-84811-5.



David Moon. 1991. Genera Retrospective. IEEE. 1991 International Workshop on Object Orientation in
Operating Systems, order #2265.



Ben-Ari Mordechai. 1984. Algorithms for On-the-fly Garbage Collection. TOPLAS. TOPLAS 6(3): 333-344 (1984).




Luc Moreau. 1998. Hierarchical Distributed Reference Counting. ACM. ISMM'98 pp.57-67. Online.



Greg Morrisett, Matthias Felleisen, Robert Harper. 1995. Abstract Models of Memory Management. Carnegie Mellon University. CMU-CS-FOX-95-01. Abstract. Online.




David S. Munro, Alfred Brown, Ron Morrison, J. Eliot B. Moss. 1999. Incremental Garbage Collection of a Persistent Object Store using PMOS. Morgan Kaufmann. in Advances in Persistent Object Systems, pp. 78-91. Abstract.



Scott Nettles, James O'Toole, David Pierce, Nickolas Haines. 1992. Replication-Based Incremental Copying Collection. IWMM'92. Abstract.




Scott Nettles. 1992. A Larch Specification of Copying Garbage Collection. Carnegie Mellon University. CMU-CS-92-219. Abstract.



Scott Nettles, James O'Toole. 1993. Implementing Orthogonal Persistence: A Simple Optimization Using Replicating Collection. USENIX. IWOOOS'93. Abstract.




Scott Nettles, James O'Toole. 1993. Real-Time Replication Garbage Collection. ACM. PLDI'93. Abstract.



Norman R. Nielsen. 1977. Dynamic Memory Allocation in Computer Simulation. ACM. CACM 20:11. Abstract.




James O'Toole. 1990. Garbage Collecting Locally. Abstract.



James O'Toole, Scott Nettles. 1994. Concurrent Replicating Garbage Collection. ACM. LFP'94. Abstract.




Simon Peyton Jones, Norman Ramsey, Fermin Reig. 1999. C--: a portable assembly language that supports garbage collection. Springer-Verlag. International Conference on Principles and Practice of Declarative Programming 1999, LNCS 1702, pp. 1-28. Abstract. Online.



John S. Pieper. 1993. Compiler Techniques for Managing Data Motion. Carnegie Mellon University. Technical report number CMU-CS-93-217. Abstract.




Pekka P. Pirinen. 1998. Barrier techniques for incremental tracing. ACM. ISMM'98 pp.20-25. Abstract. Online.



Tony Printezis. 1996. Disk Garbage Collection Strategies for Persistent Java. Proceedings of the First International Workshop on Persistence and Java. Abstract. Online.




Tony Printezis, Quentin Cutts. 1996. Measuring the Allocation Rate of Napier88. Department of Computing Science at University of Glasgow. TR ?. Online.



M. B. Reinhold. 1993. Cache Performance of Garbage Collected Programming Languages. Laboratory for Computer Science at MIT. MIT/LCS/TR-581. Abstract.




J. M. Robson. 1977. Worst case fragmentation of first fit and best bit storage allocation strategies. ACM. ACM Computer Journal, 20(3):242-244.



Gustavo Rodriguez-Rivera, Vince Russo. 1997. Non-intrusive Cloning Garbage Collection with Stock Operating System Support. Software -- Practice and Experience. 27:8. Abstract.




Niklas Röjemo. 1995. Highlights from nhc -- a space-efficient Haskell compiler. Chalmers University of Technology. Abstract. Online.



Niklas Röjemo. 1995. Generational garbage collection for lazy functional languages without temporary space leaks. Chalmers University of Technology. Online.




Niklas Röjemo, Colin Runciman. 1996. Lag, drag, void and use -- heap profiling and space-efficient compilation revisited. ACM, SIGPLAN. ICFP'96, ACM SIGPLAN Notices 31:6, ISBN 0-89791-770-7, pp. 34-41. Abstract. Online.



David J. Roth, David S. Wise. 1999. One-bit counts between unique and sticky. ACM. ISMM'98, pp. 49--56. Abstract. Online. Online.




Paul Rovner. 1985. On Adding Garbage Collection and Runtime Types to a Strongly-Typed, Statically-Checked, Concurrent Language. Xerox PARC. TR CSL-84-7.



Colin Runciman, David Wakeling. 1992. Heap Profiling of Lazy Functional Programs. University of York. Abstract. Online.




Colin Runciman, Niklas Röjemo. 1994. New dimensions in heap profiling. University of York. Abstract. Online.



Colin Runciman, Niklas Röjemo. 1996. Two-pass heap profiling: a matter of life and death. Department of Computer Science, University of York. Online.




Jacob Seligmann, Steffen Grarup. 1995. Incremental Mature Garbage Collection Using the Train Algorithm. Springer-Verlag. ECOOP'95, Lecture Notes in Computer Science, Vol. 952, pp. 235-252, ISBN 3-540-60160-0. Abstract. Online.



Manuel Serrano, Hans-J. Boehm. 2000. Understanding memory allocation of Scheme programs. ACM. Proceedings of International Conference on Functional
Programming 2000.




Marc Shapiro, Paulo Ferreira. 1994. Larchant-RDOSS: a distributed shared persistent memory and its garbage collector. INRIA. INRIA Rapport de Recherche no. 2399; Cornell Computer Science TR94-1466. Abstract. Online.



Robert A. Shaw. 1987. Improving Garbage Collector Performance in Virtual Memory. Stanford University. CSL-TR-87-323.




Robert A. Shaw. 1988. Empirical Analysis of a LISP System. Stanford University. CSL-TR-88-351.



Vivek Singhal, Sheetal V. Kakkad, Paul R. Wilson. 1992. Texas: An Efficient, Portable Persistent Store. University of Texas at Austin. Abstract. Online.




P. G. Sobalvarro. 1988. A Lifetime-based Garbage Collector for LISP Systems on General-Purpose Computers. MIT. AITR-1417. Abstract. Online.



Guy L. Steele. 1975. Multiprocessing Compactifying Garbage Collection. CACM. 18:9 pp. 495--508.




Guy L. Steele. 1976. Corrigendum: Multiprocessing Compactifying Garbage Collection. CACM. 19:6 p.354.



Guy L. Steele. 1977. Data Representation in PDP-10 MACLISP. MIT. AI Memo 421.



James M. Stichnoth, Guei-Yuan Lueh, Michal Cierniak. 1999. Support for Garbage Collection at Every Instruction in a Java Compiler. SIGPLAN. Proceedings of the 1999 ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). SIGPLAN Notices 34(5). pp. 118-127. Online.




Will R Stoye, T J W Clarke, Arthur C Norman. 1984. Some Practical Methods for Rapid Combinator Reduction. In LFP 1984, 159-166.



David Tarditi, Amer Diwan. 1995. Measuring the Cost of Storage Management. Carnegie Mellon University. CMU-CS-94-201. Abstract.




Stephen Thomas, Richard E. Jones. 1994. Garbage Collection for Shared Environment Closure Reducers. Computing Laboratory, The University of Kent at Canterbury. Technical Report 31-94. Abstract. Online.



Stephen Thomas. 1995. Garbage Collection in Shared-Environment Closure Reducers: Space-Efficient Depth First Copying using a Tailored Approach. Information Processing Letters. 56:1, pp. 1-7.




Mads Tofte, Jean-Pierre Talpin. 1997. Region-Based Memory Management. Information and Computation 132(2), pp. 109-176. Abstract.



Dave Ungar. 1984. Generation Scavenging: A Non-disruptive High Performance Storage Reclamation Algorithm. ACM, SIGSOFT, SIGPLAN. Practical Programming Environments Conference.




Dave Ungar, Frank Jackson. 1988. Tenuring Policies for Generation-Based Storage Reclamation. SIGPLAN. OOPSLA '88 Conference Proceedings, ACM SIGPLAN Notices, Vol. 23, No. 11, pp. 1-17. Abstract.



Kiem-Phong Vo. 1996. Vmalloc: A General and Efficient Memory Allocator. Software -- Practice and Experience. 26(3): 357-374 (1996). Abstract. Online.




Daniel C. Watson, David S. Wise. 1976. Tuning Garwick's algorithm for repacking sequential storage. BIT. 16, 4 (December 1976): 442--450.



Paul R. Wilson, Michael S. Lam, Thomas G. Moher. 1992. Caching Considerations for Generational Garbage Collection. ACM. L&FP 92. Abstract.




Paul R. Wilson, Sheetal V. Kakkad. 1992. Pointer Swizzling at Page Fault Time. University of Texas at Austin. Abstract. Online.



Paul R. Wilson. 1994. Uniprocessor Garbage Collection Techniques. University of Texas. Abstract. Online.




Paul R. Wilson, Mark S. Johnstone, Michael Neely, David Boles. 1995. Dynamic Storage Allocation: A Survey and Critical Review. University of Texas at Austin. Abstract. Online.




David S. Wise. 1978. The double-buddy system. Department of Computer Science at Indiana University. Technical Report 79.



David S. Wise. 1979. Morris's garbage compaction algorithm restores reference counts. TOPLAS. 1, 1 (July l979): 115--120.



David S. Wise. 1985. Design for a multiprocessing heap with on-board reference counting. Springer-Verlag. In J.-P. Jouannaud (ed.), Functional Programming Languages and Computer Architecture, Lecture Notes in Computer Science 201: 289--304.




David S. Wise. 1993. Stop-and-copy and one-bit reference counting. Information Processing Letters. 46, 5 (July 1993): 243--249. Abstract. Online.



David S. Wise, Joshua Walgenbach. 1996. Static and Dynamic Partitioning of Pointers as Links and Threads. SIGPLAN. Proc. 1996 ACM SIGPLAN Intl. Conf. on Functional Programming, SIGPLAN Not. 31, 6 (June 1996), pp. 42--49. Online. Online.




David S. Wise, Brian Heck, Caleb Hess, Willie Hunt, Eric Ost. 1997. Uniprocessor Performance of a Reference-Counting Hardware Heap. LISP and Symbolic Computation. 10, 2 (July 1997), pp. 159--181. Online.




P. Tucker Withington. 1991. How Real is "Real-Time" Garbage Collection?. ACM. OOPSLA/ECOOP '91 Workshop on Garbage Collection in Object-Oriented Systems. Abstract. Online.



G. May Yip. 1991. Incremental, Generational Mostly-Copying Garbage Collection in Uncooperative Environments. Digital Equipment Corporation. Abstract. Online.




Taiichi Yuasa. 1990. Real-Time Garbage Collection on General-Purpose Machines. Journal of Software and Systems. 11:3 pp.181-198.



Benjamin Zorn, Paul Hilfinger. 1988. A Memory Allocation Profiler for C and Lisp Programs. USENIX. Proceedings for the Summer 1988 USENIX Conference, pp223--237. Abstract. Online.




Benjamin Zorn. 1989. Comparative Performance Evaluation of Garbage Collection Algorithms. Computer Science Division (EECS) of University of California at Berkeley. Technical Report UCB/CSD 89/544 and PhD thesis. Abstract. Online.



Benjamin Zorn. 1990. Comparing Mark-and-sweep and Stop-and-copy Garbage Collection. ACM. Conference on Lisp and Functional Programming, pp. 87-98. Abstract.




Benjamin Zorn. 1990. Barrier Methods for Garbage Collection. University of Colorado at Boulder. Technical Report CU-CS-494-90. Abstract. Online.



Benjamin Zorn. 1991. The Effect of Garbage Collection on Cache Performance. University of Colorado at Boulder. Technical Report CU-CS-528-91. Abstract. Online.




Benjamin Zorn, Dirk Grunwald. 1992. Empirical Measurements of Six Allocation-intensive C Programs. ACM, SIGPLAN. SIGPLAN notices, 27(12):71-80. Abstract. Online.



Benjamin Zorn. 1993. The Measured Cost of Conservative Garbage Collection. Software -- Practice and Experience. 23(7):733-756. Abstract. Online.




Benjamin Zorn, Dirk Grunwald. 1994. Evaluating Models of Memory Allocation. ACM. Transactions on Modeling and Computer Simulation 4(1):107-131. Abstract. Online.



[JBoss-dev] [ jboss-Change Notes-658609 ] Optimistic locking support

[JBoss-dev] [ jboss-Change Notes-658609 ] Optimistic locking support

Initial Comment:
To setup optimistic locking, container configuration
element locking-policy should be set to
<locking-
policy>org.jboss.ejb.plugins.lock.JDBCOptimisticLock</l
ocking-policy>
and entity element in jbosscmp-jdbc.xml should have
optimistic-locking element.

Following are the possible configurations of optimistic-
locking element:
1. Fixed group of fields that will be used for optimistic
locking.
<optimistic-locking>
<group-name>optimisticLockingGroup</group-
name>
</optimistic-locking>
where optimisticLockingGroup is one of the entity's load-
group-name's.

2. Modified strategy. The fields that were modified during
transaction will be used for optimistic locking.
<optimistic-locking>
<modified-strategy/>
</optimistic-locking>

3. Read strategy. The fields that were read during
transaction will be used for optimistic locking.
<optimistic-locking>
<read-strategy/>
</optimistic-locking>

4. Version (counter) column strategy. Additional version
(counter) field of type java.lang.Long will be added to
entity which

will be used for optimistic locking. Each update of the
entity will increase the value of its version field by 1.
<optimistic-locking>
<version-column/>
<field-name>versionField</field-name>
<column-name>ol_version</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER(5)</sql-type>
</optimistic-locking>

5. Timestamp column strategy. Additional timestamp
column field of type java.util.Date will be added to entity
which will be

used for optimistic locking. Each update of the entity will
set the value of its timestamp field to the current time.
<optimistic-locking>
<timestamp-column/>
<field-name>timestampField</field-name>
<column-name>ol_timestamp</column-name>
<jdbc-type>TIMESTAMP</jdbc-type>
<sql-type>DATETIME</sql-type>
</optimistic-locking>

6. Version column generated by KeyGenerator.
Additional field will be added to entity that will be used
for optimistic

locking. Each update of the entity will update its version
column with value generated by KeyGenerator.
<optimistic-locking>
<key-generator-
factory>UUIDKeyGeneratorFactory</key-generator-
factory>
<field-type>java.lang.String</field-type>
<field-name>uuidField</field-name>
<column-name>ol_uuid</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(32)</sql-type>
</optimistic-locking>

星期二, 三月 16, 2004

[JBoss-user] Virtual Directory creation for Jboss

[JBoss-user] Virtual Directory creation for Jboss

You can add one or more external contexts to wars deployed to
a host by adding a Context element to the corresponding Host
by editing the jbossweb-tomcat41.sar/META-INF/jboss-service.xml
descriptor:

<server >

<mbean code= "org.jboss.web.tomcat.tc4.EmbeddedTomcatService "
name= "jboss.web:service=WebServer " >

<attribute name= "Java2ClassLoadingCompliance " >true </attribute >
<attribute name= "LenientEjbLink " >true </attribute >
<attribute name= "UseJBossWebLoader " >true </attribute >
<attribute name= "SubjectAttributeName " >j_subject </attribute >

<attribute name= "Config " >
<Server >
<Service name= "JBoss-Tomcat " >
<Engine name= "MainEngine " defaultHost= "localhost " >
<Logger className= "org.jboss.web.tomcat.Log4jLogger "
verbosityLevel= "debug "
category= "org.jboss.web.localhost.Engine "/ >
<Host name= "localhost " >
...

<Context path= "/images " docBase= "C:/tmp/images " debug= "1 "
reloadable= "true " crossContext= "true " / >
...

With this you can reference the /images path from any war deployed
to the Host. For example, a test-ex.war index.html page accessible
at http://localhost/test-ex/index.html that includes images from
the external context:

test-ex.war/index.html
<html >

<body >
<h1 >External Images </h1 >
<ul >
<li > <img src= "/images/img1.jpg " alt= "Image1 " > </li >
<li > <img src= "/images/img1.jpg " alt= "Image2 " > </li >
<li > <img src= "/images/img1.jpg " alt= "Image3 " > </li >
</ul >
</body >

</html >

有关Jboss web Server一些怪癖的确FAQ

Core Developers Network: "


/documents/*
/docroot





"

星期日, 三月 14, 2004

io architecure


/*
*/


关于JSP Model 1,Model 2很好的实现框架

Link*/
*/

*/
Model 2X

Model 2X is the result of a natural evolution that started in the early days of Web application development. This architecture enhances Model 2, allowing a more flexible and modular front-end design. With Model 2X, XML is generated by the Servlet or the JSP. This XML goes through a sequence of transformations before being sent to the browser. The sequence of transformations is described in XML pipelines. To better understand the relationship between J2EE technologies such as JSP/JSF and XML pipelines, read the article published recently by Orbeon on TheServerSide.com.
Model 1

Model 1 consists of using JSP to extract data from the HTTP request parameters, call the business logic implemented in JavaBeans or directly into the JSP, handle the HTTP session, and generate the HTML output. Using this approach usually leads to a significant amount of scriptlets (Java code embedded in HTML). Another limitation of Model 1 is that each JSP page must be individually responsible for managing the application state and verifying authentication and security./*
*/

Model 2

Model 2 is a server-side implementation of the Model View Controller architecture using Servlets and Java Server Pages (JSP). In Model 2, Servlets control the flow of the Web application and delegate the business logic to either JavaBeans or EJBs, while JSP pages take care of producing the HTML. This model encourages a much cleaner separation of business and presentation logic, making application development as well as maintenance a much easier task. The most popular example of frameworks implementing Model 2 is an Apache Jakarta project called Struts.
*/

Model 2X

Model 2 based frameworks are a big step in the right direction. However, in some cases it is not necessarily optimal to output HTML directly from JSPs to the Web browser. For example, there are situations where it would be desirable to separate look and feel logic from the localization. Likewise, there might be situations where the same application has requirements to support multiple devices with the same back-end logic. These are perfect use cases for an XML/XSLT approach. Executing a series of XML transformations before sending the appropriate markup language to the Web browser is a better approach. That is why Orbeon introduced Model 2X back in February 2002 in an article published in JavaWorld magazine.

集成JSP/JSF和XML/XSLT

Sun eCommunity
很好的一篇介绍JSF 1。0技术框架的文章。

星期六, 三月 13, 2004

InLine Image HTML 实现(二),如何在HTML页面里嵌入图片数据?

William按:当初想到为为什么不可以在HTML里面直接嵌入图片数据呢?非要用link引用的方式呢?不方便发送,也不方便保存。
最终找到了部分实现的方法,可惜丑陋的M$的IE,不支持HTML4。0的规范,BT.但可爱的Mozilla和FIreFox支持.:).
--
理论:<IMG SRC="">是通过link URL的方式获得图片资源,不过现在HTML 4。0支持:data协议。
<IMG SRC="data:....">
另外Mozilla也支持Pipeline的方式获取数据。从这里可以看出良好的API设计的重要了。否则一个模块的功能的扩展性非常差。Mozilla的HTML Rengine是在资源上加了一层Pipeline的抽象,通过chian filter的模式来匹配最终的负责render,进行这样渲染rende的都是符合某钟合格数据流。这样一下子是API的灵活性极大加强了,而IE的HTML render Enginne是死板的switch("GIF89a")类似的方式写的代码,扩展性极差,怪不得要经常升级和打补丁呢。愚昧啊,愚昧。丑陋战胜了先进.
这种Inline Image支持的图片长度有限,最少或最多是1k的图片,不过我这个可不只1K,也可以。当然页勉里面嵌入数据,最好只放在个人简介里,否则,可要给访问网站的骂的心惊肉跳了。

实现部分:
1.<IMG SRC="data:...">
2.<IMG SRC="javascript:imagedata">
<html>
<body>
<script>

var hexdata='[\x...]';//这里是存放InLineImage工具生成的GIF87a格式数据

</script>
a<br>
<img src="javascript:hexdata;">//Javascript PipeLine数据管道实现
<p><IMG SRC="data:image/gif;base64,[..base64 data]" ALT="Larry"/>
</body>
</html>

--------



a



Html Inline Image 工具(一):把Gif87a 图片转换为Ascii表示

当前网站:http://sunose.blogspot.com
目的:打开一个gif图片把16进制数字转换为ASCII表示或转为Bas64表示.为Inline Image准备数据.
------------------------------------------------------------------------
import sun.misc.*;
import java.io.*;
import java.lang.Integer;

public class InLineImageTool {
private static BASE64Encoder encoder = new BASE64Encoder();
private static BASE64Decoder decoder = new BASE64Decoder();

public InLineImageTool() {
}

public static String bytesToHex(byte[] data) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
buf.append(byteToHex(data[i]).toUpperCase());
}
return (buf.toString());
}


/**
* method to convert a byte to a hex string.
*
* @param data the byte to convert
* @return String the converted byte
*/
public static String byteToHex(byte data) {
StringBuffer buf = new StringBuffer();
buf.append(toHexChar((data >>> 4) & 0x0F));//高字节充0,把高移到低字节保存
buf.append(toHexChar(data & 0x0F));//低字节转成字符
return buf.toString();
}


/**
* Convenience method to convert an int to a hex char.
*
* @param i the int to convert
* @return char the converted char
*/
public static char toHexChar(int i) {
if ((0 <= i) && (i <= 9)) {
return (char) ('0' + i);//把0-9字节转成ASCII
} else {
return (char) ('a' + (i - 10));//把a-f转成ASCII
}
}



public static void main (String[] args) throws Exception
{
if(args.length<2){System.out.println("Syntax:java InLineImageTool gifFile format(base64 or gif)");System.exit(0);}

File giffile=null;
giffile=new File(args[0]);
FileInputStream insrc=new FileInputStream(giffile);
byte[] inbyte=new byte[1];
if(args[1].equals("gif"))
{
String temp="";

for(int i=0;i<giffile.length();i++)
{
if(insrc.read(inbyte)==-1)break;
System.out.print("\\x"+byteToHex(inbyte[0]));
}
}else if(args[1].equals("base64"))//Base64 is Latin ascii string
{
byte[] fielbyte=new byte[(int)giffile.length()];//多大的文件?:)
insrc.read(fielbyte);
System.out.print(encoder.encode(fielbyte));
}else
{
System.out.println("Invalid format String:"+args[0]+" Valid is base64 or gif");
}
}
}

//另外还有一种把gif转为base64的简便方法:打开发送邮件软件:outlookexpress或Mozilla Thunderbird 新建邮件,然后保存为草稿(drafts)然后看邮件源代码:
Content-Type: image/gif;
name="1.gif"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="1.gif"
下面所附加的就是Base64编码了.

星期五, 三月 12, 2004

如何在上传文件的HTML页面里预览图片或其他

<body bgcolor>
上传:<strong><font size=+1>dddd</strong>的照片
<script>
document.write("<img src=file:///c:\\b5.gif>");
</script>

<FORM name="mainform" ENCTYPE='multipart/form-data' method='POST' action='/Member/QuizController?page=upload'>
<INPUT TYPE='file' NAME='uploadfile' size="40" maxlength="255" onchange="javascript:displayimg();">
<INPUT TYPE='submit' VALUE='start...' >
</FORM>
<script>
function displayimg()
{
var tstr=document.mainform.uploadfile.value;
document.all.contentLayer.document.user.src=tstr;
}
</script>

<DIV ID="contentLayer" STYLE="position: absolute; left: 20px; top: 100px; height: 120px; z-index: 1; visibility: visible;">
<FONT CLASS=title>Preview</FONT>
<IMG name=user SRC="file:///c:/2.jpg">
</DIV>
</body>

星期三, 三月 10, 2004

编写Java Thread-safe 需要了解的最基本的概念.

thread safe code

Thread-safe code is code that will work even if many Threads
are executing it simultaneously. Writing it is a black art. It is extremely
difficult to debug since you can't reproduce all possible interactions between Threads.
You have to do it by logic. In a computer, something that happens only one in a
billion times must be dealt with because on average it will happen once a second.
To write code that will run stably for weeks takes extreme paranoia.
Here are your tools for writing thread-safe code.


  • Local variables


    Every Thread has its own set of local variables
    stored in a stack frame. There is no possible way a Thread
    can interfere with another Thread's local variables.
    You will often see Sun code where at the beginning of a method it fetches
    everything into local variables, then computes, then stores everything back into
    instance and class variables. The advantage of this approach is local variables
    cannot spontaneously change by the actions of other Threads.


  • The volatile keyword
    It warns the compiler that other Threads may change
    an instance or class variable at any time, and that the compiler should not
    cache that value in a register, least it be stale. Volatile
    does not imply any locking. It simply that the compiler/JVM does not cache volatile
    values in registers. On every use, it fetches the value from main shared RAM. On
    every assignment it saves the value to main shared RAM. In a multicpu machine
    with cache coherency, the value may not actually be stored all the way back to
    RAM, but logically it is. Declaring a long or double
    volatile also ensures it is fetched and stored
    atomically in one indivisible 64 bit chunk, rather than two 32 bit chunks one
    after the other as is normal. Volatile is sufficient to ensure even code as
    simply as x++ works. Pathologically you could see this
    happening:
    Thread (a) reads x, thread (a) increments x in a register, thread (b) reads x,
    thread (b) increments x in a register, thread (b) saves x, thread (a) saves x.
    The result is only one increment instead of two. You may think this highly
    improbable, but in the nanoscopic world of the CPU billions of events happen
    every second, so that highly "improbable" things happen frequently, or,
    even more infuriatingly, only during demos.


  • The synchronized keyword
    Think of synchronized as temporarily locking an
    object to have exclusing access to it for modifications or study. synchronized
    marks a block of code or an entire method as critical. Only one Thread
    can be in it at once executing. Other Threads
    automatically sleep waiting their turn to use it. For a synchronized instance
    method, the synchronized code can be run by other Thread
    on other objects simultaneously, since the locking is on the object. For a
    synchronized class method, the locking in on the class object, which thus limits
    to only one Thread executing that code.
    Does the synchronized mechanism lock Threads out of
    the object in all critical regions or the object in just one critical region? It
    is the first. All critical sections locked with the same object are blocked.
    Keep in mind that you can use an object other than the one you are working on as
    the locking object. This would let you for example allow two groups of critical
    code to be executing simultaneously, provided they locked on different objects,
    e.g. a dummy inner class locking object. Understand that the objects themselves
    are not locked. Other threads can access them with non-sychronised methods, even
    when they are locked. It also means you could have critical code acting on
    thousands of different objects funnelled to single processing stream by locking
    all the critical code on a single lock object. This would not be efficient, but
    would be theoretically possible.


  • wait, notify and sleep


    For inter-Thread communication you can use Thread.wait
    and Thread.notify. Thread.wait
    goes to sleep until some other Thread wakes it up. Thread.notify
    wakes up some other Thread. Thread.sleep
    goes to sleep for some specified number of milliseconds, unless some other Thread
    wakes it up first.


  • Immutable Objects


    Immutable objects, (ones without any setter methods, e.g. Integer)
    are automatically thread safe. They are read-only. Combine that with final
    references, and you don't need to worry all about what other threads are doing.
    Instead of modifying fields in an object, and risking it being in an
    indeterminate state, you create a new object, and then replace the object as a
    whole with the new one is one atomic operation, setting a new reference.


  • interrupt


    One Thread can interrupt another with Thread.interrupt.
    The most common use is to wake up a sleeping Thread

    prematurely, or to abort a long i/o. If a Thread is
    computing, interrupting it will have no effect until it does a sleep
    or wait etc. Interrupting a Thread
    will cause it to immediately wake the next time it tries to sleep.
    A Thread can even interrupt itself.


    Unfortunately you can't use interrupt to abort just
    any i/o. It can really only be used for that when using the JDK 1.4 java.nio
    I/O. In particular when using a Channel that
    implements InterruptibleChannel, which includes
    channels for files, pipes and networking. Thread.interrupt
    is not guaranteed to wake up any thread blocked in any other I/O operation.


See the warning under Gotchas:Threads on why
a sleeping task may never waken if somebody fiddles with the system clock
setting while your thread is asleep.

start versus run


The easiest way to start a Thread is to implement Runnable
on some class. All you have to do is say implements Runnable
and write a run method that is called when the Thread
forks (starts). However you don't call run
directly.

Java时间格式显示转换.

两个重要的类:java.util.DateFormat/java.util.Calendar
显示指定格式的时间:
jsp中:
<%=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").getDateTimeInstance(java.text.DateFormat.LONG,java.text.DateFormat.LONG).format(java.util.Calendar.getInstance().getTime())%>
显示时间为: 2004年3月10日 上午10时31分19秒//在中文2000下

数据库的Date字段对应java.sql.Date(java.util.Date)
DateTIme字段对应Java.sql.Timestamp
所以要分别对待.
private static String dateFormatPattern="yyyy-MM-dd";//时间格式.
private static String dateAndFormatPattern="yyyy-MM-dd HH:mm:ss";//datetime时间戳格式
....
SimpleDateFormat simplefmt=new SimpleDateFormat(dateFormatPattern);
SimpleDateFormat complexfmt=new SimpleDateFormat(dateAndFormatPattern);
....
//得到时间Date
java.util.Date tmpdate=simplefmt.parse(values);
java.sql.Date tmpval = new java.sql.Date(tmpdate.getTime());

//得到时间戳Datetime
java.util.Date tmpdate=complexfmt.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG).parse(values);
java.sql.Timestamp tmpval =new java.sql.Timestamp(tmpdate.getTime());

星期二, 三月 09, 2004

Java/Servlet/Jsp FormBean

绝对秘籍:实现<jsp:setProperty name="" property="*"/>类似功能.

/**
*
* @param req HttpServletRequest
* @param bean Object In Actual,It is DTO Object or any Bean class.
* @throws Exception
* @return Object
*/
public static Object mapBean(javax.servlet.http.HttpServletRequest req, Object bean,boolean debug) throws Exception
{
SimpleDateFormat simplefmt=new SimpleDateFormat(dateFormatPattern);
SimpleDateFormat complexfmt=new SimpleDateFormat(dateAndFormatPattern);
Method[] methods = bean.getClass().getMethods();
for (int i = 0; i < methods.length; i++)
{
Method method = methods[i];

if (method.getName().startsWith("set"))
{
String propertyName = method.getName().substring(3).toLowerCase();
if(debug)System.out.println("FormBean:propertyName="+ propertyName );

String values = req.getParameter(propertyName);

Class[] ts = method.getParameterTypes();
Class t;
if(ts.length>0){t = ts[0];}else {System.out.println("FormBean:Method {"+method.getName()+"} is Invalid:no parameter");continue;}
if (values != null)
{
if(debug){System.out.println("FormBean:Method is:"+method.getName()+" is invoking");}
if (t.equals(String.class))
{
method.invoke(bean, new Object[]{values});
}else if (t.equals(Integer.class)|| t.equals(Integer.TYPE))
{
Integer tmpval = new Integer(values);
tmpval = new Integer(values);
method.invoke(bean, new Object[]{tmpval});
}else if (t.equals(Byte.class)|| t.equals(Byte.TYPE)) {
Byte tmpval = new Byte(values);
method.invoke(bean, new Object[]{tmpval});
}
else if (t.equals(Boolean.class)|| t.equals(Boolean.TYPE) ) {
Boolean tmpval = new Boolean(values);
method.invoke(bean, new Object[]{tmpval});
}
else if (t.equals(Short.class) || t.equals(Short.TYPE) ) {
Short tmpval = new Short(values);
method.invoke(bean, new Object[]{tmpval});
}
else if (t.equals(Long.class)|| t.equals(Long.TYPE)) {
Long tmpval = new Long(values);
method.invoke(bean, new Object[]{tmpval});
}
else if (t.equals(Double.class)|| t.equals(Double.TYPE)) {
Double tmpval = new Double(values);
method.invoke(bean, new Object[]{tmpval});
}
else if (t.equals(Float.class)|| t.equals(Float.TYPE)) {
Float tmpval = new Float(values);
method.invoke(bean, new Object[]{tmpval});
}
else if (t.equals(Character.class) || t.equals(Character.TYPE))
{
Character[] tmpval=new Character[values.length()];
for(int ia=0;ia<values.length();ia++)
tmpval[ia]=new Character(values.charAt(ia));
method.invoke(bean, new Object[]{tmpval});
}else if(t.equals(java.sql.Date.class))//输入时间
{
java.util.Date tmpdate=simplefmt.parse(values);
java.sql.Date tmpval = new java.sql.Date(tmpdate.getTime());
System.out.println("Date="+tmpval);
method.invoke(bean, new Object[]{tmpval});

}else if(t.equals(java.sql.Timestamp.class))//输入时间戳
{
java.util.Date tmpdate=complexfmt.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG).parse(values);
java.sql.Timestamp tmpval =new java.sql.Timestamp(tmpdate.getTime());
method.invoke(bean, new Object[]{tmpval});
System.out.println("Timestamp="+tmpval);
}
}
else {
System.out.println("FormBean:"+"Method {"+method.getName()+ "} can't find Parameter");
// Object tmpval = new Integer(values);
// method.invoke(bean, new Object[]{tmpval});
}
}
}
return bean;
}

星期一, 三月 08, 2004

Java Interface VS Abstrace Class 的对比

When should you use an abstract class, when an interface, when both? Thistable may help you decide.Another issue that's important is what I call "heterogeneous vs. homogeneous."If implementors/subclasses are homogeneous, tend towards an abstract base class.If they are heterogeneous, use an interface. (Now all I have to do is come upwith a good definition of hetero/homo-geneous in this context.) If the variousobjects are all of-a-kind, and share a common state and behavior, then tendtowards a common base class. If all they share is a set of method signatures,then tend towards an interface.
Interfaces vs Abstact Classes
featureinterfaceabstract class
multiple inheritanceA class may implement several interfaces.A class may extend only one abstract class.
default implementationAn interface cannot provide any code at all, much less default code.An abstract class can provide complete code, default code, and/or just stubsthat have to be overridden.
constantsStatic final constants only, can use them without qualification in classesthat implement the interface. On the other paw, these unqualified names pollutethe namespace. You can use them and it is not obvious where they are coming fromsince the qualification is optional.Both instance and static constants are possible. Both static and instanceintialiser code are also possible to compute the constants.
third party convenienceAn interface implementation may be added to any existing third party class.A third party class must be rewritten to extend only from the abstract class.
is-a vs -able or can-doInterfaces are often used to describe the peripheral abilities of a class,not its central identity, e.g. an Automobile classmight implement the Recyclable interface, whichcould apply to many otherwise totally unrelated objects.An abstract class defines the core identity of its descendants. If youdefined a Dog abstract class then Damamation descendants are Dogs, theyare not merely dogable. Implemented interfaces enumerate the general things aclass can do, not the things a class is.

In a Java context, users should typically implement the Runnable interfacerather than extending Thread, because they're notreally interested in providing some new Threadfunctionality, they normally just want some code to have the capability ofrunning independently. They want to create something that can be run in a thread,not a new kind of thread.The similar is-a vs has-a debate comes up when youdecide to inherit or delegate. multipleinheritance for further discussion of is-a vs has-a

plug-inYou can write a new replacement module for an interface that contains notone stick of code in common with the existing implementations. When youimplement the inteface, you start from scratch without any defaultimplementation. You have to obtain your tools from other classes; nothing comeswith the interface other than a few constants. This gives you freedom toimplement a radically different internal design.You must use the abstract class as-is for the code base, with all itsattendant baggage, good or bad. The abstract class author has imposed structureon you. Depending on the cleverness of the author of the abstract class, thismay be good or bad.
homogeneityIf all the various implementaions share is the method signatures, then aninterface works best.If the various implementations are all of a kind and share a common statusand behaviour, usually an abstract class works best.
maintenanceIf your client code talks only in terms of an interface, you can easilychange the concrete implementation behind it, using a factorymethod.Just like an interface, if your client code talks only in terms of anabstract class, you can easily change the concrete implementation behind it,using a factory method.
speedSlow, requires extra indirection to find the corresponding method in theactual class. Modern JVMs are discovering ways to reduce this speed penalty.Fast
tersenessThe constant declarations in an interface are all presumed publicstatic final, so you may leave that part out. You can't call any methodsto compute the initial values of your constants. You need not declare individualmethods of an interface abstract. They are all presumed so.You can put shared code into an abstract class, where you cannot into aninterface. If interfaces want to share code, you will have to write otherbubblegum to arrange that. You may use methods to compute the initial values ofyour constants and variables, both instance and static. You must declare all theindividual methods of an abstract class abstract.
adding functionalityIf you add a new method to an interface, you must track down allimplementations of that interface in the universe and provide them with aconcrete implementation of that method.If you add a new method to an abstract class, you have the option ofproviding a default implementation of it. Then all existing code will continueto work without change.

星期六, 三月 06, 2004

很棒的R/O map tool.

安装了Hibernate后,然后去下在Hibernate extensions 包,里面带的ddl2hbm工具,可以直接连接到数据库,并生成Java
VO(Value Object)或POJO(plaint old Java Object) class.非常好。

需要修改ddl2hbm里面的路径,方便找到Hibernate的安装目录。

MySQL Auto increment 字段,如何在 JBoss CMP ejb 2.0中定义和使用.

环境:Jboss 3.2.2 with tomcat 4.1.27.Mysql 4.0.18
首先有两个Mysql 4.0.18 的表
# Host: williamwang
# Database: test
# Table: 'account'
#
CREATE TABLE `account` (
`accountid` int(11) NOT NULL auto_increment,
`acount` varchar(100) default '',
`salaryid` int(11) default '0',
`text` varchar(100) default '',
PRIMARY KEY (`accountid`)
) TYPE=MyISAM;

# Host: williamwang
# Database: test
# Table: 'salary'
#
CREATE TABLE `salary` (
`salaryid` int(11) NOT NULL auto_increment,
`userid` varchar(20) NOT NULL default '',
`workage` int(11) NOT NULL default '0',
`titlelevel` int(12) NOT NULL default '0',
PRIMARY KEY (`salaryid`)
) TYPE=MyISAM;

其次定义Jboss 的jbosscmp-jdbc.xml.红色为关键处

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
<jbosscmp-jdbc>
<defaults>
<datasource>java:/MySqlDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>
</defaults>
<enterprise-beans>
<entity>
<ejb-name>Account</ejb-name>
<table-name>account</table-name>
<cmp-field>
<field-name>accountid</field-name>
<column-name>accountid</column-name>
<auto-increment/>
</cmp-field>
<cmp-field>
<field-name>acount</field-name>
<column-name>acount</column-name>
</cmp-field>
<cmp-field>
<field-name>salaryid</field-name>
<column-name>salaryid</column-name>
</cmp-field>
<cmp-field>
<field-name>text</field-name>
<column-name>text</column-name>
</cmp-field>

<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<field-name>accountid</field-name>
<column-name>accountid</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<auto-increment/>
</unknown-pk>
<entity-command name="mysql-get-generated-keys"/>

</entity>

<entity>
<ejb-name>Salary</ejb-name>
<table-name>salary</table-name>
<cmp-field>
<field-name>salaryid</field-name>
<column-name>salaryid</column-name>
<auto-increment/>
</cmp-field>
<cmp-field>
<field-name>titlelevel</field-name>
<column-name>titlelevel</column-name>
</cmp-field>
<cmp-field>
<field-name>userid</field-name>
<column-name>userid</column-name>
</cmp-field>
<cmp-field>
<field-name>workage</field-name>
<column-name>workage</column-name>
</cmp-field>
</entity>
</enterprise-beans>
</jbosscmp-jdbc>

其三:定义一个TestClient来测试。

星期五, 三月 05, 2004

Hibernate Extensions download page.

SourceForge.net: Project Filelist

Java字符集之间转换

/**
*

Title:


*

Description:

Copyright: Copyright (c) 2004


*

Company: sos


* @author William Wang
* @version 1.0
*/
import java.io.*;

public class big2ucs {
public big2ucs() {
}
public static void main(String[] args) throws Exception
{
if(args.length<2){System.out.println("Syntax:big2ucs sourcefile(big5 format) outputfile");System.exit(0);}
System.out.println("Big5 source File is "+args[0]+" Unicode Format file is "+args[1]);
File sourcefile = new File(args[0]);
File outputfile = new File(args[1]);
FileInputStream is = new FileInputStream(sourcefile);
FileOutputStream os = new FileOutputStream(outputfile);
InputStreamReader isr = new InputStreamReader(is,"Big5-HKSCS");
BufferedReader br = new BufferedReader(isr);
OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-16LE");
String buffstr="";
char[] line={0x0d,0x0a};
char[] readc=new char[30];
int isend;
do
{
buffstr=br.readLine();
if(buffstr != null)
{
osw.write(new String(buffstr.getBytes(),"UTF-16LE"));
//osw.write(buffstr);
osw.write("\n");
}
}while(buffstr != null);

//while((isend=isr.read())!=-1)osw.write(isend);

osw.flush();
is.close();
os.close();
isr.close();
br.close();

}
public static String convert(String pValue, String pEncoding)
throws IOException
{
byte bytes[] = getBytes(pValue);
return convert(bytes, pEncoding);
}
public static byte[] getBytes(String pValue)
{
byte bytes[] = new byte[pValue.length()];
for(int i = 0; i < bytes.length; i++)
bytes[i] = (byte)pValue.charAt(i);

return bytes;
}

public static String convert(byte pValue[], String pEncoding)
throws IOException
{
ByteArrayInputStream bais = new ByteArrayInputStream(pValue);
InputStreamReader isr = new InputStreamReader(bais, pEncoding);
StringBuffer sb = new StringBuffer();
for(int c = isr.read(); c != -1; c = isr.read())
sb.append((char)c);

return sb.toString();
}

}

星期四, 三月 04, 2004

星期三, 三月 03, 2004

如何得到jboss-web.xml定义的element的值.

JBoss :: Professional Open Source
import org.jboss.security.SubjectSecurityManager;

InitialContext ctx = new InitialContext();
Context envCtx = (Context) ctx.lookup("java:comp/env");
SubjectSecurityManager ssm = (SubjectSecurityManager) envCtx.lookup("security/security-domain");

If you just want the name, use:
Code:


InitialContext ctx = new InitialContext();
Context envCtx = (Context) ctx.lookup("java:comp/env");
LinkRef ref = (LinkRef) envCtx.lookupLink("security/security-domain");
String secDomain = ref.getLinkName();



NTLM Authentication Scheme for HTTP

NTLM Authentication Scheme for HTTP
NTLM Authentication Scheme for HTTP
Introduction
This is an attempt at documenting the undocumented NTLM authentication scheme used by M$'s browsers, proxies, and servers (MSIE and IIS); this scheme is also sometimes referred to as the NT challenge/response (NTCR) scheme. Most of the info here is derived from three sources (see also the Resources section at the end of this document): Paul Ashton's work on the NTLM security holes, the encryption documentation from Samba, and network snooping. Since most of this info is reverse-engineered it is bound to contain errors; however, at least one client and one server have been implemented according to this data and work successfully in conjunction with M$'s browsers, proxies and servers.

Note that this scheme is not as secure as Digest and some other schemes; it is slightly better than the Basic authentication scheme, however.

Also note that this scheme is not an http authentication scheme - it's a connection authentication scheme which happens to (mis-)use http status codes and headers (and even those incorrectly).

NTLM Handshake
When a client needs to authenticate itself to a proxy or server using the NTLM scheme then the following 4-way handshake takes place (only parts of the request and status line and the relevant headers are shown here; "C" is the client, "S" the server):

1: C --> S GET ...

2: C <-- S 401 Unauthorized
WWW-Authenticate: NTLM

3: C --> S GET ...
Authorization: NTLM

4: C <-- S 401 Unauthorized
WWW-Authenticate: NTLM

5: C --> S GET ...
Authorization: NTLM

6: C <-- S 200 Ok

Messages
The three messages sent in the handshake are binary structures. Each one is described below as a pseudo-C struct and in a memory layout diagram. byte is an 8-bit field; short is a 16-bit field. All fields are unsigned. Numbers are stored in little-endian order. Struct fields named zero contain all zeroes. An array length of "*" indicates a variable length field. Hexadecimal numbers and quoted characters in the comments of the struct indicate fixed values for the given field.
The field flags is presumed to contain flags, but their significance is unknown; the values given are just those found in the packet traces.

Type-1 Message
This message contains the host name and the NT domain name of the client.

struct {
byte protocol[8]; // 'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0'
byte type; // 0x01
byte zero[3];
short flags; // 0xb203
byte zero[2];

short dom_len; // domain string length
short dom_len; // domain string length
short dom_off; // domain string offset
byte zero[2];

short host_len; // host string length
short host_len; // host string length
short host_off; // host string offset (always 0x20)
byte zero[2];

byte host[*]; // host string (ASCII)
byte dom[*]; // domain string (ASCII)
} type-1-message

0 1 2 3
+-------+-------+-------+-------+
0: | 'N' | 'T' | 'L' | 'M' |
+-------+-------+-------+-------+
4: | 'S' | 'S' | 'P' | 0 |
+-------+-------+-------+-------+
8: | 1 | 0 | 0 | 0 |
+-------+-------+-------+-------+
12: | 0x03 | 0xb2 | 0 | 0 |
+-------+-------+-------+-------+
16: | domain length | domain length |
+-------+-------+-------+-------+
20: | domain offset | 0 | 0 |
+-------+-------+-------+-------+
24: | host length | host length |
+-------+-------+-------+-------+
28: | host offset | 0 | 0 |
+-------+-------+-------+-------+
32: | host string |
+ +
. .
. .
+ +-----------------+
| | domain string |
+-------------+ +
. .
. .
+-------+-------+-------+-------+

The host and domain strings are ASCII (or possibly ISO-8859-1), are uppercased, and are not nul-terminated. The host name is only the host name, not the FQDN (e.g. just "GOOFY", not "GOOFY.DISNEY.COM"). The offsets refer to the offset of the specific field within the message, and the lengths are the length of specified field. For example, in the above message host_off = 32 and dom_off = host_off + host_len. Note that the lengths are included twice (for some unfathomable reason).
Type-2 Message
This message contains the server's NTLM challenge.

struct {
byte protocol[8]; // 'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0'
byte type; // 0x02
byte zero[7];
short msg_len; // 0x28
byte zero[2];
short flags; // 0x8201
byte zero[2];

byte nonce[8]; // nonce
byte zero[8];
} type-2-message

0 1 2 3
+-------+-------+-------+-------+
0: | 'N' | 'T' | 'L' | 'M' |
+-------+-------+-------+-------+
4: | 'S' | 'S' | 'P' | 0 |
+-------+-------+-------+-------+
8: | 2 | 0 | 0 | 0 |
+-------+-------+-------+-------+
12: | 0 | 0 | 0 | 0 |
+-------+-------+-------+-------+
16: | message len | 0 | 0 |
+-------+-------+-------+-------+
20: | 0x01 | 0x82 | 0 | 0 |
+-------+-------+-------+-------+
24: | |
+ server nonce |
28: | |
+-------+-------+-------+-------+
32: | 0 | 0 | 0 | 0 |
+-------+-------+-------+-------+
36: | 0 | 0 | 0 | 0 |
+-------+-------+-------+-------+

The nonce is used by the client to create the LanManager and NT responses (see Password Hashes). It is an array of 8 arbitrary bytes. The message length field contains the length of the complete message, which in this case is always 40.
Type-3 Message
This message contains the username, host name, NT domain name, and the two "responses".

struct {
byte protocol[8]; // 'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0'
byte type; // 0x03
byte zero[3];

short lm_resp_len; // LanManager response length (always 0x18)
short lm_resp_len; // LanManager response length (always 0x18)
short lm_resp_off; // LanManager response offset
byte zero[2];

short nt_resp_len; // NT response length (always 0x18)
short nt_resp_len; // NT response length (always 0x18)
short nt_resp_off; // NT response offset
byte zero[2];

short dom_len; // domain string length
short dom_len; // domain string length
short dom_off; // domain string offset (always 0x40)
byte zero[2];

short user_len; // username string length
short user_len; // username string length
short user_off; // username string offset
byte zero[2];

short host_len; // host string length
short host_len; // host string length
short host_off; // host string offset
byte zero[6];

short msg_len; // message length
byte zero[2];

short flags; // 0x8201
byte zero[2];

byte dom[*]; // domain string (unicode UTF-16LE)
byte user[*]; // username string (unicode UTF-16LE)
byte host[*]; // host string (unicode UTF-16LE)
byte lm_resp[*]; // LanManager response
byte nt_resp[*]; // NT response
} type-3-message

0 1 2 3
+-------+-------+-------+-------+
0: | 'N' | 'T' | 'L' | 'M' |
+-------+-------+-------+-------+
4: | 'S' | 'S' | 'P' | 0 |
+-------+-------+-------+-------+
8: | 3 | 0 | 0 | 0 |
+-------+-------+-------+-------+
12: | LM-resp len | LM-Resp len |
+-------+-------+-------+-------+
16: | LM-resp off | 0 | 0 |
+-------+-------+-------+-------+
20: | NT-resp len | NT-Resp len |
+-------+-------+-------+-------+
24: | NT-resp off | 0 | 0 |
+-------+-------+-------+-------+
28: | domain length | domain length |
+-------+-------+-------+-------+
32: | domain offset | 0 | 0 |
+-------+-------+-------+-------+
36: | user length | user length |
+-------+-------+-------+-------+
40: | user offset | 0 | 0 |
+-------+-------+-------+-------+
44: | host length | host length |
+-------+-------+-------+-------+
48: | host offset | 0 | 0 |
+-------+-------+-------+-------+
52: | 0 | 0 | 0 | 0 |
+-------+-------+-------+-------+
56: | message len | 0 | 0 |
+-------+-------+-------+-------+
60: | 0x01 | 0x82 | 0 | 0 |
+-------+-------+-------+-------+
64: | domain string |
+ +
. .
. .
+ +-------------------+
| | user string |
+-----------+ +
. .
. .
+ +-------------+
| | host string |
+-----------------+ +
. .
. .
+ +---------------------------+
| | LanManager-response |
+---+ +
. .
. .
+ +------------------+
| | NT-response |
+------------+ +
. .
. .
+-------+-------+-------+-------+

The host, domain, and username strings are in Unicode (UTF-16, little-endian) and are not nul-terminated; the host and domain names are in upper case. The lengths of the response strings are 24.

Password Hashes
To calculate the two response strings two password hashes are used: the LanManager password hash and the NT password hash. These are described in detail at the beginning of the Samba ENCRYPTION.html document. However, a few things are not clear (such as what the magic constant for the LanManager hash is), so here is some almost-C code which calculates the two responses. Inputs are passw and nonce, the results are in lm_resp and nt_resp.

/* setup LanManager password */

char lm_pw[14];
int len = strlen(passw);
if (len > 14) len = 14;

for (idx=0; idx lm_pw[idx] = toupper(passw[idx]);
for (; idx<14; idx++)
lm_pw[idx] = 0;


/* create LanManager hashed password */

unsigned char magic[] = { 0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 };
unsigned char lm_hpw[21];
des_key_schedule ks;

setup_des_key(lm_pw, ks);
des_ecb_encrypt(magic, lm_hpw, ks);

setup_des_key(lm_pw+7, ks);
des_ecb_encrypt(magic, lm_hpw+8, ks);

memset(lm_hpw+16, 0, 5);


/* create NT hashed password */

int len = strlen(passw);
char nt_pw[2*len];
for (idx=0; idx {
nt_pw[2*idx] = passw[idx];
nt_pw[2*idx+1] = 0;
}

unsigned char nt_hpw[21];
MD4_CTX context;
MD4Init(&context);
MD4Update(&context, nt_pw, 2*len);
MD4Final(nt_hpw, &context);

memset(nt_hpw+16, 0, 5);


/* create responses */

unsigned char lm_resp[24], nt_resp[24];
calc_resp(lm_hpw, nonce, lm_resp);
calc_resp(nt_hpw, nonce, nt_resp);

Helpers:

/*
* takes a 21 byte array and treats it as 3 56-bit DES keys. The
* 8 byte plaintext is encrypted with each key and the resulting 24
* bytes are stored in the results array.
*/
void calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results)
{
des_key_schedule ks;

setup_des_key(keys, ks);
des_ecb_encrypt((des_cblock*) plaintext, (des_cblock*) results, ks, DES_ENCRYPT);

setup_des_key(keys+7, ks);
des_ecb_encrypt((des_cblock*) plaintext, (des_cblock*) (results+8), ks, DES_ENCRYPT);

setup_des_key(keys+14, ks);
des_ecb_encrypt((des_cblock*) plaintext, (des_cblock*) (results+16), ks, DES_ENCRYPT);
}


/*
* turns a 56 bit key into the 64 bit, odd parity key and sets the key.
* The key schedule ks is also set.
*/
void setup_des_key(unsigned char key_56[], des_key_schedule ks)
{
des_cblock key;

key[0] = key_56[0];
key[1] = ((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1);
key[2] = ((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2);
key[3] = ((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3);
key[4] = ((key_56[3] << 4) & 0xFF) | (key_56[4] >> 4);
key[5] = ((key_56[4] << 3) & 0xFF) | (key_56[5] >> 5);
key[6] = ((key_56[5] << 2) & 0xFF) | (key_56[6] >> 6);
key[7] = (key_56[6] << 1) & 0xFF;

des_set_odd_parity(&key);
des_set_key(&key, ks);
}

Keeping the connection alive
As mentioned above, this scheme authenticates connections, not requests. This manifests itself in that the network connection must be kept alive during the second part of the handshake, i.e. between the receiving of the type-2 message from the server (step 4) and the sending of the type-3 message (step 5). Each time the connection is closed this second part (steps 3 through 6) must be repeated over the new connection (i.e. it's not enough to just keep sending the last type-3 message). Also, once the connection is authenticated, the Authorization header need not be sent anymore while the connection stays open, no matter what resource is accessed.

For implementations wishing to work with M$'s software this means that they must make sure they use either HTTP/1.0 keep-alive's or HTTP/1.1 persistent connections, and that they must be prepared to do the second part of the handshake each time the connection was closed and is reopened. Server implementations must also make sure that HTTP/1.0 responses contain a Content-length header (as otherwise the connection must be closed after the response), and that HTTP/1.1 responses either contain a Content-length header or use the chunked transfer encoding.

Example
Here is an actual example of all the messages. Assume the host name is "LightCity", the NT domain name is "Ursa-Minor", the username is "Zaphod", the password is "Beeblebrox", and the server sends the nonce "SrvNonce". Then the handshake is:

C -> S GET ...

S -> C 401 Unauthorized
WWW-Authenticate: NTLM

C -> S GET ...
Authorization: NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S

S -> C 401 Unauthorized
WWW-Authenticate: NTLM TlRMTVNTUAACAAAAAAAAACgAAAABggAAU3J2Tm9uY2UAAAAAAAAAAA==

C -> S GET ...
Authorization: NTLM TlRMTVNTUAADAAAAGAAYAHIAAAAYABgAigAAABQAFABAAAAADAAMAFQAAAASABIAYAAAAAAAAACiAAAAAYIAAFUAUgBTAEEALQBNAEkATgBPAFIAWgBhAHAAaABvAGQATABJAEcASABUAEMASQBUAFkArYfKbe/jRoW5xDxHeoxC1gBmfWiS5+iX4OAN4xBKG/IFPwfH3agtPEia6YnhsADT

S -> C 200 Ok

and the unencoded messages are:

Type-1 Message:

0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
0: 4e 54 4c 4d 53 53 50 00 01 00 00 00 03 b2 00 00 "NTLMSSP........."
10: 0a 00 0a 00 29 00 00 00 09 00 09 00 20 00 00 00 "....)....... ..."
20: 4c 49 47 48 54 43 49 54 59 55 52 53 41 2d 4d 49 "LIGHTCITYURSA-MI"
30: 4e 4f 52 "NOR"

Type-2 Message:

0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
0: 4e 54 4c 4d 53 53 50 00 02 00 00 00 00 00 00 00 "NTLMSSP........."
10: 28 00 00 00 01 82 00 00 53 72 76 4e 6f 6e 63 65 "(.......SrvNonce"
20: 00 00 00 00 00 00 00 00 "........"

Type-3 Message:

0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
0: 4e 54 4c 4d 53 53 50 00 03 00 00 00 18 00 18 00 "NTLMSSP........."
10: 72 00 00 00 18 00 18 00 8a 00 00 00 14 00 14 00 "r..............."
20: 40 00 00 00 0c 00 0c 00 54 00 00 00 12 00 12 00 "@.......T......."
30: 60 00 00 00 00 00 00 00 a2 00 00 00 01 82 00 00 "`..............."
40: 55 00 52 00 53 00 41 00 2d 00 4d 00 49 00 4e 00 "U.R.S.A.-.M.I.N."
50: 4f 00 52 00 5a 00 61 00 70 00 68 00 6f 00 64 00 "O.R.Z.a.p.h.o.d."
60: 4c 00 49 00 47 00 48 00 54 00 43 00 49 00 54 00 "L.I.G.H.T.C.I.T."
70: 59 00 ad 87 ca 6d ef e3 46 85 b9 c4 3c 47 7a 8c "Y....m..F... 80: 42 d6 00 66 7d 68 92 e7 e8 97 e0 e0 0d e3 10 4a "B..f}h.........J"
90: 1b f2 05 3f 07 c7 dd a8 2d 3c 48 9a e9 89 e1 b0 "...?....- a0: 00 d3 ".."

For reference, the intermediate hashed passwords are:

lm_hpw (LanManager hashed password):
91 90 16 f6 4e c7 b0 0b a2 35 02 8c a5 0c 7a 03 00 00 00 00 00
nt_hpw (NT hashed password):
8c 1b 59 e3 2e 66 6d ad f1 75 74 5f ad 62 c1 33 00 00 00 00 00
Resources
LM authentication in SMB/CIFS
http://www.ubiqx.org/cifs/SMB.html#SMB.8.3
A document on cracking NTLMv2 authentication
http://www.blackhat.com/presentations/win-usa-02/urity-winsec02.ppt
Squid's NLTM authentication project
http://squid.sourceforge.net/ntlm/
Encryption description for Samba
http://de.samba.org/samba/ftp/docs/htmldocs/ENCRYPTION.html
Info on the MSIE security hole
http://oliver.efri.hr/~crv/security/bugs/NT/ie6.html
FAQ: NT Cryptographic Password Attacks & Defences
http://www.ntbugtraq.com/default.asp?sid=1&pid=47&aid=17
M$'s hotfix to disable the sending of the LanManager response
ftp://ftp.microsoft.com/bussys/winnt/winnt-public/fixes/usa/NT40/hotfixes-postSP3/lm-fix
A description of M$'s hotfix
http://www.tryc.on.ca/archives/bugtraq/1997_3/0070.html
Acknowledgements
Special thanks to the following people who helped with the collection and debugging of the above information:
Jon Lennard
Paul Ashton
Jeremy Allison

--------------------------------------------------------------------------------

Ronald Tschal?r / 17. June 2003 / ronald@innovation.ch.

星期二, 三月 02, 2004

193998 - HOWTO: Read and Display Binary Data in ASP/jsp

193998 - HOWTO: Read and Display Binary Data in ASP

ASP:Response.ContentType = "application/x-msexcel"
Java Servlet:response.setContentType("application/x-msexcel");

如何下载一个文件而不是打开它?

260519 - HOWTO: Raise a "File Download" Dialog Box for a Known MIME Type
Content-disposition: attachment; filename=fname.ext
对IE 在ASP:Response.AddHeader "content-disposition","attachment; filename=fname.ext"
Servlet:response.addHeader("content-disposition","attachemnt; filename=fname.ext");


如何在Servlet 利用Java Reflection 机制来实现 提交的FormBean

/**
* Iterate through the setters of this object and then take the named
* parameters that match and set the value of the setter
* to the value of the corresponding parameter
*/
public void mapBean(javax.servlet.http.HttpServletRequest req, Object bean) {
Method[] methods = bean.getClass().getMethods();
for (int i=0; iMethod meth = methods[i];
if (meth.getName().startsWith("set")) {
String propertyName = meth.getName().substring(3).toUpperCase();
// matching without case is faster than matching with case
String parm = req.getParameter(propertyName);
if (parm != null) {
Object[] objs = new Object[1];
objs[0] = parm;
try {
meth.invoke(bean, objs);
} catch (Exception e) {} // could not set
}
}
}
}