From bcel-dev-return-735-apmail-jakarta-bcel-dev-archive=jakarta.apache.org@jakarta.apache.org Wed Jan 05 04:54:04 2005 Return-Path: Delivered-To: apmail-jakarta-bcel-dev-archive@www.apache.org Received: (qmail 92560 invoked from network); 5 Jan 2005 04:54:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 5 Jan 2005 04:54:04 -0000 Received: (qmail 66819 invoked by uid 500); 5 Jan 2005 04:54:03 -0000 Delivered-To: apmail-jakarta-bcel-dev-archive@jakarta.apache.org Received: (qmail 66796 invoked by uid 500); 5 Jan 2005 04:54:03 -0000 Mailing-List: contact bcel-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "BCEL Developers List" Reply-To: "BCEL Developers List" Delivered-To: mailing list bcel-dev@jakarta.apache.org Received: (qmail 66782 invoked by uid 99); 5 Jan 2005 04:54:03 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of dbrosius@qis.net designates 209.150.96.22 as permitted sender) Received: from floyd.qis.net (HELO floyd.qis.net) (209.150.96.22) by apache.org (qpsmtpd/0.28) with ESMTP; Tue, 04 Jan 2005 20:53:59 -0800 Received: from moon.qis.net (moon.qis.net [209.150.96.24]) by floyd.qis.net (Postfix) with ESMTP id C90C5738D7 for ; Tue, 4 Jan 2005 23:53:55 -0500 (EST) Received: from 209.150.96.22 by moon.qis.net (amavisd-lite) with LMTP id 1104901135-83747-55 for ; Tue Jan 4 23:58:56 2005 Received: from MBFG (animals.qis.net [209.150.97.25]) by floyd.qis.net (Postfix) with SMTP id 6166C738AC for ; Tue, 4 Jan 2005 23:53:54 -0500 (EST) Received: from balt-209-150-117-131.dynamic-dial.qis.net (dbrosius@qis.net@balt-209-150-117-131.dynamic-dial.qis.net [209.150.117.131]) by animals.qis.net (SlipStream SP Server 3.1.68 built 2004/04/13 15:19:46 -0400 (EDT)); Tue, 04 Jan 2005 23:53:59 -0500 (EST) Message-ID: <00b701c4f2e2$95e6d440$837596d1@MBFG> From: "Dave Brosius" To: "BCEL Developers List" References: <31cc373605010319222b9d8084@mail.gmail.com> <41DA114D.10408@apache.org> <41DB4B67.5030002@apache.org> Subject: [PATCH] make the JavaClass repository cache memory sensitive Date: Tue, 4 Jan 2005 23:54:05 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-lite at moon.qis.net X-Spam-Status: No, hits=0.0 required=5.0 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I'd like to wrap the repository cache (map values) in SoftReferences. Applications can load quite a few JavaClass'es that are stored in the repository, and it can become easy to start failing due to out of memory conditions. Using the softreferences keeps BCEL humming, even under heavy usage. Here's a patch against the latest, that accomplishes this. BTW, if anyone would like to give me the secret handshake, i'd be interested in committer status to help support BCEL in the future. Index: src/java/org/apache/bcel/util/SyntheticRepository.java =================================================================== RCS file: /home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/util/SyntheticRepository.java,v retrieving revision 1.9 diff -u -r1.9 SyntheticRepository.java --- src/java/org/apache/bcel/util/SyntheticRepository.java 15 Dec 2004 08:28:50 -0000 1.9 +++ src/java/org/apache/bcel/util/SyntheticRepository.java 5 Jan 2005 04:40:26 -0000 @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.ref.SoftReference; import java.util.HashMap; import org.apache.bcel.classfile.ClassParser; @@ -76,7 +77,7 @@ * Store a new JavaClass instance into this Repository. */ public void storeClass(JavaClass clazz) { - _loadedClasses.put(clazz.getClassName(), clazz); + _loadedClasses.put(clazz.getClassName(), new SoftReference(clazz)); clazz.setRepository(this); } @@ -91,7 +92,10 @@ * Find an already defined (cached) JavaClass object by name. */ public JavaClass findClass(String className) { - return (JavaClass)_loadedClasses.get(className); + SoftReference ref = (SoftReference)_loadedClasses.get(className); + if (ref == null) + return null; + return (JavaClass)ref.get(); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: bcel-dev-help@jakarta.apache.org